mirror of
https://github.com/etesync/android
synced 2025-01-11 08:10:58 +00:00
Collection membership: implement leaving collections.
This commit is contained in:
parent
bf1155d0b8
commit
39ad32bbd0
@ -6,6 +6,7 @@ import android.os.Bundle
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.Button
|
||||||
import android.widget.CheckBox
|
import android.widget.CheckBox
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
@ -21,6 +22,7 @@ import com.etesync.syncadapter.CachedCollection
|
|||||||
import com.etesync.syncadapter.Constants
|
import com.etesync.syncadapter.Constants
|
||||||
import com.etesync.syncadapter.R
|
import com.etesync.syncadapter.R
|
||||||
import com.etesync.syncadapter.resource.LocalCalendar
|
import com.etesync.syncadapter.resource.LocalCalendar
|
||||||
|
import com.etesync.syncadapter.syncadapter.requestSync
|
||||||
import com.etesync.syncadapter.ui.BaseActivity
|
import com.etesync.syncadapter.ui.BaseActivity
|
||||||
import org.jetbrains.anko.doAsync
|
import org.jetbrains.anko.doAsync
|
||||||
import org.jetbrains.anko.uiThread
|
import org.jetbrains.anko.uiThread
|
||||||
@ -28,9 +30,15 @@ import org.jetbrains.anko.uiThread
|
|||||||
class CollectionMembersFragment : Fragment() {
|
class CollectionMembersFragment : Fragment() {
|
||||||
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 var isAdmin: Boolean = false
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
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) {
|
if (savedInstanceState == null) {
|
||||||
collectionModel.observe(this) {
|
collectionModel.observe(this) {
|
||||||
@ -45,10 +53,6 @@ class CollectionMembersFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initUi(inflater: LayoutInflater, v: View, cachedCollection: CachedCollection) {
|
private fun initUi(inflater: LayoutInflater, v: View, cachedCollection: CachedCollection) {
|
||||||
v.findViewById<View>(R.id.add_member).setOnClickListener {
|
|
||||||
addMemberClicked()
|
|
||||||
}
|
|
||||||
|
|
||||||
val meta = cachedCollection.meta
|
val meta = cachedCollection.meta
|
||||||
val colorSquare = v.findViewById<View>(R.id.color)
|
val colorSquare = v.findViewById<View>(R.id.color)
|
||||||
val color = LocalCalendar.parseColor(meta.color)
|
val color = LocalCalendar.parseColor(meta.color)
|
||||||
@ -70,6 +74,24 @@ class CollectionMembersFragment : Fragment() {
|
|||||||
val desc = v.findViewById<View>(R.id.description) as TextView
|
val desc = v.findViewById<View>(R.id.description) as TextView
|
||||||
desc.text = meta.description
|
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
|
v.findViewById<View>(R.id.progressBar).visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,19 +127,11 @@ class ViewCollectionFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
R.id.on_manage_members -> {
|
R.id.on_manage_members -> {
|
||||||
if (cachedCollection.col.accessLevel == CollectionAccessLevel.Admin) {
|
parentFragmentManager.commit {
|
||||||
parentFragmentManager.commit {
|
replace(R.id.fragment_container, CollectionMembersFragment())
|
||||||
replace(R.id.fragment_container, CollectionMembersFragment())
|
addToBackStack(null)
|
||||||
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()
|
|
||||||
} }
|
|
||||||
R.id.on_import -> {
|
R.id.on_import -> {
|
||||||
if (cachedCollection.col.accessLevel != CollectionAccessLevel.ReadOnly) {
|
if (cachedCollection.col.accessLevel != CollectionAccessLevel.ReadOnly) {
|
||||||
parentFragmentManager.commit {
|
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_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>
|
<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 -->
|
<!-- Invitations -->
|
||||||
<string name="invitations_title">Invitations</string>
|
<string name="invitations_title">Invitations</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user