You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-android/app/src/main/java/org/thoughtcrime/securesms/contacts/ContactSelectionListFragmen...

114 lines
4.1 KiB
Kotlin

package org.thoughtcrime.securesms.contacts
4 years ago
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.loader.app.LoaderManager
import androidx.loader.content.Loader
import androidx.recyclerview.widget.LinearLayoutManager
import network.loki.messenger.databinding.ContactSelectionListFragmentBinding
import org.session.libsession.utilities.recipients.Recipient
3 years ago
import org.session.libsignal.utilities.Log
4 years ago
import org.thoughtcrime.securesms.mms.GlideApp
class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<List<ContactSelectionListItem>>, ContactClickListener {
private lateinit var binding: ContactSelectionListFragmentBinding
4 years ago
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 {
requireActivity().intent.getBooleanExtra(MULTI_SELECT, false)
4 years ago
}
private val listAdapter by lazy {
val result = ContactSelectionListAdapter(requireActivity(), multiSelect)
4 years ago
result.glide = GlideApp.with(this)
result.contactClickListener = this
result
}
companion object {
@JvmField val DISPLAY_MODE = "display_mode"
@JvmField val MULTI_SELECT = "multi_select"
@JvmField val REFRESHABLE = "refreshable"
}
interface OnContactSelectedListener {
fun onContactSelected(number: String?)
fun onContactDeselected(number: String?)
}
override fun onStart() {
super.onStart()
LoaderManager.getInstance(this).initLoader(0, null, this)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
binding = ContactSelectionListFragmentBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.recyclerView.layoutManager = LinearLayoutManager(activity)
binding.recyclerView.adapter = listAdapter
4 years ago
}
override fun onStop() {
super.onStop()
LoaderManager.getInstance(this).destroyLoader(0)
}
4 years ago
fun setQueryFilter(filter: String?) {
cursorFilter = filter
LoaderManager.getInstance(this).restartLoader(0, null, this)
}
fun resetQueryFilter() {
setQueryFilter(null)
}
override fun onCreateLoader(id: Int, args: Bundle?): Loader<List<ContactSelectionListItem>> {
return ContactSelectionListLoader(requireActivity(),
requireActivity().intent.getIntExtra(DISPLAY_MODE, ContactsCursorLoader.DisplayMode.FLAG_ALL),
4 years ago
cursorFilter)
}
override fun onLoadFinished(loader: Loader<List<ContactSelectionListItem>>, items: List<ContactSelectionListItem>) {
update(items)
}
override fun onLoaderReset(loader: Loader<List<ContactSelectionListItem>>) {
update(listOf())
}
private fun update(items: List<ContactSelectionListItem>) {
if (activity?.isDestroyed == true) {
Log.e(ContactSelectionListFragment::class.java.name,
"Received a loader callback after the fragment was detached from the activity.",
IllegalStateException())
return
}
4 years ago
listAdapter.items = items
Paged conversation recycler, update compile sdk version 31 (#1049) * Update build tools * Update appcompat version * Update dependencies * feat: add paging into conversation recycler and queries to fetch data off-thread * refactor: wip for updating paged results and bucketing messages / fetching enough to display * fix: currently works for scrolling and possibly refreshing? need scroll to message and auto scroll down on insert (at bottom) * fix: search and scrolling to X message works now * build: increase version code and name * fix: re-add refresh, remove the outdated comment * refactor: lets see if 25 size pages increases performance :eyes: * feat: add in some equals overrides for mms records to refresh if media has finished DLing * feat: add scroll to bottom for new messages if we are at the end of the chat * build: update build numbers * fix: update AGP and fix compile errors for sdk version 31 * feat: add log for loki-avatar and loki-fs on upload types and responses * feat: increase build number to match latest installed version * feat: changing props and permission checks for call service * fix: possible service exception when no call ID remote foreground service not terminated * revert: google services version * fix: re-add paging dependency * feat: adding new last seen function and figuring out the last seen for recycler adapter * build: update version names and codes for deploy * refactor: undo the new adapter and query changes to use previous cursor logic. revert this commit to enable new paged adapter * fix: use author's address in typist equality and hashcode for set inclusion * refactor: refactor the select contacts activity * refactor: refactor the select contacts activity * build: update version code * fix: hide all other bound views if deleted * refactor: change voice message tint, upgrade build number * fix: message detail showing up properly * revert: realise copy public key is actually not allowed if open group participant * fix: copy session ID, message detail activity support re-enabled * build: update build version code * build: remove version name * build: update build code * feat: google services version minimum compatible * fix: selection for re-created objects not properly highlighting * fix: foreground CENTER_INSIDE instead of just CENTER for scaletype * build: update version code * fix: don't show error if no error * build: update version code * fix: clear error messages if any on successful send Co-authored-by: charles <charles@oxen.io>
1 year ago
binding.recyclerView.visibility = if (items.isEmpty()) View.GONE else View.VISIBLE
binding.emptyStateContainer.visibility = if (items.isEmpty()) View.VISIBLE else View.GONE
4 years ago
}
override fun onContactClick(contact: Recipient) {
listAdapter.onContactClick(contact)
}
override fun onContactSelected(contact: Recipient) {
onContactSelectedListener?.onContactSelected(contact.address.serialize())
}
override fun onContactDeselected(contact: Recipient) {
onContactSelectedListener?.onContactDeselected(contact.address.serialize())
}
}