Skip to content

Commit

Permalink
Merge pull request #106 from infinum/develop
Browse files Browse the repository at this point in the history
* Update Kotlin to 1.7.0.
  • Loading branch information
bojankoma authored Jun 10, 2022
2 parents 6bda99c + acf30b6 commit 49243e3
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 17 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

## Version 5.4.7

_2022-06-10_

* Update Kotlin to 1.7.0.
* Update dependencies to stable version.
* Implement dynamic shortcut.

## Version 5.4.6

_2022-05-11_
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ Then add the following dependencies in your app `build.gradle` or `build.gradle.

**Groovy**
```groovy
debugImplementation "com.infinum.dbinspector:dbinspector:5.4.6"
releaseImplementation "com.infinum.dbinspector:dbinspector-no-op:5.4.6"
debugImplementation "com.infinum.dbinspector:dbinspector:5.4.7"
releaseImplementation "com.infinum.dbinspector:dbinspector-no-op:5.4.7"
```
**KotlinDSL**
```kotlin
debugImplementation("com.infinum.dbinspector:dbinspector:5.4.6")
releaseImplementation("com.infinum.dbinspector:dbinspector-no-op:5.4.6")
debugImplementation("com.infinum.dbinspector:dbinspector:5.4.7")
releaseImplementation("com.infinum.dbinspector:dbinspector-no-op:5.4.7")
```

### Usage
Expand Down
4 changes: 2 additions & 2 deletions config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ext {
]
releaseConfig = [
"group" : "com.infinum.dbinspector",
"version" : "5.4.6",
"versionCode": 5 * 100 * 100 + 4 * 100 + 6
"version" : "5.4.7",
"versionCode": 5 * 100 * 100 + 4 * 100 + 7
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ internal class DbInspectorInitializer : Initializer<Class<DbInspectorInitializer

Presentation.init(context)

DbInspectorShortcutManager.init(context)

return DbInspectorInitializer::class.java
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.infinum.dbinspector.ui

import android.annotation.SuppressLint
import android.content.ComponentName
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 com.infinum.dbinspector.R
import com.infinum.dbinspector.data.sources.memory.logger.AndroidLogger
import com.infinum.dbinspector.ui.databases.DatabasesActivity

@SuppressLint("StaticFieldLeak")
internal object DbInspectorShortcutManager {

private const val ACTIVITY_INFO_NAME = "com.infinum.dbinspector.ui.databases.DatabasesActivity"

private const val LAUNCHER_DYNAMIC_SHORTCUT_ID = "com.infinum.dbinspector.ui.dynamic_shortcut_launcher"

fun init(context: Context) = addDynamicShortcut(context)

@Suppress("LongMethod", "NestedBlockDepth")
private fun addDynamicShortcut(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
val shortcutManager: ShortcutManager = context.getSystemService(ShortcutManager::class.java)
val dynamicShortcuts: MutableList<ShortcutInfo> = shortcutManager.dynamicShortcuts

dynamicShortcuts
.none { shortcut -> shortcut.id == LAUNCHER_DYNAMIC_SHORTCUT_ID }
.takeIf { it }
?.let {
context.packageManager.queryIntentActivities(
Intent(Intent.ACTION_MAIN, null)
.apply {
addCategory(Intent.CATEGORY_LAUNCHER)
setPackage(context.packageName)
},
0
)
.filter { it.activityInfo.name != ACTIVITY_INFO_NAME }
.takeIf { it.isNotEmpty() }
?.let { activities ->
val dbInspectorActivity = activities.first().activityInfo

val componentName = ComponentName(dbInspectorActivity.packageName, dbInspectorActivity.name)

dynamicShortcuts.let {
it.count { shortcutInfo ->
shortcutInfo.activity == componentName
} + shortcutManager.manifestShortcuts.count { shortcutInfo ->
shortcutInfo.activity == componentName
}
}
.takeIf { it < shortcutManager.maxShortcutCountPerActivity }
?.let {
Presentation.setLogger(AndroidLogger())
val intent = with(Presentation.applicationContext()) {
Intent(
this,
DatabasesActivity::class.java
).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
action = "Dummy action because Android"
}
}

ShortcutInfo.Builder(context, LAUNCHER_DYNAMIC_SHORTCUT_ID)
.setLongLabel(context.getString(R.string.dbinspector_launcher_name))
.setShortLabel(context.getString(R.string.dbinspector_launcher_name))
.setActivity(componentName)
.setIcon(Icon.createWithResource(context, R.mipmap.dbinspector_launcher))
.setIntent(intent)
.build()
}
}
?.let { shortcut ->
try {
shortcutManager.addDynamicShortcuts(listOf(shortcut))
} catch (ignored: Throwable) {
Unit
}
}
}
} else {
Unit
}
}
}
22 changes: 11 additions & 11 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[versions]
dbinspector = "5.4.6"
gradle = "7.2.0"
kotlin = "1.6.21"
coroutines = "1.6.1"
core = "1.7.0"
appcompat = "1.4.1"
dbinspector = "5.4.7"
gradle = "7.2.1"
kotlin = "1.7.0"
coroutines = "1.6.2"
core = "1.8.0"
appcompat = "1.4.2"
activity = "1.4.0"
fragment = "1.4.1"
lifecycle = "2.4.1"
Expand All @@ -15,16 +15,16 @@ startup = "1.1.1"
swiperefresh = "1.1.0"
datastore = "1.0.0"
dynamicanimation = "1.0.0"
design = "1.6.0"
protobuf-core = "3.20.1"
design = "1.6.1"
protobuf-core = "3.21.1"
protobuf-plugin = "0.8.18"
koin = "3.1.6"
koin = "3.2.0"
detekt = "1.20.0"
ktlintplugin = "10.2.1"
ktlintplugin = "10.3.0"
ktlint = "0.45.2"
cpd = "3.2"
dokka = "1.6.21"
kover = "0.5.0"
kover = "0.5.1"
jacoco = "0.8.8"
intellij = "1.0.647"
junit5 = "5.8.2"
Expand Down

0 comments on commit 49243e3

Please sign in to comment.