mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
4adc05efb1
commit
53da8a8907
@ -3,7 +3,6 @@ plugins {
|
|||||||
id 'org.jetbrains.kotlin.android'
|
id 'org.jetbrains.kotlin.android'
|
||||||
id 'kotlin-parcelize'
|
id 'kotlin-parcelize'
|
||||||
id 'kotlin-kapt'
|
id 'kotlin-kapt'
|
||||||
id "de.timfreiheit.resourceplaceholders"
|
|
||||||
//id "com.google.gms.google-services"
|
//id "com.google.gms.google-services"
|
||||||
}
|
}
|
||||||
apply from: 'download.gradle'
|
apply from: 'download.gradle'
|
||||||
@ -125,13 +124,9 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resourcePlaceholders {
|
|
||||||
files = ['xml/shortcuts.xml']
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
//noinspection GradleDependency,GradlePackageUpdate
|
//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')
|
testImplementation('junit:junit:4.13.2')
|
||||||
androidTestImplementation('androidx.test:runner:1.4.0')
|
androidTestImplementation('androidx.test:runner:1.4.0')
|
||||||
androidTestImplementation('androidx.test.espresso:espresso-core:3.4.0')
|
androidTestImplementation('androidx.test.espresso:espresso-core:3.4.0')
|
||||||
|
@ -35,11 +35,6 @@
|
|||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="android.app.shortcuts"
|
|
||||||
android:launchMode="singleTask"
|
|
||||||
android:resource="@xml/shortcuts" />
|
|
||||||
</activity>
|
</activity>
|
||||||
<!-- 图标1 -->
|
<!-- 图标1 -->
|
||||||
<activity
|
<activity
|
||||||
@ -52,11 +47,6 @@
|
|||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="android.app.shortcuts"
|
|
||||||
android:launchMode="singleTask"
|
|
||||||
android:resource="@xml/shortcuts" />
|
|
||||||
</activity>
|
</activity>
|
||||||
<!-- 图标2 -->
|
<!-- 图标2 -->
|
||||||
<activity
|
<activity
|
||||||
@ -69,11 +59,6 @@
|
|||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="android.app.shortcuts"
|
|
||||||
android:launchMode="singleTask"
|
|
||||||
android:resource="@xml/shortcuts" />
|
|
||||||
</activity>
|
</activity>
|
||||||
<!-- 图标3 -->
|
<!-- 图标3 -->
|
||||||
<activity
|
<activity
|
||||||
@ -86,11 +71,6 @@
|
|||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="android.app.shortcuts"
|
|
||||||
android:launchMode="singleTask"
|
|
||||||
android:resource="@xml/shortcuts" />
|
|
||||||
</activity>
|
</activity>
|
||||||
<!-- 图标4 -->
|
<!-- 图标4 -->
|
||||||
<activity
|
<activity
|
||||||
@ -103,11 +83,6 @@
|
|||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="android.app.shortcuts"
|
|
||||||
android:launchMode="singleTask"
|
|
||||||
android:resource="@xml/shortcuts" />
|
|
||||||
</activity>
|
</activity>
|
||||||
<!-- 图标5 -->
|
<!-- 图标5 -->
|
||||||
<activity
|
<activity
|
||||||
@ -120,11 +95,6 @@
|
|||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="android.app.shortcuts"
|
|
||||||
android:launchMode="singleTask"
|
|
||||||
android:resource="@xml/shortcuts" />
|
|
||||||
</activity>
|
</activity>
|
||||||
<!-- 图标6 -->
|
<!-- 图标6 -->
|
||||||
<activity
|
<activity
|
||||||
@ -137,11 +107,6 @@
|
|||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="android.app.shortcuts"
|
|
||||||
android:launchMode="singleTask"
|
|
||||||
android:resource="@xml/shortcuts" />
|
|
||||||
</activity>
|
</activity>
|
||||||
<!-- 主界面 -->
|
<!-- 主界面 -->
|
||||||
<activity
|
<activity
|
||||||
|
@ -49,7 +49,12 @@ class ReaderProvider : ContentProvider() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate() = false
|
override fun onCreate(): Boolean {
|
||||||
|
context?.let { context ->
|
||||||
|
ShortCuts.buildShortCuts(context)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
override fun delete(
|
override fun delete(
|
||||||
uri: Uri,
|
uri: Uri,
|
||||||
|
63
app/src/main/java/io/legado/app/api/ShortCuts.kt
Normal file
63
app/src/main/java/io/legado/app/api/ShortCuts.kt
Normal file
@ -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 <reified T> 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<MainActivity>(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<MainActivity>(context)
|
||||||
|
val readBookIntent = buildIntent<ReadBookActivity>(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<SharedReceiverActivity>(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)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,60 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<shortcuts xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<shortcut
|
|
||||||
android:shortcutId="bookRead"
|
|
||||||
android:enabled="true"
|
|
||||||
android:icon="@drawable/icon_read_book"
|
|
||||||
android:shortcutShortLabel="@string/last_read"
|
|
||||||
android:shortcutLongLabel="@string/last_read"
|
|
||||||
android:shortcutDisabledMessage="@string/last_read"
|
|
||||||
tools:ignore="UnusedAttribute">
|
|
||||||
|
|
||||||
<intent
|
|
||||||
android:action="android.intent.action.VIEW"
|
|
||||||
android:targetPackage="${applicationId}"
|
|
||||||
android:targetClass="io.legado.app.ui.main.MainActivity" />
|
|
||||||
<intent
|
|
||||||
android:action="android.intent.action.VIEW"
|
|
||||||
android:targetPackage="${applicationId}"
|
|
||||||
android:targetClass="io.legado.app.ui.book.read.ReadBookActivity" />
|
|
||||||
<categories android:name="android.shortcut.conversation" />
|
|
||||||
</shortcut>
|
|
||||||
|
|
||||||
<shortcut
|
|
||||||
android:shortcutId="readAloud"
|
|
||||||
android:enabled="true"
|
|
||||||
android:icon="@drawable/icon_read_book"
|
|
||||||
android:shortcutShortLabel="@string/read_aloud"
|
|
||||||
android:shortcutLongLabel="@string/read_aloud"
|
|
||||||
android:shortcutDisabledMessage="@string/read_aloud"
|
|
||||||
tools:ignore="UnusedAttribute">
|
|
||||||
|
|
||||||
<intent
|
|
||||||
android:action="android.intent.action.VIEW"
|
|
||||||
android:targetPackage="${applicationId}"
|
|
||||||
android:targetClass="io.legado.app.receiver.SharedReceiverActivity">
|
|
||||||
<extra
|
|
||||||
android:name="action"
|
|
||||||
android:value="readAloud" />
|
|
||||||
</intent>
|
|
||||||
<categories android:name="android.shortcut.conversation" />
|
|
||||||
</shortcut>
|
|
||||||
|
|
||||||
<shortcut
|
|
||||||
android:shortcutId="bookshelf"
|
|
||||||
android:enabled="true"
|
|
||||||
android:icon="@drawable/icon_read_book"
|
|
||||||
android:shortcutShortLabel="@string/bookshelf"
|
|
||||||
android:shortcutLongLabel="@string/bookshelf"
|
|
||||||
android:shortcutDisabledMessage="@string/bookshelf"
|
|
||||||
tools:ignore="UnusedAttribute">
|
|
||||||
|
|
||||||
<intent
|
|
||||||
android:action="android.intent.action.VIEW"
|
|
||||||
android:targetPackage="${applicationId}"
|
|
||||||
android:targetClass="io.legado.app.ui.main.MainActivity" />
|
|
||||||
<categories android:name="android.shortcut.conversation" />
|
|
||||||
</shortcut>
|
|
||||||
|
|
||||||
</shortcuts>
|
|
@ -5,7 +5,7 @@ buildscript {
|
|||||||
kotlin_version = '1.7.10'
|
kotlin_version = '1.7.10'
|
||||||
compose_version = '1.2.1'
|
compose_version = '1.2.1'
|
||||||
compose_compiler_version = '1.3.0'
|
compose_compiler_version = '1.3.0'
|
||||||
agp_version = '7.2.0'
|
agp_version = '7.3.0'
|
||||||
exoplayer_version = '2.18.1'
|
exoplayer_version = '2.18.1'
|
||||||
splitties_version = '3.0.0'
|
splitties_version = '3.0.0'
|
||||||
room_version = '2.4.3'
|
room_version = '2.4.3'
|
||||||
@ -16,7 +16,6 @@ plugins {
|
|||||||
id 'com.android.application' version "$agp_version" apply false
|
id 'com.android.application' version "$agp_version" apply false
|
||||||
id 'com.android.library' 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 '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 "de.undercouch.download" version "5.1.0" apply false
|
||||||
id "com.google.gms.google-services" version "4.3.10" apply false
|
id "com.google.gms.google-services" version "4.3.10" apply false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user