Skip to content

Commit acf30b6

Browse files
author
Bojan
committed
* Update Kotlin to 1.7.0.
* Update dependencies to stable version. * Implement dynamic shortcut.
1 parent 57038b8 commit acf30b6

File tree

6 files changed

+117
-17
lines changed

6 files changed

+117
-17
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog
22
=========
33

4+
## Version 5.4.7
5+
6+
_2022-06-10_
7+
8+
* Update Kotlin to 1.7.0.
9+
* Update dependencies to stable version.
10+
* Implement dynamic shortcut.
11+
412
## Version 5.4.6
513

614
_2022-05-11_

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ Then add the following dependencies in your app `build.gradle` or `build.gradle.
4444

4545
**Groovy**
4646
```groovy
47-
debugImplementation "com.infinum.dbinspector:dbinspector:5.4.6"
48-
releaseImplementation "com.infinum.dbinspector:dbinspector-no-op:5.4.6"
47+
debugImplementation "com.infinum.dbinspector:dbinspector:5.4.7"
48+
releaseImplementation "com.infinum.dbinspector:dbinspector-no-op:5.4.7"
4949
```
5050
**KotlinDSL**
5151
```kotlin
52-
debugImplementation("com.infinum.dbinspector:dbinspector:5.4.6")
53-
releaseImplementation("com.infinum.dbinspector:dbinspector-no-op:5.4.6")
52+
debugImplementation("com.infinum.dbinspector:dbinspector:5.4.7")
53+
releaseImplementation("com.infinum.dbinspector:dbinspector-no-op:5.4.7")
5454
```
5555

5656
### Usage

config.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ext {
77
]
88
releaseConfig = [
99
"group" : "com.infinum.dbinspector",
10-
"version" : "5.4.6",
11-
"versionCode": 5 * 100 * 100 + 4 * 100 + 6
10+
"version" : "5.4.7",
11+
"versionCode": 5 * 100 * 100 + 4 * 100 + 7
1212
]
1313
}

dbinspector/src/main/kotlin/com/infinum/dbinspector/ui/DbInspectorInitializer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ internal class DbInspectorInitializer : Initializer<Class<DbInspectorInitializer
1212

1313
Presentation.init(context)
1414

15+
DbInspectorShortcutManager.init(context)
16+
1517
return DbInspectorInitializer::class.java
1618
}
1719

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package com.infinum.dbinspector.ui
2+
3+
import android.annotation.SuppressLint
4+
import android.content.ComponentName
5+
import android.content.Context
6+
import android.content.Intent
7+
import android.content.pm.ShortcutInfo
8+
import android.content.pm.ShortcutManager
9+
import android.graphics.drawable.Icon
10+
import android.os.Build
11+
import com.infinum.dbinspector.R
12+
import com.infinum.dbinspector.data.sources.memory.logger.AndroidLogger
13+
import com.infinum.dbinspector.ui.databases.DatabasesActivity
14+
15+
@SuppressLint("StaticFieldLeak")
16+
internal object DbInspectorShortcutManager {
17+
18+
private const val ACTIVITY_INFO_NAME = "com.infinum.dbinspector.ui.databases.DatabasesActivity"
19+
20+
private const val LAUNCHER_DYNAMIC_SHORTCUT_ID = "com.infinum.dbinspector.ui.dynamic_shortcut_launcher"
21+
22+
fun init(context: Context) = addDynamicShortcut(context)
23+
24+
@Suppress("LongMethod", "NestedBlockDepth")
25+
private fun addDynamicShortcut(context: Context) {
26+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
27+
val shortcutManager: ShortcutManager = context.getSystemService(ShortcutManager::class.java)
28+
val dynamicShortcuts: MutableList<ShortcutInfo> = shortcutManager.dynamicShortcuts
29+
30+
dynamicShortcuts
31+
.none { shortcut -> shortcut.id == LAUNCHER_DYNAMIC_SHORTCUT_ID }
32+
.takeIf { it }
33+
?.let {
34+
context.packageManager.queryIntentActivities(
35+
Intent(Intent.ACTION_MAIN, null)
36+
.apply {
37+
addCategory(Intent.CATEGORY_LAUNCHER)
38+
setPackage(context.packageName)
39+
},
40+
0
41+
)
42+
.filter { it.activityInfo.name != ACTIVITY_INFO_NAME }
43+
.takeIf { it.isNotEmpty() }
44+
?.let { activities ->
45+
val dbInspectorActivity = activities.first().activityInfo
46+
47+
val componentName = ComponentName(dbInspectorActivity.packageName, dbInspectorActivity.name)
48+
49+
dynamicShortcuts.let {
50+
it.count { shortcutInfo ->
51+
shortcutInfo.activity == componentName
52+
} + shortcutManager.manifestShortcuts.count { shortcutInfo ->
53+
shortcutInfo.activity == componentName
54+
}
55+
}
56+
.takeIf { it < shortcutManager.maxShortcutCountPerActivity }
57+
?.let {
58+
Presentation.setLogger(AndroidLogger())
59+
val intent = with(Presentation.applicationContext()) {
60+
Intent(
61+
this,
62+
DatabasesActivity::class.java
63+
).apply {
64+
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
65+
action = "Dummy action because Android"
66+
}
67+
}
68+
69+
ShortcutInfo.Builder(context, LAUNCHER_DYNAMIC_SHORTCUT_ID)
70+
.setLongLabel(context.getString(R.string.dbinspector_launcher_name))
71+
.setShortLabel(context.getString(R.string.dbinspector_launcher_name))
72+
.setActivity(componentName)
73+
.setIcon(Icon.createWithResource(context, R.mipmap.dbinspector_launcher))
74+
.setIntent(intent)
75+
.build()
76+
}
77+
}
78+
?.let { shortcut ->
79+
try {
80+
shortcutManager.addDynamicShortcuts(listOf(shortcut))
81+
} catch (ignored: Throwable) {
82+
Unit
83+
}
84+
}
85+
}
86+
} else {
87+
Unit
88+
}
89+
}
90+
}

gradle/libs.versions.toml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[versions]
2-
dbinspector = "5.4.6"
3-
gradle = "7.2.0"
4-
kotlin = "1.6.21"
5-
coroutines = "1.6.1"
6-
core = "1.7.0"
7-
appcompat = "1.4.1"
2+
dbinspector = "5.4.7"
3+
gradle = "7.2.1"
4+
kotlin = "1.7.0"
5+
coroutines = "1.6.2"
6+
core = "1.8.0"
7+
appcompat = "1.4.2"
88
activity = "1.4.0"
99
fragment = "1.4.1"
1010
lifecycle = "2.4.1"
@@ -15,16 +15,16 @@ startup = "1.1.1"
1515
swiperefresh = "1.1.0"
1616
datastore = "1.0.0"
1717
dynamicanimation = "1.0.0"
18-
design = "1.6.0"
19-
protobuf-core = "3.20.1"
18+
design = "1.6.1"
19+
protobuf-core = "3.21.1"
2020
protobuf-plugin = "0.8.18"
21-
koin = "3.1.6"
21+
koin = "3.2.0"
2222
detekt = "1.20.0"
23-
ktlintplugin = "10.2.1"
23+
ktlintplugin = "10.3.0"
2424
ktlint = "0.45.2"
2525
cpd = "3.2"
2626
dokka = "1.6.21"
27-
kover = "0.5.0"
27+
kover = "0.5.1"
2828
jacoco = "0.8.8"
2929
intellij = "1.0.647"
3030
junit5 = "5.8.2"

0 commit comments

Comments
 (0)