Commit ec12d74b authored by Donald's avatar Donald

clean select album bottom sheet

parent 952e01d6
......@@ -41,7 +41,7 @@ public class LookForMediaJob extends JobService {
public void run() {
try {
HandlingAlbums instance = HandlingAlbums.getInstance(getApplicationContext());
ArrayList<String> whiteList = instance.getWhiteList();
ArrayList<String> whiteList = instance.getPaths();
for (String s : whiteList) {
scanFolder(s);
Log.wtf(TAG, s);
......
......@@ -39,14 +39,18 @@ import com.mikepenz.iconics.view.IconicsImageView;
import org.horaapps.leafpic.activities.base.ThemedActivity;
import org.horaapps.leafpic.model.Album;
import org.horaapps.leafpic.model.base.FoldersFileFilter;
import org.horaapps.leafpic.model.base.ImageFileFilter;
import org.horaapps.leafpic.util.AlertDialogsHelper;
import org.horaapps.leafpic.util.ColorPalette;
import org.horaapps.leafpic.util.ContentHelper;
import org.horaapps.leafpic.util.StringUtils;
import org.horaapps.leafpic.util.ThemeHelper;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
public class SelectAlbumBuilder extends BottomSheetDialogFragment {
......@@ -144,6 +148,7 @@ public class SelectAlbumBuilder extends BottomSheetDialogFragment {
displayContentFolder(Environment.getExternalStorageDirectory());
break;
default:
// TODO: 12/11/16 do
// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
// DocumentFile documentFile = ContentHelper.getDocumentFile(getContext(), new File(ContentHelper.getExtSdCardPaths(getContext())[pos - 1]), true, false);
// if(documentFile != null){
......@@ -323,21 +328,33 @@ public class SelectAlbumBuilder extends BottomSheetDialogFragment {
@Override
public void onBindViewHolder(final BottomSheetAlbumsAdapter.ViewHolder holder, final int position) {
File f = folders.get(position);
String[] list = f.list();
int count = list == null ? 0 : list.length;
String[] list = f.list(new ImageFileFilter(true));
int countMedia = list != null ? list.length : 0;
list = f.list(new FilenameFilter() {
@Override
public boolean accept(File file, String s) {
return new File(file, s).isDirectory();
}
});
int countFolder = list != null ? list.length : 0;
holder.folderName.setText(f.getName());
holder.folderName.setTag(f.getPath());
/** SET UP THEME**/
holder.folderName.setTextColor(theme.getTextColor());
String hexAccentColor = String.format("#%06X", (0xFFFFFF & theme.getAccentColor()));
holder.folderCount.setText(StringUtils.html("<b><font color='" + hexAccentColor + "'>" + count + "</font></b>" + "<font " + "color='" + theme.getSubTextColor() + "'> Media</font>"));
String hexAccentColor =ColorPalette.getHexColor(theme.getAccentColor());
String b = String.format(Locale.ENGLISH, "<b><font color='%s'>%d</font></b><font color='%d'> %s</font>", hexAccentColor, countMedia, theme.getSubTextColor(), getString(R.string.media)) +
" " +
String.format(Locale.ENGLISH, "<b><font color='%s'>%d</font></b><font color='%d'> %s</font>", hexAccentColor, countFolder, theme.getSubTextColor(), getString(countFolder != 1 ? R.string.folders : R.string.folder));
holder.folderCount.setText(StringUtils.html(b));
holder.imgFolder.setColor(theme.getIconColor());
holder.imgFolder.setIcon(theme.getIcon(CommunityMaterial.Icon.cmd_folder));
if(canGoBack() && position == 0) { // go to parent folder
holder.folderName.setText("..");
holder.folderCount.setText(StringUtils.html("<font color='" + theme.getSubTextColor() + "'>Go to parent</font>"));
holder.folderCount.setText(StringUtils.html("<font color='" + theme.getSubTextColor() + "'>"+getString(R.string.go_to_parent)+"</font>"));
holder.imgFolder.setIcon(theme.getIcon(CommunityMaterial.Icon.cmd_arrow_up));
}
}
......
......@@ -173,8 +173,6 @@ public class SecurityActivity extends ThemedActivity {
toolbar.setBackgroundColor(getPrimaryColor());
setSwitchColor(getAccentColor(), swActiveSecurity, swApplySecurityHidden, swApplySecurityDelete);
setSwitchColor(getAccentColor(), swApplySecurityHidden);
setSwitchColor(getAccentColor(), swApplySecurityDelete);
toggleEnabledChild(swActiveSecurity.isChecked());
setStatusBarColor();
......
package org.horaapps.leafpic.activities;
import android.content.res.ColorStateList;
import android.database.Cursor;
import android.graphics.Color;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.DefaultItemAnimator;
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;
......@@ -18,12 +18,13 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
import com.mikepenz.iconics.IconicsDrawable;
import com.mikepenz.iconics.view.IconicsImageView;
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.util.StringUtils;
......@@ -37,15 +38,10 @@ import java.util.ArrayList;
*/
public class WhiteListActivity extends SharedMediaActivity {
private RecyclerView mRecyclerView;
private Toolbar toolbar;
private int REQUEST_CODE_SD_CARD_PERMISSIONS = 42;
private FloatingActionButton fabWHDone;
ArrayList<Item> folders = new ArrayList<>();
ArrayList<String> alreadyTracked;
RecyclerView mRecyclerView;
Toolbar toolbar;
private ArrayList<Item> folders = new ArrayList<>();
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -53,9 +49,8 @@ public class WhiteListActivity extends SharedMediaActivity {
setContentView(R.layout.activity_white_list);
toolbar = (Toolbar) findViewById(org.horaapps.leafpic.R.id.toolbar);
mRecyclerView = (RecyclerView) findViewById(org.horaapps.leafpic.R.id.excluded_albums);
fabWHDone = (FloatingActionButton) findViewById(R.id.fab_whitelist_done);
initUi();
alreadyTracked = getAlbums().getTrackedPaths();
folders = getAlbums().getItems();
lookForFoldersInMediaStore();
}
......@@ -86,18 +81,24 @@ public class WhiteListActivity extends SharedMediaActivity {
int mediaColumn = cur.getColumnIndex(MediaStore.Images.Media.DATA);
while (cur.moveToNext()) {
Item item = new Item(cur.getLong(idColumn),
StringUtils.getBucketPathByImagePath(cur.getString(mediaColumn)),
cur.getString(nameColumn));
int indexOf = alreadyTracked.indexOf(item.path);
if (indexOf != -1) {
item.included = true;
alreadyTracked.remove(indexOf);
if (shouldAdd(cur.getLong(idColumn))) {
folders.add(new Item(cur.getLong(idColumn),
StringUtils.getBucketPathByImagePath(cur.getString(mediaColumn)),
cur.getString(nameColumn)));
}
folders.add(item);
}
cur.close();
}
}
private boolean shouldAdd(long id) {
for (Item item : folders)
if (item.equals(id))
return false;
return true;
}
@TestOnly
......@@ -122,22 +123,39 @@ public class WhiteListActivity extends SharedMediaActivity {
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) {
String[] list = dir.list(new ImageFileFilter(true));
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());
}
});
} else {
Toast.makeText(this, "No media in that folder", Toast.LENGTH_SHORT).show();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
/*
case R.id.action_done:
tracker.handleItems(folders);
finish();
case R.id.action_add:
SelectAlbumBuilder.with(getSupportFragmentManager())
.title(getString(R.string.chose_folders))
.exploreMode(true, true)
.onFolderSelected(new SelectAlbumBuilder.OnFolderSelected() {
@Override
public void folderSelected(String path) {
addFolder(new File(path));
}
}).show();
return true;
*/
/* case R.id.action_show_music:
Toast.makeText(this, "Fuck!", Toast.LENGTH_SHORT).show();
return true;*/
}
return super.onOptionsItemSelected(item);
}
......@@ -159,30 +177,19 @@ public class WhiteListActivity extends SharedMediaActivity {
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 1));
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
fabWHDone.setImageDrawable(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_done).color(Color.WHITE));
fabWHDone.setVisibility(View.VISIBLE);
fabWHDone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getAlbums().handleItems(folders);
finish();
}
});
}
@Override
public void updateUiElements(){
toolbar.setBackgroundColor(getPrimaryColor());
mRecyclerView.setBackgroundColor(getBackgroundColor());
fabWHDone.setBackgroundTintList(ColorStateList.valueOf(getAccentColor()));
setStatusBarColor();
setNavBarColor();
setRecentApp(getString(R.string.chose_folders));
findViewById(org.horaapps.leafpic.R.id.rl_ea).setBackgroundColor(getBackgroundColor());
}
public class Item {
public static class Item {
String path;
String name;
long id;
......@@ -206,10 +213,24 @@ public class WhiteListActivity extends SharedMediaActivity {
this.id = id;
}
public Item(long id, String path, boolean included) {
this.path = path;
this.name = StringUtils.getName(path);
this.id = id;
this.included = included;
}
boolean toggleInclude() {
included = !included;
return included;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Long)
return this.id == (long) obj;
return super.equals(obj);
}
}
private class ItemsAdapter extends RecyclerView.Adapter<ItemsAdapter.ViewHolder> {
......@@ -217,10 +238,11 @@ public class WhiteListActivity extends SharedMediaActivity {
private View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = (int) v.findViewById(R.id.folder_path).getTag();
Item item = folders.get((int) v.findViewById(R.id.folder_path).getTag());
SwitchCompat s = (SwitchCompat) v.findViewById(R.id.tracked_status);
s.setChecked(folders.get(pos).toggleInclude());
s.setChecked(item.toggleInclude());
setSwitchColor(getAccentColor(), s);
getAlbums().handleTrackItem(item);
}
};
......
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_select_folder"
android:orientation="vertical"
android:layout_width="match_parent"
......@@ -40,18 +38,4 @@
/>
</RelativeLayout>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_whitelist_done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_layout_margin"
app:elevation="@dimen/fab_elevation"
app:pressedTranslationZ="@dimen/fab_pressed_translationZ"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_gravity="bottom|end"
android:theme="@style/ThemeOverlay.AppCompat.Light"
app:layout_behavior="org.horaapps.leafpic.views.FabScrollBehaviour" />
</android.support.design.widget.CoordinatorLayout>
\ No newline at end of file
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_done"
android:title="@string/done"
app:showAsAction="ifRoom"
/>
<item
android:id="@+id/action_add"
android:title="@string/add"
......
......@@ -118,6 +118,8 @@
<!--SETTINGS PREFERENCES-->
<string name="general_setting">General Setting</string>
<string name="folder">Folder</string>
<string name="folders">Folders</string>
<string name="go_to_parent">Go to parent</string>
<string name="color_palette">Color Palette</string>
<string name="app_intro_skip">Introduction Skipped!</string>
......
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