-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the dynamic app shortcuts based on the app shorting order
Signed-off-by: Keval Patel <[email protected]>
- Loading branch information
1 parent
001c854
commit da4bf70
Showing
19 changed files
with
122 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
app/src/main/java/com/kevalpatel2106/yip/utils/AppShortcutHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.kevalpatel2106.yip.utils | ||
|
||
import android.app.Application | ||
import android.content.Intent | ||
import androidx.core.content.pm.ShortcutInfoCompat | ||
import androidx.core.content.pm.ShortcutManagerCompat | ||
import androidx.core.graphics.drawable.IconCompat | ||
import com.kevalpatel2106.yip.R | ||
import com.kevalpatel2106.yip.entity.Progress | ||
import javax.inject.Inject | ||
|
||
class AppShortcutHelper @Inject internal constructor( | ||
private val application: Application | ||
) { | ||
|
||
internal fun requestPinShortcut(title: String, launchIntent: Intent) { | ||
if (!ShortcutManagerCompat.isRequestPinShortcutSupported(application)) return | ||
|
||
val shortcutInfo = ShortcutInfoCompat.Builder( | ||
application, | ||
application.getString(R.string.progress_pin_shortcut_id) | ||
).setIcon(IconCompat.createWithResource(application, R.drawable.progress_app_shortcut)) | ||
.setShortLabel(title) | ||
.setIntent(launchIntent) | ||
.setAlwaysBadged() | ||
.build() | ||
|
||
ShortcutManagerCompat.requestPinShortcut( | ||
application, | ||
shortcutInfo, | ||
null | ||
) | ||
} | ||
|
||
internal fun updateDynamicShortcuts(progresses: List<Progress>): Boolean { | ||
ShortcutManagerCompat.removeAllDynamicShortcuts(application) | ||
if (progresses.isEmpty()) return true | ||
|
||
val icon = IconCompat.createWithResource(application, R.drawable.progress_app_shortcut) | ||
val shortcuts = progresses.subList( | ||
0, | ||
ShortcutManagerCompat.getMaxShortcutCountPerActivity(application) - NUMBER_OF_STATIC_APP_SHORTCUT | ||
).map { progress -> | ||
ShortcutInfoCompat.Builder( | ||
application, | ||
application.getString(R.string.progress_app_shortcut_id, progress.id) | ||
).setIcon(icon) | ||
.setShortLabel(progress.title) | ||
.setIntent(AppLaunchHelper.launchWithProgressDetail(application, progress.id)) | ||
.build() | ||
} | ||
return ShortcutManagerCompat.addDynamicShortcuts(application, shortcuts) | ||
} | ||
|
||
companion object { | ||
private const val NUMBER_OF_STATIC_APP_SHORTCUT = 1 | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/com/kevalpatel2106/yip/utils/LocaleChangedReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.kevalpatel2106.yip.utils | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import com.kevalpatel2106.yip.notifications.ProgressNotificationReceiver | ||
import com.kevalpatel2106.yip.repo.providers.AlarmProvider | ||
import dagger.android.AndroidInjection | ||
import javax.inject.Inject | ||
|
||
internal class LocaleChangedReceiver : BroadcastReceiver() { | ||
|
||
@Inject | ||
internal lateinit var alarmProvider: AlarmProvider | ||
|
||
override fun onReceive(context: Context?, intent: Intent?) { | ||
if (intent?.action != Intent.ACTION_LOCALE_CHANGED || context == null) return | ||
AndroidInjection.inject(this, context) | ||
alarmProvider.updateAlarms(ProgressNotificationReceiver::class.java) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...m/kevalpatel2106/yip/utils/ColorPicker.kt → ...m/kevalpatel2106/yip/views/ColorPicker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters