Add "Toggle notifications filter" to tab action

This commit is contained in:
kyori19 2020-05-13 21:27:58 +09:00
parent e48d53f93f
commit db677c5bb8
3 changed files with 25 additions and 4 deletions

View File

@ -60,6 +60,7 @@ import com.keylesspalace.tusky.components.scheduled.ScheduledTootActivity
import com.keylesspalace.tusky.components.search.SearchActivity
import com.keylesspalace.tusky.db.AccountEntity
import com.keylesspalace.tusky.entity.Account
import com.keylesspalace.tusky.fragment.NotificationsFragment
import com.keylesspalace.tusky.fragment.SFragment
import com.keylesspalace.tusky.interfaces.AccountSelectionListener
import com.keylesspalace.tusky.interfaces.ActionButtonActivity
@ -199,6 +200,9 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
@SuppressLint("RestrictedApi")
if (popup.menu is MenuBuilder) {
val menuBuilder = popup.menu as MenuBuilder
if (tab.position == notificationTabPosition) {
menuBuilder.findItem(R.id.tabToggleNotificationsFilter).isVisible = true
}
menuBuilder.setOptionalIconsVisible(true)
menuBuilder.visibleItems.forEach { item ->
val iconMarginPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8f, resources.displayMetrics).toInt()
@ -220,15 +224,26 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
popup.setOnMenuItemClickListener { item ->
val fragment = adapter?.getFragment(tab.position)
if (fragment is ReselectableFragment) {
when (item.itemId) {
R.id.tabJumpToTop -> {
when (item.itemId) {
R.id.tabJumpToTop -> {
if (fragment is ReselectableFragment) {
(fragment as ReselectableFragment).onReselect()
}
R.id.tabReset -> {
}
R.id.tabReset -> {
if (fragment is ReselectableFragment) {
(fragment as ReselectableFragment).onReset()
}
}
R.id.tabToggleNotificationsFilter -> {
if (fragment is NotificationsFragment) {
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
prefs.edit().putBoolean("showNotificationsFilter",
!prefs.getBoolean("showNotificationsFilter", true))
.apply()
eventHub.dispatch(PreferenceChangedEvent("showNotificationsFilter"))
}
}
}
false
}

View File

@ -9,4 +9,9 @@
android:icon="@drawable/ic_reject_24dp"
android:title="@string/action_tab_reset" />
<item android:id="@+id/tabToggleNotificationsFilter"
android:icon="@drawable/ic_notifications_24dp"
android:title="@string/action_tab_toggle_notifications_filter"
android:visible="false" />
</menu>

View File

@ -144,6 +144,7 @@
<string name="action_authorize">Authorize Now!</string>
<string name="action_tab_jump_to_top">Jump to top</string>
<string name="action_tab_reset">Reset tab</string>
<string name="action_tab_toggle_notifications_filter">Toggle notifications filter</string>
<string name="title_hashtags_dialog">Hashtags</string>
<string name="title_mentions_dialog">Mentions</string>