forked from upstream-mirrors/quik
#848 - App shortcuts support
This commit is contained in:
@@ -50,6 +50,9 @@
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.app.shortcuts"
|
||||
android:resource="@xml/shortcuts" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".feature.compose.ComposeActivity"
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.common.util
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.ShortcutInfo
|
||||
import android.content.pm.ShortcutManager
|
||||
import android.graphics.drawable.Icon
|
||||
import android.os.Build
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.feature.compose.ComposeActivity
|
||||
import com.moez.QKSMS.model.Conversation
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
import com.moez.QKSMS.repository.MessageRepository
|
||||
import com.moez.QKSMS.util.GlideApp
|
||||
import com.moez.QKSMS.util.tryOrNull
|
||||
import me.leolin.shortcutbadger.ShortcutBadger
|
||||
import javax.inject.Inject
|
||||
|
||||
class ShortcutManagerImpl @Inject constructor(
|
||||
private val context: Context,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val messageRepo: MessageRepository
|
||||
) : com.moez.QKSMS.manager.ShortcutManager {
|
||||
|
||||
override fun updateBadge() {
|
||||
val count = messageRepo.getUnreadCount().toInt()
|
||||
ShortcutBadger.applyCount(context, count)
|
||||
}
|
||||
|
||||
override fun updateShortcuts() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
val shortcutManager = context.getSystemService(Context.SHORTCUT_SERVICE) as ShortcutManager
|
||||
if (shortcutManager.isRateLimitingActive) return
|
||||
|
||||
shortcutManager.dynamicShortcuts = conversationRepo.getTopConversations()
|
||||
.take(shortcutManager.maxShortcutCountPerActivity - shortcutManager.manifestShortcuts.size)
|
||||
.map { conversation -> createShortcutForConversation(conversation, shortcutManager) }
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(25)
|
||||
private fun createShortcutForConversation(conversation: Conversation, shortcutManager: ShortcutManager): ShortcutInfo {
|
||||
val icon = when {
|
||||
conversation.recipients.size == 1 -> {
|
||||
val address = conversation.recipients.first()!!.address
|
||||
val request = GlideApp.with(context)
|
||||
.asBitmap()
|
||||
.circleCrop()
|
||||
.load(PhoneNumberUtils.stripSeparators(address))
|
||||
.submit(shortcutManager.iconMaxWidth, shortcutManager.iconMaxHeight)
|
||||
val bitmap = tryOrNull(false) { request.get() }
|
||||
|
||||
if (bitmap != null) Icon.createWithBitmap(bitmap)
|
||||
else Icon.createWithResource(context, R.mipmap.ic_shortcut_person)
|
||||
}
|
||||
|
||||
else -> Icon.createWithResource(context, R.mipmap.ic_shortcut_people)
|
||||
}
|
||||
|
||||
val intent = Intent(context, ComposeActivity::class.java)
|
||||
.setAction(Intent.ACTION_VIEW)
|
||||
.putExtra("threadId", conversation.id)
|
||||
|
||||
return ShortcutInfo.Builder(context, "${conversation.id}")
|
||||
.setShortLabel(conversation.getTitle())
|
||||
.setLongLabel(conversation.getTitle())
|
||||
.setIcon(icon)
|
||||
.setIntent(intent)
|
||||
.build()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import androidx.lifecycle.ViewModelProvider
|
||||
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||
import com.moez.QKSMS.common.ViewModelFactory
|
||||
import com.moez.QKSMS.common.util.NotificationManagerImpl
|
||||
import com.moez.QKSMS.common.util.ShortcutManagerImpl
|
||||
import com.moez.QKSMS.feature.conversationinfo.injection.ConversationInfoComponent
|
||||
import com.moez.QKSMS.feature.themepicker.injection.ThemePickerComponent
|
||||
import com.moez.QKSMS.listener.ContactAddedListener
|
||||
@@ -42,6 +43,7 @@ import com.moez.QKSMS.manager.NotificationManager
|
||||
import com.moez.QKSMS.manager.PermissionManager
|
||||
import com.moez.QKSMS.manager.PermissionManagerImpl
|
||||
import com.moez.QKSMS.manager.RatingManager
|
||||
import com.moez.QKSMS.manager.ShortcutManager
|
||||
import com.moez.QKSMS.manager.WidgetManager
|
||||
import com.moez.QKSMS.manager.WidgetManagerImpl
|
||||
import com.moez.QKSMS.mapper.CursorToContact
|
||||
@@ -130,6 +132,9 @@ class AppModule(private var application: Application) {
|
||||
@Provides
|
||||
fun provideRatingManager(manager: RatingManagerImpl): RatingManager = manager
|
||||
|
||||
@Provides
|
||||
fun provideShortcutManager(manager: ShortcutManagerImpl): ShortcutManager = manager
|
||||
|
||||
@Provides
|
||||
fun provideWidgetManager(manager: WidgetManagerImpl): WidgetManager = manager
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 928 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
@@ -20,6 +20,10 @@
|
||||
|
||||
<string name="app_name" translatable="false">QKSMS</string>
|
||||
|
||||
<string name="shortcut_compose_long_label">New conversation</string>
|
||||
<string name="shortcut_compose_short_label">Compose</string>
|
||||
<string name="shortcut_compose_disabled_message">Shortcut disabled</string>
|
||||
|
||||
<string name="title_archived">Archived</string>
|
||||
<string name="title_settings">Settings</string>
|
||||
<string name="title_notification_prefs">Notifications</string>
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
~
|
||||
~ This file is part of QKSMS.
|
||||
~
|
||||
~ QKSMS is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ QKSMS is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<shortcut
|
||||
android:enabled="true"
|
||||
android:icon="@mipmap/ic_shortcut_compose"
|
||||
android:shortcutDisabledMessage="@string/shortcut_compose_disabled_message"
|
||||
android:shortcutId="compose"
|
||||
android:shortcutLongLabel="@string/shortcut_compose_long_label"
|
||||
android:shortcutShortLabel="@string/shortcut_compose_short_label">
|
||||
|
||||
<intent
|
||||
android:action="com.moez.QKSMS.START"
|
||||
android:targetClass="com.moez.QKSMS.feature.compose.ComposeActivity"
|
||||
android:targetPackage="com.moez.QKSMS" />
|
||||
|
||||
<categories android:name="android.shortcut.conversation" />
|
||||
|
||||
</shortcut>
|
||||
|
||||
</shortcuts>
|
||||
Reference in New Issue
Block a user