mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 18:43:49 +00:00
Refactor
This commit is contained in:
parent
dd9b134dab
commit
42d74208ff
@ -19,6 +19,6 @@
|
||||
<fragment android:id="@+id/contact_selection_list_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:name="org.thoughtcrime.securesms.loki.redesign.fragments.ContactSelectionListFragment" />
|
||||
android:name="org.thoughtcrime.securesms.loki.redesign.fragments.contactselection.ContactSelectionListFragment" />
|
||||
|
||||
</LinearLayout>
|
@ -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 @@
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
||||
<org.thoughtcrime.securesms.components.RecyclerViewFastScroller
|
||||
android:id="@+id/fastScroller"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="gone"
|
||||
android:layout_gravity="end"/>
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
@ -1,79 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<org.thoughtcrime.securesms.contacts.ContactSelectionListItem
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:focusable="true"
|
||||
android:background="@drawable/conversation_item_background"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="8dp">
|
||||
|
||||
<org.thoughtcrime.securesms.loki.redesign.views.ProfilePictureView
|
||||
android:id="@+id/profilePictureView"
|
||||
android:layout_width="@dimen/medium_profile_picture_size"
|
||||
android:layout_height="@dimen/medium_profile_picture_size" />
|
||||
|
||||
<LinearLayout android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginStart="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
<org.thoughtcrime.securesms.components.emoji.EmojiTextView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="marquee"
|
||||
android:textSize="@dimen/medium_font_size"
|
||||
android:textColor="@color/text"
|
||||
android:textStyle="bold"
|
||||
tools:text="Frieeeeeeedrich Nieeeeeeeeeetzsche" />
|
||||
|
||||
<LinearLayout android:id="@+id/number_container"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView android:id="@+id/number"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textDirection="ltr"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="marquee"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textSize="14sp"
|
||||
android:fontFamily="sans-serif-light"
|
||||
tools:text="+1 (555) 555-5555" />
|
||||
|
||||
<TextView android:id="@+id/label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="10dip"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:fontFamily="sans-serif-light"
|
||||
tools:text="Mobile" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<CheckBox android:id="@+id/check_box"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:focusable="false"
|
||||
android:clickable="false" />
|
||||
|
||||
</org.thoughtcrime.securesms.contacts.ContactSelectionListItem>
|
@ -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"/>
|
||||
|
||||
<LinearLayout android:layout_width="match_parent"
|
||||
|
@ -49,7 +49,7 @@
|
||||
android:layout_below="@id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:name="org.thoughtcrime.securesms.loki.redesign.fragments.ContactSelectionListFragment" />
|
||||
android:name="org.thoughtcrime.securesms.loki.redesign.fragments.contactselection.ContactSelectionListFragment" />
|
||||
|
||||
<org.thoughtcrime.securesms.components.SearchToolbar
|
||||
android:id="@+id/search_toolbar"
|
||||
|
@ -20,8 +20,8 @@ import android.os.Bundle;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
|
||||
import org.thoughtcrime.securesms.components.ContactFilterToolbar;
|
||||
import org.thoughtcrime.securesms.loki.redesign.activities.ContactSelectionListLoader.DisplayMode;
|
||||
import org.thoughtcrime.securesms.loki.redesign.fragments.ContactSelectionListFragment;
|
||||
import org.thoughtcrime.securesms.loki.redesign.fragments.contactselection.ContactSelectionListFragment;
|
||||
import org.thoughtcrime.securesms.loki.redesign.fragments.contactselection.ContactSelectionListLoader.DisplayMode;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
|
@ -56,8 +56,8 @@ import org.thoughtcrime.securesms.database.ThreadDatabase;
|
||||
import org.thoughtcrime.securesms.groups.GroupManager;
|
||||
import org.thoughtcrime.securesms.groups.GroupManager.GroupActionResult;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.loki.redesign.activities.ContactSelectionListLoader.DisplayMode;
|
||||
import org.thoughtcrime.securesms.loki.redesign.fragments.ContactSelectionListFragment;
|
||||
import org.thoughtcrime.securesms.loki.redesign.fragments.contactselection.ContactSelectionListFragment;
|
||||
import org.thoughtcrime.securesms.loki.redesign.fragments.contactselection.ContactSelectionListLoader.DisplayMode;
|
||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||
|
@ -28,8 +28,8 @@ import org.thoughtcrime.securesms.components.ContactFilterToolbar;
|
||||
import org.thoughtcrime.securesms.components.ContactFilterToolbar.OnFilterChangedListener;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.loki.redesign.activities.ContactSelectionListLoader.DisplayMode;
|
||||
import org.thoughtcrime.securesms.loki.redesign.fragments.ContactSelectionListFragment;
|
||||
import org.thoughtcrime.securesms.loki.redesign.fragments.contactselection.ContactSelectionListFragment;
|
||||
import org.thoughtcrime.securesms.loki.redesign.fragments.contactselection.ContactSelectionListLoader.DisplayMode;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.sms.MessageSender;
|
||||
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
||||
|
@ -19,7 +19,7 @@ package org.thoughtcrime.securesms;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.thoughtcrime.securesms.loki.redesign.fragments.ContactSelectionListFragment;
|
||||
import org.thoughtcrime.securesms.loki.redesign.fragments.contactselection.ContactSelectionListFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -40,8 +40,8 @@ import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.ThreadDatabase;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.loki.redesign.activities.ContactSelectionListLoader.DisplayMode;
|
||||
import org.thoughtcrime.securesms.loki.redesign.fragments.ContactSelectionListFragment;
|
||||
import org.thoughtcrime.securesms.loki.redesign.fragments.contactselection.ContactSelectionListFragment;
|
||||
import org.thoughtcrime.securesms.loki.redesign.fragments.contactselection.ContactSelectionListLoader.DisplayMode;
|
||||
import org.thoughtcrime.securesms.mediasend.Media;
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||
import org.thoughtcrime.securesms.providers.BlobProvider;
|
||||
|
@ -1,161 +0,0 @@
|
||||
package org.thoughtcrime.securesms.contacts;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.loki.redesign.views.ProfilePictureView;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
import org.whispersystems.signalservice.loki.api.LokiAPI;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import network.loki.messenger.R;
|
||||
|
||||
public class ContactSelectionListItem extends LinearLayout implements RecipientModifiedListener {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = ContactSelectionListItem.class.getSimpleName();
|
||||
|
||||
private ProfilePictureView profilePictureView;
|
||||
private TextView numberView;
|
||||
private TextView nameView;
|
||||
private TextView labelView;
|
||||
private CheckBox checkBox;
|
||||
|
||||
private String number;
|
||||
private Recipient recipient;
|
||||
private GlideRequests glideRequests;
|
||||
private long threadID;
|
||||
|
||||
public ContactSelectionListItem(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ContactSelectionListItem(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
this.profilePictureView = findViewById(R.id.profilePictureView);
|
||||
this.numberView = findViewById(R.id.number);
|
||||
this.labelView = findViewById(R.id.label);
|
||||
this.nameView = findViewById(R.id.name);
|
||||
this.checkBox = findViewById(R.id.check_box);
|
||||
|
||||
ViewUtil.setTextViewGravityStart(this.nameView, getContext());
|
||||
}
|
||||
|
||||
public void set(@NonNull GlideRequests glideRequests, int type, String name, String number, String label, int color, boolean multiSelect) {
|
||||
this.glideRequests = glideRequests;
|
||||
this.number = number;
|
||||
|
||||
if (type == ContactsDatabase.NEW_TYPE) {
|
||||
this.recipient = null;
|
||||
} else if (!TextUtils.isEmpty(number)) {
|
||||
Address address = Address.fromExternal(getContext(), number);
|
||||
this.recipient = Recipient.from(getContext(), address, true);
|
||||
this.recipient.addListener(this);
|
||||
|
||||
if (this.recipient.getName() != null) {
|
||||
name = this.recipient.getName();
|
||||
}
|
||||
}
|
||||
|
||||
threadID = DatabaseFactory.getThreadDatabase(getContext()).getThreadIdFor(recipient);
|
||||
|
||||
this.numberView.setTextColor(color);
|
||||
updateProfilePicture(glideRequests, name, threadID);
|
||||
|
||||
if (!multiSelect && recipient != null && recipient.isLocalNumber()) {
|
||||
name = getContext().getString(R.string.note_to_self);
|
||||
}
|
||||
|
||||
setText(type, name, number, label);
|
||||
|
||||
if (multiSelect) this.checkBox.setVisibility(View.VISIBLE);
|
||||
else this.checkBox.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void setChecked(boolean selected) {
|
||||
this.checkBox.setChecked(selected);
|
||||
}
|
||||
|
||||
public void unbind(GlideRequests glideRequests) {
|
||||
if (recipient != null) {
|
||||
recipient.removeListener(this);
|
||||
recipient = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void setText(int type, String name, String number, String label) {
|
||||
if (number == null || number.isEmpty() || GroupUtil.isEncodedGroup(number)) {
|
||||
this.nameView.setEnabled(false);
|
||||
this.numberView.setText("");
|
||||
this.labelView.setVisibility(View.GONE);
|
||||
} else if (type == ContactsDatabase.PUSH_TYPE) {
|
||||
this.numberView.setText(number);
|
||||
this.nameView.setEnabled(true);
|
||||
this.labelView.setVisibility(View.GONE);
|
||||
} else {
|
||||
this.numberView.setText(number);
|
||||
this.nameView.setEnabled(true);
|
||||
this.labelView.setText(label);
|
||||
this.labelView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
this.nameView.setText(name);
|
||||
}
|
||||
|
||||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModified(final Recipient recipient) {
|
||||
if (this.recipient == recipient) {
|
||||
Util.runOnMain(() -> {
|
||||
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<String> usersAsSet = LokiAPI.Companion.getUserHexEncodedPublicKeyCache().get(threadID);
|
||||
if (usersAsSet == null) {
|
||||
usersAsSet = new HashSet<>();
|
||||
}
|
||||
ArrayList<String> 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();
|
||||
}
|
||||
}
|
@ -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<RecyclerView.ViewHolder>() {
|
||||
class ContactSelectionListAdapter(private val context: Context, private val multiSelect: Boolean) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
|
||||
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<Recipient>()
|
||||
var items = listOf<ContactSelectionListLoaderItem>()
|
||||
var items = listOf<ContactSelectionListItem>()
|
||||
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)
|
@ -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<List<ContactSelectionListLoaderItem>>, ContactClickListener {
|
||||
class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<List<ContactSelectionListItem>>, ContactClickListener {
|
||||
|
||||
companion object {
|
||||
@JvmField val DISPLAY_MODE = "display_mode"
|
||||
@ -27,27 +23,24 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<L
|
||||
@JvmField val REFRESHABLE = "refreshable"
|
||||
}
|
||||
|
||||
var onContactSelectedListener: OnContactSelectedListener? = null
|
||||
|
||||
val selectedContacts: List<String>
|
||||
get() = listAdapter.selectedContacts.map { it.address.serialize() }
|
||||
|
||||
private var items = listOf<ContactSelectionListLoaderItem>()
|
||||
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<L
|
||||
|
||||
fun setQueryFilter(filter: String?) {
|
||||
cursorFilter = filter
|
||||
this.loaderManager.restartLoader<List<ContactSelectionListLoaderItem>>(0, null, this)
|
||||
LoaderManager.getInstance(this).restartLoader(0, null, this)
|
||||
}
|
||||
|
||||
fun resetQueryFilter() {
|
||||
@ -83,32 +76,24 @@ class ContactSelectionListFragment : Fragment(), LoaderManager.LoaderCallbacks<L
|
||||
this.swipeRefresh.setOnRefreshListener(onRefreshListener)
|
||||
}
|
||||
|
||||
override fun onCreateLoader(id: Int, args: Bundle?): Loader<List<ContactSelectionListLoaderItem>> {
|
||||
override fun onCreateLoader(id: Int, args: Bundle?): Loader<List<ContactSelectionListItem>> {
|
||||
return ContactSelectionListLoader(activity!!,
|
||||
activity!!.intent.getIntExtra(DISPLAY_MODE, ContactsCursorLoader.DisplayMode.FLAG_ALL),
|
||||
cursorFilter)
|
||||
}
|
||||
|
||||
override fun onLoadFinished(loader: Loader<List<ContactSelectionListLoaderItem>>, items: List<ContactSelectionListLoaderItem>) {
|
||||
override fun onLoadFinished(loader: Loader<List<ContactSelectionListItem>>, items: List<ContactSelectionListItem>) {
|
||||
update(items)
|
||||
}
|
||||
|
||||
override fun onLoaderReset(loader: Loader<List<ContactSelectionListLoaderItem>>) {
|
||||
override fun onLoaderReset(loader: Loader<List<ContactSelectionListItem>>) {
|
||||
update(listOf())
|
||||
}
|
||||
|
||||
private fun update(items: List<ContactSelectionListLoaderItem>) {
|
||||
this.items = items
|
||||
private fun update(items: List<ContactSelectionListItem>) {
|
||||
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) {
|
@ -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<List<ContactSelectionListLoaderItem>>(context) {
|
||||
class ContactSelectionListLoader(context: Context, val mode: Int, val filter: String?) : AsyncLoader<List<ContactSelectionListItem>>(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<ContactSelectionListLoaderItem> {
|
||||
override fun loadInBackground(): List<ContactSelectionListItem> {
|
||||
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<ContactSelectionListLoaderItem>()
|
||||
val list = mutableListOf<ContactSelectionListItem>()
|
||||
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<Contact>): List<ContactSelectionListLoaderItem> {
|
||||
private fun getFriends(contacts: List<Contact>): List<ContactSelectionListItem> {
|
||||
return getItems(contacts, context.getString(R.string.ContactSelectionListLoader_contacts)) {
|
||||
!it.recipient.isGroupRecipient && it.isFriend && !it.isOurDevice && !it.isSlave
|
||||
}
|
||||
}
|
||||
|
||||
private fun getClosedGroups(contacts: List<Contact>): List<ContactSelectionListLoaderItem> {
|
||||
private fun getClosedGroups(contacts: List<Contact>): List<ContactSelectionListItem> {
|
||||
return getItems(contacts, context.getString(R.string.ContactSelectionListLoader_closed_groups)) {
|
||||
it.recipient.address.isSignalGroup
|
||||
}
|
||||
}
|
||||
|
||||
private fun getOpenGroups(contacts: List<Contact>): List<ContactSelectionListLoaderItem> {
|
||||
private fun getOpenGroups(contacts: List<Contact>): List<ContactSelectionListItem> {
|
||||
return getItems(contacts, context.getString(R.string.ContactSelectionListLoader_open_groups)) {
|
||||
it.recipient.address.isPublicChat
|
||||
}
|
||||
}
|
||||
|
||||
private fun getItems(contacts: List<Contact>, title: String, contactFilter: (Contact) -> Boolean): List<ContactSelectionListLoaderItem> {
|
||||
private fun getItems(contacts: List<Contact>, title: String, contactFilter: (Contact) -> Boolean): List<ContactSelectionListItem> {
|
||||
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
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user