Feat: Added a toggle for sun set and sun rise info.

Signed-off-by: HeCodes2Much <wayne6324@gmail.com>
This commit is contained in:
HeCodes2Much
2024-06-17 13:50:11 +01:00
parent 7bb85c7cab
commit 0cb3aa6729
16 changed files with 14044 additions and 4658 deletions

View File

@@ -38,6 +38,10 @@ class PreferenceHelper @Inject constructor(@ApplicationContext context: Context)
get() = prefs.getBoolean(Constants.SHOW_WEATHER_WIDGET, false)
set(value) = prefs.edit().putBoolean(Constants.SHOW_WEATHER_WIDGET, value).apply()
var showWeatherWidgetSunSetRise: Boolean
get() = prefs.getBoolean(Constants.SHOW_WEATHER_WIDGET_SUN_SET_RISE, true)
set(value) = prefs.edit().putBoolean(Constants.SHOW_WEATHER_WIDGET_SUN_SET_RISE, value).apply()
var showBatteryWidget: Boolean
get() = prefs.getBoolean(Constants.SHOW_BATTERY_WIDGET, false)
set(value) = prefs.edit().putBoolean(Constants.SHOW_BATTERY_WIDGET, value).apply()

View File

@@ -279,6 +279,10 @@ class WidgetFragment : Fragment(),
weatherBatteryDrawable.setColor(preferenceHelper.widgetBackgroundColor)
}
if (preferenceHelper.showWeatherWidgetSunSetRise) {
binding.weatherSunsetSunrise.visibility = View.VISIBLE
}
binding.batteryLevel.setTextColor(preferenceHelper.widgetTextColor)
binding.batteryCount.setTextColor(preferenceHelper.widgetTextColor)
binding.chargingStatus.setTextColor(preferenceHelper.widgetTextColor)

View File

@@ -14,6 +14,7 @@ import androidx.navigation.NavController
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.github.droidworksstudio.common.hasInternetPermission
import com.github.droidworksstudio.launcher.R
import com.github.droidworksstudio.launcher.databinding.FragmentSettingsWidgetsBinding
import com.github.droidworksstudio.launcher.helper.AppHelper
@@ -74,12 +75,31 @@ class SettingsFragment : Fragment(),
private fun initializeInjectedDependencies() {
binding.nestScrollView.scrollEventListener = this
// Set initial values and listeners for switches
binding.weatherSwitchCompat.isChecked = preferenceHelper.showWeatherWidget
binding.batterySwitchCompat.isChecked = preferenceHelper.showBatteryWidget
binding.apply {
// Weather stuff here
weatherSwitchCompat.isChecked = preferenceHelper.showWeatherWidget
weatherSunsetSunriseSwitchCompat.isChecked = preferenceHelper.showWeatherWidgetSunSetRise
binding.weatherOrderControl.text = preferenceHelper.weatherOrderNumber.toString()
binding.batteryOrderControl.text = preferenceHelper.batteryOrderNumber.toString()
weatherOrderControl.text = preferenceHelper.weatherOrderNumber.toString()
if (!context.hasInternetPermission()) {
weatherSettings.visibility = View.GONE
}
val weatherVisibility = if (weatherSwitchCompat.isChecked) View.VISIBLE else View.GONE
weatherOrderMenu.visibility = weatherVisibility
weatherSunsetSunriseMenu.visibility = weatherVisibility
selectWeatherWidgetColor.visibility = View.GONE
// Battery stuff here
batterySwitchCompat.isChecked = preferenceHelper.showBatteryWidget
batteryOrderControl.text = preferenceHelper.batteryOrderNumber.toString()
val batteryVisibility = if (batterySwitchCompat.isChecked) View.VISIBLE else View.GONE
batteryOrderMenu.visibility = batteryVisibility
selectBatteryWidgetColor.visibility = View.GONE
}
}
private fun observeClickListener() {
@@ -107,10 +127,25 @@ class SettingsFragment : Fragment(),
private fun setupSwitchListeners() {
binding.weatherSwitchCompat.setOnCheckedChangeListener { _, isChecked ->
preferenceViewModel.setShowWeatherWidget(isChecked)
binding.apply {
val weatherVisibility = if (isChecked) View.VISIBLE else View.GONE
weatherOrderMenu.visibility = weatherVisibility
weatherSunsetSunriseMenu.visibility = weatherVisibility
selectWeatherWidgetColor.visibility = View.GONE
}
}
binding.weatherSunsetSunriseSwitchCompat.setOnCheckedChangeListener { _, isChecked ->
preferenceViewModel.setShowWeatherWidgetSunSetRise(isChecked)
}
binding.batterySwitchCompat.setOnCheckedChangeListener { _, isChecked ->
preferenceViewModel.setShowBatteryWidget(isChecked)
binding.apply {
val batteryVisibility = if (isChecked) View.VISIBLE else View.GONE
batteryOrderMenu.visibility = batteryVisibility
selectBatteryWidgetColor.visibility = View.GONE
}
}
}

View File

@@ -26,6 +26,7 @@ object Constants {
const val SHOW_STATUS_BAR = "SHOW_STATUS_BAR"
const val SHOW_WEATHER_WIDGET = "SHOW_WEATHER_WIDGET"
const val SHOW_WEATHER_WIDGET_SUN_SET_RISE = "SHOW_WEATHER_WIDGET_SUN_SET_RISE"
const val SHOW_BATTERY_WIDGET = "SHOW_BATTERY_WIDGET"
const val DATE_COLOR = "DATE_COLOR"

View File

@@ -19,6 +19,7 @@ class PreferenceViewModel @Inject constructor(
val showDailyWordLiveData: MutableLiveData<Boolean> = MutableLiveData()
val showBatteryLiveData: MutableLiveData<Boolean> = MutableLiveData()
private val showWeatherWidgetLiveData: MutableLiveData<Boolean> = MutableLiveData()
private val showWeatherWidgetSunSetRiseLiveData: MutableLiveData<Boolean> = MutableLiveData()
private val showBatteryWidgetLiveData: MutableLiveData<Boolean> = MutableLiveData()
private val showAppIconLiveData: MutableLiveData<Boolean> = MutableLiveData()
private val homeAppAlignmentLiveData: MutableLiveData<Int> = MutableLiveData()
@@ -96,6 +97,11 @@ class PreferenceViewModel @Inject constructor(
showWeatherWidgetLiveData.postValue(preferenceHelper.showWeatherWidget)
}
fun setShowWeatherWidgetSunSetRise(showWeatherSunSetRise: Boolean) {
preferenceHelper.showWeatherWidgetSunSetRise = showWeatherSunSetRise
showWeatherWidgetSunSetRiseLiveData.postValue(preferenceHelper.showWeatherWidgetSunSetRise)
}
fun setShowBatteryWidget(showBattery: Boolean) {
preferenceHelper.showBatteryWidget = showBattery
showBatteryWidgetLiveData.postValue(preferenceHelper.showBatteryWidget)

View File

@@ -42,6 +42,7 @@
style="@style/TextDefaultStyle" />
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/weather_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
@@ -51,7 +52,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="@string/widgets_settings_display_weather"
android:text="@string/widgets_settings_show_weather"
android:textSize="@dimen/text_super_large"
style="@style/TextDefaultStyle" />
@@ -88,6 +89,40 @@
</androidx.appcompat.widget.LinearLayoutCompat>
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/weather_sunset_sunrise_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:orientation="horizontal"
tools:ignore="MissingConstraints">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/weather_sunset_sunrise_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left|center"
android:text="@string/widgets_settings_show_weather_sun"
android:textSize="@dimen/text_large"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlHardcoded"
style="@style/TextDefaultStyle" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/weather_sunset_sunrise_switchCompat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="0.7"
android:scaleY="0.8"
android:thumb="@drawable/shape_switch_thumb"
app:track="@drawable/selector_switch"
tools:ignore="DuplicateSpeakableTextCheck,TouchTargetSizeCheck" />
</androidx.appcompat.widget.LinearLayoutCompat>
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/weather_order_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
@@ -145,6 +180,7 @@
</androidx.appcompat.widget.LinearLayoutCompat>
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/battery_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
@@ -154,7 +190,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="@string/widgets_settings_display_battery"
android:text="@string/widgets_settings_show_battery"
android:textSize="@dimen/text_super_large"
style="@style/TextDefaultStyle" />
@@ -191,6 +227,7 @@
</androidx.appcompat.widget.LinearLayoutCompat>
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/battery_order_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"

View File

@@ -162,13 +162,15 @@
<!-- Horizontal LinearLayout -->
<LinearLayout
android:id="@+id/weather_sunset_sunrise"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/weather_info"
android:layout_marginTop="22dp"
android:baselineAligned="false"
android:gravity="center_vertical"
android:orientation="horizontal">
android:orientation="horizontal"
android:visibility="gone">
<!-- Left Vertical LinearLayout -->
<LinearLayout

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -604,8 +604,9 @@
<string name="widgets_battery_voltage">Battery Voltage : %1$.2f %2$s</string>
<string name="widgets_battery_temperature">Battery Temperature : %1$.2f %2$s</string>
<string name="widgets_settings_display_weather">Weather Widget</string>
<string name="widgets_settings_display_battery">Battery Widget</string>
<string name="widgets_settings_show_weather">Weather Widget</string>
<string name="widgets_settings_show_weather_sun">Show Sunset &amp; Sunrise</string>
<string name="widgets_settings_show_battery">Battery Widget</string>
<string name="widgets_settings_display">Display</string>
<string name="widgets_settings_select_order">Select Order</string>