From 53da8a89072e74eecb00fa4cdee0f1d015c30ff4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 22 Sep 2022 20:19:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 7 +-- app/src/main/AndroidManifest.xml | 35 ----------- .../java/io/legado/app/api/ReaderProvider.kt | 7 ++- .../main/java/io/legado/app/api/ShortCuts.kt | 63 +++++++++++++++++++ app/src/main/res/xml/shortcuts.xml | 60 ------------------ build.gradle | 3 +- 6 files changed, 71 insertions(+), 104 deletions(-) create mode 100644 app/src/main/java/io/legado/app/api/ShortCuts.kt delete mode 100644 app/src/main/res/xml/shortcuts.xml diff --git a/app/build.gradle b/app/build.gradle index 8e06ced19..09dcf156b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,7 +3,6 @@ plugins { id 'org.jetbrains.kotlin.android' id 'kotlin-parcelize' id 'kotlin-kapt' - id "de.timfreiheit.resourceplaceholders" //id "com.google.gms.google-services" } apply from: 'download.gradle' @@ -125,13 +124,9 @@ android { } } -resourcePlaceholders { - files = ['xml/shortcuts.xml'] -} - dependencies { //noinspection GradleDependency,GradlePackageUpdate - coreLibraryDesugaring('com.android.tools:desugar_jdk_libs:1.1.6') + coreLibraryDesugaring('com.android.tools:desugar_jdk_libs:1.2.2') testImplementation('junit:junit:4.13.2') androidTestImplementation('androidx.test:runner:1.4.0') androidTestImplementation('androidx.test.espresso:espresso-core:3.4.0') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5311575ab..15d973081 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -35,11 +35,6 @@ - - - - - - - - - - - - - - + ShortCuts.buildShortCuts(context) + } + return false + } override fun delete( uri: Uri, diff --git a/app/src/main/java/io/legado/app/api/ShortCuts.kt b/app/src/main/java/io/legado/app/api/ShortCuts.kt new file mode 100644 index 000000000..6f9ff43e8 --- /dev/null +++ b/app/src/main/java/io/legado/app/api/ShortCuts.kt @@ -0,0 +1,63 @@ +package io.legado.app.api + +import android.content.Context +import android.content.Intent +import androidx.core.content.pm.ShortcutInfoCompat +import androidx.core.content.pm.ShortcutManagerCompat +import androidx.core.graphics.drawable.IconCompat +import io.legado.app.R +import io.legado.app.receiver.SharedReceiverActivity +import io.legado.app.ui.book.read.ReadBookActivity +import io.legado.app.ui.main.MainActivity + +object ShortCuts { + + private inline fun buildIntent(context: Context): Intent { + val intent = Intent(context, T::class.java) + intent.action = Intent.ACTION_VIEW + return intent + } + + private fun buildBookShelfShortCutInfo(context: Context): ShortcutInfoCompat { + val bookShelfIntent = buildIntent(context) + return ShortcutInfoCompat.Builder(context, "bookshelf") + .setShortLabel(context.getString(R.string.bookshelf)) + .setLongLabel(context.getString(R.string.bookshelf)) + .setIcon(IconCompat.createWithResource(context, R.drawable.icon_read_book)) + .setIntent(bookShelfIntent) + .build() + } + + private fun buildReadBookShortCutInfo(context: Context): ShortcutInfoCompat { + val bookShelfIntent = buildIntent(context) + val readBookIntent = buildIntent(context) + return ShortcutInfoCompat.Builder(context, "lastRead") + .setShortLabel(context.getString(R.string.last_read)) + .setLongLabel(context.getString(R.string.last_read)) + .setIcon(IconCompat.createWithResource(context, R.drawable.icon_read_book)) + .setIntents(arrayOf(bookShelfIntent, readBookIntent)) + .build() + } + + private fun buildReadAloudShortCutInfo(context: Context): ShortcutInfoCompat { + val readAloudIntent = buildIntent(context) + readAloudIntent.putExtra("action", "readAloud") + return ShortcutInfoCompat.Builder(context, "readAloud") + .setShortLabel(context.getString(R.string.read_aloud)) + .setLongLabel(context.getString(R.string.read_aloud)) + .setIcon(IconCompat.createWithResource(context, R.drawable.icon_read_book)) + .setIntent(readAloudIntent) + .build() + } + + fun buildShortCuts(context: Context) { + ShortcutManagerCompat.setDynamicShortcuts( + context, listOf( + buildReadBookShortCutInfo(context), + buildReadAloudShortCutInfo(context), + buildBookShelfShortCutInfo(context) + ) + ) + } + +} \ No newline at end of file diff --git a/app/src/main/res/xml/shortcuts.xml b/app/src/main/res/xml/shortcuts.xml deleted file mode 100644 index 2e6e4f6cb..000000000 --- a/app/src/main/res/xml/shortcuts.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/build.gradle b/build.gradle index ca605b366..3648cb30c 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { kotlin_version = '1.7.10' compose_version = '1.2.1' compose_compiler_version = '1.3.0' - agp_version = '7.2.0' + agp_version = '7.3.0' exoplayer_version = '2.18.1' splitties_version = '3.0.0' room_version = '2.4.3' @@ -16,7 +16,6 @@ plugins { id 'com.android.application' version "$agp_version" apply false id 'com.android.library' version "$agp_version" apply false id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false - id "de.timfreiheit.resourceplaceholders" version "0.4" apply false id "de.undercouch.download" version "5.1.0" apply false id "com.google.gms.google-services" version "4.3.10" apply false }