Move to kotlin data binding and update main fragoment

This commit is contained in:
Tommaso Berlose 2021-01-07 15:09:58 +01:00
parent ce9b343e0e
commit 98db1380b7
46 changed files with 1048 additions and 1019 deletions

Binary file not shown.

View File

@ -6,7 +6,6 @@ apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'kotlin-android' apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'realm-android' apply plugin: 'realm-android'
@ -55,11 +54,11 @@ android {
packagingOptions { packagingOptions {
exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/DEPENDENCIES'
} }
dataBinding {
enabled = true
}
viewBinding.enabled = true buildFeatures {
dataBinding = true
viewBinding = true
}
} }
dependencies { dependencies {

View File

@ -6,6 +6,7 @@ import android.graphics.Color
import android.text.Editable import android.text.Editable
import android.text.TextWatcher import android.text.TextWatcher
import android.util.Log import android.util.Log
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.GridLayout import android.widget.GridLayout
import android.widget.ImageView import android.widget.ImageView
@ -21,6 +22,8 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.card.MaterialCardView import com.google.android.material.card.MaterialCardView
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.databinding.BottomSheetMenuHorBinding
import com.tommasoberlose.anotherwidget.databinding.BottomSheetMenuListBinding
import com.tommasoberlose.anotherwidget.helpers.ColorHelper import com.tommasoberlose.anotherwidget.helpers.ColorHelper
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.isColorDark import com.tommasoberlose.anotherwidget.helpers.ColorHelper.isColorDark
import com.tommasoberlose.anotherwidget.utils.expand import com.tommasoberlose.anotherwidget.utils.expand
@ -30,10 +33,6 @@ import com.tommasoberlose.anotherwidget.utils.toPixel
import com.warkiz.widget.IndicatorSeekBar import com.warkiz.widget.IndicatorSeekBar
import com.warkiz.widget.OnSeekChangeListener import com.warkiz.widget.OnSeekChangeListener
import com.warkiz.widget.SeekParams import com.warkiz.widget.SeekParams
import kotlinx.android.synthetic.main.bottom_sheet_menu_hor.*
import kotlinx.android.synthetic.main.bottom_sheet_menu_hor.view.*
import kotlinx.android.synthetic.main.bottom_sheet_menu_hor.view.color_loader
import kotlinx.android.synthetic.main.color_picker_menu_item.view.*
import kotlinx.coroutines.* import kotlinx.coroutines.*
import net.idik.lib.slimadapter.SlimAdapter import net.idik.lib.slimadapter.SlimAdapter
import java.lang.Exception import java.lang.Exception
@ -53,23 +52,24 @@ class BottomSheetColorPicker(
private var loadingJobs: ArrayList<Job> = ArrayList() private var loadingJobs: ArrayList<Job> = ArrayList()
private lateinit var adapter: SlimAdapter private lateinit var adapter: SlimAdapter
override fun show() { private var binding: BottomSheetMenuHorBinding = BottomSheetMenuHorBinding.inflate(LayoutInflater.from(context))
val view = View.inflate(context, R.layout.bottom_sheet_menu_hor, null) private var listBinding: BottomSheetMenuListBinding = BottomSheetMenuListBinding.inflate(LayoutInflater.from(context))
override fun show() {
window?.setDimAmount(0f) window?.setDimAmount(0f)
// Header // Header
view.header.isVisible = header != null binding.header.isVisible = header != null
view.header_text.text = header ?: "" binding.headerText.text = header ?: ""
// Alpha // Alpha
view.alpha_selector_container.isVisible = showAlphaSelector binding.alphaSelectorContainer.isVisible = showAlphaSelector
view.alpha_selector.setProgress(alpha.toFloat()) binding.alphaSelector.setProgress(alpha.toFloat())
view.text_alpha.text = "%s: %s%%".format(context.getString(R.string.alpha), alpha) binding.textAlpha.text = "%s: %s%%".format(context.getString(R.string.alpha), alpha)
view.alpha_selector.onSeekChangeListener = object : OnSeekChangeListener { binding.alphaSelector.onSeekChangeListener = object : OnSeekChangeListener {
override fun onSeeking(seekParams: SeekParams?) { override fun onSeeking(seekParams: SeekParams?) {
seekParams?.let { seekParams?.let {
view.text_alpha.text = "%s: %s%%".format(context.getString(R.string.alpha), it.progress) binding.textAlpha.text = "%s: %s%%".format(context.getString(R.string.alpha), it.progress)
onAlphaChangeListener?.invoke(it.progress) onAlphaChangeListener?.invoke(it.progress)
} }
} }
@ -84,10 +84,9 @@ class BottomSheetColorPicker(
adapter = SlimAdapter.create() adapter = SlimAdapter.create()
loadingJobs.add(GlobalScope.launch(Dispatchers.IO) { loadingJobs.add(GlobalScope.launch(Dispatchers.IO) {
val listView = View.inflate(context, R.layout.bottom_sheet_menu_list, null) as RecyclerView listBinding.root.setHasFixedSize(true)
listView.setHasFixedSize(true)
val mLayoutManager = GridLayoutManager(context, 6) val mLayoutManager = GridLayoutManager(context, 6)
listView.layoutManager = mLayoutManager listBinding.root.layoutManager = mLayoutManager
adapter adapter
.register<Int>(R.layout.color_picker_menu_item) { item, injector -> .register<Int>(R.layout.color_picker_menu_item) { item, injector ->
@ -115,22 +114,22 @@ class BottomSheetColorPicker(
onColorSelected?.invoke(item) onColorSelected?.invoke(item)
val position = adapter.data.indexOf(item) val position = adapter.data.indexOf(item)
adapter.notifyItemChanged(position) adapter.notifyItemChanged(position)
(listView.layoutManager as GridLayoutManager).scrollToPositionWithOffset(position,0) (listBinding.root.layoutManager as GridLayoutManager).scrollToPositionWithOffset(position,0)
} }
} }
.attachTo(listView) .attachTo(listBinding.root)
adapter.updateData(colors.toList()) adapter.updateData(colors.toList())
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
view.color_loader.isVisible = false binding.colorLoader.isVisible = false
view.list_container.addView(listView) binding.listContainer.addView(listBinding.root)
this@BottomSheetColorPicker.behavior.state = BottomSheetBehavior.STATE_EXPANDED this@BottomSheetColorPicker.behavior.state = BottomSheetBehavior.STATE_EXPANDED
view.list_container.isVisible = true binding.listContainer.isVisible = true
} }
}) })
setContentView(view) setContentView(binding.root)
super.show() super.show()
} }

View File

@ -1,6 +1,7 @@
package com.tommasoberlose.anotherwidget.components package com.tommasoberlose.anotherwidget.components
import android.content.Context import android.content.Context
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.TextView import android.widget.TextView
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
@ -8,9 +9,8 @@ import androidx.core.view.isVisible
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import kotlinx.android.synthetic.main.bottom_sheet_menu.view.* import com.tommasoberlose.anotherwidget.databinding.BottomSheetMenuBinding
import kotlinx.android.synthetic.main.bottom_sheet_menu_item.view.* import com.tommasoberlose.anotherwidget.databinding.BottomSheetMenuItemBinding
import org.w3c.dom.Text
/** /**
* [BottomSheetDialogFragment] that uses a custom * [BottomSheetDialogFragment] that uses a custom
@ -24,6 +24,8 @@ open class BottomSheetMenu<T>(context: Context, private val header: String? = nu
private var callback: ((selectedValue: T) -> Unit)? = null private var callback: ((selectedValue: T) -> Unit)? = null
private var multipleSelectionCallback: ((selectedValues: ArrayList<T>) -> Unit)? = null private var multipleSelectionCallback: ((selectedValues: ArrayList<T>) -> Unit)? = null
private var binding = BottomSheetMenuBinding.inflate(LayoutInflater.from(context))
fun setSelectedValue(res: T): BottomSheetMenu<T> { fun setSelectedValue(res: T): BottomSheetMenu<T> {
selectedRes = ArrayList(listOf(res)) selectedRes = ArrayList(listOf(res))
return this return this
@ -50,33 +52,31 @@ open class BottomSheetMenu<T>(context: Context, private val header: String? = nu
} }
override fun show() { override fun show() {
val view = View.inflate(context, R.layout.bottom_sheet_menu, null)
// Header // Header
view.header.isVisible = header != null binding.header.isVisible = header != null
view.header_text.text = header ?: "" binding.headerText.text = header ?: ""
view.warning_text.isVisible = message != null binding.warningText.isVisible = message != null
view.warning_text.text = message ?: "" binding.warningText.text = message ?: ""
view.warning_text.setTextColor(ContextCompat.getColor(context, if (isMessageWarning) R.color.warningColorText else R.color.colorSecondaryText)) binding.warningText.setTextColor(ContextCompat.getColor(context, if (isMessageWarning) R.color.warningColorText else R.color.colorSecondaryText))
// Menu // Menu
for (item in items) { for (item in items) {
val itemBinding = BottomSheetMenuItemBinding.inflate(LayoutInflater.from(context))
if (item.value != null) { if (item.value != null) {
val itemView = View.inflate(context, R.layout.bottom_sheet_menu_item, null) itemBinding.label.text = item.title
itemView.label.text = item.title
if (isMultiSelection) { if (isMultiSelection) {
itemView.icon_check.isVisible = selectedRes.contains(item.value) itemBinding.iconCheck.isVisible = selectedRes.contains(item.value)
itemView.label.setTextColor( itemBinding.label.setTextColor(
if (selectedRes.contains(item.value)) ContextCompat.getColor( if (selectedRes.contains(item.value)) ContextCompat.getColor(
context, context,
R.color.colorPrimaryText R.color.colorPrimaryText
) else ContextCompat.getColor(context, R.color.colorSecondaryText) ) else ContextCompat.getColor(context, R.color.colorSecondaryText)
) )
} else { } else {
itemView.isSelected = selectedRes.contains(item.value) itemBinding.root.isSelected = selectedRes.contains(item.value)
} }
itemView.setOnClickListener { itemBinding.root.setOnClickListener {
if (!isMultiSelection) { if (!isMultiSelection) {
callback?.invoke(item.value) callback?.invoke(item.value)
this.dismiss() this.dismiss()
@ -88,8 +88,8 @@ open class BottomSheetMenu<T>(context: Context, private val header: String? = nu
} }
multipleSelectionCallback?.invoke(selectedRes) multipleSelectionCallback?.invoke(selectedRes)
itemView.icon_check.isVisible = selectedRes.contains(item.value) itemBinding.iconCheck.isVisible = selectedRes.contains(item.value)
itemView.label.setTextColor( itemBinding.label.setTextColor(
if (selectedRes.contains(item.value)) ContextCompat.getColor( if (selectedRes.contains(item.value)) ContextCompat.getColor(
context, context,
R.color.colorPrimaryText R.color.colorPrimaryText
@ -97,17 +97,16 @@ open class BottomSheetMenu<T>(context: Context, private val header: String? = nu
) )
} }
item.renderCallback?.invoke(itemView.label) item.renderCallback?.invoke(itemBinding.label)
} }
view.menu.addView(itemView) binding.menu.addView(itemBinding.root)
} else { } else {
val itemView = View.inflate(context, R.layout.bottom_sheet_menu_divider, null) itemBinding.label.text = item.title
itemView.label.text = item.title binding.menu.addView(itemBinding.root)
view.menu.addView(itemView)
} }
} }
setContentView(view) setContentView(binding.root)
super.show() super.show()
} }

View File

@ -5,32 +5,33 @@ import android.view.View
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.databinding.WeatherProviderSettingsLayoutBinding
import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.WeatherHelper import com.tommasoberlose.anotherwidget.helpers.WeatherHelper
import com.tommasoberlose.anotherwidget.utils.openURI import com.tommasoberlose.anotherwidget.utils.openURI
import kotlinx.android.synthetic.main.weather_provider_settings_layout.view.*
class BottomSheetWeatherProviderSettings(context: Context, callback: () -> Unit) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) { class BottomSheetWeatherProviderSettings(context: Context, callback: () -> Unit) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) {
private var binding: WeatherProviderSettingsLayoutBinding = WeatherProviderSettingsLayoutBinding.inflate(android.view.LayoutInflater.from(context))
init { init {
val view = View.inflate(context, R.layout.weather_provider_settings_layout, null) binding.apiKeyContainer.isVisible = WeatherHelper.isKeyRequired()
view.api_key_container.isVisible = WeatherHelper.isKeyRequired() binding.actionSaveKey.isVisible = WeatherHelper.isKeyRequired()
view.action_save_key.isVisible = WeatherHelper.isKeyRequired()
WeatherHelper.getProviderInfoTitle(context).let { title -> WeatherHelper.getProviderInfoTitle(context).let { title ->
view.info_title.text = title binding.infoTitle.text = title
view.info_title.isVisible = title != "" binding.infoTitle.isVisible = title != ""
} }
WeatherHelper.getProviderInfoSubtitle(context).let { subtitle -> WeatherHelper.getProviderInfoSubtitle(context).let { subtitle ->
view.info_subtitle.text = subtitle binding.infoSubtitle.text = subtitle
view.info_subtitle.isVisible = subtitle != "" binding.infoSubtitle.isVisible = subtitle != ""
} }
view.info_provider.text = WeatherHelper.getProviderName(context) binding.infoProvider.text = WeatherHelper.getProviderName(context)
view.api_key.editText?.setText(when (Constants.WeatherProvider.fromInt(Preferences.weatherProvider)) { binding.apiKey.editText?.setText(when (Constants.WeatherProvider.fromInt(Preferences.weatherProvider)) {
Constants.WeatherProvider.OPEN_WEATHER -> Preferences.weatherProviderApiOpen Constants.WeatherProvider.OPEN_WEATHER -> Preferences.weatherProviderApiOpen
Constants.WeatherProvider.WEATHER_BIT -> Preferences.weatherProviderApiWeatherBit Constants.WeatherProvider.WEATHER_BIT -> Preferences.weatherProviderApiWeatherBit
Constants.WeatherProvider.WEATHER_API -> Preferences.weatherProviderApiWeatherApi Constants.WeatherProvider.WEATHER_API -> Preferences.weatherProviderApiWeatherApi
@ -41,12 +42,12 @@ class BottomSheetWeatherProviderSettings(context: Context, callback: () -> Unit)
null -> "" null -> ""
}) })
view.action_open_provider.setOnClickListener { binding.actionOpenProvider.setOnClickListener {
context.openURI(WeatherHelper.getProviderLink()) context.openURI(WeatherHelper.getProviderLink())
} }
view.action_save_key.setOnClickListener { binding.actionSaveKey.setOnClickListener {
val key = view.api_key.editText?.text.toString() val key = binding.apiKey.editText?.text.toString()
when (Constants.WeatherProvider.fromInt(Preferences.weatherProvider)) { when (Constants.WeatherProvider.fromInt(Preferences.weatherProvider)) {
Constants.WeatherProvider.OPEN_WEATHER -> Preferences.weatherProviderApiOpen = key Constants.WeatherProvider.OPEN_WEATHER -> Preferences.weatherProviderApiOpen = key
Constants.WeatherProvider.WEATHER_BIT -> Preferences.weatherProviderApiWeatherBit = key Constants.WeatherProvider.WEATHER_BIT -> Preferences.weatherProviderApiWeatherBit = key
@ -59,6 +60,6 @@ class BottomSheetWeatherProviderSettings(context: Context, callback: () -> Unit)
dismiss() dismiss()
} }
setContentView(view) setContentView(binding.root)
} }
} }

View File

@ -1,28 +1,30 @@
package com.tommasoberlose.anotherwidget.components package com.tommasoberlose.anotherwidget.components
import android.content.Context import android.content.Context
import android.view.LayoutInflater
import android.view.View import android.view.View
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.databinding.CustomNotesDialogLayoutBinding
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import kotlinx.android.synthetic.main.custom_notes_dialog_layout.view.*
class CustomNotesDialog(context: Context, callback: (() -> Unit)?) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) { class CustomNotesDialog(context: Context, callback: (() -> Unit)?) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) {
init { private var binding: CustomNotesDialogLayoutBinding = CustomNotesDialogLayoutBinding.inflate(LayoutInflater.from(context))
val view = View.inflate(context, R.layout.custom_notes_dialog_layout, null)
view.notes.setText(Preferences.customNotes)
view.action_positive.setOnClickListener { init {
Preferences.customNotes = view.notes.text.toString() binding.notes.setText(Preferences.customNotes)
binding.actionPositive.setOnClickListener {
Preferences.customNotes = binding.notes.text.toString()
this.dismiss() this.dismiss()
callback?.invoke() callback?.invoke()
} }
view.notes.requestFocus() binding.notes.requestFocus()
setContentView(view) setContentView(binding.root)
} }
} }

View File

@ -7,6 +7,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Build import android.os.Build
import android.view.LayoutInflater
import android.view.View import android.view.View
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.google.android.gms.auth.api.signin.GoogleSignIn import com.google.android.gms.auth.api.signin.GoogleSignIn
@ -19,6 +20,7 @@ import com.karumi.dexter.PermissionToken
import com.karumi.dexter.listener.PermissionRequest import com.karumi.dexter.listener.PermissionRequest
import com.karumi.dexter.listener.multi.MultiplePermissionsListener import com.karumi.dexter.listener.multi.MultiplePermissionsListener
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.databinding.GlanceProviderSettingsLayoutBinding
import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.ActiveNotificationsHelper import com.tommasoberlose.anotherwidget.helpers.ActiveNotificationsHelper
@ -30,17 +32,17 @@ import com.tommasoberlose.anotherwidget.ui.activities.tabs.AppNotificationsFilte
import com.tommasoberlose.anotherwidget.ui.activities.tabs.MusicPlayersFilterActivity import com.tommasoberlose.anotherwidget.ui.activities.tabs.MusicPlayersFilterActivity
import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
import kotlinx.android.synthetic.main.glance_provider_settings_layout.view.*
import kotlinx.coroutines.* import kotlinx.coroutines.*
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
class GlanceSettingsDialog(val context: Activity, val provider: Constants.GlanceProviderId, private val statusCallback: (() -> Unit)?) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) { class GlanceSettingsDialog(val context: Activity, val provider: Constants.GlanceProviderId, private val statusCallback: (() -> Unit)?) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) {
private var binding: GlanceProviderSettingsLayoutBinding = GlanceProviderSettingsLayoutBinding.inflate(LayoutInflater.from(context))
override fun show() { override fun show() {
val view = View.inflate(context, R.layout.glance_provider_settings_layout, null)
/* TITLE */ /* TITLE */
view.title.text = when (provider) { binding.title.text = when (provider) {
Constants.GlanceProviderId.PLAYING_SONG -> context.getString(R.string.settings_show_music_title) Constants.GlanceProviderId.PLAYING_SONG -> context.getString(R.string.settings_show_music_title)
Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> context.getString(R.string.settings_show_next_alarm_title) Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> context.getString(R.string.settings_show_next_alarm_title)
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> context.getString(R.string.settings_low_battery_level_title) Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> context.getString(R.string.settings_low_battery_level_title)
@ -52,7 +54,7 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
} }
/* SUBTITLE*/ /* SUBTITLE*/
view.subtitle.text = when (provider) { binding.subtitle.text = when (provider) {
Constants.GlanceProviderId.PLAYING_SONG -> context.getString(R.string.settings_show_music_subtitle) Constants.GlanceProviderId.PLAYING_SONG -> context.getString(R.string.settings_show_music_subtitle)
Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> context.getString(R.string.settings_show_next_alarm_subtitle) Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> context.getString(R.string.settings_show_next_alarm_subtitle)
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> context.getString(R.string.settings_low_battery_level_subtitle) Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> context.getString(R.string.settings_low_battery_level_subtitle)
@ -64,50 +66,50 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
} }
/* SONG */ /* SONG */
view.action_filter_music_players.isVisible = provider == Constants.GlanceProviderId.PLAYING_SONG binding.actionFilterMusicPlayers.isVisible = provider == Constants.GlanceProviderId.PLAYING_SONG
if (provider == Constants.GlanceProviderId.PLAYING_SONG) { if (provider == Constants.GlanceProviderId.PLAYING_SONG) {
view.action_filter_music_players.setOnClickListener { binding.actionFilterMusicPlayers.setOnClickListener {
dismiss() dismiss()
context.startActivityForResult(Intent(context, MusicPlayersFilterActivity::class.java), 0) context.startActivityForResult(Intent(context, MusicPlayersFilterActivity::class.java), 0)
} }
checkNotificationPermission(view) checkNotificationPermission()
} }
/* ALARM */ /* ALARM */
view.alarm_set_by_container.isVisible = provider == Constants.GlanceProviderId.NEXT_CLOCK_ALARM binding.alarmSetByContainer.isVisible = provider == Constants.GlanceProviderId.NEXT_CLOCK_ALARM
if (provider == Constants.GlanceProviderId.NEXT_CLOCK_ALARM) { if (provider == Constants.GlanceProviderId.NEXT_CLOCK_ALARM) {
view.header.text = context.getString(R.string.information_header) binding.header.text = context.getString(R.string.information_header)
view.warning_container.isVisible = false binding.warningContainer.isVisible = false
checkNextAlarm(view) checkNextAlarm()
} }
/* GOOGLE STEPS */ /* GOOGLE STEPS */
view.action_toggle_google_fit.isVisible = provider == Constants.GlanceProviderId.GOOGLE_FIT_STEPS binding.actionToggleGoogleFit.isVisible = provider == Constants.GlanceProviderId.GOOGLE_FIT_STEPS
if (provider == Constants.GlanceProviderId.GOOGLE_FIT_STEPS) { if (provider == Constants.GlanceProviderId.GOOGLE_FIT_STEPS) {
view.warning_container.isVisible = false binding.warningContainer.isVisible = false
checkFitnessPermission(view) checkFitnessPermission()
checkGoogleFitConnection(view) checkGoogleFitConnection()
} }
/* BATTERY INFO */ /* BATTERY INFO */
if (provider == Constants.GlanceProviderId.BATTERY_LEVEL_LOW) { if (provider == Constants.GlanceProviderId.BATTERY_LEVEL_LOW) {
view.warning_container.isVisible = false binding.warningContainer.isVisible = false
view.header.isVisible = false binding.header.isVisible = false
view.divider.isVisible = false binding.divider.isVisible = false
} }
/* NOTIFICATIONS */ /* NOTIFICATIONS */
view.action_filter_notifications_app.isVisible = provider == Constants.GlanceProviderId.NOTIFICATIONS binding.actionFilterNotificationsApp.isVisible = provider == Constants.GlanceProviderId.NOTIFICATIONS
view.action_change_notification_timer.isVisible = provider == Constants.GlanceProviderId.NOTIFICATIONS binding.actionChangeNotificationTimer.isVisible = provider == Constants.GlanceProviderId.NOTIFICATIONS
if (provider == Constants.GlanceProviderId.NOTIFICATIONS) { if (provider == Constants.GlanceProviderId.NOTIFICATIONS) {
checkLastNotificationsPermission(view) checkLastNotificationsPermission()
val stringArray = context.resources.getStringArray(R.array.glance_notifications_timeout) val stringArray = context.resources.getStringArray(R.array.glance_notifications_timeout)
view.action_filter_notifications_app.setOnClickListener { binding.actionFilterNotificationsApp.setOnClickListener {
dismiss() dismiss()
context.startActivityForResult(Intent(context, AppNotificationsFilterActivity::class.java), 0) context.startActivityForResult(Intent(context, AppNotificationsFilterActivity::class.java), 0)
} }
view.notification_timer_label.text = stringArray[Preferences.hideNotificationAfter] binding.notificationTimerLabel.text = stringArray[Preferences.hideNotificationAfter]
view.action_change_notification_timer.setOnClickListener { binding.actionChangeNotificationTimer.setOnClickListener {
val dialog = BottomSheetMenu<Int>(context, header = context.getString(R.string.glance_notification_hide_timeout_title)).setSelectedValue(Preferences.hideNotificationAfter) val dialog = BottomSheetMenu<Int>(context, header = context.getString(R.string.glance_notification_hide_timeout_title)).setSelectedValue(Preferences.hideNotificationAfter)
Constants.GlanceNotificationTimer.values().forEachIndexed { index, timeout -> Constants.GlanceNotificationTimer.values().forEachIndexed { index, timeout ->
dialog.addItem(stringArray[index], timeout.value) dialog.addItem(stringArray[index], timeout.value)
@ -121,20 +123,20 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
/* GREETINGS */ /* GREETINGS */
if (provider == Constants.GlanceProviderId.GREETINGS) { if (provider == Constants.GlanceProviderId.GREETINGS) {
view.warning_container.isVisible = false binding.warningContainer.isVisible = false
view.header.isVisible = false binding.header.isVisible = false
view.divider.isVisible = false binding.divider.isVisible = false
} }
/* EVENTS */ /* EVENTS */
if (provider == Constants.GlanceProviderId.EVENTS) { if (provider == Constants.GlanceProviderId.EVENTS) {
view.header.isVisible = false binding.header.isVisible = false
view.divider.isVisible = false binding.divider.isVisible = false
checkCalendarConfig(view) checkCalendarConfig()
} }
/* TOGGLE */ /* TOGGLE */
view.provider_switch.setCheckedImmediatelyNoEvent(when (provider) { binding.providerSwitch.setCheckedImmediatelyNoEvent(when (provider) {
Constants.GlanceProviderId.PLAYING_SONG -> Preferences.showMusic Constants.GlanceProviderId.PLAYING_SONG -> Preferences.showMusic
Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> Preferences.showNextAlarm Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> Preferences.showNextAlarm
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> Preferences.showBatteryCharging Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> Preferences.showBatteryCharging
@ -147,7 +149,7 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
var job: Job? = null var job: Job? = null
view.provider_switch.setOnCheckedChangeListener { _, isChecked -> binding.providerSwitch.setOnCheckedChangeListener { _, isChecked ->
job?.cancel() job?.cancel()
job = GlobalScope.launch(Dispatchers.IO) { job = GlobalScope.launch(Dispatchers.IO) {
delay(300) delay(300)
@ -155,18 +157,18 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
when (provider) { when (provider) {
Constants.GlanceProviderId.PLAYING_SONG -> { Constants.GlanceProviderId.PLAYING_SONG -> {
Preferences.showMusic = isChecked Preferences.showMusic = isChecked
checkNotificationPermission(view) checkNotificationPermission()
} }
Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> { Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> {
Preferences.showNextAlarm = isChecked Preferences.showNextAlarm = isChecked
checkNextAlarm(view) checkNextAlarm()
} }
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> { Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> {
Preferences.showBatteryCharging = isChecked Preferences.showBatteryCharging = isChecked
} }
Constants.GlanceProviderId.NOTIFICATIONS -> { Constants.GlanceProviderId.NOTIFICATIONS -> {
Preferences.showNotifications = isChecked Preferences.showNotifications = isChecked
checkLastNotificationsPermission(view) checkLastNotificationsPermission()
} }
Constants.GlanceProviderId.GREETINGS -> { Constants.GlanceProviderId.GREETINGS -> {
Preferences.showGreetings = isChecked Preferences.showGreetings = isChecked
@ -194,9 +196,9 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
Preferences.showDailySteps = false Preferences.showDailySteps = false
} }
view.warning_container.isVisible = false binding.warningContainer.isVisible = false
checkFitnessPermission(view) checkFitnessPermission()
checkGoogleFitConnection(view) checkGoogleFitConnection()
} }
Constants.GlanceProviderId.EVENTS -> { Constants.GlanceProviderId.EVENTS -> {
Preferences.showEventsAsGlanceProvider = isChecked Preferences.showEventsAsGlanceProvider = isChecked
@ -209,11 +211,11 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
} }
} }
setContentView(view) setContentView(binding.root)
super.show() super.show()
} }
private fun checkNextAlarm(view: View) { private fun checkNextAlarm() {
with(context.getSystemService(Context.ALARM_SERVICE) as AlarmManager) { with(context.getSystemService(Context.ALARM_SERVICE) as AlarmManager) {
val alarm = nextAlarmClock val alarm = nextAlarmClock
if (alarm != null && alarm.showIntent != null) { if (alarm != null && alarm.showIntent != null) {
@ -223,71 +225,71 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
} catch (e: Exception) { } catch (e: Exception) {
alarm.showIntent?.creatorPackage ?: "" alarm.showIntent?.creatorPackage ?: ""
} }
view.alarm_set_by_title.text = context.getString(R.string.settings_show_next_alarm_app_title).format(appNameOrPackage) binding.alarmSetByTitle.text = context.getString(R.string.settings_show_next_alarm_app_title).format(appNameOrPackage)
view.alarm_set_by_subtitle.text = if (AlarmHelper.isAlarmProbablyWrong(context)) context.getString(R.string.settings_show_next_alarm_app_subtitle_wrong) else context.getString(R.string.settings_show_next_alarm_app_subtitle_correct) binding.alarmSetBySubtitle.text = if (AlarmHelper.isAlarmProbablyWrong(context)) context.getString(R.string.settings_show_next_alarm_app_subtitle_wrong) else context.getString(R.string.settings_show_next_alarm_app_subtitle_correct)
view.alarm_set_by_container.isVisible = true binding.alarmSetByContainer.isVisible = true
} else { } else {
view.alarm_set_by_container.isVisible = false binding.alarmSetByContainer.isVisible = false
view.header.isVisible = false binding.header.isVisible = false
view.divider.isVisible = false binding.divider.isVisible = false
} }
} }
statusCallback?.invoke() statusCallback?.invoke()
} }
private fun checkCalendarConfig(view: View) { private fun checkCalendarConfig() {
if (!Preferences.showEvents || !context.checkGrantedPermission(Manifest.permission.READ_CALENDAR)) { if (!Preferences.showEvents || !context.checkGrantedPermission(Manifest.permission.READ_CALENDAR)) {
view.warning_container.isVisible = true binding.warningContainer.isVisible = true
view.warning_title.text = context.getString(R.string.settings_show_events_as_glance_provider_error) binding.warningTitle.text = context.getString(R.string.settings_show_events_as_glance_provider_error)
view.warning_container.setOnClickListener { binding.warningContainer.setOnClickListener {
dismiss() dismiss()
EventBus.getDefault().post(MainFragment.ChangeTabEvent(1)) EventBus.getDefault().post(MainFragment.ChangeTabEvent(1))
} }
} else { } else {
view.warning_container.isVisible = false binding.warningContainer.isVisible = false
} }
} }
private fun checkNotificationPermission(view: View) { private fun checkNotificationPermission() {
when { when {
ActiveNotificationsHelper.checkNotificationAccess(context) -> { ActiveNotificationsHelper.checkNotificationAccess(context) -> {
view.warning_container.isVisible = false binding.warningContainer.isVisible = false
MediaPlayerHelper.updatePlayingMediaInfo(context) MediaPlayerHelper.updatePlayingMediaInfo(context)
} }
Preferences.showMusic -> { Preferences.showMusic -> {
view.warning_container.isVisible = true binding.warningContainer.isVisible = true
view.warning_title.text = context.getString(R.string.settings_request_notification_access) binding.warningTitle.text = context.getString(R.string.settings_request_notification_access)
view.warning_container.setOnClickListener { binding.warningContainer.setOnClickListener {
context.startActivity(Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS")) context.startActivity(Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"))
} }
} }
else -> { else -> {
view.warning_container.isVisible = false binding.warningContainer.isVisible = false
} }
} }
statusCallback?.invoke() statusCallback?.invoke()
} }
private fun checkLastNotificationsPermission(view: View) { private fun checkLastNotificationsPermission() {
when { when {
ActiveNotificationsHelper.checkNotificationAccess(context) -> { ActiveNotificationsHelper.checkNotificationAccess(context) -> {
view.warning_container.isVisible = false binding.warningContainer.isVisible = false
} }
Preferences.showNotifications -> { Preferences.showNotifications -> {
view.warning_container.isVisible = true binding.warningContainer.isVisible = true
view.warning_title.text = context.getString(R.string.settings_request_last_notification_access) binding.warningTitle.text = context.getString(R.string.settings_request_last_notification_access)
view.warning_container.setOnClickListener { binding.warningContainer.setOnClickListener {
context.startActivity(Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS")) context.startActivity(Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"))
} }
} }
else -> { else -> {
view.warning_container.isVisible = false binding.warningContainer.isVisible = false
} }
} }
statusCallback?.invoke() statusCallback?.invoke()
} }
private fun checkFitnessPermission(view: View) { private fun checkFitnessPermission() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || context.checkGrantedPermission( if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || context.checkGrantedPermission(
Manifest.permission.ACTIVITY_RECOGNITION) Manifest.permission.ACTIVITY_RECOGNITION)
) { ) {
@ -298,10 +300,10 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
} }
} else if (Preferences.showDailySteps) { } else if (Preferences.showDailySteps) {
ActivityDetectionReceiver.unregisterFence(context) ActivityDetectionReceiver.unregisterFence(context)
view.warning_container.isVisible = true binding.warningContainer.isVisible = true
view.warning_title.text = context.getString(R.string.settings_request_fitness_access) binding.warningTitle.text = context.getString(R.string.settings_request_fitness_access)
view.warning_container.setOnClickListener { binding.warningContainer.setOnClickListener {
requireFitnessPermission(view) requireFitnessPermission()
} }
} else { } else {
ActivityDetectionReceiver.unregisterFence(context) ActivityDetectionReceiver.unregisterFence(context)
@ -309,36 +311,36 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
statusCallback?.invoke() statusCallback?.invoke()
} }
private fun checkGoogleFitConnection(view: View) { private fun checkGoogleFitConnection() {
val account: GoogleSignInAccount? = GoogleSignIn.getLastSignedInAccount(context) val account: GoogleSignInAccount? = GoogleSignIn.getLastSignedInAccount(context)
if (!GoogleSignIn.hasPermissions(account, if (!GoogleSignIn.hasPermissions(account,
ActivityDetectionReceiver.FITNESS_OPTIONS ActivityDetectionReceiver.FITNESS_OPTIONS
)) { )) {
view.warning_container.isVisible = true binding.warningContainer.isVisible = true
view.warning_title.text = context.getString(R.string.settings_request_fitness_access) binding.warningTitle.text = context.getString(R.string.settings_request_fitness_access)
view.warning_container.setOnClickListener { binding.warningContainer.setOnClickListener {
GoogleSignIn.requestPermissions( GoogleSignIn.requestPermissions(
context, context,
1, 1,
account, account,
ActivityDetectionReceiver.FITNESS_OPTIONS) ActivityDetectionReceiver.FITNESS_OPTIONS)
} }
view.action_connect_to_google_fit.isVisible = true binding.actionConnectToGoogleFit.isVisible = true
view.action_disconnect_to_google_fit.isVisible = false binding.actionDisconnectToGoogleFit.isVisible = false
view.action_connect_to_google_fit.setOnClickListener { binding.actionConnectToGoogleFit.setOnClickListener {
GoogleSignIn.requestPermissions( GoogleSignIn.requestPermissions(
context, context,
1, 1,
account, account,
ActivityDetectionReceiver.FITNESS_OPTIONS) ActivityDetectionReceiver.FITNESS_OPTIONS)
} }
view.action_disconnect_to_google_fit.setOnClickListener(null) binding.actionDisconnectToGoogleFit.setOnClickListener(null)
view.google_fit_status_label.text = context.getString(R.string.google_fit_account_not_connected) binding.googleFitStatusLabel.text = context.getString(R.string.google_fit_account_not_connected)
} else { } else {
view.action_connect_to_google_fit.isVisible = false binding.actionConnectToGoogleFit.isVisible = false
view.action_disconnect_to_google_fit.isVisible = true binding.actionDisconnectToGoogleFit.isVisible = true
view.action_connect_to_google_fit.setOnClickListener(null) binding.actionConnectToGoogleFit.setOnClickListener(null)
view.action_disconnect_to_google_fit.setOnClickListener { binding.actionDisconnectToGoogleFit.setOnClickListener {
GoogleSignIn.getClient(context, GoogleSignInOptions.Builder( GoogleSignIn.getClient(context, GoogleSignInOptions.Builder(
GoogleSignInOptions.DEFAULT_SIGN_IN).addExtension( GoogleSignInOptions.DEFAULT_SIGN_IN).addExtension(
ActivityDetectionReceiver.FITNESS_OPTIONS ActivityDetectionReceiver.FITNESS_OPTIONS
@ -346,11 +348,11 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
show() show()
} }
} }
view.google_fit_status_label.text = context.getString(R.string.google_fit_account_connected) binding.googleFitStatusLabel.text = context.getString(R.string.google_fit_account_connected)
} }
} }
private fun requireFitnessPermission(view: View) { private fun requireFitnessPermission() {
Dexter.withContext(context) Dexter.withContext(context)
.withPermissions( .withPermissions(
"com.google.android.gms.permission.ACTIVITY_RECOGNITION", "com.google.android.gms.permission.ACTIVITY_RECOGNITION",
@ -358,7 +360,7 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) Manifest.permission.ACTIVITY_RECOGNITION else "com.google.android.gms.permission.ACTIVITY_RECOGNITION" if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) Manifest.permission.ACTIVITY_RECOGNITION else "com.google.android.gms.permission.ACTIVITY_RECOGNITION"
).withListener(object: MultiplePermissionsListener { ).withListener(object: MultiplePermissionsListener {
override fun onPermissionsChecked(report: MultiplePermissionsReport?) { override fun onPermissionsChecked(report: MultiplePermissionsReport?) {
checkFitnessPermission(view) checkFitnessPermission()
} }
override fun onPermissionRationaleShouldBeShown( override fun onPermissionRationaleShouldBeShown(
permissions: MutableList<PermissionRequest>?, permissions: MutableList<PermissionRequest>?,

View File

@ -1,43 +1,42 @@
package com.tommasoberlose.anotherwidget.components package com.tommasoberlose.anotherwidget.components
import android.content.Context import android.content.Context
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.ImageView import android.widget.ImageView
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.databinding.BottomSheetMenuBinding
import com.tommasoberlose.anotherwidget.databinding.IconPackMenuItemBinding
import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.WeatherHelper import com.tommasoberlose.anotherwidget.helpers.WeatherHelper
import kotlinx.android.synthetic.main.bottom_sheet_menu.view.*
import kotlinx.android.synthetic.main.bottom_sheet_menu.view.header
import kotlinx.android.synthetic.main.fragment_weather_settings.*
import kotlinx.android.synthetic.main.icon_pack_menu_item.view.*
class IconPackSelector(context: Context, private val header: String? = null) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) { class IconPackSelector(context: Context, private val header: String? = null) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) {
private var binding = BottomSheetMenuBinding.inflate(LayoutInflater.from(context))
private var itemBinding = IconPackMenuItemBinding.inflate(LayoutInflater.from(context))
override fun show() { override fun show() {
val view = View.inflate(context, R.layout.bottom_sheet_menu, null)
// Header // Header
view.header.isVisible = header != null binding.header.isVisible = header != null
view.header_text.text = header ?: "" binding.headerText.text = header ?: ""
view.warning_text.isVisible = false binding.warningText.isVisible = false
// Menu // Menu
for (item in Constants.WeatherIconPack.values()) { for (item in Constants.WeatherIconPack.values()) {
val itemView = View.inflate(context, R.layout.icon_pack_menu_item, null) itemBinding.label.text = context.getString(R.string.settings_weather_icon_pack_default).format(item.value + 1)
itemView.label.text = context.getString(R.string.settings_weather_icon_pack_default).format(item.value + 1) itemBinding.root.isSelected = item.value == Preferences.weatherIconPack
itemView.isSelected = item.value == Preferences.weatherIconPack
itemView.icon_1.setImageDrawable(ContextCompat.getDrawable(context, WeatherHelper.getWeatherIconResource(context, "01d", item.value))) itemBinding.icon1.setImageDrawable(ContextCompat.getDrawable(context, WeatherHelper.getWeatherIconResource(context, "01d", item.value)))
itemView.icon_2.setImageDrawable(ContextCompat.getDrawable(context, WeatherHelper.getWeatherIconResource(context, "01n", item.value))) itemBinding.icon2.setImageDrawable(ContextCompat.getDrawable(context, WeatherHelper.getWeatherIconResource(context, "01n", item.value)))
itemView.icon_3.setImageDrawable(ContextCompat.getDrawable(context, WeatherHelper.getWeatherIconResource(context, "10d", item.value))) itemBinding.icon3.setImageDrawable(ContextCompat.getDrawable(context, WeatherHelper.getWeatherIconResource(context, "10d", item.value)))
itemView.icon_4.setImageDrawable(ContextCompat.getDrawable(context, WeatherHelper.getWeatherIconResource(context, "09n", item.value))) itemBinding.icon4.setImageDrawable(ContextCompat.getDrawable(context, WeatherHelper.getWeatherIconResource(context, "09n", item.value)))
listOf<ImageView>(itemView.icon_1, itemView.icon_2, itemView.icon_3, itemView.icon_4).forEach { listOf<ImageView>(itemBinding.icon1, itemBinding.icon2, itemBinding.icon3, itemBinding.icon4).forEach {
if (item == Constants.WeatherIconPack.MINIMAL) { if (item == Constants.WeatherIconPack.MINIMAL) {
it.setColorFilter(ContextCompat.getColor(context, R.color.colorPrimaryText)) it.setColorFilter(ContextCompat.getColor(context, R.color.colorPrimaryText))
} else { } else {
@ -45,13 +44,13 @@ class IconPackSelector(context: Context, private val header: String? = null) : B
} }
} }
itemView.setOnClickListener { itemBinding.root.setOnClickListener {
Preferences.weatherIconPack = item.value Preferences.weatherIconPack = item.value
this.dismiss() this.dismiss()
} }
view.menu.addView(itemView) binding.menu.addView(itemBinding.root)
} }
setContentView(view) setContentView(binding.root)
super.show() super.show()
} }
} }

View File

@ -1,11 +1,11 @@
package com.tommasoberlose.anotherwidget.components package com.tommasoberlose.anotherwidget.components
import android.content.Context import android.content.Context
import android.view.View import android.view.LayoutInflater
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import kotlinx.android.synthetic.main.bottom_sheet_dialog.view.* import com.tommasoberlose.anotherwidget.databinding.BottomSheetDialogBinding
typealias DialogCallback = () -> Unit typealias DialogCallback = () -> Unit
@ -20,6 +20,8 @@ class MaterialBottomSheetDialog(
private var positiveCallback: DialogCallback? = null private var positiveCallback: DialogCallback? = null
private var negativeCallback: DialogCallback? = null private var negativeCallback: DialogCallback? = null
private var binding = BottomSheetDialogBinding.inflate(LayoutInflater.from(context))
fun setPositiveButton(label: String? = context.getString(android.R.string.ok), callback: DialogCallback? = null): MaterialBottomSheetDialog { fun setPositiveButton(label: String? = context.getString(android.R.string.ok), callback: DialogCallback? = null): MaterialBottomSheetDialog {
positiveButtonLabel = label positiveButtonLabel = label
positiveCallback = callback positiveCallback = callback
@ -33,30 +35,28 @@ class MaterialBottomSheetDialog(
} }
override fun show() { override fun show() {
val view = View.inflate(context, R.layout.bottom_sheet_dialog, null)
// Header // Header
view.title.isVisible = title != null binding.title.isVisible = title != null
view.title.text = title ?: "" binding.title.text = title ?: ""
view.message.isVisible = message != null binding.message.isVisible = message != null
view.message.text = message ?: "" binding.message.text = message ?: ""
view.action_positive.isVisible = positiveButtonLabel != null binding.actionPositive.isVisible = positiveButtonLabel != null
view.action_positive.text = positiveButtonLabel ?: "" binding.actionPositive.text = positiveButtonLabel ?: ""
view.action_positive.setOnClickListener { binding.actionPositive.setOnClickListener {
positiveCallback?.invoke() positiveCallback?.invoke()
this.dismiss() this.dismiss()
} }
view.action_negative.isVisible = negativeButtonLabel != null binding.actionNegative.isVisible = negativeButtonLabel != null
view.action_negative.text = negativeButtonLabel ?: "" binding.actionNegative.text = negativeButtonLabel ?: ""
view.action_negative.setOnClickListener { binding.actionNegative.setOnClickListener {
negativeCallback?.invoke() negativeCallback?.invoke()
this.dismiss() this.dismiss()
} }
setContentView(view) setContentView(binding.root)
super.show() super.show()
} }

View File

@ -16,18 +16,18 @@ import com.karumi.dexter.PermissionToken
import com.karumi.dexter.listener.PermissionRequest import com.karumi.dexter.listener.PermissionRequest
import com.karumi.dexter.listener.multi.MultiplePermissionsListener import com.karumi.dexter.listener.multi.MultiplePermissionsListener
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.databinding.ActivityMainBinding
import com.tommasoberlose.anotherwidget.global.Actions import com.tommasoberlose.anotherwidget.global.Actions
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.global.RequestCode import com.tommasoberlose.anotherwidget.global.RequestCode
import com.tommasoberlose.anotherwidget.ui.activities.tabs.WeatherProviderActivity import com.tommasoberlose.anotherwidget.ui.activities.tabs.WeatherProviderActivity
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
private var mAppWidgetId: Int = -1 private var mAppWidgetId: Int = -1
private lateinit var viewModel: MainViewModel private lateinit var viewModel: MainViewModel
private lateinit var binding: ActivityMainBinding
private val mainNavController: NavController? by lazy { private val mainNavController: NavController? by lazy {
Navigation.findNavController( Navigation.findNavController(
this, this,
@ -43,14 +43,16 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
viewModel = ViewModelProvider(this).get(MainViewModel::class.java) viewModel = ViewModelProvider(this).get(MainViewModel::class.java)
binding = ActivityMainBinding.inflate(layoutInflater)
controlExtras(intent) controlExtras(intent)
if (Preferences.showWallpaper) { if (Preferences.showWallpaper) {
requirePermission() requirePermission()
} }
setContentView(binding.root)
} }
override fun onBackPressed() { override fun onBackPressed() {
@ -86,8 +88,8 @@ class MainActivity : AppCompatActivity() {
AppWidgetManager.INVALID_APPWIDGET_ID) AppWidgetManager.INVALID_APPWIDGET_ID)
if (mAppWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) { if (mAppWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
action_add_widget.visibility = View.VISIBLE binding.actionAddWidget.visibility = View.VISIBLE
action_add_widget.setOnClickListener { binding.actionAddWidget.setOnClickListener {
addNewWidget() addNewWidget()
} }
} }

View File

@ -8,23 +8,23 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.databinding.ActivityIntegrationsBinding import com.tommasoberlose.anotherwidget.databinding.ActivityIntegrationsBinding
import com.tommasoberlose.anotherwidget.ui.viewmodels.IntegrationsViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.IntegrationsViewModel
import kotlinx.android.synthetic.main.activity_integrations.*
import net.idik.lib.slimadapter.SlimAdapter import net.idik.lib.slimadapter.SlimAdapter
class IntegrationsActivity : AppCompatActivity() { class IntegrationsActivity : AppCompatActivity() {
private lateinit var adapter: SlimAdapter private lateinit var adapter: SlimAdapter
private lateinit var viewModel: IntegrationsViewModel private lateinit var viewModel: IntegrationsViewModel
private lateinit var binding: ActivityIntegrationsBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
viewModel = ViewModelProvider(this).get(IntegrationsViewModel::class.java) viewModel = ViewModelProvider(this).get(IntegrationsViewModel::class.java)
val binding = DataBindingUtil.setContentView<ActivityIntegrationsBinding>(this, R.layout.activity_integrations) binding = ActivityIntegrationsBinding.inflate(layoutInflater)
list_view.setHasFixedSize(true) binding.listView.setHasFixedSize(true)
val mLayoutManager = LinearLayoutManager(this) val mLayoutManager = LinearLayoutManager(this)
list_view.layoutManager = mLayoutManager binding.listView.layoutManager = mLayoutManager
adapter = SlimAdapter.create() adapter = SlimAdapter.create()
adapter adapter
@ -33,10 +33,12 @@ class IntegrationsActivity : AppCompatActivity() {
.text(R.id.text, getString(R.string.default_name)) .text(R.id.text, getString(R.string.default_name))
} }
.attachTo(list_view) .attachTo(binding.listView)
setupListener() setupListener()
subscribeUi(binding, viewModel) subscribeUi(binding, viewModel)
setContentView(binding.root)
} }
private fun subscribeUi(binding: ActivityIntegrationsBinding, viewModel: IntegrationsViewModel) { private fun subscribeUi(binding: ActivityIntegrationsBinding, viewModel: IntegrationsViewModel) {
@ -45,7 +47,7 @@ class IntegrationsActivity : AppCompatActivity() {
} }
private fun setupListener() { private fun setupListener() {
action_back.setOnClickListener { binding.actionBack.setOnClickListener {
onBackPressed() onBackPressed()
} }
} }

View File

@ -15,25 +15,25 @@ import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.databinding.ActivitySupportDevBinding import com.tommasoberlose.anotherwidget.databinding.ActivitySupportDevBinding
import com.tommasoberlose.anotherwidget.ui.viewmodels.SupportDevViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.SupportDevViewModel
import com.tommasoberlose.anotherwidget.utils.toast import com.tommasoberlose.anotherwidget.utils.toast
import kotlinx.android.synthetic.main.activity_support_dev.*
import net.idik.lib.slimadapter.SlimAdapter import net.idik.lib.slimadapter.SlimAdapter
class SupportDevActivity : AppCompatActivity(), PurchasesUpdatedListener { class SupportDevActivity : AppCompatActivity(), PurchasesUpdatedListener {
private lateinit var viewModel: SupportDevViewModel private lateinit var viewModel: SupportDevViewModel
private lateinit var adapter: SlimAdapter private lateinit var adapter: SlimAdapter
private lateinit var binding: ActivitySupportDevBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
viewModel = ViewModelProvider(this).get(SupportDevViewModel::class.java) viewModel = ViewModelProvider(this).get(SupportDevViewModel::class.java)
viewModel.billingClient = BillingClient.newBuilder(this).enablePendingPurchases().setListener(this).build() viewModel.billingClient = BillingClient.newBuilder(this).enablePendingPurchases().setListener(this).build()
DataBindingUtil.setContentView<ActivitySupportDevBinding>(this, R.layout.activity_support_dev) binding = ActivitySupportDevBinding.inflate(layoutInflater)
list_view.setHasFixedSize(true) binding.listView.setHasFixedSize(true)
val mLayoutManager = LinearLayoutManager(this) val mLayoutManager = LinearLayoutManager(this)
list_view.layoutManager = mLayoutManager binding.listView.layoutManager = mLayoutManager
adapter = SlimAdapter.create() adapter = SlimAdapter.create()
adapter adapter
@ -54,20 +54,22 @@ class SupportDevActivity : AppCompatActivity(), PurchasesUpdatedListener {
viewModel.purchase(this, item) viewModel.purchase(this, item)
} }
} }
.attachTo(list_view) .attachTo(binding.listView)
viewModel.openConnection() viewModel.openConnection()
subscribeUi(viewModel) subscribeUi(viewModel)
action_back.setOnClickListener { binding.actionBack.setOnClickListener {
onBackPressed() onBackPressed()
} }
setContentView(binding.root)
} }
private fun subscribeUi(viewModel: SupportDevViewModel) { private fun subscribeUi(viewModel: SupportDevViewModel) {
viewModel.products.observe(this, Observer { viewModel.products.observe(this, Observer {
if (it.isNotEmpty()) { if (it.isNotEmpty()) {
loader.isVisible = false binding.loader.isVisible = false
} }
adapter.updateData(it.sortedWith(compareBy(SkuDetails::getPriceAmountMicros))) adapter.updateData(it.sortedWith(compareBy(SkuDetails::getPriceAmountMicros)))
}) })

View File

@ -17,7 +17,6 @@ import com.tommasoberlose.anotherwidget.databinding.ActivityAppNotificationsFilt
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.ActiveNotificationsHelper import com.tommasoberlose.anotherwidget.helpers.ActiveNotificationsHelper
import com.tommasoberlose.anotherwidget.ui.viewmodels.AppNotificationsViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.AppNotificationsViewModel
import kotlinx.android.synthetic.main.activity_app_notifications_filter.*
import kotlinx.coroutines.* import kotlinx.coroutines.*
import net.idik.lib.slimadapter.SlimAdapter import net.idik.lib.slimadapter.SlimAdapter
@ -26,16 +25,17 @@ class AppNotificationsFilterActivity : AppCompatActivity() {
private lateinit var adapter: SlimAdapter private lateinit var adapter: SlimAdapter
private lateinit var viewModel: AppNotificationsViewModel private lateinit var viewModel: AppNotificationsViewModel
private lateinit var binding: ActivityAppNotificationsFilterBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
viewModel = ViewModelProvider(this).get(AppNotificationsViewModel::class.java) viewModel = ViewModelProvider(this).get(AppNotificationsViewModel::class.java)
val binding = DataBindingUtil.setContentView<ActivityAppNotificationsFilterBinding>(this, R.layout.activity_app_notifications_filter) binding = ActivityAppNotificationsFilterBinding.inflate(layoutInflater)
list_view.setHasFixedSize(true) binding.listView.setHasFixedSize(true)
val mLayoutManager = LinearLayoutManager(this) val mLayoutManager = LinearLayoutManager(this)
list_view.layoutManager = mLayoutManager binding.listView.layoutManager = mLayoutManager
adapter = SlimAdapter.create() adapter = SlimAdapter.create()
adapter adapter
@ -60,12 +60,14 @@ class AppNotificationsFilterActivity : AppCompatActivity() {
} }
.checked(R.id.checkBox, ActiveNotificationsHelper.isAppAccepted(item.activityInfo.packageName)) .checked(R.id.checkBox, ActiveNotificationsHelper.isAppAccepted(item.activityInfo.packageName))
} }
.attachTo(list_view) .attachTo(binding.listView)
setupListener() setupListener()
subscribeUi(binding, viewModel) subscribeUi(binding, viewModel)
search.requestFocus() binding.search.requestFocus()
setContentView(binding.root)
} }
private var filterJob: Job? = null private var filterJob: Job? = null
@ -76,22 +78,22 @@ class AppNotificationsFilterActivity : AppCompatActivity() {
viewModel.appList.observe(this, Observer { viewModel.appList.observe(this, Observer {
updateList(list = it) updateList(list = it)
loader.visibility = View.INVISIBLE binding.loader.visibility = View.INVISIBLE
}) })
viewModel.searchInput.observe(this, Observer { search -> viewModel.searchInput.observe(this, Observer { search ->
updateList(search = search) updateList(search = search)
clear_search.isVisible = search.isNotBlank() binding.clearSearch.isVisible = search.isNotBlank()
}) })
viewModel.appNotificationsFilter.observe(this, { viewModel.appNotificationsFilter.observe(this, {
updateList() updateList()
clear_selection.isVisible = Preferences.appNotificationsFilter != "" binding.clearSelection.isVisible = Preferences.appNotificationsFilter != ""
}) })
} }
private fun updateList(list: List<ResolveInfo>? = viewModel.appList.value, search: String? = viewModel.searchInput.value) { private fun updateList(list: List<ResolveInfo>? = viewModel.appList.value, search: String? = viewModel.searchInput.value) {
loader.visibility = View.VISIBLE binding.loader.visibility = View.VISIBLE
filterJob?.cancel() filterJob?.cancel()
filterJob = lifecycleScope.launch(Dispatchers.IO) { filterJob = lifecycleScope.launch(Dispatchers.IO) {
if (list != null && list.isNotEmpty()) { if (list != null && list.isNotEmpty()) {
@ -117,22 +119,22 @@ class AppNotificationsFilterActivity : AppCompatActivity() {
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
adapter.updateData(filteredList) adapter.updateData(filteredList)
loader.visibility = View.INVISIBLE binding.loader.visibility = View.INVISIBLE
} }
} }
} }
} }
private fun setupListener() { private fun setupListener() {
action_back.setOnClickListener { binding.actionBack.setOnClickListener {
onBackPressed() onBackPressed()
} }
clear_search.setOnClickListener { binding.clearSearch.setOnClickListener {
viewModel.searchInput.value = "" viewModel.searchInput.value = ""
} }
clear_selection.setOnClickListener { binding.clearSelection.setOnClickListener {
Preferences.appNotificationsFilter = "" Preferences.appNotificationsFilter = ""
} }
} }

View File

@ -19,13 +19,6 @@ import com.bumptech.glide.Glide
import com.tommasoberlose.anotherwidget.databinding.ActivityChooseApplicationBinding import com.tommasoberlose.anotherwidget.databinding.ActivityChooseApplicationBinding
import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.ui.viewmodels.ChooseApplicationViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.ChooseApplicationViewModel
import kotlinx.android.synthetic.main.activity_choose_application.*
import kotlinx.android.synthetic.main.activity_choose_application.action_back
import kotlinx.android.synthetic.main.activity_choose_application.clear_search
import kotlinx.android.synthetic.main.activity_choose_application.list_view
import kotlinx.android.synthetic.main.activity_choose_application.loader
import kotlinx.android.synthetic.main.activity_choose_application.search
import kotlinx.android.synthetic.main.activity_music_players_filter.*
import kotlinx.coroutines.* import kotlinx.coroutines.*
import net.idik.lib.slimadapter.SlimAdapter import net.idik.lib.slimadapter.SlimAdapter
import net.idik.lib.slimadapter.SlimAdapterEx import net.idik.lib.slimadapter.SlimAdapterEx
@ -35,16 +28,17 @@ class ChooseApplicationActivity : AppCompatActivity() {
private lateinit var adapter: SlimAdapter private lateinit var adapter: SlimAdapter
private lateinit var viewModel: ChooseApplicationViewModel private lateinit var viewModel: ChooseApplicationViewModel
private lateinit var binding: ActivityChooseApplicationBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
viewModel = ViewModelProvider(this).get(ChooseApplicationViewModel::class.java) viewModel = ViewModelProvider(this).get(ChooseApplicationViewModel::class.java)
val binding = DataBindingUtil.setContentView<ActivityChooseApplicationBinding>(this, R.layout.activity_choose_application) binding = ActivityChooseApplicationBinding.inflate(layoutInflater)
list_view.setHasFixedSize(true) binding.listView.setHasFixedSize(true)
val mLayoutManager = LinearLayoutManager(this) val mLayoutManager = LinearLayoutManager(this)
list_view.layoutManager = mLayoutManager binding.listView.layoutManager = mLayoutManager
adapter = SlimAdapterEx.create() adapter = SlimAdapterEx.create()
adapter adapter
@ -80,12 +74,14 @@ class ChooseApplicationActivity : AppCompatActivity() {
saveApp(item) saveApp(item)
} }
} }
.attachTo(list_view) .attachTo(binding.listView)
setupListener() setupListener()
subscribeUi(binding, viewModel) subscribeUi(binding, viewModel)
search.requestFocus() binding.search.requestFocus()
setContentView(binding.root)
} }
private var filterJob: Job? = null private var filterJob: Job? = null
@ -96,17 +92,17 @@ class ChooseApplicationActivity : AppCompatActivity() {
viewModel.appList.observe(this, Observer { viewModel.appList.observe(this, Observer {
updateList(list = it) updateList(list = it)
loader.visibility = View.INVISIBLE binding.loader.visibility = View.INVISIBLE
}) })
viewModel.searchInput.observe(this, Observer { search -> viewModel.searchInput.observe(this, Observer { search ->
updateList(search = search) updateList(search = search)
clear_search.isVisible = search.isNotBlank() binding.clearSearch.isVisible = search.isNotBlank()
}) })
} }
private fun updateList(list: List<ResolveInfo>? = viewModel.appList.value, search: String? = viewModel.searchInput.value) { private fun updateList(list: List<ResolveInfo>? = viewModel.appList.value, search: String? = viewModel.searchInput.value) {
loader.visibility = View.VISIBLE binding.loader.visibility = View.VISIBLE
filterJob?.cancel() filterJob?.cancel()
filterJob = lifecycleScope.launch(Dispatchers.IO) { filterJob = lifecycleScope.launch(Dispatchers.IO) {
if (list != null && list.isNotEmpty()) { if (list != null && list.isNotEmpty()) {
@ -120,18 +116,18 @@ class ChooseApplicationActivity : AppCompatActivity() {
} }
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
adapter.updateData(listOf("Default") + filteredList) adapter.updateData(listOf("Default") + filteredList)
loader.visibility = View.INVISIBLE binding.loader.visibility = View.INVISIBLE
} }
} }
} }
} }
private fun setupListener() { private fun setupListener() {
action_back.setOnClickListener { binding.actionBack.setOnClickListener {
onBackPressed() onBackPressed()
} }
clear_search.setOnClickListener { binding.clearSearch.setOnClickListener {
viewModel.searchInput.value = "" viewModel.searchInput.value = ""
} }
} }

View File

@ -17,9 +17,6 @@ import com.tommasoberlose.anotherwidget.ui.viewmodels.CustomDateViewModel
import com.tommasoberlose.anotherwidget.utils.getCapWordString import com.tommasoberlose.anotherwidget.utils.getCapWordString
import com.tommasoberlose.anotherwidget.utils.openURI import com.tommasoberlose.anotherwidget.utils.openURI
import com.tommasoberlose.anotherwidget.utils.toast import com.tommasoberlose.anotherwidget.utils.toast
import kotlinx.android.synthetic.main.activity_custom_date.*
import kotlinx.android.synthetic.main.activity_custom_location.action_back
import kotlinx.android.synthetic.main.activity_custom_location.list_view
import kotlinx.coroutines.* import kotlinx.coroutines.*
import net.idik.lib.slimadapter.SlimAdapter import net.idik.lib.slimadapter.SlimAdapter
import java.lang.Exception import java.lang.Exception
@ -30,17 +27,18 @@ class CustomDateActivity : AppCompatActivity() {
private lateinit var adapter: SlimAdapter private lateinit var adapter: SlimAdapter
private lateinit var viewModel: CustomDateViewModel private lateinit var viewModel: CustomDateViewModel
private lateinit var binding: ActivityCustomDateBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
viewModel = ViewModelProvider(this).get(CustomDateViewModel::class.java) viewModel = ViewModelProvider(this).get(CustomDateViewModel::class.java)
val binding = DataBindingUtil.setContentView<ActivityCustomDateBinding>(this, R.layout.activity_custom_date) binding = ActivityCustomDateBinding.inflate(layoutInflater)
list_view.setHasFixedSize(true) binding.listView.setHasFixedSize(true)
val mLayoutManager = LinearLayoutManager(this) val mLayoutManager = LinearLayoutManager(this)
list_view.layoutManager = mLayoutManager binding.listView.layoutManager = mLayoutManager
adapter = SlimAdapter.create() adapter = SlimAdapter.create()
adapter adapter
@ -50,7 +48,7 @@ class CustomDateActivity : AppCompatActivity() {
.text(R.id.custom_date_example_value, SimpleDateFormat(item, Locale.getDefault()).format( .text(R.id.custom_date_example_value, SimpleDateFormat(item, Locale.getDefault()).format(
DATE.time)) DATE.time))
} }
.attachTo(list_view) .attachTo(binding.listView)
adapter.updateData( adapter.updateData(
listOf( listOf(
@ -61,9 +59,11 @@ class CustomDateActivity : AppCompatActivity() {
setupListener() setupListener()
subscribeUi(binding, viewModel) subscribeUi(binding, viewModel)
date_format.requestFocus() binding.dateFormat.requestFocus()
setContentView(binding.root)
} }
private var formatJob: Job? = null private var formatJob: Job? = null
private fun subscribeUi(binding: ActivityCustomDateBinding, viewModel: CustomDateViewModel) { private fun subscribeUi(binding: ActivityCustomDateBinding, viewModel: CustomDateViewModel) {
@ -74,7 +74,7 @@ class CustomDateActivity : AppCompatActivity() {
formatJob?.cancel() formatJob?.cancel()
formatJob = lifecycleScope.launch(Dispatchers.IO) { formatJob = lifecycleScope.launch(Dispatchers.IO) {
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
loader.visibility = View.VISIBLE binding.loader.visibility = View.VISIBLE
} }
delay(200) delay(200)
@ -97,8 +97,8 @@ class CustomDateActivity : AppCompatActivity() {
} }
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
loader.visibility = View.INVISIBLE binding.loader.visibility = View.INVISIBLE
date_format_value.text = text binding.dateFormatValue.text = text
} }
} }
@ -118,26 +118,26 @@ class CustomDateActivity : AppCompatActivity() {
private fun updateCapitalizeUi() { private fun updateCapitalizeUi() {
when { when {
viewModel.isDateUppercase.value == true -> { viewModel.isDateUppercase.value == true -> {
action_capitalize.setImageDrawable(ContextCompat.getDrawable(this@CustomDateActivity, R.drawable.round_publish)) binding.actionCapitalize.setImageDrawable(ContextCompat.getDrawable(this@CustomDateActivity, R.drawable.round_publish))
action_capitalize.alpha = 1f binding.actionCapitalize.alpha = 1f
} }
viewModel.isDateCapitalize.value == true -> { viewModel.isDateCapitalize.value == true -> {
action_capitalize.setImageDrawable(ContextCompat.getDrawable(this@CustomDateActivity, R.drawable.ic_capitalize)) binding.actionCapitalize.setImageDrawable(ContextCompat.getDrawable(this@CustomDateActivity, R.drawable.ic_capitalize))
action_capitalize.alpha = 1f binding.actionCapitalize.alpha = 1f
} }
else -> { else -> {
action_capitalize.setImageDrawable(ContextCompat.getDrawable(this@CustomDateActivity, R.drawable.round_publish)) binding.actionCapitalize.setImageDrawable(ContextCompat.getDrawable(this@CustomDateActivity, R.drawable.round_publish))
action_capitalize.alpha = 0.3f binding.actionCapitalize.alpha = 0.3f
} }
} }
} }
private fun setupListener() { private fun setupListener() {
action_back.setOnClickListener { binding.actionBack.setOnClickListener {
onBackPressed() onBackPressed()
} }
action_capitalize.setOnClickListener { binding.actionCapitalize.setOnClickListener {
when { when {
viewModel.isDateUppercase.value == true -> { viewModel.isDateUppercase.value == true -> {
viewModel.isDateCapitalize.value = false viewModel.isDateCapitalize.value = false
@ -154,12 +154,12 @@ class CustomDateActivity : AppCompatActivity() {
} }
} }
action_capitalize.setOnLongClickListener { binding.actionCapitalize.setOnLongClickListener {
toast(getString(R.string.action_capitalize_the_date)) toast(getString(R.string.action_capitalize_the_date))
true true
} }
action_date_format_info.setOnClickListener { binding.actionDateFormatInfo.setOnClickListener {
openURI("https://developer.android.com/reference/java/text/SimpleDateFormat") openURI("https://developer.android.com/reference/java/text/SimpleDateFormat")
} }
} }

View File

@ -27,13 +27,6 @@ import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
import com.tommasoberlose.anotherwidget.ui.viewmodels.CustomFontViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.CustomFontViewModel
import kotlinx.android.synthetic.main.activity_choose_application.*
import kotlinx.android.synthetic.main.activity_choose_application.action_back
import kotlinx.android.synthetic.main.activity_choose_application.clear_search
import kotlinx.android.synthetic.main.activity_choose_application.list_view
import kotlinx.android.synthetic.main.activity_choose_application.loader
import kotlinx.android.synthetic.main.activity_choose_application.search
import kotlinx.android.synthetic.main.activity_music_players_filter.*
import kotlinx.coroutines.* import kotlinx.coroutines.*
import net.idik.lib.slimadapter.SlimAdapter import net.idik.lib.slimadapter.SlimAdapter
import net.idik.lib.slimadapter.diff.DefaultDiffCallback import net.idik.lib.slimadapter.diff.DefaultDiffCallback
@ -43,19 +36,17 @@ class CustomFontActivity : AppCompatActivity() {
private lateinit var adapter: SlimAdapter private lateinit var adapter: SlimAdapter
private lateinit var viewModel: CustomFontViewModel private lateinit var viewModel: CustomFontViewModel
private lateinit var binding: ActivityCustomFontBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
viewModel = ViewModelProvider(this).get(CustomFontViewModel::class.java) viewModel = ViewModelProvider(this).get(CustomFontViewModel::class.java)
val binding = DataBindingUtil.setContentView<ActivityCustomFontBinding>( binding = ActivityCustomFontBinding.inflate(layoutInflater)
this,
R.layout.activity_custom_font
)
list_view.setHasFixedSize(true) binding.listView.setHasFixedSize(true)
val mLayoutManager = LinearLayoutManager(this) val mLayoutManager = LinearLayoutManager(this)
list_view.layoutManager = mLayoutManager binding.listView.layoutManager = mLayoutManager
adapter = SlimAdapter.create() adapter = SlimAdapter.create()
adapter.enableDiff(object: DefaultDiffCallback() { adapter.enableDiff(object: DefaultDiffCallback() {
@ -145,12 +136,14 @@ class CustomFontActivity : AppCompatActivity() {
}.show() }.show()
} }
} }
.attachTo(list_view) .attachTo(binding.listView)
setupListener() setupListener()
subscribeUi(binding, viewModel) subscribeUi(binding, viewModel)
search.requestFocus() binding.search.requestFocus()
setContentView(binding.root)
} }
private var filterJob: Job? = null private var filterJob: Job? = null
@ -161,12 +154,12 @@ class CustomFontActivity : AppCompatActivity() {
viewModel.fontList.observe(this, Observer { viewModel.fontList.observe(this, Observer {
updateList(list = it) updateList(list = it)
loader.visibility = View.INVISIBLE binding.loader.visibility = View.INVISIBLE
}) })
viewModel.searchInput.observe(this, Observer { search -> viewModel.searchInput.observe(this, Observer { search ->
updateList(search = search) updateList(search = search)
clear_search.isVisible = search.isNotBlank() binding.clearSearch.isVisible = search.isNotBlank()
}) })
} }
@ -174,7 +167,7 @@ class CustomFontActivity : AppCompatActivity() {
list: ArrayList<Font>? = viewModel.fontList.value, list: ArrayList<Font>? = viewModel.fontList.value,
search: String? = viewModel.searchInput.value search: String? = viewModel.searchInput.value
) { ) {
loader.visibility = View.VISIBLE binding.loader.visibility = View.VISIBLE
filterJob?.cancel() filterJob?.cancel()
filterJob = lifecycleScope.launch(Dispatchers.IO) { filterJob = lifecycleScope.launch(Dispatchers.IO) {
if (list != null && list.isNotEmpty()) { if (list != null && list.isNotEmpty()) {
@ -208,18 +201,18 @@ class CustomFontActivity : AppCompatActivity() {
} }
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
adapter.updateData(filteredList) adapter.updateData(filteredList)
loader.visibility = View.INVISIBLE binding.loader.visibility = View.INVISIBLE
} }
} }
} }
} }
private fun setupListener() { private fun setupListener() {
action_back.setOnClickListener { binding.actionBack.setOnClickListener {
onBackPressed() onBackPressed()
} }
clear_search.setOnClickListener { binding.clearSearch.setOnClickListener {
viewModel.searchInput.value = "" viewModel.searchInput.value = ""
} }
} }

View File

@ -23,12 +23,6 @@ import com.karumi.dexter.listener.multi.MultiplePermissionsListener
import com.tommasoberlose.anotherwidget.databinding.ActivityCustomLocationBinding import com.tommasoberlose.anotherwidget.databinding.ActivityCustomLocationBinding
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.ui.viewmodels.CustomLocationViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.CustomLocationViewModel
import kotlinx.android.synthetic.main.activity_custom_location.*
import kotlinx.android.synthetic.main.activity_custom_location.action_back
import kotlinx.android.synthetic.main.activity_custom_location.clear_search
import kotlinx.android.synthetic.main.activity_custom_location.list_view
import kotlinx.android.synthetic.main.activity_custom_location.loader
import kotlinx.android.synthetic.main.activity_music_players_filter.*
import kotlinx.coroutines.* import kotlinx.coroutines.*
import net.idik.lib.slimadapter.SlimAdapter import net.idik.lib.slimadapter.SlimAdapter
@ -36,17 +30,18 @@ class CustomLocationActivity : AppCompatActivity() {
private lateinit var adapter: SlimAdapter private lateinit var adapter: SlimAdapter
private lateinit var viewModel: CustomLocationViewModel private lateinit var viewModel: CustomLocationViewModel
private lateinit var binding: ActivityCustomLocationBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
viewModel = ViewModelProvider(this).get(CustomLocationViewModel::class.java) viewModel = ViewModelProvider(this).get(CustomLocationViewModel::class.java)
val binding = DataBindingUtil.setContentView<ActivityCustomLocationBinding>(this, R.layout.activity_custom_location) binding = ActivityCustomLocationBinding.inflate(layoutInflater)
list_view.setHasFixedSize(true) binding.listView.setHasFixedSize(true)
val mLayoutManager = LinearLayoutManager(this) val mLayoutManager = LinearLayoutManager(this)
list_view.layoutManager = mLayoutManager binding.listView.layoutManager = mLayoutManager
adapter = SlimAdapter.create() adapter = SlimAdapter.create()
adapter adapter
@ -69,7 +64,7 @@ class CustomLocationActivity : AppCompatActivity() {
} }
} }
} }
.attachTo(list_view) .attachTo(binding.listView)
viewModel.addresses.observe(this, Observer { viewModel.addresses.observe(this, Observer {
@ -79,9 +74,11 @@ class CustomLocationActivity : AppCompatActivity() {
setupListener() setupListener()
subscribeUi(binding, viewModel) subscribeUi(binding, viewModel)
location.requestFocus() binding.location.requestFocus()
setContentView(binding.root)
} }
private var searchJob: Job? = null private var searchJob: Job? = null
private fun subscribeUi(binding: ActivityCustomLocationBinding, viewModel: CustomLocationViewModel) { private fun subscribeUi(binding: ActivityCustomLocationBinding, viewModel: CustomLocationViewModel) {
@ -90,11 +87,11 @@ class CustomLocationActivity : AppCompatActivity() {
viewModel.addresses.observe(this, Observer { viewModel.addresses.observe(this, Observer {
adapter.updateData(listOf("Default") + it) adapter.updateData(listOf("Default") + it)
loader.visibility = View.INVISIBLE binding.loader.visibility = View.INVISIBLE
}) })
viewModel.locationInput.observe(this, Observer { location -> viewModel.locationInput.observe(this, Observer { location ->
loader.visibility = View.VISIBLE binding.loader.visibility = View.VISIBLE
searchJob?.cancel() searchJob?.cancel()
searchJob = lifecycleScope.launch(Dispatchers.IO) { searchJob = lifecycleScope.launch(Dispatchers.IO) {
delay(200) delay(200)
@ -110,11 +107,11 @@ class CustomLocationActivity : AppCompatActivity() {
} }
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
viewModel.addresses.value = list viewModel.addresses.value = list
loader.visibility = View.INVISIBLE binding.loader.visibility = View.INVISIBLE
} }
} }
clear_search.isVisible = location.isNotBlank() binding.clearSearch.isVisible = location.isNotBlank()
}) })
} }
@ -149,11 +146,11 @@ class CustomLocationActivity : AppCompatActivity() {
} }
private fun setupListener() { private fun setupListener() {
action_back.setOnClickListener { binding.actionBack.setOnClickListener {
onBackPressed() onBackPressed()
} }
clear_search.setOnClickListener { binding.clearSearch.setOnClickListener {
viewModel.locationInput.value = "" viewModel.locationInput.value = ""
} }
} }

View File

@ -17,7 +17,6 @@ import com.tommasoberlose.anotherwidget.databinding.ActivityMusicPlayersFilterBi
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.MediaPlayerHelper import com.tommasoberlose.anotherwidget.helpers.MediaPlayerHelper
import com.tommasoberlose.anotherwidget.ui.viewmodels.MusicPlayersFilterViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.MusicPlayersFilterViewModel
import kotlinx.android.synthetic.main.activity_music_players_filter.*
import kotlinx.coroutines.* import kotlinx.coroutines.*
import net.idik.lib.slimadapter.SlimAdapter import net.idik.lib.slimadapter.SlimAdapter
@ -26,16 +25,17 @@ class MusicPlayersFilterActivity : AppCompatActivity() {
private lateinit var adapter: SlimAdapter private lateinit var adapter: SlimAdapter
private lateinit var viewModel: MusicPlayersFilterViewModel private lateinit var viewModel: MusicPlayersFilterViewModel
private lateinit var binding: ActivityMusicPlayersFilterBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
viewModel = ViewModelProvider(this).get(MusicPlayersFilterViewModel::class.java) viewModel = ViewModelProvider(this).get(MusicPlayersFilterViewModel::class.java)
val binding = DataBindingUtil.setContentView<ActivityMusicPlayersFilterBinding>(this, R.layout.activity_music_players_filter) binding = ActivityMusicPlayersFilterBinding.inflate(layoutInflater)
list_view.setHasFixedSize(true) binding.listView.setHasFixedSize(true)
val mLayoutManager = LinearLayoutManager(this) val mLayoutManager = LinearLayoutManager(this)
list_view.layoutManager = mLayoutManager binding.listView.layoutManager = mLayoutManager
adapter = SlimAdapter.create() adapter = SlimAdapter.create()
adapter adapter
@ -60,12 +60,14 @@ class MusicPlayersFilterActivity : AppCompatActivity() {
} }
.checked(R.id.checkBox, MediaPlayerHelper.isMusicPlayerAccepted(item.activityInfo.packageName)) .checked(R.id.checkBox, MediaPlayerHelper.isMusicPlayerAccepted(item.activityInfo.packageName))
} }
.attachTo(list_view) .attachTo(binding.listView)
setupListener() setupListener()
subscribeUi(binding, viewModel) subscribeUi(binding, viewModel)
search.requestFocus() binding.search.requestFocus()
setContentView(binding.root)
} }
private var filterJob: Job? = null private var filterJob: Job? = null
@ -76,22 +78,22 @@ class MusicPlayersFilterActivity : AppCompatActivity() {
viewModel.appList.observe(this, Observer { viewModel.appList.observe(this, Observer {
updateList(list = it) updateList(list = it)
loader.visibility = View.INVISIBLE binding.loader.visibility = View.INVISIBLE
}) })
viewModel.searchInput.observe(this, Observer { search -> viewModel.searchInput.observe(this, Observer { search ->
updateList(search = search) updateList(search = search)
clear_search.isVisible = search.isNotBlank() binding.clearSearch.isVisible = search.isNotBlank()
}) })
viewModel.musicPlayersFilter.observe(this, { viewModel.musicPlayersFilter.observe(this, {
updateList() updateList()
clear_selection.isVisible = Preferences.musicPlayersFilter != "" binding.clearSelection.isVisible = Preferences.musicPlayersFilter != ""
}) })
} }
private fun updateList(list: List<ResolveInfo>? = viewModel.appList.value, search: String? = viewModel.searchInput.value) { private fun updateList(list: List<ResolveInfo>? = viewModel.appList.value, search: String? = viewModel.searchInput.value) {
loader.visibility = View.VISIBLE binding.loader.visibility = View.VISIBLE
filterJob?.cancel() filterJob?.cancel()
filterJob = lifecycleScope.launch(Dispatchers.IO) { filterJob = lifecycleScope.launch(Dispatchers.IO) {
if (list != null && list.isNotEmpty()) { if (list != null && list.isNotEmpty()) {
@ -117,22 +119,22 @@ class MusicPlayersFilterActivity : AppCompatActivity() {
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
adapter.updateData(filteredList) adapter.updateData(filteredList)
loader.visibility = View.INVISIBLE binding.loader.visibility = View.INVISIBLE
} }
} }
} }
} }
private fun setupListener() { private fun setupListener() {
action_back.setOnClickListener { binding.actionBack.setOnClickListener {
onBackPressed() onBackPressed()
} }
clear_search.setOnClickListener { binding.clearSearch.setOnClickListener {
viewModel.searchInput.value = "" viewModel.searchInput.value = ""
} }
clear_selection.setOnClickListener { binding.clearSelection.setOnClickListener {
Preferences.musicPlayersFilter = "" Preferences.musicPlayersFilter = ""
} }
} }

View File

@ -13,12 +13,12 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.components.BottomSheetWeatherProviderSettings import com.tommasoberlose.anotherwidget.components.BottomSheetWeatherProviderSettings
import com.tommasoberlose.anotherwidget.databinding.ActivityWeatherProviderBinding
import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.WeatherHelper import com.tommasoberlose.anotherwidget.helpers.WeatherHelper
import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment
import com.tommasoberlose.anotherwidget.ui.viewmodels.WeatherProviderViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.WeatherProviderViewModel
import kotlinx.android.synthetic.main.activity_weather_provider.*
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import net.idik.lib.slimadapter.SlimAdapter import net.idik.lib.slimadapter.SlimAdapter
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
@ -29,16 +29,17 @@ class WeatherProviderActivity : AppCompatActivity() {
private lateinit var adapter: SlimAdapter private lateinit var adapter: SlimAdapter
private lateinit var viewModel: WeatherProviderViewModel private lateinit var viewModel: WeatherProviderViewModel
private lateinit var binding: ActivityWeatherProviderBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_weather_provider)
viewModel = ViewModelProvider(this).get(WeatherProviderViewModel::class.java) viewModel = ViewModelProvider(this).get(WeatherProviderViewModel::class.java)
binding = ActivityWeatherProviderBinding.inflate(layoutInflater)
list_view.setHasFixedSize(true) binding.listView.setHasFixedSize(true)
val mLayoutManager = LinearLayoutManager(this) val mLayoutManager = LinearLayoutManager(this)
list_view.layoutManager = mLayoutManager binding.listView.layoutManager = mLayoutManager
adapter = SlimAdapter.create() adapter = SlimAdapter.create()
adapter adapter
@ -54,7 +55,7 @@ class WeatherProviderActivity : AppCompatActivity() {
Preferences.weatherProvider = provider.value Preferences.weatherProvider = provider.value
updateListItem(oldValue) updateListItem(oldValue)
updateListItem() updateListItem()
loader.isVisible = true binding.loader.isVisible = true
lifecycleScope.launch { lifecycleScope.launch {
WeatherHelper.updateWeather(this@WeatherProviderActivity) WeatherHelper.updateWeather(this@WeatherProviderActivity)
@ -69,7 +70,7 @@ class WeatherProviderActivity : AppCompatActivity() {
Preferences.weatherProvider = provider.value Preferences.weatherProvider = provider.value
updateListItem(oldValue) updateListItem(oldValue)
updateListItem() updateListItem()
loader.isVisible = true binding.loader.isVisible = true
lifecycleScope.launch { lifecycleScope.launch {
WeatherHelper.updateWeather(this@WeatherProviderActivity) WeatherHelper.updateWeather(this@WeatherProviderActivity)
@ -92,7 +93,7 @@ class WeatherProviderActivity : AppCompatActivity() {
.clicked(R.id.action_configure) { .clicked(R.id.action_configure) {
BottomSheetWeatherProviderSettings(this) { BottomSheetWeatherProviderSettings(this) {
lifecycleScope.launch { lifecycleScope.launch {
loader.isVisible = true binding.loader.isVisible = true
WeatherHelper.updateWeather(this@WeatherProviderActivity) WeatherHelper.updateWeather(this@WeatherProviderActivity)
} }
}.show() }.show()
@ -110,7 +111,7 @@ class WeatherProviderActivity : AppCompatActivity() {
} }
} }
.image(R.id.action_configure, ContextCompat.getDrawable(this, if (WeatherHelper.isKeyRequired(provider)) R.drawable.round_settings_24 else R.drawable.outline_info_24)) .image(R.id.action_configure, ContextCompat.getDrawable(this, if (WeatherHelper.isKeyRequired(provider)) R.drawable.round_settings_24 else R.drawable.outline_info_24))
}.attachTo(list_view) }.attachTo(binding.listView)
adapter.updateData( adapter.updateData(
Constants.WeatherProvider.values().asList() Constants.WeatherProvider.values().asList()
@ -120,6 +121,8 @@ class WeatherProviderActivity : AppCompatActivity() {
setupListener() setupListener()
subscribeUi(viewModel) subscribeUi(viewModel)
setContentView(binding.root)
} }
private fun subscribeUi(viewModel: WeatherProviderViewModel) { private fun subscribeUi(viewModel: WeatherProviderViewModel) {
@ -141,7 +144,7 @@ class WeatherProviderActivity : AppCompatActivity() {
} }
private fun setupListener() { private fun setupListener() {
action_back.setOnClickListener { binding.actionBack.setOnClickListener {
onBackPressed() onBackPressed()
} }
} }
@ -163,9 +166,9 @@ class WeatherProviderActivity : AppCompatActivity() {
@Subscribe(threadMode = ThreadMode.MAIN) @Subscribe(threadMode = ThreadMode.MAIN)
fun onMessageEvent(ignore: MainFragment.UpdateUiMessageEvent?) { fun onMessageEvent(ignore: MainFragment.UpdateUiMessageEvent?) {
loader.isVisible = Preferences.weatherProviderError == "-" binding.loader.isVisible = Preferences.weatherProviderError == "-"
if (Preferences.weatherProviderError == "" && Preferences.weatherProviderLocationError == "") { if (Preferences.weatherProviderError == "" && Preferences.weatherProviderLocationError == "") {
Snackbar.make(list_view, getString(R.string.settings_weather_provider_api_key_subtitle_all_set), Snackbar.LENGTH_LONG).show() Snackbar.make(binding.listView, getString(R.string.settings_weather_provider_api_key_subtitle_all_set), Snackbar.LENGTH_LONG).show()
} }
} }
} }

View File

@ -32,6 +32,7 @@ import com.google.android.material.tabs.TabLayoutMediator
import com.google.android.material.transition.MaterialSharedAxis import com.google.android.material.transition.MaterialSharedAxis
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.components.MaterialBottomSheetDialog import com.tommasoberlose.anotherwidget.components.MaterialBottomSheetDialog
import com.tommasoberlose.anotherwidget.databinding.FragmentAppMainBinding
import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.* import com.tommasoberlose.anotherwidget.helpers.*
@ -42,8 +43,6 @@ import com.tommasoberlose.anotherwidget.ui.adapters.ViewPagerAdapter
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
import com.tommasoberlose.anotherwidget.utils.* import com.tommasoberlose.anotherwidget.utils.*
import kotlinx.android.synthetic.main.fragment_app_main.*
import kotlinx.android.synthetic.main.the_widget_sans.*
import kotlinx.coroutines.* import kotlinx.coroutines.*
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.Subscribe
@ -57,6 +56,7 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
} }
private lateinit var viewModel: MainViewModel private lateinit var viewModel: MainViewModel
private lateinit var binding: FragmentAppMainBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -70,7 +70,8 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View { ): View {
viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java) viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java)
return inflater.inflate(R.layout.fragment_app_main, container, false) binding = FragmentAppMainBinding.inflate(inflater)
return binding.root
} }
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
@ -78,16 +79,16 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
// Init clock // Init clock
if (Preferences.showClock) { if (Preferences.showClock) {
time.setTextColor(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true)) binding.widgetDetail.time.setTextColor(ColorHelper.getClockFontColor(requireActivity().isDarkTheme()))
time.setTextSize(TypedValue.COMPLEX_UNIT_SP, binding.widgetDetail.time.setTextSize(TypedValue.COMPLEX_UNIT_SP,
Preferences.clockTextSize.toPixel(requireContext())) Preferences.clockTextSize.toPixel(requireContext()))
time_am_pm.setTextColor(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true)) binding.widgetDetail.timeAmPm.setTextColor(ColorHelper.getClockFontColor(requireActivity().isDarkTheme()))
time_am_pm.setTextSize(TypedValue.COMPLEX_UNIT_SP, binding.widgetDetail.timeAmPm.setTextSize(TypedValue.COMPLEX_UNIT_SP,
Preferences.clockTextSize.toPixel(requireContext()) / 5 * 2) Preferences.clockTextSize.toPixel(requireContext()) / 5 * 2)
} }
time_container.isVisible = Preferences.showClock binding.widgetDetail.timeContainer.isVisible = Preferences.showClock
preview.layoutParams = preview.layoutParams.apply { binding.preview.layoutParams = binding.preview.layoutParams.apply {
height = PREVIEW_BASE_HEIGHT.toPixel(requireContext()) + if (Preferences.showClock) 100.toPixel(requireContext()) else 0 height = PREVIEW_BASE_HEIGHT.toPixel(requireContext()) + if (Preferences.showClock) 100.toPixel(requireContext()) else 0
} }
subscribeUi(viewModel) subscribeUi(viewModel)
@ -111,12 +112,12 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
val navHost = childFragmentManager.findFragmentById(R.id.settings_fragment) as? NavHostFragment? val navHost = childFragmentManager.findFragmentById(R.id.settings_fragment) as? NavHostFragment?
navHost?.navController?.addOnDestinationChangedListener { controller, destination, _ -> navHost?.navController?.addOnDestinationChangedListener { controller, destination, _ ->
val show = destination.id != R.id.tabSelectorFragment val show = destination.id != R.id.tabSelectorFragment
action_back?.animate()?.alpha(if (show) 1f else 0f)?.setDuration(200)?.translationX((if (show) 0f else 4f).convertDpToPixel(requireContext()))?.start() binding.actionBack.animate().alpha(if (show) 1f else 0f).setDuration(200).translationX((if (show) 0f else 4f).convertDpToPixel(requireContext())).start()
action_back?.setOnClickListener { binding.actionBack.setOnClickListener {
controller.navigateUp() controller.navigateUp()
} }
action_settings?.animate()?.alpha(if (!show) 1f else 0f)?.setDuration(200)?.translationX((if (!show) 0f else -4f).convertDpToPixel(requireContext()))?.start() binding.actionSettings.animate().alpha(if (!show) 1f else 0f).setDuration(200).translationX((if (!show) 0f else -4f).convertDpToPixel(requireContext())).start()
fragment_title?.text = if (show) destination.label.toString() else getString(R.string.app_name) binding.fragmentTitle.text = if (show) destination.label.toString() else getString(R.string.app_name)
} }
} }
@ -125,76 +126,72 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
private fun updateUI() { private fun updateUI() {
uiJob?.cancel() uiJob?.cancel()
preview?.clearAnimation() binding.preview.clearAnimation()
time_container?.clearAnimation() binding.widgetDetail.timeContainer.clearAnimation()
bottom_padding.isVisible = Preferences.showPreview binding.bottomPadding.isVisible = Preferences.showPreview
if (Preferences.showPreview) { if (Preferences.showPreview) {
preview?.setCardBackgroundColor( binding.preview.setCardBackgroundColor(
ContextCompat.getColor( ContextCompat.getColor(
requireContext(), requireContext(),
if (ColorHelper.getFontColor(activity?.isDarkTheme() == true) if (ColorHelper.getFontColor(requireActivity().isDarkTheme())
.isColorDark() .isColorDark()
) android.R.color.white else R.color.colorAccent ) android.R.color.white else R.color.colorAccent
) )
) )
widget_shape_background?.setImageDrawable( binding.widgetDetail.widgetShapeBackground.setImageDrawable(
BitmapHelper.getTintedDrawable( BitmapHelper.getTintedDrawable(
requireContext(), requireContext(),
R.drawable.card_background, R.drawable.card_background,
ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true) ColorHelper.getBackgroundColor(requireActivity().isDarkTheme())
) )
) )
WidgetHelper.runWithCustomTypeface(requireContext()) { typeface -> WidgetHelper.runWithCustomTypeface(requireContext()) { typeface ->
uiJob = lifecycleScope.launch(Dispatchers.IO) { uiJob = lifecycleScope.launch(Dispatchers.IO) {
val generatedView = MainWidget.generateWidgetView(requireContext(), typeface) val generatedView = MainWidget.generateWidgetView(requireContext(), typeface).root
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
generatedView.measure(0, 0) generatedView.measure(0, 0)
preview?.measure(0, 0) binding.preview.measure(0, 0)
} }
val bitmap = if (preview != null) { val bitmap = BitmapHelper.getBitmapFromView(
BitmapHelper.getBitmapFromView(
generatedView, generatedView,
if (preview.width > 0) preview.width else generatedView.measuredWidth, if (binding.preview.width > 0) binding.preview.width else generatedView.measuredWidth,
generatedView.measuredHeight generatedView.measuredHeight
) )
} else {
null
}
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
// Clock // Clock
time?.setTextColor(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true)) binding.widgetDetail.time.setTextColor(ColorHelper.getClockFontColor(requireActivity().isDarkTheme()))
time_am_pm?.setTextColor(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true)) binding.widgetDetail.timeAmPm.setTextColor(ColorHelper.getClockFontColor(requireActivity().isDarkTheme()))
time?.setTextSize( binding.widgetDetail.time.setTextSize(
TypedValue.COMPLEX_UNIT_SP, TypedValue.COMPLEX_UNIT_SP,
Preferences.clockTextSize.toPixel(requireContext()) Preferences.clockTextSize.toPixel(requireContext())
) )
time_am_pm?.setTextSize( binding.widgetDetail.timeAmPm.setTextSize(
TypedValue.COMPLEX_UNIT_SP, TypedValue.COMPLEX_UNIT_SP,
Preferences.clockTextSize.toPixel(requireContext()) / 5 * 2 Preferences.clockTextSize.toPixel(requireContext()) / 5 * 2
) )
time_am_pm?.isVisible = Preferences.showAMPMIndicator binding.widgetDetail.timeAmPm.isVisible = Preferences.showAMPMIndicator
// Clock bottom margin // Clock bottom margin
clock_bottom_margin_none?.isVisible = binding.widgetDetail.clockBottomMarginNone.isVisible =
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.NONE.value Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.NONE.value
clock_bottom_margin_small?.isVisible = binding.widgetDetail.clockBottomMarginSmall.isVisible =
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.SMALL.value Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.SMALL.value
clock_bottom_margin_medium?.isVisible = binding.widgetDetail.clockBottomMarginMedium.isVisible =
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.MEDIUM.value Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.MEDIUM.value
clock_bottom_margin_large?.isVisible = binding.widgetDetail.clockBottomMarginLarge.isVisible =
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.LARGE.value Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.LARGE.value
if ((Preferences.showClock && (time?.alpha ?: 1f < 1f)) || (!Preferences.showClock && (time?.alpha ?: 0f > 0f))) { if ((Preferences.showClock && (binding.widgetDetail.time.alpha ?: 1f < 1f)) || (!Preferences.showClock && (binding.widgetDetail.time.alpha ?: 0f > 0f))) {
if (Preferences.showClock) { if (Preferences.showClock) {
time_container?.layoutParams = time_container.layoutParams.apply { binding.widgetDetail.timeContainer.layoutParams = binding.widgetDetail.timeContainer.layoutParams.apply {
height = RelativeLayout.LayoutParams.WRAP_CONTENT height = RelativeLayout.LayoutParams.WRAP_CONTENT
} }
time_container?.measure(0, 0) binding.widgetDetail.timeContainer.measure(0, 0)
} }
val initialHeight = time_container?.measuredHeight ?: 0 val initialHeight = binding.widgetDetail.timeContainer.measuredHeight ?: 0
ValueAnimator.ofFloat( ValueAnimator.ofFloat(
if (Preferences.showClock) 0f else 1f, if (Preferences.showClock) 0f else 1f,
if (Preferences.showClock) 1f else 0f if (Preferences.showClock) 1f else 0f
@ -202,121 +199,122 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
duration = 500L duration = 500L
addUpdateListener { addUpdateListener {
val animatedValue = animatedValue as Float val animatedValue = animatedValue as Float
time_container?.layoutParams = binding.widgetDetail.timeContainer.layoutParams =
time_container.layoutParams.apply { binding.widgetDetail.timeContainer.layoutParams.apply {
height = (initialHeight * animatedValue).toInt() height = (initialHeight * animatedValue).toInt()
} }
time?.alpha = animatedValue binding.widgetDetail.time.alpha = animatedValue
} }
addListener( addListener(
onStart = { onStart = {
if (Preferences.showClock) { if (Preferences.showClock) {
time_container?.isVisible = true binding.widgetDetail.timeContainer.isVisible = true
} }
}, },
onEnd = { onEnd = {
if (!Preferences.showClock) { if (!Preferences.showClock) {
time_container?.isVisible = false binding.widgetDetail.timeContainer.isVisible = false
} }
} }
) )
}.start() }.start()
if (preview != null) {
ValueAnimator.ofInt( ValueAnimator.ofInt(
preview.height, binding.preview.height,
PREVIEW_BASE_HEIGHT.toPixel(requireContext()) + if (Preferences.showClock) 100.toPixel( PREVIEW_BASE_HEIGHT.toPixel(requireContext()) + if (Preferences.showClock) 100.toPixel(
requireContext() requireContext()
) else 0 ) else 0
).apply { ).apply {
duration = 500L duration = 500L
addUpdateListener { addUpdateListener {
if (preview != null) {
val animatedValue = animatedValue as Int val animatedValue = animatedValue as Int
val layoutParams = preview.layoutParams val layoutParams = binding.preview.layoutParams
layoutParams.height = animatedValue layoutParams.height = animatedValue
preview.layoutParams = layoutParams binding.preview.layoutParams = layoutParams
}
} }
}.start() }.start()
}
} else { } else {
time_container?.layoutParams = time_container.layoutParams.apply { binding.widgetDetail.timeContainer.layoutParams = binding.widgetDetail.timeContainer.layoutParams.apply {
height = RelativeLayout.LayoutParams.WRAP_CONTENT height = RelativeLayout.LayoutParams.WRAP_CONTENT
} }
time_container?.measure(0, 0) binding.widgetDetail.timeContainer.measure(0, 0)
} }
if (preview != null && preview.height == 0) { if (binding.preview.height == 0) {
ValueAnimator.ofInt( ValueAnimator.ofInt(
preview.height, binding.preview.height,
PREVIEW_BASE_HEIGHT.toPixel(requireContext()) + if (Preferences.showClock) 100.toPixel( PREVIEW_BASE_HEIGHT.toPixel(requireContext()) + if (Preferences.showClock) 100.toPixel(
requireContext() requireContext()
) else 0 ) else 0
).apply { ).apply {
duration = 300L duration = 300L
addUpdateListener { addUpdateListener {
if (preview != null) {
val animatedValue = animatedValue as Int val animatedValue = animatedValue as Int
val layoutParams = preview.layoutParams val layoutParams = binding.preview.layoutParams
layoutParams.height = animatedValue layoutParams.height = animatedValue
preview?.layoutParams = layoutParams binding.preview.layoutParams = layoutParams
}
} }
}.start() }.start()
} }
widget_loader?.animate()?.scaleX(0f)?.scaleY(0f)?.alpha(0f) binding.widgetLoader.animate().scaleX(0f).scaleY(0f).alpha(0f)
?.setDuration(200L)?.start() .setDuration(200L).start()
bitmap_container?.apply { binding.widgetDetail.bitmapContainer.apply {
setImageBitmap(bitmap) setImageBitmap(bitmap)
scaleX = 0.9f scaleX = 0.9f
scaleY = 0.9f scaleY = 0.9f
} }
widget?.animate()?.alpha(1f)?.start() binding.widget.animate().alpha(1f).start()
} }
} }
} }
} else { } else {
if (preview != null) {
ValueAnimator.ofInt( ValueAnimator.ofInt(
preview.height, binding.preview.height,
0 0
).apply { ).apply {
duration = 300L duration = 300L
addUpdateListener { addUpdateListener {
if (preview != null) {
val animatedValue = animatedValue as Int val animatedValue = animatedValue as Int
val layoutParams = preview.layoutParams val layoutParams = binding.preview.layoutParams
layoutParams.height = animatedValue layoutParams.height = animatedValue
preview.layoutParams = layoutParams binding.preview.layoutParams = layoutParams
}
} }
}.start() }.start()
} }
} }
}
private fun subscribeUi(viewModel: MainViewModel) { private fun subscribeUi(viewModel: MainViewModel) {
viewModel.showWallpaper.observe(viewLifecycleOwner, Observer { viewModel.showWallpaper.observe(viewLifecycleOwner) {
activity?.let { act -> if (it) {
val wallpaper = act.getCurrentWallpaper() val wallpaper = requireActivity().getCurrentWallpaper()
widget_bg.setImageDrawable(if (it) wallpaper else null) binding.widgetBg.setImageDrawable(if (it) wallpaper else null)
if (wallpaper != null) { if (wallpaper != null) {
widget_bg.layoutParams = binding.widgetBg.layoutParams =
(widget_bg.layoutParams as ViewGroup.MarginLayoutParams).apply { (binding.widgetBg.layoutParams as ViewGroup.MarginLayoutParams).apply {
val metrics = DisplayMetrics() val metrics = DisplayMetrics()
act.windowManager.defaultDisplay.getMetrics(metrics)
val dimensions: Pair<Int, Int> = if (wallpaper.intrinsicWidth >= wallpaper.intrinsicHeight) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val display = requireActivity().display
display?.getRealMetrics(metrics)
} else {
@Suppress("DEPRECATION")
val display = requireActivity().windowManager.defaultDisplay
@Suppress("DEPRECATION")
display.getMetrics(metrics)
}
val dimensions: Pair<Int, Int> =
if (wallpaper.intrinsicWidth >= wallpaper.intrinsicHeight) {
metrics.heightPixels to (wallpaper.intrinsicWidth) * metrics.heightPixels / (wallpaper.intrinsicHeight) metrics.heightPixels to (wallpaper.intrinsicWidth) * metrics.heightPixels / (wallpaper.intrinsicHeight)
} else { } else {
metrics.widthPixels to (wallpaper.intrinsicHeight) * metrics.widthPixels / (wallpaper.intrinsicWidth) metrics.widthPixels to (wallpaper.intrinsicHeight) * metrics.widthPixels / (wallpaper.intrinsicWidth)
} }
setMargins( setMargins(
if (dimensions.first >= dimensions.second) (-80).toPixel(requireContext()) else 0, if (dimensions.first >= dimensions.second) (-80).toPixel(
requireContext()) else 0,
(-80).toPixel(requireContext()), 0, 0 (-80).toPixel(requireContext()), 0, 0
) )
@ -324,10 +322,12 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
height = dimensions.second height = dimensions.second
} }
} }
} else {
binding.widgetBg.setImageDrawable(null)
}
} }
})
action_settings.setOnClickListener { binding.actionSettings.setOnClickListener {
Navigation.findNavController(it).navigate(R.id.action_appMainFragment_to_appSettingsFragment) Navigation.findNavController(it).navigate(R.id.action_appMainFragment_to_appSettingsFragment)
} }
} }
@ -350,7 +350,7 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
override fun onSharedPreferenceChanged(preferences: SharedPreferences, p1: String) { override fun onSharedPreferenceChanged(preferences: SharedPreferences, p1: String) {
delayJob?.cancel() delayJob?.cancel()
delayJob = lifecycleScope.launch(Dispatchers.IO) { delayJob = lifecycleScope.launch(Dispatchers.IO) {
delay(200) delay(300)
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
updateUI() updateUI()
} }
@ -365,7 +365,7 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
fun onMessageEvent(ignore: UpdateUiMessageEvent?) { fun onMessageEvent(ignore: UpdateUiMessageEvent?) {
delayJob?.cancel() delayJob?.cancel()
delayJob = lifecycleScope.launch(Dispatchers.IO) { delayJob = lifecycleScope.launch(Dispatchers.IO) {
delay(200) delay(300)
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
updateUI() updateUI()
} }

View File

@ -24,7 +24,7 @@ import com.karumi.dexter.listener.multi.MultiplePermissionsListener
import com.tommasoberlose.anotherwidget.BuildConfig import com.tommasoberlose.anotherwidget.BuildConfig
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
import com.tommasoberlose.anotherwidget.databinding.FragmentSettingsBinding import com.tommasoberlose.anotherwidget.databinding.FragmentAppSettingsBinding
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.ActiveNotificationsHelper import com.tommasoberlose.anotherwidget.helpers.ActiveNotificationsHelper
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
@ -36,7 +36,6 @@ import com.tommasoberlose.anotherwidget.ui.activities.settings.SupportDevActivit
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
import com.tommasoberlose.anotherwidget.utils.openURI import com.tommasoberlose.anotherwidget.utils.openURI
import kotlinx.android.synthetic.main.fragment_settings.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -49,6 +48,7 @@ class SettingsFragment : Fragment() {
} }
private lateinit var viewModel: MainViewModel private lateinit var viewModel: MainViewModel
private lateinit var binding: FragmentAppSettingsBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -63,10 +63,7 @@ class SettingsFragment : Fragment() {
): View { ): View {
viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java) viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java)
val binding = DataBindingUtil.inflate<FragmentSettingsBinding>(inflater, binding = FragmentAppSettingsBinding.inflate(inflater)
R.layout.fragment_app_settings,
container,
false)
binding.lifecycleOwner = this binding.lifecycleOwner = this
binding.viewModel = viewModel binding.viewModel = viewModel
@ -79,16 +76,16 @@ class SettingsFragment : Fragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
action_back.setOnClickListener { binding.actionBack.setOnClickListener {
Navigation.findNavController(it).popBackStack() Navigation.findNavController(it).popBackStack()
} }
show_widget_preview_toggle.setCheckedImmediatelyNoEvent(Preferences.showPreview) binding.showWidgetPreviewToggle.setCheckedImmediatelyNoEvent(Preferences.showPreview)
show_wallpaper_toggle.setCheckedImmediatelyNoEvent(Preferences.showWallpaper) binding.showWallpaperToggle.setCheckedImmediatelyNoEvent(Preferences.showWallpaper)
setupListener() setupListener()
app_version.text = "v%s (%s)".format(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE) binding.appVersion.text = "v%s (%s)".format(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE)
} }
private fun subscribeUi( private fun subscribeUi(
@ -97,7 +94,7 @@ class SettingsFragment : Fragment() {
viewModel.darkThemePreference.observe(viewLifecycleOwner, Observer { viewModel.darkThemePreference.observe(viewLifecycleOwner, Observer {
AppCompatDelegate.setDefaultNightMode(it) AppCompatDelegate.setDefaultNightMode(it)
maintainScrollPosition { maintainScrollPosition {
theme?.text = when (it) { binding.theme?.text = when (it) {
AppCompatDelegate.MODE_NIGHT_NO -> getString(R.string.settings_subtitle_dark_theme_light) AppCompatDelegate.MODE_NIGHT_NO -> getString(R.string.settings_subtitle_dark_theme_light)
AppCompatDelegate.MODE_NIGHT_YES -> getString(R.string.settings_subtitle_dark_theme_dark) AppCompatDelegate.MODE_NIGHT_YES -> getString(R.string.settings_subtitle_dark_theme_dark)
AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY -> getString(R.string.settings_subtitle_dark_theme_by_battery_saver) AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY -> getString(R.string.settings_subtitle_dark_theme_by_battery_saver)
@ -108,21 +105,21 @@ class SettingsFragment : Fragment() {
}) })
viewModel.installedIntegrations.observe(viewLifecycleOwner, Observer { viewModel.installedIntegrations.observe(viewLifecycleOwner, Observer {
integrations_count_label?.text = binding.integrationsCountLabel?.text =
getString(R.string.label_count_installed_integrations).format( getString(R.string.label_count_installed_integrations).format(
it) it)
}) })
viewModel.showPreview.observe(viewLifecycleOwner, Observer { viewModel.showPreview.observe(viewLifecycleOwner, Observer {
maintainScrollPosition { maintainScrollPosition {
show_widget_preview_label?.text = binding.showWidgetPreviewLabel.text =
if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible) if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
} }
}) })
viewModel.showWallpaper.observe(viewLifecycleOwner, Observer { viewModel.showWallpaper.observe(viewLifecycleOwner, Observer {
maintainScrollPosition { maintainScrollPosition {
show_wallpaper_label?.text = binding.showWallpaperLabel.text =
if (it && activity?.checkGrantedPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == true) getString( if (it && activity?.checkGrantedPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == true) getString(
R.string.settings_visible R.string.settings_visible
) else getString(R.string.settings_not_visible) ) else getString(R.string.settings_not_visible)
@ -131,19 +128,19 @@ class SettingsFragment : Fragment() {
} }
private fun setupListener() { private fun setupListener() {
action_show_widget_preview.setOnClickListener { binding.actionShowWidgetPreview.setOnClickListener {
show_widget_preview_toggle.isChecked = !show_widget_preview_toggle.isChecked binding.showWidgetPreviewToggle.isChecked = !binding.showWidgetPreviewToggle.isChecked
} }
show_widget_preview_toggle.setOnCheckedChangeListener { _, isChecked -> binding.showWidgetPreviewToggle.setOnCheckedChangeListener { _, isChecked ->
Preferences.showPreview = isChecked Preferences.showPreview = isChecked
} }
action_show_wallpaper.setOnClickListener { binding.actionShowWallpaper.setOnClickListener {
show_wallpaper_toggle.isChecked = !show_wallpaper_toggle.isChecked binding.showWallpaperToggle.isChecked = !binding.showWallpaperToggle.isChecked
} }
show_wallpaper_toggle.setOnCheckedChangeListener { _, isChecked -> binding.showWallpaperToggle.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) { if (isChecked) {
requirePermission() requirePermission()
} else { } else {
@ -151,11 +148,11 @@ class SettingsFragment : Fragment() {
} }
} }
action_integrations.setOnClickListener { binding.actionIntegrations.setOnClickListener {
startActivity(Intent(requireContext(), IntegrationsActivity::class.java)) startActivity(Intent(requireContext(), IntegrationsActivity::class.java))
} }
action_change_theme.setOnClickListener { binding.actionChangeTheme.setOnClickListener {
maintainScrollPosition { maintainScrollPosition {
BottomSheetMenu<Int>(requireContext(), BottomSheetMenu<Int>(requireContext(),
header = getString(R.string.settings_theme_title)) header = getString(R.string.settings_theme_title))
@ -178,30 +175,30 @@ class SettingsFragment : Fragment() {
} }
} }
action_translate.setOnClickListener { binding.actionTranslate.setOnClickListener {
activity?.openURI("https://github.com/tommasoberlose/another-widget/blob/master/app/src/main/res/values/strings.xml") activity?.openURI("https://github.com/tommasoberlose/another-widget/blob/master/app/src/main/res/values/strings.xml")
} }
action_website.setOnClickListener { binding.actionWebsite.setOnClickListener {
activity?.openURI("http://tommasoberlose.com/") activity?.openURI("http://tommasoberlose.com/")
} }
action_feedback.setOnClickListener { binding.actionFeedback.setOnClickListener {
activity?.openURI("https://github.com/tommasoberlose/another-widget/issues") activity?.openURI("https://github.com/tommasoberlose/another-widget/issues")
} }
action_privacy_policy.setOnClickListener { binding.actionPrivacyPolicy.setOnClickListener {
activity?.openURI("https://github.com/tommasoberlose/another-widget/blob/master/privacy-policy.md") activity?.openURI("https://github.com/tommasoberlose/another-widget/blob/master/privacy-policy.md")
} }
action_help_dev.setOnClickListener { binding.actionHelpDev.setOnClickListener {
startActivity(Intent(requireContext(), SupportDevActivity::class.java)) startActivity(Intent(requireContext(), SupportDevActivity::class.java))
} }
action_refresh_widget.setOnClickListener { binding.actionRefreshWidget.setOnClickListener {
action_refresh_icon binding.actionRefreshIcon
.animate() .animate()
.rotation((action_refresh_icon.rotation - action_refresh_icon.rotation % 360f) + 360f) .rotation((binding.actionRefreshIcon.rotation - binding.actionRefreshIcon.rotation % 360f) + 360f)
.withEndAction { .withEndAction {
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) { viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
WeatherHelper.updateWeather(requireContext()) WeatherHelper.updateWeather(requireContext())
@ -215,11 +212,11 @@ class SettingsFragment : Fragment() {
} }
private fun maintainScrollPosition(callback: () -> Unit) { private fun maintainScrollPosition(callback: () -> Unit) {
scrollView.isScrollable = false binding.scrollView.isScrollable = false
callback.invoke() callback.invoke()
lifecycleScope.launch { lifecycleScope.launch {
delay(200) delay(200)
scrollView.isScrollable = true binding.scrollView.isScrollable = true
} }
} }
@ -233,7 +230,7 @@ class SettingsFragment : Fragment() {
if (report.areAllPermissionsGranted()) { if (report.areAllPermissionsGranted()) {
Preferences.showWallpaper = true Preferences.showWallpaper = true
} else { } else {
show_wallpaper_toggle?.isChecked = false binding.showWallpaperToggle.isChecked = false
} }
} }
} }

View File

@ -18,7 +18,7 @@ import com.google.android.material.transition.MaterialSharedAxis
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
import com.tommasoberlose.anotherwidget.models.CalendarSelector import com.tommasoberlose.anotherwidget.models.CalendarSelector
import com.tommasoberlose.anotherwidget.databinding.FragmentCalendarSettingsBinding import com.tommasoberlose.anotherwidget.databinding.FragmentTabCalendarBinding
import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.global.RequestCode import com.tommasoberlose.anotherwidget.global.RequestCode
@ -31,8 +31,6 @@ import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
import com.tommasoberlose.anotherwidget.utils.isDefaultSet import com.tommasoberlose.anotherwidget.utils.isDefaultSet
import com.tommasoberlose.anotherwidget.utils.toast import com.tommasoberlose.anotherwidget.utils.toast
import kotlinx.android.synthetic.main.fragment_calendar_settings.*
import kotlinx.android.synthetic.main.fragment_calendar_settings.scrollView
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlin.Comparator import kotlin.Comparator
@ -44,6 +42,7 @@ class CalendarFragment : Fragment() {
} }
private lateinit var viewModel: MainViewModel private lateinit var viewModel: MainViewModel
private lateinit var binding: FragmentTabCalendarBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -57,9 +56,9 @@ class CalendarFragment : Fragment() {
): View { ): View {
viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java) viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java)
val binding = DataBindingUtil.inflate<FragmentCalendarSettingsBinding>(inflater, R.layout.fragment_tab_calendar, container, false) binding = FragmentTabCalendarBinding.inflate(inflater)
subscribeUi(binding, viewModel) subscribeUi(viewModel)
binding.lifecycleOwner = this binding.lifecycleOwner = this
binding.viewModel = viewModel binding.viewModel = viewModel
@ -70,73 +69,72 @@ class CalendarFragment : Fragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
show_all_day_toggle.isChecked = Preferences.calendarAllDay binding.showAllDayToggle.setCheckedImmediatelyNoEvent(Preferences.calendarAllDay)
show_only_busy_events_toggle.isChecked = Preferences.showOnlyBusyEvents binding.showOnlyBusyEventsToggle.setCheckedImmediatelyNoEvent(Preferences.showOnlyBusyEvents)
show_diff_time_toggle.isChecked = Preferences.showDiffTime binding.showDiffTimeToggle.setCheckedImmediatelyNoEvent(Preferences.showDiffTime)
show_multiple_events_toggle.isChecked = Preferences.showNextEvent binding.showMultipleEventsToggle.setCheckedImmediatelyNoEvent(Preferences.showNextEvent)
setupListener() setupListener()
scrollView?.viewTreeObserver?.addOnScrollChangedListener { binding.scrollView.viewTreeObserver.addOnScrollChangedListener {
viewModel.fragmentScrollY.value = scrollView?.scrollY ?: 0 viewModel.fragmentScrollY.value = binding.scrollView.scrollY
} }
} }
private fun subscribeUi( private fun subscribeUi(
binding: FragmentCalendarSettingsBinding,
viewModel: MainViewModel viewModel: MainViewModel
) { ) {
binding.isCalendarEnabled = Preferences.showEvents binding.isCalendarEnabled = Preferences.showEvents
binding.isDiffEnabled = Preferences.showDiffTime || !Preferences.showEvents binding.isDiffEnabled = Preferences.showDiffTime || !Preferences.showEvents
viewModel.calendarAllDay.observe(viewLifecycleOwner, Observer { viewModel.calendarAllDay.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
all_day_label?.text = binding.allDayLabel.text =
if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible) if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
} }
})
viewModel.secondRowInformation.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
second_row_info_label?.text = getString(SettingsStringHelper.getSecondRowInfoString(it))
} }
})
viewModel.showDiffTime.observe(viewLifecycleOwner, Observer { viewModel.secondRowInformation.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
show_diff_time_label?.text = if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible) binding.secondRowInfoLabel.text = getString(SettingsStringHelper.getSecondRowInfoString(it))
}
}
viewModel.showDiffTime.observe(viewLifecycleOwner) {
maintainScrollPosition {
binding.showDiffTimeLabel.text = if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
binding.isDiffEnabled = it || !Preferences.showEvents binding.isDiffEnabled = it || !Preferences.showEvents
} }
}) }
viewModel.widgetUpdateFrequency.observe(viewLifecycleOwner, Observer { viewModel.widgetUpdateFrequency.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
widget_update_frequency_label?.text = when (it) { binding.widgetUpdateFrequencyLabel.text = when (it) {
Constants.WidgetUpdateFrequency.HIGH.value -> getString(R.string.settings_widget_update_frequency_high) Constants.WidgetUpdateFrequency.HIGH.value -> getString(R.string.settings_widget_update_frequency_high)
Constants.WidgetUpdateFrequency.DEFAULT.value -> getString(R.string.settings_widget_update_frequency_default) Constants.WidgetUpdateFrequency.DEFAULT.value -> getString(R.string.settings_widget_update_frequency_default)
Constants.WidgetUpdateFrequency.LOW.value -> getString(R.string.settings_widget_update_frequency_low) Constants.WidgetUpdateFrequency.LOW.value -> getString(R.string.settings_widget_update_frequency_low)
else -> "" else -> ""
} }
} }
}) }
viewModel.showUntil.observe(viewLifecycleOwner, Observer { viewModel.showUntil.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
show_until_label?.text = getString(SettingsStringHelper.getShowUntilString(it)) binding.showUntilLabel.text = getString(SettingsStringHelper.getShowUntilString(it))
} }
updateCalendar() updateCalendar()
}) }
viewModel.showNextEvent.observe(viewLifecycleOwner, Observer { viewModel.showNextEvent.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
show_multiple_events_label?.text = binding.showMultipleEventsLabel.text =
if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible) if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
} }
}) }
viewModel.calendarAppName.observe(viewLifecycleOwner, Observer { viewModel.calendarAppName.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
calendar_app_label?.text = when { binding.calendarAppLabel.text = when {
Preferences.calendarAppName != "" -> Preferences.calendarAppName Preferences.calendarAppName != "" -> Preferences.calendarAppName
else -> { else -> {
if (IntentHelper.getCalendarIntent(requireContext()).isDefaultSet(requireContext())) { if (IntentHelper.getCalendarIntent(requireContext()).isDefaultSet(requireContext())) {
@ -149,19 +147,19 @@ class CalendarFragment : Fragment() {
} }
} }
} }
})
viewModel.openEventDetails.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
open_event_details_label?.text = if (it) getString(R.string.default_event_app) else getString(R.string.default_calendar_app)
} }
})
viewModel.openEventDetails.observe(viewLifecycleOwner) {
maintainScrollPosition {
binding.openEventDetailsLabel.text = if (it) getString(R.string.default_event_app) else getString(R.string.default_calendar_app)
}
}
} }
private fun setupListener() { private fun setupListener() {
action_filter_calendar.setOnClickListener { binding.actionFilterCalendar.setOnClickListener {
val calendarSelectorList: List<CalendarSelector> = CalendarHelper.getCalendarList(requireContext()).map { val calendarSelectorList: List<CalendarSelector> = CalendarHelper.getCalendarList(requireContext()).map {
CalendarSelector( CalendarSelector(
it.id, it.id,
@ -212,16 +210,16 @@ class CalendarFragment : Fragment() {
} }
} }
action_show_all_day.setOnClickListener { binding.actionShowAllDay.setOnClickListener {
show_all_day_toggle.isChecked = !show_all_day_toggle.isChecked binding.showAllDayToggle.isChecked = !binding.showAllDayToggle.isChecked
} }
show_all_day_toggle.setOnCheckedChangeListener { _, isChecked -> binding.showAllDayToggle.setOnCheckedChangeListener { _, isChecked ->
Preferences.calendarAllDay = isChecked Preferences.calendarAllDay = isChecked
updateCalendar() updateCalendar()
} }
action_change_attendee_filter.setOnClickListener { binding.actionChangeAttendeeFilter.setOnClickListener {
val selectedValues = emptyList<Int>().toMutableList() val selectedValues = emptyList<Int>().toMutableList()
if (Preferences.showDeclinedEvents) { if (Preferences.showDeclinedEvents) {
selectedValues.add(CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED) selectedValues.add(CalendarContract.Attendees.ATTENDEE_STATUS_DECLINED)
@ -257,32 +255,32 @@ class CalendarFragment : Fragment() {
}.show() }.show()
} }
action_show_only_busy_events.setOnClickListener { binding.actionShowOnlyBusyEvents.setOnClickListener {
show_only_busy_events_toggle.isChecked = !show_only_busy_events_toggle.isChecked binding.showOnlyBusyEventsToggle.isChecked = !binding.showOnlyBusyEventsToggle.isChecked
} }
show_only_busy_events_toggle.setOnCheckedChangeListener { _, isChecked -> binding.showOnlyBusyEventsToggle.setOnCheckedChangeListener { _, isChecked ->
Preferences.showOnlyBusyEvents = isChecked Preferences.showOnlyBusyEvents = isChecked
updateCalendar() updateCalendar()
} }
action_show_multiple_events.setOnClickListener { binding.actionShowMultipleEvents.setOnClickListener {
show_multiple_events_toggle.isChecked = !show_multiple_events_toggle.isChecked binding.showMultipleEventsToggle.isChecked = !binding.showMultipleEventsToggle.isChecked
} }
show_multiple_events_toggle.setOnCheckedChangeListener { _, isChecked -> binding.showMultipleEventsToggle.setOnCheckedChangeListener { _, isChecked ->
Preferences.showNextEvent = isChecked Preferences.showNextEvent = isChecked
} }
action_show_diff_time.setOnClickListener { binding.actionShowDiffTime.setOnClickListener {
show_diff_time_toggle.isChecked = !show_diff_time_toggle.isChecked binding.showDiffTimeToggle.isChecked = !binding.showDiffTimeToggle.isChecked
} }
show_diff_time_toggle.setOnCheckedChangeListener { _, isChecked -> binding.showDiffTimeToggle.setOnCheckedChangeListener { _, isChecked ->
Preferences.showDiffTime = isChecked Preferences.showDiffTime = isChecked
} }
action_widget_update_frequency.setOnClickListener { binding.actionWidgetUpdateFrequency.setOnClickListener {
if (Preferences.showEvents && Preferences.showDiffTime) { if (Preferences.showEvents && Preferences.showDiffTime) {
BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_widget_update_frequency_title), message = getString(R.string.settings_widget_update_frequency_subtitle)).setSelectedValue(Preferences.widgetUpdateFrequency) BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_widget_update_frequency_title), message = getString(R.string.settings_widget_update_frequency_subtitle)).setSelectedValue(Preferences.widgetUpdateFrequency)
.addItem(getString(R.string.settings_widget_update_frequency_high), Constants.WidgetUpdateFrequency.HIGH.value) .addItem(getString(R.string.settings_widget_update_frequency_high), Constants.WidgetUpdateFrequency.HIGH.value)
@ -294,7 +292,7 @@ class CalendarFragment : Fragment() {
} }
} }
action_second_row_info.setOnClickListener { binding.actionSecondRowInfo.setOnClickListener {
val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_second_row_info_title)).setSelectedValue(Preferences.secondRowInformation) val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_second_row_info_title)).setSelectedValue(Preferences.secondRowInformation)
(0 .. 1).forEach { (0 .. 1).forEach {
dialog.addItem(getString(SettingsStringHelper.getSecondRowInfoString(it)), it) dialog.addItem(getString(SettingsStringHelper.getSecondRowInfoString(it)), it)
@ -304,7 +302,7 @@ class CalendarFragment : Fragment() {
}.show() }.show()
} }
action_show_until.setOnClickListener { binding.actionShowUntil.setOnClickListener {
val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_show_until_title)).setSelectedValue(Preferences.showUntil) val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_show_until_title)).setSelectedValue(Preferences.showUntil)
intArrayOf(6,7,0,1,2,3, 4, 5).forEach { intArrayOf(6,7,0,1,2,3, 4, 5).forEach {
dialog.addItem(getString(SettingsStringHelper.getShowUntilString(it)), it) dialog.addItem(getString(SettingsStringHelper.getShowUntilString(it)), it)
@ -314,7 +312,7 @@ class CalendarFragment : Fragment() {
}.show() }.show()
} }
action_open_event_details.setOnClickListener { binding.actionOpenEventDetails.setOnClickListener {
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_event_app_title)).setSelectedValue(Preferences.openEventDetails) BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_event_app_title)).setSelectedValue(Preferences.openEventDetails)
.addItem(getString(R.string.default_event_app), true) .addItem(getString(R.string.default_event_app), true)
.addItem(getString(R.string.default_calendar_app), false) .addItem(getString(R.string.default_calendar_app), false)
@ -324,7 +322,7 @@ class CalendarFragment : Fragment() {
.show() .show()
} }
action_calendar_app.setOnClickListener { binding.actionCalendarApp.setOnClickListener {
startActivityForResult(Intent(requireContext(), ChooseApplicationActivity::class.java), RequestCode.CALENDAR_APP_REQUEST_CODE.code) startActivityForResult(Intent(requireContext(), ChooseApplicationActivity::class.java), RequestCode.CALENDAR_APP_REQUEST_CODE.code)
} }
} }
@ -356,11 +354,11 @@ class CalendarFragment : Fragment() {
} }
private fun maintainScrollPosition(callback: () -> Unit) { private fun maintainScrollPosition(callback: () -> Unit) {
scrollView.isScrollable = false binding.scrollView.isScrollable = false
callback.invoke() callback.invoke()
lifecycleScope.launch { lifecycleScope.launch {
delay(200) delay(200)
scrollView.isScrollable = true binding.scrollView.isScrollable = true
} }
} }
} }

View File

@ -7,6 +7,7 @@ import android.text.format.DateFormat
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
@ -17,7 +18,7 @@ import com.google.android.material.transition.MaterialSharedAxis
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.components.BottomSheetColorPicker import com.tommasoberlose.anotherwidget.components.BottomSheetColorPicker
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
import com.tommasoberlose.anotherwidget.databinding.FragmentClockSettingsBinding import com.tommasoberlose.anotherwidget.databinding.FragmentClockBinding
import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.global.RequestCode import com.tommasoberlose.anotherwidget.global.RequestCode
@ -30,8 +31,6 @@ import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
import com.tommasoberlose.anotherwidget.utils.isDarkTheme import com.tommasoberlose.anotherwidget.utils.isDarkTheme
import com.tommasoberlose.anotherwidget.utils.isDefaultSet import com.tommasoberlose.anotherwidget.utils.isDefaultSet
import kotlinx.android.synthetic.main.fragment_clock_settings.*
import kotlinx.android.synthetic.main.fragment_clock_settings.scrollView
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -46,7 +45,7 @@ class ClockFragment : Fragment() {
private lateinit var viewModel: MainViewModel private lateinit var viewModel: MainViewModel
private lateinit var colors: IntArray private lateinit var colors: IntArray
private lateinit var binding: FragmentClockSettingsBinding private lateinit var binding: FragmentClockBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -60,9 +59,9 @@ class ClockFragment : Fragment() {
): View { ): View {
viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java) viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java)
binding = DataBindingUtil.inflate<FragmentClockSettingsBinding>(inflater, R.layout.fragment_clock, container, false) binding = FragmentClockBinding.inflate(inflater)
subscribeUi(binding, viewModel) subscribeUi(viewModel)
binding.lifecycleOwner = this binding.lifecycleOwner = this
binding.viewModel = viewModel binding.viewModel = viewModel
@ -73,7 +72,7 @@ class ClockFragment : Fragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
ampm_indicator_toggle.isChecked = Preferences.showAMPMIndicator binding.ampmIndicatorToggle.setCheckedImmediatelyNoEvent(Preferences.showAMPMIndicator)
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
val lazyColors = requireContext().resources.getIntArray(R.array.material_colors) val lazyColors = requireContext().resources.getIntArray(R.array.material_colors)
@ -83,94 +82,93 @@ class ClockFragment : Fragment() {
} }
setupListener() setupListener()
scrollView?.viewTreeObserver?.addOnScrollChangedListener { binding.scrollView.viewTreeObserver?.addOnScrollChangedListener {
viewModel.fragmentScrollY.value = scrollView?.scrollY ?: 0 viewModel.fragmentScrollY.value = binding.scrollView.scrollY
} }
} }
private fun subscribeUi( private fun subscribeUi(
binding: FragmentClockSettingsBinding,
viewModel: MainViewModel viewModel: MainViewModel
) { ) {
binding.isClockVisible = Preferences.showClock binding.isClockVisible = Preferences.showClock
binding.is24Format = DateFormat.is24HourFormat(requireContext()) binding.is24Format = DateFormat.is24HourFormat(requireContext())
binding.isDarkModeEnabled = activity?.isDarkTheme() == true binding.isDarkModeEnabled = activity?.isDarkTheme() == true
viewModel.showBigClockWarning.observe(viewLifecycleOwner, Observer { viewModel.showBigClockWarning.observe(viewLifecycleOwner) {
large_clock_warning?.isVisible = it binding.largeClockWarning.isVisible = it
small_clock_warning?.isVisible = !it binding.smallClockWarning.isVisible = !it
})
viewModel.clockTextSize.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
clock_text_size_label?.text = String.format("%.0fsp", it)
} }
})
viewModel.showAMPMIndicator.observe(viewLifecycleOwner, Observer { viewModel.clockTextSize.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
ampm_indicator_label?.text = if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible) binding.clockTextSizeLabel.text = String.format("%.0fsp", it)
}
} }
})
viewModel.clockTextColor.observe(viewLifecycleOwner, Observer { viewModel.showAMPMIndicator.observe(viewLifecycleOwner) {
maintainScrollPosition {
binding.ampmIndicatorLabel.text = if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
}
}
viewModel.clockTextColor.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (Preferences.clockTextAlpha == "00") { if (Preferences.clockTextAlpha == "00") {
clock_text_color_label?.text = getString(R.string.transparent) binding.clockTextColorLabel.text = getString(R.string.transparent)
} else { } else {
clock_text_color_label?.text = binding.clockTextColorLabel.text =
"#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
}) }
viewModel.clockTextColorDark.observe(viewLifecycleOwner, Observer { viewModel.clockTextColorDark.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (Preferences.clockTextAlphaDark == "00") { if (Preferences.clockTextAlphaDark == "00") {
clock_text_color_label?.text = getString(R.string.transparent) binding.clockTextColorLabel.text = getString(R.string.transparent)
} else { } else {
clock_text_color_label?.text = binding.clockTextColorLabel.text =
"#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
}) }
viewModel.clockTextAlpha.observe(viewLifecycleOwner, Observer { viewModel.clockTextAlpha.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (Preferences.clockTextAlpha == "00") { if (Preferences.clockTextAlpha == "00") {
clock_text_color_label?.text = getString(R.string.transparent) binding.clockTextColorLabel.text = getString(R.string.transparent)
} else { } else {
clock_text_color_label?.text = binding.clockTextColorLabel.text =
"#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
}) }
viewModel.clockTextAlphaDark.observe(viewLifecycleOwner, Observer { viewModel.clockTextAlphaDark.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (Preferences.clockTextAlphaDark == "00") { if (Preferences.clockTextAlphaDark == "00") {
clock_text_color_label?.text = getString(R.string.transparent) binding.clockTextColorLabel.text = getString(R.string.transparent)
} else { } else {
clock_text_color_label?.text = binding.clockTextColorLabel.text =
"#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
}) }
viewModel.clockBottomMargin.observe(viewLifecycleOwner, Observer { viewModel.clockBottomMargin.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
clock_bottom_margin_label?.text = when (it) { binding.clockBottomMarginLabel.text = when (it) {
Constants.ClockBottomMargin.NONE.value -> getString(R.string.settings_clock_bottom_margin_subtitle_none) Constants.ClockBottomMargin.NONE.value -> getString(R.string.settings_clock_bottom_margin_subtitle_none)
Constants.ClockBottomMargin.SMALL.value -> getString(R.string.settings_clock_bottom_margin_subtitle_small) Constants.ClockBottomMargin.SMALL.value -> getString(R.string.settings_clock_bottom_margin_subtitle_small)
Constants.ClockBottomMargin.LARGE.value -> getString(R.string.settings_clock_bottom_margin_subtitle_large) Constants.ClockBottomMargin.LARGE.value -> getString(R.string.settings_clock_bottom_margin_subtitle_large)
else -> getString(R.string.settings_clock_bottom_margin_subtitle_medium) else -> getString(R.string.settings_clock_bottom_margin_subtitle_medium)
} }
} }
}) }
viewModel.clockAppName.observe(viewLifecycleOwner, Observer { viewModel.clockAppName.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
clock_app_label?.text = when { binding.clockAppLabel.text = when {
Preferences.clockAppName != "" -> Preferences.clockAppName Preferences.clockAppName != "" -> Preferences.clockAppName
else -> { else -> {
if (IntentHelper.getClockIntent(requireContext()).isDefaultSet(requireContext())) { if (IntentHelper.getClockIntent(requireContext()).isDefaultSet(requireContext())) {
@ -183,15 +181,15 @@ class ClockFragment : Fragment() {
} }
} }
} }
}) }
} }
private fun setupListener() { private fun setupListener() {
action_hide_large_clock_warning.setOnClickListener { binding.actionHideLargeClockWarning.setOnClickListener {
Preferences.showBigClockWarning = false Preferences.showBigClockWarning = false
} }
action_clock_text_size.setOnClickListener { binding.actionClockTextSize.setOnClickListener {
val dialog = BottomSheetMenu<Float>( val dialog = BottomSheetMenu<Float>(
requireContext(), requireContext(),
header = getString(R.string.settings_clock_text_size_title) header = getString(R.string.settings_clock_text_size_title)
@ -204,15 +202,15 @@ class ClockFragment : Fragment() {
}.show() }.show()
} }
action_ampm_indicator_size.setOnClickListener { binding.actionAmpmIndicatorSize.setOnClickListener {
ampm_indicator_toggle.isChecked = !ampm_indicator_toggle.isChecked binding.ampmIndicatorToggle.isChecked = !binding.ampmIndicatorToggle.isChecked
} }
ampm_indicator_toggle.setOnCheckedChangeListener { _, isChecked -> binding.ampmIndicatorToggle.setOnCheckedChangeListener { _, isChecked ->
Preferences.showAMPMIndicator = isChecked Preferences.showAMPMIndicator = isChecked
} }
action_clock_text_color.setOnClickListener { binding.actionClockTextColor.setOnClickListener {
BottomSheetColorPicker(requireContext(), BottomSheetColorPicker(requireContext(),
colors = colors, colors = colors,
header = getString(R.string.settings_font_color_title), header = getString(R.string.settings_font_color_title),
@ -239,7 +237,7 @@ class ClockFragment : Fragment() {
).show() ).show()
} }
action_clock_bottom_margin_size.setOnClickListener { binding.actionClockBottomMarginSize.setOnClickListener {
BottomSheetMenu<Int>( BottomSheetMenu<Int>(
requireContext(), requireContext(),
header = getString(R.string.settings_clock_bottom_margin_title) header = getString(R.string.settings_clock_bottom_margin_title)
@ -265,7 +263,7 @@ class ClockFragment : Fragment() {
}.show() }.show()
} }
action_clock_app.setOnClickListener { binding.actionClockApp.setOnClickListener {
startActivityForResult( startActivityForResult(
Intent(requireContext(), ChooseApplicationActivity::class.java), Intent(requireContext(), ChooseApplicationActivity::class.java),
RequestCode.CLOCK_APP_REQUEST_CODE.code RequestCode.CLOCK_APP_REQUEST_CODE.code
@ -289,11 +287,11 @@ class ClockFragment : Fragment() {
} }
private fun maintainScrollPosition(callback: () -> Unit) { private fun maintainScrollPosition(callback: () -> Unit) {
scrollView.isScrollable = false binding.scrollView.isScrollable = false
callback.invoke() callback.invoke()
lifecycleScope.launch { lifecycleScope.launch {
delay(200) delay(200)
scrollView.isScrollable = true binding.scrollView.isScrollable = true
} }
} }
} }

View File

@ -31,7 +31,7 @@ import com.google.android.material.transition.MaterialSharedAxis
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.components.CustomNotesDialog import com.tommasoberlose.anotherwidget.components.CustomNotesDialog
import com.tommasoberlose.anotherwidget.components.GlanceSettingsDialog import com.tommasoberlose.anotherwidget.components.GlanceSettingsDialog
import com.tommasoberlose.anotherwidget.databinding.FragmentGlanceSettingsBinding import com.tommasoberlose.anotherwidget.databinding.FragmentTabGlanceBinding
import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.ActiveNotificationsHelper import com.tommasoberlose.anotherwidget.helpers.ActiveNotificationsHelper
@ -45,10 +45,6 @@ import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
import com.tommasoberlose.anotherwidget.utils.convertDpToPixel import com.tommasoberlose.anotherwidget.utils.convertDpToPixel
import kotlinx.android.synthetic.main.fragment_calendar_settings.*
import kotlinx.android.synthetic.main.fragment_glance_settings.*
import kotlinx.android.synthetic.main.fragment_glance_settings.scrollView
import kotlinx.android.synthetic.main.fragment_tab_selector.*
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import net.idik.lib.slimadapter.SlimAdapter import net.idik.lib.slimadapter.SlimAdapter
@ -64,6 +60,7 @@ class GlanceTabFragment : Fragment() {
private lateinit var adapter: SlimAdapter private lateinit var adapter: SlimAdapter
private lateinit var viewModel: MainViewModel private lateinit var viewModel: MainViewModel
private lateinit var list: ArrayList<Constants.GlanceProviderId> private lateinit var list: ArrayList<Constants.GlanceProviderId>
private lateinit var binding: FragmentTabGlanceBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -77,12 +74,9 @@ class GlanceTabFragment : Fragment() {
): View { ): View {
viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java) viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java)
val binding = DataBindingUtil.inflate<FragmentGlanceSettingsBinding>(inflater, binding = FragmentTabGlanceBinding.inflate(inflater)
R.layout.fragment_tab_glance,
container,
false)
subscribeUi(binding, viewModel) subscribeUi(viewModel)
binding.lifecycleOwner = this binding.lifecycleOwner = this
binding.viewModel = viewModel binding.viewModel = viewModel
@ -96,9 +90,9 @@ class GlanceTabFragment : Fragment() {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
// List // List
providers_list.setHasFixedSize(true) binding.providersList.setHasFixedSize(true)
val mLayoutManager = LinearLayoutManager(context) val mLayoutManager = LinearLayoutManager(context)
providers_list.layoutManager = mLayoutManager binding.providersList.layoutManager = mLayoutManager
adapter = SlimAdapter.create() adapter = SlimAdapter.create()
adapter adapter
@ -257,7 +251,7 @@ class GlanceTabFragment : Fragment() {
injector.alpha(R.id.label, if (isVisible) 1f else .25f) injector.alpha(R.id.label, if (isVisible) 1f else .25f)
injector.alpha(R.id.icon, if (isVisible) 1f else .25f) injector.alpha(R.id.icon, if (isVisible) 1f else .25f)
} }
.attachTo(providers_list) .attachTo(binding.providersList)
val mIth = ItemTouchHelper( val mIth = ItemTouchHelper(
object : ItemTouchHelper.SimpleCallback( object : ItemTouchHelper.SimpleCallback(
@ -348,19 +342,18 @@ class GlanceTabFragment : Fragment() {
} }
}) })
mIth.attachToRecyclerView(providers_list) mIth.attachToRecyclerView(binding.providersList)
adapter.updateData(list.mapNotNull { GlanceProviderHelper.getGlanceProviderById(requireContext(), it) }) adapter.updateData(list.mapNotNull { GlanceProviderHelper.getGlanceProviderById(requireContext(), it) })
providers_list.isNestedScrollingEnabled = false binding.providersList.isNestedScrollingEnabled = false
setupListener() setupListener()
scrollView?.viewTreeObserver?.addOnScrollChangedListener { binding.scrollView.viewTreeObserver.addOnScrollChangedListener {
viewModel.fragmentScrollY.value = scrollView?.scrollY ?: 0 viewModel.fragmentScrollY.value = binding.scrollView.scrollY
} }
} }
private fun subscribeUi( private fun subscribeUi(
binding: FragmentGlanceSettingsBinding,
viewModel: MainViewModel, viewModel: MainViewModel,
) { ) {
binding.isGlanceVisible = Preferences.showGlance binding.isGlanceVisible = Preferences.showGlance
@ -432,11 +425,11 @@ class GlanceTabFragment : Fragment() {
} }
private fun maintainScrollPosition(callback: () -> Unit) { private fun maintainScrollPosition(callback: () -> Unit) {
scrollView.isScrollable = false binding.scrollView.isScrollable = false
callback.invoke() callback.invoke()
lifecycleScope.launch { lifecycleScope.launch {
delay(200) delay(200)
scrollView.isScrollable = true binding.scrollView.isScrollable = true
} }
} }

View File

@ -16,7 +16,7 @@ import com.google.android.material.transition.MaterialSharedAxis
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.components.BottomSheetColorPicker import com.tommasoberlose.anotherwidget.components.BottomSheetColorPicker
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
import com.tommasoberlose.anotherwidget.databinding.FragmentGeneralSettingsBinding import com.tommasoberlose.anotherwidget.databinding.FragmentTabLayoutBinding
import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.ColorHelper import com.tommasoberlose.anotherwidget.helpers.ColorHelper
@ -27,10 +27,6 @@ import com.tommasoberlose.anotherwidget.ui.activities.tabs.CustomDateActivity
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
import com.tommasoberlose.anotherwidget.utils.isDarkTheme import com.tommasoberlose.anotherwidget.utils.isDarkTheme
import kotlinx.android.synthetic.main.fragment_calendar_settings.*
import kotlinx.android.synthetic.main.fragment_clock_settings.*
import kotlinx.android.synthetic.main.fragment_general_settings.*
import kotlinx.android.synthetic.main.fragment_tab_selector.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -46,6 +42,7 @@ class LayoutFragment : Fragment() {
private lateinit var viewModel: MainViewModel private lateinit var viewModel: MainViewModel
private lateinit var colors: IntArray private lateinit var colors: IntArray
private lateinit var binding: FragmentTabLayoutBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -59,7 +56,7 @@ class LayoutFragment : Fragment() {
): View { ): View {
viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java) viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java)
val binding = DataBindingUtil.inflate<FragmentGeneralSettingsBinding>(inflater, R.layout.fragment_tab_layout, container, false) binding = FragmentTabLayoutBinding.inflate(inflater)
subscribeUi(viewModel) subscribeUi(viewModel)
@ -73,7 +70,7 @@ class LayoutFragment : Fragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
show_dividers_toggle.isChecked = Preferences.showDividers binding.showDividersToggle.setCheckedImmediatelyNoEvent(Preferences.showDividers)
setupListener() setupListener()
lifecycleScope.launch(Dispatchers.IO) { lifecycleScope.launch(Dispatchers.IO) {
@ -83,8 +80,8 @@ class LayoutFragment : Fragment() {
} }
} }
scrollView?.viewTreeObserver?.addOnScrollChangedListener { binding.scrollView.viewTreeObserver?.addOnScrollChangedListener {
viewModel.fragmentScrollY.value = scrollView?.scrollY ?: 0 viewModel.fragmentScrollY.value = binding.scrollView.scrollY
} }
} }
@ -94,78 +91,78 @@ class LayoutFragment : Fragment() {
viewModel: MainViewModel viewModel: MainViewModel
) { ) {
viewModel.secondRowTopMargin.observe(viewLifecycleOwner, Observer { viewModel.secondRowTopMargin.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
second_row_top_margin_label?.text = when (it) { binding.secondRowTopMarginLabel.text = when (it) {
Constants.SecondRowTopMargin.NONE.value -> getString(R.string.settings_clock_bottom_margin_subtitle_none) Constants.SecondRowTopMargin.NONE.value -> getString(R.string.settings_clock_bottom_margin_subtitle_none)
Constants.SecondRowTopMargin.SMALL.value -> getString(R.string.settings_clock_bottom_margin_subtitle_small) Constants.SecondRowTopMargin.SMALL.value -> getString(R.string.settings_clock_bottom_margin_subtitle_small)
Constants.SecondRowTopMargin.LARGE.value -> getString(R.string.settings_clock_bottom_margin_subtitle_large) Constants.SecondRowTopMargin.LARGE.value -> getString(R.string.settings_clock_bottom_margin_subtitle_large)
else -> getString(R.string.settings_clock_bottom_margin_subtitle_medium) else -> getString(R.string.settings_clock_bottom_margin_subtitle_medium)
} }
} }
}) }
viewModel.backgroundCardColor.observe(viewLifecycleOwner, Observer { viewModel.backgroundCardColor.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (Preferences.backgroundCardAlpha == "00") { if (Preferences.backgroundCardAlpha == "00") {
background_color_label?.text = getString(R.string.transparent) binding.backgroundColorLabel.text = getString(R.string.transparent)
} else { } else {
background_color_label?.text = binding.backgroundColorLabel.text =
"#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
}) }
viewModel.backgroundCardColorDark.observe(viewLifecycleOwner, Observer { viewModel.backgroundCardColorDark.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (Preferences.backgroundCardAlphaDark == "00") { if (Preferences.backgroundCardAlphaDark == "00") {
background_color_label?.text = getString(R.string.transparent) binding.backgroundColorLabel.text = getString(R.string.transparent)
} else { } else {
background_color_label?.text = binding.backgroundColorLabel.text =
"#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
}) }
viewModel.backgroundCardAlpha.observe(viewLifecycleOwner, Observer { viewModel.backgroundCardAlpha.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (Preferences.backgroundCardAlpha == "00") { if (Preferences.backgroundCardAlpha == "00") {
background_color_label?.text = getString(R.string.transparent) binding.backgroundColorLabel.text = getString(R.string.transparent)
} else { } else {
background_color_label?.text = binding.backgroundColorLabel.text =
"#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
}) }
viewModel.backgroundCardAlphaDark.observe(viewLifecycleOwner, Observer { viewModel.backgroundCardAlphaDark.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (Preferences.backgroundCardAlphaDark == "00") { if (Preferences.backgroundCardAlphaDark == "00") {
background_color_label?.text = getString(R.string.transparent) binding.backgroundColorLabel.text = getString(R.string.transparent)
} else { } else {
background_color_label?.text = binding.backgroundColorLabel.text =
"#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
})
viewModel.dateFormat.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
date_format_label?.text = DateHelper.getDateText(requireContext(), Calendar.getInstance())
} }
})
viewModel.showDividers.observe(viewLifecycleOwner, Observer { viewModel.dateFormat.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
show_dividers_label?.text = binding.dateFormatLabel.text = DateHelper.getDateText(requireContext(), Calendar.getInstance())
}
}
viewModel.showDividers.observe(viewLifecycleOwner) {
maintainScrollPosition {
binding.showDividersLabel.text =
if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible) if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
} }
}) }
} }
private fun setupListener() { private fun setupListener() {
action_second_row_top_margin_size.setOnClickListener { binding.actionSecondRowTopMarginSize.setOnClickListener {
BottomSheetMenu<Int>( BottomSheetMenu<Int>(
requireContext(), requireContext(),
header = getString(R.string.settings_secondary_row_top_margin_title) header = getString(R.string.settings_secondary_row_top_margin_title)
@ -191,7 +188,7 @@ class LayoutFragment : Fragment() {
}.show() }.show()
} }
action_date_format.setOnClickListener { binding.actionDateFormat.setOnClickListener {
val now = Calendar.getInstance() val now = Calendar.getInstance()
val dialog = BottomSheetMenu<String>(requireContext(), header = getString(R.string.settings_date_format_title)).setSelectedValue(Preferences.dateFormat) val dialog = BottomSheetMenu<String>(requireContext(), header = getString(R.string.settings_date_format_title)).setSelectedValue(Preferences.dateFormat)
@ -220,7 +217,7 @@ class LayoutFragment : Fragment() {
}.show() }.show()
} }
action_background_color.setOnClickListener { binding.actionBackgroundColor.setOnClickListener {
BottomSheetColorPicker(requireContext(), BottomSheetColorPicker(requireContext(),
colors = colors, colors = colors,
header = getString(R.string.settings_background_color_title), header = getString(R.string.settings_background_color_title),
@ -247,21 +244,21 @@ class LayoutFragment : Fragment() {
).show() ).show()
} }
action_show_dividers.setOnClickListener { binding.actionShowDividers.setOnClickListener {
show_dividers_toggle.isChecked = !show_dividers_toggle.isChecked binding.showDividersToggle.isChecked = !binding.showDividersToggle.isChecked
} }
show_dividers_toggle.setOnCheckedChangeListener { _, isChecked -> binding.showDividersToggle.setOnCheckedChangeListener { _, isChecked ->
Preferences.showDividers = isChecked Preferences.showDividers = isChecked
} }
} }
private fun maintainScrollPosition(callback: () -> Unit) { private fun maintainScrollPosition(callback: () -> Unit) {
scrollView.isScrollable = false binding.scrollView.isScrollable = false
callback.invoke() callback.invoke()
lifecycleScope.launch { lifecycleScope.launch {
delay(200) delay(200)
scrollView.isScrollable = true binding.scrollView.isScrollable = true
} }
} }
} }

View File

@ -19,15 +19,13 @@ import com.karumi.dexter.listener.PermissionRequest
import com.karumi.dexter.listener.multi.MultiplePermissionsListener import com.karumi.dexter.listener.multi.MultiplePermissionsListener
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.components.MaterialBottomSheetDialog import com.tommasoberlose.anotherwidget.components.MaterialBottomSheetDialog
import com.tommasoberlose.anotherwidget.databinding.FragmentTabSelectorBinding import com.tommasoberlose.anotherwidget.databinding.FragmentPreferencesBinding
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
import com.tommasoberlose.anotherwidget.receivers.WeatherReceiver import com.tommasoberlose.anotherwidget.receivers.WeatherReceiver
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
import com.tommasoberlose.anotherwidget.utils.* import com.tommasoberlose.anotherwidget.utils.*
import kotlinx.android.synthetic.main.fragment_tab_selector.*
import kotlinx.android.synthetic.main.fragment_tab_selector.scrollView
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -38,6 +36,7 @@ class PreferencesFragment : Fragment() {
} }
private lateinit var viewModel: MainViewModel private lateinit var viewModel: MainViewModel
private lateinit var binding: FragmentPreferencesBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -52,9 +51,9 @@ class PreferencesFragment : Fragment() {
): View { ): View {
viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java) viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java)
val binding = DataBindingUtil.inflate<FragmentTabSelectorBinding>(inflater, R.layout.fragment_preferences, container, false) binding = FragmentPreferencesBinding.inflate(inflater)
subscribeUi(binding, viewModel) subscribeUi(viewModel)
binding.lifecycleOwner = this binding.lifecycleOwner = this
binding.viewModel = viewModel binding.viewModel = viewModel
@ -67,13 +66,12 @@ class PreferencesFragment : Fragment() {
setupListener() setupListener()
scrollView?.viewTreeObserver?.addOnScrollChangedListener { binding.scrollView.viewTreeObserver.addOnScrollChangedListener {
viewModel.fragmentScrollY.value = scrollView?.scrollY ?: 0 viewModel.fragmentScrollY.value = binding.scrollView.scrollY
} }
} }
private fun subscribeUi( private fun subscribeUi(
binding: FragmentTabSelectorBinding,
viewModel: MainViewModel viewModel: MainViewModel
) { ) {
binding.isCalendarEnabled = Preferences.showEvents binding.isCalendarEnabled = Preferences.showEvents
@ -81,7 +79,7 @@ class PreferencesFragment : Fragment() {
binding.isClockVisible = Preferences.showClock binding.isClockVisible = Preferences.showClock
binding.isGlanceVisible = Preferences.showGlance binding.isGlanceVisible = Preferences.showGlance
viewModel.showEvents.observe(viewLifecycleOwner, Observer { viewModel.showEvents.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
binding.isCalendarEnabled = it binding.isCalendarEnabled = it
@ -92,70 +90,70 @@ class PreferencesFragment : Fragment() {
} }
} }
checkReadEventsPermission() checkReadEventsPermission()
}) }
viewModel.showWeather.observe(viewLifecycleOwner, Observer { viewModel.showWeather.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
binding.isWeatherVisible = it binding.isWeatherVisible = it
} }
checkLocationPermission() checkLocationPermission()
}) }
viewModel.showClock.observe(viewLifecycleOwner, Observer { viewModel.showClock.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
binding.isClockVisible = it binding.isClockVisible = it
} }
}) }
viewModel.showGlance.observe(viewLifecycleOwner, Observer { viewModel.showGlance.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
binding.isGlanceVisible = it binding.isGlanceVisible = it
} }
}) }
} }
private fun setupListener() { private fun setupListener() {
action_typography.setOnClickListener { binding.actionTypography.setOnClickListener {
Navigation.findNavController(it).navigate(R.id.action_tabSelectorFragment_to_typographyTabFragment) Navigation.findNavController(it).navigate(R.id.action_tabSelectorFragment_to_typographyTabFragment)
} }
action_general_settings.setOnClickListener { binding.actionGeneralSettings.setOnClickListener {
Navigation.findNavController(it).navigate(R.id.action_tabSelectorFragment_to_generalTabFragment) Navigation.findNavController(it).navigate(R.id.action_tabSelectorFragment_to_generalTabFragment)
} }
action_show_events.setOnClickListener { binding.actionShowEvents.setOnClickListener {
Navigation.findNavController(it).navigate(R.id.action_tabSelectorFragment_to_calendarTabFragment) Navigation.findNavController(it).navigate(R.id.action_tabSelectorFragment_to_calendarTabFragment)
} }
show_events_switch.setOnCheckedChangeListener { _, enabled: Boolean -> binding.showEventsSwitch.setOnCheckedChangeListener { _, enabled: Boolean ->
Preferences.showEvents = enabled Preferences.showEvents = enabled
if (Preferences.showEvents) { if (Preferences.showEvents) {
requirePermission() requirePermission()
} }
} }
action_show_weather.setOnClickListener { binding.actionShowWeather.setOnClickListener {
Navigation.findNavController(it).navigate(R.id.action_tabSelectorFragment_to_weatherTabFragment) Navigation.findNavController(it).navigate(R.id.action_tabSelectorFragment_to_weatherTabFragment)
} }
show_weather_switch.setOnCheckedChangeListener { _, enabled: Boolean -> binding.showWeatherSwitch.setOnCheckedChangeListener { _, enabled: Boolean ->
Preferences.showWeather = enabled Preferences.showWeather = enabled
} }
action_show_clock.setOnClickListener { binding.actionShowClock.setOnClickListener {
Navigation.findNavController(it).navigate(R.id.action_tabSelectorFragment_to_clockTabFragment) Navigation.findNavController(it).navigate(R.id.action_tabSelectorFragment_to_clockTabFragment)
} }
show_clock_switch.setOnCheckedChangeListener { _, enabled: Boolean -> binding.showClockSwitch.setOnCheckedChangeListener { _, enabled: Boolean ->
Preferences.showClock = enabled Preferences.showClock = enabled
} }
action_show_glance.setOnClickListener { binding.actionShowGlance.setOnClickListener {
Navigation.findNavController(it).navigate(R.id.action_tabSelectorFragment_to_glanceTabFragment) Navigation.findNavController(it).navigate(R.id.action_tabSelectorFragment_to_glanceTabFragment)
} }
show_glance_switch.setOnCheckedChangeListener { _, enabled: Boolean -> binding.showGlanceSwitch.setOnCheckedChangeListener { _, enabled: Boolean ->
Preferences.showGlance = enabled Preferences.showGlance = enabled
} }
} }
@ -211,11 +209,11 @@ class PreferencesFragment : Fragment() {
} }
private fun maintainScrollPosition(callback: () -> Unit) { private fun maintainScrollPosition(callback: () -> Unit) {
scrollView.isScrollable = false binding.scrollView.isScrollable = false
callback.invoke() callback.invoke()
lifecycleScope.launch { lifecycleScope.launch {
delay(200) delay(200)
scrollView.isScrollable = true binding.scrollView.isScrollable = true
} }
} }
} }

View File

@ -15,7 +15,7 @@ import com.google.android.material.transition.MaterialSharedAxis
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.components.BottomSheetColorPicker import com.tommasoberlose.anotherwidget.components.BottomSheetColorPicker
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
import com.tommasoberlose.anotherwidget.databinding.FragmentTypographyTabBinding import com.tommasoberlose.anotherwidget.databinding.FragmentTabTypographyBinding
import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.global.RequestCode import com.tommasoberlose.anotherwidget.global.RequestCode
@ -28,8 +28,6 @@ import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
import com.tommasoberlose.anotherwidget.utils.isDarkTheme import com.tommasoberlose.anotherwidget.utils.isDarkTheme
import kotlinx.android.synthetic.main.fragment_typography_tab.*
import kotlinx.android.synthetic.main.fragment_typography_tab.scrollView
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -44,6 +42,8 @@ class TypographyFragment : Fragment() {
private lateinit var viewModel: MainViewModel private lateinit var viewModel: MainViewModel
private lateinit var colors: IntArray private lateinit var colors: IntArray
private lateinit var binding: FragmentTabTypographyBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
enterTransition = MaterialSharedAxis(MaterialSharedAxis.X, true) enterTransition = MaterialSharedAxis(MaterialSharedAxis.X, true)
@ -56,7 +56,7 @@ class TypographyFragment : Fragment() {
): View { ): View {
viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java) viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java)
val binding = DataBindingUtil.inflate<FragmentTypographyTabBinding>(inflater, R.layout.fragment_tab_typography, container, false) binding = FragmentTabTypographyBinding.inflate(inflater)
subscribeUi(viewModel) subscribeUi(viewModel)
@ -78,8 +78,8 @@ class TypographyFragment : Fragment() {
} }
} }
scrollView?.viewTreeObserver?.addOnScrollChangedListener { binding.scrollView.viewTreeObserver.addOnScrollChangedListener {
viewModel.fragmentScrollY.value = scrollView?.scrollY ?: 0 viewModel.fragmentScrollY.value = binding.scrollView.scrollY
} }
} }
@ -91,22 +91,22 @@ class TypographyFragment : Fragment() {
viewModel.textMainSize.observe(viewLifecycleOwner) { viewModel.textMainSize.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
main_text_size_label?.text = String.format("%.0fsp", it) binding.mainTextSizeLabel.text = String.format("%.0fsp", it)
} }
} }
viewModel.textSecondSize.observe(viewLifecycleOwner) { viewModel.textSecondSize.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
second_text_size_label?.text = String.format("%.0fsp", it) binding.secondTextSizeLabel.text = String.format("%.0fsp", it)
} }
} }
viewModel.textGlobalColor.observe(viewLifecycleOwner) { viewModel.textGlobalColor.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (Preferences.textGlobalAlpha == "00") { if (Preferences.textGlobalAlpha == "00") {
font_color_label?.text = getString(R.string.transparent) binding.fontColorLabel.text = getString(R.string.transparent)
} else { } else {
font_color_label?.text = binding.fontColorLabel.text =
"#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
@ -115,9 +115,9 @@ class TypographyFragment : Fragment() {
viewModel.textGlobalColorDark.observe(viewLifecycleOwner) { viewModel.textGlobalColorDark.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (Preferences.textGlobalAlphaDark == "00") { if (Preferences.textGlobalAlphaDark == "00") {
font_color_label_dark?.text = getString(R.string.transparent) binding.fontColorLabelDark.text = getString(R.string.transparent)
} else { } else {
font_color_label_dark?.text = binding.fontColorLabelDark.text =
"#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
@ -126,9 +126,9 @@ class TypographyFragment : Fragment() {
viewModel.textGlobalAlpha.observe(viewLifecycleOwner) { viewModel.textGlobalAlpha.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (Preferences.textGlobalAlpha == "00") { if (Preferences.textGlobalAlpha == "00") {
font_color_label?.text = getString(R.string.transparent) binding.fontColorLabel.text = getString(R.string.transparent)
} else { } else {
font_color_label?.text = binding.fontColorLabel.text =
"#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
@ -137,9 +137,9 @@ class TypographyFragment : Fragment() {
viewModel.textGlobalAlphaDark.observe(viewLifecycleOwner) { viewModel.textGlobalAlphaDark.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (Preferences.textGlobalAlphaDark == "00") { if (Preferences.textGlobalAlphaDark == "00") {
font_color_label_dark?.text = getString(R.string.transparent) binding.fontColorLabelDark.text = getString(R.string.transparent)
} else { } else {
font_color_label_dark?.text = binding.fontColorLabelDark.text =
"#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
@ -148,9 +148,9 @@ class TypographyFragment : Fragment() {
viewModel.textSecondaryColor.observe(viewLifecycleOwner) { viewModel.textSecondaryColor.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (Preferences.textSecondaryAlpha == "00") { if (Preferences.textSecondaryAlpha == "00") {
secondary_font_color_label?.text = getString(R.string.transparent) binding.secondaryFontColorLabel.text = getString(R.string.transparent)
} else { } else {
secondary_font_color_label?.text = binding.secondaryFontColorLabel.text =
"#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
@ -159,9 +159,9 @@ class TypographyFragment : Fragment() {
viewModel.textSecondaryColorDark.observe(viewLifecycleOwner) { viewModel.textSecondaryColorDark.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (Preferences.textSecondaryAlphaDark == "00") { if (Preferences.textSecondaryAlphaDark == "00") {
secondary_font_color_label_dark?.text = getString(R.string.transparent) binding.secondaryFontColorLabelDark.text = getString(R.string.transparent)
} else { } else {
secondary_font_color_label_dark?.text = binding.secondaryFontColorLabelDark.text =
"#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
@ -170,9 +170,9 @@ class TypographyFragment : Fragment() {
viewModel.textSecondaryAlpha.observe(viewLifecycleOwner) { viewModel.textSecondaryAlpha.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (Preferences.textSecondaryAlpha == "00") { if (Preferences.textSecondaryAlpha == "00") {
secondary_font_color_label?.text = getString(R.string.transparent) binding.secondaryFontColorLabel.text = getString(R.string.transparent)
} else { } else {
secondary_font_color_label?.text = binding.secondaryFontColorLabel.text =
"#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
@ -181,9 +181,9 @@ class TypographyFragment : Fragment() {
viewModel.textSecondaryAlphaDark.observe(viewLifecycleOwner) { viewModel.textSecondaryAlphaDark.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (Preferences.textSecondaryAlphaDark == "00") { if (Preferences.textSecondaryAlphaDark == "00") {
secondary_font_color_label_dark?.text = getString(R.string.transparent) binding.secondaryFontColorLabelDark.text = getString(R.string.transparent)
} else { } else {
secondary_font_color_label_dark?.text = binding.secondaryFontColorLabelDark.text =
"#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase() "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase()
} }
} }
@ -192,7 +192,7 @@ class TypographyFragment : Fragment() {
viewModel.textShadow.observe(viewLifecycleOwner) { viewModel.textShadow.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (activity?.isDarkTheme() != true) { if (activity?.isDarkTheme() != true) {
text_shadow_label?.text = binding.textShadowLabel.text =
getString(SettingsStringHelper.getTextShadowString(it)) getString(SettingsStringHelper.getTextShadowString(it))
} }
} }
@ -201,7 +201,7 @@ class TypographyFragment : Fragment() {
viewModel.textShadowDark.observe(viewLifecycleOwner) { viewModel.textShadowDark.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
if (activity?.isDarkTheme() == true) { if (activity?.isDarkTheme() == true) {
text_shadow_label_dark?.text = binding.textShadowLabelDark.text =
getString(SettingsStringHelper.getTextShadowString(it)) getString(SettingsStringHelper.getTextShadowString(it))
} }
} }
@ -209,35 +209,35 @@ class TypographyFragment : Fragment() {
viewModel.customFont.observe(viewLifecycleOwner) { viewModel.customFont.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
custom_font_label?.text = SettingsStringHelper.getCustomFontLabel(requireContext(), it) binding.customFontLabel.text = SettingsStringHelper.getCustomFontLabel(requireContext(), it)
MainWidget.updateWidget(requireContext()) MainWidget.updateWidget(requireContext())
} }
} }
viewModel.customFontFile.observe(viewLifecycleOwner) { viewModel.customFontFile.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
custom_font_label?.text = SettingsStringHelper.getCustomFontLabel(requireContext(), Preferences.customFont) binding.customFontLabel.text = SettingsStringHelper.getCustomFontLabel(requireContext(), Preferences.customFont)
MainWidget.updateWidget(requireContext()) MainWidget.updateWidget(requireContext())
} }
} }
viewModel.customFontName.observe(viewLifecycleOwner) { viewModel.customFontName.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
custom_font_label?.text = SettingsStringHelper.getCustomFontLabel(requireContext(), Preferences.customFont) binding.customFontLabel.text = SettingsStringHelper.getCustomFontLabel(requireContext(), Preferences.customFont)
MainWidget.updateWidget(requireContext()) MainWidget.updateWidget(requireContext())
} }
} }
viewModel.customFontVariant.observe(viewLifecycleOwner) { viewModel.customFontVariant.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
custom_font_label?.text = SettingsStringHelper.getCustomFontLabel(requireContext(), Preferences.customFont) binding.customFontLabel.text = SettingsStringHelper.getCustomFontLabel(requireContext(), Preferences.customFont)
MainWidget.updateWidget(requireContext()) MainWidget.updateWidget(requireContext())
} }
} }
} }
private fun setupListener() { private fun setupListener() {
action_main_text_size.setOnClickListener { binding.actionMainTextSize.setOnClickListener {
val dialog = BottomSheetMenu<Float>(requireContext(), header = getString(R.string.title_main_text_size)).setSelectedValue( val dialog = BottomSheetMenu<Float>(requireContext(), header = getString(R.string.title_main_text_size)).setSelectedValue(
Preferences.textMainSize) Preferences.textMainSize)
(40 downTo 10).filter { it % 2 == 0 }.forEach { (40 downTo 10).filter { it % 2 == 0 }.forEach {
@ -248,7 +248,7 @@ class TypographyFragment : Fragment() {
}.show() }.show()
} }
action_second_text_size.setOnClickListener { binding.actionSecondTextSize.setOnClickListener {
val dialog = BottomSheetMenu<Float>(requireContext(), header = getString(R.string.title_second_text_size)).setSelectedValue( val dialog = BottomSheetMenu<Float>(requireContext(), header = getString(R.string.title_second_text_size)).setSelectedValue(
Preferences.textSecondSize) Preferences.textSecondSize)
(40 downTo 10).filter { it % 2 == 0 }.forEach { (40 downTo 10).filter { it % 2 == 0 }.forEach {
@ -259,7 +259,7 @@ class TypographyFragment : Fragment() {
}.show() }.show()
} }
action_font_color.setOnClickListener { binding.actionFontColor.setOnClickListener {
BottomSheetColorPicker(requireContext(), BottomSheetColorPicker(requireContext(),
colors = colors, colors = colors,
header = getString(R.string.settings_font_color_title), header = getString(R.string.settings_font_color_title),
@ -284,7 +284,7 @@ class TypographyFragment : Fragment() {
).show() ).show()
} }
action_secondary_font_color.setOnClickListener { binding.actionSecondaryFontColor.setOnClickListener {
BottomSheetColorPicker(requireContext(), BottomSheetColorPicker(requireContext(),
colors = colors, colors = colors,
header = getString(R.string.settings_secondary_font_color_title), header = getString(R.string.settings_secondary_font_color_title),
@ -311,7 +311,7 @@ class TypographyFragment : Fragment() {
).show() ).show()
} }
action_text_shadow.setOnClickListener { binding.actionTextShadow.setOnClickListener {
val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.title_text_shadow)).setSelectedValue(if (activity?.isDarkTheme() == true) Preferences.textShadowDark else Preferences.textShadow) val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.title_text_shadow)).setSelectedValue(if (activity?.isDarkTheme() == true) Preferences.textShadowDark else Preferences.textShadow)
(2 downTo 0).forEach { (2 downTo 0).forEach {
dialog.addItem(getString(SettingsStringHelper.getTextShadowString(it)), it) dialog.addItem(getString(SettingsStringHelper.getTextShadowString(it)), it)
@ -325,7 +325,7 @@ class TypographyFragment : Fragment() {
}.show() }.show()
} }
action_custom_font.setOnClickListener { binding.actionCustomFont.setOnClickListener {
val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_custom_font_title)).setSelectedValue( val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_custom_font_title)).setSelectedValue(
Preferences.customFont) Preferences.customFont)
dialog.addItem(SettingsStringHelper.getCustomFontLabel(requireContext(), 0), 0) dialog.addItem(SettingsStringHelper.getCustomFontLabel(requireContext(), 0), 0)
@ -357,11 +357,11 @@ class TypographyFragment : Fragment() {
} }
private fun maintainScrollPosition(callback: () -> Unit) { private fun maintainScrollPosition(callback: () -> Unit) {
scrollView.isScrollable = false binding.scrollView.isScrollable = false
callback.invoke() callback.invoke()
lifecycleScope.launch { lifecycleScope.launch {
delay(200) delay(200)
scrollView.isScrollable = true binding.scrollView.isScrollable = true
} }
} }
} }

View File

@ -24,7 +24,7 @@ import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
import com.tommasoberlose.anotherwidget.components.IconPackSelector import com.tommasoberlose.anotherwidget.components.IconPackSelector
import com.tommasoberlose.anotherwidget.components.MaterialBottomSheetDialog import com.tommasoberlose.anotherwidget.components.MaterialBottomSheetDialog
import com.tommasoberlose.anotherwidget.databinding.FragmentWeatherSettingsBinding import com.tommasoberlose.anotherwidget.databinding.FragmentTabWeatherBinding
import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.global.RequestCode import com.tommasoberlose.anotherwidget.global.RequestCode
@ -40,8 +40,6 @@ import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
import com.tommasoberlose.anotherwidget.utils.collapse import com.tommasoberlose.anotherwidget.utils.collapse
import com.tommasoberlose.anotherwidget.utils.expand import com.tommasoberlose.anotherwidget.utils.expand
import kotlinx.android.synthetic.main.fragment_weather_settings.*
import kotlinx.android.synthetic.main.fragment_weather_settings.scrollView
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -52,6 +50,7 @@ class WeatherFragment : Fragment() {
} }
private lateinit var viewModel: MainViewModel private lateinit var viewModel: MainViewModel
private lateinit var binding: FragmentTabWeatherBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -65,9 +64,9 @@ class WeatherFragment : Fragment() {
): View { ): View {
viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java) viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java)
val binding = DataBindingUtil.inflate<FragmentWeatherSettingsBinding>(inflater, R.layout.fragment_tab_weather, container, false) binding = FragmentTabWeatherBinding.inflate(inflater)
subscribeUi(binding, viewModel) subscribeUi(viewModel)
binding.lifecycleOwner = this binding.lifecycleOwner = this
binding.viewModel = viewModel binding.viewModel = viewModel
@ -79,83 +78,76 @@ class WeatherFragment : Fragment() {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
setupListener() setupListener()
scrollView?.viewTreeObserver?.addOnScrollChangedListener { binding.scrollView.viewTreeObserver.addOnScrollChangedListener {
viewModel.fragmentScrollY.value = scrollView?.scrollY ?: 0 viewModel.fragmentScrollY.value = binding.scrollView.scrollY
} }
} }
private fun subscribeUi( private fun subscribeUi(
binding: FragmentWeatherSettingsBinding,
viewModel: MainViewModel viewModel: MainViewModel
) { ) {
binding.isWeatherVisible = Preferences.showWeather binding.isWeatherVisible = Preferences.showWeather
viewModel.weatherProvider.observe(viewLifecycleOwner, Observer { viewModel.weatherProvider.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
label_weather_provider.text = WeatherHelper.getProviderName(requireContext(), Constants.WeatherProvider.fromInt(it)!!) binding.labelWeatherProvider.text = WeatherHelper.getProviderName(requireContext(), Constants.WeatherProvider.fromInt(it)!!)
checkWeatherProviderConfig() checkWeatherProviderConfig()
} }
}) }
viewModel.weatherProviderError.observe(viewLifecycleOwner, Observer { viewModel.weatherProviderError.observe(viewLifecycleOwner) {
checkWeatherProviderConfig() checkWeatherProviderConfig()
}) }
viewModel.weatherProviderLocationError.observe(viewLifecycleOwner, Observer { viewModel.weatherProviderLocationError.observe(viewLifecycleOwner) {
checkWeatherProviderConfig() checkWeatherProviderConfig()
}) }
viewModel.customLocationAdd.observe(viewLifecycleOwner, Observer { viewModel.customLocationAdd.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
label_custom_location?.text = binding.labelCustomLocation.text =
if (it == "") getString(R.string.custom_location_gps) else it if (it == "") getString(R.string.custom_location_gps) else it
} }
checkLocationPermission() checkLocationPermission()
}) }
viewModel.weatherTempUnit.observe(viewLifecycleOwner, Observer { viewModel.weatherTempUnit.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
temp_unit?.text = binding.tempUnit.text =
if (it == "F") getString(R.string.fahrenheit) else getString(R.string.celsius) if (it == "F") getString(R.string.fahrenheit) else getString(R.string.celsius)
} }
checkLocationPermission() checkLocationPermission()
}) }
viewModel.weatherRefreshPeriod.observe(viewLifecycleOwner, Observer { viewModel.weatherRefreshPeriod.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
label_weather_refresh_period?.text = getString(SettingsStringHelper.getRefreshPeriodString(it)) binding.labelWeatherRefreshPeriod.text = getString(SettingsStringHelper.getRefreshPeriodString(it))
} }
checkLocationPermission() checkLocationPermission()
}) }
viewModel.weatherIconPack.observe(viewLifecycleOwner, Observer { viewModel.weatherIconPack.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
label_weather_icon_pack?.text = getString(R.string.settings_weather_icon_pack_default).format((it + 1)) binding.labelWeatherIconPack.text = getString(R.string.settings_weather_icon_pack_default).format((it + 1))
// weather_icon_pack.setImageDrawable(ContextCompat.getDrawable(requireContext(), WeatherHelper.getWeatherIconResource("02d")))
// if (it == Constants.WeatherIconPack.MINIMAL.value) {
// weather_icon_pack.setColorFilter(ContextCompat.getColor(requireContext(), R.color.colorPrimaryText))
// } else {
// weather_icon_pack.setColorFilter(ContextCompat.getColor(requireContext(), android.R.color.transparent))
// }
} }
checkLocationPermission() checkLocationPermission()
}) }
viewModel.weatherAppName.observe(viewLifecycleOwner, Observer { viewModel.weatherAppName.observe(viewLifecycleOwner) {
maintainScrollPosition { maintainScrollPosition {
weather_app_label?.text = binding.weatherAppLabel.text =
if (it != "") it else getString(R.string.default_weather_app) if (it != "") it else getString(R.string.default_weather_app)
} }
}) }
} }
private fun checkLocationPermission() { private fun checkLocationPermission() {
if (requireActivity().checkGrantedPermission(Manifest.permission.ACCESS_FINE_LOCATION)) { if (requireActivity().checkGrantedPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
location_permission_alert?.isVisible = false binding.locationPermissionAlert.isVisible = false
WeatherReceiver.setUpdates(requireContext()) WeatherReceiver.setUpdates(requireContext())
} else if (Preferences.showWeather && Preferences.customLocationAdd == "") { } else if (Preferences.showWeather && Preferences.customLocationAdd == "") {
location_permission_alert?.isVisible = true binding.locationPermissionAlert.isVisible = true
location_permission_alert?.setOnClickListener { binding.locationPermissionAlert.setOnClickListener {
MaterialBottomSheetDialog(requireContext(), message = getString(R.string.background_location_warning)) MaterialBottomSheetDialog(requireContext(), message = getString(R.string.background_location_warning))
.setPositiveButton(getString(android.R.string.ok)) { .setPositiveButton(getString(android.R.string.ok)) {
requirePermission() requirePermission()
@ -163,43 +155,43 @@ class WeatherFragment : Fragment() {
.show() .show()
} }
} else { } else {
location_permission_alert?.isVisible = false binding.locationPermissionAlert.isVisible = false
} }
} }
private fun checkWeatherProviderConfig() { private fun checkWeatherProviderConfig() {
if (Preferences.showWeather && Preferences.weatherProviderError != "" && Preferences.weatherProviderError != "-" && !location_permission_alert.isVisible) { if (Preferences.showWeather && Preferences.weatherProviderError != "" && Preferences.weatherProviderError != "-" && !binding.locationPermissionAlert.isVisible) {
weather_provider_error.expand() binding.weatherProviderError.expand()
} else { } else {
weather_provider_error.collapse() binding.weatherProviderError.collapse()
} }
weather_provider_error?.text = Preferences.weatherProviderError binding.weatherProviderError.text = Preferences.weatherProviderError
if (Preferences.showWeather && Preferences.weatherProviderLocationError != "" && !location_permission_alert.isVisible) { if (Preferences.showWeather && Preferences.weatherProviderLocationError != "" && !binding.locationPermissionAlert.isVisible) {
weather_provider_location_error.expand() binding.weatherProviderLocationError.expand()
} else { } else {
weather_provider_location_error.collapse() binding.weatherProviderLocationError.collapse()
} }
weather_provider_location_error?.text = Preferences.weatherProviderLocationError binding.weatherProviderLocationError.text = Preferences.weatherProviderLocationError
} }
private fun setupListener() { private fun setupListener() {
action_weather_provider.setOnClickListener { binding.actionWeatherProvider.setOnClickListener {
startActivityForResult( startActivityForResult(
Intent(requireContext(), WeatherProviderActivity::class.java), Intent(requireContext(), WeatherProviderActivity::class.java),
RequestCode.WEATHER_PROVIDER_REQUEST_CODE.code RequestCode.WEATHER_PROVIDER_REQUEST_CODE.code
) )
} }
action_custom_location.setOnClickListener { binding.actionCustomLocation.setOnClickListener {
startActivityForResult( startActivityForResult(
Intent(requireContext(), CustomLocationActivity::class.java), Intent(requireContext(), CustomLocationActivity::class.java),
Constants.RESULT_CODE_CUSTOM_LOCATION Constants.RESULT_CODE_CUSTOM_LOCATION
) )
} }
action_change_unit.setOnClickListener { binding.actionChangeUnit.setOnClickListener {
BottomSheetMenu<String>(requireContext(), header = getString(R.string.settings_unit_title)).setSelectedValue(Preferences.weatherTempUnit) BottomSheetMenu<String>(requireContext(), header = getString(R.string.settings_unit_title)).setSelectedValue(Preferences.weatherTempUnit)
.addItem(getString(R.string.fahrenheit), "F") .addItem(getString(R.string.fahrenheit), "F")
.addItem(getString(R.string.celsius), "C") .addItem(getString(R.string.celsius), "C")
@ -213,7 +205,7 @@ class WeatherFragment : Fragment() {
}.show() }.show()
} }
action_weather_refresh_period.setOnClickListener { binding.actionWeatherRefreshPeriod.setOnClickListener {
val dialog = val dialog =
BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_weather_refresh_period_title)).setSelectedValue(Preferences.weatherRefreshPeriod) BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_weather_refresh_period_title)).setSelectedValue(Preferences.weatherRefreshPeriod)
(5 downTo 0).forEach { (5 downTo 0).forEach {
@ -225,11 +217,11 @@ class WeatherFragment : Fragment() {
}.show() }.show()
} }
action_weather_icon_pack.setOnClickListener { binding.actionWeatherIconPack.setOnClickListener {
IconPackSelector(requireContext(), header = getString(R.string.settings_weather_icon_pack_title)).show() IconPackSelector(requireContext(), header = getString(R.string.settings_weather_icon_pack_title)).show()
} }
action_weather_app.setOnClickListener { binding.actionWeatherApp.setOnClickListener {
startActivityForResult( startActivityForResult(
Intent(requireContext(), ChooseApplicationActivity::class.java), Intent(requireContext(), ChooseApplicationActivity::class.java),
RequestCode.WEATHER_APP_REQUEST_CODE.code RequestCode.WEATHER_APP_REQUEST_CODE.code
@ -284,11 +276,11 @@ class WeatherFragment : Fragment() {
} }
private fun maintainScrollPosition(callback: () -> Unit) { private fun maintainScrollPosition(callback: () -> Unit) {
scrollView.isScrollable = false binding.scrollView.isScrollable = false
callback.invoke() callback.invoke()
lifecycleScope.launch { lifecycleScope.launch {
delay(200) delay(200)
scrollView.isScrollable = true binding.scrollView.isScrollable = true
} }
} }
} }

View File

@ -15,6 +15,7 @@ import android.os.Bundle
import android.text.format.DateUtils import android.text.format.DateUtils
import android.util.Log import android.util.Log
import android.util.TypedValue import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.widget.ImageView import android.widget.ImageView
import android.widget.RemoteViews import android.widget.RemoteViews
@ -23,6 +24,7 @@ import androidx.core.content.ContextCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.google.gson.Gson import com.google.gson.Gson
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.databinding.TheWidgetBinding
import com.tommasoberlose.anotherwidget.db.EventRepository import com.tommasoberlose.anotherwidget.db.EventRepository
import com.tommasoberlose.anotherwidget.global.Actions import com.tommasoberlose.anotherwidget.global.Actions
import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Constants
@ -34,7 +36,6 @@ import com.tommasoberlose.anotherwidget.receivers.*
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
import com.tommasoberlose.anotherwidget.utils.isDarkTheme import com.tommasoberlose.anotherwidget.utils.isDarkTheme
import com.tommasoberlose.anotherwidget.utils.toPixel import com.tommasoberlose.anotherwidget.utils.toPixel
import kotlinx.android.synthetic.main.the_widget.view.*
import java.text.DateFormat import java.text.DateFormat
import java.util.* import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@ -133,13 +134,13 @@ class MainWidget : AppWidgetProvider() {
// Setup listener // Setup listener
try { try {
val generatedView = generateWidgetView(context, typeface) val generatedBinding = generateWidgetView(context, typeface)
views.setImageViewBitmap( views.setImageViewBitmap(
R.id.bitmap_container, R.id.bitmap_container,
BitmapHelper.getBitmapFromView(generatedView, width = w) BitmapHelper.getBitmapFromView(generatedBinding.root, width = w)
) )
views = updateCalendarView(context, generatedView, views, appWidgetId) views = updateCalendarView(context, generatedBinding, views, appWidgetId)
views = updateWeatherView(context, generatedView, views, appWidgetId) views = updateWeatherView(context, generatedBinding, views, appWidgetId)
} catch (ex: Exception) { } catch (ex: Exception) {
ex.printStackTrace() ex.printStackTrace()
CrashlyticsReceiver.sendCrash(context, ex) CrashlyticsReceiver.sendCrash(context, ex)
@ -148,12 +149,12 @@ class MainWidget : AppWidgetProvider() {
appWidgetManager.updateAppWidget(appWidgetId, views) appWidgetManager.updateAppWidget(appWidgetId, views)
} }
private fun updateCalendarView(context: Context, v: View, views: RemoteViews, widgetID: Int): RemoteViews { private fun updateCalendarView(context: Context, bindingView: TheWidgetBinding, views: RemoteViews, widgetID: Int): RemoteViews {
val eventRepository = EventRepository(context) val eventRepository = EventRepository(context)
try { try {
views.setImageViewBitmap( views.setImageViewBitmap(
R.id.empty_date_rect, R.id.empty_date_rect,
BitmapHelper.getBitmapFromView(v.empty_date, draw = false) BitmapHelper.getBitmapFromView(bindingView.emptyDate, draw = false)
) )
views.setViewVisibility(R.id.empty_layout_rect, View.VISIBLE) views.setViewVisibility(R.id.empty_layout_rect, View.VISIBLE)
@ -176,7 +177,7 @@ class MainWidget : AppWidgetProvider() {
if (Preferences.showNextEvent && eventRepository.getEventsCount() > 1) { if (Preferences.showNextEvent && eventRepository.getEventsCount() > 1) {
views.setImageViewBitmap( views.setImageViewBitmap(
R.id.action_next_rect, R.id.action_next_rect,
BitmapHelper.getBitmapFromView(v.action_next, draw = false) BitmapHelper.getBitmapFromView(bindingView.actionNext, draw = false)
) )
views.setViewVisibility(R.id.action_next_rect, View.VISIBLE) views.setViewVisibility(R.id.action_next_rect, View.VISIBLE)
views.setOnClickPendingIntent( views.setOnClickPendingIntent(
@ -194,7 +195,7 @@ class MainWidget : AppWidgetProvider() {
views.setImageViewBitmap( views.setImageViewBitmap(
R.id.action_previous_rect, R.id.action_previous_rect,
BitmapHelper.getBitmapFromView(v.action_previous, draw = false) BitmapHelper.getBitmapFromView(bindingView.actionPrevious, draw = false)
) )
views.setViewVisibility(R.id.action_previous_rect, View.VISIBLE) views.setViewVisibility(R.id.action_previous_rect, View.VISIBLE)
views.setOnClickPendingIntent( views.setOnClickPendingIntent(
@ -227,7 +228,7 @@ class MainWidget : AppWidgetProvider() {
views.setImageViewBitmap( views.setImageViewBitmap(
R.id.next_event_difference_time_rect, R.id.next_event_difference_time_rect,
BitmapHelper.getBitmapFromView( BitmapHelper.getBitmapFromView(
v.next_event_difference_time, bindingView.nextEventDifferenceTime,
draw = false draw = false
) )
) )
@ -260,12 +261,12 @@ class MainWidget : AppWidgetProvider() {
views.setImageViewBitmap( views.setImageViewBitmap(
R.id.next_event_rect, R.id.next_event_rect,
BitmapHelper.getBitmapFromView(v.next_event, draw = false) BitmapHelper.getBitmapFromView(bindingView.nextEvent, draw = false)
) )
views.setImageViewBitmap( views.setImageViewBitmap(
R.id.second_row_rect, R.id.second_row_rect,
BitmapHelper.getBitmapFromView(v.second_row, draw = false) BitmapHelper.getBitmapFromView(bindingView.secondRow, draw = false)
) )
views.setViewVisibility(R.id.second_row_rect, View.VISIBLE) views.setViewVisibility(R.id.second_row_rect, View.VISIBLE)
@ -284,7 +285,7 @@ class MainWidget : AppWidgetProvider() {
R.id.second_row_top_margin_large_sans, R.id.second_row_top_margin_large_sans,
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.value) View.VISIBLE else View.GONE if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.value) View.VISIBLE else View.GONE
) )
} else if (GlanceProviderHelper.showGlanceProviders(context) && v.calendar_layout.isVisible) { } else if (GlanceProviderHelper.showGlanceProviders(context) && bindingView.calendarLayout.isVisible) {
var showSomething = false var showSomething = false
loop@ for (provider:Constants.GlanceProviderId in GlanceProviderHelper.getGlanceProviders(context)) { loop@ for (provider:Constants.GlanceProviderId in GlanceProviderHelper.getGlanceProviders(context)) {
when (provider) { when (provider) {
@ -405,12 +406,12 @@ class MainWidget : AppWidgetProvider() {
if (showSomething) { if (showSomething) {
views.setImageViewBitmap( views.setImageViewBitmap(
R.id.next_event_rect, R.id.next_event_rect,
BitmapHelper.getBitmapFromView(v.next_event, draw = false) BitmapHelper.getBitmapFromView(bindingView.nextEvent, draw = false)
) )
views.setImageViewBitmap( views.setImageViewBitmap(
R.id.second_row_rect, R.id.second_row_rect,
BitmapHelper.getBitmapFromView(v.second_row, draw = false) BitmapHelper.getBitmapFromView(bindingView.secondRow, draw = false)
) )
views.setViewVisibility(R.id.second_row_rect, View.VISIBLE) views.setViewVisibility(R.id.second_row_rect, View.VISIBLE)
@ -443,7 +444,7 @@ class MainWidget : AppWidgetProvider() {
return views return views
} }
private fun updateWeatherView(context: Context, v: View, views: RemoteViews, widgetID: Int): RemoteViews { private fun updateWeatherView(context: Context, bindingView: TheWidgetBinding, views: RemoteViews, widgetID: Int): RemoteViews {
try { try {
if (Preferences.showWeather && Preferences.weatherIcon != "") { if (Preferences.showWeather && Preferences.weatherIcon != "") {
views.setViewVisibility(R.id.weather_rect, View.VISIBLE) views.setViewVisibility(R.id.weather_rect, View.VISIBLE)
@ -460,17 +461,17 @@ class MainWidget : AppWidgetProvider() {
views.setImageViewBitmap( views.setImageViewBitmap(
R.id.weather_rect, R.id.weather_rect,
BitmapHelper.getBitmapFromView(v.weather, draw = false) BitmapHelper.getBitmapFromView(bindingView.weather, draw = false)
) )
views.setImageViewBitmap( views.setImageViewBitmap(
R.id.calendar_weather_rect, R.id.calendar_weather_rect,
BitmapHelper.getBitmapFromView(v.calendar_weather, draw = false) BitmapHelper.getBitmapFromView(bindingView.calendarWeather, draw = false)
) )
views.setImageViewBitmap( views.setImageViewBitmap(
R.id.special_weather_rect, R.id.special_weather_rect,
BitmapHelper.getBitmapFromView(v.calendar_weather, draw = false) BitmapHelper.getBitmapFromView(bindingView.calendarWeather, draw = false)
) )
if (GlanceProviderHelper.showGlanceProviders(context)) { if (GlanceProviderHelper.showGlanceProviders(context)) {
@ -550,39 +551,39 @@ class MainWidget : AppWidgetProvider() {
// Generates the widget bitmap from the view // Generates the widget bitmap from the view
fun generateWidgetView(context: Context, typeface: Typeface? = null): View { fun generateWidgetView(context: Context, typeface: Typeface? = null): TheWidgetBinding {
val eventRepository = EventRepository(context) val eventRepository = EventRepository(context)
val v = View.inflate(context, R.layout.the_widget, null) val bindingView = TheWidgetBinding.inflate(LayoutInflater.from(context))
v.loader.isVisible = false bindingView.loader.isVisible = false
val now = Calendar.getInstance().apply { val now = Calendar.getInstance().apply {
set(Calendar.SECOND, 0) set(Calendar.SECOND, 0)
set(Calendar.MILLISECOND, 0) set(Calendar.MILLISECOND, 0)
} }
v.empty_layout.visibility = View.VISIBLE bindingView.emptyLayout.visibility = View.VISIBLE
v.calendar_layout.visibility = View.GONE bindingView.calendarLayout.visibility = View.GONE
v.next_event_difference_time.visibility = View.GONE bindingView.nextEventDifferenceTime.visibility = View.GONE
v.action_next.isVisible = false bindingView.actionNext.isVisible = false
v.action_previous.isVisible = false bindingView.actionPrevious.isVisible = false
v.empty_date.text = DateHelper.getDateText(context, now) bindingView.emptyDate.text = DateHelper.getDateText(context, now)
val nextEvent = eventRepository.getNextEvent() val nextEvent = eventRepository.getNextEvent()
val nextAlarm = AlarmHelper.getNextAlarm(context) val nextAlarm = AlarmHelper.getNextAlarm(context)
if (Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null && !Preferences.showEventsAsGlanceProvider) { if (Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null && !Preferences.showEventsAsGlanceProvider) {
// Multiple counter // Multiple counter
v.action_next.isVisible = bindingView.actionNext.isVisible =
Preferences.showNextEvent && eventRepository.getEventsCount() > 1 Preferences.showNextEvent && eventRepository.getEventsCount() > 1
v.action_previous.isVisible = bindingView.actionPrevious.isVisible =
Preferences.showNextEvent && eventRepository.getEventsCount() > 1 Preferences.showNextEvent && eventRepository.getEventsCount() > 1
v.next_event.text = nextEvent.title bindingView.nextEvent.text = nextEvent.title
if (Preferences.showDiffTime && now.timeInMillis < nextEvent.startDate) { if (Preferences.showDiffTime && now.timeInMillis < nextEvent.startDate) {
v.next_event_difference_time.text = if (!nextEvent.allDay) { bindingView.nextEventDifferenceTime.text = if (!nextEvent.allDay) {
SettingsStringHelper.getDifferenceText( SettingsStringHelper.getDifferenceText(
context, context,
now.timeInMillis, now.timeInMillis,
@ -596,21 +597,21 @@ class MainWidget : AppWidgetProvider() {
nextEvent.startDate nextEvent.startDate
).toLowerCase(Locale.getDefault()) ).toLowerCase(Locale.getDefault())
} }
v.next_event_difference_time.visibility = View.VISIBLE bindingView.nextEventDifferenceTime.visibility = View.VISIBLE
} else { } else {
v.next_event_difference_time.visibility = View.GONE bindingView.nextEventDifferenceTime.visibility = View.GONE
} }
if (nextEvent.address != "" && Preferences.secondRowInformation == 1) { if (nextEvent.address != "" && Preferences.secondRowInformation == 1) {
v.second_row_icon.setImageDrawable( bindingView.secondRowIcon.setImageDrawable(
ContextCompat.getDrawable( ContextCompat.getDrawable(
context, context,
R.drawable.round_place_24 R.drawable.round_place_24
) )
) )
v.next_event_date.text = nextEvent.address bindingView.nextEventDate.text = nextEvent.address
} else { } else {
v.second_row_icon.setImageDrawable( bindingView.secondRowIcon.setImageDrawable(
ContextCompat.getDrawable( ContextCompat.getDrawable(
context, context,
R.drawable.round_today_24 R.drawable.round_today_24
@ -651,10 +652,10 @@ class MainWidget : AppWidgetProvider() {
} }
if (nextEvent.startDate != nextEvent.endDate) { if (nextEvent.startDate != nextEvent.endDate) {
v.next_event_date.text = bindingView.nextEventDate.text =
String.format("%s - %s%s", startHour, endHour, multipleDay) String.format("%s - %s%s", startHour, endHour, multipleDay)
} else { } else {
v.next_event_date.text = bindingView.nextEventDate.text =
String.format("%s", startHour) String.format("%s", startHour)
} }
@ -663,7 +664,7 @@ class MainWidget : AppWidgetProvider() {
DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_NO_YEAR or DateUtils.FORMAT_ABBREV_MONTH DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_NO_YEAR or DateUtils.FORMAT_ABBREV_MONTH
val start = Calendar.getInstance().apply { timeInMillis = nextEvent.startDate } val start = Calendar.getInstance().apply { timeInMillis = nextEvent.startDate }
v.next_event_date.text = if (now.get(Calendar.DAY_OF_YEAR) == start.get(Calendar.DAY_OF_YEAR)) { bindingView.nextEventDate.text = if (now.get(Calendar.DAY_OF_YEAR) == start.get(Calendar.DAY_OF_YEAR)) {
DateUtils.formatDateTime(context, nextEvent.startDate, flags) DateUtils.formatDateTime(context, nextEvent.startDate, flags)
} else if (now.get(Calendar.DAY_OF_YEAR) > start.get(Calendar.DAY_OF_YEAR) || now.get(Calendar.YEAR) > start.get(Calendar.YEAR)) { } else if (now.get(Calendar.DAY_OF_YEAR) > start.get(Calendar.DAY_OF_YEAR) || now.get(Calendar.YEAR) > start.get(Calendar.YEAR)) {
DateUtils.formatDateTime(context, now.timeInMillis, flags) DateUtils.formatDateTime(context, now.timeInMillis, flags)
@ -673,17 +674,17 @@ class MainWidget : AppWidgetProvider() {
} }
} }
v.empty_layout.visibility = View.GONE bindingView.emptyLayout.visibility = View.GONE
v.calendar_layout.visibility = View.VISIBLE bindingView.calendarLayout.visibility = View.VISIBLE
v.second_row_top_margin_small.visibility = bindingView.secondRowTopMarginSmall.visibility =
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.value) View.VISIBLE else View.GONE if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.value) View.VISIBLE else View.GONE
v.second_row_top_margin_medium.visibility = bindingView.secondRowTopMarginMedium.visibility =
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.MEDIUM.value) View.VISIBLE else View.GONE if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.MEDIUM.value) View.VISIBLE else View.GONE
v.second_row_top_margin_large.visibility = bindingView.secondRowTopMarginLarge.visibility =
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.value) View.VISIBLE else View.GONE if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.value) View.VISIBLE else View.GONE
} else if (GlanceProviderHelper.showGlanceProviders(context)) { } else if (GlanceProviderHelper.showGlanceProviders(context)) {
v.second_row_icon.isVisible = true bindingView.secondRowIcon.isVisible = true
var showSomething = false var showSomething = false
loop@ for (provider: Constants.GlanceProviderId in GlanceProviderHelper.getGlanceProviders( loop@ for (provider: Constants.GlanceProviderId in GlanceProviderHelper.getGlanceProviders(
context context
@ -691,26 +692,26 @@ class MainWidget : AppWidgetProvider() {
when (provider) { when (provider) {
Constants.GlanceProviderId.PLAYING_SONG -> { Constants.GlanceProviderId.PLAYING_SONG -> {
if (MediaPlayerHelper.isSomeonePlaying(context)) { if (MediaPlayerHelper.isSomeonePlaying(context)) {
v.second_row_icon.setImageDrawable( bindingView.secondRowIcon.setImageDrawable(
ContextCompat.getDrawable( ContextCompat.getDrawable(
context, context,
R.drawable.round_music_note_24 R.drawable.round_music_note_24
) )
) )
v.next_event_date.text = MediaPlayerHelper.getMediaInfo() bindingView.nextEventDate.text = MediaPlayerHelper.getMediaInfo()
showSomething = true showSomething = true
break@loop break@loop
} }
} }
Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> { Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> {
if (Preferences.showNextAlarm && nextAlarm != "") { if (Preferences.showNextAlarm && nextAlarm != "") {
v.second_row_icon.setImageDrawable( bindingView.secondRowIcon.setImageDrawable(
ContextCompat.getDrawable( ContextCompat.getDrawable(
context, context,
R.drawable.round_alarm_24 R.drawable.round_alarm_24
) )
) )
v.next_event_date.text = AlarmHelper.getNextAlarm(context) bindingView.nextEventDate.text = AlarmHelper.getNextAlarm(context)
showSomething = true showSomething = true
break@loop break@loop
} }
@ -719,19 +720,19 @@ class MainWidget : AppWidgetProvider() {
if (Preferences.showBatteryCharging) { if (Preferences.showBatteryCharging) {
BatteryHelper.updateBatteryInfo(context) BatteryHelper.updateBatteryInfo(context)
if (Preferences.isCharging) { if (Preferences.isCharging) {
v.second_row_icon.isVisible = false bindingView.secondRowIcon.isVisible = false
val batteryLevel = BatteryHelper.getBatteryLevel(context) val batteryLevel = BatteryHelper.getBatteryLevel(context)
if (batteryLevel != 100) { if (batteryLevel != 100) {
v.next_event_date.text = context.getString(R.string.charging) bindingView.nextEventDate.text = context.getString(R.string.charging)
} else { } else {
v.next_event_date.text = bindingView.nextEventDate.text =
context.getString(R.string.charged) context.getString(R.string.charged)
} }
showSomething = true showSomething = true
break@loop break@loop
} else if (Preferences.isBatteryLevelLow) { } else if (Preferences.isBatteryLevelLow) {
v.second_row_icon.isVisible = false bindingView.secondRowIcon.isVisible = false
v.next_event_date.text = bindingView.nextEventDate.text =
context.getString(R.string.battery_low_warning) context.getString(R.string.battery_low_warning)
showSomething = true showSomething = true
break@loop break@loop
@ -740,17 +741,17 @@ class MainWidget : AppWidgetProvider() {
} }
Constants.GlanceProviderId.CUSTOM_INFO -> { Constants.GlanceProviderId.CUSTOM_INFO -> {
if (Preferences.customNotes.isNotEmpty()) { if (Preferences.customNotes.isNotEmpty()) {
v.second_row_icon.isVisible = false bindingView.secondRowIcon.isVisible = false
v.next_event_date.text = Preferences.customNotes bindingView.nextEventDate.text = Preferences.customNotes
v.next_event_date.maxLines = 2 bindingView.nextEventDate.maxLines = 2
showSomething = true showSomething = true
break@loop break@loop
} }
} }
Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> { Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> {
if (Preferences.showDailySteps && Preferences.googleFitSteps > 0) { if (Preferences.showDailySteps && Preferences.googleFitSteps > 0) {
v.second_row_icon.isVisible = false bindingView.secondRowIcon.isVisible = false
v.next_event_date.text = bindingView.nextEventDate.text =
context.getString(R.string.daily_steps_counter) context.getString(R.string.daily_steps_counter)
.format(Preferences.googleFitSteps) .format(Preferences.googleFitSteps)
showSomething = true showSomething = true
@ -764,12 +765,12 @@ class MainWidget : AppWidgetProvider() {
val remotePackageContext = context.createPackageContext(Preferences.lastNotificationPackage, 0) val remotePackageContext = context.createPackageContext(Preferences.lastNotificationPackage, 0)
val icon = ContextCompat.getDrawable(remotePackageContext, val icon = ContextCompat.getDrawable(remotePackageContext,
Preferences.lastNotificationIcon) Preferences.lastNotificationIcon)
v.second_row_icon.isVisible = true bindingView.secondRowIcon.isVisible = true
v.second_row_icon.setImageDrawable(icon) bindingView.secondRowIcon.setImageDrawable(icon)
} else { } else {
v.second_row_icon.isVisible = false bindingView.secondRowIcon.isVisible = false
} }
v.next_event_date.text = Preferences.lastNotificationTitle bindingView.nextEventDate.text = Preferences.lastNotificationTitle
showSomething = true showSomething = true
break@loop break@loop
} catch (ex: Exception) {} } catch (ex: Exception) {}
@ -778,16 +779,16 @@ class MainWidget : AppWidgetProvider() {
Constants.GlanceProviderId.GREETINGS -> { Constants.GlanceProviderId.GREETINGS -> {
val greetingsText = GreetingsHelper.getRandomString(context) val greetingsText = GreetingsHelper.getRandomString(context)
if (Preferences.showGreetings && GreetingsHelper.showGreetings() && greetingsText.isNotBlank()) { if (Preferences.showGreetings && GreetingsHelper.showGreetings() && greetingsText.isNotBlank()) {
v.next_event_date.text = greetingsText bindingView.nextEventDate.text = greetingsText
v.next_event_date.maxLines = 2 bindingView.nextEventDate.maxLines = 2
v.second_row_icon.isVisible = false bindingView.secondRowIcon.isVisible = false
showSomething = true showSomething = true
break@loop break@loop
} }
} }
Constants.GlanceProviderId.EVENTS -> { Constants.GlanceProviderId.EVENTS -> {
if (Preferences.showEventsAsGlanceProvider && Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null) { if (Preferences.showEventsAsGlanceProvider && Preferences.showEvents && context.checkGrantedPermission(Manifest.permission.READ_CALENDAR) && nextEvent != null) {
v.next_event_date.text = context.getString(R.string.events_glance_provider_format).format(nextEvent.title, if (Preferences.showDiffTime && now.timeInMillis < nextEvent.startDate) { bindingView.nextEventDate.text = context.getString(R.string.events_glance_provider_format).format(nextEvent.title, if (Preferences.showDiffTime && now.timeInMillis < nextEvent.startDate) {
if (!nextEvent.allDay) { if (!nextEvent.allDay) {
SettingsStringHelper.getDifferenceText( SettingsStringHelper.getDifferenceText(
context, context,
@ -803,8 +804,8 @@ class MainWidget : AppWidgetProvider() {
).toLowerCase(Locale.getDefault()) ).toLowerCase(Locale.getDefault())
} }
} else "").trimEnd() } else "").trimEnd()
v.second_row_icon.isVisible = true bindingView.secondRowIcon.isVisible = true
v.second_row_icon.setImageDrawable( bindingView.secondRowIcon.setImageDrawable(
ContextCompat.getDrawable( ContextCompat.getDrawable(
context, context,
R.drawable.round_today_24 R.drawable.round_today_24
@ -818,43 +819,43 @@ class MainWidget : AppWidgetProvider() {
} }
if (showSomething) { if (showSomething) {
v.next_event.text = DateHelper.getDateText(context, now) bindingView.nextEvent.text = DateHelper.getDateText(context, now)
v.empty_layout.visibility = View.GONE bindingView.emptyLayout.visibility = View.GONE
v.calendar_layout.visibility = View.VISIBLE bindingView.calendarLayout.visibility = View.VISIBLE
v.second_row_top_margin_small.visibility = bindingView.secondRowTopMarginSmall.visibility =
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.value) View.VISIBLE else View.GONE if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.value) View.VISIBLE else View.GONE
v.second_row_top_margin_medium.visibility = bindingView.secondRowTopMarginMedium.visibility =
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.MEDIUM.value) View.VISIBLE else View.GONE if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.MEDIUM.value) View.VISIBLE else View.GONE
v.second_row_top_margin_large.visibility = bindingView.secondRowTopMarginLarge.visibility =
if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.value) View.VISIBLE else View.GONE if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.value) View.VISIBLE else View.GONE
} else { } else {
v.second_row_icon.isVisible = false bindingView.secondRowIcon.isVisible = false
} }
} }
// Color // Color
listOf<TextView>( listOf<TextView>(
v.empty_date, bindingView.emptyDate,
v.divider1, bindingView.divider1,
v.temp, bindingView.temp,
v.next_event, bindingView.nextEvent,
v.next_event_difference_time, bindingView.nextEventDifferenceTime,
v.divider3, bindingView.divider3,
v.special_temp bindingView.specialTemp
).forEach { ).forEach {
it.setTextColor(ColorHelper.getFontColor(context.applicationContext.isDarkTheme())) it.setTextColor(ColorHelper.getFontColor(context.applicationContext.isDarkTheme()))
} }
if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.value) { if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.value) {
listOf<ImageView>(v.action_next, v.action_previous) listOf<ImageView>(bindingView.actionNext, bindingView.actionPrevious)
} else { } else {
listOf<ImageView>( listOf<ImageView>(
v.action_next, bindingView.actionNext,
v.action_previous, bindingView.actionPrevious,
v.empty_weather_icon, bindingView.emptyWeatherIcon,
v.special_weather_icon bindingView.specialWeatherIcon
) )
}.forEach { }.forEach {
it.setColorFilter(ColorHelper.getFontColorRgb(context.applicationContext.isDarkTheme())) it.setColorFilter(ColorHelper.getFontColorRgb(context.applicationContext.isDarkTheme()))
@ -864,14 +865,14 @@ class MainWidget : AppWidgetProvider() {
.toFloat()) / 100 .toFloat()) / 100
} }
listOf<TextView>(v.next_event_date, v.divider2, v.calendar_temp).forEach { listOf<TextView>(bindingView.nextEventDate, bindingView.divider2, bindingView.calendarTemp).forEach {
it.setTextColor(ColorHelper.getSecondaryFontColor(context.applicationContext.isDarkTheme())) it.setTextColor(ColorHelper.getSecondaryFontColor(context.applicationContext.isDarkTheme()))
} }
if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.value) { if (Preferences.weatherIconPack != Constants.WeatherIconPack.MINIMAL.value) {
listOf<ImageView>(v.second_row_icon, v.second_row_icon_shadow) listOf<ImageView>(bindingView.secondRowIcon, bindingView.secondRowIconShadow)
} else { } else {
listOf<ImageView>(v.second_row_icon, v.weather_icon, v.second_row_icon_shadow) listOf<ImageView>(bindingView.secondRowIcon, bindingView.weatherIcon, bindingView.secondRowIconShadow)
}.forEach { }.forEach {
it.setColorFilter(ColorHelper.getSecondaryFontColorRgb(context.applicationContext.isDarkTheme())) it.setColorFilter(ColorHelper.getSecondaryFontColorRgb(context.applicationContext.isDarkTheme()))
it.alpha = it.alpha =
@ -882,38 +883,38 @@ class MainWidget : AppWidgetProvider() {
// Text Size // Text Size
listOf<Pair<TextView, Float>>( listOf<Pair<TextView, Float>>(
v.empty_date to Preferences.textMainSize, bindingView.emptyDate to Preferences.textMainSize,
v.divider1 to (Preferences.textMainSize - 2), bindingView.divider1 to (Preferences.textMainSize - 2),
v.temp to Preferences.textMainSize, bindingView.temp to Preferences.textMainSize,
v.next_event to Preferences.textMainSize, bindingView.nextEvent to Preferences.textMainSize,
v.next_event_difference_time to Preferences.textMainSize, bindingView.nextEventDifferenceTime to Preferences.textMainSize,
v.next_event_date to Preferences.textSecondSize, bindingView.nextEventDate to Preferences.textSecondSize,
v.divider2 to (Preferences.textSecondSize - 2), bindingView.divider2 to (Preferences.textSecondSize - 2),
v.calendar_temp to Preferences.textSecondSize, bindingView.calendarTemp to Preferences.textSecondSize,
v.divider3 to (Preferences.textMainSize - 2), bindingView.divider3 to (Preferences.textMainSize - 2),
v.special_temp to Preferences.textMainSize bindingView.specialTemp to Preferences.textMainSize
).forEach { ).forEach {
it.first.setTextSize(TypedValue.COMPLEX_UNIT_SP, it.second) it.first.setTextSize(TypedValue.COMPLEX_UNIT_SP, it.second)
} }
// Icons scale // Icons scale
v.second_row_icon.scaleX = Preferences.textSecondSize / 18f bindingView.secondRowIcon.scaleX = Preferences.textSecondSize / 18f
v.second_row_icon.scaleY = Preferences.textSecondSize / 18f bindingView.secondRowIcon.scaleY = Preferences.textSecondSize / 18f
v.weather_icon.scaleX = Preferences.textSecondSize / 14f bindingView.weatherIcon.scaleX = Preferences.textSecondSize / 14f
v.weather_icon.scaleY = Preferences.textSecondSize / 14f bindingView.weatherIcon.scaleY = Preferences.textSecondSize / 14f
v.empty_weather_icon.scaleX = Preferences.textMainSize / 18f bindingView.emptyWeatherIcon.scaleX = Preferences.textMainSize / 18f
v.empty_weather_icon.scaleY = Preferences.textMainSize / 18f bindingView.emptyWeatherIcon.scaleY = Preferences.textMainSize / 18f
v.action_next.scaleX = Preferences.textMainSize / 28f bindingView.actionNext.scaleX = Preferences.textMainSize / 28f
v.action_next.scaleY = Preferences.textMainSize / 28f bindingView.actionNext.scaleY = Preferences.textMainSize / 28f
v.action_previous.scaleX = Preferences.textMainSize / 28f bindingView.actionPrevious.scaleX = Preferences.textMainSize / 28f
v.action_previous.scaleY = Preferences.textMainSize / 28f bindingView.actionPrevious.scaleY = Preferences.textMainSize / 28f
v.special_weather_icon.scaleX = Preferences.textMainSize / 18f bindingView.specialWeatherIcon.scaleX = Preferences.textMainSize / 18f
v.special_weather_icon.scaleY = Preferences.textMainSize / 18f bindingView.specialWeatherIcon.scaleY = Preferences.textMainSize / 18f
// Shadows // Shadows
@ -940,16 +941,16 @@ class MainWidget : AppWidgetProvider() {
} }
listOf<TextView>( listOf<TextView>(
v.empty_date, bindingView.emptyDate,
v.divider1, bindingView.divider1,
v.temp, bindingView.temp,
v.next_event, bindingView.nextEvent,
v.next_event_difference_time, bindingView.nextEventDifferenceTime,
v.next_event_date, bindingView.nextEventDate,
v.divider2, bindingView.divider2,
v.calendar_temp, bindingView.calendarTemp,
v.divider3, bindingView.divider3,
v.special_temp bindingView.specialTemp
).forEach { ).forEach {
it.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor) it.setShadowLayer(shadowRadius, 0f, shadowDy, shadowColor)
} }
@ -957,7 +958,7 @@ class MainWidget : AppWidgetProvider() {
// Icons shadow // Icons shadow
listOf( listOf(
Pair(v.second_row_icon, v.second_row_icon_shadow), Pair(bindingView.secondRowIcon, bindingView.secondRowIconShadow),
).forEach { ).forEach {
if ((if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) == 0) { if ((if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) == 0) {
it.second.isVisible = false it.second.isVisible = false
@ -970,8 +971,8 @@ class MainWidget : AppWidgetProvider() {
} }
listOf( listOf(
Pair(v.action_next, v.action_next_shadow), Pair(bindingView.actionNext, bindingView.actionNextShadow),
Pair(v.action_previous, v.action_previous_shadow), Pair(bindingView.actionPrevious, bindingView.actionPreviousShadow),
).forEach { ).forEach {
if ((if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) == 0) { if ((if (context.isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) == 0) {
it.second.isVisible = false it.second.isVisible = false
@ -983,8 +984,8 @@ class MainWidget : AppWidgetProvider() {
} }
} }
v.action_previous.scaleX = v.action_previous.scaleX * -1 bindingView.actionPrevious.scaleX = bindingView.actionPrevious.scaleX * -1
v.action_previous_shadow.scaleX = v.action_previous_shadow.scaleX * -1 bindingView.actionPreviousShadow.scaleX = bindingView.actionPreviousShadow.scaleX * -1
// Custom Font // Custom Font
if (Preferences.customFont == Constants.CUSTOM_FONT_GOOGLE_SANS) { if (Preferences.customFont == Constants.CUSTOM_FONT_GOOGLE_SANS) {
@ -998,31 +999,31 @@ class MainWidget : AppWidgetProvider() {
} }
listOf<TextView>( listOf<TextView>(
v.empty_date, bindingView.emptyDate,
v.divider1, bindingView.divider1,
v.temp, bindingView.temp,
v.next_event, bindingView.nextEvent,
v.next_event_difference_time, bindingView.nextEventDifferenceTime,
v.next_event_date, bindingView.nextEventDate,
v.divider2, bindingView.divider2,
v.calendar_temp, bindingView.calendarTemp,
v.divider3, bindingView.divider3,
v.special_temp bindingView.specialTemp
).forEach { ).forEach {
it.typeface = googleSans it.typeface = googleSans
} }
} else if (Preferences.customFont == Constants.CUSTOM_FONT_DOWNLOADED && typeface != null) { } else if (Preferences.customFont == Constants.CUSTOM_FONT_DOWNLOADED && typeface != null) {
listOf<TextView>( listOf<TextView>(
v.empty_date, bindingView.emptyDate,
v.divider1, bindingView.divider1,
v.temp, bindingView.temp,
v.next_event, bindingView.nextEvent,
v.next_event_difference_time, bindingView.nextEventDifferenceTime,
v.next_event_date, bindingView.nextEventDate,
v.divider2, bindingView.divider2,
v.calendar_temp, bindingView.calendarTemp,
v.divider3, bindingView.divider3,
v.special_temp bindingView.specialTemp
).forEach { ).forEach {
it.typeface = typeface it.typeface = typeface
} }
@ -1030,9 +1031,9 @@ class MainWidget : AppWidgetProvider() {
// Weather // Weather
if (Preferences.showWeather && Preferences.weatherIcon != "") { if (Preferences.showWeather && Preferences.weatherIcon != "") {
v.weather.visibility = View.VISIBLE bindingView.weather.visibility = View.VISIBLE
v.calendar_weather.visibility = View.VISIBLE bindingView.calendarWeather.visibility = View.VISIBLE
v.special_weather.visibility = View.VISIBLE bindingView.specialWeather.visibility = View.VISIBLE
val currentTemp = String.format( val currentTemp = String.format(
Locale.getDefault(), Locale.getDefault(),
"%d °%s", "%d °%s",
@ -1042,41 +1043,41 @@ class MainWidget : AppWidgetProvider() {
val icon: String = Preferences.weatherIcon val icon: String = Preferences.weatherIcon
if (icon == "") { if (icon == "") {
v.weather_icon.visibility = View.GONE bindingView.weatherIcon.visibility = View.GONE
v.empty_weather_icon.visibility = View.GONE bindingView.emptyWeatherIcon.visibility = View.GONE
v.special_weather_icon.visibility = View.GONE bindingView.specialWeatherIcon.visibility = View.GONE
} else { } else {
v.weather_icon.setImageResource(WeatherHelper.getWeatherIconResource(context, icon)) bindingView.weatherIcon.setImageResource(WeatherHelper.getWeatherIconResource(context, icon))
v.empty_weather_icon.setImageResource(WeatherHelper.getWeatherIconResource(context, icon)) bindingView.emptyWeatherIcon.setImageResource(WeatherHelper.getWeatherIconResource(context, icon))
v.special_weather_icon.setImageResource(WeatherHelper.getWeatherIconResource(context, icon)) bindingView.specialWeatherIcon.setImageResource(WeatherHelper.getWeatherIconResource(context, icon))
v.weather_icon.visibility = View.VISIBLE bindingView.weatherIcon.visibility = View.VISIBLE
v.empty_weather_icon.visibility = View.VISIBLE bindingView.emptyWeatherIcon.visibility = View.VISIBLE
v.special_weather_icon.visibility = View.VISIBLE bindingView.specialWeatherIcon.visibility = View.VISIBLE
} }
v.temp.text = currentTemp bindingView.temp.text = currentTemp
v.calendar_temp.text = currentTemp bindingView.calendarTemp.text = currentTemp
v.special_temp.text = currentTemp bindingView.specialTemp.text = currentTemp
if (GlanceProviderHelper.showGlanceProviders(context)) { if (GlanceProviderHelper.showGlanceProviders(context)) {
v.calendar_weather.visibility = View.GONE bindingView.calendarWeather.visibility = View.GONE
} else { } else {
v.special_weather.visibility = View.GONE bindingView.specialWeather.visibility = View.GONE
} }
} else { } else {
v.weather.visibility = View.GONE bindingView.weather.visibility = View.GONE
v.calendar_weather.visibility = View.GONE bindingView.calendarWeather.visibility = View.GONE
v.special_weather.visibility = View.GONE bindingView.specialWeather.visibility = View.GONE
} }
// Dividers // Dividers
arrayOf(v.divider1, v.divider2, v.divider3).forEach { arrayOf(bindingView.divider1, bindingView.divider2, bindingView.divider3).forEach {
it.isVisible = Preferences.showDividers it.isVisible = Preferences.showDividers
} }
eventRepository.close() eventRepository.close()
return v return bindingView
} }
} }
} }

View File

@ -2,7 +2,6 @@ package com.tommasoberlose.anotherwidget.utils
import android.animation.* import android.animation.*
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.view.Gravity
import android.view.View import android.view.View
import android.view.ViewAnimationUtils import android.view.ViewAnimationUtils
import android.widget.Toast import android.widget.Toast
@ -21,22 +20,12 @@ import android.content.Intent
import android.content.res.Resources import android.content.res.Resources
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.util.DisplayMetrics import android.util.DisplayMetrics
import android.util.Log
import android.util.TypedValue import android.util.TypedValue
import android.view.ViewPropertyAnimator
import android.view.animation.Animation
import android.view.animation.Transformation
import android.widget.LinearLayout
import android.widget.RelativeLayout import android.widget.RelativeLayout
import androidx.browser.customtabs.CustomTabColorSchemeParams
import androidx.core.animation.addListener import androidx.core.animation.addListener
import androidx.core.animation.doOnEnd
import androidx.core.animation.doOnStart
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment
import kotlinx.android.synthetic.main.fragment_app_main.*
import kotlinx.android.synthetic.main.the_widget_sans.*
import java.util.* import java.util.*
@ -149,7 +138,7 @@ fun View.collapse(duration: Long = 500L) {
fun Context.openURI(url: String) { fun Context.openURI(url: String) {
try { try {
val builder: CustomTabsIntent.Builder = CustomTabsIntent.Builder() val builder: CustomTabsIntent.Builder = CustomTabsIntent.Builder()
builder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary)) builder.setDefaultColorSchemeParams(CustomTabColorSchemeParams.Builder().setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary)).build())
val customTabsIntent: CustomTabsIntent = builder.build() val customTabsIntent: CustomTabsIntent = builder.build()
customTabsIntent.launchUrl(this, Uri.parse(url)) customTabsIntent.launchUrl(this, Uri.parse(url))
} catch (e: Exception) { } catch (e: Exception) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 720 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M4,13h6c0.55,0 1,-0.45 1,-1L11,4c0,-0.55 -0.45,-1 -1,-1L4,3c-0.55,0 -1,0.45 -1,1v8c0,0.55 0.45,1 1,1zM4,21h6c0.55,0 1,-0.45 1,-1v-4c0,-0.55 -0.45,-1 -1,-1L4,15c-0.55,0 -1,0.45 -1,1v4c0,0.55 0.45,1 1,1zM14,21h6c0.55,0 1,-0.45 1,-1v-8c0,-0.55 -0.45,-1 -1,-1h-6c-0.55,0 -1,0.45 -1,1v8c0,0.55 0.45,1 1,1zM13,4v4c0,0.55 0.45,1 1,1h6c0.55,0 1,-0.45 1,-1L21,4c0,-0.55 -0.45,-1 -1,-1h-6c-0.55,0 -1,0.45 -1,1z"/>
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19.3,16.9c0.58,-1.01 0.95,-2.23 0.51,-3.65c-0.53,-1.72 -2.04,-3.05 -3.84,-3.22c-2.87,-0.28 -5.23,2.07 -4.95,4.95c0.18,1.79 1.5,3.31 3.22,3.84c1.43,0.44 2.64,0.07 3.65,-0.51l2.5,2.5c0.39,0.39 1.01,0.39 1.4,0l0,0c0.39,-0.39 0.39,-1.01 0,-1.4L19.3,16.9zM15.5,17c-1.4,0 -2.5,-1.1 -2.5,-2.5s1.1,-2.5 2.5,-2.5s2.5,1.1 2.5,2.5S16.9,17 15.5,17zM12,20v2C6.48,22 2,17.52 2,12C2,6.48 6.48,2 12,2c4.84,0 8.87,3.44 9.8,8h-2.07c-0.64,-2.46 -2.4,-4.47 -4.73,-5.41V5c0,1.1 -0.9,2 -2,2h-2v2c0,0.55 -0.45,1 -1,1H8v2h2v3H9l-4.79,-4.79C4.08,10.79 4,11.38 4,12C4,16.41 7.59,20 12,20z"/>
</vector>

View File

@ -99,7 +99,7 @@
android:id="@+id/widget" android:id="@+id/widget"
android:alpha="0" android:alpha="0"
android:gravity="center"> android:gravity="center">
<include layout="@layout/the_widget_sans" /> <include layout="@layout/the_widget_sans" android:id="@+id/widget_detail" />
</LinearLayout> </LinearLayout>
<ProgressBar <ProgressBar
android:layout_width="32dp" android:layout_width="32dp"

View File

@ -72,7 +72,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Change the text design" android:text="Text font, size and color"
style="@style/AnotherWidget.Settings.Subtitle"/> style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
@ -93,7 +93,7 @@
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:padding="12dp" android:padding="12dp"
android:src="@drawable/round_palette_24" android:src="@drawable/round_dashboard_24"
app:tint="@color/colorPrimaryText"/> app:tint="@color/colorPrimaryText"/>
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
@ -106,7 +106,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
style="@style/AnotherWidget.Settings.Title" style="@style/AnotherWidget.Settings.Title"
android:text="@string/appearance_header"/> android:text="Layout"/>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -114,10 +114,74 @@
style="@style/AnotherWidget.Settings.Subtitle"/> style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingLeft="8dp"
android:paddingRight="0dp"
android:orientation="horizontal"
android:gravity="center_vertical"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
android:id="@+id/action_show_clock">
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:padding="12dp"
app:tint="@color/colorPrimaryText"
android:src="@drawable/round_schedule_24"/>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/AnotherWidget.Settings.Title"
android:text="@string/settings_clock_title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change the clock "
style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout>
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/cardBorder"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:alpha="0.6" />
</LinearLayout>
<com.kyleduo.switchbutton.SwitchButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginStart="16dp"
app:kswThumbWidth="16sp"
app:kswThumbHeight="16sp"
app:kswBackRadius="16dp"
app:kswTintColor="@color/colorAccent"
android:checked="@{isClockVisible}"
android:id="@+id/show_clock_switch"
android:buttonTint="@color/colorAccent" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Content" android:text="Smart content"
android:paddingTop="16dp" android:paddingTop="16dp"
android:paddingStart="20dp" android:paddingStart="20dp"
android:paddingEnd="20dp" android:paddingEnd="20dp"
@ -251,70 +315,6 @@
android:id="@+id/show_weather_switch" android:id="@+id/show_weather_switch"
android:buttonTint="@color/colorAccent" /> android:buttonTint="@color/colorAccent" />
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingLeft="8dp"
android:paddingRight="0dp"
android:orientation="horizontal"
android:gravity="center_vertical"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
android:id="@+id/action_show_clock">
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:padding="12dp"
app:tint="@color/colorPrimaryText"
android:src="@drawable/round_schedule_24"/>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/AnotherWidget.Settings.Title"
android:text="@string/settings_clock_title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change the clock "
style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout>
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/cardBorder"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:alpha="0.6" />
</LinearLayout>
<com.kyleduo.switchbutton.SwitchButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginStart="16dp"
app:kswThumbWidth="16sp"
app:kswThumbHeight="16sp"
app:kswBackRadius="16dp"
app:kswTintColor="@color/colorAccent"
android:checked="@{isClockVisible}"
android:id="@+id/show_clock_switch"
android:buttonTint="@color/colorAccent" />
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -379,6 +379,52 @@
android:id="@+id/show_glance_switch" android:id="@+id/show_glance_switch"
android:buttonTint="@color/colorAccent" /> android:buttonTint="@color/colorAccent" />
</LinearLayout> </LinearLayout>
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Gestures &amp; input"
android:paddingTop="16dp"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:textAppearance="@style/AnotherWidget.Settings.Header" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="12dp"
android:paddingBottom="12dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:id="@+id/action_tab_default_app"
android:orientation="horizontal">
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:padding="12dp"
android:src="@drawable/round_add_to_home_screen_24"
app:tint="@color/colorPrimaryText"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/AnotherWidget.Settings.Title"
android:text="Gestures"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change the widget design"
style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>
</com.tommasoberlose.anotherwidget.components.FixedFocusScrollView> </com.tommasoberlose.anotherwidget.components.FixedFocusScrollView>
</layout> </layout>

View File

@ -51,7 +51,7 @@
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:padding="12dp" android:padding="12dp"
android:src="@drawable/round_language_24" android:src="@drawable/round_travel_explore_24"
app:tint="@color/colorPrimaryText"/> app:tint="@color/colorPrimaryText"/>
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"

View File

@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext.kotlin_version = '1.4.10' ext.kotlin_version = '1.4.21'
repositories { repositories {
google() google()
jcenter() jcenter()