diff --git a/res/layout/contact_selection_list_fragment.xml b/res/layout/contact_selection_list_fragment.xml index 038e28692a..2eb74847f8 100644 --- a/res/layout/contact_selection_list_fragment.xml +++ b/res/layout/contact_selection_list_fragment.xml @@ -1,13 +1,13 @@ - + android:layout_height="match_parent"> + + android:id="@+id/swipeRefreshLayout" + android:layout_width="match_parent" + android:layout_height="match_parent"> - + android:textSize="@dimen/large_font_size" /> diff --git a/res/values/strings.xml b/res/values/strings.xml index 8d5e300f2a..1f8e364b2b 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1668,9 +1668,7 @@ Are you sure you want to leave this group? Are you sure you want to delete this conversation? Conversation deleted - - - Contacts - Groups - Public Chats + Contacts + Closed Groups + Open Groups diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/CreateClosedGroupLoader.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/CreateClosedGroupLoader.kt index a10d1ac18f..89fcd2ef26 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/activities/CreateClosedGroupLoader.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/CreateClosedGroupLoader.kt @@ -8,7 +8,7 @@ class CreateClosedGroupLoader(context: Context) : AsyncLoader>(cont override fun loadInBackground(): List { val contacts = ContactUtilities.getAllContacts(context) - // Only show the master device of the users we are friends with + // Only show the master devices of the users we are friends with return contacts.filter { contact -> !contact.recipient.isGroupRecipient && contact.isFriend && !contact.isOurDevice && !contact.isSlave }.map { diff --git a/src/org/thoughtcrime/securesms/loki/redesign/fragments/contactselection/ContactSelectionListAdapter.kt b/src/org/thoughtcrime/securesms/loki/redesign/fragments/contactselection/ContactSelectionListAdapter.kt index 8fe3fffe30..f0dc5057bf 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/fragments/contactselection/ContactSelectionListAdapter.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/fragments/contactselection/ContactSelectionListAdapter.kt @@ -12,20 +12,19 @@ import org.thoughtcrime.securesms.mms.GlideRequests import org.thoughtcrime.securesms.recipients.Recipient class ContactSelectionListAdapter(private val context: Context, private val multiSelect: Boolean) : RecyclerView.Adapter() { - - private object ViewType { - const val Contact = 0 - const val Divider = 1 - } - lateinit var glide: GlideRequests val selectedContacts = mutableSetOf() var items = listOf() set(value) { field = value; notifyDataSetChanged() } var contactClickListener: ContactClickListener? = null + private object ViewType { + const val Contact = 0 + const val Divider = 1 + } + class UserViewHolder(val view: UserView) : RecyclerView.ViewHolder(view) - class DividerViewHolder(val view: View): RecyclerView.ViewHolder(view) + class DividerViewHolder(val view: View) : RecyclerView.ViewHolder(view) override fun getItemCount(): Int { return items.size diff --git a/src/org/thoughtcrime/securesms/loki/redesign/fragments/contactselection/ContactSelectionListFragment.kt b/src/org/thoughtcrime/securesms/loki/redesign/fragments/contactselection/ContactSelectionListFragment.kt index 0fb530da0d..a4dcc92af5 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/fragments/contactselection/ContactSelectionListFragment.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/fragments/contactselection/ContactSelectionListFragment.kt @@ -16,18 +16,16 @@ import org.thoughtcrime.securesms.mms.GlideApp import org.thoughtcrime.securesms.recipients.Recipient class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks>, ContactClickListener { - - companion object { - @JvmField val DISPLAY_MODE = "display_mode" - @JvmField val MULTI_SELECT = "multi_select" - @JvmField val REFRESHABLE = "refreshable" - } - + private var cursorFilter: String? = null var onContactSelectedListener: OnContactSelectedListener? = null val selectedContacts: List get() = listAdapter.selectedContacts.map { it.address.serialize() } + private val multiSelect: Boolean by lazy { + activity!!.intent.getBooleanExtra(MULTI_SELECT, false) + } + private val listAdapter by lazy { val result = ContactSelectionListAdapter(activity!!, multiSelect) result.glide = GlideApp.with(this) @@ -35,18 +33,22 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks> { @@ -107,9 +109,4 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks>(context) { @@ -35,6 +35,7 @@ class ContactSelectionListLoader(context: Context, val mode: Int, val filter: St } val list = mutableListOf() + if (isFlagSet(DisplayMode.FLAG_CLOSED_GROUPS)) { list.addAll(getClosedGroups(contacts)) } @@ -51,19 +52,19 @@ class ContactSelectionListLoader(context: Context, val mode: Int, val filter: St } private fun getFriends(contacts: List): List { - return getItems(contacts, context.getString(R.string.ContactSelectionListLoader_contacts)) { + return getItems(contacts, context.getString(R.string.fragment_contact_selection_contacts_title)) { !it.recipient.isGroupRecipient && it.isFriend && !it.isOurDevice && !it.isSlave } } private fun getClosedGroups(contacts: List): List { - return getItems(contacts, context.getString(R.string.ContactSelectionListLoader_closed_groups)) { + return getItems(contacts, context.getString(R.string.fragment_contact_selection_closed_groups_title)) { it.recipient.address.isSignalGroup } } private fun getOpenGroups(contacts: List): List { - return getItems(contacts, context.getString(R.string.ContactSelectionListLoader_open_groups)) { + return getItems(contacts, context.getString(R.string.fragment_contact_selection_open_groups_title)) { it.recipient.address.isPublicChat } } @@ -72,9 +73,11 @@ class ContactSelectionListLoader(context: Context, val mode: Int, val filter: St val items = contacts.filter(contactFilter).map { ContactSelectionListItem.Contact(it.recipient) } + if (items.isEmpty()) return listOf() val header = ContactSelectionListItem.Header(title) + return listOf(header) + items } } \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/loki/redesign/utilities/ContactUtilities.kt b/src/org/thoughtcrime/securesms/loki/redesign/utilities/ContactUtilities.kt index d8634b7beb..450ce571c3 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/utilities/ContactUtilities.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/utilities/ContactUtilities.kt @@ -12,12 +12,11 @@ data class Contact( val isSlave: Boolean, val isOurDevice: Boolean ) { + override fun equals(other: Any?): Boolean { if (this === other) return true if (other?.javaClass != javaClass) return false - other as Contact - return recipient == other.recipient } @@ -34,15 +33,11 @@ object ContactUtilities { val lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context) val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context) val lokiAPIDatabase = DatabaseFactory.getLokiAPIDatabase(context) - val groupDatabase = DatabaseFactory.getGroupDatabase(context) - val lokiUserDatabase = DatabaseFactory.getLokiUserDatabase(context) - val ourDeviceLinks = lokiAPIDatabase.getDeviceLinks(userHexEncodedPublicKey) val ourDevices = ourDeviceLinks.flatMap { listOf( it.masterHexEncodedPublicKey.toLowerCase(), it.slaveHexEncodedPublicKey.toLowerCase() ) }.toMutableSet() ourDevices.add(userHexEncodedPublicKey.toLowerCase()) - val cursor = threadDatabase.conversationList val result = mutableSetOf() threadDatabase.readerFor(cursor).use { reader -> @@ -50,7 +45,6 @@ object ContactUtilities { val thread = reader.current val recipient = thread.recipient val address = recipient.address.serialize() - val isOurDevice = ourDevices.contains(address) val isFriend = lokiThreadDatabase.getFriendRequestStatus(thread.threadId) == LokiThreadFriendRequestStatus.FRIENDS var isSlave = false @@ -58,12 +52,9 @@ object ContactUtilities { val deviceLinks = lokiAPIDatabase.getDeviceLinks(address) isSlave = deviceLinks.find { it.slaveHexEncodedPublicKey == address } != null } - result.add(Contact(recipient, isFriend, isSlave, isOurDevice)) } } - return result } - } \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/loki/redesign/views/UserView.kt b/src/org/thoughtcrime/securesms/loki/redesign/views/UserView.kt index a7968ed6d7..6df9b4ad60 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/views/UserView.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/views/UserView.kt @@ -47,13 +47,13 @@ class UserView : LinearLayout { fun bind(user: Recipient, isSelected: Boolean, glide: GlideRequests) { val address = user.address.serialize() if (user.isGroupRecipient) { - if (user.address.isPublicChat || user.address.isRSSFeed) { + if ("Session Public Chat" == user.name || user.address.isRSSFeed) { profilePictureView.hexEncodedPublicKey = "" profilePictureView.additionalHexEncodedPublicKey = null profilePictureView.isRSSFeed = true } else { - val threadId = GroupManager.getThreadIdFromGroupId(address, context) - val users = LokiAPI.userHexEncodedPublicKeyCache[threadId]?.toList() ?: listOf() + val threadID = GroupManager.getThreadIdFromGroupId(address, context) + val users = LokiAPI.userHexEncodedPublicKeyCache[threadID]?.toList() ?: listOf() val randomUsers = users.sorted() // Sort to provide a level of stability profilePictureView.hexEncodedPublicKey = randomUsers.getOrNull(0) ?: "" profilePictureView.additionalHexEncodedPublicKey = randomUsers.getOrNull(1) ?: ""