This commit is contained in:
nielsandriesse 2020-05-06 11:43:04 +10:00
parent 42d74208ff
commit 4599407b3a
8 changed files with 52 additions and 62 deletions

View File

@ -1,13 +1,13 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/emptyStateContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal|center_vertical"
android:gravity="center"
android:orientation="vertical">
<TextView
@ -16,6 +16,7 @@
android:text="You don't have any contacts yet"
android:textColor="@color/text"
android:textSize="@dimen/medium_font_size" />
</LinearLayout>
<LinearLayout
@ -25,9 +26,9 @@
android:orientation="vertical">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefresh"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
@ -36,13 +37,14 @@
android:clipToPadding="false"
android:scrollbars="vertical" />
<TextView android:id="@android:id/empty"
<TextView
android:id="@+id/loadingTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|center_vertical"
android:layout_marginTop="15dp"
android:gravity="center"
android:textColor="@color/text"
android:text="@string/contact_selection_group_activity__finding_contacts"
android:textSize="20sp" />
android:textSize="@dimen/large_font_size" />
</android.support.v4.widget.SwipeRefreshLayout>

View File

@ -1668,9 +1668,7 @@
<string name="activity_home_leave_group_dialog_message">Are you sure you want to leave this group?</string>
<string name="activity_home_delete_conversation_dialog_message">Are you sure you want to delete this conversation?</string>
<string name="activity_home_conversation_deleted_message">Conversation deleted</string>
<!-- ContactSelectionListLoader -->
<string name="ContactSelectionListLoader_contacts">Contacts</string>
<string name="ContactSelectionListLoader_closed_groups">Groups</string>
<string name="ContactSelectionListLoader_open_groups">Public Chats</string>
<string name="fragment_contact_selection_contacts_title">Contacts</string>
<string name="fragment_contact_selection_closed_groups_title">Closed Groups</string>
<string name="fragment_contact_selection_open_groups_title">Open Groups</string>
</resources>

View File

@ -8,7 +8,7 @@ class CreateClosedGroupLoader(context: Context) : AsyncLoader<List<String>>(cont
override fun loadInBackground(): List<String> {
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 {

View File

@ -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<RecyclerView.ViewHolder>() {
private object ViewType {
const val Contact = 0
const val Divider = 1
}
lateinit var glide: GlideRequests
val selectedContacts = mutableSetOf<Recipient>()
var items = listOf<ContactSelectionListItem>()
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

View File

@ -16,18 +16,16 @@ import org.thoughtcrime.securesms.mms.GlideApp
import org.thoughtcrime.securesms.recipients.Recipient
class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<List<ContactSelectionListItem>>, 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<String>
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<L
result
}
private val multiSelect: Boolean by lazy {
activity!!.intent.getBooleanExtra(MULTI_SELECT, false)
companion object {
@JvmField val DISPLAY_MODE = "display_mode"
@JvmField val MULTI_SELECT = "multi_select"
@JvmField val REFRESHABLE = "refreshable"
}
private var cursorFilter: String? = null
interface OnContactSelectedListener {
fun onContactSelected(number: String?)
fun onContactDeselected(number: String?)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
recyclerView.layoutManager = LinearLayoutManager(activity)
recyclerView.adapter = listAdapter
swipeRefresh.isEnabled = activity!!.intent.getBooleanExtra(REFRESHABLE, true)
swipeRefreshLayout.isEnabled = activity!!.intent.getBooleanExtra(REFRESHABLE, true)
}
override fun onStart() {
@ -65,15 +67,15 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<L
fun resetQueryFilter() {
setQueryFilter(null)
swipeRefresh.isRefreshing = false
swipeRefreshLayout.isRefreshing = false
}
fun setRefreshing(refreshing: Boolean) {
swipeRefresh.isRefreshing = refreshing
swipeRefreshLayout.isRefreshing = refreshing
}
fun setOnRefreshListener(onRefreshListener: OnRefreshListener?) {
this.swipeRefresh.setOnRefreshListener(onRefreshListener)
swipeRefreshLayout.setOnRefreshListener(onRefreshListener)
}
override fun onCreateLoader(id: Int, args: Bundle?): Loader<List<ContactSelectionListItem>> {
@ -107,9 +109,4 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<L
override fun onContactDeselected(contact: Recipient) {
onContactSelectedListener?.onContactDeselected(contact.address.serialize())
}
interface OnContactSelectedListener {
fun onContactSelected(number: String?)
fun onContactDeselected(number: String?)
}
}

View File

@ -8,8 +8,8 @@ import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.util.AsyncLoader
sealed class ContactSelectionListItem {
class Header(val name: String): ContactSelectionListItem()
class Contact(val recipient: Recipient): ContactSelectionListItem()
class Header(val name: String) : ContactSelectionListItem()
class Contact(val recipient: Recipient) : ContactSelectionListItem()
}
class ContactSelectionListLoader(context: Context, val mode: Int, val filter: String?) : AsyncLoader<List<ContactSelectionListItem>>(context) {
@ -35,6 +35,7 @@ class ContactSelectionListLoader(context: Context, val mode: Int, val filter: St
}
val list = mutableListOf<ContactSelectionListItem>()
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<Contact>): List<ContactSelectionListItem> {
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<Contact>): List<ContactSelectionListItem> {
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<Contact>): List<ContactSelectionListItem> {
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
}
}

View File

@ -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<Contact>()
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
}
}

View File

@ -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) ?: ""