diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/global/Constants.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/global/Constants.kt index 600c093..b8b710c 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/global/Constants.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/global/Constants.kt @@ -15,6 +15,13 @@ object Constants { LARGE(3) } + enum class SecondRowTopMargin(val value: Int) { + NONE(0), + SMALL(1), + MEDIUM(2), + LARGE(3) + } + enum class GlanceProviderId(val id: String) { PLAYING_SONG("PLAYING_SONG"), NEXT_CLOCK_ALARM("NEXT_CLOCK_ALARM"), diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt index 3d59d32..02548fb 100755 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt @@ -65,6 +65,7 @@ object Preferences : KotprefModel() { var textSecondSize by floatPref(key = "PREF_TEXT_SECOND_SIZE", default = 18f) var clockTextSize by floatPref(key = "PREF_TEXT_CLOCK_SIZE", default = 90f) var clockBottomMargin by intPref(default = Constants.ClockBottomMargin.MEDIUM.value) + var secondRowTopMargin by intPref(default = Constants.SecondRowTopMargin.NONE.value) var showClock by booleanPref(key = "PREF_SHOW_CLOCK", default = false) var clockAppName by stringPref(key = "PREF_CLOCK_APP_NAME", default = "") var clockAppPackage by stringPref(key = "PREF_CLOCK_APP_PACKAGE", default = "") diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/GeneralTabFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/GeneralTabFragment.kt index 22274c0..0adc012 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/GeneralTabFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/GeneralTabFragment.kt @@ -17,6 +17,7 @@ import com.tommasoberlose.anotherwidget.R import com.tommasoberlose.anotherwidget.components.BottomSheetColorPicker import com.tommasoberlose.anotherwidget.components.BottomSheetMenu import com.tommasoberlose.anotherwidget.databinding.FragmentGeneralSettingsBinding +import com.tommasoberlose.anotherwidget.global.Constants import com.tommasoberlose.anotherwidget.global.Preferences import com.tommasoberlose.anotherwidget.global.RequestCode import com.tommasoberlose.anotherwidget.helpers.ColorHelper @@ -27,7 +28,9 @@ import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper import com.tommasoberlose.anotherwidget.ui.activities.CustomDateActivity import com.tommasoberlose.anotherwidget.ui.activities.MainActivity import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel +import kotlinx.android.synthetic.main.fragment_clock_settings.* import kotlinx.android.synthetic.main.fragment_general_settings.* +import kotlinx.android.synthetic.main.fragment_general_settings.scrollView import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.launch @@ -141,6 +144,17 @@ class GeneralTabFragment : Fragment() { } }) + viewModel.secondRowTopMargin.observe(viewLifecycleOwner, Observer { + maintainScrollPosition { + second_row_top_margin_label?.text = when (it) { + 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.LARGE.value -> getString(R.string.settings_clock_bottom_margin_subtitle_large) + else -> getString(R.string.settings_clock_bottom_margin_subtitle_medium) + } + } + }) + viewModel.backgroundCardColor.observe(viewLifecycleOwner, Observer { maintainScrollPosition { if (Preferences.backgroundCardAlpha == "00") { @@ -244,6 +258,32 @@ class GeneralTabFragment : Fragment() { ).show() } + action_second_row_top_margin_size.setOnClickListener { + BottomSheetMenu( + requireContext(), + header = getString(R.string.settings_secondary_row_top_margin_title) + ).setSelectedValue(Preferences.secondRowTopMargin) + .addItem( + getString(R.string.settings_clock_bottom_margin_subtitle_none), + Constants.SecondRowTopMargin.NONE.value + ) + .addItem( + getString(R.string.settings_clock_bottom_margin_subtitle_small), + Constants.SecondRowTopMargin.SMALL.value + ) + .addItem( + getString(R.string.settings_clock_bottom_margin_subtitle_medium), + Constants.SecondRowTopMargin.MEDIUM.value + ) + .addItem( + getString(R.string.settings_clock_bottom_margin_subtitle_large), + Constants.SecondRowTopMargin.LARGE.value + ) + .addOnSelectItemListener { value -> + Preferences.secondRowTopMargin = value + }.show() + } + action_date_format.setOnClickListener { val now = Calendar.getInstance() val dialog = BottomSheetMenu(requireContext(), header = getString(R.string.settings_date_format_title)).setSelectedValue(Preferences.dateFormat) 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 1d5d949..417c4f9 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 @@ -19,6 +19,7 @@ class MainViewModel : ViewModel() { val customFont = Preferences.asLiveData(Preferences::customFont) val secondRowInformation = Preferences.asLiveData(Preferences::secondRowInformation) val showDividers = Preferences.asLiveData(Preferences::showDividers) + val secondRowTopMargin = Preferences.asLiveData(Preferences::secondRowTopMargin) // Calendar Settings val showEvents = Preferences.asLiveData(Preferences::showEvents) diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/MainWidget.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/MainWidget.kt index 96cef1f..3cbbc86 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/MainWidget.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/MainWidget.kt @@ -261,7 +261,21 @@ class MainWidget : AppWidgetProvider() { views.setViewVisibility(R.id.empty_layout_rect, View.GONE) views.setViewVisibility(R.id.calendar_layout_rect, View.VISIBLE) + + views.setViewVisibility( + R.id.second_row_top_margin_small_sans, + if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.value) View.VISIBLE else View.GONE + ) + views.setViewVisibility( + R.id.second_row_top_margin_medium_sans, + if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.MEDIUM.value) View.VISIBLE else View.GONE + ) + views.setViewVisibility( + R.id.second_row_top_margin_large_sans, + if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.value) View.VISIBLE else View.GONE + ) } else if (GlanceProviderHelper.showGlanceProviders(context) && v.calendar_layout.isVisible) { + var showSomething = false loop@ for (provider:Constants.GlanceProviderId in GlanceProviderHelper.getGlanceProviders(context)) { when (provider) { Constants.GlanceProviderId.PLAYING_SONG -> { @@ -273,6 +287,7 @@ class MainWidget : AppWidgetProvider() { PendingIntent.FLAG_UPDATE_CURRENT ) views.setOnClickPendingIntent(R.id.second_row_rect, musicIntent) + showSomething = true break@loop } } @@ -285,6 +300,7 @@ class MainWidget : AppWidgetProvider() { PendingIntent.FLAG_UPDATE_CURRENT ) views.setOnClickPendingIntent(R.id.second_row_rect, alarmIntent) + showSomething = true break@loop } } @@ -299,6 +315,7 @@ class MainWidget : AppWidgetProvider() { PendingIntent.FLAG_UPDATE_CURRENT ) views.setOnClickPendingIntent(R.id.second_row_rect, batteryIntent) + showSomething = true break@loop } } @@ -317,26 +334,44 @@ class MainWidget : AppWidgetProvider() { PendingIntent.FLAG_UPDATE_CURRENT ) views.setOnClickPendingIntent(R.id.second_row_rect, fitIntent) + showSomething = true break@loop } } } } - views.setImageViewBitmap( - R.id.next_event_rect, - BitmapHelper.getBitmapFromView(v.next_event, draw = false) - ) - views.setImageViewBitmap( - R.id.second_row_rect, - BitmapHelper.getBitmapFromView(v.second_row, draw = false) - ) + if (showSomething) { + views.setImageViewBitmap( + R.id.next_event_rect, + BitmapHelper.getBitmapFromView(v.next_event, draw = false) + ) - views.setViewVisibility(R.id.second_row_rect, View.VISIBLE) - views.setViewVisibility(R.id.empty_layout_rect, View.GONE) - views.setViewVisibility(R.id.calendar_layout_rect, View.VISIBLE) - views.setOnClickPendingIntent(R.id.next_event_rect, calPIntent) + views.setImageViewBitmap( + R.id.second_row_rect, + BitmapHelper.getBitmapFromView(v.second_row, draw = false) + ) + + views.setViewVisibility(R.id.second_row_rect, View.VISIBLE) + views.setViewVisibility(R.id.empty_layout_rect, View.GONE) + views.setViewVisibility(R.id.calendar_layout_rect, View.VISIBLE) + views.setOnClickPendingIntent(R.id.next_event_rect, calPIntent) + + + views.setViewVisibility( + R.id.second_row_top_margin_small_sans, + if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.value) View.VISIBLE else View.GONE + ) + views.setViewVisibility( + R.id.second_row_top_margin_medium_sans, + if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.MEDIUM.value) View.VISIBLE else View.GONE + ) + views.setViewVisibility( + R.id.second_row_top_margin_large_sans, + if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.value) View.VISIBLE else View.GONE + ) + } } } catch (ex: Exception) { ex.printStackTrace() @@ -534,6 +569,10 @@ class MainWidget : AppWidgetProvider() { v.empty_layout.visibility = View.GONE v.calendar_layout.visibility = View.VISIBLE + + v.second_row_top_margin_small.visibility = if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.value) View.VISIBLE else View.GONE + v.second_row_top_margin_medium.visibility = if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.MEDIUM.value) View.VISIBLE else View.GONE + v.second_row_top_margin_large.visibility = if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.value) View.VISIBLE else View.GONE } else if (GlanceProviderHelper.showGlanceProviders(context)) { v.second_row_icon.isVisible = true var showSomething = false @@ -612,6 +651,10 @@ class MainWidget : AppWidgetProvider() { v.next_event.text = DateHelper.getDateText(context, now) v.empty_layout.visibility = View.GONE v.calendar_layout.visibility = View.VISIBLE + + v.second_row_top_margin_small.visibility = if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.value) View.VISIBLE else View.GONE + v.second_row_top_margin_medium.visibility = if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.MEDIUM.value) View.VISIBLE else View.GONE + v.second_row_top_margin_large.visibility = if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.value) View.VISIBLE else View.GONE } else { v.second_row_icon.isVisible = false } diff --git a/app/src/main/res/layout/fragment_general_settings.xml b/app/src/main/res/layout/fragment_general_settings.xml index f0fd63b..65526bc 100644 --- a/app/src/main/res/layout/fragment_general_settings.xml +++ b/app/src/main/res/layout/fragment_general_settings.xml @@ -227,6 +227,43 @@ style="@style/AnotherWidget.Settings.Subtitle"/> + + + + + + + + + + + + + Data maiuscola Formato data Sfondo widget + Margine Calendario diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dc9eded..5726c03 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -28,6 +28,7 @@ Capitalize the date Date format Widget background + Margin Calendar