Commit febaa740 authored by Donald's avatar Donald

new ui for delete media

parent 6244c191
......@@ -121,6 +121,8 @@ dependencies {
implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.8.0'
implementation 'jp.wasabeef:recyclerview-animators:2.2.7'
implementation 'com.github.HoraApps:Liz:-SNAPSHOT'
implementation 'com.github.lzyzsd:circleprogress:1.2.1'
// debug Only
//debugCompile project(':inappstoragereader')
......
......@@ -309,7 +309,7 @@ public class MainActivity extends SharedMediaActivity implements
fab.setVisibility(Hawk.get(getString(R.string.preference_show_fab), false) ? View.VISIBLE : View.GONE);
mainLayout.setBackgroundColor(getBackgroundColor());
setScrollViewColor(navigationDrawerView);
// setScrollViewColor(navigationDrawerView);
setAllScrollbarsColor();
navigationDrawerView.setTheme(getPrimaryColor(), getBackgroundColor(), getTextColor(), getIconColor());
......
package org.horaapps.leafpic.delete;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetDialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.github.lzyzsd.circleprogress.DonutProgress;
import org.horaapps.leafpic.R;
import org.horaapps.leafpic.data.Media;
import org.horaapps.leafpic.data.MediaHelper;
import org.horaapps.leafpic.util.StringUtils;
import org.horaapps.leafpic.util.file.DeleteException;
import org.horaapps.liz.ThemeHelper;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Locale;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
/**
* Created by dnld on 11/03/18.
*/
public class DeleteMediaBottomSheet extends BottomSheetDialogFragment {
public interface DeleteMediaListener {
void onCompleted();
void onDeleted(Media media);
}
public static final String TAG = "delete_bootomsheet";
public static final String EXTRA_MEDIA = "media";
@BindView(R.id.title)
TextView title;
@BindView(R.id.delete_progress_bar)
DonutProgress progress;
@BindView(R.id.txt_errors)
TextView txtErrors;
private ArrayList<Media> media;
DeleteMediaListener listener;
public void setListener(DeleteMediaListener listener) {
this.listener = listener;
}
public static DeleteMediaBottomSheet make(ArrayList<Media> media, DeleteMediaListener listener) {
DeleteMediaBottomSheet deleteMediaBottomSheet = new DeleteMediaBottomSheet();
Bundle bundle = new Bundle();
bundle.putParcelableArrayList(EXTRA_MEDIA, media);
deleteMediaBottomSheet.setArguments(bundle);
deleteMediaBottomSheet.setCancelable(false);
deleteMediaBottomSheet.setListener(listener);
return deleteMediaBottomSheet;
}
private void setProgress(int p) {
progress.setProgress(p);
progress.setText(String.format(Locale.ENGLISH, "%d/%d", p, progress.getMax()));
}
@Override
public void setupDialog(Dialog dialog, int style) {
dialog.setCancelable(false);
ThemeHelper th = ThemeHelper.getInstanceLoaded(getContext());
View view = LayoutInflater.from(getContext()).inflate(R.layout.bottom_sheet_delete_media, null, false);
ButterKnife.bind(this, view);
view.setBackgroundColor(th.getBackgroundColor());
title.setBackgroundColor(th.getPrimaryColor());
txtErrors.setTextColor(th.getTextColor());
progress.setFinishedStrokeColor(th.getAccentColor());
progress.setTextColor(th.getTextColor());
progress.setMax(media.size());
setProgress(0);
dialog.setContentView(view);
}
private void showErrors(HashSet<String> errors) {
StringBuilder b = new StringBuilder();
b.append("<b>").append("Errors:").append("</b>").append("<br/>");
for (String error : errors)
b.append("<i>").append(" - ").append(error).append("</i>").append("<br/>");
txtErrors.setText(StringUtils.html(b.toString()));
txtErrors.setVisibility(View.VISIBLE);
progress.setVisibility(View.GONE);
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
media = getArguments().getParcelableArrayList(EXTRA_MEDIA);
HashSet<String> errors = new HashSet<>(0);
Disposable end = MediaHelper.deleteMedia(getContext(), media)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
m -> {
listener.onDeleted(m);
setProgress((int) (progress.getProgress() + 1));
},
throwable -> {
setProgress((int) (progress.getProgress() + 1));
if (throwable instanceof DeleteException) {
errors.add(((DeleteException) throwable).getMedia().getPath());
} else {
errors.add(throwable.getLocalizedMessage());
}
},
() -> {
setCancelable(true);
listener.onCompleted();
if (errors.size() == 0)
dismiss();
else {
showErrors(errors);
}
}
);
}
}
......@@ -39,7 +39,6 @@ import com.orhanobut.hawk.Hawk;
import org.horaapps.leafpic.R;
import org.horaapps.leafpic.activities.PaletteActivity;
import org.horaapps.leafpic.adapters.MediaAdapter;
import org.horaapps.leafpic.adapters.ProgressAdapter;
import org.horaapps.leafpic.data.Album;
import org.horaapps.leafpic.data.HandlingAlbums;
import org.horaapps.leafpic.data.Media;
......@@ -49,6 +48,7 @@ import org.horaapps.leafpic.data.filter.MediaFilter;
import org.horaapps.leafpic.data.provider.CPHelper;
import org.horaapps.leafpic.data.sort.SortingMode;
import org.horaapps.leafpic.data.sort.SortingOrder;
import org.horaapps.leafpic.delete.DeleteMediaBottomSheet;
import org.horaapps.leafpic.util.Affix;
import org.horaapps.leafpic.util.AlertDialogsHelper;
import org.horaapps.leafpic.util.AnimationUtils;
......@@ -56,7 +56,6 @@ import org.horaapps.leafpic.util.LegacyCompatFileProvider;
import org.horaapps.leafpic.util.Measure;
import org.horaapps.leafpic.util.MimeTypeUtils;
import org.horaapps.leafpic.util.StringUtils;
import org.horaapps.leafpic.util.file.DeleteException;
import org.horaapps.leafpic.util.preferences.Prefs;
import org.horaapps.leafpic.views.GridSpacingItemDecoration;
import org.horaapps.liz.ThemeHelper;
......@@ -434,7 +433,23 @@ public class RvMediaFragment extends BaseFragment {
case R.id.delete:
ProgressAdapter errorsAdapter = new ProgressAdapter(getContext());
DeleteMediaBottomSheet deleteMediaBottomSheet =
DeleteMediaBottomSheet.make(adapter.getSelected(), new DeleteMediaBottomSheet.DeleteMediaListener() {
@Override
public void onCompleted() {
adapter.clearSelected();
}
@Override
public void onDeleted(Media media) {
adapter.remove(media);
}
});
deleteMediaBottomSheet.show(getFragmentManager(), DeleteMediaBottomSheet.TAG);
/*ProgressAdapter errorsAdapter = new ProgressAdapter(getContext());
ArrayList<Media> selected = adapter.getSelected();
AlertDialog alertDialog = AlertDialogsHelper.getProgressDialogWithErrors(((ThemedActivity) getActivity()), R.string.deleting_images, errorsAdapter, selected.size());
......@@ -460,7 +475,7 @@ public class RvMediaFragment extends BaseFragment {
if (errorsAdapter.getItemCount() == 0)
alertDialog.dismiss();
adapter.clearSelected();
});
});*/
return true;
//region Affix
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
app:liz_background_style="normal"
android:layout_width="match_parent"
android:id="@+id/delete_background"
android:layout_height="match_parent">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:textColor="@color/md_dark_primary_text"
android:layout_height="wrap_content"
android:background="@color/md_red_500"
android:padding="@dimen/big_spacing"
android:textSize="@dimen/sub_big_text"
android:textStyle="bold"
android:text="Cleaning up memories" />
<com.github.lzyzsd.circleprogress.DonutProgress
android:layout_marginTop="@dimen/medium_spacing"
android:layout_marginBottom="@dimen/medium_spacing"
android:id="@+id/delete_progress_bar"
android:layout_gravity="center_horizontal"
android:layout_width="120dp"
android:layout_height="120dp"
app:donut_progress="30" />
<ProgressBar
android:layout_width="match_parent"
android:visibility="gone"
style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
android:layout_height="10dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:padding="@dimen/small_spacing"
android:id="@+id/txt_errors" />
</LinearLayout>
\ No newline at end of file
......@@ -6,9 +6,10 @@ buildscript {
maven {
url "https://maven.google.com"
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0-alpha08'
classpath 'com.android.tools.build:gradle:3.1.0-beta3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
......
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