Skip to content
This repository has been archived by the owner on Sep 8, 2019. It is now read-only.

Commit

Permalink
- now able to set custom ColumnCount for each Style(except NestedRecy…
Browse files Browse the repository at this point in the history
…clerView Style)

- Bug fixes
  • Loading branch information
kollerlukas committed Apr 7, 2018
1 parent 465eb6b commit 7dd587f
Show file tree
Hide file tree
Showing 19 changed files with 488 additions and 260 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,5 +1,5 @@
*.iml
.gradle
.gradle/
/local.properties
/.idea
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion '26.0.2'
/*buildToolsVersion '26.0.2'*/
defaultConfig {
applicationId "us.koller.cameraroll"
minSdkVersion 19
Expand Down
Expand Up @@ -30,7 +30,6 @@
import us.koller.cameraroll.data.models.Photo;
import us.koller.cameraroll.data.models.RAWImage;
import us.koller.cameraroll.data.models.Video;
import us.koller.cameraroll.ui.AlbumActivity;
import us.koller.cameraroll.ui.ItemActivity;

public class AlbumAdapter extends AbstractRecyclerViewAdapter<Album> {
Expand Down
190 changes: 11 additions & 179 deletions app/src/main/java/us/koller/cameraroll/adapter/main/MainAdapter.java
Expand Up @@ -3,80 +3,49 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

import us.koller.cameraroll.R;
import us.koller.cameraroll.adapter.AbstractRecyclerViewAdapter;
import us.koller.cameraroll.styles.Style;
import us.koller.cameraroll.themes.Theme;
import us.koller.cameraroll.adapter.SelectorModeManager;
import us.koller.cameraroll.adapter.main.viewHolder.AlbumHolder;
import us.koller.cameraroll.adapter.main.viewHolder.NestedRecyclerViewAlbumHolder;
import us.koller.cameraroll.adapter.main.viewHolder.SimpleAlbumHolder;
import us.koller.cameraroll.data.models.Album;
import us.koller.cameraroll.data.provider.Provider;
import us.koller.cameraroll.data.Settings;
import us.koller.cameraroll.ui.AlbumActivity;
import us.koller.cameraroll.ui.MainActivity;
import us.koller.cameraroll.ui.ThemeableActivity;

public class MainAdapter extends AbstractRecyclerViewAdapter<ArrayList<Album>> {

private int viewType;
private Style style;

public MainAdapter(Context context, boolean pick_photos) {
super(pick_photos);

Settings settings = Settings.getInstance(context);

viewType = settings.getStyle(context, pick_photos);
// not allowing NestedRecyclerView Style, when picking photos
Resources res = context.getResources();
if (pick_photos && viewType == res
.getInteger(R.integer.STYLE_NESTED_RECYCLER_VIEW_VALUE)) {
viewType = res.getInteger(R.integer.STYLE_CARDS_VALUE);
}
style = settings.getStyleInstance(context, pick_photos);

setSelectorModeManager(new SelectorModeManager());
}

@NonNull
@Override
public int getItemViewType(int position) {
boolean albumExcluded
= Provider.isDirExcluded(getData().get(position).getPath(),
Provider.getExcludedPaths()) ||
Provider.isDirExcludedBecauseParentDirIsExcluded(
getData().get(position).getPath(), Provider.getExcludedPaths());
if (albumExcluded) {
return viewType + 1;
} else {
return viewType;
}
}

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
RecyclerView.ViewHolder viewHolder;
Resources res = parent.getContext().getResources();
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
if (viewType == res.getInteger(R.integer.STYLE_PARALLAX_VALUE)) {
View v = inflater.inflate(R.layout.album_cover_parallax, parent, false);
viewHolder = new SimpleAlbumHolder(v);
} else if (viewType == res.getInteger(R.integer.STYLE_CARDS_VALUE)) {
View v = inflater.inflate(R.layout.album_cover_card, parent, false);
viewHolder = new SimpleAlbumHolder(v);
} else if (viewType == res.getInteger(R.integer.STYLE_CARDS_2_VALUE)) {
View v = inflater.inflate(R.layout.album_cover_card_2, parent, false);
viewHolder = new SimpleAlbumHolder(v);
} else /*if (viewType == res.getInteger(R.integer.STYLE_NESTED_RECYCLER_VIEW_VALUE))*/ {
View v = inflater.inflate(R.layout.album_cover_nested_recyclerview, parent, false);
viewHolder = new NestedRecyclerViewAlbumHolder(v).setSelectorModeManager(getSelectorManager());

viewHolder = style.createViewHolderInstance(parent);
if (viewHolder instanceof NestedRecyclerViewAlbumHolder) {
((NestedRecyclerViewAlbumHolder) viewHolder).setSelectorModeManager(getSelectorManager());
}

Context context = viewHolder.itemView.getContext();
Expand All @@ -86,7 +55,7 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType
}

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
final Album album = getData().get(position);

((AlbumHolder) holder).setAlbum(album);
Expand Down Expand Up @@ -146,140 +115,3 @@ public void setSelectorModeManager(SelectorModeManager selectorManager) {
notifyItemRangeChanged(0, getItemCount());
}
}

/*public class MainAdapter extends RecyclerView.Adapter {
private int viewType;
private ArrayList<Album> albums;
private boolean pick_photos;
private SelectorModeManager selectorManager;
public MainAdapter(Context context, boolean pick_photos) {
this.pick_photos = pick_photos;
Settings settings = Settings.getInstance(context);
viewType = settings.getStyle(context, pick_photos);
// not allowing NestedRecyclerView Style, when picking photos
Resources res = context.getResources();
if (pick_photos && viewType == res
.getInteger(R.integer.STYLE_NESTED_RECYCLER_VIEW_VALUE)) {
viewType = res.getInteger(R.integer.STYLE_CARDS_VALUE);
}
selectorManager = new SelectorModeManager();
}
public MainAdapter setAlbums(ArrayList<Album> albums) {
this.albums = albums;
return this;
}
@Override
public int getItemViewType(int position) {
boolean albumExcluded
= Provider.isDirExcluded(albums.get(position).getPath(),
Provider.getExcludedPaths()) ||
Provider.isDirExcludedBecauseParentDirIsExcluded(
albums.get(position).getPath(), Provider.getExcludedPaths());
if (albumExcluded) {
return viewType + 1;
} else {
return viewType;
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
RecyclerView.ViewHolder viewHolder;
Resources res = parent.getContext().getResources();
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
if (viewType == res.getInteger(R.integer.STYLE_PARALLAX_VALUE)) {
View v = inflater.inflate(R.layout.album_cover_parallax, parent, false);
viewHolder = new SimpleAlbumHolder(v);
} else if (viewType == res.getInteger(R.integer.STYLE_CARDS_VALUE)) {
View v = inflater.inflate(R.layout.album_cover_card, parent, false);
viewHolder = new SimpleAlbumHolder(v);
} else if (viewType == res.getInteger(R.integer.STYLE_CARDS_2_VALUE)) {
View v = inflater.inflate(R.layout.album_cover_card_2, parent, false);
viewHolder = new SimpleAlbumHolder(v);
} else *//*if (viewType == res.getInteger(R.integer.STYLE_NESTED_RECYCLER_VIEW_VALUE))*//* {
View v = inflater.inflate(R.layout.album_cover_nested_recyclerview, parent, false);
viewHolder = new NestedRecyclerViewAlbumHolder(v).setSelectorModeManager(selectorManager);
}
Context context = viewHolder.itemView.getContext();
Theme theme = Settings.getInstance(context).getThemeInstance(context);
ThemeableActivity.checkTags((ViewGroup) viewHolder.itemView, theme);
return viewHolder;
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
final Album album = albums.get(position);
((AlbumHolder) holder).setAlbum(album);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(holder.itemView.getContext(), AlbumActivity.class);
//intent.putExtra(AlbumActivity.ALBUM, album);
intent.putExtra(AlbumActivity.ALBUM_PATH, album.getPath());
if (pick_photos) {
Context c = holder.itemView.getContext();
boolean allowMultiple = false;
if (c instanceof Activity) {
Activity a = (Activity) c;
allowMultiple = a.getIntent()
.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false);
}
intent.setAction(MainActivity.PICK_PHOTOS);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, allowMultiple);
} else {
intent.setAction(AlbumActivity.VIEW_ALBUM);
}
ActivityOptionsCompat options;
Activity context = (Activity) holder.itemView.getContext();
if (!pick_photos) {
//noinspection unchecked
options = ActivityOptionsCompat.makeSceneTransitionAnimation(context);
context.startActivityForResult(intent,
MainActivity.REFRESH_PHOTOS_REQUEST_CODE, options.toBundle());
} else {
View toolbar = context.findViewById(R.id.toolbar);
options = ActivityOptionsCompat.makeSceneTransitionAnimation(
context, toolbar, context.getString(R.string.toolbar_transition_name));
context.startActivityForResult(intent,
MainActivity.PICK_PHOTOS_REQUEST_CODE, options.toBundle());
}
}
});
}
public void setSelectorModeManager(SelectorModeManager selectorManager) {
this.selectorManager = selectorManager;
notifyItemRangeChanged(0, getItemCount());
}
public SelectorModeManager getSelectorManager() {
return selectorManager;
}
@Override
public int getItemCount() {
return albums != null ? albums.size() : 0;
}
public boolean onBackPressed() {
return getSelectorManager().onBackPressed();
}
public void saveInstanceState(Bundle outState) {
getSelectorManager().saveInstanceState(outState);
}
}*/
56 changes: 22 additions & 34 deletions app/src/main/java/us/koller/cameraroll/data/Settings.java
Expand Up @@ -8,6 +8,11 @@
import android.util.Log;

import us.koller.cameraroll.R;
import us.koller.cameraroll.styles.Cards;
import us.koller.cameraroll.styles.Cards2;
import us.koller.cameraroll.styles.NestedRecyclerView;
import us.koller.cameraroll.styles.Parallax;
import us.koller.cameraroll.styles.Style;
import us.koller.cameraroll.themes.BlackTheme;
import us.koller.cameraroll.themes.DarkTheme;
import us.koller.cameraroll.themes.LightTheme;
Expand All @@ -31,6 +36,7 @@ public class Settings {
private boolean cameraShortcut;
private Uri removableStorageTreeUri;
private boolean virtualDirectories;
@SuppressWarnings("FieldCanBeLocal")
private boolean fadeImages = false;
private boolean showAnimations;

Expand Down Expand Up @@ -129,9 +135,8 @@ public void useStorageRetriever(boolean storageRetriever) {
}

public int getStyle(Context context, boolean pickPhotos) {
Resources res = context.getResources();
if (pickPhotos && style == res.getInteger(R.integer.STYLE_NESTED_RECYCLER_VIEW_VALUE)) {
return res.getInteger(R.integer.STYLE_CARDS_VALUE);
if (pickPhotos && style == NestedRecyclerView.getValue(context)) {
return Cards2.getValue(context);
}
return style;
}
Expand All @@ -140,25 +145,22 @@ public void setStyle(int style) {
this.style = style;
}

public int getStyleColumnCount(Context context, int style) {
Resources res = context.getResources();
boolean landscape = res.getBoolean(R.bool.landscape);
int styleColumnCount = getDefaultStyleColumnCount(context, style);
if (landscape &&
(style == res.getInteger(R.integer.STYLE_CARDS_VALUE) ||
style == res.getInteger(R.integer.STYLE_CARDS_2_VALUE))) {
return styleColumnCount + 1;
}
return styleColumnCount;
public Style getStyleInstance(Context context, boolean pickPhotos) {
int style = getStyle(context, pickPhotos);
return getStyleInstance(context, style);
}

public int getStyleGridSpacing(Context context, int style) {
Resources res = context.getResources();
if (style == res.getInteger(R.integer.STYLE_CARDS_VALUE)
|| style == res.getInteger(R.integer.STYLE_CARDS_2_VALUE)) {
return (int) res.getDimension(R.dimen.cards_style_grid_spacing);
public Style getStyleInstance(Context context, int style) {
if (style == Parallax.getValue(context)) {
return new Parallax();
} else if (style == Cards.getValue(context)) {
return new Cards();
} else if (style == Cards2.getValue(context)) {
return new Cards2();
} else if (style == NestedRecyclerView.getValue(context)) {
return new NestedRecyclerView();
}
return 0;
return null;
}

public int getColumnCount(Context context) {
Expand All @@ -184,20 +186,6 @@ public void setColumnCount(int columnCount) {
this.columnCount = columnCount;
}

private static int getDefaultStyleColumnCount(Context context, int style) {
Resources res = context.getResources();
if (style == res.getInteger(R.integer.STYLE_PARALLAX_VALUE)) {
return res.getInteger(R.integer.STYLE_PARALLAX_COLUMN_COUNT);
} else if (style == res.getInteger(R.integer.STYLE_CARDS_VALUE)) {
return res.getInteger(R.integer.STYLE_CARDS_COLUMN_COUNT);
} else if (style == res.getInteger(R.integer.STYLE_CARDS_2_VALUE)) {
return res.getInteger(R.integer.STYLE_CARDS_2_COLUMN_COUNT);
} else if (style == res.getInteger(R.integer.STYLE_NESTED_RECYCLER_VIEW_VALUE)) {
return res.getInteger(R.integer.STYLE_NESTED_RECYCLER_VIEW_COLUMN_COUNT);
}
return 1;
}

public int sortAlbumsBy() {
return sort_albums_by;
}
Expand Down Expand Up @@ -293,7 +281,7 @@ public void setRemovableStorageTreeUri(Context context, Uri removableStorageTree
removableStorageTreeUri.toString());
}

private static void saveInt(Context context, String key, int value) {
public static void saveInt(Context context, String key, int value) {
SharedPreferences sharedPreferences
= PreferenceManager.getDefaultSharedPreferences(context);
sharedPreferences
Expand Down

0 comments on commit 7dd587f

Please sign in to comment.