mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 02:25:19 +00:00
parent
f010a3ec0d
commit
2c28fa6a57
@ -69,6 +69,7 @@ public class GiphyActivity extends PassphraseRequiredActionBarActivity
|
|||||||
GiphyActivityToolbar toolbar = ViewUtil.findById(this, R.id.giphy_toolbar);
|
GiphyActivityToolbar toolbar = ViewUtil.findById(this, R.id.giphy_toolbar);
|
||||||
toolbar.setOnFilterChangedListener(this);
|
toolbar.setOnFilterChangedListener(this);
|
||||||
toolbar.setOnLayoutChangedListener(this);
|
toolbar.setOnLayoutChangedListener(this);
|
||||||
|
toolbar.setPersistence(GiphyActivityToolbarTextSecurePreferencesPersistence.fromContext(this));
|
||||||
|
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
@ -99,9 +100,9 @@ public class GiphyActivity extends PassphraseRequiredActionBarActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLayoutChanged(int type) {
|
public void onLayoutChanged(boolean gridLayout) {
|
||||||
this.gifFragment.setLayoutManager(type);
|
gifFragment.setLayoutManager(gridLayout);
|
||||||
this.stickerFragment.setLayoutManager(type);
|
stickerFragment.setLayoutManager(gridLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
|
@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.giph.ui;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
@ -21,7 +22,6 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.components.AnimatingToggle;
|
import org.thoughtcrime.securesms.components.AnimatingToggle;
|
||||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
|
||||||
|
|
||||||
public class GiphyActivityToolbar extends Toolbar {
|
public class GiphyActivityToolbar extends Toolbar {
|
||||||
|
|
||||||
@ -31,10 +31,11 @@ public class GiphyActivityToolbar extends Toolbar {
|
|||||||
private EditText searchText;
|
private EditText searchText;
|
||||||
private AnimatingToggle toggle;
|
private AnimatingToggle toggle;
|
||||||
private ImageView action;
|
private ImageView action;
|
||||||
private ImageView listToggle;
|
|
||||||
private ImageView gridToggle;
|
|
||||||
private ImageView clearToggle;
|
private ImageView clearToggle;
|
||||||
private LinearLayout toggleContainer;
|
private LinearLayout toggleContainer;
|
||||||
|
private View listLayoutToggle;
|
||||||
|
private View gridLayoutToggle;
|
||||||
|
private Persistence persistence;
|
||||||
|
|
||||||
public GiphyActivityToolbar(Context context) {
|
public GiphyActivityToolbar(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
@ -48,29 +49,15 @@ public class GiphyActivityToolbar extends Toolbar {
|
|||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
inflate(context, R.layout.giphy_activity_toolbar, this);
|
inflate(context, R.layout.giphy_activity_toolbar, this);
|
||||||
|
|
||||||
this.action = ViewUtil.findById(this, R.id.action_icon);
|
this.action = findViewById(R.id.action_icon);
|
||||||
this.searchText = ViewUtil.findById(this, R.id.search_view);
|
this.searchText = findViewById(R.id.search_view);
|
||||||
this.toggle = ViewUtil.findById(this, R.id.button_toggle);
|
this.toggle = findViewById(R.id.button_toggle);
|
||||||
this.listToggle = ViewUtil.findById(this, R.id.view_stream);
|
this.clearToggle = findViewById(R.id.search_clear);
|
||||||
this.gridToggle = ViewUtil.findById(this, R.id.view_grid);
|
this.toggleContainer = findViewById(R.id.toggle_container);
|
||||||
this.clearToggle = ViewUtil.findById(this, R.id.search_clear);
|
this.listLayoutToggle = findViewById(R.id.view_stream);
|
||||||
this.toggleContainer = ViewUtil.findById(this, R.id.toggle_container);
|
this.gridLayoutToggle = findViewById(R.id.view_grid);
|
||||||
|
|
||||||
this.listToggle.setOnClickListener(new View.OnClickListener() {
|
setupGridLayoutToggles();
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
displayTogglingView(gridToggle);
|
|
||||||
if (layoutListener != null) layoutListener.onLayoutChanged(OnLayoutChangedListener.LAYOUT_LIST);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.gridToggle.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
displayTogglingView(listToggle);
|
|
||||||
if (layoutListener != null) layoutListener.onLayoutChanged(OnLayoutChangedListener.LAYOUT_GRID);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.clearToggle.setOnClickListener(new View.OnClickListener() {
|
this.clearToggle.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -116,7 +103,29 @@ public class GiphyActivityToolbar extends Toolbar {
|
|||||||
setNavigationIcon(null);
|
setNavigationIcon(null);
|
||||||
setContentInsetStartWithNavigation(0);
|
setContentInsetStartWithNavigation(0);
|
||||||
expandTapArea(this, action);
|
expandTapArea(this, action);
|
||||||
expandTapArea(toggleContainer, gridToggle);
|
}
|
||||||
|
|
||||||
|
public void setPersistence(@NonNull Persistence persistence) {
|
||||||
|
this.persistence = persistence;
|
||||||
|
displayTogglingView(persistence.getGridSelected() ? listLayoutToggle : gridLayoutToggle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupGridLayoutToggles() {
|
||||||
|
setUpGridToggle(listLayoutToggle, gridLayoutToggle, false);
|
||||||
|
setUpGridToggle(gridLayoutToggle, listLayoutToggle, true);
|
||||||
|
displayTogglingView(gridLayoutToggle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setUpGridToggle(View gridToggle, View otherToggle, boolean gridLayout) {
|
||||||
|
gridToggle.setOnClickListener(v -> {
|
||||||
|
displayTogglingView(otherToggle);
|
||||||
|
if (layoutListener != null) {
|
||||||
|
layoutListener.onLayoutChanged(gridLayout);
|
||||||
|
}
|
||||||
|
if (persistence != null) {
|
||||||
|
persistence.setGridSelected(gridLayout);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -184,10 +193,11 @@ public class GiphyActivityToolbar extends Toolbar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface OnLayoutChangedListener {
|
public interface OnLayoutChangedListener {
|
||||||
public static final int LAYOUT_GRID = 1;
|
void onLayoutChanged(boolean gridLayout);
|
||||||
public static final int LAYOUT_LIST = 2;
|
|
||||||
void onLayoutChanged(int type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface Persistence {
|
||||||
|
boolean getGridSelected();
|
||||||
|
void setGridSelected(boolean isGridSelected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
package org.thoughtcrime.securesms.giph.ui;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
|
|
||||||
|
class GiphyActivityToolbarTextSecurePreferencesPersistence implements GiphyActivityToolbar.Persistence {
|
||||||
|
|
||||||
|
static GiphyActivityToolbar.Persistence fromContext(Context context) {
|
||||||
|
return new GiphyActivityToolbarTextSecurePreferencesPersistence(context.getApplicationContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
|
private GiphyActivityToolbarTextSecurePreferencesPersistence(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getGridSelected() {
|
||||||
|
return TextSecurePreferences.isGifSearchInGridLayout(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setGridSelected(boolean isGridSelected) {
|
||||||
|
TextSecurePreferences.setIsGifSearchInGridLayout(context, isGridSelected);
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,7 @@ import org.thoughtcrime.securesms.giph.model.GiphyImage;
|
|||||||
import org.thoughtcrime.securesms.giph.net.GiphyLoader;
|
import org.thoughtcrime.securesms.giph.net.GiphyLoader;
|
||||||
import org.thoughtcrime.securesms.giph.util.InfiniteScrollListener;
|
import org.thoughtcrime.securesms.giph.util.InfiniteScrollListener;
|
||||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||||
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -56,7 +57,7 @@ public abstract class GiphyFragment extends Fragment implements LoaderManager.Lo
|
|||||||
this.giphyAdapter = new GiphyAdapter(getActivity(), GlideApp.with(this), new LinkedList<>());
|
this.giphyAdapter = new GiphyAdapter(getActivity(), GlideApp.with(this), new LinkedList<>());
|
||||||
this.giphyAdapter.setListener(this);
|
this.giphyAdapter.setListener(this);
|
||||||
|
|
||||||
this.recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
setLayoutManager(TextSecurePreferences.isGifSearchInGridLayout(getContext()));
|
||||||
this.recyclerView.setItemAnimator(new DefaultItemAnimator());
|
this.recyclerView.setItemAnimator(new DefaultItemAnimator());
|
||||||
this.recyclerView.setAdapter(giphyAdapter);
|
this.recyclerView.setAdapter(giphyAdapter);
|
||||||
this.recyclerView.addOnScrollListener(new GiphyScrollListener());
|
this.recyclerView.addOnScrollListener(new GiphyScrollListener());
|
||||||
@ -80,12 +81,13 @@ public abstract class GiphyFragment extends Fragment implements LoaderManager.Lo
|
|||||||
this.giphyAdapter.setImages(new LinkedList<GiphyImage>());
|
this.giphyAdapter.setImages(new LinkedList<GiphyImage>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLayoutManager(int type) {
|
public void setLayoutManager(boolean gridLayout) {
|
||||||
if (type == GiphyActivityToolbar.OnLayoutChangedListener.LAYOUT_GRID) {
|
recyclerView.setLayoutManager(getLayoutManager(gridLayout));
|
||||||
this.recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
|
|
||||||
} else {
|
|
||||||
this.recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private RecyclerView.LayoutManager getLayoutManager(boolean gridLayout) {
|
||||||
|
return gridLayout ? new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
|
||||||
|
: new LinearLayoutManager(getActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setClickListener(GiphyAdapter.OnItemClickListener listener) {
|
public void setClickListener(GiphyAdapter.OnItemClickListener listener) {
|
||||||
|
@ -177,6 +177,8 @@ public class TextSecurePreferences {
|
|||||||
|
|
||||||
public static final String LINK_PREVIEWS = "pref_link_previews";
|
public static final String LINK_PREVIEWS = "pref_link_previews";
|
||||||
|
|
||||||
|
private static final String GIF_GRID_LAYOUT = "pref_gif_grid_layout";
|
||||||
|
|
||||||
public static boolean isScreenLockEnabled(@NonNull Context context) {
|
public static boolean isScreenLockEnabled(@NonNull Context context) {
|
||||||
return getBooleanPreference(context, SCREEN_LOCK, false);
|
return getBooleanPreference(context, SCREEN_LOCK, false);
|
||||||
}
|
}
|
||||||
@ -362,6 +364,14 @@ public class TextSecurePreferences {
|
|||||||
return getBooleanPreference(context, LINK_PREVIEWS, true);
|
return getBooleanPreference(context, LINK_PREVIEWS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isGifSearchInGridLayout(Context context) {
|
||||||
|
return getBooleanPreference(context, GIF_GRID_LAYOUT, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setIsGifSearchInGridLayout(Context context, boolean isGrid) {
|
||||||
|
setBooleanPreference(context, GIF_GRID_LAYOUT, isGrid);
|
||||||
|
}
|
||||||
|
|
||||||
public static @Nullable String getProfileKey(Context context) {
|
public static @Nullable String getProfileKey(Context context) {
|
||||||
return getStringPreference(context, PROFILE_KEY_PREF, null);
|
return getStringPreference(context, PROFILE_KEY_PREF, null);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user