Replace ListPicker with FilterPicker

Simplify fragment result listeners
pull/1962/head
Alex Baker 2 years ago
parent 5fca19e21f
commit bb9e2f90b4

@ -41,9 +41,7 @@ import com.google.android.material.appbar.AppBarLayout.Behavior.DragCallback
import com.google.android.material.composethemeadapter.MdcTheme
import com.todoroo.andlib.utility.AndroidUtilities
import com.todoroo.andlib.utility.DateUtilities
import com.todoroo.astrid.api.CaldavFilter
import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.api.GtasksFilter
import com.todoroo.astrid.dao.TaskDao
import com.todoroo.astrid.data.Task
import com.todoroo.astrid.files.FilesControlSet
@ -56,11 +54,11 @@ import com.todoroo.astrid.ui.StartDateControlSet
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.tasks.LocalBroadcastManager
import org.tasks.R
import org.tasks.Strings.isNullOrEmpty
import org.tasks.activities.ListPicker
import org.tasks.analytics.Firebase
import org.tasks.calendars.CalendarPicker
import org.tasks.compose.BeastModeBanner
@ -74,6 +72,8 @@ import org.tasks.databinding.*
import org.tasks.date.DateTimeUtils.newDateTime
import org.tasks.dialogs.DateTimePicker
import org.tasks.dialogs.DialogBuilder
import org.tasks.dialogs.FilterPicker.Companion.newFilterPicker
import org.tasks.dialogs.FilterPicker.Companion.setFilterPickerResultListener
import org.tasks.dialogs.Linkify
import org.tasks.files.FileHelper
import org.tasks.fragments.TaskEditControlSetFragmentManager
@ -237,6 +237,9 @@ class TaskEditFragment : Fragment(), Toolbar.OnMenuItemClickListener {
}
}
}
childFragmentManager.setFilterPickerResultListener(this) {
editViewModel.selectedList.update { it }
}
return view
}
@ -373,17 +376,6 @@ class TaskEditFragment : Fragment(), Toolbar.OnMenuItemClickListener {
editViewModel.setDueDate(data!!.getLongExtra(DateTimePicker.EXTRA_TIMESTAMP, 0L))
}
}
REQUEST_CODE_SELECT_LIST -> {
if (resultCode == Activity.RESULT_OK) {
data?.getParcelableExtra<Filter>(ListPicker.EXTRA_SELECTED_FILTER)?.let {
if (it is GtasksFilter || it is CaldavFilter) {
editViewModel.selectedList.value = it
} else {
throw RuntimeException("Unhandled filter type")
}
}
}
}
REQUEST_CODE_PICK_CALENDAR -> {
if (resultCode == Activity.RESULT_OK) {
editViewModel.selectedCalendar.value =
@ -458,14 +450,9 @@ class TaskEditFragment : Fragment(), Toolbar.OnMenuItemClickListener {
list = editViewModel.selectedList.collectAsStateLifecycleAware().value,
colorProvider = { chipProvider.getColor(it) },
onClick = {
ListPicker
.newListPicker(
editViewModel.selectedList.value,
this@TaskEditFragment,
REQUEST_CODE_SELECT_LIST
)
newFilterPicker(editViewModel.selectedList.value, true)
.show(
parentFragmentManager,
childFragmentManager,
FRAG_TAG_GOOGLE_TASK_LIST_SELECTION
)
}
@ -509,7 +496,6 @@ class TaskEditFragment : Fragment(), Toolbar.OnMenuItemClickListener {
private const val FRAG_TAG_GOOGLE_TASK_LIST_SELECTION = "frag_tag_google_task_list_selection"
const val FRAG_TAG_CALENDAR_PICKER = "frag_tag_calendar_picker"
private const val FRAG_TAG_DATE_PICKER = "frag_tag_date_picker"
private const val REQUEST_CODE_SELECT_LIST = 10101
const val REQUEST_CODE_PICK_CALENDAR = 70
private const val REQUEST_DATE = 504

@ -64,8 +64,10 @@ import org.tasks.LocalBroadcastManager
import org.tasks.R
import org.tasks.ShortcutManager
import org.tasks.Tasks.Companion.IS_GOOGLE_PLAY
import org.tasks.activities.*
import org.tasks.activities.ListPicker.Companion.newListPicker
import org.tasks.activities.FilterSettingsActivity
import org.tasks.activities.GoogleTaskListSettingsActivity
import org.tasks.activities.PlaceSettingsActivity
import org.tasks.activities.TagSettingsActivity
import org.tasks.analytics.Firebase
import org.tasks.billing.PurchaseActivity
import org.tasks.caldav.BaseCaldavCalendarSettingsActivity
@ -77,6 +79,8 @@ import org.tasks.databinding.FragmentTaskListBinding
import org.tasks.db.SuspendDbUtils.chunkedMap
import org.tasks.dialogs.DateTimePicker.Companion.newDateTimePicker
import org.tasks.dialogs.DialogBuilder
import org.tasks.dialogs.FilterPicker.Companion.newFilterPicker
import org.tasks.dialogs.FilterPicker.Companion.setFilterPickerResultListener
import org.tasks.dialogs.SortDialog
import org.tasks.extensions.Context.openUri
import org.tasks.extensions.Context.toast
@ -301,7 +305,13 @@ class TaskListFragment : Fragment(), OnRefreshListener, Toolbar.OnMenuItemClickL
toolbar.setOnMenuItemClickListener(this)
toolbar.setNavigationOnClickListener { callbacks.onNavigationIconClicked() }
setupMenu(toolbar)
childFragmentManager.setFilterPickerResultListener(this) {
val selected = taskAdapter.getSelected()
lifecycleScope.launch {
taskMover.move(selected, it)
}
finishActionMode()
}
return binding.root
}
@ -611,15 +621,6 @@ class TaskListFragment : Fragment(), OnRefreshListener, Toolbar.OnMenuItemClickL
}
}
}
REQUEST_MOVE_TASKS -> if (resultCode == Activity.RESULT_OK) {
data?.getParcelableExtra<Filter>(ListPicker.EXTRA_SELECTED_FILTER)?.let {
val selected = taskAdapter.getSelected()
lifecycleScope.launch {
taskMover.move(selected, it)
}
}
finishActionMode()
}
REQUEST_LIST_SETTINGS -> if (resultCode == Activity.RESULT_OK) {
val action = data!!.action
if (ACTION_DELETED == action) {
@ -718,12 +719,8 @@ class TaskListFragment : Fragment(), OnRefreshListener, Toolbar.OnMenuItemClickL
R.id.move_tasks -> {
lifecycleScope.launch {
val singleFilter = taskMover.getSingleFilter(selected)
val fragment = newListPicker(
selected = singleFilter,
targetFragment = this@TaskListFragment,
requestCode = REQUEST_MOVE_TASKS
)
fragment.show(parentFragmentManager, FRAG_TAG_REMOTE_LIST_PICKER)
newFilterPicker(singleFilter, true)
.show(childFragmentManager, FRAG_TAG_REMOTE_LIST_PICKER)
}
true
}
@ -979,7 +976,6 @@ class TaskListFragment : Fragment(), OnRefreshListener, Toolbar.OnMenuItemClickL
private const val FRAG_TAG_SORT_DIALOG = "frag_tag_sort_dialog"
private const val FRAG_TAG_DATE_TIME_PICKER = "frag_tag_date_time_picker"
private const val REQUEST_LIST_SETTINGS = 10101
private const val REQUEST_MOVE_TASKS = 10103
private const val REQUEST_TAG_TASKS = 10106
private const val SEARCH_DEBOUNCE_TIMEOUT = 300L
fun newTaskListFragment(context: Context, filter: Filter?): TaskListFragment {

@ -1,52 +0,0 @@
package org.tasks.activities
import android.app.Activity
import android.app.Dialog
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import com.todoroo.astrid.api.Filter
import dagger.hilt.android.AndroidEntryPoint
import org.tasks.R
import org.tasks.compose.pickers.ListPicker
import org.tasks.dialogs.DialogBuilder
import javax.inject.Inject
@AndroidEntryPoint
class ListPicker : DialogFragment() {
@Inject lateinit var dialogBuilder: DialogBuilder
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return dialogBuilder
.newDialog()
.setNegativeButton(R.string.cancel, null)
.setContent {
ListPicker(
selected = arguments?.getParcelable(EXTRA_SELECTED_FILTER),
onSelected = {
targetFragment!!.onActivityResult(
targetRequestCode,
Activity.RESULT_OK,
Intent().putExtra(EXTRA_SELECTED_FILTER, it)
)
dismiss()
},
)
}
.show()
}
companion object {
const val EXTRA_SELECTED_FILTER = "extra_selected_filter"
fun newListPicker(
selected: Filter?, targetFragment: Fragment?, requestCode: Int): ListPicker {
val dialog = ListPicker()
val arguments = Bundle()
arguments.putParcelable(EXTRA_SELECTED_FILTER, selected)
dialog.arguments = arguments
dialog.setTargetFragment(targetFragment, requestCode)
return dialog
}
}
}

@ -1,106 +0,0 @@
package org.tasks.activities
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.api.FilterListItem
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.tasks.LocalBroadcastManager
import org.tasks.R
import org.tasks.billing.Inventory
import org.tasks.data.CaldavDao
import org.tasks.data.GoogleTaskDao
import org.tasks.filters.FilterProvider
import org.tasks.filters.NavigationDrawerSubheader
import org.tasks.preferences.Preferences
import org.tasks.themes.ColorProvider
import org.tasks.themes.CustomIcons
import javax.inject.Inject
@HiltViewModel
class ListPickerViewModel @Inject constructor(
@ApplicationContext private val context: Context,
private val filterProvider: FilterProvider,
private val localBroadcastManager: LocalBroadcastManager,
private val inventory: Inventory,
private val colorProvider: ColorProvider,
private val preferences: Preferences,
private val googleTaskDao: GoogleTaskDao,
private val caldavDao: CaldavDao,
) : ViewModel() {
data class ViewState(
val filters: List<FilterListItem> = emptyList(),
)
private val refreshReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
refresh()
}
}
private val _viewState = MutableStateFlow(ViewState())
val viewState: StateFlow<ViewState>
get() = _viewState.asStateFlow()
fun onClick(subheader: NavigationDrawerSubheader) = viewModelScope.launch {
val collapsed = !subheader.isCollapsed
when (subheader.subheaderType) {
NavigationDrawerSubheader.SubheaderType.PREFERENCE ->
preferences.setBoolean(subheader.id.toInt(), collapsed)
NavigationDrawerSubheader.SubheaderType.GOOGLE_TASKS ->
googleTaskDao.setCollapsed(subheader.id, collapsed)
NavigationDrawerSubheader.SubheaderType.CALDAV,
NavigationDrawerSubheader.SubheaderType.TASKS,
NavigationDrawerSubheader.SubheaderType.ETESYNC ->
caldavDao.setCollapsed(subheader.id, collapsed)
}
localBroadcastManager.broadcastRefreshList()
}
private fun refresh() {
viewModelScope.launch {
val items = filterProvider.listPickerItems()
_viewState.update {
it.copy(filters = items)
}
}
}
fun getIcon(filter: Filter): Int {
if (filter.icon < 1000 || inventory.hasPro) {
val icon = CustomIcons.getIconResId(filter.icon)
if (icon != null) {
return icon
}
}
return R.drawable.ic_list_24px
}
fun getColor(filter: Filter): Int {
if (filter.tint != 0) {
val color = colorProvider.getThemeColor(filter.tint, true)
if (color.isFree || inventory.purchasedThemes()) {
return color.primaryColor
}
}
return context.getColor(R.color.text_primary)
}
override fun onCleared() {
localBroadcastManager.unregisterReceiver(refreshReceiver)
}
init {
localBroadcastManager.registerRefreshListReceiver(refreshReceiver)
refresh()
}
}

@ -20,8 +20,8 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.todoroo.astrid.api.Filter
import org.tasks.R
import org.tasks.activities.FilterPickerViewModel
import org.tasks.compose.collectAsStateLifecycleAware
import org.tasks.dialogs.FilterPickerViewModel
import org.tasks.filters.NavigationDrawerSubheader
@Composable

@ -1,82 +0,0 @@
package org.tasks.compose.pickers
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.ContentAlpha
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment.Companion.CenterVertically
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.todoroo.astrid.api.Filter
import org.tasks.R
import org.tasks.activities.ListPickerViewModel
import org.tasks.compose.collectAsStateLifecycleAware
import org.tasks.filters.NavigationDrawerSubheader
@Composable
fun ListPicker(
viewModel: ListPickerViewModel = viewModel(),
selected: Filter?,
onSelected: (Filter) -> Unit,
) {
val filters = viewModel.viewState.collectAsStateLifecycleAware().value.filters
Column(
modifier = Modifier
.verticalScroll(rememberScrollState())
.padding(vertical = 12.dp)
) {
filters.forEach { filter ->
when (filter) {
is NavigationDrawerSubheader -> {
CollapsibleRow(
text = filter.listingTitle,
collapsed = filter.isCollapsed,
onClick = { viewModel.onClick(filter) },
)
}
is Filter -> {
CheckableIconRow(
icon = painterResource(id = viewModel.getIcon(filter)),
tint = Color(viewModel.getColor(filter)),
selected = filter == selected,
onClick = { onSelected(filter) },
) {
Row(verticalAlignment = CenterVertically) {
Text(
text = filter.listingTitle,
style = MaterialTheme.typography.body2.copy(
fontWeight = FontWeight.Medium
),
modifier = Modifier.weight(1f),
)
if (filter.principals > 0) {
Icon(
painter = painterResource(
id = when (filter.principals) {
1 -> R.drawable.ic_outline_perm_identity_24px
in 2..Int.MAX_VALUE -> R.drawable.ic_outline_people_outline_24
else -> 0
}
),
modifier = Modifier.alpha(ContentAlpha.medium),
contentDescription = null,
)
}
}
}
}
}
}
}
}

@ -1,16 +1,17 @@
package org.tasks.activities
package org.tasks.dialogs
import android.app.Dialog
import android.content.DialogInterface
import android.os.Bundle
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.setFragmentResult
import androidx.lifecycle.LifecycleOwner
import com.todoroo.andlib.utility.AndroidUtilities
import com.todoroo.astrid.api.Filter
import dagger.hilt.android.AndroidEntryPoint
import org.tasks.R
import org.tasks.compose.pickers.FilterPicker
import org.tasks.dialogs.DialogBuilder
import javax.inject.Inject
@AndroidEntryPoint
@ -49,15 +50,27 @@ class FilterPicker : DialogFragment() {
const val SELECT_FILTER = "select_filter"
const val EXTRA_FILTER = "extra_filter"
const val EXTRA_FILTER_VALUES = "extra_filter_values"
const val EXTRA_LISTS_ONLY = "extra_lists_only"
fun newFilterPicker(
selected: Filter?,
listsOnly: Boolean = false,
): FilterPicker {
val dialog = FilterPicker()
val arguments = Bundle()
arguments.putParcelable(EXTRA_FILTER, selected)
arguments.putBoolean(EXTRA_LISTS_ONLY, listsOnly)
dialog.arguments = arguments
return dialog
}
fun FragmentManager.setFilterPickerResultListener(
lifecycleOwner: LifecycleOwner,
callback: (Filter) -> Unit
) {
setFragmentResultListener(SELECT_FILTER, lifecycleOwner) { _, data ->
data.getParcelable<Filter>(EXTRA_FILTER)?.let(callback)
}
}
}
}

@ -1,8 +1,9 @@
package org.tasks.activities
package org.tasks.dialogs
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.todoroo.astrid.api.Filter
@ -19,6 +20,7 @@ import org.tasks.R
import org.tasks.billing.Inventory
import org.tasks.data.CaldavDao
import org.tasks.data.GoogleTaskDao
import org.tasks.dialogs.FilterPicker.Companion.EXTRA_LISTS_ONLY
import org.tasks.filters.FilterProvider
import org.tasks.filters.NavigationDrawerSubheader
import org.tasks.preferences.Preferences
@ -28,6 +30,7 @@ import javax.inject.Inject
@HiltViewModel
class FilterPickerViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
@ApplicationContext private val context: Context,
private val filterProvider: FilterProvider,
private val localBroadcastManager: LocalBroadcastManager,
@ -37,6 +40,7 @@ class FilterPickerViewModel @Inject constructor(
private val googleTaskDao: GoogleTaskDao,
private val caldavDao: CaldavDao,
) : ViewModel() {
private val listsOnly = savedStateHandle[EXTRA_LISTS_ONLY] ?: false
data class ViewState(
val filters: List<FilterListItem> = emptyList(),
@ -53,7 +57,11 @@ class FilterPickerViewModel @Inject constructor(
}
private fun refresh() = viewModelScope.launch {
val items = filterProvider.filterPickerItems()
val items = if (listsOnly) {
filterProvider.listPickerItems()
} else {
filterProvider.filterPickerItems()
}
_viewState.update { it.copy(filters = items) }
}

@ -6,9 +6,8 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import org.tasks.LocalBroadcastManager
import org.tasks.R
import org.tasks.activities.FilterPicker
import org.tasks.activities.FilterPicker.Companion.SELECT_FILTER
import org.tasks.activities.FilterPicker.Companion.newFilterPicker
import org.tasks.dialogs.FilterPicker.Companion.newFilterPicker
import org.tasks.dialogs.FilterPicker.Companion.setFilterPickerResultListener
import org.tasks.injection.InjectingPreferenceFragment
import org.tasks.preferences.DefaultFilterProvider
import javax.inject.Inject
@ -23,11 +22,8 @@ class DashClock : InjectingPreferenceFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
childFragmentManager.setFragmentResultListener(
SELECT_FILTER,
this
) { _, data ->
defaultFilterProvider.dashclockFilter = data.getParcelable(FilterPicker.EXTRA_FILTER)!!
childFragmentManager.setFilterPickerResultListener(this) {
defaultFilterProvider.dashclockFilter = it
lifecycleScope.launch {
refreshPreferences()
}

@ -12,19 +12,18 @@ import androidx.appcompat.app.AppCompatDelegate
import androidx.core.os.LocaleListCompat
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import com.todoroo.astrid.api.Filter
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import org.tasks.LocalBroadcastManager
import org.tasks.R
import org.tasks.activities.FilterPicker
import org.tasks.activities.FilterPicker.Companion.newFilterPicker
import org.tasks.billing.Inventory
import org.tasks.billing.PurchaseActivity
import org.tasks.dialogs.ColorPalettePicker
import org.tasks.dialogs.ColorPalettePicker.Companion.newColorPalette
import org.tasks.dialogs.ColorPickerAdapter
import org.tasks.dialogs.ColorWheelPicker
import org.tasks.dialogs.FilterPicker.Companion.newFilterPicker
import org.tasks.dialogs.FilterPicker.Companion.setFilterPickerResultListener
import org.tasks.dialogs.ThemePickerDialog
import org.tasks.dialogs.ThemePickerDialog.Companion.newThemePickerDialog
import org.tasks.injection.InjectingPreferenceFragment
@ -57,13 +56,9 @@ class LookAndFeel : InjectingPreferenceFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
childFragmentManager.setFragmentResultListener(
FilterPicker.SELECT_FILTER,
this
) { _, data ->
val filter: Filter = data.getParcelable(FilterPicker.EXTRA_FILTER)!!
defaultFilterProvider.setDefaultOpenFilter(filter)
findPreference(R.string.p_default_open_filter).summary = filter.listingTitle
childFragmentManager.setFilterPickerResultListener(this) {
defaultFilterProvider.setDefaultOpenFilter(it)
findPreference(R.string.p_default_open_filter).summary = it.listingTitle
localBroadcastManager.broadcastRefresh()
}
}

@ -14,14 +14,13 @@ import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import androidx.preference.SwitchPreferenceCompat
import com.todoroo.andlib.utility.AndroidUtilities
import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.voice.VoiceOutputAssistant
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import org.tasks.LocalBroadcastManager
import org.tasks.R
import org.tasks.activities.FilterPicker
import org.tasks.activities.FilterPicker.Companion.newFilterPicker
import org.tasks.dialogs.FilterPicker.Companion.newFilterPicker
import org.tasks.dialogs.FilterPicker.Companion.setFilterPickerResultListener
import org.tasks.dialogs.MyTimePickerDialog.Companion.newTimePicker
import org.tasks.extensions.Context.getResourceUri
import org.tasks.injection.InjectingPreferenceFragment
@ -46,13 +45,9 @@ class Notifications : InjectingPreferenceFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
childFragmentManager.setFragmentResultListener(
FilterPicker.SELECT_FILTER,
this
) { _, data ->
val filter: Filter = data.getParcelable(FilterPicker.EXTRA_FILTER)!!
defaultFilterProvider.setBadgeFilter(filter)
findPreference(R.string.p_badge_list).summary = filter.listingTitle
childFragmentManager.setFilterPickerResultListener(this) {
defaultFilterProvider.setBadgeFilter(it)
findPreference(R.string.p_badge_list).summary = it.listingTitle
localBroadcastManager.broadcastRefresh()
}
}

@ -12,12 +12,12 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import org.tasks.LocalBroadcastManager
import org.tasks.R
import org.tasks.activities.FilterPicker
import org.tasks.activities.FilterPicker.Companion.newFilterPicker
import org.tasks.dialogs.ColorPalettePicker
import org.tasks.dialogs.ColorPalettePicker.Companion.newColorPalette
import org.tasks.dialogs.ColorPickerAdapter.Palette
import org.tasks.dialogs.ColorWheelPicker
import org.tasks.dialogs.FilterPicker.Companion.newFilterPicker
import org.tasks.dialogs.FilterPicker.Companion.setFilterPickerResultListener
import org.tasks.dialogs.SortDialog.newSortDialog
import org.tasks.dialogs.ThemePickerDialog.Companion.newThemePickerDialog
import org.tasks.injection.InjectingPreferenceFragment
@ -60,12 +60,8 @@ class ScrollableWidget : InjectingPreferenceFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
childFragmentManager.setFragmentResultListener(
FilterPicker.SELECT_FILTER,
this
) { _, data ->
val filter: Filter = data.getParcelable(FilterPicker.EXTRA_FILTER)!!
widgetPreferences.setFilter(defaultFilterProvider.getFilterPreferenceValue(filter))
childFragmentManager.setFilterPickerResultListener(this) {
widgetPreferences.setFilter(defaultFilterProvider.getFilterPreferenceValue(it))
updateFilter()
}
}

@ -6,16 +6,12 @@ import android.os.Bundle
import android.view.View
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import com.todoroo.astrid.api.CaldavFilter
import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.api.GtasksFilter
import com.todoroo.astrid.data.Task.Companion.NOTIFY_AFTER_DEADLINE
import com.todoroo.astrid.data.Task.Companion.NOTIFY_AT_DEADLINE
import com.todoroo.astrid.data.Task.Companion.NOTIFY_AT_START
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import org.tasks.R
import org.tasks.activities.ListPicker
import org.tasks.calendars.CalendarPicker
import org.tasks.calendars.CalendarPicker.Companion.newCalendarPicker
import org.tasks.calendars.CalendarProvider
@ -23,6 +19,8 @@ import org.tasks.data.LocationDao
import org.tasks.data.Place
import org.tasks.data.TagData
import org.tasks.data.TagDataDao
import org.tasks.dialogs.FilterPicker.Companion.newFilterPicker
import org.tasks.dialogs.FilterPicker.Companion.setFilterPickerResultListener
import org.tasks.injection.InjectingPreferenceFragment
import org.tasks.location.LocationPickerActivity
import org.tasks.location.LocationPickerActivity.Companion.EXTRA_PLACE
@ -38,7 +36,6 @@ import javax.inject.Inject
private const val FRAG_TAG_DEFAULT_LIST_SELECTION = "frag_tag_default_list_selection"
private const val FRAG_TAG_CALENDAR_PICKER = "frag_tag_calendar_picker"
private const val REQUEST_DEFAULT_LIST = 10010
private const val REQUEST_CALENDAR_SELECTION = 10011
@AndroidEntryPoint
@ -53,6 +50,14 @@ class TaskDefaults : InjectingPreferenceFragment() {
private lateinit var defaultCalendarPref: Preference
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
childFragmentManager.setFilterPickerResultListener(this) {
defaultFilterProvider.defaultList = it
updateRemoteListSummary()
}
}
override fun getPreferenceXml() = R.xml.preferences_task_defaults
override suspend fun setupPreferences(savedInstanceState: Bundle?) {
@ -67,11 +72,8 @@ class TaskDefaults : InjectingPreferenceFragment() {
findPreference(R.string.p_default_list)
.setOnPreferenceClickListener {
lifecycleScope.launch {
ListPicker.newListPicker(
defaultFilterProvider.getDefaultList(),
this@TaskDefaults,
REQUEST_DEFAULT_LIST)
.show(parentFragmentManager, FRAG_TAG_DEFAULT_LIST_SELECTION)
newFilterPicker(defaultFilterProvider.getDefaultList(), true)
.show(childFragmentManager, FRAG_TAG_DEFAULT_LIST_SELECTION)
}
false
}
@ -122,15 +124,6 @@ class TaskDefaults : InjectingPreferenceFragment() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
REQUEST_DEFAULT_LIST -> {
val list: Filter? = data!!.getParcelableExtra(ListPicker.EXTRA_SELECTED_FILTER)
if (list is GtasksFilter || list is CaldavFilter) {
defaultFilterProvider.defaultList = list
} else {
throw RuntimeException("Unhandled filter type")
}
updateRemoteListSummary()
}
REQUEST_CALENDAR_SELECTION -> if (resultCode == RESULT_OK) {
preferences.setString(
R.string.gcal_p_default,

@ -5,10 +5,10 @@ import android.os.Bundle
import com.todoroo.astrid.api.Filter
import dagger.hilt.android.AndroidEntryPoint
import org.tasks.R
import org.tasks.activities.FilterPicker
import org.tasks.activities.FilterPicker.Companion.newFilterPicker
import org.tasks.billing.Inventory
import org.tasks.billing.PurchaseActivity
import org.tasks.dialogs.FilterPicker.Companion.newFilterPicker
import org.tasks.dialogs.FilterPicker.Companion.setFilterPickerResultListener
import org.tasks.injection.InjectingPreferenceFragment
import org.tasks.locale.bundle.ListNotificationBundle
import org.tasks.preferences.DefaultFilterProvider
@ -41,11 +41,8 @@ class TaskerListNotification : InjectingPreferenceFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
childFragmentManager.setFragmentResultListener(
FilterPicker.SELECT_FILTER,
this
) { _, data ->
filter = data.getParcelable(FilterPicker.EXTRA_FILTER)!!
childFragmentManager.setFilterPickerResultListener(this) {
filter = it
refreshPreferences()
}
}

@ -13,12 +13,12 @@ import com.todoroo.astrid.api.Filter
import dagger.hilt.android.AndroidEntryPoint
import org.tasks.R
import org.tasks.Strings.isNullOrEmpty
import org.tasks.activities.FilterPicker
import org.tasks.activities.FilterPicker.Companion.newFilterPicker
import org.tasks.databinding.ActivityWidgetShortcutLayoutBinding
import org.tasks.dialogs.ColorPalettePicker
import org.tasks.dialogs.ColorPalettePicker.Companion.newColorPalette
import org.tasks.dialogs.ColorPickerAdapter.Palette
import org.tasks.dialogs.FilterPicker.Companion.newFilterPicker
import org.tasks.dialogs.FilterPicker.Companion.setFilterPickerResultListener
import org.tasks.injection.ThemedInjectingAppCompatActivity
import org.tasks.intents.TaskIntents
import org.tasks.preferences.DefaultFilterProvider
@ -67,14 +67,11 @@ class ShortcutConfigActivity : ThemedInjectingAppCompatActivity(), ColorPaletteP
}
updateFilterAndTheme()
supportFragmentManager.setFragmentResultListener(
FilterPicker.SELECT_FILTER,
this
) { _, data ->
supportFragmentManager.setFilterPickerResultListener(this) {
if (selectedFilter != null && selectedFilter!!.listingTitle == getShortcutName()) {
shortcutName.text = null
}
selectedFilter = data.getParcelable(FilterPicker.EXTRA_FILTER)
selectedFilter = it
updateFilterAndTheme()
}
}

@ -17,7 +17,7 @@ import dagger.hilt.android.AndroidEntryPoint
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.runBlocking
import org.tasks.R
import org.tasks.activities.FilterPicker
import org.tasks.dialogs.FilterPicker
import org.tasks.intents.TaskIntents
import org.tasks.preferences.DefaultFilterProvider
import org.tasks.preferences.Preferences

@ -6,9 +6,9 @@ import android.os.Bundle
import com.todoroo.astrid.api.Filter
import dagger.hilt.android.AndroidEntryPoint
import org.tasks.LocalBroadcastManager
import org.tasks.activities.FilterPicker.Companion.EXTRA_FILTER
import org.tasks.activities.FilterPicker.Companion.SELECT_FILTER
import org.tasks.activities.FilterPicker.Companion.newFilterPicker
import org.tasks.dialogs.FilterPicker.Companion.EXTRA_FILTER
import org.tasks.dialogs.FilterPicker.Companion.SELECT_FILTER
import org.tasks.dialogs.FilterPicker.Companion.newFilterPicker
import org.tasks.injection.InjectingAppCompatActivity
import org.tasks.preferences.DefaultFilterProvider
import org.tasks.preferences.Preferences
@ -28,15 +28,14 @@ class WidgetFilterSelectionActivity : InjectingAppCompatActivity() {
}
supportFragmentManager
.setFragmentResultListener(SELECT_FILTER, this) { _, result ->
if (result.isEmpty) {
val filter: Filter? = result.getParcelable(EXTRA_FILTER)
if (filter == null) {
finish()
return@setFragmentResultListener
}
result.getParcelable<Filter>(EXTRA_FILTER)?.let { filter ->
WidgetPreferences(this, preferences, widgetId)
.setFilter(defaultFilterProvider.getFilterPreferenceValue(filter))
localBroadcastManager.reconfigureWidget(widgetId)
}
WidgetPreferences(this, preferences, widgetId)
.setFilter(defaultFilterProvider.getFilterPreferenceValue(filter))
localBroadcastManager.reconfigureWidget(widgetId)
setResult(RESULT_OK, Intent().putExtras(result))
finish()
}

Loading…
Cancel
Save