Commit d8f8edfd authored by Donald's avatar Donald

sorting on albums works well

parent a93b5a54
......@@ -2,7 +2,6 @@ apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
repositories {
maven { url "http://repo1.maven.org/maven2" }
maven { url "http://dl.bintray.com/dasar/maven" }
}
......
......@@ -255,11 +255,18 @@ public class MainActivity extends SharedMediaActivity {
// TODO: 3/25/17 organize better
/**** DRAWER ****/
drawer.addDrawerListener(new ActionBarDrawerToggle(this,
ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this,
drawer, toolbar, R.string.drawer_open, R.string.drawer_close) {
public void onDrawerClosed(View view) { }
public void onDrawerOpened(View drawerView) { }
});
public void onDrawerClosed(View view) {
}
public void onDrawerOpened(View drawerView) {
}
};
drawer.addDrawerListener(drawerToggle);
drawerToggle.syncState();
findViewById(R.id.ll_drawer_Donate).setOnClickListener(new View.OnClickListener() {
@Override
......
......@@ -55,25 +55,6 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
private SortingOrder sortingOrder;
private SortingMode sortingMode;
public SortingOrder sortingOrder() {
return sortingOrder;
}
public void changeSortingOrder(SortingOrder sortingOrder) {
this.sortingOrder = sortingOrder;
reverseOrder();
notifyDataSetChanged();
}
public SortingMode sortingMode() {
return sortingMode;
}
public void changeSortingMode(SortingMode sortingMode) {
this.sortingMode = sortingMode;
sort();
}
private ThemeHelper theme;
private BitmapDrawable placeholder;
private CardViewStyle cvs;
......@@ -85,10 +66,6 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
this.sortingOrder = sortingOrder;
}
public AlbumsAdapter(Context context) {
this(context, SortingMode.DATE, SortingOrder.DESCENDING);
}
public void sort() {
/*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
albums.sort(AlbumsComparators.getComparator(sortingMode));
......@@ -97,9 +74,29 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
Collections.sort(albums, AlbumsComparators.getComparator(sortingMode, sortingOrder));
/*if (sortingOrder.equals(SortingOrder.DESCENDING))
reverseOrder();*/
notifyDataSetChanged();
}
public SortingOrder sortingOrder() {
return sortingOrder;
}
public void changeSortingOrder(SortingOrder sortingOrder) {
this.sortingOrder = sortingOrder;
reverseOrder();
notifyDataSetChanged();
}
public SortingMode sortingMode() {
return sortingMode;
}
public void changeSortingMode(SortingMode sortingMode) {
this.sortingMode = sortingMode;
sort();
}
public List<Album> getSelectedAlbums() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return albums.stream().filter(Album::isSelected).collect(Collectors.toList());
......@@ -264,7 +261,7 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
private void reverseOrder() {
int z = 0, size = getItemCount();
while (z < size && albums.get(0).isPinned())
while (z < size && albums.get(z).isPinned())
z++;
for (int i = Math.max(0, z), mid = (i+size)>>1, j = size-1; i < mid; i++, j--)
......
......@@ -10,6 +10,7 @@ import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
......@@ -57,10 +58,8 @@ public class AlbumsFragment extends Fragment implements IFragment, Themeable {
private AlbumsAdapter albumsAdapter;
private GridSpacingItemDecoration rvAlbumsDecoration;
MainActivity act;
MainActivity act;
boolean hidden;
@Override
......@@ -141,7 +140,6 @@ public class AlbumsFragment extends Fragment implements IFragment, Themeable {
private void updateToolbar() {
if (editMode())
//todo improve
act.updateToolbar(
String.format(Locale.ENGLISH, "%d/%d",
......@@ -174,6 +172,11 @@ public class AlbumsFragment extends Fragment implements IFragment, Themeable {
.observeOn(AndroidSchedulers.mainThread())
.subscribe(album -> Toast.makeText(getContext(), album.toString(), Toast.LENGTH_SHORT).show());
albumsAdapter.getAlbumsSelectedClicks()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(album -> updateToolbar());
refresh.setOnRefreshListener(this::displayAlbums);
rvAlbums.setAdapter(albumsAdapter);
......@@ -190,6 +193,8 @@ public class AlbumsFragment extends Fragment implements IFragment, Themeable {
? R.string.clear_selected
: R.string.select_all));
Log.d(TAG, "onCreateOptionsMenu: " +sortingOrder());
menu.findItem(R.id.ascending_sort_action).setChecked(sortingOrder() == SortingOrder.ASCENDING);
switch (sortingMode()) {
......@@ -295,9 +300,10 @@ public class AlbumsFragment extends Fragment implements IFragment, Themeable {
return true;
case R.id.ascending_sort_action:
albumsAdapter.changeSortingOrder(SortingOrder.fromValue(item.isChecked()));
AlbumsHelper.setSortingOrder(getContext(), sortingOrder());
item.setChecked(!item.isChecked());
SortingOrder sortingOrder = SortingOrder.fromValue(item.isChecked());
albumsAdapter.changeSortingOrder(sortingOrder);
AlbumsHelper.setSortingOrder(getContext(), sortingOrder);
return true;
}
......
......@@ -36,22 +36,6 @@ public class AlbumsComparators {
return (o1, o2) -> comparator.compare(o2, o1);
}
/*private static Comparator<Album> getNameComparator(final SortingOrder sortingOrder) {
return (a1, a2) -> {
switch (sortingOrder) {
case ASCENDING:
if (a1.isPinned() == a2.isPinned())
return a1.getName().toLowerCase().compareTo(a2.getName().toLowerCase());
return a1.isPinned() ? -1 : 1;
case DESCENDING: default:
if (a1.isPinned() == a2.isPinned())
return a2.getName().toLowerCase().compareTo(a1.getName().toLowerCase());
return a2.isPinned() ? 1 : -1;
}
};
}*/
private static Comparator<Album> getBaseComparator(SortingOrder sortingOrder) {
return sortingOrder == SortingOrder.ASCENDING
? getPinned() : getReversedPinned();
......@@ -65,10 +49,7 @@ public class AlbumsComparators {
}
private static Comparator<Album> getReversedPinned() {
return (o1, o2) -> {
if (o1.isPinned() == o2.isPinned()) return 0;
return o2.isPinned() ? 1 : -1;
};
return (o1, o2) -> getPinned().compare(o2, o1);
}
private static Comparator<Album> getDateComparator(Comparator<Album> base){
......
......@@ -3,7 +3,6 @@ package org.horaapps.leafpic.new_way;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;
import org.horaapps.leafpic.util.StringUtils;
......@@ -30,7 +29,7 @@ public class Query {
}
public Cursor getCursor(ContentResolver cr) {
Log.wtf("asd",hack());
//Log.wtf("asd",hack());
return cr.query(uri, projection, selection, args, hack());
}
......
......@@ -3,8 +3,6 @@
buildscript {
repositories {
jcenter()
maven { url "https://plugins.gradle.org/m2/" }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.4.0-alpha3'
......
......@@ -13,9 +13,3 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Sat Mar 25 09:54:58 CET 2017
systemProp.https.proxyPort=3128
systemProp.http.proxyHost=10.0.5.1
org.gradle.daemon=true
systemProp.https.proxyHost=10.0.5.1
org.gradle.configureondemand=true
systemProp.http.proxyPort=3128
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment