mirror of
https://github.com/rebelonion/Dantotsu.git
synced 2026-01-22 00:53:55 +00:00
feat: add per-widget configuration
This commit is contained in:
@@ -60,7 +60,11 @@ class ProfileStatsConfigure : AppCompatActivity(),
|
||||
binding = StatisticsWidgetConfigureBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
val prefs = getSharedPreferences(ProfileStatsWidget.PREFS_NAME, Context.MODE_PRIVATE)
|
||||
appWidgetId = intent.getIntExtra(
|
||||
AppWidgetManager.EXTRA_APPWIDGET_ID,
|
||||
AppWidgetManager.INVALID_APPWIDGET_ID
|
||||
)
|
||||
val prefs = getSharedPreferences(ProfileStatsWidget.getPrefsName(appWidgetId), Context.MODE_PRIVATE)
|
||||
val topBackground = prefs.getInt(ProfileStatsWidget.PREF_BACKGROUND_COLOR, Color.parseColor("#80000000"))
|
||||
(binding.topBackgroundButton as MaterialButton).iconTint = ColorStateList.valueOf(topBackground)
|
||||
binding.topBackgroundButton.setOnClickListener {
|
||||
@@ -192,7 +196,7 @@ class ProfileStatsConfigure : AppCompatActivity(),
|
||||
)
|
||||
val subTextColor = typedValueOutline.data
|
||||
|
||||
getSharedPreferences(ProfileStatsWidget.PREFS_NAME, Context.MODE_PRIVATE).edit().apply {
|
||||
getSharedPreferences(ProfileStatsWidget.getPrefsName(appWidgetId), Context.MODE_PRIVATE).edit().apply {
|
||||
putInt(ProfileStatsWidget.PREF_BACKGROUND_COLOR, backgroundColor)
|
||||
putInt(ProfileStatsWidget.PREF_BACKGROUND_FADE, backgroundColor)
|
||||
putInt(ProfileStatsWidget.PREF_TITLE_TEXT_COLOR, textColor)
|
||||
@@ -204,12 +208,13 @@ class ProfileStatsConfigure : AppCompatActivity(),
|
||||
override fun onResult(dialogTag: String, which: Int, extras: Bundle): Boolean {
|
||||
if (which == SimpleDialog.OnDialogResultListener.BUTTON_POSITIVE) {
|
||||
if (!isMonetEnabled) {
|
||||
val prefs = getSharedPreferences(
|
||||
ProfileStatsWidget.getPrefsName(appWidgetId),
|
||||
Context.MODE_PRIVATE
|
||||
)
|
||||
when (dialogTag) {
|
||||
ProfileStatsWidget.PREF_BACKGROUND_COLOR -> {
|
||||
getSharedPreferences(
|
||||
ProfileStatsWidget.PREFS_NAME,
|
||||
Context.MODE_PRIVATE
|
||||
).edit()
|
||||
prefs.edit()
|
||||
.putInt(
|
||||
ProfileStatsWidget.PREF_BACKGROUND_COLOR,
|
||||
extras.getInt(SimpleColorDialog.COLOR)
|
||||
@@ -220,10 +225,7 @@ class ProfileStatsConfigure : AppCompatActivity(),
|
||||
}
|
||||
|
||||
ProfileStatsWidget.PREF_BACKGROUND_FADE -> {
|
||||
getSharedPreferences(
|
||||
ProfileStatsWidget.PREFS_NAME,
|
||||
Context.MODE_PRIVATE
|
||||
).edit()
|
||||
prefs.edit()
|
||||
.putInt(
|
||||
ProfileStatsWidget.PREF_BACKGROUND_FADE,
|
||||
extras.getInt(SimpleColorDialog.COLOR)
|
||||
@@ -234,10 +236,7 @@ class ProfileStatsConfigure : AppCompatActivity(),
|
||||
}
|
||||
|
||||
ProfileStatsWidget.PREF_TITLE_TEXT_COLOR -> {
|
||||
getSharedPreferences(
|
||||
ProfileStatsWidget.PREFS_NAME,
|
||||
Context.MODE_PRIVATE
|
||||
).edit()
|
||||
prefs.edit()
|
||||
.putInt(
|
||||
ProfileStatsWidget.PREF_TITLE_TEXT_COLOR,
|
||||
extras.getInt(SimpleColorDialog.COLOR)
|
||||
@@ -248,10 +247,7 @@ class ProfileStatsConfigure : AppCompatActivity(),
|
||||
}
|
||||
|
||||
ProfileStatsWidget.PREF_STATS_TEXT_COLOR -> {
|
||||
getSharedPreferences(
|
||||
ProfileStatsWidget.PREFS_NAME,
|
||||
Context.MODE_PRIVATE
|
||||
).edit()
|
||||
prefs.edit()
|
||||
.putInt(
|
||||
ProfileStatsWidget.PREF_STATS_TEXT_COLOR,
|
||||
extras.getInt(SimpleColorDialog.COLOR)
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.net.Uri
|
||||
import android.widget.RemoteViews
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import ani.dantotsu.MainActivity
|
||||
@@ -89,7 +90,7 @@ class ProfileStatsWidget : AppWidgetProvider() {
|
||||
appWidgetId: Int
|
||||
) {
|
||||
|
||||
val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||
val prefs = context.getSharedPreferences(getPrefsName(appWidgetId), Context.MODE_PRIVATE)
|
||||
val backgroundColor =
|
||||
prefs.getInt(PREF_BACKGROUND_COLOR, Color.parseColor("#80000000"))
|
||||
val backgroundFade = prefs.getInt(PREF_BACKGROUND_FADE, Color.parseColor("#00000000"))
|
||||
@@ -133,6 +134,7 @@ class ProfileStatsWidget : AppWidgetProvider() {
|
||||
1,
|
||||
Intent(context, ProfileStatsConfigure::class.java).apply {
|
||||
putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
|
||||
data = Uri.parse(toUri(Intent.URI_INTENT_SCHEME))
|
||||
},
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
@@ -248,7 +250,9 @@ class ProfileStatsWidget : AppWidgetProvider() {
|
||||
}
|
||||
}
|
||||
|
||||
const val PREFS_NAME = "ani.dantotsu.widgets.ResumableWidget"
|
||||
fun getPrefsName(appWidgetId: Int): String {
|
||||
return "ani.dantotsu.widgets.Statistics.${appWidgetId}"
|
||||
}
|
||||
const val PREF_BACKGROUND_COLOR = "background_color"
|
||||
const val PREF_BACKGROUND_FADE = "background_fade"
|
||||
const val PREF_TITLE_TEXT_COLOR = "title_text_color"
|
||||
|
||||
Reference in New Issue
Block a user