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">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/displayNameContainer"
|
||||
android:id="@+id/ctnGroupNameSection"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/large_spacing"
|
||||
@ -19,17 +19,17 @@
|
||||
android:layout_marginRight="@dimen/large_spacing">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cancelEditButton"
|
||||
android:id="@+id/btnCancelGroupNameEdit"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_toLeftOf="@+id/groupNameEditText"
|
||||
android:layout_toLeftOf="@+id/edtGroupName"
|
||||
android:layout_centerVertical="true"
|
||||
android:src="@drawable/ic_close_white_24dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<EditText
|
||||
style="@style/SessionEditText"
|
||||
android:id="@+id/groupNameEditText"
|
||||
android:id="@+id/edtGroupName"
|
||||
android:layout_width="@dimen/album_total_width"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
@ -41,7 +41,7 @@
|
||||
android:hint="@string/activity_edit_closed_group_edit_text_hint" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/displayNameTextView"
|
||||
android:id="@+id/txvGroupNameDisplay"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
@ -52,11 +52,11 @@
|
||||
android:drawablePadding="@dimen/small_spacing"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/saveEditButton"
|
||||
android:id="@+id/btnSaveGroupName"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:src="@drawable/ic_check_white_24dp"
|
||||
android:layout_toRightOf="@+id/groupNameEditText"
|
||||
android:layout_toRightOf="@+id/edtGroupName"
|
||||
android:layout_centerVertical="true"
|
||||
android:visibility="gone" />
|
||||
|
||||
|
@ -77,7 +77,7 @@
|
||||
android:layout_marginTop="@dimen/medium_spacing" />
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/displayNameContainer"
|
||||
android:id="@+id/ctnGroupNameSection"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/large_spacing"
|
||||
@ -97,7 +97,7 @@
|
||||
android:hint="@string/activity_settings_display_name_edit_text_hint" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/displayNameTextView"
|
||||
android:id="@+id/txvGroupNameDisplay"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
|
@ -35,7 +35,7 @@
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/displayNameTextView"
|
||||
android:id="@+id/txvGroupNameDisplay"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
|
@ -30,7 +30,7 @@
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/displayNameTextView"
|
||||
android:id="@+id/txvGroupNameDisplay"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
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.logging.Log;
|
||||
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.database.LokiThreadDatabase;
|
||||
import org.thoughtcrime.securesms.loki.database.LokiThreadDatabaseDelegate;
|
||||
@ -1181,7 +1182,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
private void handleEditPushGroup() {
|
||||
Intent intent = new Intent(this, EditClosedGroupActivity.class);
|
||||
String groupID = this.recipient.getAddress().toGroupString();
|
||||
intent.putExtra(EditClosedGroupActivity.GROUP_ID, groupID);
|
||||
intent.putExtra(EditClosedGroupActivityKt.EXTRA_GROUP_ID, groupID);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
|
@ -30,9 +30,8 @@ class CreateClosedGroupActivity : PassphraseRequiredActionBarActivity(), MemberC
|
||||
set(value) { field = value; createClosedGroupAdapter.members = value }
|
||||
|
||||
private val createClosedGroupAdapter by lazy {
|
||||
val result = SelectContactsAdapter(this)
|
||||
result.glide = GlideApp.with(this)
|
||||
result.memberClickListener = this
|
||||
val glide = GlideApp.with(this)
|
||||
val result = SelectContactsAdapter(this, glide, this)
|
||||
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.mainContentContainer
|
||||
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.displayNameTextView
|
||||
import kotlinx.android.synthetic.main.activity_edit_closed_group.ctnGroupNameSection
|
||||
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_settings.*
|
||||
import network.loki.messenger.R
|
||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||
import org.thoughtcrime.securesms.database.Address
|
||||
@ -28,46 +27,71 @@ import org.thoughtcrime.securesms.mms.GlideApp
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.whispersystems.signalservice.api.crypto.ProfileCipher
|
||||
|
||||
class EditClosedGroupActivity : PassphraseRequiredActionBarActivity(), MemberClickListener, LoaderManager.LoaderCallbacks<List<String>> {
|
||||
private var members = listOf<String>()
|
||||
set(value) { field = value; editClosedGroupAdapter.members = value }
|
||||
const val EXTRA_GROUP_ID = "GROUP_ID"
|
||||
const val REQ_CODE_ADD_USERS = 124
|
||||
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 var membersToRemove = listOf<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 originalName: 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
|
||||
set(value) { field = value; handleIsEditingDisplayNameChanged() }
|
||||
|
||||
companion object {
|
||||
@JvmField
|
||||
public val GROUP_ID = "GROUP_ID"
|
||||
}
|
||||
|
||||
// region Lifecycle
|
||||
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
|
||||
super.onCreate(savedInstanceState, isReady)
|
||||
groupID = intent.getStringExtra(GROUP_ID)
|
||||
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)
|
||||
displayNameContainer.setOnClickListener { showEditDisplayNameUI() }
|
||||
displayNameTextView.text = originalName
|
||||
cancelEditButton.setOnClickListener { cancelEditingDisplayName() }
|
||||
saveEditButton.setOnClickListener { saveDisplayName() }
|
||||
recyclerView.adapter = editClosedGroupAdapter
|
||||
|
||||
txvGroupNameDisplay.text = originalName
|
||||
ctnGroupNameSection.setOnClickListener { showEditDisplayNameUI() }
|
||||
btnCancelGroupNameEdit.setOnClickListener { cancelEditingDisplayName() }
|
||||
btnSaveGroupName.setOnClickListener { saveDisplayName() }
|
||||
|
||||
addMembersClosedGroupButton.setOnClickListener { onAddMembersClick() }
|
||||
|
||||
this.memberListAdapter = EditClosedGroupMembersAdapter(
|
||||
this,
|
||||
GlideApp.with(this),
|
||||
this::onMemberClick
|
||||
)
|
||||
recyclerView.adapter = this.memberListAdapter
|
||||
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 {
|
||||
@ -77,20 +101,12 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity(), MemberCli
|
||||
// endregion
|
||||
|
||||
// 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>>) {
|
||||
update(listOf())
|
||||
}
|
||||
|
||||
private fun update(members: List<String>) {
|
||||
this.members = members
|
||||
private fun updateMembers(members: Set<String>) {
|
||||
this.members.clear()
|
||||
this.members.addAll(members)
|
||||
this.memberListAdapter.setItems(members)
|
||||
mainContentContainer.visibility = if (members.isEmpty()) View.GONE else View.VISIBLE
|
||||
emptyStateContainer.visibility = if (members.isEmpty()) View.VISIBLE else View.GONE
|
||||
invalidateOptionsMenu()
|
||||
@ -99,8 +115,7 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity(), MemberCli
|
||||
|
||||
// region Interaction
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
val id = item.itemId
|
||||
when(id) {
|
||||
when(item.itemId) {
|
||||
R.id.applyButton -> modifyClosedGroup()
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
@ -113,54 +128,54 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity(), MemberCli
|
||||
isEditingGroupName = false
|
||||
}
|
||||
|
||||
override fun onMemberClick(member: String) {
|
||||
private fun onMemberClick(member: String) {
|
||||
val bottomSheet = GroupEditingOptionsBottomSheet()
|
||||
bottomSheet.onRemoveTapped = {
|
||||
membersToRemove = membersToRemove + member
|
||||
members = members - member
|
||||
val changedMembers = members - member
|
||||
updateMembers(changedMembers)
|
||||
bottomSheet.dismiss()
|
||||
}
|
||||
// bottomSheet.onAdminTapped = {
|
||||
// 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)
|
||||
startActivityForResult(intent, 124)
|
||||
startActivityForResult(intent, REQ_CODE_ADD_USERS)
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (data != null && data.hasExtra("Selected Contacts Result")) {
|
||||
val returnedContacts = data.extras.getStringArray("Selected Contacts Result")
|
||||
val selectedContacts = returnedContacts.toList()
|
||||
membersToAdd = selectedContacts + membersToAdd
|
||||
members = members + membersToAdd
|
||||
Toast.makeText(this.applicationContext, membersToAdd.toString(), Toast.LENGTH_LONG).show()
|
||||
//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?
|
||||
when (requestCode) {
|
||||
REQ_CODE_ADD_USERS -> {
|
||||
if (resultCode != RESULT_OK) return
|
||||
if (data == null || data.extras == null || !data.hasExtra(EXTRA_SELECTED_CONTACTS)) return
|
||||
|
||||
val selectedContacts = data.extras!!.getStringArray(EXTRA_SELECTED_CONTACTS)!!.toSet()
|
||||
val changedMembers = members + selectedContacts
|
||||
updateMembers(changedMembers)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleIsEditingDisplayNameChanged() {
|
||||
cancelEditButton.visibility = if (isEditingGroupName) View.VISIBLE else View.GONE
|
||||
saveEditButton.visibility = if (isEditingGroupName) View.VISIBLE else View.GONE
|
||||
displayNameTextView.visibility = if (isEditingGroupName) View.INVISIBLE else View.VISIBLE
|
||||
groupNameEditText.visibility = if (isEditingGroupName) View.VISIBLE else View.INVISIBLE
|
||||
btnCancelGroupNameEdit.visibility = if (isEditingGroupName) View.VISIBLE else View.GONE
|
||||
btnSaveGroupName.visibility = if (isEditingGroupName) View.VISIBLE else View.GONE
|
||||
txvGroupNameDisplay.visibility = if (isEditingGroupName) View.INVISIBLE else View.VISIBLE
|
||||
edtGroupName.visibility = if (isEditingGroupName) View.VISIBLE else View.INVISIBLE
|
||||
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
if (isEditingGroupName) {
|
||||
groupNameEditText.requestFocus()
|
||||
inputMethodManager.showSoftInput(groupNameEditText, 0)
|
||||
edtGroupName.requestFocus()
|
||||
inputMethodManager.showSoftInput(edtGroupName, 0)
|
||||
} else {
|
||||
inputMethodManager.hideSoftInputFromWindow(groupNameEditText.windowToken, 0)
|
||||
inputMethodManager.hideSoftInputFromWindow(edtGroupName.windowToken, 0)
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveDisplayName() {
|
||||
var groupDisplayName = groupNameEditText.text.toString().trim()
|
||||
val groupDisplayName = edtGroupName.text.toString().trim()
|
||||
if (groupDisplayName.isEmpty()) {
|
||||
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()
|
||||
}
|
||||
newGroupDisplayName = groupDisplayName
|
||||
displayNameTextView.text = groupDisplayName
|
||||
txvGroupNameDisplay.text = groupDisplayName
|
||||
nameHasChanged = true
|
||||
isEditingGroupName = false
|
||||
return Toast.makeText(this, "Name Changed", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
private fun modifyClosedGroup() {
|
||||
if (!nameHasChanged && membersToRemove.isEmpty() && membersToAdd.isEmpty()) { finish() } else {
|
||||
var groupDisplayName = originalName
|
||||
if (nameHasChanged) {
|
||||
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)
|
||||
val membersHaveChanged = members.size != originalMembers.size || !members.containsAll(originalMembers)
|
||||
|
||||
if (!nameHasChanged && !membersHaveChanged) {
|
||||
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.mms.GlideApp
|
||||
|
||||
const val EXTRA_SELECTED_CONTACTS = "SELECTED_CONTACTS_RESULT"
|
||||
|
||||
class SelectContactsActivity : PassphraseRequiredActionBarActivity(), MemberClickListener, LoaderManager.LoaderCallbacks<List<String>> {
|
||||
private var members = listOf<String>()
|
||||
set(value) { field = value; selectContactsAdapter.members = value }
|
||||
|
||||
private val selectContactsAdapter by lazy {
|
||||
val result = SelectContactsAdapter(this)
|
||||
result.glide = GlideApp.with(this)
|
||||
result.memberClickListener = this
|
||||
val glide = GlideApp.with(this)
|
||||
val result = SelectContactsAdapter(this, glide, this)
|
||||
result
|
||||
}
|
||||
|
||||
@ -94,7 +95,7 @@ class SelectContactsActivity : PassphraseRequiredActionBarActivity(), MemberClic
|
||||
val selectedMembers = this.selectedMembers
|
||||
val selectedContacts = selectedMembers.toTypedArray()
|
||||
val data = Intent()
|
||||
data.putExtra("Selected Contacts Result", selectedContacts)
|
||||
data.putExtra(EXTRA_SELECTED_CONTACTS, selectedContacts)
|
||||
setResult(Activity.RESULT_OK, data)
|
||||
finish()
|
||||
}
|
||||
|
@ -8,12 +8,16 @@ import org.thoughtcrime.securesms.loki.views.UserView
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
|
||||
class SelectContactsAdapter(private val context: Context) : RecyclerView.Adapter<SelectContactsAdapter.ViewHolder>() {
|
||||
lateinit var glide: GlideRequests
|
||||
class SelectContactsAdapter(
|
||||
private val context: Context,
|
||||
private val glide: GlideRequests,
|
||||
private val memberClickListener: MemberClickListener? = null)
|
||||
: RecyclerView.Adapter<SelectContactsAdapter.ViewHolder>() {
|
||||
|
||||
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)
|
||||
|
||||
|
@ -77,8 +77,8 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
|
||||
profilePictureView.isLarge = true
|
||||
profilePictureView.update()
|
||||
profilePictureView.setOnClickListener { showEditProfilePictureUI() }
|
||||
displayNameContainer.setOnClickListener { showEditDisplayNameUI() }
|
||||
displayNameTextView.text = DatabaseFactory.getLokiUserDatabase(this).getDisplayName(hexEncodedPublicKey)
|
||||
ctnGroupNameSection.setOnClickListener { showEditDisplayNameUI() }
|
||||
txvGroupNameDisplay.text = DatabaseFactory.getLokiUserDatabase(this).getDisplayName(hexEncodedPublicKey)
|
||||
publicKeyTextView.text = hexEncodedPublicKey
|
||||
copyButton.setOnClickListener { copyPublicKey() }
|
||||
shareButton.setOnClickListener { sharePublicKey() }
|
||||
@ -132,7 +132,7 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
|
||||
cancelButton.visibility = if (isEditingDisplayName) View.VISIBLE else View.GONE
|
||||
showQRCodeButton.visibility = if (isEditingDisplayName) View.GONE else View.VISIBLE
|
||||
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
|
||||
val titleTextViewLayoutParams = titleTextView.layoutParams as LinearLayout.LayoutParams
|
||||
titleTextViewLayoutParams.leftMargin = if (isEditingDisplayName) toPx(16, resources) else 0
|
||||
@ -176,7 +176,7 @@ class SettingsActivity : PassphraseRequiredActionBarActivity() {
|
||||
}
|
||||
all(promises).alwaysUi {
|
||||
if (displayName != null) {
|
||||
displayNameTextView.text = displayName
|
||||
txvGroupNameDisplay.text = displayName
|
||||
}
|
||||
displayNameToBeUploaded = null
|
||||
if (isUpdatingProfilePicture && profilePicture != null) {
|
||||
|
@ -80,7 +80,7 @@ class ConversationView : LinearLayout {
|
||||
profilePictureView.glide = glide
|
||||
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()
|
||||
displayNameTextView.text = senderDisplayName
|
||||
txvGroupNameDisplay.text = senderDisplayName
|
||||
timestampTextView.text = DateUtils.getBriefRelativeTimeSpanString(context, Locale.getDefault(), thread.date)
|
||||
muteIndicatorImageView.visibility = if (thread.recipient.isMuted) VISIBLE else GONE
|
||||
val rawSnippet = thread.getDisplayBody(context)
|
||||
|
@ -30,7 +30,7 @@ class MentionCandidateView(context: Context, attrs: AttributeSet?, defStyleAttr:
|
||||
}
|
||||
|
||||
private fun update() {
|
||||
displayNameTextView.text = mentionCandidate.displayName
|
||||
txvGroupNameDisplay.text = mentionCandidate.displayName
|
||||
profilePictureView.publicKey = mentionCandidate.publicKey
|
||||
profilePictureView.additionalPublicKey = null
|
||||
profilePictureView.isRSSFeed = false
|
||||
|
Loading…
x
Reference in New Issue
Block a user