Release v2.0.1
This commit is contained in:
@ -14,23 +14,21 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.karumi.dexter.Dexter
|
||||
import com.karumi.dexter.MultiplePermissionsReport
|
||||
import com.karumi.dexter.PermissionToken
|
||||
import com.karumi.dexter.listener.PermissionRequest
|
||||
import com.karumi.dexter.listener.multi.MultiplePermissionsListener
|
||||
import com.tommasoberlose.anotherwidget.BuildConfig
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
|
||||
import com.tommasoberlose.anotherwidget.databinding.FragmentAdvancedSettingsBinding
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
||||
import com.tommasoberlose.anotherwidget.receivers.WeatherReceiver
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.SupportDevActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||
import com.tommasoberlose.anotherwidget.utils.CalendarUtil
|
||||
import com.tommasoberlose.anotherwidget.utils.Util
|
||||
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
import com.tommasoberlose.anotherwidget.utils.openURI
|
||||
import kotlinx.android.synthetic.main.fragment_advanced_settings.*
|
||||
import kotlinx.coroutines.delay
|
||||
@ -57,7 +55,7 @@ class AdvancedSettingsFragment : Fragment() {
|
||||
viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java)
|
||||
val binding = DataBindingUtil.inflate<FragmentAdvancedSettingsBinding>(inflater, R.layout.fragment_advanced_settings, container, false)
|
||||
|
||||
subscribeUi(binding, viewModel)
|
||||
subscribeUi(viewModel)
|
||||
|
||||
binding.lifecycleOwner = this
|
||||
binding.viewModel = viewModel
|
||||
@ -69,10 +67,11 @@ class AdvancedSettingsFragment : Fragment() {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
|
||||
setupListener()
|
||||
|
||||
app_version.text = "v%s".format(BuildConfig.VERSION_NAME)
|
||||
}
|
||||
|
||||
private fun subscribeUi(
|
||||
binding: FragmentAdvancedSettingsBinding,
|
||||
viewModel: MainViewModel
|
||||
) {
|
||||
viewModel.darkThemePreference.observe(viewLifecycleOwner, Observer {
|
||||
@ -94,8 +93,8 @@ class AdvancedSettingsFragment : Fragment() {
|
||||
private fun setupListener() {
|
||||
action_change_theme.setOnClickListener {
|
||||
maintainScrollPosition {
|
||||
BottomSheetMenu<Int>(requireContext())
|
||||
.selectResource(Preferences.darkThemePreference)
|
||||
BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_theme_title))
|
||||
.setSelectedValue(Preferences.darkThemePreference)
|
||||
.addItem(
|
||||
getString(R.string.settings_subtitle_dark_theme_light),
|
||||
AppCompatDelegate.MODE_NIGHT_NO
|
||||
@ -116,11 +115,23 @@ class AdvancedSettingsFragment : Fragment() {
|
||||
|
||||
action_show_wallpaper.setOnClickListener {
|
||||
maintainScrollPosition {
|
||||
if (Preferences.showWallpaper) {
|
||||
Preferences.showWallpaper = false
|
||||
} else {
|
||||
requirePermission()
|
||||
}
|
||||
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_title_show_wallpaper))
|
||||
.setSelectedValue(Preferences.showWallpaper)
|
||||
.addItem(
|
||||
getString(R.string.settings_visible),
|
||||
true
|
||||
)
|
||||
.addItem(
|
||||
getString(R.string.settings_not_visible),
|
||||
false
|
||||
)
|
||||
.addOnSelectItemListener { value ->
|
||||
if (value) {
|
||||
requirePermission()
|
||||
} else {
|
||||
Preferences.showWallpaper = value
|
||||
}
|
||||
}.show()
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,8 +148,8 @@ class AdvancedSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
action_refresh_widget.setOnClickListener {
|
||||
Util.updateWidget(requireContext())
|
||||
CalendarUtil.updateEventList(requireContext())
|
||||
MainWidget.updateWidget(requireContext())
|
||||
CalendarHelper.updateEventList(requireContext())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,12 +4,11 @@ import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.SimpleAdapter
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.databinding.DataBindingUtil
|
||||
@ -25,7 +24,7 @@ import com.karumi.dexter.listener.PermissionRequest
|
||||
import com.karumi.dexter.listener.multi.MultiplePermissionsListener
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
|
||||
import com.tommasoberlose.anotherwidget.components.CalendarSelector
|
||||
import com.tommasoberlose.anotherwidget.models.CalendarSelector
|
||||
import com.tommasoberlose.anotherwidget.databinding.FragmentCalendarSettingsBinding
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
@ -33,16 +32,19 @@ import com.tommasoberlose.anotherwidget.global.RequestCode
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.ChooseApplicationActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||
import com.tommasoberlose.anotherwidget.utils.CalendarUtil
|
||||
import com.tommasoberlose.anotherwidget.utils.Util
|
||||
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.DateHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.CustomDateActivity
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
import com.tommasoberlose.anotherwidget.utils.toast
|
||||
import kotlinx.android.synthetic.main.fragment_calendar_settings.*
|
||||
import kotlinx.android.synthetic.main.fragment_calendar_settings.scrollView
|
||||
import kotlinx.android.synthetic.main.fragment_weather_settings.*
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import kotlin.Comparator
|
||||
|
||||
class CalendarSettingsFragment : Fragment() {
|
||||
|
||||
@ -85,6 +87,12 @@ class CalendarSettingsFragment : Fragment() {
|
||||
viewModel.showEvents.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
binding.isCalendarEnabled = it
|
||||
|
||||
if (it) {
|
||||
CalendarHelper.setEventUpdatesAndroidN(requireContext())
|
||||
} else {
|
||||
CalendarHelper.removeEventUpdatesAndroidN(requireContext())
|
||||
}
|
||||
}
|
||||
checkReadEventsPermission()
|
||||
})
|
||||
@ -106,7 +114,7 @@ class CalendarSettingsFragment : Fragment() {
|
||||
|
||||
viewModel.secondRowInformation.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
second_row_info_label.text = getString(Util.getSecondRowInfoString(it))
|
||||
second_row_info_label.text = getString(SettingsStringHelper.getSecondRowInfoString(it))
|
||||
}
|
||||
})
|
||||
|
||||
@ -118,23 +126,18 @@ class CalendarSettingsFragment : Fragment() {
|
||||
|
||||
viewModel.showUntil.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
show_until_label.text = getString(Util.getShowUntilString(it))
|
||||
show_until_label.text = getString(SettingsStringHelper.getShowUntilString(it))
|
||||
}
|
||||
checkReadEventsPermission()
|
||||
})
|
||||
|
||||
viewModel.showNextEvent.observe(viewLifecycleOwner, Observer {
|
||||
show_multiple_events_label.text = if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
|
||||
show_multiple_events_label.setTextKeepState(if (it) getString(R.string.settings_visible) else getString(R.string.settings_not_visible))
|
||||
})
|
||||
|
||||
viewModel.dateFormat.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
val now = Calendar.getInstance()
|
||||
var dateStringValue: String = String.format("%s%s", SimpleDateFormat(Constants.engDateFormat, Locale.getDefault()).format(now.time)[0].toUpperCase(), SimpleDateFormat(Constants.engDateFormat, Locale.getDefault()).format(now.time).substring(1))
|
||||
if (it) {
|
||||
dateStringValue = String.format("%s%s", SimpleDateFormat(Constants.itDateFormat, Locale.getDefault()).format(now.time)[0].toUpperCase(), SimpleDateFormat(Constants.itDateFormat, Locale.getDefault()).format(now.time).substring(1))
|
||||
}
|
||||
date_format_label.text = dateStringValue
|
||||
date_format_label.text = DateHelper.getDateText(requireContext(), Calendar.getInstance())
|
||||
}
|
||||
})
|
||||
|
||||
@ -159,26 +162,51 @@ class CalendarSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
action_filter_calendar.setOnClickListener {
|
||||
val calendarSelectorList: List<CalendarSelector> = CalendarUtil.getCalendarList(requireContext()).map { CalendarSelector(it.id.toInt(), it.displayName, it.accountName) }
|
||||
var calFiltered = Preferences.calendarFilter
|
||||
val calendarSelectorList: List<CalendarSelector> = CalendarHelper.getCalendarList(requireContext()).map {
|
||||
CalendarSelector(
|
||||
it.id,
|
||||
it.displayName,
|
||||
it.accountName
|
||||
)
|
||||
}.sortedWith(Comparator { cal1, cal2 ->
|
||||
when {
|
||||
cal1.accountName != cal2.accountName -> {
|
||||
cal1.accountName.compareTo(cal2.accountName)
|
||||
}
|
||||
cal1.accountName == cal1.name -> {
|
||||
-1
|
||||
}
|
||||
cal2.accountName == cal2.accountName -> {
|
||||
1
|
||||
}
|
||||
else -> {
|
||||
cal1.name.compareTo(cal2.name)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (calendarSelectorList.isNotEmpty()) {
|
||||
val calNames = calendarSelectorList.map { if (it.name == it.account_name) String.format("%s: %s", getString(R.string.main_calendar), it.name) else it.name }.toTypedArray()
|
||||
val calSelected = calendarSelectorList.map { !calFiltered.contains(" " + it.id.toString() + ",") }.toBooleanArray()
|
||||
val filteredCalendarIds = CalendarHelper.getFilteredCalendarIdList()
|
||||
val visibleCalendarIds = calendarSelectorList.map { it.id }.filter { id: Long -> !filteredCalendarIds.contains(id) }
|
||||
|
||||
AlertDialog.Builder(requireContext()).setTitle(getString(R.string.settings_filter_calendar_subtitle))
|
||||
.setMultiChoiceItems(calNames, calSelected) { _, item, isChecked ->
|
||||
val dialogItem: String = String.format(" %s%s", calendarSelectorList.get(item).id, ",")
|
||||
calFiltered = calFiltered.replace(dialogItem, "");
|
||||
if (!isChecked) {
|
||||
calFiltered += dialogItem
|
||||
}
|
||||
val dialog = BottomSheetMenu<Long>(requireContext(), header = getString(R.string.settings_filter_calendar_subtitle), isMultiSelection = true)
|
||||
.setSelectedValues(visibleCalendarIds)
|
||||
|
||||
calendarSelectorList.indices.forEach { index ->
|
||||
if (index == 0 || calendarSelectorList[index].accountName != calendarSelectorList[index - 1].accountName) {
|
||||
dialog.addItem(calendarSelectorList[index].accountName)
|
||||
}
|
||||
.setPositiveButton(android.R.string.ok) { _: DialogInterface, _: Int ->
|
||||
Preferences.calendarFilter = calFiltered
|
||||
}
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show()
|
||||
|
||||
dialog.addItem(
|
||||
if (calendarSelectorList[index].name == calendarSelectorList[index].accountName) getString(R.string.account_events) else calendarSelectorList[index].name,
|
||||
calendarSelectorList[index].id
|
||||
)
|
||||
}
|
||||
|
||||
dialog.addOnMultipleSelectItemListener { values ->
|
||||
CalendarHelper.filterCalendar(calendarSelectorList.map { it.id }.filter { !values.contains(it) })
|
||||
checkReadEventsPermission()
|
||||
}.show()
|
||||
} else {
|
||||
requireActivity().toast(getString(R.string.calendar_settings_list_error))
|
||||
}
|
||||
@ -186,7 +214,7 @@ class CalendarSettingsFragment : Fragment() {
|
||||
|
||||
action_show_all_day.setOnClickListener {
|
||||
if (Preferences.showEvents) {
|
||||
BottomSheetMenu<Boolean>(requireContext()).selectResource(Preferences.calendarAllDay)
|
||||
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_all_day_title)).setSelectedValue(Preferences.calendarAllDay)
|
||||
.addItem(getString(R.string.settings_all_day_subtitle_visible), true)
|
||||
.addItem(getString(R.string.settings_all_day_subtitle_gone), false)
|
||||
.addOnSelectItemListener { value ->
|
||||
@ -197,7 +225,7 @@ class CalendarSettingsFragment : Fragment() {
|
||||
|
||||
action_show_declined_events.setOnClickListener {
|
||||
if (Preferences.showEvents) {
|
||||
BottomSheetMenu<Boolean>(requireContext()).selectResource(Preferences.showDeclinedEvents)
|
||||
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_show_declined_events_title)).setSelectedValue(Preferences.showDeclinedEvents)
|
||||
.addItem(getString(R.string.settings_visible), true)
|
||||
.addItem(getString(R.string.settings_not_visible), false)
|
||||
.addOnSelectItemListener { value ->
|
||||
@ -208,7 +236,7 @@ class CalendarSettingsFragment : Fragment() {
|
||||
|
||||
action_show_multiple_events.setOnClickListener {
|
||||
if (Preferences.showEvents) {
|
||||
BottomSheetMenu<Boolean>(requireContext()).selectResource(Preferences.showNextEvent)
|
||||
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_show_multiple_events_title)).setSelectedValue(Preferences.showNextEvent)
|
||||
.addItem(getString(R.string.settings_visible), true)
|
||||
.addItem(getString(R.string.settings_not_visible), false)
|
||||
.addOnSelectItemListener { value ->
|
||||
@ -219,7 +247,7 @@ class CalendarSettingsFragment : Fragment() {
|
||||
|
||||
action_show_diff_time.setOnClickListener {
|
||||
if (Preferences.showEvents) {
|
||||
BottomSheetMenu<Boolean>(requireContext()).selectResource(Preferences.showDiffTime)
|
||||
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_show_diff_time_title)).setSelectedValue(Preferences.showDiffTime)
|
||||
.addItem(getString(R.string.settings_visible), true)
|
||||
.addItem(getString(R.string.settings_not_visible), false)
|
||||
.addOnSelectItemListener { value ->
|
||||
@ -230,9 +258,9 @@ class CalendarSettingsFragment : Fragment() {
|
||||
|
||||
action_second_row_info.setOnClickListener {
|
||||
if (Preferences.showEvents) {
|
||||
val dialog = BottomSheetMenu<Int>(requireContext()).selectResource(Preferences.secondRowInformation)
|
||||
val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_second_row_info_title)).setSelectedValue(Preferences.secondRowInformation)
|
||||
(0 .. 1).forEach {
|
||||
dialog.addItem(getString(Util.getSecondRowInfoString(it)), it)
|
||||
dialog.addItem(getString(SettingsStringHelper.getSecondRowInfoString(it)), it)
|
||||
}
|
||||
dialog.addOnSelectItemListener { value ->
|
||||
Preferences.secondRowInformation = value
|
||||
@ -242,9 +270,9 @@ class CalendarSettingsFragment : Fragment() {
|
||||
|
||||
action_show_until.setOnClickListener {
|
||||
if (Preferences.showEvents) {
|
||||
val dialog = BottomSheetMenu<Int>(requireContext()).selectResource(Preferences.showUntil)
|
||||
val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_show_until_title)).setSelectedValue(Preferences.showUntil)
|
||||
intArrayOf(6,7,0,1,2,3,4,5).forEach {
|
||||
dialog.addItem(getString(Util.getShowUntilString(it)), it)
|
||||
dialog.addItem(getString(SettingsStringHelper.getShowUntilString(it)), it)
|
||||
}
|
||||
dialog.addOnSelectItemListener { value ->
|
||||
Preferences.showUntil = value
|
||||
@ -252,6 +280,27 @@ class CalendarSettingsFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
action_date_format.setOnClickListener {
|
||||
if (Preferences.showEvents) {
|
||||
val now = Calendar.getInstance()
|
||||
val dialog = BottomSheetMenu<String>(requireContext(), header = getString(R.string.settings_date_format_title)).setSelectedValue(Preferences.dateFormat)
|
||||
|
||||
dialog.addItem(DateHelper.getDefaultDateText(requireContext(), now), "")
|
||||
if (Preferences.dateFormat != "") {
|
||||
dialog.addItem(DateHelper.getDateText(requireContext(), now), Preferences.dateFormat)
|
||||
}
|
||||
dialog.addItem(getString(R.string.custom_date_format), "-")
|
||||
|
||||
dialog.addOnSelectItemListener { value ->
|
||||
if (value == "-") {
|
||||
startActivity(Intent(requireActivity(), CustomDateActivity::class.java))
|
||||
} else {
|
||||
Preferences.dateFormat = value
|
||||
}
|
||||
}.show()
|
||||
}
|
||||
}
|
||||
|
||||
action_event_app.setOnClickListener {
|
||||
startActivityForResult(Intent(requireContext(), ChooseApplicationActivity::class.java), RequestCode.EVENT_APP_REQUEST_CODE.code)
|
||||
}
|
||||
@ -262,10 +311,10 @@ class CalendarSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun checkReadEventsPermission(showEvents: Boolean = Preferences.showEvents) {
|
||||
if (requireActivity().checkCallingOrSelfPermission(Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_GRANTED) {
|
||||
if (requireActivity().checkGrantedPermission(Manifest.permission.READ_CALENDAR)) {
|
||||
show_events_label.text = if (showEvents) getString(R.string.show_events_visible) else getString(R.string.show_events_not_visible)
|
||||
read_calendar_permission_alert_icon.isVisible = false
|
||||
CalendarUtil.updateEventList(requireContext())
|
||||
CalendarHelper.updateEventList(requireContext())
|
||||
} else {
|
||||
show_events_label.text = if (showEvents) getString(R.string.description_permission_calendar) else getString(R.string.show_events_not_visible)
|
||||
read_calendar_permission_alert_icon.isVisible = showEvents
|
||||
|
@ -3,10 +3,10 @@ package com.tommasoberlose.anotherwidget.ui.fragments
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Observer
|
||||
@ -15,7 +15,6 @@ import androidx.lifecycle.lifecycleScope
|
||||
import com.chibatching.kotpref.bulk
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.components.BottomSheetMenu
|
||||
import com.tommasoberlose.anotherwidget.databinding.FragmentCalendarSettingsBinding
|
||||
import com.tommasoberlose.anotherwidget.databinding.FragmentClockSettingsBinding
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
@ -23,8 +22,6 @@ import com.tommasoberlose.anotherwidget.global.RequestCode
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.ChooseApplicationActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||
import com.tommasoberlose.anotherwidget.utils.Util
|
||||
import com.tommasoberlose.anotherwidget.utils.toast
|
||||
import kotlinx.android.synthetic.main.fragment_clock_settings.*
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
@ -67,6 +64,11 @@ class ClockSettingsFragment : Fragment() {
|
||||
binding: FragmentClockSettingsBinding,
|
||||
viewModel: MainViewModel
|
||||
) {
|
||||
viewModel.showBigClockWarning.observe(viewLifecycleOwner, Observer {
|
||||
large_clock_warning.isVisible = it
|
||||
small_clock_warning.isVisible = !it
|
||||
})
|
||||
|
||||
viewModel.showClock.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
show_clock_label.text =
|
||||
@ -96,12 +98,16 @@ class ClockSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun setupListener() {
|
||||
action_hide_large_clock_warning.setOnClickListener {
|
||||
Preferences.showBigClockWarning = false
|
||||
}
|
||||
|
||||
action_show_clock.setOnClickListener {
|
||||
Preferences.showClock = !Preferences.showClock
|
||||
}
|
||||
|
||||
action_clock_text_size.setOnClickListener {
|
||||
val dialog = BottomSheetMenu<Float>(requireContext()).selectResource(Preferences.clockTextSize)
|
||||
val dialog = BottomSheetMenu<Float>(requireContext(), header = getString(R.string.settings_clock_text_size_title)).setSelectedValue(Preferences.clockTextSize)
|
||||
(46 downTo 28).filter { it % 2 == 0 }.forEach {
|
||||
dialog.addItem("${it}sp", it.toFloat())
|
||||
}
|
||||
@ -111,7 +117,7 @@ class ClockSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
action_show_next_alarm.setOnClickListener {
|
||||
BottomSheetMenu<Boolean>(requireContext()).selectResource(Preferences.showNextAlarm)
|
||||
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_show_next_alarm_title)).setSelectedValue(Preferences.showNextAlarm)
|
||||
.addItem(getString(R.string.settings_visible), true)
|
||||
.addItem(getString(R.string.settings_not_visible), false)
|
||||
.addOnSelectItemListener { value ->
|
||||
|
@ -13,20 +13,17 @@ import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
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.Preferences
|
||||
import com.tommasoberlose.anotherwidget.global.RequestCode
|
||||
import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||
import com.tommasoberlose.anotherwidget.utils.Util
|
||||
import com.tommasoberlose.anotherwidget.utils.toPixel
|
||||
import com.tommasoberlose.anotherwidget.utils.toast
|
||||
import dev.sasikanth.colorsheet.ColorSheet
|
||||
import kotlinx.android.synthetic.main.fragment_general_settings.*
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.*
|
||||
|
||||
|
||||
class GeneralSettingsFragment : Fragment() {
|
||||
@ -50,7 +47,7 @@ class GeneralSettingsFragment : Fragment() {
|
||||
viewModel = ViewModelProvider(activity as MainActivity).get(MainViewModel::class.java)
|
||||
val binding = DataBindingUtil.inflate<FragmentGeneralSettingsBinding>(inflater, R.layout.fragment_general_settings, container, false)
|
||||
|
||||
subscribeUi(binding, viewModel)
|
||||
subscribeUi(viewModel)
|
||||
|
||||
binding.lifecycleOwner = this
|
||||
binding.viewModel = viewModel
|
||||
@ -66,7 +63,6 @@ class GeneralSettingsFragment : Fragment() {
|
||||
|
||||
|
||||
private fun subscribeUi(
|
||||
binding: FragmentGeneralSettingsBinding,
|
||||
viewModel: MainViewModel
|
||||
) {
|
||||
|
||||
@ -95,13 +91,13 @@ class GeneralSettingsFragment : Fragment() {
|
||||
|
||||
viewModel.textShadow.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
text_shadow_label.text = getString(Util.getTextShadowString(it))
|
||||
text_shadow_label.text = getString(SettingsStringHelper.getTextShadowString(it))
|
||||
}
|
||||
})
|
||||
|
||||
viewModel.customFont.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
custom_font_label.text = getString(Util.getCustomFontLabel(it))
|
||||
custom_font_label.text = getString(SettingsStringHelper.getCustomFontLabel(it))
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -117,7 +113,7 @@ class GeneralSettingsFragment : Fragment() {
|
||||
|
||||
private fun setupListener() {
|
||||
action_main_text_size.setOnClickListener {
|
||||
val dialog = BottomSheetMenu<Float>(requireContext()).selectResource(Preferences.textMainSize)
|
||||
val dialog = BottomSheetMenu<Float>(requireContext(), header = getString(R.string.title_main_text_size)).setSelectedValue(Preferences.textMainSize)
|
||||
(32 downTo 20).filter { it % 2 == 0 }.forEach {
|
||||
dialog.addItem("${it}sp", it.toFloat())
|
||||
}
|
||||
@ -127,7 +123,7 @@ class GeneralSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
action_second_text_size.setOnClickListener {
|
||||
val dialog = BottomSheetMenu<Float>(requireContext()).selectResource(Preferences.textSecondSize)
|
||||
val dialog = BottomSheetMenu<Float>(requireContext(), header = getString(R.string.title_second_text_size)).setSelectedValue(Preferences.textSecondSize)
|
||||
(24 downTo 12).filter { it % 2 == 0 }.forEach {
|
||||
dialog.addItem("${it}sp", it.toFloat())
|
||||
}
|
||||
@ -143,21 +139,21 @@ class GeneralSettingsFragment : Fragment() {
|
||||
Preferences.textGlobalColor = "#FFFFFF"
|
||||
Color.parseColor(Preferences.textGlobalColor)
|
||||
}
|
||||
ColorSheet()
|
||||
.cornerRadius(16.toPixel(requireContext()))
|
||||
.colorPicker(
|
||||
BottomSheetColorPicker(requireContext(),
|
||||
colors = requireActivity().resources.getIntArray(R.array.grey),
|
||||
selectedColor = textColor,
|
||||
listener = { color ->
|
||||
Preferences.textGlobalColor = "#" + Integer.toHexString(color)
|
||||
})
|
||||
.show(requireActivity().supportFragmentManager)
|
||||
header = getString(R.string.settings_font_color_title),
|
||||
selected = textColor,
|
||||
onColorSelected = { color: Int ->
|
||||
val colorString = Integer.toHexString(color)
|
||||
Preferences.textGlobalColor = "#" + if (colorString.length > 6) colorString.substring(2) else colorString
|
||||
}
|
||||
).show()
|
||||
}
|
||||
|
||||
action_text_shadow.setOnClickListener {
|
||||
val dialog = BottomSheetMenu<Int>(requireContext()).selectResource(Preferences.textShadow)
|
||||
val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.title_text_shadow)).setSelectedValue(Preferences.textShadow)
|
||||
(2 downTo 0).forEach {
|
||||
dialog.addItem(getString(Util.getTextShadowString(it)), it)
|
||||
dialog.addItem(getString(SettingsStringHelper.getTextShadowString(it)), it)
|
||||
}
|
||||
dialog.addOnSelectItemListener { value ->
|
||||
Preferences.textShadow = value
|
||||
@ -165,9 +161,9 @@ class GeneralSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
action_custom_font.setOnClickListener {
|
||||
val dialog = BottomSheetMenu<Int>(requireContext()).selectResource(Preferences.customFont)
|
||||
val dialog = BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_custom_font_title)).setSelectedValue(Preferences.customFont)
|
||||
(0..1).forEach {
|
||||
dialog.addItem(getString(Util.getCustomFontLabel(it)), it)
|
||||
dialog.addItem(getString(SettingsStringHelper.getCustomFontLabel(it)), it)
|
||||
}
|
||||
dialog.addOnSelectItemListener { value ->
|
||||
Preferences.customFont = value
|
||||
|
@ -3,7 +3,6 @@ package com.tommasoberlose.anotherwidget.ui.fragments
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@ -26,13 +25,15 @@ import com.tommasoberlose.anotherwidget.databinding.FragmentWeatherSettingsBindi
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.global.RequestCode
|
||||
import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
|
||||
import com.tommasoberlose.anotherwidget.receivers.WeatherReceiver
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.ChooseApplicationActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.CustomLocationActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.WeatherProviderActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||
import com.tommasoberlose.anotherwidget.utils.Util
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
import kotlinx.android.synthetic.main.fragment_weather_settings.*
|
||||
import kotlinx.android.synthetic.main.fragment_weather_settings.scrollView
|
||||
import kotlinx.coroutines.delay
|
||||
@ -76,6 +77,10 @@ class WeatherSettingsFragment : Fragment() {
|
||||
binding: FragmentWeatherSettingsBinding,
|
||||
viewModel: MainViewModel
|
||||
) {
|
||||
viewModel.showWeatherWarning.observe(viewLifecycleOwner, Observer {
|
||||
weather_warning.isVisible = it
|
||||
})
|
||||
|
||||
viewModel.showWeather.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
show_weather_label.text =
|
||||
@ -113,7 +118,7 @@ class WeatherSettingsFragment : Fragment() {
|
||||
|
||||
viewModel.weatherRefreshPeriod.observe(viewLifecycleOwner, Observer {
|
||||
maintainScrollPosition {
|
||||
label_weather_refresh_period.text = getString(Util.getRefreshPeriodString(it))
|
||||
label_weather_refresh_period.text = getString(SettingsStringHelper.getRefreshPeriodString(it))
|
||||
}
|
||||
checkLocationPermission()
|
||||
})
|
||||
@ -127,7 +132,7 @@ class WeatherSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun checkLocationPermission() {
|
||||
if (requireActivity().checkCallingOrSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
|
||||
if (requireActivity().checkGrantedPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||
location_permission_alert_icon.isVisible = false
|
||||
WeatherReceiver.setUpdates(requireContext())
|
||||
} else if (Preferences.showWeather && Preferences.customLocationAdd == "") {
|
||||
@ -139,6 +144,9 @@ class WeatherSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun setupListener() {
|
||||
action_hide_weather_warning.setOnClickListener {
|
||||
Preferences.showWeatherWarning = false
|
||||
}
|
||||
|
||||
action_show_weather.setOnClickListener {
|
||||
Preferences.showWeather = !Preferences.showWeather
|
||||
@ -164,7 +172,7 @@ class WeatherSettingsFragment : Fragment() {
|
||||
|
||||
action_change_unit.setOnClickListener {
|
||||
if (Preferences.showWeather) {
|
||||
BottomSheetMenu<String>(requireContext()).selectResource(Preferences.weatherTempUnit)
|
||||
BottomSheetMenu<String>(requireContext(), header = getString(R.string.settings_unit_title)).setSelectedValue(Preferences.weatherTempUnit)
|
||||
.addItem(getString(R.string.fahrenheit), "F")
|
||||
.addItem(getString(R.string.celsius), "C")
|
||||
.addOnSelectItemListener { value ->
|
||||
@ -176,9 +184,9 @@ class WeatherSettingsFragment : Fragment() {
|
||||
action_weather_refresh_period.setOnClickListener {
|
||||
if (Preferences.showWeather) {
|
||||
val dialog =
|
||||
BottomSheetMenu<Int>(requireContext()).selectResource(Preferences.weatherRefreshPeriod)
|
||||
BottomSheetMenu<Int>(requireContext(), header = getString(R.string.settings_weather_refresh_period_title)).setSelectedValue(Preferences.weatherRefreshPeriod)
|
||||
(5 downTo 0).forEach {
|
||||
dialog.addItem(getString(Util.getRefreshPeriodString(it)), it)
|
||||
dialog.addItem(getString(SettingsStringHelper.getRefreshPeriodString(it)), it)
|
||||
}
|
||||
dialog
|
||||
.addOnSelectItemListener { value ->
|
||||
@ -202,13 +210,14 @@ class WeatherSettingsFragment : Fragment() {
|
||||
when (requestCode) {
|
||||
Constants.RESULT_CODE_CUSTOM_LOCATION -> {
|
||||
WeatherReceiver.setUpdates(requireContext())
|
||||
checkLocationPermission()
|
||||
}
|
||||
RequestCode.WEATHER_APP_REQUEST_CODE.code -> {
|
||||
Preferences.bulk {
|
||||
weatherAppName = data?.getStringExtra(Constants.RESULT_APP_NAME) ?: getString(R.string.default_weather_app)
|
||||
weatherAppPackage = data?.getStringExtra(Constants.RESULT_APP_PACKAGE) ?: ""
|
||||
}
|
||||
Util.updateWidget(requireContext())
|
||||
MainWidget.updateWidget(requireContext())
|
||||
}
|
||||
RequestCode.WEATHER_PROVIDER_REQUEST_CODE.code -> {
|
||||
WeatherReceiver.setOneTimeUpdate(requireContext())
|
||||
|
Reference in New Issue
Block a user