fix: layout tweaks for upcoming widget
This commit is contained in:
parent
3375496ef2
commit
be07fad8f1
14 changed files with 93 additions and 91 deletions
|
@ -23,15 +23,15 @@ import java.io.InputStream
|
|||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
|
||||
class CurrentlyAiringRemoteViewsFactory(private val context: Context) :
|
||||
class UpcomingRemoteViewsFactory(private val context: Context) :
|
||||
RemoteViewsService.RemoteViewsFactory {
|
||||
private var widgetItems = mutableListOf<WidgetItem>()
|
||||
private var refreshing = false
|
||||
private val prefs =
|
||||
context.getSharedPreferences(CurrentlyAiringWidget.PREFS_NAME, Context.MODE_PRIVATE)
|
||||
context.getSharedPreferences(UpcomingWidget.PREFS_NAME, Context.MODE_PRIVATE)
|
||||
|
||||
override fun onCreate() {
|
||||
Logger.log("CurrentlyAiringRemoteViewsFactory onCreate")
|
||||
Logger.log("UpcomingRemoteViewsFactory onCreate")
|
||||
fillWidgetItems()
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ class CurrentlyAiringRemoteViewsFactory(private val context: Context) :
|
|||
|
||||
override fun onDataSetChanged() {
|
||||
if (refreshing) return
|
||||
Logger.log("CurrentlyAiringRemoteViewsFactory onDataSetChanged")
|
||||
Logger.log("UpcomingRemoteViewsFactory onDataSetChanged")
|
||||
widgetItems.clear()
|
||||
fillWidgetItems()
|
||||
|
||||
|
@ -78,12 +78,12 @@ class CurrentlyAiringRemoteViewsFactory(private val context: Context) :
|
|||
}
|
||||
|
||||
override fun getViewAt(position: Int): RemoteViews {
|
||||
Logger.log("CurrentlyAiringRemoteViewsFactory getViewAt")
|
||||
Logger.log("UpcomingRemoteViewsFactory getViewAt")
|
||||
val item = widgetItems[position]
|
||||
val titleTextColor = prefs.getInt(CurrentlyAiringWidget.PREF_TITLE_TEXT_COLOR, Color.WHITE)
|
||||
val titleTextColor = prefs.getInt(UpcomingWidget.PREF_TITLE_TEXT_COLOR, Color.WHITE)
|
||||
val countdownTextColor =
|
||||
prefs.getInt(CurrentlyAiringWidget.PREF_COUNTDOWN_TEXT_COLOR, Color.WHITE)
|
||||
val rv = RemoteViews(context.packageName, R.layout.item_currently_airing_widget).apply {
|
||||
prefs.getInt(UpcomingWidget.PREF_COUNTDOWN_TEXT_COLOR, Color.WHITE)
|
||||
val rv = RemoteViews(context.packageName, R.layout.item_upcoming_widget).apply {
|
||||
setTextViewText(R.id.text_show_title, item.title)
|
||||
setTextViewText(R.id.text_show_countdown, item.countdown)
|
||||
setTextColor(R.id.text_show_title, titleTextColor)
|
||||
|
@ -138,7 +138,7 @@ class CurrentlyAiringRemoteViewsFactory(private val context: Context) :
|
|||
|
||||
|
||||
override fun getLoadingView(): RemoteViews {
|
||||
return RemoteViews(context.packageName, R.layout.item_currently_airing_widget)
|
||||
return RemoteViews(context.packageName, R.layout.item_upcoming_widget)
|
||||
}
|
||||
|
||||
override fun getViewTypeCount(): Int {
|
|
@ -4,9 +4,9 @@ import android.content.Intent
|
|||
import android.widget.RemoteViewsService
|
||||
import ani.dantotsu.util.Logger
|
||||
|
||||
class CurrentlyAiringRemoteViewsService : RemoteViewsService() {
|
||||
class UpcomingRemoteViewsService : RemoteViewsService() {
|
||||
override fun onGetViewFactory(intent: Intent): RemoteViewsFactory {
|
||||
Logger.log("CurrentlyAiringRemoteViewsFactory onGetViewFactory")
|
||||
return CurrentlyAiringRemoteViewsFactory(applicationContext)
|
||||
Logger.log("UpcomingRemoteViewsFactory onGetViewFactory")
|
||||
return UpcomingRemoteViewsFactory(applicationContext)
|
||||
}
|
||||
}
|
|
@ -19,9 +19,9 @@ import ani.dantotsu.R
|
|||
|
||||
/**
|
||||
* Implementation of App Widget functionality.
|
||||
* App Widget Configuration implemented in [CurrentlyAiringWidgetConfigureActivity]
|
||||
* App Widget Configuration implemented in [UpcomingWidgetConfigureActivity]
|
||||
*/
|
||||
class CurrentlyAiringWidget : AppWidgetProvider() {
|
||||
class UpcomingWidget : AppWidgetProvider() {
|
||||
override fun onUpdate(
|
||||
context: Context,
|
||||
appWidgetManager: AppWidgetManager,
|
||||
|
@ -62,7 +62,7 @@ class CurrentlyAiringWidget : AppWidgetProvider() {
|
|||
val titleTextColor = prefs.getInt(PREF_TITLE_TEXT_COLOR, Color.WHITE)
|
||||
val countdownTextColor = prefs.getInt(PREF_COUNTDOWN_TEXT_COLOR, Color.WHITE)
|
||||
|
||||
val intent = Intent(context, CurrentlyAiringRemoteViewsService::class.java).apply {
|
||||
val intent = Intent(context, UpcomingRemoteViewsService::class.java).apply {
|
||||
putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
|
||||
data = Uri.parse(toUri(Intent.URI_INTENT_SCHEME))
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ class CurrentlyAiringWidget : AppWidgetProvider() {
|
|||
intentTemplate.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
intentTemplate.putExtra("fromWidget", true)
|
||||
|
||||
val views = RemoteViews(context.packageName, R.layout.currently_airing_widget).apply {
|
||||
val views = RemoteViews(context.packageName, R.layout.upcoming_widget).apply {
|
||||
setImageViewBitmap(R.id.backgroundView, convertDrawableToBitmap(gradientDrawable))
|
||||
setTextColor(R.id.text_show_title, titleTextColor)
|
||||
setTextColor(R.id.text_show_countdown, countdownTextColor)
|
||||
|
@ -98,7 +98,7 @@ class CurrentlyAiringWidget : AppWidgetProvider() {
|
|||
PendingIntent.getActivity(
|
||||
context,
|
||||
1,
|
||||
Intent(context, CurrentlyAiringWidgetConfigureActivity::class.java).apply {
|
||||
Intent(context, UpcomingWidgetConfigureActivity::class.java).apply {
|
||||
putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
|
||||
},
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
|
@ -118,7 +118,7 @@ class CurrentlyAiringWidget : AppWidgetProvider() {
|
|||
return bitmap
|
||||
}
|
||||
|
||||
const val PREFS_NAME = "ani.dantotsu.widgets.CurrentlyAiringWidget"
|
||||
const val PREFS_NAME = "ani.dantotsu.widgets.UpcomingWidget"
|
||||
const val PREF_BACKGROUND_COLOR = "background_color"
|
||||
const val PREF_BACKGROUND_FADE = "background_fade"
|
||||
const val PREF_TITLE_TEXT_COLOR = "title_text_color"
|
||||
|
@ -131,7 +131,7 @@ internal fun updateAppWidget(
|
|||
appWidgetManager: AppWidgetManager,
|
||||
appWidgetId: Int
|
||||
) {
|
||||
val views = CurrentlyAiringWidget.updateAppWidget(context, appWidgetId)
|
||||
val views = UpcomingWidget.updateAppWidget(context, appWidgetId)
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.widgetListView)
|
||||
}
|
|
@ -9,20 +9,20 @@ import android.view.View
|
|||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import ani.dantotsu.R
|
||||
import ani.dantotsu.databinding.CurrentlyAiringWidgetConfigureBinding
|
||||
import ani.dantotsu.databinding.UpcomingWidgetConfigureBinding
|
||||
import ani.dantotsu.themes.ThemeManager
|
||||
import eltos.simpledialogfragment.SimpleDialog
|
||||
import eltos.simpledialogfragment.color.SimpleColorDialog
|
||||
|
||||
/**
|
||||
* The configuration screen for the [CurrentlyAiringWidget] AppWidget.
|
||||
* The configuration screen for the [UpcomingWidget] AppWidget.
|
||||
*/
|
||||
class CurrentlyAiringWidgetConfigureActivity : AppCompatActivity(),
|
||||
class UpcomingWidgetConfigureActivity : AppCompatActivity(),
|
||||
SimpleDialog.OnDialogResultListener {
|
||||
private var appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID
|
||||
|
||||
private var onClickListener = View.OnClickListener {
|
||||
val context = this@CurrentlyAiringWidgetConfigureActivity
|
||||
val context = this@UpcomingWidgetConfigureActivity
|
||||
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||
|
||||
updateAppWidget(
|
||||
|
@ -36,28 +36,28 @@ class CurrentlyAiringWidgetConfigureActivity : AppCompatActivity(),
|
|||
setResult(RESULT_OK, resultValue)
|
||||
finish()
|
||||
}
|
||||
private lateinit var binding: CurrentlyAiringWidgetConfigureBinding
|
||||
private lateinit var binding: UpcomingWidgetConfigureBinding
|
||||
|
||||
public override fun onCreate(icicle: Bundle?) {
|
||||
ThemeManager(this).applyTheme()
|
||||
super.onCreate(icicle)
|
||||
setResult(RESULT_CANCELED)
|
||||
|
||||
binding = CurrentlyAiringWidgetConfigureBinding.inflate(layoutInflater)
|
||||
binding = UpcomingWidgetConfigureBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
val prefs = getSharedPreferences(CurrentlyAiringWidget.PREFS_NAME, Context.MODE_PRIVATE)
|
||||
val prefs = getSharedPreferences(UpcomingWidget.PREFS_NAME, Context.MODE_PRIVATE)
|
||||
|
||||
binding.topBackgroundButton.setOnClickListener {
|
||||
val tag = CurrentlyAiringWidget.PREF_BACKGROUND_COLOR
|
||||
val tag = UpcomingWidget.PREF_BACKGROUND_COLOR
|
||||
SimpleColorDialog().title(R.string.custom_theme)
|
||||
.colorPreset(
|
||||
prefs.getInt(
|
||||
CurrentlyAiringWidget.PREF_BACKGROUND_COLOR,
|
||||
UpcomingWidget.PREF_BACKGROUND_COLOR,
|
||||
ContextCompat.getColor(this, R.color.theme)
|
||||
)
|
||||
)
|
||||
.colors(
|
||||
this@CurrentlyAiringWidgetConfigureActivity,
|
||||
this@UpcomingWidgetConfigureActivity,
|
||||
SimpleColorDialog.MATERIAL_COLOR_PALLET
|
||||
)
|
||||
.allowCustom(true)
|
||||
|
@ -65,14 +65,14 @@ class CurrentlyAiringWidgetConfigureActivity : AppCompatActivity(),
|
|||
.gridNumColumn(5)
|
||||
.choiceMode(SimpleColorDialog.SINGLE_CHOICE)
|
||||
.neg()
|
||||
.show(this@CurrentlyAiringWidgetConfigureActivity, tag)
|
||||
.show(this@UpcomingWidgetConfigureActivity, tag)
|
||||
}
|
||||
binding.bottomBackgroundButton.setOnClickListener {
|
||||
val tag = CurrentlyAiringWidget.PREF_BACKGROUND_FADE
|
||||
val tag = UpcomingWidget.PREF_BACKGROUND_FADE
|
||||
SimpleColorDialog().title(R.string.custom_theme)
|
||||
.colorPreset(prefs.getInt(CurrentlyAiringWidget.PREF_BACKGROUND_FADE, Color.GRAY))
|
||||
.colorPreset(prefs.getInt(UpcomingWidget.PREF_BACKGROUND_FADE, Color.GRAY))
|
||||
.colors(
|
||||
this@CurrentlyAiringWidgetConfigureActivity,
|
||||
this@UpcomingWidgetConfigureActivity,
|
||||
SimpleColorDialog.MATERIAL_COLOR_PALLET
|
||||
)
|
||||
.allowCustom(true)
|
||||
|
@ -80,14 +80,14 @@ class CurrentlyAiringWidgetConfigureActivity : AppCompatActivity(),
|
|||
.gridNumColumn(5)
|
||||
.choiceMode(SimpleColorDialog.SINGLE_CHOICE)
|
||||
.neg()
|
||||
.show(this@CurrentlyAiringWidgetConfigureActivity, tag)
|
||||
.show(this@UpcomingWidgetConfigureActivity, tag)
|
||||
}
|
||||
binding.titleColorButton.setOnClickListener {
|
||||
val tag = CurrentlyAiringWidget.PREF_TITLE_TEXT_COLOR
|
||||
val tag = UpcomingWidget.PREF_TITLE_TEXT_COLOR
|
||||
SimpleColorDialog().title(R.string.custom_theme)
|
||||
.colorPreset(prefs.getInt(CurrentlyAiringWidget.PREF_TITLE_TEXT_COLOR, Color.WHITE))
|
||||
.colorPreset(prefs.getInt(UpcomingWidget.PREF_TITLE_TEXT_COLOR, Color.WHITE))
|
||||
.colors(
|
||||
this@CurrentlyAiringWidgetConfigureActivity,
|
||||
this@UpcomingWidgetConfigureActivity,
|
||||
SimpleColorDialog.MATERIAL_COLOR_PALLET
|
||||
)
|
||||
.allowCustom(true)
|
||||
|
@ -95,19 +95,19 @@ class CurrentlyAiringWidgetConfigureActivity : AppCompatActivity(),
|
|||
.gridNumColumn(5)
|
||||
.choiceMode(SimpleColorDialog.SINGLE_CHOICE)
|
||||
.neg()
|
||||
.show(this@CurrentlyAiringWidgetConfigureActivity, tag)
|
||||
.show(this@UpcomingWidgetConfigureActivity, tag)
|
||||
}
|
||||
binding.countdownColorButton.setOnClickListener {
|
||||
val tag = CurrentlyAiringWidget.PREF_COUNTDOWN_TEXT_COLOR
|
||||
val tag = UpcomingWidget.PREF_COUNTDOWN_TEXT_COLOR
|
||||
SimpleColorDialog().title(R.string.custom_theme)
|
||||
.colorPreset(
|
||||
prefs.getInt(
|
||||
CurrentlyAiringWidget.PREF_COUNTDOWN_TEXT_COLOR,
|
||||
UpcomingWidget.PREF_COUNTDOWN_TEXT_COLOR,
|
||||
Color.WHITE
|
||||
)
|
||||
)
|
||||
.colors(
|
||||
this@CurrentlyAiringWidgetConfigureActivity,
|
||||
this@UpcomingWidgetConfigureActivity,
|
||||
SimpleColorDialog.MATERIAL_COLOR_PALLET
|
||||
)
|
||||
.allowCustom(true)
|
||||
|
@ -115,7 +115,7 @@ class CurrentlyAiringWidgetConfigureActivity : AppCompatActivity(),
|
|||
.gridNumColumn(5)
|
||||
.choiceMode(SimpleColorDialog.SINGLE_CHOICE)
|
||||
.neg()
|
||||
.show(this@CurrentlyAiringWidgetConfigureActivity, tag)
|
||||
.show(this@UpcomingWidgetConfigureActivity, tag)
|
||||
}
|
||||
|
||||
binding.addButton.setOnClickListener(onClickListener)
|
||||
|
@ -137,49 +137,49 @@ class CurrentlyAiringWidgetConfigureActivity : AppCompatActivity(),
|
|||
override fun onResult(dialogTag: String, which: Int, extras: Bundle): Boolean {
|
||||
if (which == SimpleDialog.OnDialogResultListener.BUTTON_POSITIVE) {
|
||||
when (dialogTag) {
|
||||
CurrentlyAiringWidget.PREF_BACKGROUND_COLOR -> {
|
||||
UpcomingWidget.PREF_BACKGROUND_COLOR -> {
|
||||
getSharedPreferences(
|
||||
CurrentlyAiringWidget.PREFS_NAME,
|
||||
UpcomingWidget.PREFS_NAME,
|
||||
Context.MODE_PRIVATE
|
||||
).edit()
|
||||
.putInt(
|
||||
CurrentlyAiringWidget.PREF_BACKGROUND_COLOR,
|
||||
UpcomingWidget.PREF_BACKGROUND_COLOR,
|
||||
extras.getInt(SimpleColorDialog.COLOR)
|
||||
)
|
||||
.apply()
|
||||
}
|
||||
|
||||
CurrentlyAiringWidget.PREF_BACKGROUND_FADE -> {
|
||||
UpcomingWidget.PREF_BACKGROUND_FADE -> {
|
||||
getSharedPreferences(
|
||||
CurrentlyAiringWidget.PREFS_NAME,
|
||||
UpcomingWidget.PREFS_NAME,
|
||||
Context.MODE_PRIVATE
|
||||
).edit()
|
||||
.putInt(
|
||||
CurrentlyAiringWidget.PREF_BACKGROUND_FADE,
|
||||
UpcomingWidget.PREF_BACKGROUND_FADE,
|
||||
extras.getInt(SimpleColorDialog.COLOR)
|
||||
)
|
||||
.apply()
|
||||
}
|
||||
|
||||
CurrentlyAiringWidget.PREF_TITLE_TEXT_COLOR -> {
|
||||
UpcomingWidget.PREF_TITLE_TEXT_COLOR -> {
|
||||
getSharedPreferences(
|
||||
CurrentlyAiringWidget.PREFS_NAME,
|
||||
UpcomingWidget.PREFS_NAME,
|
||||
Context.MODE_PRIVATE
|
||||
).edit()
|
||||
.putInt(
|
||||
CurrentlyAiringWidget.PREF_TITLE_TEXT_COLOR,
|
||||
UpcomingWidget.PREF_TITLE_TEXT_COLOR,
|
||||
extras.getInt(SimpleColorDialog.COLOR)
|
||||
)
|
||||
.apply()
|
||||
}
|
||||
|
||||
CurrentlyAiringWidget.PREF_COUNTDOWN_TEXT_COLOR -> {
|
||||
UpcomingWidget.PREF_COUNTDOWN_TEXT_COLOR -> {
|
||||
getSharedPreferences(
|
||||
CurrentlyAiringWidget.PREFS_NAME,
|
||||
UpcomingWidget.PREFS_NAME,
|
||||
Context.MODE_PRIVATE
|
||||
).edit()
|
||||
.putInt(
|
||||
CurrentlyAiringWidget.PREF_COUNTDOWN_TEXT_COLOR,
|
||||
UpcomingWidget.PREF_COUNTDOWN_TEXT_COLOR,
|
||||
extras.getInt(SimpleColorDialog.COLOR)
|
||||
)
|
||||
.apply()
|
Loading…
Add table
Add a link
Reference in a new issue