Skip to content

Commit

Permalink
Apply the default theme to activities when needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
pandulapeter committed Sep 8, 2024
1 parent 71623e9 commit cd22a64
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 10 deletions.
4 changes: 3 additions & 1 deletion internal-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
<uses-permission android:name="android.permission.VIBRATE" />
Expand All @@ -11,12 +11,14 @@
android:name=".view.gallery.GalleryActivity"
android:exported="false"
android:launchMode="singleTop"
android:theme="@style/BeagleDefaultTheme"
android:windowSoftInputMode="adjustResize" />

<activity
android:name=".view.bugReport.BugReportActivity"
android:exported="false"
android:launchMode="singleTop"
android:theme="@style/BeagleDefaultTheme"
android:windowSoftInputMode="adjustResize" />

<service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ class BeagleImplementation(val uiManager: UiManagerContract) : BeagleContract {
BeagleCore.implementation = this
}

internal fun invalidateThemeOverride() {
if (appearance.themeResourceId != null) {
appearance = appearance.copy(
themeResourceId = null
)
}
}

override fun initialize(
application: Application,
appearance: Appearance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ internal class BugReportManager {

fun openBugReportingScreen() {
BeagleCore.implementation.currentActivity?.run {
startActivity(BugReportActivity.newIntent(this))
startActivity(
BugReportActivity.newIntent(
context = this,
themeResourceId = BeagleCore.implementation.appearance.themeResourceId
)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ private fun Context.toMaterialContext(): Context {
return if (isMaterialTheme) {
this
} else {
ContextThemeWrapper(this, R.style.BeagleDefaultTheme)
ContextThemeWrapper(this, R.style.BeagleDefaultTheme).also {
BeagleCore.implementation.invalidateThemeOverride()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class BugReportActivity : AppCompatActivity() {
}
}
}
private val themeResourceId by lazy {
intent.getIntExtra(THEME_RESOURCE_ID, -1)
}

@Suppress("UNCHECKED_CAST")
private val viewModel by lazy {
Expand All @@ -79,7 +82,9 @@ class BugReportActivity : AppCompatActivity() {
}

override fun onCreate(savedInstanceState: Bundle?) {
BeagleCore.implementation.appearance.themeResourceId?.let { setTheme(it) }
if (themeResourceId != -1) {
setTheme(themeResourceId)
}
super.onCreate(savedInstanceState)
binding = BeagleActivityBugReportBinding.inflate(layoutInflater)
setContentView(binding.root)
Expand Down Expand Up @@ -219,13 +224,16 @@ class BugReportActivity : AppCompatActivity() {
companion object {
private const val CRASH_LOG_ENTRY_TO_SHOW = "crashLogEntry"
private const val RESTORE_MODEL = "restoreModel"
private const val THEME_RESOURCE_ID = "themeResourceId"

fun newIntent(
context: Context,
crashLogEntryToShowJson: String = "",
restoreModelJson: String = ""
restoreModelJson: String = "",
themeResourceId: Int? = null,
) = Intent(context, BugReportActivity::class.java)
.putExtra(CRASH_LOG_ENTRY_TO_SHOW, crashLogEntryToShowJson)
.putExtra(RESTORE_MODEL, restoreModelJson)
.putExtra(THEME_RESOURCE_ID, themeResourceId)
}
}
4 changes: 1 addition & 3 deletions internal-core/src/main/res/layout/beagle_view_media.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
android:id="@+id/beagle_check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="-8dp"
android:layout_marginEnd="-12dp" />
android:layout_gravity="end" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/beagle_text_view"
Expand Down
6 changes: 6 additions & 0 deletions internal-core/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="BeagleDefaultTheme" parent="BeagleDefaultThemeBase" />

</resources>
7 changes: 6 additions & 1 deletion internal-core/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="BeagleDefaultTheme" parent="Theme.Material3.DayNight.NoActionBar">
<style name="BeagleDefaultThemeBase" parent="Theme.Material3.DayNight.NoActionBar">
<item name="colorPrimary">@color/beagle_accent</item>
<item name="colorOnPrimary">@color/beagle_on_accent</item>
<item name="colorControlActivated">@color/beagle_accent</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>

<style name="BeagleDefaultTheme" parent="BeagleDefaultThemeBase">
<item name="android:windowLightStatusBar">true</item>
</style>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ internal class ExceptionHandler private constructor(
networkLogs = networkLogsToRestore,
lifecycleLogs = lifecycleLogsToRestore
)
)
),
themeResourceId = BeagleCore.implementation.appearance.themeResourceId
).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
)
tryToCallDefaultExceptionHandler(thread, exception)
Expand Down

0 comments on commit cd22a64

Please sign in to comment.