mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 11:28:34 +00:00
Close keyboard on contact list scroll.
This commit is contained in:
parent
9acdc37729
commit
4aded3a436
@ -19,20 +19,18 @@ package org.thoughtcrime.securesms;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.components.ContactFilterToolbar;
|
import org.thoughtcrime.securesms.components.ContactFilterToolbar;
|
||||||
import org.thoughtcrime.securesms.contacts.ContactsCursorLoader.DisplayMode;
|
import org.thoughtcrime.securesms.contacts.ContactsCursorLoader.DisplayMode;
|
||||||
import org.thoughtcrime.securesms.contacts.sync.DirectoryHelper;
|
import org.thoughtcrime.securesms.contacts.sync.DirectoryHelper;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
||||||
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
||||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||||
|
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
|
||||||
import org.whispersystems.libsignal.util.guava.Optional;
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -46,14 +44,14 @@ import java.lang.ref.WeakReference;
|
|||||||
*/
|
*/
|
||||||
public abstract class ContactSelectionActivity extends PassphraseRequiredActionBarActivity
|
public abstract class ContactSelectionActivity extends PassphraseRequiredActionBarActivity
|
||||||
implements SwipeRefreshLayout.OnRefreshListener,
|
implements SwipeRefreshLayout.OnRefreshListener,
|
||||||
ContactSelectionListFragment.OnContactSelectedListener
|
ContactSelectionListFragment.OnContactSelectedListener,
|
||||||
|
ContactSelectionListFragment.ScrollCallback
|
||||||
{
|
{
|
||||||
private static final String TAG = ContactSelectionActivity.class.getSimpleName();
|
private static final String TAG = ContactSelectionActivity.class.getSimpleName();
|
||||||
|
|
||||||
public static final String EXTRA_LAYOUT_RES_ID = "layout_res_id";
|
public static final String EXTRA_LAYOUT_RES_ID = "layout_res_id";
|
||||||
|
|
||||||
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
|
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
|
||||||
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
|
||||||
|
|
||||||
protected ContactSelectionListFragment contactsFragment;
|
protected ContactSelectionListFragment contactsFragment;
|
||||||
|
|
||||||
@ -62,7 +60,6 @@ public abstract class ContactSelectionActivity extends PassphraseRequiredActionB
|
|||||||
@Override
|
@Override
|
||||||
protected void onPreCreate() {
|
protected void onPreCreate() {
|
||||||
dynamicTheme.onCreate(this);
|
dynamicTheme.onCreate(this);
|
||||||
dynamicLanguage.onCreate(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -84,7 +81,6 @@ public abstract class ContactSelectionActivity extends PassphraseRequiredActionB
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
dynamicTheme.onResume(this);
|
dynamicTheme.onResume(this);
|
||||||
dynamicLanguage.onResume(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ContactFilterToolbar getToolbar() {
|
protected ContactFilterToolbar getToolbar() {
|
||||||
@ -95,7 +91,6 @@ public abstract class ContactSelectionActivity extends PassphraseRequiredActionB
|
|||||||
this.toolbar = findViewById(R.id.toolbar);
|
this.toolbar = findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
assert getSupportActionBar() != null;
|
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||||
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
||||||
getSupportActionBar().setIcon(null);
|
getSupportActionBar().setIcon(null);
|
||||||
@ -123,6 +118,17 @@ public abstract class ContactSelectionActivity extends PassphraseRequiredActionB
|
|||||||
@Override
|
@Override
|
||||||
public void onContactDeselected(Optional<RecipientId> recipientId, String number) {}
|
public void onContactDeselected(Optional<RecipientId> recipientId, String number) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBeginScroll() {
|
||||||
|
hideKeyboard();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void hideKeyboard() {
|
||||||
|
ServiceUtil.getInputMethodManager(this)
|
||||||
|
.hideSoftInputFromWindow(toolbar.getWindowToken(), 0);
|
||||||
|
toolbar.clearFocus();
|
||||||
|
}
|
||||||
|
|
||||||
private static class RefreshDirectoryTask extends AsyncTask<Context, Void, Void> {
|
private static class RefreshDirectoryTask extends AsyncTask<Context, Void, Void> {
|
||||||
|
|
||||||
private final WeakReference<ContactSelectionActivity> activity;
|
private final WeakReference<ContactSelectionActivity> activity;
|
||||||
|
@ -67,7 +67,6 @@ import org.thoughtcrime.securesms.util.FeatureFlags;
|
|||||||
import org.thoughtcrime.securesms.util.StickyHeaderDecoration;
|
import org.thoughtcrime.securesms.util.StickyHeaderDecoration;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.thoughtcrime.securesms.util.UsernameUtil;
|
import org.thoughtcrime.securesms.util.UsernameUtil;
|
||||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
|
||||||
import org.thoughtcrime.securesms.util.adapter.FixedViewsAdapter;
|
import org.thoughtcrime.securesms.util.adapter.FixedViewsAdapter;
|
||||||
import org.thoughtcrime.securesms.util.adapter.RecyclerViewConcatenateAdapterStickyHeader;
|
import org.thoughtcrime.securesms.util.adapter.RecyclerViewConcatenateAdapterStickyHeader;
|
||||||
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
|
import org.thoughtcrime.securesms.util.concurrent.SimpleTask;
|
||||||
@ -114,6 +113,7 @@ public final class ContactSelectionListFragment extends Fragment
|
|||||||
@Nullable private FixedViewsAdapter headerAdapter;
|
@Nullable private FixedViewsAdapter headerAdapter;
|
||||||
@Nullable private FixedViewsAdapter footerAdapter;
|
@Nullable private FixedViewsAdapter footerAdapter;
|
||||||
@Nullable private ListCallback listCallback;
|
@Nullable private ListCallback listCallback;
|
||||||
|
@Nullable private ScrollCallback scrollCallback;
|
||||||
private GlideRequests glideRequests;
|
private GlideRequests glideRequests;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -123,6 +123,10 @@ public final class ContactSelectionListFragment extends Fragment
|
|||||||
if (context instanceof ListCallback) {
|
if (context instanceof ListCallback) {
|
||||||
listCallback = (ListCallback) context;
|
listCallback = (ListCallback) context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (context instanceof ScrollCallback) {
|
||||||
|
scrollCallback = (ScrollCallback) context;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -164,10 +168,10 @@ public final class ContactSelectionListFragment extends Fragment
|
|||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.contact_selection_list_fragment, container, false);
|
View view = inflater.inflate(R.layout.contact_selection_list_fragment, container, false);
|
||||||
|
|
||||||
emptyText = ViewUtil.findById(view, android.R.id.empty);
|
emptyText = view.findViewById(android.R.id.empty);
|
||||||
recyclerView = ViewUtil.findById(view, R.id.recycler_view);
|
recyclerView = view.findViewById(R.id.recycler_view);
|
||||||
swipeRefresh = ViewUtil.findById(view, R.id.swipe_refresh);
|
swipeRefresh = view.findViewById(R.id.swipe_refresh);
|
||||||
fastScroller = ViewUtil.findById(view, R.id.fast_scroller);
|
fastScroller = view.findViewById(R.id.fast_scroller);
|
||||||
showContactsLayout = view.findViewById(R.id.show_contacts_container);
|
showContactsLayout = view.findViewById(R.id.show_contacts_container);
|
||||||
showContactsButton = view.findViewById(R.id.show_contacts_button);
|
showContactsButton = view.findViewById(R.id.show_contacts_button);
|
||||||
showContactsDescription = view.findViewById(R.id.show_contacts_description);
|
showContactsDescription = view.findViewById(R.id.show_contacts_description);
|
||||||
@ -236,6 +240,16 @@ public final class ContactSelectionListFragment extends Fragment
|
|||||||
|
|
||||||
recyclerView.setAdapter(concatenateAdapter);
|
recyclerView.setAdapter(concatenateAdapter);
|
||||||
recyclerView.addItemDecoration(new StickyHeaderDecoration(concatenateAdapter, true, true));
|
recyclerView.addItemDecoration(new StickyHeaderDecoration(concatenateAdapter, true, true));
|
||||||
|
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
|
@Override
|
||||||
|
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
|
||||||
|
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
|
||||||
|
if (scrollCallback != null) {
|
||||||
|
scrollCallback.onBeginScroll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private View createInviteActionView(@NonNull ListCallback listCallback) {
|
private View createInviteActionView(@NonNull ListCallback listCallback) {
|
||||||
@ -292,15 +306,16 @@ public final class ContactSelectionListFragment extends Fragment
|
|||||||
cursorRecyclerViewAdapter.clearSelectedContacts();
|
cursorRecyclerViewAdapter.clearSelectedContacts();
|
||||||
|
|
||||||
if (!isDetached() && !isRemoving() && getActivity() != null && !getActivity().isFinishing()) {
|
if (!isDetached() && !isRemoving() && getActivity() != null && !getActivity().isFinishing()) {
|
||||||
getLoaderManager().restartLoader(0, null, this);
|
LoaderManager.getInstance(this).restartLoader(0, null, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
public @NonNull Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
||||||
return new ContactsCursorLoader(getActivity(),
|
FragmentActivity activity = requireActivity();
|
||||||
getActivity().getIntent().getIntExtra(DISPLAY_MODE, DisplayMode.FLAG_ALL),
|
return new ContactsCursorLoader(activity,
|
||||||
cursorFilter, getActivity().getIntent().getBooleanExtra(RECENTS, false));
|
activity.getIntent().getIntExtra(DISPLAY_MODE, DisplayMode.FLAG_ALL),
|
||||||
|
cursorFilter, activity.getIntent().getBooleanExtra(RECENTS, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -501,4 +516,8 @@ public final class ContactSelectionListFragment extends Fragment
|
|||||||
void onInvite();
|
void onInvite();
|
||||||
void onNewGroup();
|
void onNewGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface ScrollCallback {
|
||||||
|
void onBeginScroll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user