diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 80f4f6c..23d826d 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/app/build.gradle b/app/build.gradle index a087359..b7bf1c4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -94,7 +94,7 @@ dependencies { // Other implementation 'androidx.multidex:multidex:2.0.1' - implementation 'joda-time:joda-time:2.10.6' + implementation 'net.danlew:android.joda:2.10.9' implementation 'me.everything:providers-android:1.0.1' implementation 'com.github.warkiz.widget:indicatorseekbar:2.1.2' diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/AWApplication.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/AWApplication.kt index f91dd54..131cb83 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/AWApplication.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/AWApplication.kt @@ -8,6 +8,7 @@ import com.google.firebase.crashlytics.FirebaseCrashlytics import com.tommasoberlose.anotherwidget.global.Preferences import io.realm.Realm import io.realm.RealmConfiguration +import net.danlew.android.joda.JodaTimeAndroid class AWApplication : Application() { override fun onCreate() { diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/components/GlanceSettingsDialog.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/components/GlanceSettingsDialog.kt index d890407..dbdb44c 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/components/GlanceSettingsDialog.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/components/GlanceSettingsDialog.kt @@ -10,6 +10,7 @@ import android.os.Build import android.view.LayoutInflater import android.view.View import androidx.core.view.isVisible +import androidx.navigation.Navigation import com.google.android.gms.auth.api.signin.GoogleSignIn import com.google.android.gms.auth.api.signin.GoogleSignInAccount import com.google.android.gms.auth.api.signin.GoogleSignInOptions diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt index 0274521..7f32ba2 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt @@ -119,33 +119,43 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList binding.actionSettings.animate().alpha(if (!show) 1f else 0f).setDuration(200).translationX((if (!show) 0f else -4f).convertDpToPixel(requireContext())).start() binding.fragmentTitle.text = if (show) destination.label.toString() else getString(R.string.app_name) } + + binding.actionSettings.setOnClickListener { + Navigation.findNavController(it).navigate(R.id.action_appMainFragment_to_appSettingsFragment, null, null, FragmentNavigatorExtras( + binding.actionBack to "action_back" + )) + } } private var uiJob: Job? = null private fun updateUI() { + Log.d("ciao", "UPDATE UI") uiJob?.cancel() binding.preview.clearAnimation() binding.widgetDetail.timeContainer.clearAnimation() - binding.bottomPadding.isVisible = Preferences.showPreview if (Preferences.showPreview) { - binding.preview.setCardBackgroundColor( - ContextCompat.getColor( + lifecycleScope.launch(Dispatchers.IO) { + val bgColor: Int = ContextCompat.getColor( requireContext(), if (ColorHelper.getFontColor(requireActivity().isDarkTheme()) .isColorDark() ) android.R.color.white else R.color.colorAccent ) - ) - binding.widgetDetail.widgetShapeBackground.setImageDrawable( - BitmapHelper.getTintedDrawable( + + 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 @@ -269,18 +279,9 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList } } } else { - ValueAnimator.ofInt( - binding.preview.height, - 0 - ).apply { - duration = 300L - addUpdateListener { - val animatedValue = animatedValue as Int - val layoutParams = binding.preview.layoutParams - layoutParams.height = animatedValue - binding.preview.layoutParams = layoutParams - } - }.start() + binding.preview.layoutParams = binding.preview.layoutParams.apply { + height = 0 + } } } @@ -312,10 +313,7 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList metrics.widthPixels to (wallpaper.intrinsicHeight) * metrics.widthPixels / (wallpaper.intrinsicWidth) } - setMargins( - if (dimensions.first >= dimensions.second) (-80).toPixel( - requireContext()) else 0, - (-80).toPixel(requireContext()), 0, 0 + setMargins(0, (-80).toPixel(requireContext()), 0, 0 ) width = dimensions.first @@ -327,8 +325,8 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList } } - binding.actionSettings.setOnClickListener { - Navigation.findNavController(it).navigate(R.id.action_appMainFragment_to_appSettingsFragment) + viewModel.fragmentScrollY.observe(viewLifecycleOwner) { + binding.toolbar.cardElevation = if (it > 0) 24f else 0f } } @@ -362,7 +360,7 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList class ChangeTabEvent(val page: Int) @Subscribe(threadMode = ThreadMode.MAIN) - fun onMessageEvent(ignore: UpdateUiMessageEvent?) { + fun onMessageEvent(ignore: UpdateUiMessageEvent) { delayJob?.cancel() delayJob = lifecycleScope.launch(Dispatchers.IO) { delay(300) @@ -371,4 +369,10 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList } } } + + @Subscribe(threadMode = ThreadMode.MAIN) + fun onChangeTabEvent(ignore: ChangeTabEvent) { + val navHost = childFragmentManager.findFragmentById(R.id.settings_fragment) as? NavHostFragment? + navHost?.navController?.navigateUp() + } } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/SettingsFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/SettingsFragment.kt index e63eb7b..8e6b253 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/SettingsFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/SettingsFragment.kt @@ -86,6 +86,10 @@ class SettingsFragment : Fragment() { setupListener() binding.appVersion.text = "v%s (%s)".format(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE) + + binding.scrollView.viewTreeObserver.addOnScrollChangedListener { + binding.toolbar.cardElevation = if (binding.scrollView.scrollY > 0) 32f else 0f + } } private fun subscribeUi( diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/CalendarFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/CalendarFragment.kt index 6d76830..1ac70e9 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/CalendarFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/CalendarFragment.kt @@ -175,7 +175,7 @@ class CalendarFragment : Fragment() { updateCalendar() }.show() } else { - activity?.toast(getString(R.string.calendar_settings_list_error)) + requireActivity().toast(getString(R.string.calendar_settings_list_error)) } } @@ -275,7 +275,7 @@ class CalendarFragment : Fragment() { } private fun updateCalendar() { - if (activity?.checkGrantedPermission(Manifest.permission.READ_CALENDAR) == true) { + if (requireActivity().checkGrantedPermission(Manifest.permission.READ_CALENDAR)) { CalendarHelper.updateEventList(requireContext()) } } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/ClockFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/ClockFragment.kt index 02f4b24..a47c4de 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/ClockFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/ClockFragment.kt @@ -127,28 +127,6 @@ class ClockFragment : Fragment() { } } } - - viewModel.clockTextAlpha.observe(viewLifecycleOwner) { - maintainScrollPosition { - if (Preferences.clockTextAlpha == "00") { - binding.clockTextColorLabel.text = getString(R.string.transparent) - } else { - binding.clockTextColorLabel.text = - "#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase() - } - } - } - - viewModel.clockTextAlphaDark.observe(viewLifecycleOwner) { - maintainScrollPosition { - if (Preferences.clockTextAlphaDark == "00") { - binding.clockTextColorLabel.text = getString(R.string.transparent) - } else { - binding.clockTextColorLabel.text = - "#%s".format(Integer.toHexString(ColorHelper.getClockFontColor(activity?.isDarkTheme() == true))).toUpperCase() - } - } - } } private fun setupListener() { diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/GlanceTabFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/GlanceTabFragment.kt index f0b0913..380daf1 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/GlanceTabFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/GlanceTabFragment.kt @@ -312,13 +312,11 @@ class GlanceTabFragment : Fragment() { if (isCurrentlyActive) { ViewCompat.setElevation(view, 8f.convertDpToPixel(requireContext())) view.setCardBackgroundColor(ContextCompat.getColor(requireContext(), - R.color.colorPrimary)) - view.strokeWidth = 0 + R.color.cardBorder)) } else { ViewCompat.setElevation(view, 0f) view.setCardBackgroundColor(ContextCompat.getColor(requireContext(), - R.color.colorPrimaryDark)) - view.strokeWidth = 1 + 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 diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/LayoutFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/LayoutFragment.kt index 5ea1174..110719c 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/LayoutFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/LayoutFragment.kt @@ -62,7 +62,7 @@ class LayoutFragment : Fragment() { binding.lifecycleOwner = this binding.viewModel = viewModel - binding.isDarkModeEnabled = activity?.isDarkTheme() == true + binding.isDarkModeEnabled = requireActivity().isDarkTheme() return binding.root } @@ -119,7 +119,7 @@ class LayoutFragment : Fragment() { binding.backgroundColorLabel.text = getString(R.string.transparent) } else { binding.backgroundColorLabel.text = - "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase() + "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(requireActivity().isDarkTheme()))).toUpperCase() } } } @@ -130,29 +130,7 @@ class LayoutFragment : Fragment() { binding.backgroundColorLabel.text = getString(R.string.transparent) } else { binding.backgroundColorLabel.text = - "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase() - } - } - } - - viewModel.backgroundCardAlpha.observe(viewLifecycleOwner) { - maintainScrollPosition { - if (Preferences.backgroundCardAlpha == "00") { - binding.backgroundColorLabel.text = getString(R.string.transparent) - } else { - binding.backgroundColorLabel.text = - "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase() - } - } - } - - viewModel.backgroundCardAlphaDark.observe(viewLifecycleOwner) { - maintainScrollPosition { - if (Preferences.backgroundCardAlphaDark == "00") { - binding.backgroundColorLabel.text = getString(R.string.transparent) - } else { - binding.backgroundColorLabel.text = - "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(activity?.isDarkTheme() == true))).toUpperCase() + "#%s".format(Integer.toHexString(ColorHelper.getBackgroundColor(requireActivity().isDarkTheme()))).toUpperCase() } } } @@ -223,10 +201,10 @@ class LayoutFragment : Fragment() { BottomSheetColorPicker(requireContext(), colors = colors, header = getString(R.string.settings_background_color_title), - getSelected = { ColorHelper.getBackgroundColorRgb(activity?.isDarkTheme() == true) }, + getSelected = { ColorHelper.getBackgroundColorRgb(requireActivity().isDarkTheme()) }, onColorSelected = { color: Int -> val colorString = Integer.toHexString(color) - if (activity?.isDarkTheme() == true) { + if (requireActivity().isDarkTheme()) { Preferences.backgroundCardColorDark = "#" + if (colorString.length > 6) colorString.substring(2) else colorString } else { @@ -235,9 +213,9 @@ class LayoutFragment : Fragment() { } }, showAlphaSelector = true, - alpha = if (activity?.isDarkTheme() == true) Preferences.backgroundCardAlphaDark.toIntValue() else Preferences.backgroundCardAlpha.toIntValue(), + alpha = if (requireActivity().isDarkTheme()) Preferences.backgroundCardAlphaDark.toIntValue() else Preferences.backgroundCardAlpha.toIntValue(), onAlphaChangeListener = { alpha -> - if (activity?.isDarkTheme() == true) { + if (requireActivity().isDarkTheme()) { Preferences.backgroundCardAlphaDark = alpha.toHexValue() } else { Preferences.backgroundCardAlpha = alpha.toHexValue() diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/PreferencesFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/PreferencesFragment.kt index 0b21bc6..aa55c84 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/PreferencesFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/PreferencesFragment.kt @@ -66,6 +66,10 @@ class PreferencesFragment : Fragment() { setupListener() + binding.showEventsSwitch.setCheckedImmediatelyNoEvent(Preferences.showEvents) + binding.showWeatherSwitch.setCheckedImmediatelyNoEvent(Preferences.showWeather) + binding.showClockSwitch.setCheckedImmediatelyNoEvent(Preferences.showClock) + binding.scrollView.viewTreeObserver.addOnScrollChangedListener { viewModel.fragmentScrollY.value = binding.scrollView.scrollY } @@ -74,9 +78,6 @@ class PreferencesFragment : Fragment() { private fun subscribeUi( viewModel: MainViewModel ) { - binding.isCalendarEnabled = Preferences.showEvents - binding.isWeatherVisible = Preferences.showWeather - binding.isClockVisible = Preferences.showClock viewModel.showEvents.observe(viewLifecycleOwner) { maintainScrollPosition { diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/TypographyFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/TypographyFragment.kt index 4aa6b0d..b2c4e42 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/TypographyFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/TypographyFragment.kt @@ -111,7 +111,7 @@ class TypographyFragment : Fragment() { binding.fontColorLabel.text = getString(R.string.transparent) } else { binding.fontColorLabel.text = - "#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase() + "#%s".format(Integer.toHexString(ColorHelper.getFontColor(requireActivity().isDarkTheme()))).toUpperCase() } } } @@ -122,29 +122,7 @@ class TypographyFragment : Fragment() { binding.fontColorLabelDark.text = getString(R.string.transparent) } else { binding.fontColorLabelDark.text = - "#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase() - } - } - } - - viewModel.textGlobalAlpha.observe(viewLifecycleOwner) { - maintainScrollPosition { - if (Preferences.textGlobalAlpha == "00") { - binding.fontColorLabel.text = getString(R.string.transparent) - } else { - binding.fontColorLabel.text = - "#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase() - } - } - } - - viewModel.textGlobalAlphaDark.observe(viewLifecycleOwner) { - maintainScrollPosition { - if (Preferences.textGlobalAlphaDark == "00") { - binding.fontColorLabelDark.text = getString(R.string.transparent) - } else { - binding.fontColorLabelDark.text = - "#%s".format(Integer.toHexString(ColorHelper.getFontColor(activity?.isDarkTheme() == true))).toUpperCase() + "#%s".format(Integer.toHexString(ColorHelper.getFontColor(requireActivity().isDarkTheme()))).toUpperCase() } } } @@ -155,7 +133,7 @@ class TypographyFragment : Fragment() { binding.secondaryFontColorLabel.text = getString(R.string.transparent) } else { binding.secondaryFontColorLabel.text = - "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase() + "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(requireActivity().isDarkTheme()))).toUpperCase() } } } @@ -166,29 +144,7 @@ class TypographyFragment : Fragment() { binding.secondaryFontColorLabelDark.text = getString(R.string.transparent) } else { binding.secondaryFontColorLabelDark.text = - "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase() - } - } - } - - viewModel.textSecondaryAlpha.observe(viewLifecycleOwner) { - maintainScrollPosition { - if (Preferences.textSecondaryAlpha == "00") { - binding.secondaryFontColorLabel.text = getString(R.string.transparent) - } else { - binding.secondaryFontColorLabel.text = - "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase() - } - } - } - - viewModel.textSecondaryAlphaDark.observe(viewLifecycleOwner) { - maintainScrollPosition { - if (Preferences.textSecondaryAlphaDark == "00") { - binding.secondaryFontColorLabelDark.text = getString(R.string.transparent) - } else { - binding.secondaryFontColorLabelDark.text = - "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(activity?.isDarkTheme() == true))).toUpperCase() + "#%s".format(Integer.toHexString(ColorHelper.getSecondaryFontColor(requireActivity().isDarkTheme()))).toUpperCase() } } } @@ -204,38 +160,16 @@ class TypographyFragment : Fragment() { viewModel.textShadowDark.observe(viewLifecycleOwner) { maintainScrollPosition { - if (activity?.isDarkTheme() == true) { + if (requireActivity().isDarkTheme()) { binding.textShadowLabelDark.text = getString(SettingsStringHelper.getTextShadowString(it)) } } } - viewModel.customFont.observe(viewLifecycleOwner) { - maintainScrollPosition { - binding.customFontLabel.text = SettingsStringHelper.getCustomFontLabel(requireContext(), it) - MainWidget.updateWidget(requireContext()) - } - } - - viewModel.customFontFile.observe(viewLifecycleOwner) { + viewModel.font.observe(viewLifecycleOwner) { maintainScrollPosition { binding.customFontLabel.text = SettingsStringHelper.getCustomFontLabel(requireContext(), Preferences.customFont) - MainWidget.updateWidget(requireContext()) - } - } - - viewModel.customFontName.observe(viewLifecycleOwner) { - maintainScrollPosition { - binding.customFontLabel.text = SettingsStringHelper.getCustomFontLabel(requireContext(), Preferences.customFont) - MainWidget.updateWidget(requireContext()) - } - } - - viewModel.customFontVariant.observe(viewLifecycleOwner) { - maintainScrollPosition { - binding.customFontLabel.text = SettingsStringHelper.getCustomFontLabel(requireContext(), Preferences.customFont) - MainWidget.updateWidget(requireContext()) } } @@ -273,19 +207,19 @@ class TypographyFragment : Fragment() { BottomSheetColorPicker(requireContext(), colors = colors, header = getString(R.string.settings_font_color_title), - getSelected = { ColorHelper.getFontColorRgb(activity?.isDarkTheme() == true) }, + getSelected = { ColorHelper.getFontColorRgb(requireActivity().isDarkTheme()) }, onColorSelected = { color: Int -> val colorString = Integer.toHexString(color) - if (activity?.isDarkTheme() == true) { + if (requireActivity().isDarkTheme()) { Preferences.textGlobalColorDark = "#" + if (colorString.length > 6) colorString.substring(2) else colorString } else { Preferences.textGlobalColor = "#" + if (colorString.length > 6) colorString.substring(2) else colorString } }, showAlphaSelector = true, - alpha = if (activity?.isDarkTheme() == true) Preferences.textGlobalAlphaDark.toIntValue() else Preferences.textGlobalAlpha.toIntValue(), + alpha = if (requireActivity().isDarkTheme()) Preferences.textGlobalAlphaDark.toIntValue() else Preferences.textGlobalAlpha.toIntValue(), onAlphaChangeListener = { alpha -> - if (activity?.isDarkTheme() == true) { + if (requireActivity().isDarkTheme()) { Preferences.textGlobalAlphaDark = alpha.toHexValue() } else { Preferences.textGlobalAlpha = alpha.toHexValue() @@ -298,10 +232,10 @@ class TypographyFragment : Fragment() { BottomSheetColorPicker(requireContext(), colors = colors, header = getString(R.string.settings_secondary_font_color_title), - getSelected = { ColorHelper.getSecondaryFontColorRgb(activity?.isDarkTheme() == true) }, + getSelected = { ColorHelper.getSecondaryFontColorRgb(requireActivity().isDarkTheme()) }, onColorSelected = { color: Int -> val colorString = Integer.toHexString(color) - if (activity?.isDarkTheme() == true) { + if (requireActivity().isDarkTheme()) { Preferences.textSecondaryColorDark = "#" + if (colorString.length > 6) colorString.substring(2) else colorString } else { @@ -310,9 +244,9 @@ class TypographyFragment : Fragment() { } }, showAlphaSelector = true, - alpha = if (activity?.isDarkTheme() == true) Preferences.textSecondaryAlphaDark.toIntValue() else Preferences.textSecondaryAlpha.toIntValue(), + alpha = if (requireActivity().isDarkTheme()) Preferences.textSecondaryAlphaDark.toIntValue() else Preferences.textSecondaryAlpha.toIntValue(), onAlphaChangeListener = { alpha -> - if (activity?.isDarkTheme() == true) { + if (requireActivity().isDarkTheme()) { Preferences.textSecondaryAlphaDark = alpha.toHexValue() } else { Preferences.textSecondaryAlpha = alpha.toHexValue() @@ -322,12 +256,12 @@ class TypographyFragment : Fragment() { } binding.actionTextShadow.setOnClickListener { - val dialog = BottomSheetMenu(requireContext(), header = getString(R.string.title_text_shadow)).setSelectedValue(if (activity?.isDarkTheme() == true) Preferences.textShadowDark else Preferences.textShadow) + val dialog = BottomSheetMenu(requireContext(), header = getString(R.string.title_text_shadow)).setSelectedValue(if (requireActivity().isDarkTheme()) Preferences.textShadowDark else Preferences.textShadow) (2 downTo 0).forEach { dialog.addItem(getString(SettingsStringHelper.getTextShadowString(it)), it) } dialog.addOnSelectItemListener { value -> - if (activity?.isDarkTheme() == true) { + if (requireActivity().isDarkTheme()) { Preferences.textShadowDark = value } else { Preferences.textShadow = value diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/viewmodels/MainViewModel.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/viewmodels/MainViewModel.kt index 3833646..162f4e8 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/viewmodels/MainViewModel.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/viewmodels/MainViewModel.kt @@ -7,26 +7,41 @@ import com.tommasoberlose.anotherwidget.global.Preferences class MainViewModel : ViewModel() { // General Settings - val textGlobalColor = Preferences.asLiveData(Preferences::textGlobalColor) - val textGlobalAlpha = Preferences.asLiveData(Preferences::textGlobalAlpha) - val textSecondaryColor = Preferences.asLiveData(Preferences::textSecondaryColor) - val textSecondaryAlpha = Preferences.asLiveData(Preferences::textSecondaryAlpha) - val backgroundCardColor = Preferences.asLiveData(Preferences::backgroundCardColor) - val backgroundCardAlpha = Preferences.asLiveData(Preferences::backgroundCardAlpha) - val textGlobalColorDark = Preferences.asLiveData(Preferences::textGlobalColorDark) - val textGlobalAlphaDark = Preferences.asLiveData(Preferences::textGlobalAlphaDark) - val textSecondaryColorDark = Preferences.asLiveData(Preferences::textSecondaryColorDark) - val textSecondaryAlphaDark = Preferences.asLiveData(Preferences::textSecondaryAlphaDark) - val backgroundCardColorDark = Preferences.asLiveData(Preferences::backgroundCardColorDark) - val backgroundCardAlphaDark = Preferences.asLiveData(Preferences::backgroundCardAlphaDark) + val textGlobalColor = MediatorLiveData().apply { + addSource(Preferences.asLiveData(Preferences::textGlobalColor)) { value = true } + addSource(Preferences.asLiveData(Preferences::textGlobalAlpha)) { value = true } + } + val textSecondaryColor = MediatorLiveData().apply { + addSource(Preferences.asLiveData(Preferences::textSecondaryColor)) { value = true } + addSource(Preferences.asLiveData(Preferences::textSecondaryAlpha)) { value = true } + } + val backgroundCardColor = MediatorLiveData().apply { + addSource(Preferences.asLiveData(Preferences::backgroundCardColor)) { value = true } + addSource(Preferences.asLiveData(Preferences::backgroundCardAlpha)) { value = true } + } + val textGlobalColorDark = MediatorLiveData().apply { + addSource(Preferences.asLiveData(Preferences::textGlobalColorDark)) { value = true } + addSource(Preferences.asLiveData(Preferences::textGlobalAlphaDark)) { value = true } + } + val textSecondaryColorDark = MediatorLiveData().apply { + addSource(Preferences.asLiveData(Preferences::textSecondaryColorDark)) { value = true } + addSource(Preferences.asLiveData(Preferences::textSecondaryAlphaDark)) { value = true } + } + val backgroundCardColorDark = MediatorLiveData().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) val textShadowDark = Preferences.asLiveData(Preferences::textShadowDark) - val customFont = Preferences.asLiveData(Preferences::customFont) - val customFontFile = Preferences.asLiveData(Preferences::customFontFile) - val customFontName = Preferences.asLiveData(Preferences::customFontName) - val customFontVariant = Preferences.asLiveData(Preferences::customFontVariant) + val font = MediatorLiveData().apply { + addSource(Preferences.asLiveData(Preferences::customFont)) { value = true } + addSource(Preferences.asLiveData(Preferences::customFontFile)) { value = true } + addSource(Preferences.asLiveData(Preferences::customFontName)) { value = true } + addSource(Preferences.asLiveData(Preferences::customFontVariant)) { value = true } + } + val secondRowInformation = Preferences.asLiveData(Preferences::secondRowInformation) val showDividers = Preferences.asLiveData(Preferences::showDividers) val secondRowTopMargin = Preferences.asLiveData(Preferences::secondRowTopMargin) @@ -36,52 +51,42 @@ class MainViewModel : ViewModel() { val calendarAllDay = Preferences.asLiveData(Preferences::calendarAllDay) val showUntil = Preferences.asLiveData(Preferences::showUntil) val showDiffTime = Preferences.asLiveData(Preferences::showDiffTime) - val showDeclinedEvents = Preferences.asLiveData(Preferences::showDeclinedEvents) val showNextEvent = Preferences.asLiveData(Preferences::showNextEvent) val openEventDetails = Preferences.asLiveData(Preferences::openEventDetails) val calendarAppName = Preferences.asLiveData(Preferences::calendarAppName) val widgetUpdateFrequency = Preferences.asLiveData(Preferences::widgetUpdateFrequency) - val showOnlyBusyEvents = Preferences.asLiveData(Preferences::showOnlyBusyEvents) // Clock Settings val showClock = Preferences.asLiveData(Preferences::showClock) val clockTextSize = Preferences.asLiveData(Preferences::clockTextSize) - val clockTextColor = Preferences.asLiveData(Preferences::clockTextColor) - val clockTextAlpha = Preferences.asLiveData(Preferences::clockTextAlpha) - val clockTextColorDark = Preferences.asLiveData(Preferences::clockTextColorDark) - val clockTextAlphaDark = Preferences.asLiveData(Preferences::clockTextAlphaDark) + val clockTextColor = MediatorLiveData().apply { + addSource(Preferences.asLiveData(Preferences::clockTextColor)) { value = true } + addSource(Preferences.asLiveData(Preferences::clockTextAlpha)) { value = true } + } + val clockTextColorDark = MediatorLiveData().apply { + addSource(Preferences.asLiveData(Preferences::clockTextColorDark)) { value = true } + addSource(Preferences.asLiveData(Preferences::clockTextAlphaDark)) { value = true } + } val showAMPMIndicator = Preferences.asLiveData(Preferences::showAMPMIndicator) val clockAppName = Preferences.asLiveData(Preferences::clockAppName) val dateFormat = Preferences.asLiveData(Preferences::dateFormat) val clockBottomMargin = Preferences.asLiveData(Preferences::clockBottomMargin) - val showBigClockWarning = Preferences.asLiveData(Preferences::showBigClockWarning) - // Weather Settings val showWeather = Preferences.asLiveData(Preferences::showWeather) val weatherTempUnit = Preferences.asLiveData(Preferences::weatherTempUnit) val weatherRefreshPeriod = Preferences.asLiveData(Preferences::weatherRefreshPeriod) val weatherAppName = Preferences.asLiveData(Preferences::weatherAppName) - val weatherProviderApi = Preferences.asLiveData(Preferences::weatherProviderApiOpen) val customLocationAdd = Preferences.asLiveData(Preferences::customLocationAdd) - val showWeatherWarning = Preferences.asLiveData(Preferences::showWeatherWarning) val weatherIconPack = Preferences.asLiveData(Preferences::weatherIconPack) val weatherProvider = Preferences.asLiveData(Preferences::weatherProvider) val weatherProviderError = Preferences.asLiveData(Preferences::weatherProviderError) val weatherProviderLocationError = Preferences.asLiveData(Preferences::weatherProviderLocationError) - // Glance - val showMusic = Preferences.asLiveData(Preferences::showMusic) - val showNextAlarm = Preferences.asLiveData(Preferences::showNextAlarm) - val showBatteryCharging = Preferences.asLiveData(Preferences::showBatteryCharging) - val showDailySteps = Preferences.asLiveData(Preferences::showDailySteps) - val customInfo = Preferences.asLiveData(Preferences::customNotes) - val musicPlayersFilter = Preferences.asLiveData(Preferences::musicPlayersFilter) - // Advanced Settings val darkThemePreference = Preferences.asLiveData(Preferences::darkThemePreference) val showWallpaper = Preferences.asLiveData(Preferences::showWallpaper) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 4fe9c23..bf6c9a0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -4,13 +4,13 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="?android:attr/colorPrimaryDark" + android:background="?android:attr/colorPrimary" tools:context=".ui.activities.MainActivity"> diff --git a/app/src/main/res/layout/fragment_app_main.xml b/app/src/main/res/layout/fragment_app_main.xml index 139b2a1..bbc7b41 100644 --- a/app/src/main/res/layout/fragment_app_main.xml +++ b/app/src/main/res/layout/fragment_app_main.xml @@ -11,7 +11,7 @@ android:layout_width="match_parent" android:layout_height="0dp" app:layout_constraintTop_toTopOf="parent" - app:cardElevation="4dp" + app:cardElevation="0dp" app:cardCornerRadius="0dp" android:id="@+id/toolbar" android:transitionName="toolbar" @@ -32,6 +32,7 @@ android:src="@drawable/round_arrow_back_24" android:clickable="true" android:focusable="true" + android:transitionName="action_back" android:background="?attr/selectableItemBackgroundBorderless" app:tint="@color/colorPrimaryText" android:layout_centerVertical="true" @@ -51,9 +52,9 @@ android:text="@string/app_name" android:gravity="center" android:textStyle="bold" - android:transitionName="title" android:id="@+id/fragment_title" - android:layout_marginBottom="1dp" + android:transitionName="fragment_title" + android:layout_marginBottom="6dp" style="@style/AnotherWidget.Main.Title"/> - + android:layout_height="56dp" + android:gravity="center_vertical"> @@ -56,13 +59,13 @@ android:layout_height="match_parent" android:id="@+id/scrollView" android:scrollbarThumbVertical="@color/colorPrimary" - android:background="@color/colorPrimaryDark"> + android:background="@color/colorPrimary"> + android:paddingBottom="48dp"> + android:label="@string/layout_settings_title" /> + android:label="@string/typography_settings_title" /> + android:label="@string/gestures_settings_title" /> \ No newline at end of file