Use coroutines in notification preferences

pull/1051/head
Alex Baker 4 years ago
parent 9b4ccd5137
commit 5879774905

@ -24,35 +24,32 @@ class DefaultFilterProvider @Inject constructor(
private val locationDao: LocationDao, private val locationDao: LocationDao,
private val googleTaskDao: GoogleTaskDao) { private val googleTaskDao: GoogleTaskDao) {
@Deprecated("use coroutines")
var dashclockFilter: Filter var dashclockFilter: Filter
get() = runBlocking { getFilterFromPreference(R.string.p_dashclock_filter) } @Deprecated("use coroutines") get() = runBlocking { getFilterFromPreference(R.string.p_dashclock_filter) }
set(filter) = setFilterPreference(filter, R.string.p_dashclock_filter) set(filter) = setFilterPreference(filter, R.string.p_dashclock_filter)
@Deprecated("use coroutines")
var badgeFilter: Filter var badgeFilter: Filter
get() = runBlocking { getFilterFromPreference(R.string.p_badge_list) } @Deprecated("use coroutines") get() = runBlocking { getBadgeFilter() }
set(filter) = setFilterPreference(filter, R.string.p_badge_list) set(filter) = setFilterPreference(filter, R.string.p_badge_list)
@Deprecated("use coroutines")
var defaultOpenFilter: Filter var defaultOpenFilter: Filter
get() = runBlocking { getDefaultOpenFilter() } @Deprecated("use coroutines") get() = runBlocking { getDefaultOpenFilter() }
set(filter) = setFilterPreference(filter, R.string.p_default_open_filter) set(filter) = setFilterPreference(filter, R.string.p_default_open_filter)
@Deprecated("use coroutines")
var lastViewedFilter: Filter var lastViewedFilter: Filter
get() = runBlocking { getFilterFromPreference(R.string.p_last_viewed_list) } @Deprecated("use coroutines") get() = runBlocking { getFilterFromPreference(R.string.p_last_viewed_list) }
set(filter) = setFilterPreference(filter, R.string.p_last_viewed_list) set(filter) = setFilterPreference(filter, R.string.p_last_viewed_list)
@Deprecated("use coroutines")
var defaultList: Filter var defaultList: Filter
get() = runBlocking { getDefaultList() } @Deprecated("use coroutines") get() = runBlocking { getDefaultList() }
set(filter) = setFilterPreference(filter, R.string.p_default_list) set(filter) = setFilterPreference(filter, R.string.p_default_list)
@Deprecated("use coroutines") @Deprecated("use coroutines")
val startupFilter: Filter val startupFilter: Filter
get() = runBlocking { getStartupFilter() } get() = runBlocking { getStartupFilter() }
suspend fun getBadgeFilter() = getFilterFromPreference(R.string.p_badge_list)
suspend fun getDefaultList() = suspend fun getDefaultList() =
getFilterFromPreference(preferences.getStringValue(R.string.p_default_list), null) getFilterFromPreference(preferences.getStringValue(R.string.p_default_list), null)
?: getAnyList() ?: getAnyList()

@ -9,12 +9,14 @@ import android.os.Bundle
import android.os.PowerManager import android.os.PowerManager
import android.provider.Settings import android.provider.Settings
import android.speech.tts.TextToSpeech import android.speech.tts.TextToSpeech
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.SwitchPreferenceCompat import androidx.preference.SwitchPreferenceCompat
import com.todoroo.andlib.utility.AndroidUtilities import com.todoroo.andlib.utility.AndroidUtilities
import com.todoroo.astrid.api.Filter import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.voice.VoiceOutputAssistant import com.todoroo.astrid.voice.VoiceOutputAssistant
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import org.tasks.LocalBroadcastManager import org.tasks.LocalBroadcastManager
import org.tasks.R import org.tasks.R
import org.tasks.activities.FilterSelectionActivity import org.tasks.activities.FilterSelectionActivity
@ -76,15 +78,17 @@ class Notifications : InjectingPreferenceFragment() {
} }
val badgePreference: Preference = findPreference(R.string.p_badge_list) val badgePreference: Preference = findPreference(R.string.p_badge_list)
val filter = defaultFilterProvider.badgeFilter val filter = defaultFilterProvider.getBadgeFilter()
badgePreference.summary = filter.listingTitle badgePreference.summary = filter.listingTitle
badgePreference.onPreferenceClickListener = Preference.OnPreferenceClickListener { badgePreference.onPreferenceClickListener = Preference.OnPreferenceClickListener {
val intent = Intent(context, FilterSelectionActivity::class.java) lifecycleScope.launch {
intent.putExtra( val intent = Intent(context, FilterSelectionActivity::class.java)
FilterSelectionActivity.EXTRA_FILTER, defaultFilterProvider.badgeFilter intent.putExtra(
) FilterSelectionActivity.EXTRA_FILTER, defaultFilterProvider.getBadgeFilter()
intent.putExtra(FilterSelectionActivity.EXTRA_RETURN_FILTER, true) )
startActivityForResult(intent, REQUEST_BADGE_LIST) intent.putExtra(FilterSelectionActivity.EXTRA_RETURN_FILTER, true)
startActivityForResult(intent, REQUEST_BADGE_LIST)
}
true true
} }

Loading…
Cancel
Save