From a538c25dccfd7be8c10ee194913c2df2a5858a7a Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Sat, 6 Jul 2024 03:51:17 -0500 Subject: [PATCH] Move request codes to FilterProvider --- .../java/com/todoroo/astrid/activity/MainActivity.kt | 6 +++--- .../todoroo/astrid/adapter/SubheaderClickHandler.kt | 6 +++--- .../main/java/org/tasks/dialogs/NewFilterDialog.kt | 4 ++-- .../main/java/org/tasks/filters/FilterProvider.kt | 12 +++++++----- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/todoroo/astrid/activity/MainActivity.kt b/app/src/main/java/com/todoroo/astrid/activity/MainActivity.kt index b64ecd7ab..e38a187a0 100644 --- a/app/src/main/java/com/todoroo/astrid/activity/MainActivity.kt +++ b/app/src/main/java/com/todoroo/astrid/activity/MainActivity.kt @@ -69,6 +69,9 @@ import org.tasks.extensions.Context.openUri import org.tasks.extensions.hideKeyboard import org.tasks.filters.Filter import org.tasks.filters.FilterProvider +import org.tasks.filters.FilterProvider.Companion.REQUEST_NEW_LIST +import org.tasks.filters.FilterProvider.Companion.REQUEST_NEW_PLACE +import org.tasks.filters.FilterProvider.Companion.REQUEST_NEW_TAGS import org.tasks.filters.NavigationDrawerSubheader import org.tasks.filters.PlaceFilter import org.tasks.location.LocationPickerActivity @@ -502,9 +505,6 @@ class MainActivity : AppCompatActivity() { private const val FRAG_TAG_TASK_EDIT = "frag_tag_task_edit" private const val FLAG_FROM_HISTORY = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY - const val REQUEST_NEW_LIST = 10100 - const val REQUEST_NEW_TAGS = 10101 - const val REQUEST_NEW_PLACE = 10104 val Intent.getFilter: Filter? get() = if (isFromHistory) { diff --git a/app/src/main/java/com/todoroo/astrid/adapter/SubheaderClickHandler.kt b/app/src/main/java/com/todoroo/astrid/adapter/SubheaderClickHandler.kt index c4da005a7..eedebd590 100644 --- a/app/src/main/java/com/todoroo/astrid/adapter/SubheaderClickHandler.kt +++ b/app/src/main/java/com/todoroo/astrid/adapter/SubheaderClickHandler.kt @@ -4,9 +4,6 @@ import android.app.Activity import android.content.Intent import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.lifecycleScope -import com.todoroo.astrid.activity.MainActivity.Companion.REQUEST_NEW_LIST -import com.todoroo.astrid.activity.MainActivity.Companion.REQUEST_NEW_PLACE -import com.todoroo.astrid.activity.MainActivity.Companion.REQUEST_NEW_TAGS import kotlinx.coroutines.launch import org.tasks.LocalBroadcastManager import org.tasks.activities.GoogleTaskListSettingsActivity @@ -16,6 +13,9 @@ import org.tasks.data.dao.CaldavDao import org.tasks.data.listSettingsClass import org.tasks.dialogs.NewFilterDialog import org.tasks.filters.FilterProvider +import org.tasks.filters.FilterProvider.Companion.REQUEST_NEW_LIST +import org.tasks.filters.FilterProvider.Companion.REQUEST_NEW_PLACE +import org.tasks.filters.FilterProvider.Companion.REQUEST_NEW_TAGS import org.tasks.filters.NavigationDrawerSubheader import org.tasks.filters.NavigationDrawerSubheader.SubheaderType.CALDAV import org.tasks.filters.NavigationDrawerSubheader.SubheaderType.ETESYNC diff --git a/app/src/main/java/org/tasks/dialogs/NewFilterDialog.kt b/app/src/main/java/org/tasks/dialogs/NewFilterDialog.kt index c5b269f3e..5df0b2f5f 100644 --- a/app/src/main/java/org/tasks/dialogs/NewFilterDialog.kt +++ b/app/src/main/java/org/tasks/dialogs/NewFilterDialog.kt @@ -4,7 +4,6 @@ import android.app.Dialog import android.content.Intent import android.os.Bundle import androidx.fragment.app.DialogFragment -import com.todoroo.astrid.activity.MainActivity import com.todoroo.astrid.api.CustomFilterCriterion import com.todoroo.astrid.core.CriterionInstance import com.todoroo.astrid.core.CriterionInstance.Companion.TYPE_INTERSECT @@ -15,6 +14,7 @@ import dagger.hilt.android.AndroidEntryPoint import org.tasks.R import org.tasks.activities.FilterSettingsActivity import org.tasks.filters.FilterCriteriaProvider +import org.tasks.filters.FilterProvider.Companion.REQUEST_NEW_LIST import javax.inject.Inject @AndroidEntryPoint @@ -123,7 +123,7 @@ class NewFilterDialog : DialogFragment() { intent.putExtra(FilterSettingsActivity.EXTRA_TITLE, title) intent.putExtra(FilterSettingsActivity.EXTRA_CRITERIA, serialize(list)) } - activity?.startActivityForResult(intent, MainActivity.REQUEST_NEW_LIST) + activity?.startActivityForResult(intent, REQUEST_NEW_LIST) dismiss() } diff --git a/app/src/main/java/org/tasks/filters/FilterProvider.kt b/app/src/main/java/org/tasks/filters/FilterProvider.kt index 274cdc1ee..ca744136a 100644 --- a/app/src/main/java/org/tasks/filters/FilterProvider.kt +++ b/app/src/main/java/org/tasks/filters/FilterProvider.kt @@ -1,7 +1,6 @@ package org.tasks.filters import android.content.Context -import com.todoroo.astrid.activity.MainActivity import com.todoroo.astrid.api.CustomFilter import com.todoroo.astrid.core.BuiltInFilterExposer import dagger.hilt.android.qualifiers.ApplicationContext @@ -128,7 +127,7 @@ class FilterProvider @Inject constructor( collapsed, SubheaderType.PREFERENCE, R.string.p_collapse_tags.toLong(), - if (showCreate) MainActivity.REQUEST_NEW_TAGS else 0, + if (showCreate) REQUEST_NEW_TAGS else 0, ) ) .apply { if (collapsed) return this } @@ -156,7 +155,7 @@ class FilterProvider @Inject constructor( collapsed, SubheaderType.PREFERENCE, R.string.p_collapse_locations.toLong(), - if (showCreate) MainActivity.REQUEST_NEW_PLACE else 0, + if (showCreate) REQUEST_NEW_PLACE else 0, ) ) .apply { if (collapsed) return this } @@ -200,7 +199,7 @@ class FilterProvider @Inject constructor( collapsed, SubheaderType.GOOGLE_TASKS, account.id, - if (showCreate) MainActivity.REQUEST_NEW_LIST else 0, + if (showCreate) REQUEST_NEW_LIST else 0, ) ) .apply { if (collapsed) return this } @@ -252,7 +251,7 @@ class FilterProvider @Inject constructor( else -> SubheaderType.CALDAV }, account.id, - if (showCreate) MainActivity.REQUEST_NEW_LIST else 0, + if (showCreate) REQUEST_NEW_LIST else 0, ) ) .apply { if (collapsed) return this } @@ -269,6 +268,9 @@ class FilterProvider @Inject constructor( } companion object { + const val REQUEST_NEW_LIST = 10100 + const val REQUEST_NEW_TAGS = 10101 + const val REQUEST_NEW_PLACE = 10104 const val REQUEST_NEW_FILTER = 101015 private val COMPARATOR = Comparator { f1, f2 -> when {