mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-16 11:01:26 +00:00
Clean
This commit is contained in:
parent
42d74208ff
commit
4599407b3a
@ -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_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/emptyStateContainer"
|
android:id="@+id/emptyStateContainer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center_horizontal|center_vertical"
|
android:gravity="center"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@ -16,6 +16,7 @@
|
|||||||
android:text="You don't have any contacts yet"
|
android:text="You don't have any contacts yet"
|
||||||
android:textColor="@color/text"
|
android:textColor="@color/text"
|
||||||
android:textSize="@dimen/medium_font_size" />
|
android:textSize="@dimen/medium_font_size" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
@ -25,9 +26,9 @@
|
|||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<android.support.v4.widget.SwipeRefreshLayout
|
<android.support.v4.widget.SwipeRefreshLayout
|
||||||
android:id="@+id/swipeRefresh"
|
android:id="@+id/swipeRefreshLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/recyclerView"
|
android:id="@+id/recyclerView"
|
||||||
@ -36,13 +37,14 @@
|
|||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
android:scrollbars="vertical" />
|
android:scrollbars="vertical" />
|
||||||
|
|
||||||
<TextView android:id="@android:id/empty"
|
<TextView
|
||||||
|
android:id="@+id/loadingTextView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center|center_vertical"
|
android:gravity="center"
|
||||||
android:layout_marginTop="15dp"
|
android:textColor="@color/text"
|
||||||
android:text="@string/contact_selection_group_activity__finding_contacts"
|
android:text="@string/contact_selection_group_activity__finding_contacts"
|
||||||
android:textSize="20sp" />
|
android:textSize="@dimen/large_font_size" />
|
||||||
|
|
||||||
</android.support.v4.widget.SwipeRefreshLayout>
|
</android.support.v4.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
|
@ -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_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_delete_conversation_dialog_message">Are you sure you want to delete this conversation?</string>
|
||||||
<string name="activity_home_conversation_deleted_message">Conversation deleted</string>
|
<string name="activity_home_conversation_deleted_message">Conversation deleted</string>
|
||||||
|
<string name="fragment_contact_selection_contacts_title">Contacts</string>
|
||||||
<!-- ContactSelectionListLoader -->
|
<string name="fragment_contact_selection_closed_groups_title">Closed Groups</string>
|
||||||
<string name="ContactSelectionListLoader_contacts">Contacts</string>
|
<string name="fragment_contact_selection_open_groups_title">Open Groups</string>
|
||||||
<string name="ContactSelectionListLoader_closed_groups">Groups</string>
|
|
||||||
<string name="ContactSelectionListLoader_open_groups">Public Chats</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -8,7 +8,7 @@ class CreateClosedGroupLoader(context: Context) : AsyncLoader<List<String>>(cont
|
|||||||
|
|
||||||
override fun loadInBackground(): List<String> {
|
override fun loadInBackground(): List<String> {
|
||||||
val contacts = ContactUtilities.getAllContacts(context)
|
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 ->
|
return contacts.filter { contact ->
|
||||||
!contact.recipient.isGroupRecipient && contact.isFriend && !contact.isOurDevice && !contact.isSlave
|
!contact.recipient.isGroupRecipient && contact.isFriend && !contact.isOurDevice && !contact.isSlave
|
||||||
}.map {
|
}.map {
|
||||||
|
@ -12,20 +12,19 @@ import org.thoughtcrime.securesms.mms.GlideRequests
|
|||||||
import org.thoughtcrime.securesms.recipients.Recipient
|
import org.thoughtcrime.securesms.recipients.Recipient
|
||||||
|
|
||||||
class ContactSelectionListAdapter(private val context: Context, private val multiSelect: Boolean) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
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
|
lateinit var glide: GlideRequests
|
||||||
val selectedContacts = mutableSetOf<Recipient>()
|
val selectedContacts = mutableSetOf<Recipient>()
|
||||||
var items = listOf<ContactSelectionListItem>()
|
var items = listOf<ContactSelectionListItem>()
|
||||||
set(value) { field = value; notifyDataSetChanged() }
|
set(value) { field = value; notifyDataSetChanged() }
|
||||||
var contactClickListener: ContactClickListener? = null
|
var contactClickListener: ContactClickListener? = null
|
||||||
|
|
||||||
|
private object ViewType {
|
||||||
|
const val Contact = 0
|
||||||
|
const val Divider = 1
|
||||||
|
}
|
||||||
|
|
||||||
class UserViewHolder(val view: UserView) : RecyclerView.ViewHolder(view)
|
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 {
|
override fun getItemCount(): Int {
|
||||||
return items.size
|
return items.size
|
||||||
|
@ -16,18 +16,16 @@ import org.thoughtcrime.securesms.mms.GlideApp
|
|||||||
import org.thoughtcrime.securesms.recipients.Recipient
|
import org.thoughtcrime.securesms.recipients.Recipient
|
||||||
|
|
||||||
class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<List<ContactSelectionListItem>>, ContactClickListener {
|
class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<List<ContactSelectionListItem>>, ContactClickListener {
|
||||||
|
private var cursorFilter: String? = null
|
||||||
companion object {
|
|
||||||
@JvmField val DISPLAY_MODE = "display_mode"
|
|
||||||
@JvmField val MULTI_SELECT = "multi_select"
|
|
||||||
@JvmField val REFRESHABLE = "refreshable"
|
|
||||||
}
|
|
||||||
|
|
||||||
var onContactSelectedListener: OnContactSelectedListener? = null
|
var onContactSelectedListener: OnContactSelectedListener? = null
|
||||||
|
|
||||||
val selectedContacts: List<String>
|
val selectedContacts: List<String>
|
||||||
get() = listAdapter.selectedContacts.map { it.address.serialize() }
|
get() = listAdapter.selectedContacts.map { it.address.serialize() }
|
||||||
|
|
||||||
|
private val multiSelect: Boolean by lazy {
|
||||||
|
activity!!.intent.getBooleanExtra(MULTI_SELECT, false)
|
||||||
|
}
|
||||||
|
|
||||||
private val listAdapter by lazy {
|
private val listAdapter by lazy {
|
||||||
val result = ContactSelectionListAdapter(activity!!, multiSelect)
|
val result = ContactSelectionListAdapter(activity!!, multiSelect)
|
||||||
result.glide = GlideApp.with(this)
|
result.glide = GlideApp.with(this)
|
||||||
@ -35,18 +33,22 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<L
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
private val multiSelect: Boolean by lazy {
|
companion object {
|
||||||
activity!!.intent.getBooleanExtra(MULTI_SELECT, false)
|
@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?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
super.onActivityCreated(savedInstanceState)
|
super.onActivityCreated(savedInstanceState)
|
||||||
|
|
||||||
recyclerView.layoutManager = LinearLayoutManager(activity)
|
recyclerView.layoutManager = LinearLayoutManager(activity)
|
||||||
recyclerView.adapter = listAdapter
|
recyclerView.adapter = listAdapter
|
||||||
swipeRefresh.isEnabled = activity!!.intent.getBooleanExtra(REFRESHABLE, true)
|
swipeRefreshLayout.isEnabled = activity!!.intent.getBooleanExtra(REFRESHABLE, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
@ -65,15 +67,15 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<L
|
|||||||
|
|
||||||
fun resetQueryFilter() {
|
fun resetQueryFilter() {
|
||||||
setQueryFilter(null)
|
setQueryFilter(null)
|
||||||
swipeRefresh.isRefreshing = false
|
swipeRefreshLayout.isRefreshing = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setRefreshing(refreshing: Boolean) {
|
fun setRefreshing(refreshing: Boolean) {
|
||||||
swipeRefresh.isRefreshing = refreshing
|
swipeRefreshLayout.isRefreshing = refreshing
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setOnRefreshListener(onRefreshListener: OnRefreshListener?) {
|
fun setOnRefreshListener(onRefreshListener: OnRefreshListener?) {
|
||||||
this.swipeRefresh.setOnRefreshListener(onRefreshListener)
|
swipeRefreshLayout.setOnRefreshListener(onRefreshListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateLoader(id: Int, args: Bundle?): Loader<List<ContactSelectionListItem>> {
|
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) {
|
override fun onContactDeselected(contact: Recipient) {
|
||||||
onContactSelectedListener?.onContactDeselected(contact.address.serialize())
|
onContactSelectedListener?.onContactDeselected(contact.address.serialize())
|
||||||
}
|
}
|
||||||
|
|
||||||
interface OnContactSelectedListener {
|
|
||||||
fun onContactSelected(number: String?)
|
|
||||||
fun onContactDeselected(number: String?)
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -8,8 +8,8 @@ import org.thoughtcrime.securesms.recipients.Recipient
|
|||||||
import org.thoughtcrime.securesms.util.AsyncLoader
|
import org.thoughtcrime.securesms.util.AsyncLoader
|
||||||
|
|
||||||
sealed class ContactSelectionListItem {
|
sealed class ContactSelectionListItem {
|
||||||
class Header(val name: String): ContactSelectionListItem()
|
class Header(val name: String) : ContactSelectionListItem()
|
||||||
class Contact(val recipient: Recipient): ContactSelectionListItem()
|
class Contact(val recipient: Recipient) : ContactSelectionListItem()
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContactSelectionListLoader(context: Context, val mode: Int, val filter: String?) : AsyncLoader<List<ContactSelectionListItem>>(context) {
|
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>()
|
val list = mutableListOf<ContactSelectionListItem>()
|
||||||
|
|
||||||
if (isFlagSet(DisplayMode.FLAG_CLOSED_GROUPS)) {
|
if (isFlagSet(DisplayMode.FLAG_CLOSED_GROUPS)) {
|
||||||
list.addAll(getClosedGroups(contacts))
|
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> {
|
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
|
!it.recipient.isGroupRecipient && it.isFriend && !it.isOurDevice && !it.isSlave
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getClosedGroups(contacts: List<Contact>): List<ContactSelectionListItem> {
|
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
|
it.recipient.address.isSignalGroup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getOpenGroups(contacts: List<Contact>): List<ContactSelectionListItem> {
|
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
|
it.recipient.address.isPublicChat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -72,9 +73,11 @@ class ContactSelectionListLoader(context: Context, val mode: Int, val filter: St
|
|||||||
val items = contacts.filter(contactFilter).map {
|
val items = contacts.filter(contactFilter).map {
|
||||||
ContactSelectionListItem.Contact(it.recipient)
|
ContactSelectionListItem.Contact(it.recipient)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (items.isEmpty()) return listOf()
|
if (items.isEmpty()) return listOf()
|
||||||
|
|
||||||
val header = ContactSelectionListItem.Header(title)
|
val header = ContactSelectionListItem.Header(title)
|
||||||
|
|
||||||
return listOf(header) + items
|
return listOf(header) + items
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,12 +12,11 @@ data class Contact(
|
|||||||
val isSlave: Boolean,
|
val isSlave: Boolean,
|
||||||
val isOurDevice: Boolean
|
val isOurDevice: Boolean
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (other?.javaClass != javaClass) return false
|
if (other?.javaClass != javaClass) return false
|
||||||
|
|
||||||
other as Contact
|
other as Contact
|
||||||
|
|
||||||
return recipient == other.recipient
|
return recipient == other.recipient
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,15 +33,11 @@ object ContactUtilities {
|
|||||||
val lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context)
|
val lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context)
|
||||||
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
|
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
|
||||||
val lokiAPIDatabase = DatabaseFactory.getLokiAPIDatabase(context)
|
val lokiAPIDatabase = DatabaseFactory.getLokiAPIDatabase(context)
|
||||||
val groupDatabase = DatabaseFactory.getGroupDatabase(context)
|
|
||||||
val lokiUserDatabase = DatabaseFactory.getLokiUserDatabase(context)
|
|
||||||
|
|
||||||
val ourDeviceLinks = lokiAPIDatabase.getDeviceLinks(userHexEncodedPublicKey)
|
val ourDeviceLinks = lokiAPIDatabase.getDeviceLinks(userHexEncodedPublicKey)
|
||||||
val ourDevices = ourDeviceLinks.flatMap {
|
val ourDevices = ourDeviceLinks.flatMap {
|
||||||
listOf( it.masterHexEncodedPublicKey.toLowerCase(), it.slaveHexEncodedPublicKey.toLowerCase() )
|
listOf( it.masterHexEncodedPublicKey.toLowerCase(), it.slaveHexEncodedPublicKey.toLowerCase() )
|
||||||
}.toMutableSet()
|
}.toMutableSet()
|
||||||
ourDevices.add(userHexEncodedPublicKey.toLowerCase())
|
ourDevices.add(userHexEncodedPublicKey.toLowerCase())
|
||||||
|
|
||||||
val cursor = threadDatabase.conversationList
|
val cursor = threadDatabase.conversationList
|
||||||
val result = mutableSetOf<Contact>()
|
val result = mutableSetOf<Contact>()
|
||||||
threadDatabase.readerFor(cursor).use { reader ->
|
threadDatabase.readerFor(cursor).use { reader ->
|
||||||
@ -50,7 +45,6 @@ object ContactUtilities {
|
|||||||
val thread = reader.current
|
val thread = reader.current
|
||||||
val recipient = thread.recipient
|
val recipient = thread.recipient
|
||||||
val address = recipient.address.serialize()
|
val address = recipient.address.serialize()
|
||||||
|
|
||||||
val isOurDevice = ourDevices.contains(address)
|
val isOurDevice = ourDevices.contains(address)
|
||||||
val isFriend = lokiThreadDatabase.getFriendRequestStatus(thread.threadId) == LokiThreadFriendRequestStatus.FRIENDS
|
val isFriend = lokiThreadDatabase.getFriendRequestStatus(thread.threadId) == LokiThreadFriendRequestStatus.FRIENDS
|
||||||
var isSlave = false
|
var isSlave = false
|
||||||
@ -58,12 +52,9 @@ object ContactUtilities {
|
|||||||
val deviceLinks = lokiAPIDatabase.getDeviceLinks(address)
|
val deviceLinks = lokiAPIDatabase.getDeviceLinks(address)
|
||||||
isSlave = deviceLinks.find { it.slaveHexEncodedPublicKey == address } != null
|
isSlave = deviceLinks.find { it.slaveHexEncodedPublicKey == address } != null
|
||||||
}
|
}
|
||||||
|
|
||||||
result.add(Contact(recipient, isFriend, isSlave, isOurDevice))
|
result.add(Contact(recipient, isFriend, isSlave, isOurDevice))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -47,13 +47,13 @@ class UserView : LinearLayout {
|
|||||||
fun bind(user: Recipient, isSelected: Boolean, glide: GlideRequests) {
|
fun bind(user: Recipient, isSelected: Boolean, glide: GlideRequests) {
|
||||||
val address = user.address.serialize()
|
val address = user.address.serialize()
|
||||||
if (user.isGroupRecipient) {
|
if (user.isGroupRecipient) {
|
||||||
if (user.address.isPublicChat || user.address.isRSSFeed) {
|
if ("Session Public Chat" == user.name || user.address.isRSSFeed) {
|
||||||
profilePictureView.hexEncodedPublicKey = ""
|
profilePictureView.hexEncodedPublicKey = ""
|
||||||
profilePictureView.additionalHexEncodedPublicKey = null
|
profilePictureView.additionalHexEncodedPublicKey = null
|
||||||
profilePictureView.isRSSFeed = true
|
profilePictureView.isRSSFeed = true
|
||||||
} else {
|
} else {
|
||||||
val threadId = GroupManager.getThreadIdFromGroupId(address, context)
|
val threadID = GroupManager.getThreadIdFromGroupId(address, context)
|
||||||
val users = LokiAPI.userHexEncodedPublicKeyCache[threadId]?.toList() ?: listOf()
|
val users = LokiAPI.userHexEncodedPublicKeyCache[threadID]?.toList() ?: listOf()
|
||||||
val randomUsers = users.sorted() // Sort to provide a level of stability
|
val randomUsers = users.sorted() // Sort to provide a level of stability
|
||||||
profilePictureView.hexEncodedPublicKey = randomUsers.getOrNull(0) ?: ""
|
profilePictureView.hexEncodedPublicKey = randomUsers.getOrNull(0) ?: ""
|
||||||
profilePictureView.additionalHexEncodedPublicKey = randomUsers.getOrNull(1) ?: ""
|
profilePictureView.additionalHexEncodedPublicKey = randomUsers.getOrNull(1) ?: ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user