|
|
|
@ -3,6 +3,7 @@ package org.tasks.preferences.fragments
|
|
|
|
|
import android.app.Activity.RESULT_OK
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.view.View
|
|
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
|
|
import androidx.preference.Preference
|
|
|
|
|
import com.google.ical.values.RRule
|
|
|
|
@ -16,8 +17,13 @@ import org.tasks.activities.ListPicker
|
|
|
|
|
import org.tasks.calendars.CalendarPicker
|
|
|
|
|
import org.tasks.calendars.CalendarPicker.newCalendarPicker
|
|
|
|
|
import org.tasks.calendars.CalendarProvider
|
|
|
|
|
import org.tasks.data.LocationDao
|
|
|
|
|
import org.tasks.data.Place
|
|
|
|
|
import org.tasks.injection.InjectingPreferenceFragment
|
|
|
|
|
import org.tasks.location.LocationPickerActivity
|
|
|
|
|
import org.tasks.location.LocationPickerActivity.Companion.EXTRA_PLACE
|
|
|
|
|
import org.tasks.preferences.DefaultFilterProvider
|
|
|
|
|
import org.tasks.preferences.IconPreference
|
|
|
|
|
import org.tasks.preferences.Preferences
|
|
|
|
|
import org.tasks.repeats.BasicRecurrenceDialog
|
|
|
|
|
import org.tasks.repeats.BasicRecurrenceDialog.EXTRA_RRULE
|
|
|
|
@ -36,6 +42,7 @@ class TaskDefaults : InjectingPreferenceFragment() {
|
|
|
|
|
@Inject lateinit var preferences: Preferences
|
|
|
|
|
@Inject lateinit var calendarProvider: CalendarProvider
|
|
|
|
|
@Inject lateinit var repeatRuleToString: RepeatRuleToString
|
|
|
|
|
@Inject lateinit var locationDao: LocationDao
|
|
|
|
|
|
|
|
|
|
private lateinit var defaultCalendarPref: Preference
|
|
|
|
|
|
|
|
|
@ -76,8 +83,19 @@ class TaskDefaults : InjectingPreferenceFragment() {
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val defaultLocation = findPreference(R.string.p_default_location) as IconPreference
|
|
|
|
|
defaultLocation
|
|
|
|
|
.setOnPreferenceClickListener {
|
|
|
|
|
startActivityForResult(
|
|
|
|
|
Intent(context, LocationPickerActivity::class.java),
|
|
|
|
|
REQUEST_LOCATION
|
|
|
|
|
)
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateRemoteListSummary()
|
|
|
|
|
updateRecurrence()
|
|
|
|
|
updateDefaultLocation()
|
|
|
|
|
|
|
|
|
|
requires(device.supportsGeofences(), R.string.p_default_location_reminder_key, R.string.p_default_location_radius)
|
|
|
|
|
}
|
|
|
|
@ -108,16 +126,26 @@ class TaskDefaults : InjectingPreferenceFragment() {
|
|
|
|
|
)
|
|
|
|
|
updateRecurrence()
|
|
|
|
|
}
|
|
|
|
|
} else if (requestCode == REQUEST_LOCATION) {
|
|
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
|
|
setDefaultLocation(data?.getParcelableExtra(EXTRA_PLACE))
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
super.onActivityResult(requestCode, resultCode, data)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun setDefaultLocation(place: Place?) {
|
|
|
|
|
preferences.setString(R.string.p_default_location, place?.uid)
|
|
|
|
|
updateDefaultLocation()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
|
super.onResume()
|
|
|
|
|
|
|
|
|
|
updateRemoteListSummary()
|
|
|
|
|
updateRecurrence()
|
|
|
|
|
updateDefaultLocation()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun getDefaultCalendarName(): String? {
|
|
|
|
@ -130,6 +158,24 @@ class TaskDefaults : InjectingPreferenceFragment() {
|
|
|
|
|
findPreference(R.string.p_default_list).summary = defaultFilter.listingTitle
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun updateDefaultLocation() = lifecycleScope.launch {
|
|
|
|
|
val place = preferences
|
|
|
|
|
.getStringValue(R.string.p_default_location)
|
|
|
|
|
?.let { locationDao.getByUid(it) }
|
|
|
|
|
val defaultLocation = findPreference(R.string.p_default_location) as IconPreference
|
|
|
|
|
if (place == null) {
|
|
|
|
|
defaultLocation.iconVisible = false
|
|
|
|
|
defaultLocation.summary = requireContext().getString(R.string.none)
|
|
|
|
|
} else {
|
|
|
|
|
defaultLocation.drawable =
|
|
|
|
|
context?.getDrawable(R.drawable.ic_outline_delete_24px)?.mutate()
|
|
|
|
|
defaultLocation.tint = context?.getColor(R.color.icon_tint_with_alpha)
|
|
|
|
|
defaultLocation.iconClickListener = View.OnClickListener { setDefaultLocation(null) }
|
|
|
|
|
defaultLocation.iconVisible = true
|
|
|
|
|
defaultLocation.summary = place.displayName
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun updateRecurrence() {
|
|
|
|
|
val rrule = preferences.getStringValue(R.string.p_default_recurrence)
|
|
|
|
|
findPreference(R.string.p_default_recurrence).summary =
|
|
|
|
@ -148,6 +194,7 @@ class TaskDefaults : InjectingPreferenceFragment() {
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
const val REQUEST_RECURRENCE = 10000
|
|
|
|
|
const val REQUEST_LOCATION = 10001
|
|
|
|
|
const val FRAG_TAG_BASIC_RECURRENCE = "frag_tag_basic_recurrence"
|
|
|
|
|
}
|
|
|
|
|
}
|