mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Edit closed group activitiy cleanup.
This commit is contained in:
parent
f88558a719
commit
6664c2baa7
@ -11,7 +11,7 @@
|
|||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/displayNameContainer"
|
android:id="@+id/ctnGroupNameSection"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="@dimen/large_spacing"
|
android:layout_marginLeft="@dimen/large_spacing"
|
||||||
@ -19,17 +19,17 @@
|
|||||||
android:layout_marginRight="@dimen/large_spacing">
|
android:layout_marginRight="@dimen/large_spacing">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/cancelEditButton"
|
android:id="@+id/btnCancelGroupNameEdit"
|
||||||
android:layout_width="36dp"
|
android:layout_width="36dp"
|
||||||
android:layout_height="36dp"
|
android:layout_height="36dp"
|
||||||
android:layout_toLeftOf="@+id/groupNameEditText"
|
android:layout_toLeftOf="@+id/edtGroupName"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:src="@drawable/ic_close_white_24dp"
|
android:src="@drawable/ic_close_white_24dp"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
style="@style/SessionEditText"
|
style="@style/SessionEditText"
|
||||||
android:id="@+id/groupNameEditText"
|
android:id="@+id/edtGroupName"
|
||||||
android:layout_width="@dimen/album_total_width"
|
android:layout_width="@dimen/album_total_width"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
@ -41,7 +41,7 @@
|
|||||||
android:hint="@string/activity_edit_closed_group_edit_text_hint" />
|
android:hint="@string/activity_edit_closed_group_edit_text_hint" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/displayNameTextView"
|
android:id="@+id/txvGroupNameDisplay"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
@ -52,11 +52,11 @@
|
|||||||
android:drawablePadding="@dimen/small_spacing"/>
|
android:drawablePadding="@dimen/small_spacing"/>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/saveEditButton"
|
android:id="@+id/btnSaveGroupName"
|
||||||
android:layout_width="36dp"
|
android:layout_width="36dp"
|
||||||
android:layout_height="36dp"
|
android:layout_height="36dp"
|
||||||
android:src="@drawable/ic_check_white_24dp"
|
android:src="@drawable/ic_check_white_24dp"
|
||||||
android:layout_toRightOf="@+id/groupNameEditText"
|
android:layout_toRightOf="@+id/edtGroupName"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@
|
|||||||
android:layout_marginTop="@dimen/medium_spacing" />
|
android:layout_marginTop="@dimen/medium_spacing" />
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/displayNameContainer"
|
android:id="@+id/ctnGroupNameSection"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="@dimen/large_spacing"
|
android:layout_marginLeft="@dimen/large_spacing"
|
||||||
@ -97,7 +97,7 @@
|
|||||||
android:hint="@string/activity_settings_display_name_edit_text_hint" />
|
android:hint="@string/activity_settings_display_name_edit_text_hint" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/displayNameTextView"
|
android:id="@+id/txvGroupNameDisplay"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
android:gravity="center_vertical">
|
android:gravity="center_vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/displayNameTextView"
|
android:id="@+id/txvGroupNameDisplay"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/displayNameTextView"
|
android:id="@+id/txvGroupNameDisplay"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="@dimen/medium_spacing"
|
android:layout_marginStart="@dimen/medium_spacing"
|
||||||
|
@ -153,6 +153,7 @@ import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil;
|
|||||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel;
|
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel;
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
import org.thoughtcrime.securesms.loki.activities.EditClosedGroupActivity;
|
import org.thoughtcrime.securesms.loki.activities.EditClosedGroupActivity;
|
||||||
|
import org.thoughtcrime.securesms.loki.activities.EditClosedGroupActivityKt;
|
||||||
import org.thoughtcrime.securesms.loki.activities.HomeActivity;
|
import org.thoughtcrime.securesms.loki.activities.HomeActivity;
|
||||||
import org.thoughtcrime.securesms.loki.database.LokiThreadDatabase;
|
import org.thoughtcrime.securesms.loki.database.LokiThreadDatabase;
|
||||||
import org.thoughtcrime.securesms.loki.database.LokiThreadDatabaseDelegate;
|
import org.thoughtcrime.securesms.loki.database.LokiThreadDatabaseDelegate;
|
||||||
@ -1181,7 +1182,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(EditClosedGroupActivity.GROUP_ID, groupID);
|
intent.putExtra(EditClosedGroupActivityKt.EXTRA_GROUP_ID, groupID);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,9 +30,8 @@ class CreateClosedGroupActivity : PassphraseRequiredActionBarActivity(), MemberC
|
|||||||
set(value) { field = value; createClosedGroupAdapter.members = value }
|
set(value) { field = value; createClosedGroupAdapter.members = value }
|
||||||
|
|
||||||
private val createClosedGroupAdapter by lazy {
|
private val createClosedGroupAdapter by lazy {
|
||||||
val result = SelectContactsAdapter(this)
|
val glide = GlideApp.with(this)
|
||||||
result.glide = GlideApp.with(this)
|
val result = SelectContactsAdapter(this, glide, this)
|
||||||
result.memberClickListener = this
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,10 +14,9 @@ import android.widget.Toast
|
|||||||
import kotlinx.android.synthetic.main.activity_create_closed_group.emptyStateContainer
|
import kotlinx.android.synthetic.main.activity_create_closed_group.emptyStateContainer
|
||||||
import kotlinx.android.synthetic.main.activity_create_closed_group.mainContentContainer
|
import kotlinx.android.synthetic.main.activity_create_closed_group.mainContentContainer
|
||||||
import kotlinx.android.synthetic.main.activity_edit_closed_group.*
|
import kotlinx.android.synthetic.main.activity_edit_closed_group.*
|
||||||
import kotlinx.android.synthetic.main.activity_edit_closed_group.displayNameContainer
|
import kotlinx.android.synthetic.main.activity_edit_closed_group.ctnGroupNameSection
|
||||||
import kotlinx.android.synthetic.main.activity_edit_closed_group.displayNameTextView
|
import kotlinx.android.synthetic.main.activity_edit_closed_group.txvGroupNameDisplay
|
||||||
import kotlinx.android.synthetic.main.activity_linked_devices.recyclerView
|
import kotlinx.android.synthetic.main.activity_linked_devices.recyclerView
|
||||||
import kotlinx.android.synthetic.main.activity_settings.*
|
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||||
import org.thoughtcrime.securesms.database.Address
|
import org.thoughtcrime.securesms.database.Address
|
||||||
@ -28,46 +27,71 @@ import org.thoughtcrime.securesms.mms.GlideApp
|
|||||||
import org.thoughtcrime.securesms.recipients.Recipient
|
import org.thoughtcrime.securesms.recipients.Recipient
|
||||||
import org.whispersystems.signalservice.api.crypto.ProfileCipher
|
import org.whispersystems.signalservice.api.crypto.ProfileCipher
|
||||||
|
|
||||||
class EditClosedGroupActivity : PassphraseRequiredActionBarActivity(), MemberClickListener, LoaderManager.LoaderCallbacks<List<String>> {
|
const val EXTRA_GROUP_ID = "GROUP_ID"
|
||||||
private var members = listOf<String>()
|
const val REQ_CODE_ADD_USERS = 124
|
||||||
set(value) { field = value; editClosedGroupAdapter.members = value }
|
const val LOADER_ID_MEMBERS = 0
|
||||||
|
|
||||||
|
class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
|
||||||
|
|
||||||
|
private lateinit var memberListAdapter: EditClosedGroupMembersAdapter
|
||||||
|
private val originalMembers = HashSet<String>()
|
||||||
|
private val members = HashSet<String>()
|
||||||
|
// private var adminMembers = HashSet<String>()
|
||||||
|
|
||||||
private lateinit var groupID: String
|
private lateinit var groupID: String
|
||||||
private var membersToRemove = listOf<String>()
|
private lateinit var originalName: String
|
||||||
private var membersToAdd = listOf<String>()
|
|
||||||
private var admins = listOf<String>()
|
|
||||||
private val originalName by lazy { DatabaseFactory.getGroupDatabase(this).getGroup(groupID).get().title }
|
|
||||||
private var nameHasChanged = false
|
|
||||||
private lateinit var newGroupDisplayName: String
|
private lateinit var newGroupDisplayName: String
|
||||||
|
|
||||||
|
private var nameHasChanged = false
|
||||||
|
|
||||||
private val editClosedGroupAdapter by lazy {
|
|
||||||
val result = EditClosedGroupAdapter(this)
|
|
||||||
result.glide = GlideApp.with(this)
|
|
||||||
result.memberClickListener = this
|
|
||||||
result
|
|
||||||
}
|
|
||||||
private var isEditingGroupName = false
|
private var isEditingGroupName = false
|
||||||
set(value) { field = value; handleIsEditingDisplayNameChanged() }
|
set(value) { field = value; handleIsEditingDisplayNameChanged() }
|
||||||
|
|
||||||
companion object {
|
|
||||||
@JvmField
|
|
||||||
public val GROUP_ID = "GROUP_ID"
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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)
|
||||||
groupID = intent.getStringExtra(GROUP_ID)
|
|
||||||
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
|
||||||
|
|
||||||
supportActionBar!!.title = resources.getString(R.string.activity_edit_closed_group_title)
|
supportActionBar!!.title = resources.getString(R.string.activity_edit_closed_group_title)
|
||||||
displayNameContainer.setOnClickListener { showEditDisplayNameUI() }
|
|
||||||
displayNameTextView.text = originalName
|
txvGroupNameDisplay.text = originalName
|
||||||
cancelEditButton.setOnClickListener { cancelEditingDisplayName() }
|
ctnGroupNameSection.setOnClickListener { showEditDisplayNameUI() }
|
||||||
saveEditButton.setOnClickListener { saveDisplayName() }
|
btnCancelGroupNameEdit.setOnClickListener { cancelEditingDisplayName() }
|
||||||
recyclerView.adapter = editClosedGroupAdapter
|
btnSaveGroupName.setOnClickListener { saveDisplayName() }
|
||||||
|
|
||||||
|
addMembersClosedGroupButton.setOnClickListener { onAddMembersClick() }
|
||||||
|
|
||||||
|
this.memberListAdapter = EditClosedGroupMembersAdapter(
|
||||||
|
this,
|
||||||
|
GlideApp.with(this),
|
||||||
|
this::onMemberClick
|
||||||
|
)
|
||||||
|
recyclerView.adapter = this.memberListAdapter
|
||||||
recyclerView.layoutManager = LinearLayoutManager(this)
|
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||||
addMembersClosedGroupButton.setOnClickListener { onAddMember() }
|
|
||||||
LoaderManager.getInstance(this).initLoader(0, null, this)
|
// Setup member list loader.
|
||||||
|
LoaderManager.getInstance(this).initLoader(LOADER_ID_MEMBERS, null, object : LoaderManager.LoaderCallbacks<List<String>> {
|
||||||
|
override fun onCreateLoader(id: Int, bundle: Bundle?): Loader<List<String>> {
|
||||||
|
return EditClosedGroupLoader(groupID, this@EditClosedGroupActivity)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLoadFinished(loader: Loader<List<String>>, members: List<String>) {
|
||||||
|
// We no longer need any subsequent loading events
|
||||||
|
// (they will occur on every activity resume)
|
||||||
|
LoaderManager.getInstance(this@EditClosedGroupActivity).destroyLoader(LOADER_ID_MEMBERS)
|
||||||
|
|
||||||
|
originalMembers.clear()
|
||||||
|
originalMembers.addAll(members.toHashSet())
|
||||||
|
updateMembers(originalMembers)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLoaderReset(loader: Loader<List<String>>) {
|
||||||
|
updateMembers(setOf())
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||||
@ -77,20 +101,12 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity(), MemberCli
|
|||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Updating
|
// region Updating
|
||||||
override fun onCreateLoader(id: Int, bundle: Bundle?): Loader<List<String>> {
|
|
||||||
return EditClosedGroupLoader(groupID, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onLoadFinished(loader: Loader<List<String>>, members: List<String>) {
|
|
||||||
update(members)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onLoaderReset(loader: Loader<List<String>>) {
|
private fun updateMembers(members: Set<String>) {
|
||||||
update(listOf())
|
this.members.clear()
|
||||||
}
|
this.members.addAll(members)
|
||||||
|
this.memberListAdapter.setItems(members)
|
||||||
private fun update(members: List<String>) {
|
|
||||||
this.members = members
|
|
||||||
mainContentContainer.visibility = if (members.isEmpty()) View.GONE else View.VISIBLE
|
mainContentContainer.visibility = if (members.isEmpty()) View.GONE else View.VISIBLE
|
||||||
emptyStateContainer.visibility = if (members.isEmpty()) View.VISIBLE else View.GONE
|
emptyStateContainer.visibility = if (members.isEmpty()) View.VISIBLE else View.GONE
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
@ -99,8 +115,7 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity(), MemberCli
|
|||||||
|
|
||||||
// region Interaction
|
// region Interaction
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
val id = item.itemId
|
when(item.itemId) {
|
||||||
when(id) {
|
|
||||||
R.id.applyButton -> modifyClosedGroup()
|
R.id.applyButton -> modifyClosedGroup()
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
return super.onOptionsItemSelected(item)
|
||||||
@ -113,54 +128,54 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity(), MemberCli
|
|||||||
isEditingGroupName = false
|
isEditingGroupName = false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMemberClick(member: String) {
|
private fun onMemberClick(member: String) {
|
||||||
val bottomSheet = GroupEditingOptionsBottomSheet()
|
val bottomSheet = GroupEditingOptionsBottomSheet()
|
||||||
bottomSheet.onRemoveTapped = {
|
bottomSheet.onRemoveTapped = {
|
||||||
membersToRemove = membersToRemove + member
|
val changedMembers = members - member
|
||||||
members = members - member
|
updateMembers(changedMembers)
|
||||||
bottomSheet.dismiss()
|
bottomSheet.dismiss()
|
||||||
}
|
}
|
||||||
// bottomSheet.onAdminTapped = {
|
// bottomSheet.onAdminTapped = {
|
||||||
// bottomSheet.dismiss()
|
// bottomSheet.dismiss()
|
||||||
// }
|
// }
|
||||||
bottomSheet.show(supportFragmentManager, "closeBottomSheet")
|
bottomSheet.show(supportFragmentManager, "MEMBER_BOTTOM_SHEET")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onAddMember() {
|
private fun onAddMembersClick() {
|
||||||
val intent = Intent(this@EditClosedGroupActivity, SelectContactsActivity::class.java)
|
val intent = Intent(this@EditClosedGroupActivity, SelectContactsActivity::class.java)
|
||||||
startActivityForResult(intent, 124)
|
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)
|
||||||
if (resultCode == RESULT_OK) {
|
when (requestCode) {
|
||||||
if (data != null && data.hasExtra("Selected Contacts Result")) {
|
REQ_CODE_ADD_USERS -> {
|
||||||
val returnedContacts = data.extras.getStringArray("Selected Contacts Result")
|
if (resultCode != RESULT_OK) return
|
||||||
val selectedContacts = returnedContacts.toList()
|
if (data == null || data.extras == null || !data.hasExtra(EXTRA_SELECTED_CONTACTS)) return
|
||||||
membersToAdd = selectedContacts + membersToAdd
|
|
||||||
members = members + membersToAdd
|
val selectedContacts = data.extras!!.getStringArray(EXTRA_SELECTED_CONTACTS)!!.toSet()
|
||||||
Toast.makeText(this.applicationContext, membersToAdd.toString(), Toast.LENGTH_LONG).show()
|
val changedMembers = members + selectedContacts
|
||||||
//TODO:this works for users that were already in the group but were removed in the same edit activity, but not users that were never in the chat. WHy?
|
updateMembers(changedMembers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleIsEditingDisplayNameChanged() {
|
private fun handleIsEditingDisplayNameChanged() {
|
||||||
cancelEditButton.visibility = if (isEditingGroupName) View.VISIBLE else View.GONE
|
btnCancelGroupNameEdit.visibility = if (isEditingGroupName) View.VISIBLE else View.GONE
|
||||||
saveEditButton.visibility = if (isEditingGroupName) View.VISIBLE else View.GONE
|
btnSaveGroupName.visibility = if (isEditingGroupName) View.VISIBLE else View.GONE
|
||||||
displayNameTextView.visibility = if (isEditingGroupName) View.INVISIBLE else View.VISIBLE
|
txvGroupNameDisplay.visibility = if (isEditingGroupName) View.INVISIBLE else View.VISIBLE
|
||||||
groupNameEditText.visibility = if (isEditingGroupName) View.VISIBLE else View.INVISIBLE
|
edtGroupName.visibility = if (isEditingGroupName) View.VISIBLE else View.INVISIBLE
|
||||||
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
if (isEditingGroupName) {
|
if (isEditingGroupName) {
|
||||||
groupNameEditText.requestFocus()
|
edtGroupName.requestFocus()
|
||||||
inputMethodManager.showSoftInput(groupNameEditText, 0)
|
inputMethodManager.showSoftInput(edtGroupName, 0)
|
||||||
} else {
|
} else {
|
||||||
inputMethodManager.hideSoftInputFromWindow(groupNameEditText.windowToken, 0)
|
inputMethodManager.hideSoftInputFromWindow(edtGroupName.windowToken, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveDisplayName() {
|
private fun saveDisplayName() {
|
||||||
var groupDisplayName = groupNameEditText.text.toString().trim()
|
val groupDisplayName = edtGroupName.text.toString().trim()
|
||||||
if (groupDisplayName.isEmpty()) {
|
if (groupDisplayName.isEmpty()) {
|
||||||
return Toast.makeText(this, R.string.activity_settings_display_name_missing_error, Toast.LENGTH_SHORT).show()
|
return Toast.makeText(this, R.string.activity_settings_display_name_missing_error, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
@ -171,26 +186,32 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity(), MemberCli
|
|||||||
return Toast.makeText(this, R.string.activity_settings_display_name_too_long_error, Toast.LENGTH_SHORT).show()
|
return Toast.makeText(this, R.string.activity_settings_display_name_too_long_error, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
newGroupDisplayName = groupDisplayName
|
newGroupDisplayName = groupDisplayName
|
||||||
displayNameTextView.text = groupDisplayName
|
txvGroupNameDisplay.text = groupDisplayName
|
||||||
nameHasChanged = true
|
nameHasChanged = true
|
||||||
isEditingGroupName = false
|
isEditingGroupName = false
|
||||||
return Toast.makeText(this, "Name Changed", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun modifyClosedGroup() {
|
private fun modifyClosedGroup() {
|
||||||
if (!nameHasChanged && membersToRemove.isEmpty() && membersToAdd.isEmpty()) { finish() } else {
|
val membersHaveChanged = members.size != originalMembers.size || !members.containsAll(originalMembers)
|
||||||
var groupDisplayName = originalName
|
|
||||||
if (nameHasChanged) {
|
if (!nameHasChanged && !membersHaveChanged) {
|
||||||
groupDisplayName = newGroupDisplayName
|
|
||||||
}
|
|
||||||
val finalGroupMembers = members.map {
|
|
||||||
Recipient.from(this, Address.fromSerialized(it), false)
|
|
||||||
}.toSet()
|
|
||||||
val finalGroupAdmins = admins.map {
|
|
||||||
Recipient.from(this, Address.fromSerialized(it), false)
|
|
||||||
}.toSet()
|
|
||||||
GroupManager.updateGroup(this, groupID, finalGroupMembers, null, groupDisplayName, finalGroupAdmins)
|
|
||||||
finish()
|
finish()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var groupDisplayName = originalName
|
||||||
|
if (nameHasChanged) {
|
||||||
|
groupDisplayName = newGroupDisplayName
|
||||||
|
}
|
||||||
|
|
||||||
|
val finalGroupMembers = members.map {
|
||||||
|
Recipient.from(this, Address.fromSerialized(it), false)
|
||||||
|
}.toSet()
|
||||||
|
// val finalGroupAdmins = adminMembers.map {
|
||||||
|
// Recipient.from(this, Address.fromSerialized(it), false)
|
||||||
|
// }.toSet()
|
||||||
|
val finalGroupAdmins = finalGroupMembers.toSet() //TODO For now, consider all the group's users are admins.
|
||||||
|
GroupManager.updateGroup(this, groupID, finalGroupMembers, null, groupDisplayName, finalGroupAdmins)
|
||||||
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,48 +0,0 @@
|
|||||||
package org.thoughtcrime.securesms.loki.activities
|
|
||||||
|
|
||||||
import android.R
|
|
||||||
import android.app.PendingIntent.getActivity
|
|
||||||
import android.content.Context
|
|
||||||
import android.support.v7.app.AlertDialog
|
|
||||||
import android.support.v7.widget.RecyclerView
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import android.widget.AdapterView
|
|
||||||
import android.widget.EditText
|
|
||||||
import android.widget.LinearLayout
|
|
||||||
import org.thoughtcrime.securesms.DeviceListItem
|
|
||||||
import org.thoughtcrime.securesms.database.Address
|
|
||||||
import org.thoughtcrime.securesms.loki.dialogs.DeviceEditingOptionsBottomSheet
|
|
||||||
import org.thoughtcrime.securesms.loki.dialogs.GroupEditingOptionsBottomSheet
|
|
||||||
import org.thoughtcrime.securesms.loki.utilities.toPx
|
|
||||||
import org.thoughtcrime.securesms.loki.views.UserView
|
|
||||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient
|
|
||||||
|
|
||||||
class EditClosedGroupAdapter(private val context: Context) : RecyclerView.Adapter<EditClosedGroupAdapter.ViewHolder>() {
|
|
||||||
lateinit var glide: GlideRequests
|
|
||||||
private val selectedMembers = mutableSetOf<String>()
|
|
||||||
var members = listOf<String>()
|
|
||||||
set(value) {
|
|
||||||
field = value; notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
var memberClickListener: MemberClickListener? = null
|
|
||||||
|
|
||||||
class ViewHolder(val view: UserView) : RecyclerView.ViewHolder(view)
|
|
||||||
|
|
||||||
override fun getItemCount(): Int {
|
|
||||||
return members.size
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
|
||||||
val view = UserView(context)
|
|
||||||
return ViewHolder(view)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
|
|
||||||
val member = members[position]
|
|
||||||
viewHolder.view.setOnClickListener { memberClickListener?.onMemberClick(member) }
|
|
||||||
val isSelected = selectedMembers.contains(member)
|
|
||||||
viewHolder.view.bind(Recipient.from(context, Address.fromSerialized(member), false), isSelected, glide, true)
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,42 @@
|
|||||||
|
package org.thoughtcrime.securesms.loki.activities
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.support.v7.widget.RecyclerView
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import org.thoughtcrime.securesms.database.Address
|
||||||
|
import org.thoughtcrime.securesms.loki.views.UserView
|
||||||
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||||
|
import org.thoughtcrime.securesms.recipients.Recipient
|
||||||
|
|
||||||
|
class EditClosedGroupMembersAdapter(
|
||||||
|
private val context: Context,
|
||||||
|
private val glide: GlideRequests,
|
||||||
|
private val memberClickListener: ((String) -> Unit)? = null
|
||||||
|
) : RecyclerView.Adapter<EditClosedGroupMembersAdapter.ViewHolder>() {
|
||||||
|
|
||||||
|
private val items = ArrayList<String>()
|
||||||
|
|
||||||
|
// private val selectedItems = mutableSetOf<String>()
|
||||||
|
|
||||||
|
fun setItems(items: Collection<String>) {
|
||||||
|
this.items.clear()
|
||||||
|
this.items.addAll(items)
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int = items.size
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
|
val view = UserView(context)
|
||||||
|
return ViewHolder(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
|
||||||
|
val item = items[position]
|
||||||
|
// val isSelected = selectedItems.contains(item)
|
||||||
|
viewHolder.view.bind(Recipient.from(context, Address.fromSerialized(item), false), false, glide, true)
|
||||||
|
viewHolder.view.setOnClickListener { this.memberClickListener?.invoke(item) }
|
||||||
|
}
|
||||||
|
|
||||||
|
class ViewHolder(val view: UserView) : RecyclerView.ViewHolder(view)
|
||||||
|
}
|
@ -15,14 +15,15 @@ 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_SELECTED_CONTACTS = "SELECTED_CONTACTS_RESULT"
|
||||||
|
|
||||||
class SelectContactsActivity : PassphraseRequiredActionBarActivity(), MemberClickListener, LoaderManager.LoaderCallbacks<List<String>> {
|
class SelectContactsActivity : PassphraseRequiredActionBarActivity(), MemberClickListener, 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 val selectContactsAdapter by lazy {
|
private val selectContactsAdapter by lazy {
|
||||||
val result = SelectContactsAdapter(this)
|
val glide = GlideApp.with(this)
|
||||||
result.glide = GlideApp.with(this)
|
val result = SelectContactsAdapter(this, glide, this)
|
||||||
result.memberClickListener = this
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +95,7 @@ class SelectContactsActivity : PassphraseRequiredActionBarActivity(), MemberClic
|
|||||||
val selectedMembers = this.selectedMembers
|
val selectedMembers = this.selectedMembers
|
||||||
val selectedContacts = selectedMembers.toTypedArray()
|
val selectedContacts = selectedMembers.toTypedArray()
|
||||||
val data = Intent()
|
val data = Intent()
|
||||||
data.putExtra("Selected Contacts Result", selectedContacts)
|
data.putExtra(EXTRA_SELECTED_CONTACTS, selectedContacts)
|
||||||
setResult(Activity.RESULT_OK, data)
|
setResult(Activity.RESULT_OK, data)
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,16 @@ 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(private val context: Context) : RecyclerView.Adapter<SelectContactsAdapter.ViewHolder>() {
|
class SelectContactsAdapter(
|
||||||
lateinit var glide: GlideRequests
|
private val context: Context,
|
||||||
|
private val glide: GlideRequests,
|
||||||
|
private val memberClickListener: MemberClickListener? = null)
|
||||||
|
: 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() }
|
||||||
var memberClickListener: MemberClickListener? = null
|
|
||||||
|
|
||||||
class ViewHolder(val view: UserView) : RecyclerView.ViewHolder(view)
|
class ViewHolder(val view: UserView) : RecyclerView.ViewHolder(view)
|
||||||
|
|
||||||
|
@ -77,8 +77,8 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
profilePictureView.isLarge = true
|
profilePictureView.isLarge = true
|
||||||
profilePictureView.update()
|
profilePictureView.update()
|
||||||
profilePictureView.setOnClickListener { showEditProfilePictureUI() }
|
profilePictureView.setOnClickListener { showEditProfilePictureUI() }
|
||||||
displayNameContainer.setOnClickListener { showEditDisplayNameUI() }
|
ctnGroupNameSection.setOnClickListener { showEditDisplayNameUI() }
|
||||||
displayNameTextView.text = DatabaseFactory.getLokiUserDatabase(this).getDisplayName(hexEncodedPublicKey)
|
txvGroupNameDisplay.text = DatabaseFactory.getLokiUserDatabase(this).getDisplayName(hexEncodedPublicKey)
|
||||||
publicKeyTextView.text = hexEncodedPublicKey
|
publicKeyTextView.text = hexEncodedPublicKey
|
||||||
copyButton.setOnClickListener { copyPublicKey() }
|
copyButton.setOnClickListener { copyPublicKey() }
|
||||||
shareButton.setOnClickListener { sharePublicKey() }
|
shareButton.setOnClickListener { sharePublicKey() }
|
||||||
@ -132,7 +132,7 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
cancelButton.visibility = if (isEditingDisplayName) View.VISIBLE else View.GONE
|
cancelButton.visibility = if (isEditingDisplayName) View.VISIBLE else View.GONE
|
||||||
showQRCodeButton.visibility = if (isEditingDisplayName) View.GONE else View.VISIBLE
|
showQRCodeButton.visibility = if (isEditingDisplayName) View.GONE else View.VISIBLE
|
||||||
saveButton.visibility = if (isEditingDisplayName) View.VISIBLE else View.GONE
|
saveButton.visibility = if (isEditingDisplayName) View.VISIBLE else View.GONE
|
||||||
displayNameTextView.visibility = if (isEditingDisplayName) View.INVISIBLE else View.VISIBLE
|
txvGroupNameDisplay.visibility = if (isEditingDisplayName) View.INVISIBLE else View.VISIBLE
|
||||||
displayNameEditText.visibility = if (isEditingDisplayName) View.VISIBLE else View.INVISIBLE
|
displayNameEditText.visibility = if (isEditingDisplayName) View.VISIBLE else View.INVISIBLE
|
||||||
val titleTextViewLayoutParams = titleTextView.layoutParams as LinearLayout.LayoutParams
|
val titleTextViewLayoutParams = titleTextView.layoutParams as LinearLayout.LayoutParams
|
||||||
titleTextViewLayoutParams.leftMargin = if (isEditingDisplayName) toPx(16, resources) else 0
|
titleTextViewLayoutParams.leftMargin = if (isEditingDisplayName) toPx(16, resources) else 0
|
||||||
@ -176,7 +176,7 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
|
|||||||
}
|
}
|
||||||
all(promises).alwaysUi {
|
all(promises).alwaysUi {
|
||||||
if (displayName != null) {
|
if (displayName != null) {
|
||||||
displayNameTextView.text = displayName
|
txvGroupNameDisplay.text = displayName
|
||||||
}
|
}
|
||||||
displayNameToBeUploaded = null
|
displayNameToBeUploaded = null
|
||||||
if (isUpdatingProfilePicture && profilePicture != null) {
|
if (isUpdatingProfilePicture && profilePicture != null) {
|
||||||
|
@ -80,7 +80,7 @@ class ConversationView : LinearLayout {
|
|||||||
profilePictureView.glide = glide
|
profilePictureView.glide = glide
|
||||||
profilePictureView.update()
|
profilePictureView.update()
|
||||||
val senderDisplayName = if (thread.recipient.isLocalNumber) context.getString(R.string.note_to_self) else if (!thread.recipient.name.isNullOrEmpty()) thread.recipient.name else thread.recipient.address.toString()
|
val senderDisplayName = if (thread.recipient.isLocalNumber) context.getString(R.string.note_to_self) else if (!thread.recipient.name.isNullOrEmpty()) thread.recipient.name else thread.recipient.address.toString()
|
||||||
displayNameTextView.text = senderDisplayName
|
txvGroupNameDisplay.text = senderDisplayName
|
||||||
timestampTextView.text = DateUtils.getBriefRelativeTimeSpanString(context, Locale.getDefault(), thread.date)
|
timestampTextView.text = DateUtils.getBriefRelativeTimeSpanString(context, Locale.getDefault(), thread.date)
|
||||||
muteIndicatorImageView.visibility = if (thread.recipient.isMuted) VISIBLE else GONE
|
muteIndicatorImageView.visibility = if (thread.recipient.isMuted) VISIBLE else GONE
|
||||||
val rawSnippet = thread.getDisplayBody(context)
|
val rawSnippet = thread.getDisplayBody(context)
|
||||||
|
@ -30,7 +30,7 @@ class MentionCandidateView(context: Context, attrs: AttributeSet?, defStyleAttr:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun update() {
|
private fun update() {
|
||||||
displayNameTextView.text = mentionCandidate.displayName
|
txvGroupNameDisplay.text = mentionCandidate.displayName
|
||||||
profilePictureView.publicKey = mentionCandidate.publicKey
|
profilePictureView.publicKey = mentionCandidate.publicKey
|
||||||
profilePictureView.additionalPublicKey = null
|
profilePictureView.additionalPublicKey = null
|
||||||
profilePictureView.isRSSFeed = false
|
profilePictureView.isRSSFeed = false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user