Add 'System default' widget theme

pull/1151/head
Alex Baker 4 years ago
parent c41b8d8453
commit 424b07f8fc

@ -2,6 +2,7 @@ package org.tasks.widget
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.res.Configuration
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.Paint import android.graphics.Paint
import android.view.View import android.view.View
@ -15,6 +16,7 @@ import com.todoroo.astrid.data.Task
import com.todoroo.astrid.subtasks.SubtasksHelper import com.todoroo.astrid.subtasks.SubtasksHelper
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.tasks.BuildConfig import org.tasks.BuildConfig
import org.tasks.LocalBroadcastManager
import org.tasks.R import org.tasks.R
import org.tasks.data.SubtaskInfo import org.tasks.data.SubtaskInfo
import org.tasks.data.TaskContainer import org.tasks.data.TaskContainer
@ -40,10 +42,10 @@ internal class ScrollableViewsFactory(
private val defaultFilterProvider: DefaultFilterProvider, private val defaultFilterProvider: DefaultFilterProvider,
private val checkBoxProvider: CheckBoxProvider, private val checkBoxProvider: CheckBoxProvider,
private val locale: Locale, private val locale: Locale,
private val chipProvider: ChipProvider private val chipProvider: ChipProvider,
private val localBroadcastManager: LocalBroadcastManager
) : RemoteViewsFactory { ) : RemoteViewsFactory {
private val indentPadding: Int private val indentPadding: Int
private var isDark = false
private var showDueDates = false private var showDueDates = false
private var endDueDate = false private var endDueDate = false
private var showCheckboxes = false private var showCheckboxes = false
@ -69,6 +71,14 @@ internal class ScrollableViewsFactory(
private var sortMode = -1 private var sortMode = -1
private var tasks = SectionedDataSource(emptyList(), false, 0, collapsed) private var tasks = SectionedDataSource(emptyList(), false, 0, collapsed)
private val widgetPreferences = WidgetPreferences(context, preferences, widgetId) private val widgetPreferences = WidgetPreferences(context, preferences, widgetId)
private var isDark = checkIfDark
private val checkIfDark: Boolean
get() = when (widgetPreferences.themeIndex) {
0 -> false
3 -> context.isDark
else -> true
}
override fun onCreate() {} override fun onCreate() {}
@ -108,6 +118,10 @@ internal class ScrollableViewsFactory(
override fun getItemId(position: Int) = getTask(position)?.id ?: 0 override fun getItemId(position: Int) = getTask(position)?.id ?: 0
override fun hasStableIds(): Boolean { override fun hasStableIds(): Boolean {
if (isDark != checkIfDark) {
isDark = !isDark
localBroadcastManager.reconfigureWidget(widgetId)
}
return true return true
} }
@ -337,7 +351,6 @@ internal class ScrollableViewsFactory(
showFullTaskTitle = widgetPreferences.showFullTaskTitle() showFullTaskTitle = widgetPreferences.showFullTaskTitle()
showDescription = widgetPreferences.showDescription() showDescription = widgetPreferences.showDescription()
showFullDescription = widgetPreferences.showFullDescription() showFullDescription = widgetPreferences.showFullDescription()
isDark = widgetPreferences.themeIndex > 0
chipProvider.isDark = isDark chipProvider.isDark = isDark
textColorPrimary = context.getColor(if (isDark) R.color.white_87 else R.color.black_87) textColorPrimary = context.getColor(if (isDark) R.color.white_87 else R.color.black_87)
textColorSecondary = context.getColor(if (isDark) R.color.white_60 else R.color.black_60) textColorSecondary = context.getColor(if (isDark) R.color.white_60 else R.color.black_60)
@ -369,4 +382,10 @@ internal class ScrollableViewsFactory(
val metrics = context.resources.displayMetrics val metrics = context.resources.displayMetrics
indentPadding = (20 * metrics.density).toInt() indentPadding = (20 * metrics.density).toInt()
} }
companion object {
val Context.isDark: Boolean
get() = (Configuration.UI_MODE_NIGHT_YES ==
(resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK))
}
} }

@ -8,6 +8,7 @@ import android.widget.RemoteViewsService;
import com.todoroo.astrid.subtasks.SubtasksHelper; import com.todoroo.astrid.subtasks.SubtasksHelper;
import dagger.hilt.android.AndroidEntryPoint; import dagger.hilt.android.AndroidEntryPoint;
import javax.inject.Inject; import javax.inject.Inject;
import org.tasks.LocalBroadcastManager;
import org.tasks.data.TaskDao; import org.tasks.data.TaskDao;
import org.tasks.locale.Locale; import org.tasks.locale.Locale;
import org.tasks.preferences.DefaultFilterProvider; import org.tasks.preferences.DefaultFilterProvider;
@ -24,6 +25,7 @@ public class ScrollableWidgetUpdateService extends RemoteViewsService {
@Inject DefaultFilterProvider defaultFilterProvider; @Inject DefaultFilterProvider defaultFilterProvider;
@Inject Locale locale; @Inject Locale locale;
@Inject ChipProvider chipProvider; @Inject ChipProvider chipProvider;
@Inject LocalBroadcastManager localBroadcastManager;
@Override @Override
public void onStart(Intent intent, int startId) { public void onStart(Intent intent, int startId) {
@ -54,6 +56,7 @@ public class ScrollableWidgetUpdateService extends RemoteViewsService {
defaultFilterProvider, defaultFilterProvider,
new CheckBoxProvider(context, new ColorProvider(context, preferences)), new CheckBoxProvider(context, new ColorProvider(context, preferences)),
locale, locale,
chipProvider); chipProvider,
localBroadcastManager);
} }
} }

@ -21,6 +21,7 @@ import org.tasks.locale.Locale
import org.tasks.preferences.DefaultFilterProvider import org.tasks.preferences.DefaultFilterProvider
import org.tasks.preferences.Preferences import org.tasks.preferences.Preferences
import org.tasks.themes.ThemeColor import org.tasks.themes.ThemeColor
import org.tasks.widget.ScrollableViewsFactory.Companion.isDark
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -111,6 +112,7 @@ class TasksWidget : AppWidgetProvider() {
val background: Int = when (themeIndex) { val background: Int = when (themeIndex) {
1 -> android.R.color.black 1 -> android.R.color.black
2 -> R.color.md_background_dark 2 -> R.color.md_background_dark
3 -> if (context.isDark) R.color.md_background_dark else android.R.color.white
else -> android.R.color.white else -> android.R.color.white
} }
return context.getColor(background) return context.getColor(background)

@ -115,7 +115,7 @@ public class WidgetPreferences {
} }
public int getThemeIndex() { public int getThemeIndex() {
return getInt(R.string.p_widget_theme, 0); return getInt(R.string.p_widget_theme, 3);
} }
public int getColor() { public int getColor() {

@ -40,6 +40,7 @@
<item>@string/theme_light</item> <item>@string/theme_light</item>
<item>@string/theme_black</item> <item>@string/theme_black</item>
<item>@string/theme_dark</item> <item>@string/theme_dark</item>
<item>@string/theme_system_default</item>
</string-array> </string-array>
<string-array name="localization"> <string-array name="localization">

Loading…
Cancel
Save