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 {
val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
val backgroundColor =
prefs.getInt(PREF_BACKGROUND_COLOR, ContextCompat.getColor(context, R.color.theme))
val backgroundFade = prefs.getInt(PREF_BACKGROUND_FADE, Color.GRAY)
prefs.getInt(PREF_BACKGROUND_COLOR, Color.parseColor("#80000000"))
val backgroundFade = prefs.getInt(PREF_BACKGROUND_FADE, Color.parseColor("#00000000"))
val titleTextColor = prefs.getInt(PREF_TITLE_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(
context.resources,
R.drawable.gradient_background,
R.drawable.linear_gradient_black,
null
) as GradientDrawable
gradientDrawable.colors = intArrayOf(backgroundColor, backgroundFade)
val widgetSizeProvider = WidgetSizeProvider(context)
var (width, height) = widgetSizeProvider.getWidgetsSize(appWidgetId)
if (width > 0 && height > 0) {
gradientDrawable.cornerRadius = 50f
gradientDrawable.cornerRadius = 64f
} else {
width = 300
height = 300

View file

@ -5,9 +5,9 @@ import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import android.util.TypedValue
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import ani.dantotsu.R
import ani.dantotsu.databinding.UpcomingWidgetConfigureBinding
import ani.dantotsu.themes.ThemeManager
@ -20,7 +20,7 @@ import eltos.simpledialogfragment.color.SimpleColorDialog
class UpcomingWidgetConfigureActivity : AppCompatActivity(),
SimpleDialog.OnDialogResultListener {
private var appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID
private var isMonetEnabled = false
private var onClickListener = View.OnClickListener {
val context = this@UpcomingWidgetConfigureActivity
val appWidgetManager = AppWidgetManager.getInstance(context)
@ -53,7 +53,7 @@ class UpcomingWidgetConfigureActivity : AppCompatActivity(),
.colorPreset(
prefs.getInt(
UpcomingWidget.PREF_BACKGROUND_COLOR,
ContextCompat.getColor(this, R.color.theme)
Color.parseColor("#80000000")
)
)
.colors(
@ -71,7 +71,7 @@ class UpcomingWidgetConfigureActivity : AppCompatActivity(),
binding.bottomBackgroundButton.setOnClickListener {
val tag = UpcomingWidget.PREF_BACKGROUND_FADE
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(
this@UpcomingWidgetConfigureActivity,
SimpleColorDialog.MATERIAL_COLOR_PALLET
@ -119,7 +119,22 @@ class UpcomingWidgetConfigureActivity : AppCompatActivity(),
.neg()
.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)
val intent = intent
@ -138,6 +153,7 @@ class UpcomingWidgetConfigureActivity : AppCompatActivity(),
override fun onResult(dialogTag: String, which: Int, extras: Bundle): Boolean {
if (which == SimpleDialog.OnDialogResultListener.BUTTON_POSITIVE) {
if (!isMonetEnabled) {
when (dialogTag) {
UpcomingWidget.PREF_BACKGROUND_COLOR -> {
getSharedPreferences(
@ -189,7 +205,29 @@ class UpcomingWidgetConfigureActivity : AppCompatActivity(),
}
}
}
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_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/gradient_background"
android:src="@drawable/linear_gradient_black"
tools:ignore="ContentDescription"/>
<RelativeLayout
android:id="@+id/widgetContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp">
android:padding="16dp">
<ImageView
android:id="@+id/logoView"

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<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_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="16dp">
@ -10,8 +10,28 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:fontFamily="@font/poppins_bold"
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
android:id="@+id/topBackgroundButton"
android:layout_width="match_parent"

View file

@ -661,6 +661,7 @@
<string name="NSFWExtention">NSFW Extensions</string>
<string name="skip_loading_extension_icons">Skip loading extension icons</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="theme_">Theme:</string>
<string name="user_agent">User Agent</string>