1
0
mirror of https://github.com/etesync/android synced 2024-12-23 15:18:14 +00:00

Members: implement removing members.

This commit is contained in:
Tom Hacohen 2020-08-28 13:34:09 +03:00
parent df9f2f4ed4
commit cbe7e142dc
2 changed files with 28 additions and 7 deletions

View File

@ -8,6 +8,7 @@ import android.view.ViewGroup
import android.widget.AdapterView import android.widget.AdapterView
import android.widget.ArrayAdapter import android.widget.ArrayAdapter
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.ListFragment import androidx.fragment.app.ListFragment
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
@ -27,7 +28,7 @@ import java.util.concurrent.Future
class CollectionMembersListFragment : ListFragment(), AdapterView.OnItemClickListener { class CollectionMembersListFragment : ListFragment(), AdapterView.OnItemClickListener {
private val model: AccountViewModel by activityViewModels() private val model: AccountViewModel by activityViewModels()
private val collectionModel: CollectionViewModel by activityViewModels() private val collectionModel: CollectionViewModel by activityViewModels()
private val membersModel: LoadMembersViewModel by viewModels() private val membersModel: CollectionMembersViewModel by viewModels()
private var emptyTextView: TextView? = null private var emptyTextView: TextView? = null
@ -77,17 +78,23 @@ class CollectionMembersListFragment : ListFragment(), AdapterView.OnItemClickLis
override fun onItemClick(parent: AdapterView<*>, view: View, position: Int, id: Long) { override fun onItemClick(parent: AdapterView<*>, view: View, position: Int, id: Long) {
val member = listAdapter?.getItem(position) as CollectionMember val member = listAdapter?.getItem(position) as CollectionMember
/* if (member.accessLevel == "adm") {
AlertDialog.Builder(requireActivity())
.setIcon(R.drawable.ic_error_dark)
.setTitle(R.string.collection_members_remove_title)
.setMessage(R.string.collection_members_remove_admin)
.setNegativeButton(android.R.string.ok) { _, _ -> }.show()
return
}
AlertDialog.Builder(requireActivity()) AlertDialog.Builder(requireActivity())
.setIcon(R.drawable.ic_info_dark) .setIcon(R.drawable.ic_info_dark)
.setTitle(R.string.collection_members_remove_title) .setTitle(R.string.collection_members_remove_title)
.setMessage(getString(R.string.collection_members_remove, member.user)) .setMessage(getString(R.string.collection_members_remove, member.username))
.setPositiveButton(android.R.string.yes) { dialog, which -> .setPositiveButton(android.R.string.yes) { dialog, which ->
val frag = RemoveMemberFragment.newInstance(account, info, member.user!!) membersModel.removeMember(model.value!!, collectionModel.value!!, member.username)
frag.show(requireFragmentManager(), null)
} }
.setNegativeButton(android.R.string.no) { dialog, which -> }.show() .setNegativeButton(android.R.string.no) { dialog, which -> }.show()
*/
} }
internal inner class MembersListAdapter(context: Context) : ArrayAdapter<CollectionMember>(context, R.layout.collection_members_list_item) { internal inner class MembersListAdapter(context: Context) : ArrayAdapter<CollectionMember>(context, R.layout.collection_members_list_item) {
@ -111,7 +118,7 @@ class CollectionMembersListFragment : ListFragment(), AdapterView.OnItemClickLis
} }
} }
class LoadMembersViewModel : ViewModel() { class CollectionMembersViewModel : ViewModel() {
private val members = MutableLiveData<List<CollectionMember>>() private val members = MutableLiveData<List<CollectionMember>>()
private var asyncTask: Future<Unit>? = null private var asyncTask: Future<Unit>? = null
@ -136,6 +143,19 @@ class LoadMembersViewModel : ViewModel() {
} }
} }
fun removeMember(accountCollectionHolder: AccountHolder, cachedCollection: CachedCollection, username: String) {
doAsync {
val col = cachedCollection.col
val memberManager = accountCollectionHolder.colMgr.getMemberManager(col)
memberManager.remove(username)
val ret = members.value!!.filter { it.username != username }
uiThread {
members.value = ret
}
}
}
fun cancelLoad() { fun cancelLoad() {
asyncTask?.cancel(true) asyncTask?.cancel(true)
} }

View File

@ -166,6 +166,7 @@
<string name="collection_members_remove_error">Error removing member</string> <string name="collection_members_remove_error">Error removing member</string>
<string name="collection_members_remove_title">Remove member</string> <string name="collection_members_remove_title">Remove member</string>
<string name="collection_members_remove">Would you like to revoke %s\'s access?\nPlease be advised that a malicious user would potentially be able to retain access to encryption keys. Please refer to the FAQ for more information.</string> <string name="collection_members_remove">Would you like to revoke %s\'s access?\nPlease be advised that a malicious user would potentially be able to retain access to encryption keys. Please refer to the FAQ for more information.</string>
<string name="collection_members_remove_admin">Removing access to admins is currently not supported.</string>
<!-- JournalItemActivity --> <!-- JournalItemActivity -->
<string name="about">About</string> <string name="about">About</string>