mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -35,11 +35,6 @@
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.shortcuts"
|
||||
android:launchMode="singleTask"
|
||||
android:resource="@xml/shortcuts" />
|
||||
</activity>
|
||||
<!-- 图标1 -->
|
||||
<activity
|
||||
@@ -52,11 +47,6 @@
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.shortcuts"
|
||||
android:launchMode="singleTask"
|
||||
android:resource="@xml/shortcuts" />
|
||||
</activity>
|
||||
<!-- 图标2 -->
|
||||
<activity
|
||||
@@ -69,11 +59,6 @@
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.shortcuts"
|
||||
android:launchMode="singleTask"
|
||||
android:resource="@xml/shortcuts" />
|
||||
</activity>
|
||||
<!-- 图标3 -->
|
||||
<activity
|
||||
@@ -86,11 +71,6 @@
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.shortcuts"
|
||||
android:launchMode="singleTask"
|
||||
android:resource="@xml/shortcuts" />
|
||||
</activity>
|
||||
<!-- 图标4 -->
|
||||
<activity
|
||||
@@ -103,11 +83,6 @@
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.shortcuts"
|
||||
android:launchMode="singleTask"
|
||||
android:resource="@xml/shortcuts" />
|
||||
</activity>
|
||||
<!-- 图标5 -->
|
||||
<activity
|
||||
@@ -120,11 +95,6 @@
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.shortcuts"
|
||||
android:launchMode="singleTask"
|
||||
android:resource="@xml/shortcuts" />
|
||||
</activity>
|
||||
<!-- 图标6 -->
|
||||
<activity
|
||||
@@ -137,11 +107,6 @@
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.shortcuts"
|
||||
android:launchMode="singleTask"
|
||||
android:resource="@xml/shortcuts" />
|
||||
</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(
|
||||
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>
|
||||
Reference in New Issue
Block a user