Skip to content

Commit

Permalink
removed gen stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
dnldsht committed Jun 28, 2017
1 parent d109ee7 commit dd86963
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 35 deletions.
8 changes: 0 additions & 8 deletions app/src/main/gen/com/horaapps/leafpic/BuildConfig.java

This file was deleted.

7 changes: 0 additions & 7 deletions app/src/main/gen/com/horaapps/leafpic/Manifest.java

This file was deleted.

7 changes: 0 additions & 7 deletions app/src/main/gen/com/horaapps/leafpic/R.java

This file was deleted.

51 changes: 42 additions & 9 deletions app/src/main/java/org/horaapps/leafpic/data/provider/CPHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.provider.MediaStore;
import android.util.Log;

import org.horaapps.leafpic.data.Album;
import org.horaapps.leafpic.data.ContentHelper;
Expand All @@ -13,6 +14,7 @@
import org.horaapps.leafpic.util.PreferenceUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;

import io.reactivex.Observable;
Expand All @@ -31,30 +33,61 @@ public static Observable<Album> getAlbums(Context context, boolean hidden, Sorti
return !hidden ? getAlbums(context, excluded, sortingMode, sortingOrder) : getHiddenAlbums(context, excluded);
}

private static String getHavingCluause(HashSet<String> excluded){
if (excluded.size() == 0) return "";


private static Observable<Album> getAlbums(Context context, HashSet<String> excludedAlbums, SortingMode sortingMode, SortingOrder sortingOrder) {
//String[] paths = excluded.toArray(new String[excluded.size()]);
StringBuilder res = new StringBuilder();
res.append("HAVING (");
//res.append(MediaStore.Images.Media.DATA).append(" NOT LIKE '").append(pa.).append("%'");
res.append(MediaStore.Images.Media.DATA).append(" NOT LIKE ?");

for (int i = 1; i < excluded.size(); i++)
res.append(" AND ")
.append(MediaStore.Images.Media.DATA)
.append(" NOT LIKE ?");


res.append(")");

return res.toString();

}

public static Observable<Album> getAlbums(Context context, HashSet<String> excludedAlbums, SortingMode sortingMode, SortingOrder sortingOrder) {

Query.Builder query = new Query.Builder()
.uri(MediaStore.Files.getContentUri("external"))
.projection(Album.getProjection())
.sort(sortingMode.getAlbumsColumn())
.ascending(sortingOrder.isAscending());

ArrayList<Object> args = new ArrayList<>();

if (PreferenceUtil.getBool(context, "set_include_video", true)) {
query.selection(String.format("%s=? or %s=?) group by ( %s ",
query.selection(String.format("%s=? or %s=?) group by (%s) %s ",
MediaStore.Files.FileColumns.MEDIA_TYPE,
MediaStore.Files.FileColumns.MEDIA_TYPE,
MediaStore.Files.FileColumns.PARENT));

query.args(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE,
MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO);
MediaStore.Files.FileColumns.PARENT,
getHavingCluause(excludedAlbums)));
args.add(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE);
args.add(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO);
} else {
query.selection(String.format("%s=?) group by ( %s ",
query.selection(String.format("%s=?) group by (%s) %s ",
MediaStore.Files.FileColumns.MEDIA_TYPE,
MediaStore.Files.FileColumns.PARENT));
query.args(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE);
MediaStore.Files.FileColumns.PARENT,
getHavingCluause(excludedAlbums)));
args.add(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE);
//query.args(, excludedAlbums);
}

Log.wtf("asd", query.selection);
for (String s : excludedAlbums) {
args.add(s+"%");
}
//args.addAll(excludedAlbums);
query.args(args.toArray());


return QueryUtils.query(query.build(), context.getContentResolver(), Album::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.support.v4.widget.SwipeRefreshLayout;
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;
Expand All @@ -32,6 +33,7 @@
import org.horaapps.leafpic.util.ThemeHelper;
import org.horaapps.leafpic.views.GridSpacingItemDecoration;

import java.util.HashSet;
import java.util.Locale;

import butterknife.BindView;
Expand All @@ -56,10 +58,14 @@ public class AlbumsFragment extends BaseFragment{

private MainActivity act;
private boolean hidden = false;
HashSet<String> excuded = new HashSet<>();


@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
excuded.add("/storage/emulated/0/Pictures");
excuded.add("/storage/emulated/0/Download/apk");
setHasOptionsMenu(true);
}

Expand All @@ -81,21 +87,37 @@ public void displayAlbums(boolean hidden) {
displayAlbums();
}


private boolean isOk(String path){
for (String s : excuded) {
if (path.startsWith(s)) return false;
}
return true;
}

private void displayAlbums() {
adapter.clear();


adapter.clear();
long start = System.currentTimeMillis();
SQLiteDatabase db = HandlingAlbums.getInstance(getContext()).getReadableDatabase();
CPHelper.getAlbums(getContext(), hidden, sortingMode(), sortingOrder())
CPHelper.getAlbums(getContext(), excuded, sortingMode(), sortingOrder())
.subscribeOn(Schedulers.io())
//.filter(album -> isOk(album.getPath()))
.map(album -> album.withSettings(HandlingAlbums.getSettings(db, album.getPath())))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
album -> adapter.add(album),
album -> {
adapter.add(album);
Log.wtf("asd", album.getPath());
},
throwable -> refresh.setRefreshing(false),
() -> {
db.close();
act.nothingToShow(getCount() == 0);
refresh.setRefreshing(false);
long end = System.currentTimeMillis() - start;
Log.wtf("time", end+"");
});
}

Expand Down
1 change: 0 additions & 1 deletion scripts/crowdin.key

This file was deleted.

0 comments on commit dd86963

Please sign in to comment.