Skip to content

Commit

Permalink
Focus mode; Fixes for gestureless; Move share menu; Fixed multi context
Browse files Browse the repository at this point in the history
  • Loading branch information
arianneorpilla committed Apr 23, 2021
1 parent b1b8608 commit f3ec92f
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 104 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<p align="center">A mobile video player tailored for Japanese language learners.</p>

<p align="center" style="margin:0"><b>Latest GitHub Release:<br>
<a href="https://github.com/lrorpilla/jidoujisho/releases/tag/0.13.0-beta">0.13.0-beta 🇯🇵 → 🇬🇧</a><br>
<a href="https://github.com/lrorpilla/jidoujisho/releases/tag/0.13.1-beta">0.13.1-beta 🇯🇵 → 🇬🇧</a><br>
<a href="https://github.com/lrorpilla/jidoujisho/releases/tag/0.5.3-enjp-beta">0.5.3-beta 🇬🇧 → 🇯🇵</a></b><br></p>
<div latest></div>

Expand Down
1 change: 1 addition & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ android {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
shrinkResources false
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<uses-permission android:name="android.permission.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.ichi2.anki.permission.READ_WRITE_DATABASE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<application
android:label="jidoujisho"
android:icon="@mipmap/launcher_icon"
Expand Down Expand Up @@ -42,6 +43,16 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service android:name="com.ryanheise.audioservice.AudioService">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
<receiver android:name="com.ryanheise.audioservice.MediaButtonReceiver" >
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
Expand Down
2 changes: 2 additions & 0 deletions chewie/lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class ChewieController extends ChangeNotifier {
@required this.currentDictionaryEntry,
@required this.currentSubtitle,
@required this.currentSubTrack,
@required this.wasPlaying,
@required this.playExternalSubtitles,
@required this.retimeSubtitles,
this.aspectRatio,
Expand Down Expand Up @@ -260,6 +261,7 @@ class ChewieController extends ChangeNotifier {
final ValueNotifier<Subtitle> currentSubtitle;
final ValueNotifier<DictionaryEntry> currentDictionaryEntry;
final ValueNotifier<int> currentSubTrack;
final ValueNotifier<bool> wasPlaying;
final VoidCallback playExternalSubtitles;
final VoidCallback retimeSubtitles;
final YouTubeMux streamData;
Expand Down
85 changes: 57 additions & 28 deletions chewie/lib/src/material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,43 @@ class _MaterialControlsState extends State<MaterialControls>
);
}

Future<void> openExtraShare() async {
final chosenOption = await showModalBottomSheet<int>(
context: context,
isScrollControlled: true,
useRootNavigator: true,
builder: (context) => const _MoreOptionsDialog(options: [
"Search Current Subtitle with Jisho.org",
"Translate Current Subtitle with DeepL",
"Translate Current Subtitle with Google Translate",
"Share Current Subtitle with Menu",
], icons: [
Icons.menu_book_rounded,
Icons.translate_rounded,
Icons.g_translate_rounded,
Icons.share_outlined,
]),
);

final String subtitleText = chewieController.currentSubtitle.value.text;

switch (chosenOption) {
case 0:
await launch("https://jisho.org/search/$subtitleText");
break;
case 1:
await launch("https://www.deepl.com/translator#ja/en/$subtitleText");
break;
case 2:
await launch(
"https://translate.google.com/?sl=ja&tl=en&text=$subtitleText&op=translate");
break;
case 3:
Share.share(subtitleText);
break;
}
}

Widget _buildMoreButton(VlcPlayerController controller) {
return GestureDetector(
onTap: () async {
Expand All @@ -260,62 +297,53 @@ class _MaterialControlsState extends State<MaterialControls>
isScrollControlled: true,
useRootNavigator: true,
builder: (context) => _MoreOptionsDialog(options: [
"Search Current Subtitle with Jisho.org",
"Translate Current Subtitle with DeepL",
"Translate Current Subtitle with Google Translate",
"Share Current Subtitle to App",
if (gIsSelectMode.value)
"Share Current Subtitle to Applications",
if (getSelectMode())
"Use Tap to Select Subtitle Selection"
else
"Use Drag to Select Subtitle Selection",
if (getFocusMode())
"Turn Off Definition Focus Mode"
else
"Turn On Definition Focus Mode",
"Adjust Subtitle Delay",
"Load External Subtitles",
"Export Current Context to Anki",
], icons: [
Icons.menu_book_rounded,
Icons.translate_rounded,
Icons.g_translate_rounded,
Icons.share_outlined,
if (gIsSelectMode.value)
if (getSelectMode())
Icons.touch_app_rounded
else
Icons.select_all_rounded,
Icons.timer_sharp,
if (getFocusMode())
Icons.lightbulb_outline_rounded
else
Icons.lightbulb,
Icons.timer_rounded,
Icons.subtitles_outlined,
Icons.mobile_screen_share_rounded,
]),
);

final String subtitleText = chewieController.currentSubtitle.value.text;

switch (chosenOption) {
case 0:
await launch("https://jisho.org/search/$subtitleText");
openExtraShare();
break;
case 1:
await launch(
"https://www.deepl.com/translator#ja/en/$subtitleText");
toggleSelectMode();
gIsSelectMode.value = getSelectMode();
break;
case 2:
await launch(
"https://translate.google.com/?sl=ja&tl=en&text=$subtitleText&op=translate");
toggleFocusMode();
break;
case 3:
Share.share(subtitleText);
break;
case 4:
toggleSelectMode();
gIsSelectMode.value = getSelectMode();
break;
case 5:
controller.pause();
chewieController.retimeSubtitles();
break;
case 6:
case 4:
chewieController.playExternalSubtitles();
break;
case 7:
final bool wasPlaying = await controller.isPlaying();
case 5:
controller.pause();

final Subtitle currentSubtitle =
Expand All @@ -332,7 +360,7 @@ class _MaterialControlsState extends State<MaterialControls>
chewieController.clipboard,
currentSubtitle,
currentDictionaryEntry,
wasPlaying,
chewieController.wasPlaying.value,
);

break;
Expand Down Expand Up @@ -591,6 +619,7 @@ class _MaterialControlsState extends State<MaterialControls>

void _playPause() {
final isFinished = controller.value.isEnded;
chewieController.wasPlaying.value = false;

setState(() {
if (controller.value.isPlaying) {
Expand Down
7 changes: 5 additions & 2 deletions lib/anki.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,12 @@ void showAnkiDialog(
flex: 30,
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Image.file(File(getPreviewImagePath()),
fit: BoxFit.contain),
Image.file(
File(getPreviewImagePath()),
fit: BoxFit.fitWidth,
),
DeckDropDown(
decks: decks,
selectedDeck: _selectedDeck,
Expand Down
3 changes: 3 additions & 0 deletions lib/globals.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:async/async.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';
import 'package:fuzzy/fuzzy.dart';
import 'package:mecab_dart/mecab_dart.dart';
import 'package:package_info/package_info.dart';
Expand Down Expand Up @@ -29,3 +30,5 @@ Map<String, AsyncMemoizer> gMetadataCache = {};

List<DictionaryEntry> gCustomDictionary;
Fuzzy gCustomDictionaryFuzzy;

ValueNotifier<bool> gPlayPause = ValueNotifier<bool>(true);
87 changes: 53 additions & 34 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'dart:io';

import 'package:async/async.dart';
import 'package:audio_service/audio_service.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';
import 'package:fuzzy/fuzzy.dart';

import 'package:lazy_load_scrollview/lazy_load_scrollview.dart';
Expand All @@ -29,7 +31,8 @@ typedef void SearchCallback(String term);

void main() async {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setEnabledSystemUIOverlays([]);
SystemChrome.setEnabledSystemUIOverlays(
[SystemUiOverlay.bottom, SystemUiOverlay.top]);

await Permission.storage.request();
requestAnkiDroidPermissions();
Expand All @@ -47,9 +50,51 @@ void main() async {
gCustomDictionary = importCustomDictionary();
gCustomDictionaryFuzzy = Fuzzy(getAllImportedWords());

await AudioService.connect();
await AudioService.start(backgroundTaskEntrypoint: _backgroundTaskEntrypoint);

runApp(App());
}

_backgroundTaskEntrypoint() {
AudioServiceBackground.run(() => AudioPlayerTask());
}

class AudioPlayerTask extends BackgroundAudioTask {
AudioPlayerTask();

@override
Future<void> onPlay() async {
AudioServiceBackground.sendCustomEvent("playPause");
}

@override
Future<void> onPause() async {
AudioServiceBackground.sendCustomEvent("playPause");
}

@override
Future<void> onFastForward() async {
AudioServiceBackground.sendCustomEvent("rewindFastForward");
}

@override
Future<void> onRewind() async {
AudioServiceBackground.sendCustomEvent("rewindFastForward");
}
}

void unlockLandscape() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);

SystemChrome.setEnabledSystemUIOverlays(
[SystemUiOverlay.bottom, SystemUiOverlay.top]);
}

class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
Expand All @@ -63,7 +108,7 @@ class App extends StatelessWidget {
appBarTheme: AppBarTheme(backgroundColor: Colors.black),
canvasColor: Colors.grey[900],
),
home: Home(),
home: AudioServiceWidget(child: Home()),
);
}
}
Expand Down Expand Up @@ -97,13 +142,7 @@ class _HomeState extends State<Home> {
builder: (context) => Player(),
),
).then((returnValue) {
setState(() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
});
unlockLandscape();
});
} else {
_selectedIndex = index;
Expand Down Expand Up @@ -177,11 +216,7 @@ class _HomeState extends State<Home> {

@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
unlockLandscape();

return new WillPopScope(
onWillPop: _onWillPop,
Expand Down Expand Up @@ -716,11 +751,7 @@ class _HomeState extends State<Home> {
),
).then((returnValue) {
setState(() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
unlockLandscape();
});

setLastPlayedPath(webURL);
Expand Down Expand Up @@ -889,11 +920,7 @@ class _HomeState extends State<Home> {
),
),
).then((returnValue) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
unlockLandscape();
});
},
);
Expand Down Expand Up @@ -1145,11 +1172,7 @@ class _YouTubeResultState extends State<YouTubeResult>
),
),
).then((returnValue) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
unlockLandscape();

setLastPlayedPath(videoStreamURL);
setLastPlayedPosition(0);
Expand Down Expand Up @@ -1759,11 +1782,7 @@ class _HistoryResultState extends State<HistoryResult>
),
),
).then((returnValue) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
unlockLandscape();

setLastPlayedPath(history.url);
setLastPlayedPosition(0);
Expand Down
Loading

0 comments on commit f3ec92f

Please sign in to comment.