Skip to content

Commit

Permalink
feat: keybindings
Browse files Browse the repository at this point in the history
  • Loading branch information
aayush2622 committed Dec 21, 2024
1 parent 0e28e65 commit 0696053
Show file tree
Hide file tree
Showing 18 changed files with 194 additions and 116 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (flutterVersionName == null) {
}

android {
namespace = "com.aayush262.dantotsu"
namespace = "ani.aayush262.dartotsu"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion

Expand All @@ -39,7 +39,7 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.aayush262.dantotsu"
applicationId = "ani.aayush262.dartotsu"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdk = flutter.minSdkVersion
Expand Down
2 changes: 1 addition & 1 deletion android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
-keep class androidx.lifecycle.** { *; }

# Keep your custom package classes (optimize to specific ones if possible)
-keep class com.aayush262.** { *; }
-keep class ani.aayush262.** { *; }

# Keep Gson models (optimize to specific models if possible)
-keep class com.google.gson.** { *; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.aayush262.dantotsu
package ani.aayush262.dartotsu

import io.flutter.embedding.android.FlutterActivity

Expand Down
12 changes: 6 additions & 6 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.aayush262.dantotsu;
PRODUCT_BUNDLE_IDENTIFIER = ani.aayush262.dartotsu;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand All @@ -384,7 +384,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.aayush262.dantotsu.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = ani.aayush262.dartotsu.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -401,7 +401,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.aayush262.dantotsu.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = ani.aayush262.dartotsu.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
Expand All @@ -416,7 +416,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.aayush262.dantotsu.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = ani.aayush262.dartotsu.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
Expand Down Expand Up @@ -547,7 +547,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.aayush262.dantotsu;
PRODUCT_BUNDLE_IDENTIFIER = ani.aayush262.dartotsu;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -569,7 +569,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.aayush262.dantotsu;
PRODUCT_BUNDLE_IDENTIFIER = ani.aayush262.dartotsu;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down
4 changes: 2 additions & 2 deletions lib/Preferences/Preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class PrefName {
Pref(Location.General, 'source', 'ANILIST');

//theme
static const Pref<bool> isDarkMode =
Pref(Location.General, 'isDarkMode', false);
static const Pref<int> isDarkMode =
Pref(Location.General, 'isDarkMode', 0);
static const Pref<bool> isOled = Pref(Location.General, 'isOled', false);
static const Pref<bool> useMaterialYou =
Pref(Location.General, 'useMaterialYou', false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ abstract class BasePlayer extends GetxController {
Future<void> playOrPause();
Future<void> setVolume(double volume);
Future<void> setRate(double rate);
Future<void> open(String url);
Future<void> open(String url,Duration duration);
Future<void> setSubtitle(String subtitleUri, String language);

void listenToPlayerStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class WindowsPlayer extends BasePlayer {
videoController.player.setVolume(volume);

@override
Future<void> open(String url) async =>
videoController.player.open(Media(url));
Future<void> open(String url,Duration duration) async =>
videoController.player.open(Media(url,start: duration));

@override
Future<void> setSubtitle(String subtitleUri, String language) =>
Expand All @@ -58,6 +58,7 @@ class WindowsPlayer extends BasePlayer {

@override
void listenToPlayerStream() {

videoController.player.stream.position
.listen((e) => currentTime.value = _formatTime(e.inSeconds));
videoController.player.stream.duration
Expand Down
37 changes: 33 additions & 4 deletions lib/Screens/Info/Tabs/Watch/Anime/Player/Player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class MediaPlayerState extends State<MediaPlayer>
void _initializePlayer() {
currentQuality = widget.videos[widget.index];
videoPlayerController = WindowsPlayer(resizeMode, settings);
videoPlayerController.open(currentQuality.url);
videoPlayerController.open(currentQuality.url, Duration.zero);
}

void _loadPlayerSettings() {
Expand Down Expand Up @@ -175,9 +175,11 @@ class MediaPlayerState extends State<MediaPlayer>
}
return GestureDetector(
onHorizontalDragUpdate: (details) {
setState(() => episodePanelWidth =
(episodePanelWidth - details.delta.dx)
.clamp(minWidth, availableWidth));
setState(
() => episodePanelWidth =
(episodePanelWidth - details.delta.dx)
.clamp(minWidth, availableWidth),
);
},
child: SizedBox(
width: episodePanelWidth,
Expand Down Expand Up @@ -551,10 +553,37 @@ class MediaPlayerState extends State<MediaPlayer>
_skipSegments(false);
} else if (event.logicalKey == LogicalKeyboardKey.space) {
videoPlayerController.playOrPause();
} else if (event.logicalKey == LogicalKeyboardKey.enter) {
showEpisodes.value = !showEpisodes.value;
} else if (RegExp(r'^[0-9]$').hasMatch(event.logicalKey.keyLabel)) {
var keyNumber = int.parse(event.logicalKey.keyLabel);

var videoDurationSeconds =
_timeStringToSeconds(videoPlayerController.maxTime.value);
var targetSeconds = (keyNumber / 10) * videoDurationSeconds;

if (keyNumber == 1) {
targetSeconds = 0;
} else if (keyNumber == 0) {
targetSeconds = videoDurationSeconds.toDouble();
} else {
targetSeconds = (keyNumber / 10) * videoDurationSeconds;
}

videoPlayerController.seek(Duration(seconds: targetSeconds.toInt()));
}
}
}

int _timeStringToSeconds(String time) {
final parts = time.split(':').map(int.parse).toList();
if (parts.length == 2) return parts[0] * 60 + parts[1];
if (parts.length == 3) {
return parts[0] * 3600 + parts[1] * 60 + parts[2];
}
return 0;
}

void changeViewType(RxInt viewType, int index) {
var type = loadSelected(widget.media);
viewType.value = index;
Expand Down
10 changes: 7 additions & 3 deletions lib/Screens/Info/Tabs/Watch/Anime/Player/PlayerController.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class _PlayerControllerState extends State<PlayerController> {
settings = media.anime!.playerSettings!;
fitType = settings.resizeMode;
WakelockPlus.enable();
initFullScreen();
_controller = widget.player.videoPlayerController;
currentQuality = videos[widget.player.widget.index];
_controller.listenToPlayerStream();
Expand All @@ -70,6 +71,8 @@ class _PlayerControllerState extends State<PlayerController> {
WakelockPlus.disable();
super.dispose();
}
Future initFullScreen() async =>
isFullScreen.value = await WindowManager.instance.isFullScreen();

String _formatTime(int seconds) {
final hours = seconds ~/ 3600;
Expand Down Expand Up @@ -123,7 +126,8 @@ class _PlayerControllerState extends State<PlayerController> {
children: [
Row(
children: [
Text(_controller.currentTime.value),
Text(_controller.currentTime.value,
style: const TextStyle(color: Colors.white),),
Text(
" / ",
style: TextStyle(
Expand Down Expand Up @@ -533,7 +537,7 @@ class _PlayerControllerState extends State<PlayerController> {
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 12),
backgroundColor:
Theme.of(context).colorScheme.surface.withValues(alpha: 0.2),
Colors.black.withValues(alpha: 0.2),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
side: BorderSide(
Expand Down Expand Up @@ -608,7 +612,7 @@ class _PlayerControllerState extends State<PlayerController> {
return;
}
currentQuality = videos[index];
_controller.open(currentQuality.url);
_controller.open(currentQuality.url, _controller.currentPosition.value);
Get.back();
},
);
Expand Down
4 changes: 2 additions & 2 deletions lib/Screens/Settings/SettingsThemeScreen.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:dantotsu/Screens/Settings/BaseSettingsScreen.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'package:dantotsu/Theme/LanguageSwitcher.dart';
import '../../Adaptor/Settings/SettingsAdaptor.dart';

import '../../DataClass/Setting.dart';
import '../../Theme/LanguageSwitcher.dart';
import '../../Theme/CustomColorPicker.dart';
import '../../Theme/ThemeManager.dart';
import '../../Theme/ThemeProvider.dart';
Expand Down
18 changes: 15 additions & 3 deletions lib/Theme/ThemeProvider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,19 @@ class ThemeNotifier extends ChangeNotifier {
}

Future<void> _initialize() async {
_isDarkMode = PrefManager.getVal(PrefName.isDarkMode);
var darkMode = PrefManager.getVal(PrefName.isDarkMode);
bool isDark;

if (darkMode == 0) {
isDark = WidgetsBinding.instance.window.platformBrightness == Brightness.dark;
PrefManager.setVal(PrefName.isDarkMode, isDark ? 1 : 2);
} else if (darkMode == 1) {
isDark = true;
} else{
isDark = false;
}

_isDarkMode = isDark;
_isOled = PrefManager.getVal(PrefName.isOled);
_theme = PrefManager.getVal(PrefName.theme);
_useMaterialYou = PrefManager.getVal(PrefName.useMaterialYou);
Expand All @@ -39,7 +51,7 @@ class ThemeNotifier extends ChangeNotifier {

Future<void> setDarkMode(bool isDarkMode) async {
_isDarkMode = isDarkMode;
PrefManager.setVal(PrefName.isDarkMode, isDarkMode);
PrefManager.setVal(PrefName.isDarkMode, _isDarkMode ? 1 : 2);
if (!isDarkMode) {
_isOled = false;
PrefManager.setVal(PrefName.isOled, false);
Expand All @@ -52,7 +64,7 @@ class ThemeNotifier extends ChangeNotifier {
PrefManager.setVal(PrefName.isOled, isOled);
if (isOled) {
_isDarkMode = true;
PrefManager.setVal(PrefName.isDarkMode, true);
PrefManager.setVal(PrefName.isDarkMode, _isDarkMode ? 1 : 2);
}
notifyListeners();
}
Expand Down
64 changes: 45 additions & 19 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,37 +112,63 @@ class MainActivity extends StatefulWidget {

FloatingBottomNavBar? navbar;

class MainActivityState extends State<MainActivity> {
class MainActivityState extends State<MainActivity> with WidgetsBindingObserver {

@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}

int _selectedIndex = 1;

void _onTabSelected(int index) => setState(() => _selectedIndex = index);

@override
Widget build(BuildContext context) {
Discord.getSavedToken();
var service = Provider.of<MediaServiceProvider>(context).currentService;
var service = Provider
.of<MediaServiceProvider>(context)
.currentService;
navbar = FloatingBottomNavBar(
selectedIndex: _selectedIndex,
onTabSelected: _onTabSelected,
);

return Scaffold(
body: Stack(
children: [
Obx(() {
return IndexedStack(
index: _selectedIndex,
children: [
const AnimeScreen(),
service.data.token.value.isNotEmpty
? const HomeScreen()
: const LoginScreen(),
const MangaScreen(),
],
);
}),
navbar!,
],
return RawKeyboardListener(
focusNode: FocusNode(),
autofocus: true,
onKey: (RawKeyEvent event) async {
if (event is RawKeyDownEvent ) {
if (event.logicalKey == LogicalKeyboardKey.escape) {
if (Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
}
if (event.logicalKey == LogicalKeyboardKey.f11) {
WindowManager.instance.setFullScreen(!await WindowManager.instance.isFullScreen());
}

}
},
child: Scaffold(
body: Stack(
children: [
Obx(() {
return IndexedStack(
index: _selectedIndex,
children: [
const AnimeScreen(),
service.data.token.value.isNotEmpty
? const HomeScreen()
: const LoginScreen(),
const MangaScreen(),
],
);
}),
navbar!,
],
),
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ project(runner LANGUAGES CXX)
set(BINARY_NAME "dantotsu")
# The unique GTK application identifier for this application. See:
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
set(APPLICATION_ID "com.aayush262.dantotsu")
set(APPLICATION_ID "ani.aayush262.dartotsu")

# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
# versions of CMake.
Expand Down
Loading

0 comments on commit 0696053

Please sign in to comment.