mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Implement remaining feedback
This commit is contained in:
parent
fdec8eae4b
commit
74dac84796
@ -1199,7 +1199,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
private void handleEditPushGroup() {
|
private void handleEditPushGroup() {
|
||||||
Intent intent = new Intent(this, EditClosedGroupActivity.class);
|
Intent intent = new Intent(this, EditClosedGroupActivity.class);
|
||||||
String groupID = this.recipient.getAddress().toGroupString();
|
String groupID = this.recipient.getAddress().toGroupString();
|
||||||
intent.putExtra(EditClosedGroupActivityKt.EXTRA_GROUP_ID, groupID);
|
intent.putExtra(EditClosedGroupActivity.Companion.getGroupIDKey(), groupID);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ class CreateClosedGroupActivity : PassphraseRequiredActionBarActivity(), LoaderM
|
|||||||
if (selectedMembers.count() < 2) {
|
if (selectedMembers.count() < 2) {
|
||||||
return Toast.makeText(this, R.string.activity_create_closed_group_not_enough_group_members_error, Toast.LENGTH_LONG).show()
|
return Toast.makeText(this, R.string.activity_create_closed_group_not_enough_group_members_error, Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
if (selectedMembers.count() > 49) { // Minus one because we're going to include self later
|
if (selectedMembers.count() > ClosedGroupsProtocol.groupSizeLimit) { // Minus one because we're going to include self later
|
||||||
return Toast.makeText(this, R.string.activity_create_closed_group_too_many_group_members_error, Toast.LENGTH_LONG).show()
|
return Toast.makeText(this, R.string.activity_create_closed_group_too_many_group_members_error, Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
val userPublicKey = TextSecurePreferences.getLocalNumber(this)
|
val userPublicKey = TextSecurePreferences.getLocalNumber(this)
|
||||||
|
@ -21,7 +21,7 @@ import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
|||||||
import org.thoughtcrime.securesms.database.Address
|
import org.thoughtcrime.securesms.database.Address
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||||
import org.thoughtcrime.securesms.groups.GroupManager
|
import org.thoughtcrime.securesms.groups.GroupManager
|
||||||
import org.thoughtcrime.securesms.loki.dialogs.GroupEditingOptionsBottomSheet
|
import org.thoughtcrime.securesms.loki.dialogs.ClosedGroupEditingOptionsBottomSheet
|
||||||
import org.thoughtcrime.securesms.loki.protocol.ClosedGroupsProtocol
|
import org.thoughtcrime.securesms.loki.protocol.ClosedGroupsProtocol
|
||||||
import org.thoughtcrime.securesms.mms.GlideApp
|
import org.thoughtcrime.securesms.mms.GlideApp
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient
|
import org.thoughtcrime.securesms.recipients.Recipient
|
||||||
@ -30,71 +30,66 @@ import org.thoughtcrime.securesms.util.TextSecurePreferences
|
|||||||
import org.whispersystems.signalservice.loki.utilities.toHexString
|
import org.whispersystems.signalservice.loki.utilities.toHexString
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
const val EXTRA_GROUP_ID = "GROUP_ID"
|
|
||||||
const val REQ_CODE_ADD_USERS = 124
|
|
||||||
const val LOADER_ID_MEMBERS = 0
|
|
||||||
|
|
||||||
const val MAX_GROUP_MEMBERS_LEGACY = 10
|
|
||||||
const val MAX_GROUP_MEMBERS_SSK = 50
|
|
||||||
|
|
||||||
class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
|
class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
|
||||||
|
|
||||||
private lateinit var memberListAdapter: EditClosedGroupMembersAdapter
|
|
||||||
private val originalMembers = HashSet<String>()
|
private val originalMembers = HashSet<String>()
|
||||||
private val members = HashSet<String>()
|
private val members = HashSet<String>()
|
||||||
// private var adminMembers = HashSet<String>()
|
private var hasNameChanged = false
|
||||||
|
|
||||||
private lateinit var groupID: String
|
private lateinit var groupID: String
|
||||||
private lateinit var originalName: String
|
private lateinit var originalName: String
|
||||||
private lateinit var newGroupDisplayName: String
|
private lateinit var name: String
|
||||||
|
|
||||||
private var nameHasChanged = false
|
private var isEditingName = false
|
||||||
|
|
||||||
private var isEditingGroupName = false
|
|
||||||
set(value) {
|
set(value) {
|
||||||
if (field == value) return
|
if (field == value) return
|
||||||
field = value
|
field = value
|
||||||
handleIsEditingDisplayNameChanged()
|
handleIsEditingNameChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val memberListAdapter by lazy {
|
||||||
|
EditClosedGroupMembersAdapter(this, GlideApp.with(this), this::onMemberClick)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic val groupIDKey = "groupIDKey"
|
||||||
|
private val loaderID = 0
|
||||||
|
val addUsersRequestCode = 124
|
||||||
|
val legacyGroupSizeLimit = 10
|
||||||
|
}
|
||||||
|
|
||||||
// region Lifecycle
|
// region Lifecycle
|
||||||
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
|
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
|
||||||
super.onCreate(savedInstanceState, isReady)
|
super.onCreate(savedInstanceState, isReady)
|
||||||
|
|
||||||
setContentView(R.layout.activity_edit_closed_group)
|
setContentView(R.layout.activity_edit_closed_group)
|
||||||
|
|
||||||
this.groupID = intent.getStringExtra(EXTRA_GROUP_ID)
|
|
||||||
this.originalName = DatabaseFactory.getGroupDatabase(this).getGroup(groupID).get().title
|
|
||||||
this.newGroupDisplayName = this.originalName
|
|
||||||
|
|
||||||
supportActionBar!!.title = resources.getString(R.string.activity_edit_closed_group_title)
|
supportActionBar!!.title = resources.getString(R.string.activity_edit_closed_group_title)
|
||||||
|
|
||||||
|
groupID = intent.getStringExtra(Companion.groupIDKey)
|
||||||
|
originalName = DatabaseFactory.getGroupDatabase(this).getGroup(groupID).get().title
|
||||||
|
name = originalName
|
||||||
|
|
||||||
addMembersClosedGroupButton.setOnClickListener { onAddMembersClick() }
|
addMembersClosedGroupButton.setOnClickListener { onAddMembersClick() }
|
||||||
|
|
||||||
this.memberListAdapter = EditClosedGroupMembersAdapter(
|
recyclerView.adapter = memberListAdapter
|
||||||
this,
|
|
||||||
GlideApp.with(this),
|
|
||||||
this::onMemberClick
|
|
||||||
)
|
|
||||||
recyclerView.adapter = this.memberListAdapter
|
|
||||||
recyclerView.layoutManager = LinearLayoutManager(this)
|
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||||
|
|
||||||
lblGroupNameDisplay.text = this.originalName
|
lblGroupNameDisplay.text = originalName
|
||||||
cntGroupNameDisplay.setOnClickListener { isEditingGroupName = true }
|
cntGroupNameDisplay.setOnClickListener { isEditingName = true }
|
||||||
btnCancelGroupNameEdit.setOnClickListener { isEditingGroupName = false }
|
btnCancelGroupNameEdit.setOnClickListener { isEditingName = false }
|
||||||
btnSaveGroupNameEdit.setOnClickListener { saveDisplayName() }
|
btnSaveGroupNameEdit.setOnClickListener { saveName() }
|
||||||
edtGroupName.setImeActionLabel(getString(R.string.save), EditorInfo.IME_ACTION_DONE)
|
edtGroupName.setImeActionLabel(getString(R.string.save), EditorInfo.IME_ACTION_DONE)
|
||||||
edtGroupName.setOnEditorActionListener { _, actionId, _ ->
|
edtGroupName.setOnEditorActionListener { _, actionId, _ ->
|
||||||
when (actionId) {
|
when (actionId) {
|
||||||
EditorInfo.IME_ACTION_DONE -> {
|
EditorInfo.IME_ACTION_DONE -> {
|
||||||
saveDisplayName()
|
saveName()
|
||||||
return@setOnEditorActionListener true
|
return@setOnEditorActionListener true
|
||||||
}
|
}
|
||||||
else -> return@setOnEditorActionListener false
|
else -> return@setOnEditorActionListener false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup member list loader.
|
LoaderManager.getInstance(this).initLoader(Companion.loaderID, null, object : LoaderManager.LoaderCallbacks<List<String>> {
|
||||||
LoaderManager.getInstance(this).initLoader(LOADER_ID_MEMBERS, null, object : LoaderManager.LoaderCallbacks<List<String>> {
|
|
||||||
override fun onCreateLoader(id: Int, bundle: Bundle?): Loader<List<String>> {
|
override fun onCreateLoader(id: Int, bundle: Bundle?): Loader<List<String>> {
|
||||||
return EditClosedGroupLoader(this@EditClosedGroupActivity, groupID)
|
return EditClosedGroupLoader(this@EditClosedGroupActivity, groupID)
|
||||||
}
|
}
|
||||||
@ -102,7 +97,7 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
override fun onLoadFinished(loader: Loader<List<String>>, members: List<String>) {
|
override fun onLoadFinished(loader: Loader<List<String>>, members: List<String>) {
|
||||||
// We no longer need any subsequent loading events
|
// We no longer need any subsequent loading events
|
||||||
// (they will occur on every activity resume).
|
// (they will occur on every activity resume).
|
||||||
LoaderManager.getInstance(this@EditClosedGroupActivity).destroyLoader(LOADER_ID_MEMBERS)
|
LoaderManager.getInstance(this@EditClosedGroupActivity).destroyLoader(Companion.loaderID)
|
||||||
|
|
||||||
originalMembers.clear()
|
originalMembers.clear()
|
||||||
originalMembers.addAll(members.toHashSet())
|
originalMembers.addAll(members.toHashSet())
|
||||||
@ -122,66 +117,26 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Updating
|
// region Updating
|
||||||
private fun updateMembers(members: Set<String>) {
|
|
||||||
this.members.clear()
|
|
||||||
this.members.addAll(members)
|
|
||||||
this.memberListAdapter.setMembers(members)
|
|
||||||
|
|
||||||
val localUserPublicKey = TextSecurePreferences.getLocalNumber(this)
|
|
||||||
this.memberListAdapter.setLockedMembers(arrayListOf(localUserPublicKey))
|
|
||||||
|
|
||||||
mainContentContainer.visibility = if (members.isEmpty()) View.GONE else View.VISIBLE
|
|
||||||
emptyStateContainer.visibility = if (members.isEmpty()) View.VISIBLE else View.GONE
|
|
||||||
invalidateOptionsMenu()
|
|
||||||
}
|
|
||||||
// endregion
|
|
||||||
|
|
||||||
// region Interaction
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
||||||
when(item.itemId) {
|
|
||||||
R.id.applyButton -> commitClosedGroupChanges()
|
|
||||||
}
|
|
||||||
return super.onOptionsItemSelected(item)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onMemberClick(member: String) {
|
|
||||||
val bottomSheet = GroupEditingOptionsBottomSheet()
|
|
||||||
bottomSheet.onRemoveTapped = {
|
|
||||||
val changedMembers = members - member
|
|
||||||
updateMembers(changedMembers)
|
|
||||||
bottomSheet.dismiss()
|
|
||||||
}
|
|
||||||
// bottomSheet.onAdminTapped = {
|
|
||||||
// bottomSheet.dismiss()
|
|
||||||
// }
|
|
||||||
bottomSheet.show(supportFragmentManager, "MEMBER_BOTTOM_SHEET")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onAddMembersClick() {
|
|
||||||
val intent = Intent(this@EditClosedGroupActivity, SelectContactsActivity::class.java)
|
|
||||||
startActivityForResult(intent, REQ_CODE_ADD_USERS)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
super.onActivityResult(requestCode, resultCode, data)
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
when (requestCode) {
|
when (requestCode) {
|
||||||
REQ_CODE_ADD_USERS -> {
|
Companion.addUsersRequestCode -> {
|
||||||
if (resultCode != RESULT_OK) return
|
if (resultCode != RESULT_OK) return
|
||||||
if (data == null || data.extras == null || !data.hasExtra(EXTRA_RESULT_SELECTED_CONTACTS)) return
|
if (data == null || data.extras == null || !data.hasExtra(SelectContactsActivity.selectedContactsKey)) return
|
||||||
|
|
||||||
val selectedContacts = data.extras!!.getStringArray(EXTRA_RESULT_SELECTED_CONTACTS)!!.toSet()
|
val selectedContacts = data.extras!!.getStringArray(SelectContactsActivity.selectedContactsKey)!!.toSet()
|
||||||
val changedMembers = members + selectedContacts
|
val changedMembers = members + selectedContacts
|
||||||
updateMembers(changedMembers)
|
updateMembers(changedMembers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleIsEditingDisplayNameChanged() {
|
private fun handleIsEditingNameChanged() {
|
||||||
cntGroupNameEdit.visibility = if (isEditingGroupName) View.VISIBLE else View.INVISIBLE
|
cntGroupNameEdit.visibility = if (isEditingName) View.VISIBLE else View.INVISIBLE
|
||||||
cntGroupNameDisplay.visibility = if (isEditingGroupName) View.INVISIBLE else View.VISIBLE
|
cntGroupNameDisplay.visibility = if (isEditingName) View.INVISIBLE else View.VISIBLE
|
||||||
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
if (isEditingGroupName) {
|
if (isEditingName) {
|
||||||
edtGroupName.setText(newGroupDisplayName)
|
edtGroupName.setText(name)
|
||||||
edtGroupName.selectAll()
|
edtGroupName.selectAll()
|
||||||
edtGroupName.requestFocus()
|
edtGroupName.requestFocus()
|
||||||
inputMethodManager.showSoftInput(edtGroupName, 0)
|
inputMethodManager.showSoftInput(edtGroupName, 0)
|
||||||
@ -190,67 +145,98 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveDisplayName() {
|
private fun updateMembers(members: Set<String>) {
|
||||||
val groupDisplayName = edtGroupName.text.toString().trim()
|
this.members.clear()
|
||||||
if (groupDisplayName.isEmpty()) {
|
this.members.addAll(members)
|
||||||
return Toast.makeText(this, R.string.activity_edit_closed_group_group_name_missing_error, Toast.LENGTH_SHORT).show()
|
memberListAdapter.setMembers(members)
|
||||||
|
|
||||||
|
val userPublicKey = TextSecurePreferences.getLocalNumber(this)
|
||||||
|
memberListAdapter.setLockedMembers(arrayListOf(userPublicKey))
|
||||||
|
|
||||||
|
mainContentContainer.visibility = if (members.isEmpty()) View.GONE else View.VISIBLE
|
||||||
|
emptyStateContainer.visibility = if (members.isEmpty()) View.VISIBLE else View.GONE
|
||||||
|
|
||||||
|
invalidateOptionsMenu()
|
||||||
|
}
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region Interaction
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
|
when(item.itemId) {
|
||||||
|
R.id.applyButton -> commitChanges()
|
||||||
}
|
}
|
||||||
// if (groupDisplayName.toByteArray().size > ProfileCipher.NAME_PADDED_LENGTH) {
|
return super.onOptionsItemSelected(item)
|
||||||
if (groupDisplayName.length >= 64) {
|
|
||||||
return Toast.makeText(this, R.string.activity_edit_closed_group_group_name_too_long_error, Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
// if (!groupDisplayName.matches(Regex("[a-zA-Z0-9_]+"))) {
|
|
||||||
// return Toast.makeText(this, R.string.activity_settings_invalid_display_name_error, Toast.LENGTH_SHORT).show()
|
|
||||||
// }
|
|
||||||
newGroupDisplayName = groupDisplayName
|
|
||||||
lblGroupNameDisplay.text = groupDisplayName
|
|
||||||
nameHasChanged = true
|
|
||||||
isEditingGroupName = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun commitClosedGroupChanges() {
|
private fun onMemberClick(member: String) {
|
||||||
val membersHaveChanged = members.size != originalMembers.size || !members.containsAll(originalMembers)
|
val bottomSheet = ClosedGroupEditingOptionsBottomSheet()
|
||||||
|
bottomSheet.onRemoveTapped = {
|
||||||
|
val changedMembers = members - member
|
||||||
|
updateMembers(changedMembers)
|
||||||
|
bottomSheet.dismiss()
|
||||||
|
}
|
||||||
|
bottomSheet.show(supportFragmentManager, "GroupEditingOptionsBottomSheet")
|
||||||
|
}
|
||||||
|
|
||||||
if (!nameHasChanged && !membersHaveChanged) {
|
private fun onAddMembersClick() {
|
||||||
finish()
|
val intent = Intent(this@EditClosedGroupActivity, SelectContactsActivity::class.java)
|
||||||
return
|
startActivityForResult(intent, Companion.addUsersRequestCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun saveName() {
|
||||||
|
val name = edtGroupName.text.toString().trim()
|
||||||
|
if (name.isEmpty()) {
|
||||||
|
return Toast.makeText(this, R.string.activity_edit_closed_group_group_name_missing_error, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
if (name.length >= 64) {
|
||||||
|
return Toast.makeText(this, R.string.activity_edit_closed_group_group_name_too_long_error, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
this.name = name
|
||||||
|
lblGroupNameDisplay.text = name
|
||||||
|
hasNameChanged = true
|
||||||
|
isEditingName = false
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun commitChanges() {
|
||||||
|
val hasMemberListChanges = members != originalMembers
|
||||||
|
|
||||||
|
if (!hasNameChanged && !hasMemberListChanges) {
|
||||||
|
return finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
val groupDisplayName = if (nameHasChanged) newGroupDisplayName else originalName
|
val name = if (hasNameChanged) this.name else originalName
|
||||||
|
|
||||||
val finalGroupMembers = members.map {
|
val members = this.members.map {
|
||||||
Recipient.from(this, Address.fromSerialized(it), false)
|
Recipient.from(this, Address.fromSerialized(it), false)
|
||||||
}.toSet()
|
}.toSet()
|
||||||
|
|
||||||
// val finalGroupAdmins = adminMembers.map {
|
val admins = members.toSet() //TODO For now, consider all the users to be admins.
|
||||||
// Recipient.from(this, Address.fromSerialized(it), false)
|
|
||||||
// }.toSet()
|
|
||||||
val finalGroupAdmins = finalGroupMembers.toSet() //TODO For now, consider all the users are admins.
|
|
||||||
|
|
||||||
var isSSKBasedClosedGroup: Boolean
|
var isSSKBasedClosedGroup: Boolean
|
||||||
var groupPublicKey: String?
|
var groupPublicKey: String?
|
||||||
try {
|
try {
|
||||||
groupPublicKey = GroupUtil.getDecodedId(groupID).toHexString()
|
groupPublicKey = ClosedGroupsProtocol.doubleDecodeGroupID(groupID).toHexString()
|
||||||
isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey)
|
isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
groupPublicKey = null
|
groupPublicKey = null
|
||||||
isSSKBasedClosedGroup = false
|
isSSKBasedClosedGroup = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (finalGroupMembers.size < 2) {
|
if (members.size < 2) {
|
||||||
return Toast.makeText(this, R.string.activity_edit_closed_group_not_enough_group_members_error, Toast.LENGTH_LONG).show()
|
return Toast.makeText(this, R.string.activity_edit_closed_group_not_enough_group_members_error, Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
val maxGroupMembers = if (isSSKBasedClosedGroup) MAX_GROUP_MEMBERS_SSK else MAX_GROUP_MEMBERS_LEGACY
|
|
||||||
if (finalGroupMembers.size > maxGroupMembers) {
|
val maxGroupMembers = if (isSSKBasedClosedGroup) ClosedGroupsProtocol.groupSizeLimit else Companion.legacyGroupSizeLimit
|
||||||
|
if (members.size > maxGroupMembers) {
|
||||||
|
// TODO: Update copy for SSK based closed groups
|
||||||
return Toast.makeText(this, R.string.activity_edit_closed_group_too_many_group_members_error, Toast.LENGTH_LONG).show()
|
return Toast.makeText(this, R.string.activity_edit_closed_group_too_many_group_members_error, Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSSKBasedClosedGroup) {
|
if (isSSKBasedClosedGroup) {
|
||||||
//TODO AC: Should it use "groupPublicKey" or "groupID"?
|
ClosedGroupsProtocol.update(this, groupPublicKey!!, members.map { it.address.serialize() },
|
||||||
ClosedGroupsProtocol.update(this, groupPublicKey!!, finalGroupMembers.map { it.address.serialize() },
|
name, admins.map { it.address.serialize() })
|
||||||
groupDisplayName, finalGroupAdmins.map { it.address.serialize() })
|
|
||||||
} else {
|
} else {
|
||||||
GroupManager.updateGroup(this, groupID, finalGroupMembers, null, groupDisplayName, finalGroupAdmins)
|
GroupManager.updateGroup(this, groupID, members, null, name, admins)
|
||||||
}
|
}
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,12 @@ import org.thoughtcrime.securesms.database.DatabaseFactory
|
|||||||
import org.thoughtcrime.securesms.loki.utilities.ContactUtilities
|
import org.thoughtcrime.securesms.loki.utilities.ContactUtilities
|
||||||
import org.thoughtcrime.securesms.util.AsyncLoader
|
import org.thoughtcrime.securesms.util.AsyncLoader
|
||||||
|
|
||||||
class EditClosedGroupLoader(
|
class EditClosedGroupLoader(context: Context, val groupID: String) : AsyncLoader<List<String>>(context) {
|
||||||
context: Context,
|
|
||||||
val groupID: String
|
|
||||||
) : AsyncLoader<List<String>>(context) {
|
|
||||||
|
|
||||||
override fun loadInBackground(): List<String> {
|
override fun loadInBackground(): List<String> {
|
||||||
val members = DatabaseFactory.getGroupDatabase(context).getGroupMembers(groupID, true)
|
val members = DatabaseFactory.getGroupDatabase(context).getGroupMembers(groupID, true)
|
||||||
return members.map {
|
return members.map {
|
||||||
it.address.toPhoneString()
|
it.address.toPhoneString()
|
||||||
}
|
}
|
||||||
/* TODO:Load admins in the process here */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,11 +9,10 @@ import org.thoughtcrime.securesms.mms.GlideRequests
|
|||||||
import org.thoughtcrime.securesms.recipients.Recipient
|
import org.thoughtcrime.securesms.recipients.Recipient
|
||||||
|
|
||||||
class EditClosedGroupMembersAdapter(
|
class EditClosedGroupMembersAdapter(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val glide: GlideRequests,
|
private val glide: GlideRequests,
|
||||||
private val memberClickListener: ((String) -> Unit)? = null
|
private val memberClickListener: ((String) -> Unit)? = null
|
||||||
) : RecyclerView.Adapter<EditClosedGroupMembersAdapter.ViewHolder>() {
|
) : RecyclerView.Adapter<EditClosedGroupMembersAdapter.ViewHolder>() {
|
||||||
|
|
||||||
private val members = ArrayList<String>()
|
private val members = ArrayList<String>()
|
||||||
private val lockedMembers = HashSet<String>()
|
private val lockedMembers = HashSet<String>()
|
||||||
|
|
||||||
@ -42,10 +41,10 @@ class EditClosedGroupMembersAdapter(
|
|||||||
val lockedMember = lockedMembers.contains(member)
|
val lockedMember = lockedMembers.contains(member)
|
||||||
|
|
||||||
viewHolder.view.bind(Recipient.from(
|
viewHolder.view.bind(Recipient.from(
|
||||||
context,
|
context,
|
||||||
Address.fromSerialized(member), false),
|
Address.fromSerialized(member), false),
|
||||||
glide,
|
glide,
|
||||||
(if (lockedMember) UserView.ActionIndicator.None else UserView.ActionIndicator.Menu))
|
if (lockedMember) UserView.ActionIndicator.None else UserView.ActionIndicator.Menu)
|
||||||
|
|
||||||
if (!lockedMember) {
|
if (!lockedMember) {
|
||||||
viewHolder.view.setOnClickListener { this.memberClickListener?.invoke(member) }
|
viewHolder.view.setOnClickListener { this.memberClickListener?.invoke(member) }
|
||||||
|
@ -15,27 +15,28 @@ import network.loki.messenger.R
|
|||||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||||
import org.thoughtcrime.securesms.mms.GlideApp
|
import org.thoughtcrime.securesms.mms.GlideApp
|
||||||
|
|
||||||
const val EXTRA_RESULT_SELECTED_CONTACTS = "RESULT_SELECTED_CONTACTS"
|
|
||||||
//const val RESULT_CREATE_PRIVATE_CHAT = 100;
|
|
||||||
|
|
||||||
class SelectContactsActivity : PassphraseRequiredActionBarActivity(), LoaderManager.LoaderCallbacks<List<String>> {
|
class SelectContactsActivity : PassphraseRequiredActionBarActivity(), LoaderManager.LoaderCallbacks<List<String>> {
|
||||||
private var members = listOf<String>()
|
private var members = listOf<String>()
|
||||||
set(value) { field = value; selectContactsAdapter.members = value }
|
set(value) { field = value; selectContactsAdapter.members = value }
|
||||||
|
|
||||||
private lateinit var selectContactsAdapter: SelectContactsAdapter
|
private val selectContactsAdapter by lazy {
|
||||||
|
SelectContactsAdapter(this, GlideApp.with(this))
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val selectedContactsKey = "selectedContactsKey"
|
||||||
|
}
|
||||||
|
|
||||||
// region Lifecycle
|
// region Lifecycle
|
||||||
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
|
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
|
||||||
super.onCreate(savedInstanceState, isReady)
|
super.onCreate(savedInstanceState, isReady)
|
||||||
|
|
||||||
setContentView(R.layout.activity_select_contacts)
|
setContentView(R.layout.activity_select_contacts)
|
||||||
supportActionBar!!.title = resources.getString(R.string.activity_select_contacts_title)
|
supportActionBar!!.title = resources.getString(R.string.activity_select_contacts_title)
|
||||||
|
|
||||||
this.selectContactsAdapter = SelectContactsAdapter(this, GlideApp.with(this))
|
|
||||||
recyclerView.adapter = selectContactsAdapter
|
recyclerView.adapter = selectContactsAdapter
|
||||||
recyclerView.layoutManager = LinearLayoutManager(this)
|
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||||
|
|
||||||
// btnCreateNewPrivateChat.setOnClickListener { closeAndCreatePrivateChat() }
|
|
||||||
|
|
||||||
LoaderManager.getInstance(this).initLoader(0, null, this)
|
LoaderManager.getInstance(this).initLoader(0, null, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,16 +75,11 @@ class SelectContactsActivity : PassphraseRequiredActionBarActivity(), LoaderMana
|
|||||||
return super.onOptionsItemSelected(item)
|
return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
// private fun closeAndCreatePrivateChat() {
|
|
||||||
// setResult(RESULT_CREATE_PRIVATE_CHAT)
|
|
||||||
// finish()
|
|
||||||
// }
|
|
||||||
|
|
||||||
private fun closeAndReturnSelected() {
|
private fun closeAndReturnSelected() {
|
||||||
val selectedMembers = this.selectContactsAdapter.selectedMembers
|
val selectedMembers = selectContactsAdapter.selectedMembers
|
||||||
val selectedContacts = selectedMembers.toTypedArray()
|
val selectedContacts = selectedMembers.toTypedArray()
|
||||||
val intent = Intent()
|
val intent = Intent()
|
||||||
intent.putExtra(EXTRA_RESULT_SELECTED_CONTACTS, selectedContacts)
|
intent.putExtra(selectedContactsKey, selectedContacts)
|
||||||
setResult(Activity.RESULT_OK, intent)
|
setResult(Activity.RESULT_OK, intent)
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,8 @@ import org.thoughtcrime.securesms.loki.views.UserView
|
|||||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient
|
import org.thoughtcrime.securesms.recipients.Recipient
|
||||||
|
|
||||||
class SelectContactsAdapter(
|
class SelectContactsAdapter(private val context: Context, private val glide: GlideRequests) : RecyclerView.Adapter<SelectContactsAdapter.ViewHolder>() {
|
||||||
private val context: Context,
|
|
||||||
private val glide: GlideRequests)
|
|
||||||
: RecyclerView.Adapter<SelectContactsAdapter.ViewHolder>() {
|
|
||||||
|
|
||||||
val selectedMembers = mutableSetOf<String>()
|
val selectedMembers = mutableSetOf<String>()
|
||||||
|
|
||||||
var members = listOf<String>()
|
var members = listOf<String>()
|
||||||
set(value) { field = value; notifyDataSetChanged() }
|
set(value) { field = value; notifyDataSetChanged() }
|
||||||
|
|
||||||
@ -34,11 +29,11 @@ class SelectContactsAdapter(
|
|||||||
viewHolder.view.setOnClickListener { onMemberClick(member) }
|
viewHolder.view.setOnClickListener { onMemberClick(member) }
|
||||||
val isSelected = selectedMembers.contains(member)
|
val isSelected = selectedMembers.contains(member)
|
||||||
viewHolder.view.bind(Recipient.from(
|
viewHolder.view.bind(Recipient.from(
|
||||||
context,
|
context,
|
||||||
Address.fromSerialized(member), false),
|
Address.fromSerialized(member), false),
|
||||||
glide,
|
glide,
|
||||||
UserView.ActionIndicator.Tick,
|
UserView.ActionIndicator.Tick,
|
||||||
isSelected)
|
isSelected)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onMemberClick(member: String) {
|
private fun onMemberClick(member: String) {
|
||||||
|
@ -5,20 +5,18 @@ import android.support.design.widget.BottomSheetDialogFragment
|
|||||||
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 kotlinx.android.synthetic.main.fragment_group_edit_bottom_sheet.*
|
import kotlinx.android.synthetic.main.fragment_closed_group_edit_bottom_sheet.*
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
|
|
||||||
public class GroupEditingOptionsBottomSheet : BottomSheetDialogFragment() {
|
public class ClosedGroupEditingOptionsBottomSheet : BottomSheetDialogFragment() {
|
||||||
var onRemoveTapped: (() -> Unit)? = null
|
var onRemoveTapped: (() -> Unit)? = null
|
||||||
// var onAdminTapped: (() -> Unit)? = null
|
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
return inflater.inflate(R.layout.fragment_group_edit_bottom_sheet, container, false)
|
return inflater.inflate(R.layout.fragment_closed_group_edit_bottom_sheet, container, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
removeFromGroup.setOnClickListener { onRemoveTapped?.invoke() }
|
removeFromGroup.setOnClickListener { onRemoveTapped?.invoke() }
|
||||||
// makeAdministrator.setOnClickListener { onAdminTapped?.invoke() }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,6 +33,7 @@ import java.util.*
|
|||||||
|
|
||||||
object ClosedGroupsProtocol {
|
object ClosedGroupsProtocol {
|
||||||
val isSharedSenderKeysEnabled = false
|
val isSharedSenderKeysEnabled = false
|
||||||
|
val groupSizeLimit = 10
|
||||||
|
|
||||||
public fun createClosedGroup(context: Context, name: String, members: Collection<String>): String {
|
public fun createClosedGroup(context: Context, name: String, members: Collection<String>): String {
|
||||||
// Prepare
|
// Prepare
|
||||||
|
Loading…
x
Reference in New Issue
Block a user