This commit is contained in:
Tommaso Berlose 2020-10-02 15:45:59 +02:00
parent 59dc5de21a
commit ca6fb75dfd
10 changed files with 179 additions and 12 deletions

View File

@ -15,6 +15,13 @@ object Constants {
LARGE(3) LARGE(3)
} }
enum class SecondRowTopMargin(val value: Int) {
NONE(0),
SMALL(1),
MEDIUM(2),
LARGE(3)
}
enum class GlanceProviderId(val id: String) { enum class GlanceProviderId(val id: String) {
PLAYING_SONG("PLAYING_SONG"), PLAYING_SONG("PLAYING_SONG"),
NEXT_CLOCK_ALARM("NEXT_CLOCK_ALARM"), NEXT_CLOCK_ALARM("NEXT_CLOCK_ALARM"),

View File

@ -65,6 +65,7 @@ object Preferences : KotprefModel() {
var textSecondSize by floatPref(key = "PREF_TEXT_SECOND_SIZE", default = 18f) var textSecondSize by floatPref(key = "PREF_TEXT_SECOND_SIZE", default = 18f)
var clockTextSize by floatPref(key = "PREF_TEXT_CLOCK_SIZE", default = 90f) var clockTextSize by floatPref(key = "PREF_TEXT_CLOCK_SIZE", default = 90f)
var clockBottomMargin by intPref(default = Constants.ClockBottomMargin.MEDIUM.value) 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 showClock by booleanPref(key = "PREF_SHOW_CLOCK", default = false)
var clockAppName by stringPref(key = "PREF_CLOCK_APP_NAME", default = "") var clockAppName by stringPref(key = "PREF_CLOCK_APP_NAME", default = "")
var clockAppPackage by stringPref(key = "PREF_CLOCK_APP_PACKAGE", default = "") var clockAppPackage by stringPref(key = "PREF_CLOCK_APP_PACKAGE", default = "")

View File

@ -17,6 +17,7 @@ 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.FragmentGeneralSettingsBinding
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
import com.tommasoberlose.anotherwidget.helpers.ColorHelper 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.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 kotlinx.android.synthetic.main.fragment_clock_settings.*
import kotlinx.android.synthetic.main.fragment_general_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.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch 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 { viewModel.backgroundCardColor.observe(viewLifecycleOwner, Observer {
maintainScrollPosition { maintainScrollPosition {
if (Preferences.backgroundCardAlpha == "00") { if (Preferences.backgroundCardAlpha == "00") {
@ -244,6 +258,32 @@ class GeneralTabFragment : Fragment() {
).show() ).show()
} }
action_second_row_top_margin_size.setOnClickListener {
BottomSheetMenu<Int>(
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 { action_date_format.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)

View File

@ -19,6 +19,7 @@ class MainViewModel : ViewModel() {
val customFont = Preferences.asLiveData(Preferences::customFont) val customFont = Preferences.asLiveData(Preferences::customFont)
val secondRowInformation = Preferences.asLiveData(Preferences::secondRowInformation) val secondRowInformation = Preferences.asLiveData(Preferences::secondRowInformation)
val showDividers = Preferences.asLiveData(Preferences::showDividers) val showDividers = Preferences.asLiveData(Preferences::showDividers)
val secondRowTopMargin = Preferences.asLiveData(Preferences::secondRowTopMargin)
// Calendar Settings // Calendar Settings
val showEvents = Preferences.asLiveData(Preferences::showEvents) val showEvents = Preferences.asLiveData(Preferences::showEvents)

View File

@ -261,7 +261,21 @@ class MainWidget : AppWidgetProvider() {
views.setViewVisibility(R.id.empty_layout_rect, View.GONE) views.setViewVisibility(R.id.empty_layout_rect, View.GONE)
views.setViewVisibility(R.id.calendar_layout_rect, View.VISIBLE) 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) { } else if (GlanceProviderHelper.showGlanceProviders(context) && v.calendar_layout.isVisible) {
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) {
Constants.GlanceProviderId.PLAYING_SONG -> { Constants.GlanceProviderId.PLAYING_SONG -> {
@ -273,6 +287,7 @@ class MainWidget : AppWidgetProvider() {
PendingIntent.FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT
) )
views.setOnClickPendingIntent(R.id.second_row_rect, musicIntent) views.setOnClickPendingIntent(R.id.second_row_rect, musicIntent)
showSomething = true
break@loop break@loop
} }
} }
@ -285,6 +300,7 @@ class MainWidget : AppWidgetProvider() {
PendingIntent.FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT
) )
views.setOnClickPendingIntent(R.id.second_row_rect, alarmIntent) views.setOnClickPendingIntent(R.id.second_row_rect, alarmIntent)
showSomething = true
break@loop break@loop
} }
} }
@ -299,6 +315,7 @@ class MainWidget : AppWidgetProvider() {
PendingIntent.FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT
) )
views.setOnClickPendingIntent(R.id.second_row_rect, batteryIntent) views.setOnClickPendingIntent(R.id.second_row_rect, batteryIntent)
showSomething = true
break@loop break@loop
} }
} }
@ -317,26 +334,44 @@ class MainWidget : AppWidgetProvider() {
PendingIntent.FLAG_UPDATE_CURRENT PendingIntent.FLAG_UPDATE_CURRENT
) )
views.setOnClickPendingIntent(R.id.second_row_rect, fitIntent) views.setOnClickPendingIntent(R.id.second_row_rect, fitIntent)
showSomething = true
break@loop break@loop
} }
} }
} }
} }
views.setImageViewBitmap(
R.id.next_event_rect,
BitmapHelper.getBitmapFromView(v.next_event, draw = false)
)
views.setImageViewBitmap( if (showSomething) {
R.id.second_row_rect, views.setImageViewBitmap(
BitmapHelper.getBitmapFromView(v.second_row, draw = false) R.id.next_event_rect,
) BitmapHelper.getBitmapFromView(v.next_event, draw = false)
)
views.setViewVisibility(R.id.second_row_rect, View.VISIBLE) views.setImageViewBitmap(
views.setViewVisibility(R.id.empty_layout_rect, View.GONE) R.id.second_row_rect,
views.setViewVisibility(R.id.calendar_layout_rect, View.VISIBLE) BitmapHelper.getBitmapFromView(v.second_row, draw = false)
views.setOnClickPendingIntent(R.id.next_event_rect, calPIntent) )
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) { } catch (ex: Exception) {
ex.printStackTrace() ex.printStackTrace()
@ -534,6 +569,10 @@ class MainWidget : AppWidgetProvider() {
v.empty_layout.visibility = View.GONE v.empty_layout.visibility = View.GONE
v.calendar_layout.visibility = View.VISIBLE 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)) { } else if (GlanceProviderHelper.showGlanceProviders(context)) {
v.second_row_icon.isVisible = true v.second_row_icon.isVisible = true
var showSomething = false var showSomething = false
@ -612,6 +651,10 @@ class MainWidget : AppWidgetProvider() {
v.next_event.text = DateHelper.getDateText(context, now) v.next_event.text = DateHelper.getDateText(context, now)
v.empty_layout.visibility = View.GONE v.empty_layout.visibility = View.GONE
v.calendar_layout.visibility = View.VISIBLE 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 { } else {
v.second_row_icon.isVisible = false v.second_row_icon.isVisible = false
} }

View File

@ -227,6 +227,43 @@
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:paddingTop="16dp"
android:paddingBottom="16dp"
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_second_row_top_margin_size"
android:orientation="horizontal">
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:padding="12dp"
android:src="@drawable/round_format_line_spacing"
app:tint="@color/colorPrimaryText"/>
<LinearLayout
android:layout_width="match_parent"
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_secondary_row_top_margin_title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/second_row_top_margin_label"
style="@style/AnotherWidget.Settings.Subtitle"/>
</LinearLayout>
</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"

View File

@ -133,6 +133,24 @@
android:id="@+id/special_temp"/> android:id="@+id/special_temp"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="4dp"
android:visibility="gone"
android:orientation="horizontal"
android:id="@+id/second_row_top_margin_small" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="8dp"
android:visibility="gone"
android:orientation="horizontal"
android:id="@+id/second_row_top_margin_medium" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="12dp"
android:visibility="gone"
android:orientation="horizontal"
android:id="@+id/second_row_top_margin_large" />
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -128,6 +128,24 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/special_weather_rect" /> android:id="@+id/special_weather_rect" />
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="4dp"
android:visibility="gone"
android:orientation="horizontal"
android:id="@+id/second_row_top_margin_small_sans" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="8dp"
android:visibility="gone"
android:orientation="horizontal"
android:id="@+id/second_row_top_margin_medium_sans" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="12dp"
android:visibility="gone"
android:orientation="horizontal"
android:id="@+id/second_row_top_margin_large_sans" />
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -26,6 +26,7 @@
<string name="action_capitalize_the_date">Data maiuscola</string> <string name="action_capitalize_the_date">Data maiuscola</string>
<string name="settings_date_format_title">Formato data</string> <string name="settings_date_format_title">Formato data</string>
<string name="header_widget_background">Sfondo widget</string> <string name="header_widget_background">Sfondo widget</string>
<string name="settings_secondary_row_top_margin_title">Margine</string>
<!-- Calendar --> <!-- Calendar -->
<string name="settings_calendar_title">Calendario</string> <string name="settings_calendar_title">Calendario</string>

View File

@ -28,6 +28,7 @@
<string name="action_capitalize_the_date">Capitalize the date</string> <string name="action_capitalize_the_date">Capitalize the date</string>
<string name="settings_date_format_title">Date format</string> <string name="settings_date_format_title">Date format</string>
<string name="header_widget_background">Widget background</string> <string name="header_widget_background">Widget background</string>
<string name="settings_secondary_row_top_margin_title">Margin</string>
<!-- Calendar --> <!-- Calendar -->
<string name="settings_calendar_title">Calendar</string> <string name="settings_calendar_title">Calendar</string>