Add "System theme" option to widgets
MODIFY
app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetConfigureActivity.kt
app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetConfigureActivity.kt
@@ -4,6 +4,9 @@ import android.appwidget.AppWidgetManager.ACTION_APPWIDGET_UPDATE
import android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_ID
import android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_IDS
import android.content.Intent
+import android.content.res.Configuration
+import android.content.res.Configuration.UI_MODE_NIGHT_YES
+import android.os.Build
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
@@ -13,6 +16,7 @@ import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import io.github.wulkanowy.R
import io.github.wulkanowy.ui.base.BaseActivity
import io.github.wulkanowy.ui.modules.login.LoginActivity
+import io.github.wulkanowy.utils.AppInfo
import io.github.wulkanowy.utils.setOnItemClickListener
import kotlinx.android.synthetic.main.activity_widget_configure.*
import javax.inject.Inject
@@ -26,6 +30,9 @@ class LuckyNumberWidgetConfigureActivity : BaseActivity<LuckyNumberWidgetConfigu
@Inject
override lateinit var presenter: LuckyNumberWidgetConfigurePresenter
+ @Inject
+ lateinit var appInfo: AppInfo
+
private var dialog: AlertDialog? = null
override fun onCreate(savedInstanceState: Bundle?) {
@@ -48,16 +55,18 @@ class LuckyNumberWidgetConfigureActivity : BaseActivity<LuckyNumberWidgetConfigu
}
override fun showThemeDialog() {
- val items = arrayOf(
+ var items = arrayOf(
getString(R.string.widget_timetable_theme_light),
getString(R.string.widget_timetable_theme_dark)
)
+ if (appInfo.versionCode >= Build.VERSION_CODES.Q) items+=(getString(R.string.widget_timetable_theme_system))
dialog = AlertDialog.Builder(this, R.style.WulkanowyTheme_WidgetAccountSwitcher)
.setTitle(R.string.widget_timetable_theme_title)
.setOnDismissListener { presenter.onDismissThemeView() }
.setSingleChoiceItems(items, -1) { _, which ->
- presenter.onThemeSelect(which)
+ val isDarkMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == UI_MODE_NIGHT_YES
+ presenter.onThemeSelect(if (isDarkMode && which == 2 || which == 1) 1 else 0)
}
.show()
}

MODIFY
app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetConfigureActivity.kt
app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetConfigureActivity.kt
@@ -4,6 +4,9 @@ import android.appwidget.AppWidgetManager.ACTION_APPWIDGET_UPDATE
import android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_ID
import android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_IDS
import android.content.Intent
+import android.content.res.Configuration
+import android.content.res.Configuration.UI_MODE_NIGHT_YES
+import android.os.Build
import android.os.Bundle
import android.widget.Toast
import android.widget.Toast.LENGTH_LONG
@@ -15,6 +18,7 @@ import io.github.wulkanowy.R
import io.github.wulkanowy.ui.base.BaseActivity
import io.github.wulkanowy.ui.modules.login.LoginActivity
import io.github.wulkanowy.ui.modules.timetablewidget.TimetableWidgetProvider.Companion.EXTRA_FROM_PROVIDER
+import io.github.wulkanowy.utils.AppInfo
import io.github.wulkanowy.utils.setOnItemClickListener
import kotlinx.android.synthetic.main.activity_widget_configure.*
import javax.inject.Inject
@@ -28,6 +32,9 @@ class TimetableWidgetConfigureActivity : BaseActivity<TimetableWidgetConfigurePr
@Inject
override lateinit var presenter: TimetableWidgetConfigurePresenter
+ @Inject
+ lateinit var appInfo: AppInfo
+
private var dialog: AlertDialog? = null
override fun onCreate(savedInstanceState: Bundle?) {
@@ -50,16 +57,18 @@ class TimetableWidgetConfigureActivity : BaseActivity<TimetableWidgetConfigurePr
}
override fun showThemeDialog() {
- val items = arrayOf(
+ var items = arrayOf(
getString(R.string.widget_timetable_theme_light),
getString(R.string.widget_timetable_theme_dark)
)
+ if (appInfo.versionCode >= Build.VERSION_CODES.Q) items += getString(R.string.widget_timetable_theme_system)
dialog = AlertDialog.Builder(this, R.style.WulkanowyTheme_WidgetAccountSwitcher)
.setTitle(R.string.widget_timetable_theme_title)
.setOnDismissListener { presenter.onDismissThemeView() }
.setSingleChoiceItems(items, -1) { _, which ->
- presenter.onThemeSelect(which)
+ val isDarkMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == UI_MODE_NIGHT_YES
+ presenter.onThemeSelect(if (isDarkMode && which == 2 || which == 1) 1 else 0)
}
.show()
}

MODIFY
app/src/main/res/values-pl/strings.xml
app/src/main/res/values-pl/strings.xml
<string name="widget_timetable_theme_title">Wybierz motyw</string>
<string name="widget_timetable_theme_light">Jasny</string>
<string name="widget_timetable_theme_dark">Ciemny</string>
+ <string name="widget_timetable_theme_system">Motyw systemu</string>
<!--Preferences-->

MODIFY
app/src/main/res/values/strings.xml
app/src/main/res/values/strings.xml
<string name="widget_timetable_theme_title">Choose theme</string>
<string name="widget_timetable_theme_light">Light</string>
<string name="widget_timetable_theme_dark">Dark</string>
+ <string name="widget_timetable_theme_system">System Theme</string>
<!--Preferences-->

Add "System theme" option to widgets (#739)