Commit 5035591e authored by Donald's avatar Donald

clean and white list improvements

parent 70393e1f
......@@ -268,7 +268,7 @@ public class SelectAlbumBuilder extends BottomSheetDialogFragment {
exploreModePanel.setVisibility(View.VISIBLE);
} else {
currentFolderPath.setText(R.string.local_folder);
for (Album album : ((MyApplication) getActivity().getApplicationContext()).getAlbums().dispAlbums) {
for (Album album : ((MyApplication) getActivity().getApplicationContext()).getAlbums().albums) {
folders.add(new File(album.getPath()));
}
imgExploreMode.setIcon(theme.getIcon(CommunityMaterial.Icon.cmd_compass_outline));
......
......@@ -240,7 +240,7 @@ public class MainActivity extends SharedMediaActivity {
toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_menu));
toolbar.setTitle(getString(R.string.app_name));
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
albumsAdapter.swapDataSet(getAlbums().dispAlbums);
albumsAdapter.swapDataSet(getAlbums().albums);
if (reload) new PrepareAlbumTask().execute();
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
......@@ -310,7 +310,7 @@ public class MainActivity extends SharedMediaActivity {
rvMedia.setHasFixedSize(true);
rvMedia.setItemAnimator(new DefaultItemAnimator());
albumsAdapter = new AlbumsAdapter(getAlbums().dispAlbums, MainActivity.this);
albumsAdapter = new AlbumsAdapter(getAlbums().albums, MainActivity.this);
albumsAdapter.setOnClickListener(albumOnClickListener);
albumsAdapter.setOnLongClickListener(albumOnLongCLickListener);
rvAlbums.setAdapter(albumsAdapter);
......@@ -541,7 +541,7 @@ public class MainActivity extends SharedMediaActivity {
private void updateSelectedStuff() {
if (albumsMode) {
if (editMode) toolbar.setTitle(getAlbums().getSelectedCount() + "/" + getAlbums().dispAlbums.size());
if (editMode) toolbar.setTitle(getAlbums().getSelectedCount() + "/" + getAlbums().albums.size());
else {
toolbar.setTitle(getString(R.string.app_name));
toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_menu));
......@@ -592,7 +592,7 @@ public class MainActivity extends SharedMediaActivity {
private void checkNothing() {
TextView a = (TextView) findViewById(R.id.nothing_to_show);
a.setTextColor(getTextColor());
a.setVisibility((albumsMode && getAlbums().dispAlbums.size() == 0) || (!albumsMode && getAlbum().getMedia().size() == 0) ? View.VISIBLE : View.GONE);
a.setVisibility((albumsMode && getAlbums().albums.size() == 0) || (!albumsMode && getAlbum().getMedia().size() == 0) ? View.VISIBLE : View.GONE);
}
//region MENU
......@@ -714,7 +714,7 @@ public class MainActivity extends SharedMediaActivity {
getAlbums().getSelectedAlbum(0).togglePinAlbum(getApplicationContext());
getAlbums().sortAlbums(getApplicationContext());
getAlbums().clearSelectedAlbums();
albumsAdapter.swapDataSet(getAlbums().dispAlbums);
albumsAdapter.swapDataSet(getAlbums().albums);
invalidateOptionsMenu();
return true;
......@@ -895,7 +895,7 @@ public class MainActivity extends SharedMediaActivity {
if (albumsMode) {
getAlbums().setDefaultSortingMode(SortingMode.NAME);
getAlbums().sortAlbums(getApplicationContext());
albumsAdapter.swapDataSet(getAlbums().dispAlbums);
albumsAdapter.swapDataSet(getAlbums().albums);
} else {
getAlbum().setDefaultSortingMode(getApplicationContext(), SortingMode.NAME);
getAlbum().sortPhotos();
......@@ -908,7 +908,7 @@ public class MainActivity extends SharedMediaActivity {
if (albumsMode) {
getAlbums().setDefaultSortingMode(SortingMode.DATE);
getAlbums().sortAlbums(getApplicationContext());
albumsAdapter.swapDataSet(getAlbums().dispAlbums);
albumsAdapter.swapDataSet(getAlbums().albums);
} else {
getAlbum().setDefaultSortingMode(getApplicationContext(), SortingMode.DATE);
getAlbum().sortPhotos();
......@@ -921,7 +921,7 @@ public class MainActivity extends SharedMediaActivity {
if (albumsMode) {
getAlbums().setDefaultSortingMode(SortingMode.SIZE);
getAlbums().sortAlbums(getApplicationContext());
albumsAdapter.swapDataSet(getAlbums().dispAlbums);
albumsAdapter.swapDataSet(getAlbums().albums);
} else {
getAlbum().setDefaultSortingMode(getApplicationContext(), SortingMode.SIZE);
getAlbum().sortPhotos();
......@@ -944,7 +944,7 @@ public class MainActivity extends SharedMediaActivity {
if (albumsMode) {
getAlbums().setDefaultSortingMode(SortingMode.NUMERIC);
getAlbums().sortAlbums(getApplicationContext());
albumsAdapter.swapDataSet(getAlbums().dispAlbums);
albumsAdapter.swapDataSet(getAlbums().albums);
} else {
getAlbum().setDefaultSortingMode(getApplicationContext(), SortingMode.NUMERIC);
getAlbum().sortPhotos();
......@@ -957,7 +957,7 @@ public class MainActivity extends SharedMediaActivity {
if (albumsMode) {
getAlbums().setDefaultSortingAscending(item.isChecked() ? SortingOrder.DESCENDING : SortingOrder.ASCENDING);
getAlbums().sortAlbums(getApplicationContext());
albumsAdapter.swapDataSet(getAlbums().dispAlbums);
albumsAdapter.swapDataSet(getAlbums().albums);
} else {
getAlbum().setDefaultSortingAscending(getApplicationContext(), item.isChecked() ? SortingOrder.DESCENDING : SortingOrder.ASCENDING);
getAlbum().sortPhotos();
......@@ -1180,7 +1180,7 @@ public class MainActivity extends SharedMediaActivity {
boolean success;
if (albumsMode) {
int index = getAlbums().dispAlbums.indexOf(getAlbums().getSelectedAlbum(0));
int index = getAlbums().albums.indexOf(getAlbums().getSelectedAlbum(0));
getAlbums().getAlbum(index).updatePhotos(getApplicationContext());
success = getAlbums().getAlbum(index).renameAlbum(getApplicationContext(),
editTextNewName.getText().toString());
......@@ -1260,7 +1260,7 @@ public class MainActivity extends SharedMediaActivity {
@Override
protected void onPostExecute(Void result) {
albumsAdapter.swapDataSet(getAlbums().dispAlbums);
albumsAdapter.swapDataSet(getAlbums().albums);
checkNothing();
swipeRefreshLayout.setRefreshing(false);
getAlbums().saveBackup(getApplicationContext());
......
......@@ -167,7 +167,7 @@ public class SplashScreen extends SharedMediaActivity {
@Override
protected Boolean doInBackground(Boolean... arg0) {
getAlbums().restoreBackup(getApplicationContext());
if(getAlbums().dispAlbums.size() == 0) {
if(getAlbums().albums.size() == 0) {
getAlbums().loadAlbums(getApplicationContext(), false);
return true;
}
......
......@@ -10,7 +10,6 @@ import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SwitchCompat;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
......@@ -27,6 +26,7 @@ import org.horaapps.leafpic.R;
import org.horaapps.leafpic.SelectAlbumBuilder;
import org.horaapps.leafpic.activities.base.SharedMediaActivity;
import org.horaapps.leafpic.model.base.ImageFileFilter;
import org.horaapps.leafpic.model.providers.MediaStoreProvider;
import org.horaapps.leafpic.util.StringUtils;
import org.jetbrains.annotations.TestOnly;
......@@ -39,6 +39,7 @@ import java.util.ArrayList;
public class WhiteListActivity extends SharedMediaActivity {
private RecyclerView mRecyclerView;
private ItemsAdapter adapter;
private Toolbar toolbar;
private ArrayList<Item> folders = new ArrayList<>();
......@@ -54,7 +55,6 @@ public class WhiteListActivity extends SharedMediaActivity {
lookForFoldersInMediaStore();
}
private void lookForFoldersInMediaStore() {
String[] projection = new String[]{
MediaStore.Files.FileColumns.PARENT,
......@@ -63,10 +63,10 @@ public class WhiteListActivity extends SharedMediaActivity {
};
String selection, selectionArgs[];
selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=? or " +
MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
+ " ) GROUP BY ( " + MediaStore.Files.FileColumns.PARENT + " ";
selection = String.format("%s=? or %s=? ) GROUP BY (%s ",
MediaStore.Files.FileColumns.MEDIA_TYPE,
MediaStore.Files.FileColumns.MEDIA_TYPE,
MediaStore.Files.FileColumns.PARENT);
selectionArgs = new String[]{
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE),
......@@ -86,12 +86,9 @@ public class WhiteListActivity extends SharedMediaActivity {
StringUtils.getBucketPathByImagePath(cur.getString(mediaColumn)),
cur.getString(nameColumn)));
}
}
cur.close();
}
}
private boolean shouldAdd(long id) {
......@@ -101,18 +98,6 @@ public class WhiteListActivity extends SharedMediaActivity {
return true;
}
@TestOnly
private void fetchFolders(File dir) {
// if (!alreadyTracked.contains(dir)) {
// if (isFolderWithMedia(dir))
// folders.add(new Item(dir.getPath(), dir.getName()));
// File[] foo = dir.listFiles(new NotHiddenFoldersFilter());
// if (foo != null)
// for (File f : foo)
// if (!alreadyTracked.contains(f)) fetchFolders(f);
// }
}
@TestOnly
private boolean isFolderWithMedia(File dir) {
String[] list = dir.list(new ImageFileFilter(true));
......@@ -122,19 +107,27 @@ public class WhiteListActivity extends SharedMediaActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_track_albums, menu);
//menu.findItem(R.id.action_done).setIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_done));
menu.findItem(R.id.action_add).setIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_add_circle));
return true;
}
private void addFolder(File dir) {
private void addFolder(final File dir) {
String[] list = dir.list(new ImageFileFilter(true));
final boolean[] found = { false };
if (list != null && list.length > 0) {
MediaScannerConnection.scanFile(getApplicationContext(), list, null, new MediaScannerConnection.OnScanCompletedListener() {
@Override
public void onScanCompleted(String s, Uri uri) {
Log.wtf("asd", s+" - "+uri.toString());
// TODO: 12/15/16 test this!
if(!found[0]) {
long albumId = MediaStoreProvider.getAlbumId(getApplicationContext(), s);
if (albumId != -1) {
found[0] = true;
folders.add(0, new Item(albumId, dir.getPath(), dir.getName()));
}
}
}
});
} else {
......@@ -156,13 +149,18 @@ public class WhiteListActivity extends SharedMediaActivity {
}
}).show();
return true;
case R.id.action_select_all:
for (Item folder : folders) folder.included = true;
getAlbums().trackItems(folders);
adapter.notifyDataSetChanged();
return true;
}
return super.onOptionsItemSelected(item);
}
private void initUi() {
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_arrow_back));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
......@@ -173,10 +171,9 @@ public class WhiteListActivity extends SharedMediaActivity {
});
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setAdapter(new ItemsAdapter());
mRecyclerView.setAdapter((adapter = new ItemsAdapter()));
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 1));
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
}
@Override
......@@ -190,8 +187,8 @@ public class WhiteListActivity extends SharedMediaActivity {
}
public static class Item {
String path;
String name;
String path, name;
long id;
boolean included = false;
......
......@@ -12,7 +12,6 @@ import org.horaapps.leafpic.model.base.MediaComparators;
import org.horaapps.leafpic.model.base.SortingMode;
import org.horaapps.leafpic.model.base.SortingOrder;
import org.horaapps.leafpic.model.providers.MediaStoreProvider;
import org.horaapps.leafpic.model.providers.StorageProvider;
import org.horaapps.leafpic.util.ContentHelper;
import org.horaapps.leafpic.util.PreferenceUtil;
import org.horaapps.leafpic.util.StringUtils;
......@@ -154,14 +153,16 @@ public class Album implements Serializable {
PreferenceUtil SP = PreferenceUtil.getInstance(context);
ArrayList<Media> mediaArrayList = new ArrayList<>();
// TODO: 18/08/16
if (isFromMediaStore()) {
mediaArrayList.addAll(
MediaStoreProvider.getMedia(context, id, SP.getBoolean("set_include_video", true)));
/*if (isFromMediaStore()) {
mediaArrayList.addAll(
MediaStoreProvider.getMedia(
context, id, SP.getBoolean("set_include_video", true)));
} else {
mediaArrayList.addAll(StorageProvider.getMedia(
getPath(), SP.getBoolean("set_include_video", true)));
}
}*/
return mediaArrayList;
}
......
......@@ -56,22 +56,25 @@ public class MediaStoreProvider {
if(includeVideo) {
selection = "( "+MediaStore.Files.FileColumns.MEDIA_TYPE + "=? or "
+ MediaStore.Files.FileColumns.MEDIA_TYPE + "=? ) and " + MediaStore.Files.FileColumns.PARENT + "=?";
selection = String.format("(%s=? or %s=?) and %s=?",
MediaStore.Files.FileColumns.MEDIA_TYPE,
MediaStore.Files.FileColumns.MEDIA_TYPE,
MediaStore.Files.FileColumns.PARENT);
selectionArgs = new String[] {
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE),
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO),
String.valueOf(albumId)
};
} else {
selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=? and " + MediaStore.Files.FileColumns.PARENT + "=?";
selection = String.format("%s=? and %s=?",
MediaStore.Files.FileColumns.MEDIA_TYPE,
MediaStore.Files.FileColumns.PARENT);
selectionArgs = new String[] { String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE), String.valueOf(albumId) };
}
Cursor cur = context.getContentResolver().query(
images, projection, selection, selectionArgs,
" " + MediaStore.Images.Media.DATE_TAKEN + " DESC " + limit);
MediaStore.Images.Media.DATE_TAKEN + " DESC " + limit);
if (cur != null) {
if (cur.moveToFirst()) do list.add(new Media(cur)); while (cur.moveToNext());
......@@ -93,18 +96,17 @@ public class MediaStoreProvider {
}
public static int getCount(Context context, long albumId) {
int c = 0;
String selection = String.format("(%s=? or %s=?) and %s=?",
MediaStore.Files.FileColumns.MEDIA_TYPE,
MediaStore.Files.FileColumns.MEDIA_TYPE,
MediaStore.Files.FileColumns.PARENT),
String selection = "( "+MediaStore.Files.FileColumns.MEDIA_TYPE + "=? or "
+ MediaStore.Files.FileColumns.MEDIA_TYPE + "=? ) and " + MediaStore.Files.FileColumns.PARENT + "=?";
String[] selectionArgs = new String[] {
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE),
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO),
String.valueOf(albumId)
};
selectionArgs[] = new String[] {
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE),
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO),
String.valueOf(albumId)
};
Cursor cur = context.getContentResolver().query(MediaStore.Files.getContentUri("external"),
new String[]{ "count(*)" }, selection, selectionArgs, null);
......@@ -135,7 +137,6 @@ public class MediaStoreProvider {
return null;
}
@Deprecated
public static ArrayList<Album> getAlbums(Context context, boolean hidden) {
excludedAlbums = getExcludedFolders(context);
......@@ -147,7 +148,7 @@ public class MediaStoreProvider {
ArrayList<Album> list = new ArrayList<Album>();
String[] projection = new String[]{ MediaStore.Files.FileColumns.DATA, MediaStore.Files.FileColumns.PARENT };
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE+"="+MediaStore.Files.FileColumns.MEDIA_TYPE_NONE+" and "+
MediaStore.Files.FileColumns.DATA +" LIKE '%.nomedia'";
MediaStore.Files.FileColumns.DATA +" LIKE '%.nomedia'";
Cursor cur = context.getContentResolver().query(MediaStore.Files.getContentUri("external"), projection, selection, null, null);
if(cur != null && cur.moveToFirst()) {
do {
......@@ -187,8 +188,8 @@ public class MediaStoreProvider {
ArrayList<Album> list = new ArrayList<Album>();
String[] projection = new String[]{
MediaStore.Files.FileColumns.PARENT,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME
MediaStore.Files.FileColumns.PARENT,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME
};
String selection, selectionArgs[];
......@@ -198,12 +199,12 @@ public class MediaStoreProvider {
if (includeVideo) {
selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=? or " +
MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
+ " ) GROUP BY ( " + MediaStore.Files.FileColumns.PARENT + " ";
MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
+ " ) GROUP BY ( " + MediaStore.Files.FileColumns.PARENT + " ";
selectionArgs = new String[]{
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE),
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO),
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE),
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO),
};
} else {
selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=? ) GROUP BY ( " + MediaStore.Files.FileColumns.PARENT + " ";
......@@ -211,7 +212,7 @@ public class MediaStoreProvider {
}
Cursor cur = context.getContentResolver().query(
MediaStore.Files.getContentUri("external"), projection, selection, selectionArgs, null);
MediaStore.Files.getContentUri("external"), projection, selection, selectionArgs, null);
if (cur != null) {
if (cur.moveToFirst()) {
......@@ -237,7 +238,7 @@ public class MediaStoreProvider {
@Deprecated
private static ArrayList<String> getExcludedFolders(Context context) {
ArrayList<String> list = new ArrayList<String>();
ArrayList<String> list = new ArrayList<>();
//forced excluded folder
HashSet<File> storageRoots = ContentHelper.getStorageRoots(context);
for(File file : storageRoots) {
......@@ -253,16 +254,16 @@ public class MediaStoreProvider {
private static int getAlbumCount(Context context, long id) {
int c = 0;
String selection = "( "+MediaStore.Files.FileColumns.MEDIA_TYPE + "=? or "
+ MediaStore.Files.FileColumns.MEDIA_TYPE + "=? ) and " + MediaStore.Files.FileColumns.PARENT + "=?";
+ MediaStore.Files.FileColumns.MEDIA_TYPE + "=? ) and " + MediaStore.Files.FileColumns.PARENT + "=?";
String[] selectionArgs = new String[] {
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE),
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO),
String.valueOf(id)
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE),
String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO),
String.valueOf(id)
};
Cursor cur = context.getContentResolver().query(MediaStore.Files.getContentUri("external"),
new String[]{ MediaStore.Files.FileColumns.PARENT }, selection, selectionArgs, null);
new String[]{ MediaStore.Files.FileColumns.PARENT }, selection, selectionArgs, null);
if (cur != null) {
c = cur.getCount();
......
......@@ -37,7 +37,7 @@ import java.util.Locale;
*/
public class AlertDialogsHelper {
public static AlertDialog getInsertTextDialog(final ThemedActivity activity, EditText editText, @StringRes int title) {
public static AlertDialog getInsertTextDialog(ThemedActivity activity, EditText editText, @StringRes int title) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity, activity.getDialogStyle());
View dialogLayout = activity.getLayoutInflater().inflate(org.horaapps.leafpic.R.layout.dialog_insert_text, null);
......@@ -66,7 +66,7 @@ public class AlertDialogsHelper {
return dialogBuilder.create();
}
public static AlertDialog getTextDialog(final ThemedActivity activity, @StringRes int title, @StringRes int Message){
public static AlertDialog getTextDialog(ThemedActivity activity, @StringRes int title, @StringRes int Message){
AlertDialog.Builder builder = new AlertDialog.Builder(activity,activity.getDialogStyle());
View dialogLayout = activity.getLayoutInflater().inflate(org.horaapps.leafpic.R.layout.dialog_text, null);
......@@ -180,7 +180,6 @@ public class AlertDialogsHelper {
}
private static void showMoreDetails(View dialogLayout, ThemedActivity activity, Media media) {
MediaDetailsMap<String, String> metadata = media.getAllDetails();
loadDetails(dialogLayout ,activity , metadata);
}
......
......@@ -6,9 +6,9 @@
android:title="@string/add"
app:showAsAction="always"
/>
<!--<item
android:id="@+id/action_show_music"
android:title="Show Music folder"
<item
android:id="@+id/action_select_all"
android:title="@string/select_all"
app:showAsAction="never"
/>-->
/>
</menu>
\ No newline at end of file
......@@ -6,7 +6,7 @@ buildscript {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0-alpha2'
classpath 'com.android.tools.build:gradle:2.3.0-alpha3'
classpath "gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:0.2.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
......
#Wed Aug 10 14:40:38 CEST 2016
#Wed Dec 14 22:26:11 CET 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2-all.zip
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