Disable tab switching in media overview during multiselect.

Multiselect only applies to items in the "media" tab, so people
shouldn't be able to switch tabs during multiselect.
This commit is contained in:
Greyson Parrelli 2018-09-27 09:47:08 -07:00
parent a0ab252bc9
commit 84c71fce16
4 changed files with 100 additions and 7 deletions

View File

@ -18,7 +18,7 @@
android:titleTextColor="?attr/media_overview_toolbar_foreground"
app:layout_scrollFlags="scroll|enterAlways"/>
<android.support.design.widget.TabLayout
<org.thoughtcrime.securesms.components.ControllableTabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -30,7 +30,7 @@
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
<org.thoughtcrime.securesms.components.ControllableViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"

View File

@ -71,7 +71,7 @@ import java.util.Locale;
/**
* Activity for displaying media attachments in-app
*/
public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity {
public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity {
@SuppressWarnings("unused")
private final static String TAG = MediaOverviewActivity.class.getSimpleName();
@ -137,6 +137,16 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity
this.recipient.addListener(recipient -> getSupportActionBar().setTitle(recipient.toShortString()));
}
public void onEnterMultiSelect() {
tabLayout.setEnabled(false);
viewPager.setEnabled(false);
}
public void onExitMultiSelect() {
tabLayout.setEnabled(true);
viewPager.setEnabled(true);
}
private class MediaOverviewPagerAdapter extends FragmentStatePagerAdapter {
MediaOverviewPagerAdapter(FragmentManager fragmentManager) {
@ -270,8 +280,7 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity
adapter.toggleSelection(mediaRecord);
if (adapter.getSelectedMediaCount() == 0) {
actionMode.finish();
actionMode = null;
exitMultiSelect();
} else {
actionMode.setTitle(String.valueOf(adapter.getSelectedMediaCount()));
}
@ -304,7 +313,7 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity
((MediaGalleryAdapter) recyclerView.getAdapter()).toggleSelection(mediaRecord);
recyclerView.getAdapter().notifyDataSetChanged();
actionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(actionModeCallback);
enterMultiSelect();
}
}
@ -352,6 +361,17 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity
return (MediaGalleryAdapter) recyclerView.getAdapter();
}
private void enterMultiSelect() {
actionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(actionModeCallback);
((MediaOverviewActivity) getActivity()).onEnterMultiSelect();
}
private void exitMultiSelect() {
actionMode.finish();
actionMode = null;
((MediaOverviewActivity) getActivity()).onExitMultiSelect();
}
private class ActionModeCallback implements ActionMode.Callback {
private int originalStatusBarColor;
@ -379,7 +399,7 @@ public class MediaOverviewActivity extends PassphraseRequiredActionBarActivity
switch (menuItem.getItemId()) {
case R.id.delete:
handleDeleteMedia(getListAdapter().getSelectedMedia());
mode.finish();
exitMultiSelect();
return true;
}
return false;

View File

@ -0,0 +1,41 @@
package org.thoughtcrime.securesms.components;
import android.content.Context;
import android.support.design.widget.TabLayout;
import android.util.AttributeSet;
import android.view.View;
import java.util.List;
/**
* An implementation of {@link TabLayout} that disables taps when the view is disabled.
*/
public class ControllableTabLayout extends TabLayout {
private List<View> touchables;
public ControllableTabLayout(Context context) {
super(context);
}
public ControllableTabLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ControllableTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void setEnabled(boolean enabled) {
if (isEnabled() && !enabled) {
touchables = getTouchables();
}
for (View touchable : touchables) {
touchable.setClickable(enabled);
}
super.setEnabled(enabled);
}
}

View File

@ -0,0 +1,32 @@
package org.thoughtcrime.securesms.components;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
/**
* An implementation of {@link ViewPager} that disables swiping when the view is disabled.
*/
public class ControllableViewPager extends ViewPager {
public ControllableViewPager(@NonNull Context context) {
super(context);
}
public ControllableViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
return isEnabled() && super.onTouchEvent(ev);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return isEnabled() && super.onInterceptTouchEvent(ev);
}
}