Skip to content

Commit

Permalink
feat: add ability to open app information from Android Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-w committed Nov 22, 2024
1 parent dc906d2 commit 7acc9c3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
android:exported="true"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">

<intent-filter>
<action android:name="android.intent.action.SHOW_APP_INFO" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
43 changes: 23 additions & 20 deletions app/src/main/kotlin/com/looker/droidify/ScreenActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.looker.droidify

import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.Parcelable
import android.view.ViewGroup
Expand Down Expand Up @@ -63,9 +64,7 @@ abstract class ScreenActivity : AppCompatActivity() {

@Parcelize
private class FragmentStackItem(
val className: String,
val arguments: Bundle?,
val savedState: Fragment.SavedState?
val className: String, val arguments: Bundle?, val savedState: Fragment.SavedState?
) : Parcelable

lateinit var cursorOwner: CursorOwner
Expand All @@ -88,28 +87,23 @@ abstract class ScreenActivity : AppCompatActivity() {
}

private fun collectChange() {
val hiltEntryPoint =
EntryPointAccessors.fromApplication(
this,
CustomUserRepositoryInjector::class.java
)
val newSettings = hiltEntryPoint.settingsRepository()
.get { theme to dynamicTheme }
val hiltEntryPoint = EntryPointAccessors.fromApplication(
this, CustomUserRepositoryInjector::class.java
)
val newSettings = hiltEntryPoint.settingsRepository().get { theme to dynamicTheme }
runBlocking {
val theme = newSettings.first()
setTheme(
resources.configuration.getThemeRes(
theme = theme.first,
dynamicTheme = theme.second
theme = theme.first, dynamicTheme = theme.second
)
)
}
lifecycleScope.launch {
newSettings.drop(1).collect { themeAndDynamic ->
setTheme(
resources.configuration.getThemeRes(
theme = themeAndDynamic.first,
dynamicTheme = themeAndDynamic.second
theme = themeAndDynamic.first, dynamicTheme = themeAndDynamic.second
)
)
recreate()
Expand All @@ -122,10 +116,8 @@ abstract class ScreenActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
val rootView = FrameLayout(this).apply { id = R.id.main_content }
addContentView(
rootView,
ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
rootView, ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT
)
)

Expand All @@ -141,8 +133,8 @@ abstract class ScreenActivity : AppCompatActivity() {
add(cursorOwner, CursorOwner::class.java.name)
}
} else {
cursorOwner = supportFragmentManager
.findFragmentByTag(CursorOwner::class.java.name) as CursorOwner
cursorOwner =
supportFragmentManager.findFragmentByTag(CursorOwner::class.java.name) as CursorOwner
}

savedInstanceState?.getParcelableArrayList<FragmentStackItem>(STATE_FRAGMENT_STACK)
Expand Down Expand Up @@ -285,6 +277,17 @@ abstract class ScreenActivity : AppCompatActivity() {
null -> {}
}
}

Intent.ACTION_SHOW_APP_INFO -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val packageName = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME)

if (packageName != null && currentFragment !is AppDetailFragment) {
navigateProduct(packageName)
}
}

}
}
}

Expand Down

0 comments on commit 7acc9c3

Please sign in to comment.