app/src/main/kotlin/space/subread/overlay/Anki.kt (1497 bytes)
1 package space.subread.overlay 2 3 import android.content.Context 4 import android.content.Intent 5 6 /** 7 * Sends a card to SubRead Anki: the word and the subtitle line it is in. The strings are the 8 * intent contract of that app, see its docs/intent-api.md. SubRead Anki looks the word up in 9 * SubRead Dictionary, takes a screenshot of the player, reads the line with the voice of the 10 * device, and puts the card in AnkiDroid. 11 */ 12 object Anki { 13 const val PACKAGE = "space.subread.anki" 14 const val INSTALL = "https://github.com/equwal/subread-anki/releases/latest" 15 private const val ACTION_ADD = "space.subread.anki.action.ADD" 16 private const val EXTRA_WORD = "space.subread.anki.extra.WORD" 17 private const val EXTRA_SENTENCE = "space.subread.anki.extra.SENTENCE" 18 private const val EXTRA_SOURCE = "space.subread.anki.extra.SOURCE" 19 private const val EXTRA_SCREENSHOT = "space.subread.anki.extra.SCREENSHOT" 20 21 fun installed(context: Context): Boolean = 22 context.packageManager.resolveActivity(Intent(ACTION_ADD).setPackage(PACKAGE), 0) != null 23 24 /** The intent for one card. The panel is not an activity, so the intent starts a new task. */ 25 fun intent(word: String, line: String, source: String): Intent = Intent(ACTION_ADD) 26 .setPackage(PACKAGE) 27 .putExtra(EXTRA_WORD, word) 28 .putExtra(EXTRA_SENTENCE, line) 29 .putExtra(EXTRA_SOURCE, source) 30 .putExtra(EXTRA_SCREENSHOT, true) 31 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 32 }