mirror of
https://github.com/etesync/android
synced 2025-01-11 00:01:12 +00:00
Collections: implement inviting members.
This commit is contained in:
parent
cbe7e142dc
commit
c24936ff7e
@ -1,20 +1,32 @@
|
|||||||
package com.etesync.syncadapter.ui.etebase
|
package com.etesync.syncadapter.ui.etebase
|
||||||
|
|
||||||
|
import android.app.Dialog
|
||||||
|
import android.app.ProgressDialog
|
||||||
import android.graphics.Color.parseColor
|
import android.graphics.Color.parseColor
|
||||||
import android.os.Bundle
|
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.CheckBox
|
||||||
|
import android.widget.EditText
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
|
import androidx.fragment.app.DialogFragment
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
|
import com.etebase.client.Utils
|
||||||
|
import com.etebase.client.exceptions.EtebaseException
|
||||||
|
import com.etebase.client.exceptions.NotFoundException
|
||||||
import com.etesync.syncadapter.CachedCollection
|
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.ui.BaseActivity
|
import com.etesync.syncadapter.ui.BaseActivity
|
||||||
|
import org.jetbrains.anko.doAsync
|
||||||
|
import org.jetbrains.anko.uiThread
|
||||||
|
|
||||||
class CollectionMembersFragment : Fragment() {
|
class CollectionMembersFragment : Fragment() {
|
||||||
|
private val model: AccountViewModel by activityViewModels()
|
||||||
private val collectionModel: CollectionViewModel by activityViewModels()
|
private val collectionModel: CollectionViewModel by activityViewModels()
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
@ -34,7 +46,7 @@ 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 {
|
v.findViewById<View>(R.id.add_member).setOnClickListener {
|
||||||
|
addMemberClicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
val meta = cachedCollection.meta
|
val meta = cachedCollection.meta
|
||||||
@ -60,4 +72,75 @@ class CollectionMembersFragment : Fragment() {
|
|||||||
|
|
||||||
v.findViewById<View>(R.id.progressBar).visibility = View.GONE
|
v.findViewById<View>(R.id.progressBar).visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun addMemberClicked() {
|
||||||
|
val view = View.inflate(requireContext(), R.layout.add_member_fragment, null)
|
||||||
|
val dialog = AlertDialog.Builder(requireContext())
|
||||||
|
.setTitle(R.string.collection_members_add)
|
||||||
|
.setIcon(R.drawable.ic_account_add_dark)
|
||||||
|
.setPositiveButton(android.R.string.yes) { _, _ ->
|
||||||
|
val username = view.findViewById<EditText>(R.id.username).text.toString()
|
||||||
|
val readOnly = view.findViewById<CheckBox>(R.id.read_only).isChecked
|
||||||
|
|
||||||
|
val frag = AddMemberFragment(model.value!!, collectionModel.value!!, username, if (readOnly) "ro" else "rw")
|
||||||
|
frag.show(childFragmentManager, null)
|
||||||
|
}
|
||||||
|
.setNegativeButton(android.R.string.no) { _, _ -> }
|
||||||
|
dialog.setView(view)
|
||||||
|
dialog.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AddMemberFragment(private val accountHolder: AccountHolder, private val cachedCollection: CachedCollection, private val username: String, private val accessLevel: String) : DialogFragment() {
|
||||||
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
|
val progress = ProgressDialog(context)
|
||||||
|
progress.setTitle(R.string.collection_members_adding)
|
||||||
|
progress.setMessage(getString(R.string.please_wait))
|
||||||
|
progress.isIndeterminate = true
|
||||||
|
progress.setCanceledOnTouchOutside(false)
|
||||||
|
isCancelable = false
|
||||||
|
|
||||||
|
doAsync {
|
||||||
|
val invitationManager = accountHolder.etebase.invitationManager
|
||||||
|
try {
|
||||||
|
val profile = invitationManager.fetchUserProfile(username)
|
||||||
|
val fingerprint = Utils.prettyFingerprint(profile.pubkey)
|
||||||
|
uiThread {
|
||||||
|
val view = LayoutInflater.from(context).inflate(R.layout.fingerprint_alertdialog, null)
|
||||||
|
(view.findViewById<View>(R.id.body) as TextView).text = getString(R.string.trust_fingerprint_body, username)
|
||||||
|
(view.findViewById<View>(R.id.fingerprint) as TextView).text = fingerprint
|
||||||
|
AlertDialog.Builder(requireContext())
|
||||||
|
.setIcon(R.drawable.ic_fingerprint_dark)
|
||||||
|
.setTitle(R.string.trust_fingerprint_title)
|
||||||
|
.setView(view)
|
||||||
|
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||||
|
doAsync {
|
||||||
|
try {
|
||||||
|
invitationManager.invite(cachedCollection.col, username, profile.pubkey, accessLevel)
|
||||||
|
uiThread { dismiss() }
|
||||||
|
} catch (e: EtebaseException) {
|
||||||
|
uiThread { handleError(e.localizedMessage) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.setNegativeButton(android.R.string.cancel) { _, _ -> dismiss() }.show()
|
||||||
|
}
|
||||||
|
} catch (e: NotFoundException) {
|
||||||
|
uiThread { handleError(getString(R.string.collection_members_error_user_not_found, username)) }
|
||||||
|
} catch (e: EtebaseException) {
|
||||||
|
uiThread { handleError(e.localizedMessage) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return progress
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleError(message: String) {
|
||||||
|
AlertDialog.Builder(requireContext())
|
||||||
|
.setIcon(R.drawable.ic_error_dark)
|
||||||
|
.setTitle(R.string.collection_members_add_error)
|
||||||
|
.setMessage(message)
|
||||||
|
.setPositiveButton(android.R.string.yes) { _, _ -> }.show()
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
}
|
}
|
@ -161,7 +161,7 @@
|
|||||||
<string name="collection_members_adding">Adding member</string>
|
<string name="collection_members_adding">Adding member</string>
|
||||||
<string name="trust_fingerprint_title">Verify security fingerprint</string>
|
<string name="trust_fingerprint_title">Verify security fingerprint</string>
|
||||||
<string name="trust_fingerprint_body">Verify %s\'s security fingerprint to ensure the encryption is secure.</string>
|
<string name="trust_fingerprint_body">Verify %s\'s security fingerprint to ensure the encryption is secure.</string>
|
||||||
<string name="collection_members_error_user_not_found">User (%s) not found. Have they setup their encryption password from one of the apps?</string>
|
<string name="collection_members_error_user_not_found">User (%s) not found</string>
|
||||||
<string name="collection_members_removing">Removing member</string>
|
<string name="collection_members_removing">Removing member</string>
|
||||||
<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>
|
||||||
|
Loading…
Reference in New Issue
Block a user