diff --git a/res/layout/contact_selection_activity.xml b/res/layout/contact_selection_activity.xml
index 1ad3e1343c..b14d81f2bf 100644
--- a/res/layout/contact_selection_activity.xml
+++ b/res/layout/contact_selection_activity.xml
@@ -19,6 +19,6 @@
+ android:name="org.thoughtcrime.securesms.loki.redesign.fragments.contactselection.ContactSelectionListFragment" />
\ No newline at end of file
diff --git a/res/layout/contact_selection_list_fragment.xml b/res/layout/contact_selection_list_fragment.xml
index ee9d18b434..038e28692a 100644
--- a/res/layout/contact_selection_list_fragment.xml
+++ b/res/layout/contact_selection_list_fragment.xml
@@ -7,7 +7,6 @@
android:id="@+id/emptyStateContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:layout_centerInParent="true"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical">
@@ -47,12 +46,6 @@
-
diff --git a/res/layout/contact_selection_list_item.xml b/res/layout/contact_selection_list_item.xml
deleted file mode 100644
index e639a524f3..0000000000
--- a/res/layout/contact_selection_list_item.xml
+++ /dev/null
@@ -1,79 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/res/layout/invite_activity.xml b/res/layout/invite_activity.xml
index 7015fecd8a..98bb11c628 100644
--- a/res/layout/invite_activity.xml
+++ b/res/layout/invite_activity.xml
@@ -94,7 +94,7 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
- android:name="org.thoughtcrime.securesms.loki.redesign.fragments.ContactSelectionListFragment"
+ android:name="org.thoughtcrime.securesms.loki.redesign.fragments.contactselection.ContactSelectionListFragment"
tools:layout="@layout/contact_selection_list_fragment"/>
+ android:name="org.thoughtcrime.securesms.loki.redesign.fragments.contactselection.ContactSelectionListFragment" />
{
- threadID = DatabaseFactory.getThreadDatabase(getContext()).getThreadIdFor(recipient);
- updateProfilePicture(glideRequests, recipient.getName(), threadID);
- nameView.setText(recipient.toShortString());
- });
- }
- }
-
- private void updateProfilePicture(GlideRequests glide, String name, long threadID) {
- if (this.recipient.isGroupRecipient()) {
- Set usersAsSet = LokiAPI.Companion.getUserHexEncodedPublicKeyCache().get(threadID);
- if (usersAsSet == null) {
- usersAsSet = new HashSet<>();
- }
- ArrayList users = new ArrayList<>(usersAsSet);
- Collections.sort(users); // Sort to provide a level of stability
- profilePictureView.setHexEncodedPublicKey(users.size() > 0 ? users.get(0) : "");
- profilePictureView.setAdditionalHexEncodedPublicKey(users.size() > 1 ? users.get(1) : "");
- profilePictureView.setRSSFeed(name.equals("Loki News") || name.equals("Session Updates"));
- } else {
- profilePictureView.setHexEncodedPublicKey(this.number);
- profilePictureView.setAdditionalHexEncodedPublicKey(null);
- profilePictureView.setRSSFeed(false);
- }
- profilePictureView.glide = glide;
- profilePictureView.update();
- }
-}
diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/ContactSelectionListAdapter.kt b/src/org/thoughtcrime/securesms/loki/redesign/fragments/contactselection/ContactSelectionListAdapter.kt
similarity index 75%
rename from src/org/thoughtcrime/securesms/loki/redesign/activities/ContactSelectionListAdapter.kt
rename to src/org/thoughtcrime/securesms/loki/redesign/fragments/contactselection/ContactSelectionListAdapter.kt
index 821ae6a554..8fe3fffe30 100644
--- a/src/org/thoughtcrime/securesms/loki/redesign/activities/ContactSelectionListAdapter.kt
+++ b/src/org/thoughtcrime/securesms/loki/redesign/fragments/contactselection/ContactSelectionListAdapter.kt
@@ -1,4 +1,4 @@
-package org.thoughtcrime.securesms.loki.redesign.activities
+package org.thoughtcrime.securesms.loki.redesign.fragments.contactselection
import android.content.Context
import android.support.v7.widget.RecyclerView
@@ -11,7 +11,7 @@ import org.thoughtcrime.securesms.loki.redesign.views.UserView
import org.thoughtcrime.securesms.mms.GlideRequests
import org.thoughtcrime.securesms.recipients.Recipient
-class ContactSelectionListAdapter(private val context: Context, private val isMulti: Boolean) : RecyclerView.Adapter() {
+class ContactSelectionListAdapter(private val context: Context, private val multiSelect: Boolean) : RecyclerView.Adapter() {
private object ViewType {
const val Contact = 0
@@ -20,11 +20,11 @@ class ContactSelectionListAdapter(private val context: Context, private val isMu
lateinit var glide: GlideRequests
val selectedContacts = mutableSetOf()
- var items = listOf()
+ var items = listOf()
set(value) { field = value; notifyDataSetChanged() }
var contactClickListener: ContactClickListener? = null
- class ViewHolder(val view: UserView) : RecyclerView.ViewHolder(view)
+ class UserViewHolder(val view: UserView) : RecyclerView.ViewHolder(view)
class DividerViewHolder(val view: View): RecyclerView.ViewHolder(view)
override fun getItemCount(): Int {
@@ -33,14 +33,14 @@ class ContactSelectionListAdapter(private val context: Context, private val isMu
override fun getItemViewType(position: Int): Int {
return when (items[position]) {
- is ContactSelectionListLoaderItem.Header -> ViewType.Divider
+ is ContactSelectionListItem.Header -> ViewType.Divider
else -> ViewType.Contact
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return if (viewType == ViewType.Contact) {
- ViewHolder(UserView(context))
+ UserViewHolder(UserView(context))
} else {
val view = LayoutInflater.from(context).inflate(R.layout.contact_selection_list_divider, parent, false)
DividerViewHolder(view)
@@ -49,13 +49,14 @@ class ContactSelectionListAdapter(private val context: Context, private val isMu
override fun onBindViewHolder(viewHolder: RecyclerView.ViewHolder, position: Int) {
val item = items[position]
- if (viewHolder is ViewHolder) {
- item as ContactSelectionListLoaderItem.Contact
+ if (viewHolder is UserViewHolder) {
+ item as ContactSelectionListItem.Contact
viewHolder.view.setOnClickListener { contactClickListener?.onContactClick(item.recipient) }
val isSelected = selectedContacts.contains(item.recipient)
viewHolder.view.bind(item.recipient, isSelected, glide)
+ viewHolder.view.setCheckBoxVisible(multiSelect)
} else if (viewHolder is DividerViewHolder) {
- item as ContactSelectionListLoaderItem.Header
+ item as ContactSelectionListItem.Header
viewHolder.view.label.text = item.name
}
}
@@ -64,14 +65,14 @@ class ContactSelectionListAdapter(private val context: Context, private val isMu
if (selectedContacts.contains(recipient)) {
selectedContacts.remove(recipient)
contactClickListener?.onContactDeselected(recipient)
- } else {
+ } else if (multiSelect || selectedContacts.isEmpty()) {
selectedContacts.add(recipient)
contactClickListener?.onContactSelected(recipient)
}
val index = items.indexOfFirst {
when (it) {
- is ContactSelectionListLoaderItem.Header -> false
- is ContactSelectionListLoaderItem.Contact -> it.recipient == recipient
+ is ContactSelectionListItem.Header -> false
+ is ContactSelectionListItem.Contact -> it.recipient == recipient
}
}
notifyItemChanged(index)
diff --git a/src/org/thoughtcrime/securesms/loki/redesign/fragments/ContactSelectionListFragment.kt b/src/org/thoughtcrime/securesms/loki/redesign/fragments/contactselection/ContactSelectionListFragment.kt
similarity index 72%
rename from src/org/thoughtcrime/securesms/loki/redesign/fragments/ContactSelectionListFragment.kt
rename to src/org/thoughtcrime/securesms/loki/redesign/fragments/contactselection/ContactSelectionListFragment.kt
index a94ea997df..0fb530da0d 100644
--- a/src/org/thoughtcrime/securesms/loki/redesign/fragments/ContactSelectionListFragment.kt
+++ b/src/org/thoughtcrime/securesms/loki/redesign/fragments/contactselection/ContactSelectionListFragment.kt
@@ -1,4 +1,4 @@
-package org.thoughtcrime.securesms.loki.redesign.fragments
+package org.thoughtcrime.securesms.loki.redesign.fragments.contactselection
import android.os.Bundle
import android.support.v4.app.Fragment
@@ -12,14 +12,10 @@ import android.view.ViewGroup
import kotlinx.android.synthetic.main.contact_selection_list_fragment.*
import network.loki.messenger.R
import org.thoughtcrime.securesms.contacts.ContactsCursorLoader
-import org.thoughtcrime.securesms.loki.redesign.activities.ContactClickListener
-import org.thoughtcrime.securesms.loki.redesign.activities.ContactSelectionListAdapter
-import org.thoughtcrime.securesms.loki.redesign.activities.ContactSelectionListLoader
-import org.thoughtcrime.securesms.loki.redesign.activities.ContactSelectionListLoaderItem
import org.thoughtcrime.securesms.mms.GlideApp
import org.thoughtcrime.securesms.recipients.Recipient
-class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks>, ContactClickListener {
+class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks>, ContactClickListener {
companion object {
@JvmField val DISPLAY_MODE = "display_mode"
@@ -27,27 +23,24 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks
get() = listAdapter.selectedContacts.map { it.address.serialize() }
- private var items = listOf()
- set(value) { field = value; listAdapter.items = value }
-
private val listAdapter by lazy {
- val result = ContactSelectionListAdapter(activity!!, isMulti)
+ val result = ContactSelectionListAdapter(activity!!, multiSelect)
result.glide = GlideApp.with(this)
result.contactClickListener = this
result
}
- private val isMulti: Boolean by lazy {
+ private val multiSelect: Boolean by lazy {
activity!!.intent.getBooleanExtra(MULTI_SELECT, false)
}
private var cursorFilter: String? = null
- var onContactSelectedListener: OnContactSelectedListener? = null
-
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
@@ -67,7 +60,7 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks>(0, null, this)
+ LoaderManager.getInstance(this).restartLoader(0, null, this)
}
fun resetQueryFilter() {
@@ -83,32 +76,24 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks> {
+ override fun onCreateLoader(id: Int, args: Bundle?): Loader> {
return ContactSelectionListLoader(activity!!,
activity!!.intent.getIntExtra(DISPLAY_MODE, ContactsCursorLoader.DisplayMode.FLAG_ALL),
cursorFilter)
}
- override fun onLoadFinished(loader: Loader>, items: List) {
+ override fun onLoadFinished(loader: Loader>, items: List) {
update(items)
}
- override fun onLoaderReset(loader: Loader>) {
+ override fun onLoaderReset(loader: Loader>) {
update(listOf())
}
- private fun update(items: List) {
- this.items = items
+ private fun update(items: List) {
+ listAdapter.items = items
mainContentContainer.visibility = if (items.isEmpty()) View.GONE else View.VISIBLE
emptyStateContainer.visibility = if (items.isEmpty()) View.VISIBLE else View.GONE
- val useFastScroller = items.count() > 20
- recyclerView.isVerticalScrollBarEnabled = !useFastScroller
- if (useFastScroller) {
- fastScroller.visibility = View.VISIBLE
- fastScroller.setRecyclerView(recyclerView)
- } else {
- fastScroller.visibility = View.GONE
- }
}
override fun onContactClick(contact: Recipient) {
diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/ContactSelectionListLoader.kt b/src/org/thoughtcrime/securesms/loki/redesign/fragments/contactselection/ContactSelectionListLoader.kt
similarity index 74%
rename from src/org/thoughtcrime/securesms/loki/redesign/activities/ContactSelectionListLoader.kt
rename to src/org/thoughtcrime/securesms/loki/redesign/fragments/contactselection/ContactSelectionListLoader.kt
index 0f768b8ef2..badcb45ae7 100644
--- a/src/org/thoughtcrime/securesms/loki/redesign/activities/ContactSelectionListLoader.kt
+++ b/src/org/thoughtcrime/securesms/loki/redesign/fragments/contactselection/ContactSelectionListLoader.kt
@@ -1,4 +1,4 @@
-package org.thoughtcrime.securesms.loki.redesign.activities
+package org.thoughtcrime.securesms.loki.redesign.fragments.contactselection
import android.content.Context
import network.loki.messenger.R
@@ -7,13 +7,13 @@ import org.thoughtcrime.securesms.loki.redesign.utilities.ContactUtilities
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.util.AsyncLoader
-sealed class ContactSelectionListLoaderItem {
- class Header(val name: String): ContactSelectionListLoaderItem()
- class Contact(val recipient: Recipient): ContactSelectionListLoaderItem()
-
+sealed class ContactSelectionListItem {
+ class Header(val name: String): ContactSelectionListItem()
+ class Contact(val recipient: Recipient): ContactSelectionListItem()
}
-class ContactSelectionListLoader(context: Context, val mode: Int, val filter: String?) : AsyncLoader>(context) {
+class ContactSelectionListLoader(context: Context, val mode: Int, val filter: String?) : AsyncLoader>(context) {
+
object DisplayMode {
const val FLAG_FRIENDS = 1
const val FLAG_CLOSED_GROUPS = 1 shl 1
@@ -25,7 +25,7 @@ class ContactSelectionListLoader(context: Context, val mode: Int, val filter: St
return mode and flag > 0
}
- override fun loadInBackground(): List {
+ override fun loadInBackground(): List {
val contacts = ContactUtilities.getAllContacts(context).filter {
if (filter.isNullOrEmpty()) return@filter true
@@ -34,7 +34,7 @@ class ContactSelectionListLoader(context: Context, val mode: Int, val filter: St
it.recipient.toShortString()
}
- val list = mutableListOf()
+ val list = mutableListOf()
if (isFlagSet(DisplayMode.FLAG_CLOSED_GROUPS)) {
list.addAll(getClosedGroups(contacts))
}
@@ -50,31 +50,31 @@ class ContactSelectionListLoader(context: Context, val mode: Int, val filter: St
return list
}
- private fun getFriends(contacts: List): List {
+ private fun getFriends(contacts: List): List {
return getItems(contacts, context.getString(R.string.ContactSelectionListLoader_contacts)) {
!it.recipient.isGroupRecipient && it.isFriend && !it.isOurDevice && !it.isSlave
}
}
- private fun getClosedGroups(contacts: List): List {
+ private fun getClosedGroups(contacts: List): List {
return getItems(contacts, context.getString(R.string.ContactSelectionListLoader_closed_groups)) {
it.recipient.address.isSignalGroup
}
}
- private fun getOpenGroups(contacts: List): List {
+ private fun getOpenGroups(contacts: List): List {
return getItems(contacts, context.getString(R.string.ContactSelectionListLoader_open_groups)) {
it.recipient.address.isPublicChat
}
}
- private fun getItems(contacts: List, title: String, contactFilter: (Contact) -> Boolean): List {
+ private fun getItems(contacts: List, title: String, contactFilter: (Contact) -> Boolean): List {
val items = contacts.filter(contactFilter).map {
- ContactSelectionListLoaderItem.Contact(it.recipient)
+ ContactSelectionListItem.Contact(it.recipient)
}
if (items.isEmpty()) return listOf()
- val header = ContactSelectionListLoaderItem.Header(title)
+ 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 f925863947..d8634b7beb 100644
--- a/src/org/thoughtcrime/securesms/loki/redesign/utilities/ContactUtilities.kt
+++ b/src/org/thoughtcrime/securesms/loki/redesign/utilities/ContactUtilities.kt
@@ -54,8 +54,6 @@ object ContactUtilities {
val isOurDevice = ourDevices.contains(address)
val isFriend = lokiThreadDatabase.getFriendRequestStatus(thread.threadId) == LokiThreadFriendRequestStatus.FRIENDS
var isSlave = false
- var displayName = ""
-
if (!recipient.isGroupRecipient) {
val deviceLinks = lokiAPIDatabase.getDeviceLinks(address)
isSlave = deviceLinks.find { it.slaveHexEncodedPublicKey == address } != null
diff --git a/src/org/thoughtcrime/securesms/loki/redesign/views/UserView.kt b/src/org/thoughtcrime/securesms/loki/redesign/views/UserView.kt
index e8f86e4ba5..a7968ed6d7 100644
--- a/src/org/thoughtcrime/securesms/loki/redesign/views/UserView.kt
+++ b/src/org/thoughtcrime/securesms/loki/redesign/views/UserView.kt
@@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.loki.redesign.views
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
+import android.view.View
import android.widget.LinearLayout
import kotlinx.android.synthetic.main.view_conversation.view.profilePictureView
import kotlinx.android.synthetic.main.view_user.view.*
@@ -13,7 +14,6 @@ import org.thoughtcrime.securesms.recipients.Recipient
import org.whispersystems.signalservice.loki.api.LokiAPI
class UserView : LinearLayout {
- var user: String? = null
// region Lifecycle
constructor(context: Context) : super(context) {
@@ -40,6 +40,10 @@ class UserView : LinearLayout {
// endregion
// region Updating
+ fun setCheckBoxVisible(visible: Boolean) {
+ tickImageView.visibility = if (visible) View.VISIBLE else View.GONE
+ }
+
fun bind(user: Recipient, isSelected: Boolean, glide: GlideRequests) {
val address = user.address.serialize()
if (user.isGroupRecipient) {