feat(widget): use app color

This commit is contained in:
aayush262 2024-03-27 13:52:00 +05:30
parent 19b5b11b07
commit ef97b5679e
5 changed files with 115 additions and 56 deletions

View file

@ -69,8 +69,8 @@ class UpcomingWidget : AppWidgetProvider() {
): RemoteViews { ): RemoteViews {
val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
val backgroundColor = val backgroundColor =
prefs.getInt(PREF_BACKGROUND_COLOR, ContextCompat.getColor(context, R.color.theme)) prefs.getInt(PREF_BACKGROUND_COLOR, Color.parseColor("#80000000"))
val backgroundFade = prefs.getInt(PREF_BACKGROUND_FADE, Color.GRAY) val backgroundFade = prefs.getInt(PREF_BACKGROUND_FADE, Color.parseColor("#00000000"))
val titleTextColor = prefs.getInt(PREF_TITLE_TEXT_COLOR, Color.WHITE) val titleTextColor = prefs.getInt(PREF_TITLE_TEXT_COLOR, Color.WHITE)
val countdownTextColor = prefs.getInt(PREF_COUNTDOWN_TEXT_COLOR, Color.WHITE) val countdownTextColor = prefs.getInt(PREF_COUNTDOWN_TEXT_COLOR, Color.WHITE)
@ -80,14 +80,14 @@ class UpcomingWidget : AppWidgetProvider() {
} }
val gradientDrawable = ResourcesCompat.getDrawable( val gradientDrawable = ResourcesCompat.getDrawable(
context.resources, context.resources,
R.drawable.gradient_background, R.drawable.linear_gradient_black,
null null
) as GradientDrawable ) as GradientDrawable
gradientDrawable.colors = intArrayOf(backgroundColor, backgroundFade) gradientDrawable.colors = intArrayOf(backgroundColor, backgroundFade)
val widgetSizeProvider = WidgetSizeProvider(context) val widgetSizeProvider = WidgetSizeProvider(context)
var (width, height) = widgetSizeProvider.getWidgetsSize(appWidgetId) var (width, height) = widgetSizeProvider.getWidgetsSize(appWidgetId)
if (width > 0 && height > 0) { if (width > 0 && height > 0) {
gradientDrawable.cornerRadius = 50f gradientDrawable.cornerRadius = 64f
} else { } else {
width = 300 width = 300
height = 300 height = 300

View file

@ -5,9 +5,9 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.graphics.Color import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.util.TypedValue
import android.view.View import android.view.View
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import ani.dantotsu.R import ani.dantotsu.R
import ani.dantotsu.databinding.UpcomingWidgetConfigureBinding import ani.dantotsu.databinding.UpcomingWidgetConfigureBinding
import ani.dantotsu.themes.ThemeManager import ani.dantotsu.themes.ThemeManager
@ -20,7 +20,7 @@ import eltos.simpledialogfragment.color.SimpleColorDialog
class UpcomingWidgetConfigureActivity : AppCompatActivity(), class UpcomingWidgetConfigureActivity : AppCompatActivity(),
SimpleDialog.OnDialogResultListener { SimpleDialog.OnDialogResultListener {
private var appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID private var appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID
private var isMonetEnabled = false
private var onClickListener = View.OnClickListener { private var onClickListener = View.OnClickListener {
val context = this@UpcomingWidgetConfigureActivity val context = this@UpcomingWidgetConfigureActivity
val appWidgetManager = AppWidgetManager.getInstance(context) val appWidgetManager = AppWidgetManager.getInstance(context)
@ -53,7 +53,7 @@ class UpcomingWidgetConfigureActivity : AppCompatActivity(),
.colorPreset( .colorPreset(
prefs.getInt( prefs.getInt(
UpcomingWidget.PREF_BACKGROUND_COLOR, UpcomingWidget.PREF_BACKGROUND_COLOR,
ContextCompat.getColor(this, R.color.theme) Color.parseColor("#80000000")
) )
) )
.colors( .colors(
@ -71,7 +71,7 @@ class UpcomingWidgetConfigureActivity : AppCompatActivity(),
binding.bottomBackgroundButton.setOnClickListener { binding.bottomBackgroundButton.setOnClickListener {
val tag = UpcomingWidget.PREF_BACKGROUND_FADE val tag = UpcomingWidget.PREF_BACKGROUND_FADE
SimpleColorDialog().title(R.string.custom_theme) SimpleColorDialog().title(R.string.custom_theme)
.colorPreset(prefs.getInt(UpcomingWidget.PREF_BACKGROUND_FADE, Color.GRAY)) .colorPreset(prefs.getInt(UpcomingWidget.PREF_BACKGROUND_FADE, Color.parseColor("#00000000")))
.colors( .colors(
this@UpcomingWidgetConfigureActivity, this@UpcomingWidgetConfigureActivity,
SimpleColorDialog.MATERIAL_COLOR_PALLET SimpleColorDialog.MATERIAL_COLOR_PALLET
@ -119,7 +119,22 @@ class UpcomingWidgetConfigureActivity : AppCompatActivity(),
.neg() .neg()
.show(this@UpcomingWidgetConfigureActivity, tag) .show(this@UpcomingWidgetConfigureActivity, tag)
} }
binding.useAppTheme.setOnCheckedChangeListener { _, isChecked ->
isMonetEnabled = isChecked
if (isChecked) {
binding.topBackgroundButton.visibility = View.GONE
binding.bottomBackgroundButton.visibility = View.GONE
binding.titleColorButton.visibility = View.GONE
binding.countdownColorButton.visibility = View.GONE
themeColors()
} else {
binding.topBackgroundButton.visibility = View.VISIBLE
binding.bottomBackgroundButton.visibility = View.VISIBLE
binding.titleColorButton.visibility = View.VISIBLE
binding.countdownColorButton.visibility = View.VISIBLE
}
}
binding.addButton.setOnClickListener(onClickListener) binding.addButton.setOnClickListener(onClickListener)
val intent = intent val intent = intent
@ -138,58 +153,81 @@ class UpcomingWidgetConfigureActivity : AppCompatActivity(),
override fun onResult(dialogTag: String, which: Int, extras: Bundle): Boolean { override fun onResult(dialogTag: String, which: Int, extras: Bundle): Boolean {
if (which == SimpleDialog.OnDialogResultListener.BUTTON_POSITIVE) { if (which == SimpleDialog.OnDialogResultListener.BUTTON_POSITIVE) {
when (dialogTag) { if (!isMonetEnabled) {
UpcomingWidget.PREF_BACKGROUND_COLOR -> { when (dialogTag) {
getSharedPreferences( UpcomingWidget.PREF_BACKGROUND_COLOR -> {
UpcomingWidget.PREFS_NAME, getSharedPreferences(
Context.MODE_PRIVATE UpcomingWidget.PREFS_NAME,
).edit() Context.MODE_PRIVATE
.putInt( ).edit()
UpcomingWidget.PREF_BACKGROUND_COLOR, .putInt(
extras.getInt(SimpleColorDialog.COLOR) UpcomingWidget.PREF_BACKGROUND_COLOR,
) extras.getInt(SimpleColorDialog.COLOR)
.apply() )
} .apply()
}
UpcomingWidget.PREF_BACKGROUND_FADE -> { UpcomingWidget.PREF_BACKGROUND_FADE -> {
getSharedPreferences( getSharedPreferences(
UpcomingWidget.PREFS_NAME, UpcomingWidget.PREFS_NAME,
Context.MODE_PRIVATE Context.MODE_PRIVATE
).edit() ).edit()
.putInt( .putInt(
UpcomingWidget.PREF_BACKGROUND_FADE, UpcomingWidget.PREF_BACKGROUND_FADE,
extras.getInt(SimpleColorDialog.COLOR) extras.getInt(SimpleColorDialog.COLOR)
) )
.apply() .apply()
} }
UpcomingWidget.PREF_TITLE_TEXT_COLOR -> { UpcomingWidget.PREF_TITLE_TEXT_COLOR -> {
getSharedPreferences( getSharedPreferences(
UpcomingWidget.PREFS_NAME, UpcomingWidget.PREFS_NAME,
Context.MODE_PRIVATE Context.MODE_PRIVATE
).edit() ).edit()
.putInt( .putInt(
UpcomingWidget.PREF_TITLE_TEXT_COLOR, UpcomingWidget.PREF_TITLE_TEXT_COLOR,
extras.getInt(SimpleColorDialog.COLOR) extras.getInt(SimpleColorDialog.COLOR)
) )
.apply() .apply()
} }
UpcomingWidget.PREF_COUNTDOWN_TEXT_COLOR -> { UpcomingWidget.PREF_COUNTDOWN_TEXT_COLOR -> {
getSharedPreferences( getSharedPreferences(
UpcomingWidget.PREFS_NAME, UpcomingWidget.PREFS_NAME,
Context.MODE_PRIVATE Context.MODE_PRIVATE
).edit() ).edit()
.putInt( .putInt(
UpcomingWidget.PREF_COUNTDOWN_TEXT_COLOR, UpcomingWidget.PREF_COUNTDOWN_TEXT_COLOR,
extras.getInt(SimpleColorDialog.COLOR) extras.getInt(SimpleColorDialog.COLOR)
) )
.apply() .apply()
} }
}
} }
} }
return true return true
} }
private fun themeColors() {
val typedValueSurface = TypedValue()
theme.resolveAttribute(com.google.android.material.R.attr.colorSurface, typedValueSurface, true)
val backgroundColor = typedValueSurface.data
val typedValuePrimary = TypedValue()
theme.resolveAttribute(com.google.android.material.R.attr.colorPrimary, typedValuePrimary, true)
val textColor = typedValuePrimary.data
val typedValueOutline = TypedValue()
theme.resolveAttribute(com.google.android.material.R.attr.colorOutline, typedValueOutline, true)
val subTextColor = typedValueOutline.data
getSharedPreferences(UpcomingWidget.PREFS_NAME, Context.MODE_PRIVATE).edit().apply {
putInt(UpcomingWidget.PREF_BACKGROUND_COLOR, backgroundColor)
putInt(UpcomingWidget.PREF_BACKGROUND_FADE, backgroundColor)
putInt(UpcomingWidget.PREF_TITLE_TEXT_COLOR, textColor)
putInt(UpcomingWidget.PREF_COUNTDOWN_TEXT_COLOR, subTextColor)
apply()
}
}
} }

View file

@ -9,14 +9,14 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:scaleType="fitXY" android:scaleType="fitXY"
android:src="@drawable/gradient_background" android:src="@drawable/linear_gradient_black"
tools:ignore="ContentDescription"/> tools:ignore="ContentDescription"/>
<RelativeLayout <RelativeLayout
android:id="@+id/widgetContainer" android:id="@+id/widgetContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:padding="8dp"> android:padding="16dp">
<ImageView <ImageView
android:id="@+id/logoView" android:id="@+id/logoView"

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:orientation="vertical"
android:padding="16dp"> android:padding="16dp">
@ -10,8 +10,28 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:fontFamily="@font/poppins_bold"
android:text="@string/configure" /> android:text="@string/configure" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/useAppTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:checked="false"
android:drawableStart="@drawable/ic_round_new_releases_24"
android:drawablePadding="16dp"
android:elegantTextHeight="true"
android:fontFamily="@font/poppins_bold"
android:minHeight="64dp"
android:text="@string/use_app_theme"
android:textAlignment="viewStart"
android:textColor="?attr/colorOnBackground"
app:cornerRadius="0dp"
app:drawableTint="?attr/colorPrimary"
app:showText="false"
app:thumbTint="@color/button_switch_track" />
<Button <Button
android:id="@+id/topBackgroundButton" android:id="@+id/topBackgroundButton"
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -661,6 +661,7 @@
<string name="NSFWExtention">NSFW Extensions</string> <string name="NSFWExtention">NSFW Extensions</string>
<string name="skip_loading_extension_icons">Skip loading extension icons</string> <string name="skip_loading_extension_icons">Skip loading extension icons</string>
<string name="use_material_you">Material You</string> <string name="use_material_you">Material You</string>
<string name="use_app_theme">Use App Theme</string>
<string name="extension_specific_dns">Extension-specific DNS</string> <string name="extension_specific_dns">Extension-specific DNS</string>
<string name="theme_">Theme:</string> <string name="theme_">Theme:</string>
<string name="user_agent">User Agent</string> <string name="user_agent">User Agent</string>