update ui

This commit is contained in:
Tommaso Berlose
2021-01-09 18:33:22 +01:00
parent d32f680519
commit 889783bb4e
66 changed files with 553 additions and 466 deletions

View File

@ -56,8 +56,6 @@ class BottomSheetColorPicker(
private var listBinding: BottomSheetMenuListBinding = BottomSheetMenuListBinding.inflate(LayoutInflater.from(context))
override fun show() {
window?.setDimAmount(0f)
// Header
binding.header.isVisible = header != null
binding.headerText.text = header ?: ""

View File

@ -111,8 +111,6 @@ object Preferences : KotprefModel() {
// Settings
var showWallpaper by booleanPref(default = true)
var showBigClockWarning by booleanPref(default = true)
var showWeatherWarning by booleanPref(default = true)
var showPreview by booleanPref(default = true)
var showXiaomiWarning by booleanPref(default = true)

View File

@ -2,14 +2,16 @@ package com.tommasoberlose.anotherwidget.helpers
import android.annotation.SuppressLint
import android.graphics.Color
import android.util.Log
import com.tommasoberlose.anotherwidget.global.Preferences
import kotlin.math.roundToInt
object ColorHelper {
fun getFontColor(isDark: Boolean): Int {
return try {
Color.parseColor("#%s%s".format(if (!isDark) Preferences.textGlobalAlpha else Preferences.textGlobalAlphaDark, (if (!isDark) Preferences.textGlobalColor else Preferences.textGlobalColorDark).replace("#", "")))
Color.parseColor("#%s%s".format(if (!isDark) Preferences.textGlobalAlpha else Preferences.textGlobalAlphaDark,
(if (!isDark) Preferences.textGlobalColor else Preferences.textGlobalColorDark).replace(
"#",
"")))
} catch (e: Exception) {
Color.parseColor("#FFFFFFFF")
}
@ -33,7 +35,10 @@ object ColorHelper {
fun getSecondaryFontColor(isDark: Boolean): Int {
return try {
Color.parseColor("#%s%s".format((if (!isDark) Preferences.textSecondaryAlpha else Preferences.textSecondaryAlphaDark), (if (!isDark) Preferences.textSecondaryColor else Preferences.textSecondaryColorDark).replace("#", "")))
Color.parseColor("#%s%s".format((if (!isDark) Preferences.textSecondaryAlpha else Preferences.textSecondaryAlphaDark),
(if (!isDark) Preferences.textSecondaryColor else Preferences.textSecondaryColorDark).replace(
"#",
"")))
} catch (e: Exception) {
Color.parseColor("#FFFFFFFF")
}
@ -57,7 +62,10 @@ object ColorHelper {
fun getClockFontColor(isDark: Boolean): Int {
return try {
Color.parseColor("#%s%s".format((if (!isDark) Preferences.clockTextAlpha else Preferences.clockTextAlphaDark), (if (!isDark) Preferences.clockTextColor else Preferences.clockTextColorDark).replace("#", "")))
Color.parseColor("#%s%s".format((if (!isDark) Preferences.clockTextAlpha else Preferences.clockTextAlphaDark),
(if (!isDark) Preferences.clockTextColor else Preferences.clockTextColorDark).replace(
"#",
"")))
} catch (e: Exception) {
Color.parseColor("#FFFFFFFF")
}
@ -81,7 +89,10 @@ object ColorHelper {
fun getBackgroundColor(isDark: Boolean): Int {
return try {
Color.parseColor("#%s%s".format((if (!isDark) Preferences.backgroundCardAlpha else Preferences.backgroundCardAlphaDark), (if (!isDark) Preferences.backgroundCardColor else Preferences.backgroundCardColorDark).replace("#", "")))
Color.parseColor("#%s%s".format((if (!isDark) Preferences.backgroundCardAlpha else Preferences.backgroundCardAlphaDark),
(if (!isDark) Preferences.backgroundCardColor else Preferences.backgroundCardColorDark).replace(
"#",
"")))
} catch (e: Exception) {
Color.parseColor("#00000000")
}
@ -123,4 +134,14 @@ object ColorHelper {
val hexValue = this.toInt(16).toDouble()
return (hexValue * 100 / 255).roundToInt()
}
fun String.isColor(): Boolean {
return try {
Color.parseColor(this)
true
} catch (iae: IllegalArgumentException) {
iae.printStackTrace()
false
}
}
}

View File

@ -30,7 +30,7 @@ object ImageHelper {
canvas.drawColor(Color.TRANSPARENT)
canvas.save()
val rect = Rect()
val bounds = originalView.drawable.copyBounds()
// val bounds = originalView.drawable.copyBounds()
canvas.getClipBounds(rect)
rect.inset(-2 * getBlurRadius(context, cElevation).toInt(), -2 * getBlurRadius(context, cElevation).toInt())
canvas.save()

View File

@ -25,9 +25,8 @@ object WidgetHelper {
) {
fun getWidgetsSize(widgetId: Int): Pair<Int, Int> {
val isPortrait = context.resources.configuration.orientation == ORIENTATION_PORTRAIT
val width = getWidgetWidth(isPortrait, widgetId)
val height = getWidgetHeight(isPortrait, widgetId)
val width = getWidgetWidth(widgetId)
val height = getWidgetHeight(widgetId)
val widthInPx = context.dip(width)
val heightInPx = context.dip(height)
FirebaseCrashlytics.getInstance().setCustomKey("widthInPx", widthInPx)
@ -35,9 +34,9 @@ object WidgetHelper {
return widthInPx to heightInPx
}
private fun getWidgetWidth(isPortrait: Boolean, widgetId: Int): Int = getWidgetSizeInDp(widgetId, AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH)
private fun getWidgetWidth(widgetId: Int): Int = getWidgetSizeInDp(widgetId, AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH)
private fun getWidgetHeight(isPortrait: Boolean, widgetId: Int): Int = getWidgetSizeInDp(widgetId, AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT)
private fun getWidgetHeight(widgetId: Int): Int = getWidgetSizeInDp(widgetId, AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT)
private fun getWidgetSizeInDp(widgetId: Int, key: String): Int =
appWidgetManager.getAppWidgetOptions(widgetId).getInt(key, 0)

View File

@ -344,7 +344,7 @@ class WeatherNetworkApi(val context: Context) {
private suspend fun useAccuweatherProvider(context: Context) {
if (Preferences.weatherProviderApiAccuweather != "") {
val repository = AccuweatherRepository()
// val repository = AccuweatherRepository()
// when (val response = repository.getWeather()) {
// is NetworkResponse.Success -> {

View File

@ -138,10 +138,8 @@ class ActivityDetectionReceiver : BroadcastReceiver() {
val endTime: Long = cal.timeInMillis
val readRequest = DataReadRequest.Builder()
.aggregate(
DataType.TYPE_STEP_COUNT_DELTA,
DataType.AGGREGATE_STEP_COUNT_DELTA
)
.aggregate(DataType.TYPE_STEP_COUNT_DELTA)
.aggregate(DataType.AGGREGATE_STEP_COUNT_DELTA)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.bucketByTime(1, TimeUnit.DAYS)
.build()

View File

@ -41,6 +41,7 @@ class NotificationListener : NotificationListenerService() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
Preferences.lastNotificationIcon = sbn.notification.smallIcon.resId
} else {
@Suppress("DEPRECATION")
Preferences.lastNotificationIcon = sbn.notification.icon
}
} catch (ex: Exception) {

View File

@ -2,12 +2,11 @@ package com.tommasoberlose.anotherwidget.ui.activities.settings
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.databinding.ActivityIntegrationsBinding
import com.tommasoberlose.anotherwidget.ui.viewmodels.IntegrationsViewModel
import com.tommasoberlose.anotherwidget.ui.viewmodels.settings.IntegrationsViewModel
import net.idik.lib.slimadapter.SlimAdapter
class IntegrationsActivity : AppCompatActivity() {

View File

@ -4,7 +4,6 @@ import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
@ -13,7 +12,7 @@ import com.android.billingclient.api.BillingClient.BillingResponseCode.OK
import com.android.billingclient.api.BillingClient.BillingResponseCode.USER_CANCELED
import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.databinding.ActivitySupportDevBinding
import com.tommasoberlose.anotherwidget.ui.viewmodels.SupportDevViewModel
import com.tommasoberlose.anotherwidget.ui.viewmodels.settings.SupportDevViewModel
import com.tommasoberlose.anotherwidget.utils.toast
import net.idik.lib.slimadapter.SlimAdapter

View File

@ -6,7 +6,6 @@ import android.view.View
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
@ -16,7 +15,7 @@ import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.databinding.ActivityAppNotificationsFilterBinding
import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.ActiveNotificationsHelper
import com.tommasoberlose.anotherwidget.ui.viewmodels.AppNotificationsViewModel
import com.tommasoberlose.anotherwidget.ui.viewmodels.tabs.AppNotificationsViewModel
import kotlinx.coroutines.*
import net.idik.lib.slimadapter.SlimAdapter

View File

@ -10,7 +10,6 @@ import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
@ -18,7 +17,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.bumptech.glide.Glide
import com.tommasoberlose.anotherwidget.databinding.ActivityChooseApplicationBinding
import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.ui.viewmodels.ChooseApplicationViewModel
import com.tommasoberlose.anotherwidget.ui.viewmodels.tabs.ChooseApplicationViewModel
import kotlinx.coroutines.*
import net.idik.lib.slimadapter.SlimAdapter
import net.idik.lib.slimadapter.SlimAdapterEx
@ -90,15 +89,15 @@ class ChooseApplicationActivity : AppCompatActivity() {
binding.viewModel = viewModel
binding.lifecycleOwner = this
viewModel.appList.observe(this, Observer {
viewModel.appList.observe(this) {
updateList(list = it)
binding.loader.visibility = View.INVISIBLE
})
}
viewModel.searchInput.observe(this, Observer { search ->
viewModel.searchInput.observe(this) { search ->
updateList(search = search)
binding.clearSearch.isVisible = search.isNotBlank()
})
}
}
private fun updateList(list: List<ResolveInfo>? = viewModel.appList.value, search: String? = viewModel.searchInput.value) {

View File

@ -4,7 +4,6 @@ import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
@ -13,7 +12,7 @@ import com.chibatching.kotpref.blockingBulk
import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.databinding.ActivityCustomDateBinding
import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.ui.viewmodels.CustomDateViewModel
import com.tommasoberlose.anotherwidget.ui.viewmodels.tabs.CustomDateViewModel
import com.tommasoberlose.anotherwidget.utils.getCapWordString
import com.tommasoberlose.anotherwidget.utils.openURI
import com.tommasoberlose.anotherwidget.utils.toast

View File

@ -13,7 +13,6 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.provider.FontRequest
import androidx.core.provider.FontsContractCompat
import androidx.core.view.isVisible
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
@ -26,7 +25,7 @@ import com.tommasoberlose.anotherwidget.databinding.ActivityCustomFontBinding
import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
import com.tommasoberlose.anotherwidget.ui.viewmodels.CustomFontViewModel
import com.tommasoberlose.anotherwidget.ui.viewmodels.tabs.CustomFontViewModel
import kotlinx.coroutines.*
import net.idik.lib.slimadapter.SlimAdapter
import net.idik.lib.slimadapter.diff.DefaultDiffCallback

View File

@ -9,7 +9,6 @@ import com.tommasoberlose.anotherwidget.R
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
@ -22,7 +21,7 @@ import com.karumi.dexter.listener.PermissionRequest
import com.karumi.dexter.listener.multi.MultiplePermissionsListener
import com.tommasoberlose.anotherwidget.databinding.ActivityCustomLocationBinding
import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.ui.viewmodels.CustomLocationViewModel
import com.tommasoberlose.anotherwidget.ui.viewmodels.tabs.CustomLocationViewModel
import kotlinx.coroutines.*
import net.idik.lib.slimadapter.SlimAdapter

View File

@ -7,7 +7,6 @@ import android.view.View
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
@ -16,7 +15,7 @@ import com.bumptech.glide.Glide
import com.tommasoberlose.anotherwidget.databinding.ActivityMusicPlayersFilterBinding
import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.MediaPlayerHelper
import com.tommasoberlose.anotherwidget.ui.viewmodels.MusicPlayersFilterViewModel
import com.tommasoberlose.anotherwidget.ui.viewmodels.tabs.MusicPlayersFilterViewModel
import kotlinx.coroutines.*
import net.idik.lib.slimadapter.SlimAdapter
@ -76,20 +75,20 @@ class MusicPlayersFilterActivity : AppCompatActivity() {
binding.viewModel = viewModel
binding.lifecycleOwner = this
viewModel.appList.observe(this, Observer {
viewModel.appList.observe(this) {
updateList(list = it)
binding.loader.visibility = View.INVISIBLE
})
}
viewModel.searchInput.observe(this, Observer { search ->
viewModel.searchInput.observe(this) { search ->
updateList(search = search)
binding.clearSearch.isVisible = search.isNotBlank()
})
}
viewModel.musicPlayersFilter.observe(this, {
viewModel.musicPlayersFilter.observe(this) {
updateList()
binding.clearSelection.isVisible = Preferences.musicPlayersFilter != ""
})
}
}
private fun updateList(list: List<ResolveInfo>? = viewModel.appList.value, search: String? = viewModel.searchInput.value) {

View File

@ -18,7 +18,7 @@ import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.WeatherHelper
import com.tommasoberlose.anotherwidget.ui.fragments.MainFragment
import com.tommasoberlose.anotherwidget.ui.viewmodels.WeatherProviderViewModel
import com.tommasoberlose.anotherwidget.ui.viewmodels.tabs.WeatherProviderViewModel
import kotlinx.coroutines.launch
import net.idik.lib.slimadapter.SlimAdapter
import org.greenrobot.eventbus.EventBus

View File

@ -119,100 +119,6 @@ class MainFragment : Fragment() {
binding.actionBack to "action_back"
))
}
}
private var uiJob: Job? = null
private fun updateUI() {
uiJob?.cancel()
if (Preferences.showPreview) {
lifecycleScope.launch(Dispatchers.IO) {
val bgColor: Int = ContextCompat.getColor(
requireContext(),
if (ColorHelper.getFontColor(requireActivity().isDarkTheme())
.isColorDark()
) android.R.color.white else R.color.colorAccent
)
val wallpaperDrawable = BitmapHelper.getTintedDrawable(
requireContext(),
R.drawable.card_background,
ColorHelper.getBackgroundColor(requireActivity().isDarkTheme())
)
withContext(Dispatchers.Main) {
binding.preview.setCardBackgroundColor(bgColor)
binding.widgetDetail.widgetShapeBackground.setImageDrawable(wallpaperDrawable)
}
}
WidgetHelper.runWithCustomTypeface(requireContext()) { typeface ->
uiJob = lifecycleScope.launch(Dispatchers.IO) {
val generatedView = MainWidget.generateWidgetView(requireContext(), typeface).root
withContext(Dispatchers.Main) {
generatedView.measure(0, 0)
binding.preview.measure(0, 0)
}
val bitmap = BitmapHelper.getBitmapFromView(
generatedView,
if (binding.preview.width > 0) binding.preview.width else generatedView.measuredWidth,
generatedView.measuredHeight
)
withContext(Dispatchers.Main) {
binding.widget.animate().alpha(0f).start()
binding.widgetLoader.animate().scaleX(1f).scaleY(1f).alpha(1f)
.setDuration(200L).start()
binding.widgetDetail.bitmapContainer.apply {
setImageBitmap(bitmap)
}
binding.widgetLoader.animate().scaleX(0f).scaleY(0f).alpha(0f)
.setDuration(200L).start()
binding.widget.animate().alpha(1f).start()
}
}
}
} else {
binding.preview.layoutParams = binding.preview.layoutParams.apply {
height = 0
}
}
}
private fun updateClock() {
// Clock
binding.widgetDetail.time.setTextColor(ColorHelper.getClockFontColor(requireActivity().isDarkTheme()))
binding.widgetDetail.timeAmPm.setTextColor(ColorHelper.getClockFontColor(requireActivity().isDarkTheme()))
binding.widgetDetail.time.setTextSize(
TypedValue.COMPLEX_UNIT_SP,
Preferences.clockTextSize.toPixel(requireContext())
)
binding.widgetDetail.timeAmPm.setTextSize(
TypedValue.COMPLEX_UNIT_SP,
Preferences.clockTextSize.toPixel(requireContext()) / 5 * 2
)
binding.widgetDetail.timeAmPm.isVisible = Preferences.showAMPMIndicator
// Clock bottom margin
binding.widgetDetail.clockBottomMarginNone.isVisible =
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.NONE.value
binding.widgetDetail.clockBottomMarginSmall.isVisible =
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.SMALL.value
binding.widgetDetail.clockBottomMarginMedium.isVisible =
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.MEDIUM.value
binding.widgetDetail.clockBottomMarginLarge.isVisible =
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.LARGE.value
if (Preferences.showClock) {
binding.widgetDetail.timeContainer.expand()
} else {
binding.widgetDetail.timeContainer.collapse()
}
binding.preview.layoutParams = binding.preview.layoutParams.apply {
height = PREVIEW_BASE_HEIGHT.toPixel(requireContext()) + if (Preferences.showClock) 100.toPixel(
@ -272,6 +178,120 @@ class MainFragment : Fragment() {
viewModel.widgetPreferencesUpdate.observe(viewLifecycleOwner) {
onUpdateUiEvent(null)
}
viewModel.showClock.observe(viewLifecycleOwner) {
updateClockVisibility(it)
}
}
private var uiJob: Job? = null
private fun updateUI() {
uiJob?.cancel()
if (Preferences.showPreview) {
lifecycleScope.launch(Dispatchers.IO) {
val bgColor: Int = ContextCompat.getColor(
requireContext(),
if (ColorHelper.getFontColor(requireActivity().isDarkTheme())
.isColorDark()
) android.R.color.white else R.color.colorAccent
)
val wallpaperDrawable = BitmapHelper.getTintedDrawable(
requireContext(),
R.drawable.card_background,
ColorHelper.getBackgroundColor(requireActivity().isDarkTheme())
)
withContext(Dispatchers.Main) {
binding.preview.setCardBackgroundColor(bgColor)
binding.widgetDetail.widgetShapeBackground.setImageDrawable(wallpaperDrawable)
}
}
WidgetHelper.runWithCustomTypeface(requireContext()) { typeface ->
uiJob = lifecycleScope.launch(Dispatchers.IO) {
val generatedView = MainWidget.generateWidgetView(requireContext(), typeface).root
withContext(Dispatchers.Main) {
generatedView.measure(0, 0)
binding.preview.measure(0, 0)
}
val bitmap = BitmapHelper.getBitmapFromView(
generatedView,
if (binding.preview.width > 0) binding.preview.width else generatedView.measuredWidth,
generatedView.measuredHeight
)
withContext(Dispatchers.Main) {
binding.widgetDetail.bitmapContainer.apply {
setImageBitmap(bitmap)
}
binding.widgetLoader.animate().scaleX(0f).scaleY(0f).alpha(0f)
.setDuration(200L).start()
binding.widget.animate().alpha(1f).start()
}
}
}
} else {
binding.preview.layoutParams = binding.preview.layoutParams.apply {
height = 0
}
}
}
private fun updateClock() {
// Clock
binding.widgetDetail.time.setTextColor(ColorHelper.getClockFontColor(requireActivity().isDarkTheme()))
binding.widgetDetail.timeAmPm.setTextColor(ColorHelper.getClockFontColor(requireActivity().isDarkTheme()))
binding.widgetDetail.time.setTextSize(
TypedValue.COMPLEX_UNIT_SP,
Preferences.clockTextSize.toPixel(requireContext())
)
binding.widgetDetail.timeAmPm.setTextSize(
TypedValue.COMPLEX_UNIT_SP,
Preferences.clockTextSize.toPixel(requireContext()) / 5 * 2
)
binding.widgetDetail.timeAmPm.isVisible = Preferences.showAMPMIndicator
// Clock bottom margin
binding.widgetDetail.clockBottomMarginNone.isVisible =
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.NONE.value
binding.widgetDetail.clockBottomMarginSmall.isVisible =
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.SMALL.value
binding.widgetDetail.clockBottomMarginMedium.isVisible =
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.MEDIUM.value
binding.widgetDetail.clockBottomMarginLarge.isVisible =
Preferences.showClock && Preferences.clockBottomMargin == Constants.ClockBottomMargin.LARGE.value
}
private fun updateClockVisibility(showClock: Boolean) {
binding.preview.animation?.cancel()
val clockInitialHeight = binding.widgetDetail.timeContainer.measuredHeight.toFloat()
ValueAnimator.ofFloat(
if (Preferences.showClock) 0f else 1f,
if (Preferences.showClock) 1f else 0f
).apply {
this.duration = 500L
addUpdateListener {
val animatedValue = animatedValue as Float
binding.preview.layoutParams = binding.preview.layoutParams.apply {
height = (PREVIEW_BASE_HEIGHT.toPixel(requireContext()) + 100.toPixel(requireContext()) * animatedValue).toInt()
}
binding.widgetDetail.timeContainer.layoutParams = binding.widgetDetail.timeContainer.layoutParams.apply {
height = (clockInitialHeight * animatedValue).toInt()
}
binding.widgetDetail.timeContainer.translationY = (clockInitialHeight * animatedValue - clockInitialHeight)
binding.widgetDetail.timeContainer.alpha = animatedValue
}
}.start()
}
override fun onResume() {

View File

@ -85,7 +85,7 @@ class CalendarFragment : Fragment() {
viewModel: MainViewModel
) {
binding.isCalendarEnabled = Preferences.showEvents
binding.isDiffEnabled = Preferences.showDiffTime || !Preferences.showEvents
binding.isDiffEnabled = Preferences.showDiffTime
viewModel.calendarAllDay.observe(viewLifecycleOwner) {
maintainScrollPosition {
@ -122,7 +122,6 @@ class CalendarFragment : Fragment() {
maintainScrollPosition {
binding.showUntilLabel.text = getString(SettingsStringHelper.getShowUntilString(it))
}
updateCalendar()
}
}
@ -136,7 +135,7 @@ class CalendarFragment : Fragment() {
it.displayName,
it.accountName
)
}.sortedWith(Comparator { cal1, cal2 ->
}.sortedWith { cal1, cal2 ->
when {
cal1.accountName != cal2.accountName -> {
cal1.accountName.compareTo(cal2.accountName)
@ -151,7 +150,7 @@ class CalendarFragment : Fragment() {
cal1.name.compareTo(cal2.name)
}
}
})
}
if (calendarSelectorList.isNotEmpty()) {
val filteredCalendarIds = CalendarHelper.getFilteredCalendarIdList()
@ -271,6 +270,7 @@ class CalendarFragment : Fragment() {
}
dialog.addOnSelectItemListener { value ->
Preferences.showUntil = value
updateCalendar()
}.show()
}
}

View File

@ -13,10 +13,11 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.animation.AnimationUtils
import android.view.animation.LayoutAnimationController
import android.widget.ImageView
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
@ -45,8 +46,9 @@ import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
import com.tommasoberlose.anotherwidget.utils.convertDpToPixel
import com.tommasoberlose.anotherwidget.utils.expand
import com.tommasoberlose.anotherwidget.utils.reveal
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import net.idik.lib.slimadapter.SlimAdapter
@ -78,8 +80,6 @@ class GlanceTabFragment : Fragment() {
viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java)
binding = FragmentTabGlanceBinding.inflate(inflater)
subscribeUi(viewModel)
binding.lifecycleOwner = this
binding.viewModel = viewModel
@ -90,16 +90,12 @@ class GlanceTabFragment : Fragment() {
super.onActivityCreated(savedInstanceState)
// List
binding.providersList.setHasFixedSize(true)
binding.providersList.hasFixedSize()
val mLayoutManager = LinearLayoutManager(context)
binding.providersList.layoutManager = mLayoutManager
adapter = SlimAdapter.create()
adapter
.register<String>(R.layout.glance_providers_list_ornament) { item, injector ->
injector.visibility(R.id.footer, if(item == "footer") View.VISIBLE else View.GONE)
injector.visibility(R.id.header, if(item == "header") View.VISIBLE else View.GONE)
}
.register<GlanceProvider>(R.layout.glance_provider_item) { item, injector ->
val provider = Constants.GlanceProviderId.from(item.id)!!
injector
@ -130,9 +126,12 @@ class GlanceTabFragment : Fragment() {
MediaPlayerHelper.updatePlayingMediaInfo(requireContext())
injector.visibility(R.id.error_icon, View.GONE)
injector.visibility(R.id.info_icon, View.VISIBLE)
injector.text(R.id.label,
injector.text(
R.id.label,
if (Preferences.showMusic) getString(R.string.settings_visible) else getString(
R.string.settings_not_visible))
R.string.settings_not_visible
)
)
isVisible = Preferences.showMusic
}
Preferences.showMusic -> {
@ -150,26 +149,40 @@ class GlanceTabFragment : Fragment() {
}
}
Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> {
injector.text(R.id.label,
injector.text(
R.id.label,
if (Preferences.showNextAlarm && !AlarmHelper.isAlarmProbablyWrong(
requireContext())
requireContext()
)
) getString(R.string.settings_visible) else getString(
R.string.settings_not_visible))
injector.visibility(R.id.error_icon,
R.string.settings_not_visible
)
)
injector.visibility(
R.id.error_icon,
if (Preferences.showNextAlarm && AlarmHelper.isAlarmProbablyWrong(
requireContext())
) View.VISIBLE else View.GONE)
injector.visibility(R.id.info_icon,
requireContext()
)
) View.VISIBLE else View.GONE
)
injector.visibility(
R.id.info_icon,
if (!(Preferences.showNextAlarm && AlarmHelper.isAlarmProbablyWrong(
requireContext()))
) View.VISIBLE else View.GONE)
requireContext()
))
) View.VISIBLE else View.GONE
)
isVisible = !(Preferences.showNextAlarm && AlarmHelper.isAlarmProbablyWrong(
requireContext()))
requireContext()
))
}
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> {
injector.text(R.id.label,
injector.text(
R.id.label,
if (Preferences.showBatteryCharging) getString(R.string.settings_visible) else getString(
R.string.settings_not_visible))
R.string.settings_not_visible
)
)
injector.visibility(R.id.error_icon, View.GONE)
injector.visibility(R.id.info_icon, View.VISIBLE)
isVisible = Preferences.showBatteryCharging
@ -179,9 +192,12 @@ class GlanceTabFragment : Fragment() {
ActiveNotificationsHelper.checkNotificationAccess(requireContext()) -> {
injector.visibility(R.id.error_icon, View.GONE)
injector.visibility(R.id.info_icon, View.VISIBLE)
injector.text(R.id.label,
injector.text(
R.id.label,
if (Preferences.showNotifications) getString(
R.string.settings_visible) else getString(R.string.settings_not_visible))
R.string.settings_visible
) else getString(R.string.settings_not_visible)
)
isVisible = Preferences.showNotifications
}
Preferences.showNotifications -> {
@ -199,29 +215,44 @@ class GlanceTabFragment : Fragment() {
}
}
Constants.GlanceProviderId.GREETINGS -> {
injector.text(R.id.label,
injector.text(
R.id.label,
if (Preferences.showGreetings) getString(R.string.settings_visible) else getString(
R.string.settings_not_visible))
R.string.settings_not_visible
)
)
injector.visibility(R.id.error_icon, View.GONE)
injector.visibility(R.id.info_icon, View.VISIBLE)
isVisible = Preferences.showGreetings
}
Constants.GlanceProviderId.CUSTOM_INFO -> {
injector.text(R.id.label,
injector.text(
R.id.label,
if (Preferences.customNotes != "") getString(R.string.settings_visible) else getString(
R.string.settings_not_visible))
R.string.settings_not_visible
)
)
injector.visibility(R.id.error_icon, View.GONE)
injector.visibility(R.id.info_icon, View.VISIBLE)
isVisible = Preferences.customNotes != ""
}
Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> {
val account: GoogleSignInAccount? = GoogleSignIn.getLastSignedInAccount(context)
if (GoogleSignIn.hasPermissions(account, FITNESS_OPTIONS) && (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || requireActivity().checkGrantedPermission(
Manifest.permission.ACTIVITY_RECOGNITION))
val account: GoogleSignInAccount? = GoogleSignIn.getLastSignedInAccount(
context
)
if (GoogleSignIn.hasPermissions(
account,
FITNESS_OPTIONS
) && (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || requireActivity().checkGrantedPermission(
Manifest.permission.ACTIVITY_RECOGNITION
))
) {
injector.text(R.id.label,
injector.text(
R.id.label,
if (Preferences.showDailySteps) getString(R.string.settings_visible) else getString(
R.string.settings_not_visible))
R.string.settings_not_visible
)
)
injector.visibility(R.id.error_icon, View.GONE)
injector.visibility(R.id.info_icon, View.VISIBLE)
isVisible = Preferences.showDailySteps
@ -240,12 +271,24 @@ class GlanceTabFragment : Fragment() {
}
}
Constants.GlanceProviderId.EVENTS -> {
isVisible = Preferences.showEventsAsGlanceProvider && Preferences.showEvents && requireContext().checkGrantedPermission(Manifest.permission.READ_CALENDAR)
injector.text(R.id.label,
isVisible =
Preferences.showEventsAsGlanceProvider && Preferences.showEvents && requireContext().checkGrantedPermission(
Manifest.permission.READ_CALENDAR
)
injector.text(
R.id.label,
if (isVisible) getString(R.string.settings_visible) else getString(
R.string.settings_not_visible))
injector.visibility(R.id.error_icon, if (isVisible) View.GONE else View.VISIBLE)
injector.visibility(R.id.info_icon, if (isVisible) View.VISIBLE else View.GONE)
R.string.settings_not_visible
)
)
injector.visibility(
R.id.error_icon,
if (isVisible) View.GONE else View.VISIBLE
)
injector.visibility(
R.id.info_icon,
if (isVisible) View.VISIBLE else View.GONE
)
}
}
@ -300,7 +343,12 @@ class GlanceTabFragment : Fragment() {
GlanceProviderHelper.saveGlanceProviderOrder(
list
)
adapter.updateData(listOf("header") + list.mapNotNull { GlanceProviderHelper.getGlanceProviderById(requireContext(), it) } + listOf("footer"))
adapter.updateData(listOf("header") + list.mapNotNull {
GlanceProviderHelper.getGlanceProviderById(
requireContext(),
it
)
} + listOf("footer"))
}
override fun onChildDraw(
@ -315,23 +363,37 @@ class GlanceTabFragment : Fragment() {
val view = viewHolder.itemView as MaterialCardView
if (isCurrentlyActive) {
ViewCompat.setElevation(view, 8f.convertDpToPixel(requireContext()))
view.setCardBackgroundColor(ContextCompat.getColor(requireContext(),
R.color.cardBorder))
view.setCardBackgroundColor(
ContextCompat.getColor(
requireContext(),
R.color.cardBorder
)
)
} else {
ViewCompat.setElevation(view, 0f)
view.setCardBackgroundColor(ContextCompat.getColor(requireContext(),
R.color.colorPrimary))
view.setCardBackgroundColor(
ContextCompat.getColor(
requireContext(),
R.color.colorPrimary
)
)
}
val topEdge = if ((view.top == 0 && dY < 0) || ((view.top + view.height >= recyclerView.height - 32f.convertDpToPixel(requireContext())) && dY > 0)) 0f else dY
val topEdge =
if ((view.top == 0 && dY < 0) || ((view.top + view.height >= recyclerView.height - 32f.convertDpToPixel(
requireContext()
)) && dY > 0)
) 0f else dY
super.onChildDraw(c,
super.onChildDraw(
c,
recyclerView,
viewHolder,
dX,
topEdge,
actionState,
isCurrentlyActive)
isCurrentlyActive
)
}
override fun onSwiped(
@ -343,7 +405,6 @@ class GlanceTabFragment : Fragment() {
})
mIth.attachToRecyclerView(binding.providersList)
binding.providersList.isNestedScrollingEnabled = false
setupListener()
@ -351,13 +412,16 @@ class GlanceTabFragment : Fragment() {
viewModel.fragmentScrollY.value = binding.scrollView.scrollY
}
adapter.updateData(listOf("header") + list.mapNotNull { GlanceProviderHelper.getGlanceProviderById(requireContext(), it) } + listOf("footer"))
}
private fun subscribeUi(
viewModel: MainViewModel,
) {
adapter.updateData(emptyList<Constants.GlanceProviderId>())
lifecycleScope.launchWhenResumed {
delay(800)
val l = list.mapNotNull { GlanceProviderHelper.getGlanceProviderById(
requireContext(),
it
) }
adapter.updateData(l)
binding.listContainer.expand()
}
}
private fun setupListener() {
@ -371,8 +435,10 @@ class GlanceTabFragment : Fragment() {
override fun onStart() {
super.onStart()
requireActivity().registerReceiver(nextAlarmChangeBroadcastReceiver,
IntentFilter(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED))
requireActivity().registerReceiver(
nextAlarmChangeBroadcastReceiver,
IntentFilter(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)
)
if (dialog != null) {
dialog?.show()
}
@ -403,13 +469,15 @@ class GlanceTabFragment : Fragment() {
2 -> {
try {
val account: GoogleSignInAccount? = GoogleSignIn.getSignedInAccountFromIntent(
data).getResult(ApiException::class.java)
data
).getResult(ApiException::class.java)
if (!GoogleSignIn.hasPermissions(account, FITNESS_OPTIONS)) {
GoogleSignIn.requestPermissions(
requireActivity(),
1,
account,
FITNESS_OPTIONS)
FITNESS_OPTIONS
)
} else {
adapter.notifyItemRangeChanged(0, adapter.data.size)
}
@ -425,18 +493,9 @@ class GlanceTabFragment : Fragment() {
}
}
private fun maintainScrollPosition(callback: () -> Unit) {
binding.scrollView.isScrollable = false
callback.invoke()
lifecycleScope.launch {
delay(200)
binding.scrollView.isScrollable = true
}
}
override fun onResume() {
super.onResume()
adapter.notifyItemRangeChanged(0, adapter.data?.size ?: 0)
adapter.notifyItemRangeChanged(1, adapter.data?.size ?: 0)
if (dialog != null) {
dialog?.show()
}

View File

@ -124,17 +124,6 @@ class LayoutFragment : Fragment() {
}
}
viewModel.backgroundCardColorDark.observe(viewLifecycleOwner) {
maintainScrollPosition {
if (Preferences.backgroundCardAlphaDark == "00") {
binding.backgroundColorLabel.text = getString(R.string.transparent)
} else {
binding.backgroundColorLabel.text =
"#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(requireActivity().isDarkTheme()))).toUpperCase()
}
}
}
viewModel.showDividers.observe(viewLifecycleOwner) {
maintainScrollPosition {
binding.showDividersLabel.text =

View File

@ -94,9 +94,6 @@ class PreferencesFragment : Fragment() {
viewModel.showWeather.observe(viewLifecycleOwner) {
checkWeatherProviderConfig()
}
viewModel.showClock.observe(viewLifecycleOwner) {
}
}
private fun setupListener() {
@ -115,9 +112,6 @@ class PreferencesFragment : Fragment() {
binding.showEventsSwitch.setOnCheckedChangeListener { _, enabled: Boolean ->
if (enabled) {
if (!requireActivity().checkGrantedPermission(Manifest.permission.READ_CALENDAR)) {
binding.showEventsSwitch.setCheckedImmediatelyNoEvent(false)
}
requireCalendarPermission()
} else {
Preferences.showEvents = enabled
@ -196,6 +190,11 @@ class PreferencesFragment : Fragment() {
binding.weatherProviderLocationError.text = Preferences.weatherProviderLocationError
}
override fun onResume() {
super.onResume()
binding.showEventsSwitch.setCheckedNoEvent(Preferences.showEvents && requireActivity().checkGrantedPermission(Manifest.permission.READ_CALENDAR))
}
private fun maintainScrollPosition(callback: () -> Unit) {
binding.scrollView.isScrollable = false
callback.invoke()

View File

@ -116,17 +116,6 @@ class TypographyFragment : Fragment() {
}
}
viewModel.textGlobalColorDark.observe(viewLifecycleOwner) {
maintainScrollPosition {
if (Preferences.textGlobalAlphaDark == "00") {
binding.fontColorLabelDark.text = getString(R.string.transparent)
} else {
binding.fontColorLabelDark.text =
"#%s".format(Integer.toHexString(ColorHelper.getFontColor(requireActivity().isDarkTheme()))).toUpperCase()
}
}
}
viewModel.textSecondaryColor.observe(viewLifecycleOwner) {
maintainScrollPosition {
if (Preferences.textSecondaryAlpha == "00") {
@ -138,20 +127,18 @@ class TypographyFragment : Fragment() {
}
}
viewModel.textSecondaryColorDark.observe(viewLifecycleOwner) {
viewModel.textShadow.observe(viewLifecycleOwner) {
maintainScrollPosition {
if (Preferences.textSecondaryAlphaDark == "00") {
binding.secondaryFontColorLabelDark.text = getString(R.string.transparent)
} else {
binding.secondaryFontColorLabelDark.text =
"#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(requireActivity().isDarkTheme()))).toUpperCase()
if (requireActivity().isDarkTheme()) {
binding.textShadowLabel.text =
getString(SettingsStringHelper.getTextShadowString(it))
}
}
}
viewModel.textShadow.observe(viewLifecycleOwner) {
maintainScrollPosition {
if (activity?.isDarkTheme() != true) {
if (!requireActivity().isDarkTheme()) {
binding.textShadowLabel.text =
getString(SettingsStringHelper.getTextShadowString(it))
}
@ -161,7 +148,7 @@ class TypographyFragment : Fragment() {
viewModel.textShadowDark.observe(viewLifecycleOwner) {
maintainScrollPosition {
if (requireActivity().isDarkTheme()) {
binding.textShadowLabelDark.text =
binding.textShadowLabel.text =
getString(SettingsStringHelper.getTextShadowString(it))
}
}

View File

@ -1,36 +1,40 @@
package com.tommasoberlose.anotherwidget.ui.viewmodels
import android.app.Application
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import androidx.core.os.ConfigurationCompat
import androidx.lifecycle.*
import com.chibatching.kotpref.livedata.asLiveData
import com.tommasoberlose.anotherwidget.R
import com.tommasoberlose.anotherwidget.global.Constants
import com.tommasoberlose.anotherwidget.global.Preferences
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.isColor
import com.tommasoberlose.anotherwidget.utils.isMetric
class MainViewModel : ViewModel() {
class MainViewModel(context: Application) : AndroidViewModel(context) {
// General Settings
val textGlobalColor = MediatorLiveData<Boolean>().apply {
addSource(Preferences.asLiveData(Preferences::textGlobalColor)) { value = true }
addSource(Preferences.asLiveData(Preferences::textGlobalAlpha)) { value = true }
addSource(Preferences.asLiveData(Preferences::textGlobalColorDark)) { value = true }
addSource(Preferences.asLiveData(Preferences::textGlobalAlphaDark)) { value = true }
}
val textSecondaryColor = MediatorLiveData<Boolean>().apply {
addSource(Preferences.asLiveData(Preferences::textSecondaryColor)) { value = true }
addSource(Preferences.asLiveData(Preferences::textSecondaryAlpha)) { value = true }
addSource(Preferences.asLiveData(Preferences::textSecondaryColorDark)) { value = true }
addSource(Preferences.asLiveData(Preferences::textSecondaryAlphaDark)) { value = true }
}
val backgroundCardColor = MediatorLiveData<Boolean>().apply {
addSource(Preferences.asLiveData(Preferences::backgroundCardColor)) { value = true }
addSource(Preferences.asLiveData(Preferences::backgroundCardAlpha)) { value = true }
}
val textGlobalColorDark = MediatorLiveData<Boolean>().apply {
addSource(Preferences.asLiveData(Preferences::textGlobalColorDark)) { value = true }
addSource(Preferences.asLiveData(Preferences::textGlobalAlphaDark)) { value = true }
}
val textSecondaryColorDark = MediatorLiveData<Boolean>().apply {
addSource(Preferences.asLiveData(Preferences::textSecondaryColorDark)) { value = true }
addSource(Preferences.asLiveData(Preferences::textSecondaryAlphaDark)) { value = true }
}
val backgroundCardColorDark = MediatorLiveData<Boolean>().apply {
addSource(Preferences.asLiveData(Preferences::backgroundCardColorDark)) { value = true }
addSource(Preferences.asLiveData(Preferences::backgroundCardAlphaDark)) { value = true }
}
val textMainSize = Preferences.asLiveData(Preferences::textMainSize)
val textSecondSize = Preferences.asLiveData(Preferences::textSecondSize)
val textShadow = Preferences.asLiveData(Preferences::textShadow)
@ -92,11 +96,11 @@ class MainViewModel : ViewModel() {
val showWallpaper = Preferences.asLiveData(Preferences::showWallpaper)
val showPreview = Preferences.asLiveData(Preferences::showPreview)
val installedIntegrations = Preferences.asLiveData(Preferences::installedIntegrations)
var colorClipboard: ArrayList<String> = ArrayList()
// UI
val fragmentScrollY = MutableLiveData<Int>()
val clockPreferencesUpdate = MediatorLiveData<Boolean>().apply {
addSource(Preferences.asLiveData(Preferences::showClock)) { value = true }
addSource(Preferences.asLiveData(Preferences::clockTextSize)) { value = true }
addSource(Preferences.asLiveData(Preferences::clockTextColor)) { value = true }
addSource(Preferences.asLiveData(Preferences::clockTextAlpha)) { value = true }
@ -130,14 +134,57 @@ class MainViewModel : ViewModel() {
addSource(Preferences.asLiveData(Preferences::secondRowInformation)) { value = true }
addSource(Preferences.asLiveData(Preferences::showDividers)) { value = true }
addSource(Preferences.asLiveData(Preferences::secondRowTopMargin)) { value = true }
addSource(Preferences.asLiveData(Preferences::isDateCapitalize)) { value = true }
addSource(Preferences.asLiveData(Preferences::isDateUppercase)) { value = true }
addSource(Preferences.asLiveData(Preferences::showEvents)) { value = true }
addSource(Preferences.asLiveData(Preferences::calendarAllDay)) { value = true }
addSource(Preferences.asLiveData(Preferences::showDiffTime)) { value = true }
addSource(Preferences.asLiveData(Preferences::showNextEvent)) { value = true }
addSource(Preferences.asLiveData(Preferences::showDeclinedEvents)) { value = true }
addSource(Preferences.asLiveData(Preferences::showInvitedEvents)) { value = true }
addSource(Preferences.asLiveData(Preferences::showAcceptedEvents)) { value = true }
addSource(Preferences.asLiveData(Preferences::showOnlyBusyEvents)) { value = true }
addSource(Preferences.asLiveData(Preferences::secondRowInformation)) { value = true }
addSource(Preferences.asLiveData(Preferences::showWeather)) { value = true }
addSource(Preferences.asLiveData(Preferences::weatherTempUnit)) { value = true }
addSource(Preferences.asLiveData(Preferences::weatherIconPack)) { value = true }
addSource(Preferences.asLiveData(Preferences::customLocationLat)) { value = true }
addSource(Preferences.asLiveData(Preferences::customLocationLon)) { value = true }
addSource(Preferences.asLiveData(Preferences::customLocationAdd)) { value = true }
addSource(Preferences.asLiveData(Preferences::showPreview)) { value = true }
addSource(Preferences.asLiveData(Preferences::enabledGlanceProviderOrder)) { value = true }
addSource(Preferences.asLiveData(Preferences::customNotes)) { value = true }
addSource(Preferences.asLiveData(Preferences::showNextAlarm)) { value = true }
addSource(Preferences.asLiveData(Preferences::showBatteryCharging)) { value = true }
addSource(Preferences.asLiveData(Preferences::showDailySteps)) { value = true }
addSource(Preferences.asLiveData(Preferences::showGreetings)) { value = true }
addSource(Preferences.asLiveData(Preferences::showNotifications)) { value = true }
addSource(Preferences.asLiveData(Preferences::showMusic)) { value = true }
addSource(Preferences.asLiveData(Preferences::mediaInfoFormat)) { value = true }
addSource(Preferences.asLiveData(Preferences::musicPlayersFilter)) { value = true }
addSource(Preferences.asLiveData(Preferences::appNotificationsFilter)) { value = true }
addSource(Preferences.asLiveData(Preferences::showEventsAsGlanceProvider)) { value = true }
addSource(Preferences.asLiveData(Preferences::installedIntegrations)) { value = true }
}
init {
with(context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager) {
if (hasPrimaryClip()) {
(0..primaryClip!!.itemCount).forEach {
try {
val color = primaryClip!!.getItemAt(it).text.toString()
if (color.isColor()) {
colorClipboard.add(color)
}
} catch (ex: Exception) {}
}
}
}
}
}

View File

@ -1,4 +1,4 @@
package com.tommasoberlose.anotherwidget.ui.viewmodels
package com.tommasoberlose.anotherwidget.ui.viewmodels.settings
import android.app.Application
import androidx.lifecycle.AndroidViewModel

View File

@ -1,4 +1,4 @@
package com.tommasoberlose.anotherwidget.ui.viewmodels
package com.tommasoberlose.anotherwidget.ui.viewmodels.settings
import android.app.Activity
import android.content.Context

View File

@ -1,4 +1,4 @@
package com.tommasoberlose.anotherwidget.ui.viewmodels
package com.tommasoberlose.anotherwidget.ui.viewmodels.tabs
import android.app.Application
import android.content.Intent

View File

@ -1,11 +1,9 @@
package com.tommasoberlose.anotherwidget.ui.viewmodels
package com.tommasoberlose.anotherwidget.ui.viewmodels.tabs
import android.app.Application
import android.content.Intent
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.util.Log
import androidx.lifecycle.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

View File

@ -1,4 +1,4 @@
package com.tommasoberlose.anotherwidget.ui.viewmodels
package com.tommasoberlose.anotherwidget.ui.viewmodels.tabs
import android.app.Application
import androidx.lifecycle.AndroidViewModel

View File

@ -1,4 +1,4 @@
package com.tommasoberlose.anotherwidget.ui.viewmodels
package com.tommasoberlose.anotherwidget.ui.viewmodels.tabs
import android.app.Application
import android.content.Intent

View File

@ -1,4 +1,4 @@
package com.tommasoberlose.anotherwidget.ui.viewmodels
package com.tommasoberlose.anotherwidget.ui.viewmodels.tabs
import android.app.Application
import android.content.pm.ApplicationInfo

View File

@ -1,11 +1,9 @@
package com.tommasoberlose.anotherwidget.ui.viewmodels
package com.tommasoberlose.anotherwidget.ui.viewmodels.tabs
import android.app.Application
import android.content.Intent
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.util.Log
import androidx.lifecycle.*
import com.chibatching.kotpref.livedata.asLiveData
import com.tommasoberlose.anotherwidget.global.Preferences

View File

@ -1,4 +1,4 @@
package com.tommasoberlose.anotherwidget.ui.viewmodels
package com.tommasoberlose.anotherwidget.ui.viewmodels.tabs
import android.app.Application
import androidx.lifecycle.AndroidViewModel