Implement disabling PMs. Fixes #1331

This commit is contained in:
Phillip Thelen 2020-08-26 16:29:37 +02:00
parent 6d9f482e2c
commit 75fd669107
9 changed files with 72 additions and 8 deletions

View file

@ -9,13 +9,39 @@
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/opt_out_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingHorizontal="32dp"
android:paddingVertical="12dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/pms_disabled"
android:gravity="center"
style="@style/Subheader1"
android:textColor="@color/gray_50"
android:layout_marginBottom="4dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/pms_disabled_description"
android:gravity="center"
style="@style/Body3" />
</LinearLayout>
<LinearLayout
android:id="@+id/inbox_messages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:divider="?android:listDivider"
android:showDividers="middle">
</LinearLayout>
android:showDividers="middle" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

View file

@ -1089,4 +1089,7 @@
<string name="block_user_title">Block %s?</string>
<string name="block_user_description">A blocked user cannot send you Private Messages but you will still see their posts in Tavern or Guilds. This will have no effect if the person is a moderator now or in the future.</string>
<string name="block">Block</string>
<string name="disablePrivateMessages">Disable Private Messages</string>
<string name="pms_disabled">Private Messages are disabled</string>
<string name="pms_disabled_description">You can still send messages, but no one can send them to you. You can enable again from Settings.</string>
</resources>

View file

@ -160,6 +160,10 @@
android:summary="@string/dailyDueDefaultViewDescription"
android:layout="@layout/preference_child_summary"
/>
<CheckBoxPreference android:title="@string/disablePrivateMessages"
android:key="disablePMs"
android:layout="@layout/preference_child_summary"
/>
<ListPreference
android:entries="@array/weekdays"
android:entryValues="@array/weekdayValues"

View file

@ -338,6 +338,9 @@ class UserRepositoryImpl(localRepository: UserLocalRepository, apiClient: ApiCli
} else {
oldUser
}
if (newUser.inbox != null) {
copiedUser.inbox = newUser.inbox
}
if (newUser.items != null) {
copiedUser.items = newUser.items
}

View file

@ -134,15 +134,17 @@ class AchievementsFragment: BaseMainFragment(), SwipeRefreshLayout.OnRefreshList
menuID = menuItem?.itemId ?: 0
menuItem?.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
menuItem?.setIcon(R.drawable.ic_round_view_list_24px)
tintMenuIcon(menuItem)
} else {
val menuItem = menu.add(R.string.switch_to_grid_view)
menuID = menuItem?.itemId ?: 0
menuItem?.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
menuItem?.setIcon(R.drawable.ic_round_view_module_24px)
tintMenuIcon(menuItem)
}
activity?.findViewById<Toolbar>(R.id.toolbar)?.let {
ToolbarColorHelper.colorizeToolbar(it, activity, false)
ToolbarColorHelper.colorizeToolbar(it, activity, null)
}
super.onCreateOptionsMenu(menu, inflater)
}

View file

@ -8,6 +8,7 @@ import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.preference.CheckBoxPreference
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceScreen
@ -236,6 +237,13 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
val preference = findPreference(key) as ListPreference
preference.summary = preference.entry
}
"disablePMs" -> {
val isDisabled = sharedPreferences.getBoolean("disablePMs", false)
if (user?.inbox?.optOut != isDisabled) {
compositeSubscription.add(userRepository.updateUser(user, "inbox.optOut", isDisabled)
.subscribe(Consumer { }, RxErrorHandler.handleEmptyError()))
}
}
}
}
@ -296,6 +304,10 @@ class PreferencesFragment : BasePreferencesFragment(), SharedPreferences.OnShare
preference.summary = context?.getString(R.string.username_not_confirmed)
}
val disablePMsPreference = findPreference("disablePMs") as? CheckBoxPreference
val inbox = user?.inbox
disablePMsPreference?.isChecked = inbox?.optOut ?: true
if (user?.contributor?.admin == true) {
serverUrlPreference?.isVisible = true
}

View file

@ -111,6 +111,7 @@ class InboxMessageListFragment : BaseMainFragment(), androidx.swiperefreshlayout
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
this.activity?.menuInflater?.inflate(R.menu.inbox_chat, menu)
val item = menu.findItem(R.id.open_profile)
super.onCreateOptionsMenu(menu, inflater)
}

View file

@ -41,6 +41,7 @@ class InboxOverviewFragment : BaseMainFragment(), androidx.swiperefreshlayout.wi
compositeSubscription.add(this.socialRepository.markPrivateMessagesRead(user).subscribe(Consumer { }, RxErrorHandler.handleEmptyError()))
return inflater.inflate(R.layout.fragment_inbox, container, false)
}
@ -49,6 +50,10 @@ class InboxOverviewFragment : BaseMainFragment(), androidx.swiperefreshlayout.wi
inbox_refresh_layout?.setOnRefreshListener(this)
compositeSubscription.add(userRepository.getUser().map { user?.inbox?.optOut ?: false }.distinctUntilChanged().subscribe {
opt_out_view.visibility = if (it) View.VISIBLE else View.GONE
})
loadMessages()
retrieveMessages()
}
@ -66,6 +71,8 @@ class InboxOverviewFragment : BaseMainFragment(), androidx.swiperefreshlayout.wi
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
this.activity?.menuInflater?.inflate(R.menu.inbox, menu)
val item = menu.findItem(R.id.send_message)
tintMenuIcon(item)
super.onCreateOptionsMenu(menu, inflater)
}

View file

@ -79,11 +79,17 @@ class TasksFragment : BaseMainFragment(), SearchView.OnQueryTextListener {
super.onResume()
bottomNavigation?.onTabSelectedListener = {
when (it) {
Task.TYPE_HABIT -> viewPager?.currentItem = 0
Task.TYPE_DAILY -> viewPager?.currentItem = 1
Task.TYPE_TODO -> viewPager?.currentItem = 2
Task.TYPE_REWARD -> viewPager?.currentItem = 3
val newItem = when (it) {
Task.TYPE_HABIT -> 0
Task.TYPE_DAILY -> 1
Task.TYPE_TODO -> 2
Task.TYPE_REWARD -> 3
else -> 0
}
if (newItem == viewPager?.currentItem) {
refresh()
} else {
viewPager?.currentItem = newItem
}
updateBottomBarBadges()
}