pull/2337/head
			
			
		
		
							parent
							
								
									4adc05efb1
								
							
						
					
					
						commit
						53da8a8907
					
				| @ -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> | ||||
					Loading…
					
					
				
		Reference in new issue