3891: Directly start the edit filter activity

This commit is contained in:
Lakoja 2023-07-27 17:36:43 +02:00
parent a883ec71d5
commit e5456b0197
3 changed files with 21 additions and 4 deletions

View File

@ -27,6 +27,7 @@ import at.connyduck.calladapter.networkresult.fold
import com.google.android.material.snackbar.Snackbar
import com.keylesspalace.tusky.appstore.EventHub
import com.keylesspalace.tusky.appstore.PreferenceChangedEvent
import com.keylesspalace.tusky.components.filters.EditFilterActivity
import com.keylesspalace.tusky.components.filters.FiltersActivity
import com.keylesspalace.tusky.components.timeline.TimelineFragment
import com.keylesspalace.tusky.components.timeline.viewmodel.TimelineViewModel.Kind
@ -184,6 +185,7 @@ class StatusListActivity : BottomSheetActivity(), HasAndroidInjector {
mastodonApi.getFilters().fold(
{ filters ->
mutedFilter = filters.firstOrNull { filter ->
// TODO shouldn't this be an exact match (only one keyword; exactly the hashtag)?
filter.context.contains(Filter.Kind.HOME.kind) && filter.keywords.any {
it.keyword == hashedTag
}
@ -238,7 +240,9 @@ class StatusListActivity : BottomSheetActivity(), HasAndroidInjector {
).fold(
{ filter ->
if (mastodonApi.addFilterKeyword(filterId = filter.id, keyword = hashedTag, wholeWord = true).isSuccess) {
mutedFilter = filter
// must be requested again; otherwise does not contain the keyword (but server does)
mutedFilter = mastodonApi.getFilter(filter.id).getOrNull()
// TODO the preference key here ("home") is not meaningful; should probably be another event if any
eventHub.dispatch(PreferenceChangedEvent(filter.context[0]))
filterCreateSuccess = true
@ -276,8 +280,16 @@ class StatusListActivity : BottomSheetActivity(), HasAndroidInjector {
if (filterCreateSuccess) {
updateTagMuteState(true)
Snackbar.make(binding.root, getString(R.string.muting_hashtag_success_format, tag), Snackbar.LENGTH_LONG).apply {
setAction(R.string.action_view_filters) {
startActivityWithSlideInAnimation(Intent(this@StatusListActivity, FiltersActivity::class.java))
setAction(R.string.action_view_filter) {
val intent = if (mutedFilter != null) {
Intent(this@StatusListActivity, EditFilterActivity::class.java).apply {
putExtra(EditFilterActivity.FILTER_TO_EDIT, mutedFilter)
}
} else {
Intent(this@StatusListActivity, FiltersActivity::class.java)
}
startActivityWithSlideInAnimation(intent)
}
show()
}

View File

@ -89,6 +89,11 @@ interface MastodonApi {
@GET("api/v1/filters")
suspend fun getFiltersV1(): NetworkResult<List<FilterV1>>
@GET("api/v2/filters/{filterId}")
suspend fun getFilter(
@Path("filterId") filterId: String
): NetworkResult<Filter>
@GET("api/v2/filters")
suspend fun getFilters(): NetworkResult<List<Filter>>

View File

@ -616,7 +616,7 @@
<string name="muting_hashtag_success_format">Muting hashtag #%s as a warning</string>
<string name="unmuting_hashtag_success_format">Unmuting hashtag #%s</string>
<string name="action_view_filters">View filters</string>
<string name="action_view_filter">View filter</string>
<string name="following_hashtag_success_format">Now following hashtag #%s</string>
<string name="unfollowing_hashtag_success_format">No longer following hashtag #%s</string>