Collection membership: implement leaving collections.

pull/131/head
Tom Hacohen 4 years ago
parent bf1155d0b8
commit 39ad32bbd0

@ -6,6 +6,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.CheckBox
import android.widget.EditText
import android.widget.TextView
@ -21,6 +22,7 @@ import com.etesync.syncadapter.CachedCollection
import com.etesync.syncadapter.Constants
import com.etesync.syncadapter.R
import com.etesync.syncadapter.resource.LocalCalendar
import com.etesync.syncadapter.syncadapter.requestSync
import com.etesync.syncadapter.ui.BaseActivity
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
@ -28,9 +30,15 @@ import org.jetbrains.anko.uiThread
class CollectionMembersFragment : Fragment() {
private val model: AccountViewModel by activityViewModels()
private val collectionModel: CollectionViewModel by activityViewModels()
private var isAdmin: Boolean = false
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val ret = inflater.inflate(R.layout.etebase_view_collection_members, container, false)
val ret = if (collectionModel.value!!.col.accessLevel == CollectionAccessLevel.Admin) {
isAdmin = true
inflater.inflate(R.layout.etebase_view_collection_members, container, false)
} else {
inflater.inflate(R.layout.etebase_view_collection_members_no_access, container, false)
}
if (savedInstanceState == null) {
collectionModel.observe(this) {
@ -45,10 +53,6 @@ class CollectionMembersFragment : Fragment() {
}
private fun initUi(inflater: LayoutInflater, v: View, cachedCollection: CachedCollection) {
v.findViewById<View>(R.id.add_member).setOnClickListener {
addMemberClicked()
}
val meta = cachedCollection.meta
val colorSquare = v.findViewById<View>(R.id.color)
val color = LocalCalendar.parseColor(meta.color)
@ -70,6 +74,24 @@ class CollectionMembersFragment : Fragment() {
val desc = v.findViewById<View>(R.id.description) as TextView
desc.text = meta.description
if (isAdmin) {
v.findViewById<View>(R.id.add_member).setOnClickListener {
addMemberClicked()
}
} else {
v.findViewById<Button>(R.id.leave).setOnClickListener {
doAsync {
val membersManager = model.value!!.colMgr.getMemberManager(cachedCollection.col)
membersManager.leave()
val applicationContext = activity?.applicationContext
if (applicationContext != null) {
requestSync(applicationContext, model.value!!.account)
}
activity?.finish()
}
}
}
v.findViewById<View>(R.id.progressBar).visibility = View.GONE
}

@ -127,19 +127,11 @@ class ViewCollectionFragment : Fragment() {
}
}
R.id.on_manage_members -> {
if (cachedCollection.col.accessLevel == CollectionAccessLevel.Admin) {
parentFragmentManager.commit {
replace(R.id.fragment_container, CollectionMembersFragment())
addToBackStack(null)
}
} else {
val dialog = AlertDialog.Builder(requireContext())
.setIcon(R.drawable.ic_info_dark)
.setTitle(R.string.not_allowed_title)
.setMessage(R.string.edit_owner_only_anon)
.setPositiveButton(android.R.string.yes) { _, _ -> }.create()
dialog.show()
} }
parentFragmentManager.commit {
replace(R.id.fragment_container, CollectionMembersFragment())
addToBackStack(null)
}
}
R.id.on_import -> {
if (cachedCollection.col.accessLevel != CollectionAccessLevel.ReadOnly) {
parentFragmentManager.commit {

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
layout="@layout/collection_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_margin" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/activity_margin">
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="@string/collection_members_no_access" />
<Button
android:id="@+id/leave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="14dp"
android:text="@string/collection_members_leave" />
</LinearLayout>

@ -167,6 +167,8 @@
<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_admin">Removing access to admins is currently not supported.</string>
<string name="collection_members_no_access">Only admins are allowed to manage collection memberships. Would you like to leave the collection?</string>
<string name="collection_members_leave">Leave</string>
<!-- Invitations -->
<string name="invitations_title">Invitations</string>

Loading…
Cancel
Save