Skip to content

Commit

Permalink
Shadowing mode, share intent, card creator
Browse files Browse the repository at this point in the history
  • Loading branch information
arianneorpilla committed May 3, 2021
1 parent 833911e commit e6b7937
Show file tree
Hide file tree
Showing 11 changed files with 1,338 additions and 59 deletions.
31 changes: 31 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,37 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!--TODO: Add this filter, if you want support opening urls into your app-->
<data
android:scheme="https"
android:host="example.com"
android:pathPrefix="/invite"/>
</intent-filter>

<!--TODO: Add this filter, if you want to support sharing text into your app-->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" />
</intent-filter>

<!--TODO: Add this filter, if you want to support sharing images into your app-->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>

<!--TODO: Add this filter, if you want to support sharing videos into your app-->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="video/*" />
</intent-filter>
</activity>
<service android:name="com.ryanheise.audioservice.AudioService">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,64 @@ protected void onCreate(Bundle savedInstanceState) {
mAnkiDroid = new AnkiDroidHelper(context);
}

private void addCreatorNote(String deck, String image, String audio, String sentence, String word, String meaning, String reading) {
final AddContentApi api = new AddContentApi(context);

long deckId;
if (deckExists(deck)) {
deckId = mAnkiDroid.findDeckIdByName(deck);
} else {
deckId = api.addNewDeck(deck);
}

long modelId;
if (modelExists("jidoujisho (Creator)")) {
modelId = mAnkiDroid.findModelIdByName("jidoujisho (Creator)", 6);
} else {
modelId = api.addNewCustomModel("jidoujisho (Creator)",
new String[] {"Image", "Audio", "Sentence", "Word", "Meaning", "Reading"},
new String[] {"jidoujisho (Creator) Default"},
new String[] {"{{Image}}<br>{{Word}}"},
new String[] {"{{Image}}<br>{{Word}}" +
"<hr id=reading><p id=\"reading\">{{Reading}}</p><h2 id=\"word\">{{Word}}</h2><br><p><small id=\"meaning\">{{Meaning}}</small></p>"},
"p {\n" +
" margin: 0px\n" +
"}\n" +
"\n" +
"h2 {\n" +
" margin: 0px\n" +
"}\n" +
"\n" +
"small {\n" +
" margin: 0px\n" +
"}\n" +
"\n" +
".card {\n" +
" font-family: arial;\n" +
" font-size: 20px;\n" +
" white-space: pre-line;\n" +
" text-align: center;\n" +
" color: black;\n" +
" background-color: white;\n" +
"}\n" +
"\n" +
"#sentence {\n" +
" font-size: 30px\n" +
"}",
null,
null
);
}

Set<String> tags = new HashSet<>(Arrays.asList("jidoujisho"));

api.addNote(modelId, deckId, new String[] {image, audio, sentence, word, meaning, reading}, tags);

System.out.println("Added note via flutter_ankidroid_api");
System.out.println("Model: " + modelId);
System.out.println("Deck: " + deckId);
}

private void addNote(String deck, String image, String audio, String sentence, String word, String meaning, String reading) {
final AddContentApi api = new AddContentApi(context);

Expand Down Expand Up @@ -156,22 +214,27 @@ private Long getModelId() {

@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {

super.configureFlutterEngine(flutterEngine);
new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), ANKIDROID_CHANNEL)
.setMethodCallHandler(
(call, result) -> {
final String deck = call.argument("deck");
final String image = call.argument("image");
final String audio = call.argument("audio");
final String sentence = call.argument("sentence");
final String answer = call.argument("answer");
final String meaning = call.argument("meaning");
final String reading = call.argument("reading");

switch (call.method) {
case "addNote":
final String deck = call.argument("deck");
final String image = call.argument("image");
final String audio = call.argument("audio");
final String sentence = call.argument("sentence");
final String answer = call.argument("answer");
final String meaning = call.argument("meaning");
final String reading = call.argument("reading");

addNote(deck, image, audio, sentence, answer, meaning, reading);
break;
case "addCreatorNote":

addCreatorNote(deck, image, audio, sentence, answer, meaning, reading);
break;
case "getDecks":
final AddContentApi api = new AddContentApi(context);
result.success(api.getDeckList());
Expand Down
4 changes: 4 additions & 0 deletions chewie/lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ class ChewieController extends ChangeNotifier {
@required this.playExternalSubtitles,
@required this.retimeSubtitles,
@required this.exportSingleCallback,
@required this.toggleShadowingMode,
@required this.shadowingSubtitle,
this.aspectRatio,
this.autoInitialize = false,
this.autoPlay = false,
Expand Down Expand Up @@ -266,6 +268,8 @@ class ChewieController extends ChangeNotifier {
final VoidCallback playExternalSubtitles;
final VoidCallback retimeSubtitles;
final VoidCallback exportSingleCallback;
final VoidCallback toggleShadowingMode;
final ValueNotifier<Subtitle> shadowingSubtitle;
final YouTubeMux streamData;

/// Initialize the Video on Startup. This will prep the video for playback.
Expand Down
45 changes: 34 additions & 11 deletions chewie/lib/src/material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -549,19 +549,42 @@ class _MaterialControlsState extends State<MaterialControls>
? _latestValue.duration
: Duration.zero;

return GestureDetector(
child: Padding(
padding: const EdgeInsets.only(right: 24.0),
child: Text(
duration != Duration.zero
? '${formatDuration(position)} / ${formatDuration(duration)}'
: '',
style: const TextStyle(
fontSize: 14.0,
if (chewieController.shadowingSubtitle.value != null) {
return GestureDetector(
onTap: () {
chewieController.toggleShadowingMode();
},
child: Padding(
padding: const EdgeInsets.only(right: 24.0),
child: Text(
duration != Duration.zero
? '${formatDuration(position)} / ${formatDuration(chewieController.shadowingSubtitle.value.endTime)}'
: '',
style: const TextStyle(
fontSize: 14.0,
color: Colors.red,
),
),
),
),
);
);
} else {
return GestureDetector(
onTap: () {
chewieController.toggleShadowingMode();
},
child: Padding(
padding: const EdgeInsets.only(right: 24.0),
child: Text(
duration != Duration.zero
? '${formatDuration(position)} / ${formatDuration(duration)}'
: '',
style: const TextStyle(
fontSize: 14.0,
),
),
),
);
}
}

void _cancelAndRestartTimer() {
Expand Down
58 changes: 54 additions & 4 deletions lib/anki.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Future exportToAnki(
int audioAllowance,
int subtitleDelay,
) async {
String lastDeck = gSharedPrefs.getString("lastDeck") ?? "Default";
String lastDeck = getLastDeck();

List<String> decks;
try {
Expand Down Expand Up @@ -247,9 +247,9 @@ void showAnkiDialog(
decoration: InputDecoration(
prefixIcon: Icon(icon),
suffixIcon: IconButton(
iconSize: 12,
iconSize: 18,
onPressed: () => controller.clear(),
icon: Icon(Icons.clear),
icon: Icon(Icons.clear, color: Colors.white),
),
labelText: labelText,
hintText: hintText,
Expand Down Expand Up @@ -521,6 +521,33 @@ Future<void> addNote(
}
}

Future<void> addCreatorNote(
String deck,
String image,
String audio,
String sentence,
String answer,
String meaning,
String reading,
) async {
const platform = const MethodChannel('com.lrorpilla.api/ankidroid');

try {
await platform.invokeMethod('addCreatorNote', <String, dynamic>{
'deck': deck,
'image': image,
'audio': audio,
'sentence': sentence,
'answer': answer,
'meaning': meaning,
'reading': reading,
});
} on PlatformException catch (e) {
print("Failed to add note via AnkiDroid API");
print(e);
}
}

Future<List<String>> getDecks() async {
const platform = const MethodChannel('com.lrorpilla.api/ankidroid');
Map<dynamic, dynamic> deckMap = await platform.invokeMethod('getDecks');
Expand Down Expand Up @@ -557,7 +584,7 @@ class _DeckDropDownState extends State<DeckDropDown> {
);
}).toList(),
onChanged: (selectedDeck) async {
gSharedPrefs.setString("lastDeck", selectedDeck);
setLastDeck(selectedDeck);

setState(() {
_selectedDeck.value = selectedDeck;
Expand Down Expand Up @@ -606,3 +633,26 @@ void exportAnkiCard(String deck, String sentence, String answer, String reading,
requestAnkiDroidPermissions();
addNote(deck, addImage, addAudio, sentence, answer, meaning, reading);
}

void exportCreatorAnkiCard(String deck, String sentence, String answer,
String reading, String meaning, File imageFile) {
DateTime now = DateTime.now();
String newFileName =
"jidoujisho-" + intl.DateFormat('yyyyMMddTkkmmss').format(now);

String newImagePath = path.join(
getAnkiDroidDirectory().path,
"collection.media/$newFileName.jpg",
);

String addImage = "";
String addAudio = "";

if (imageFile.existsSync()) {
imageFile.copySync(newImagePath);
addImage = "<img src=\"$newFileName.jpg\">";
}

requestAnkiDroidPermissions();
addCreatorNote(deck, addImage, addAudio, sentence, answer, meaning, reading);
}
Loading

0 comments on commit e6b7937

Please sign in to comment.