Skip to content

Commit

Permalink
Don't show 'Done' after creating new folder; AlbumActivity properly d…
Browse files Browse the repository at this point in the history
…eals with ItemActivity's delete/move/copy broadcast
  • Loading branch information
Jahhow committed Apr 11, 2020
1 parent 0a761bf commit 89e7195
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public AlbumAdapter(SelectorModeManager.Callback callback, final RecyclerView re
@Override
public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder, int fromX, int fromY, int toX, int toY) {
if (oldHolder != newHolder)
Log.w(TAG, "animateChange");
//Log.w(TAG, "animateChange");
return super.animateChange(oldHolder, newHolder, fromX, fromY, toX, toY);
}
});*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,12 @@ public boolean autoSendDoneBroadcast() {
}

public void sendDoneBroadcast() {
sendDoneBroadcast(true);
}

public void sendDoneBroadcast(boolean showToastDone) {
ContentObserver.selfChange = false;
showToast(getString(R.string.done));
if (showToastDone) showToast(getString(R.string.done));
Intent intent = getDoneIntent();
sendLocalBroadcast(intent);
}
Expand Down Expand Up @@ -222,12 +226,7 @@ public void onProgress(final int progress, final int totalNumber) {
}

public void showToast(final String message) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getBaseContext(), message, Toast.LENGTH_SHORT).show();
}
});
runOnUiThread(() -> Toast.makeText(getBaseContext(), message, Toast.LENGTH_SHORT).show());
}

public void runOnUiThread(Runnable r) {
Expand Down Expand Up @@ -417,7 +416,7 @@ public static void scanPathsWithNotification(final Context context, final String

@SuppressLint("ShowToast")
private static void scanPaths(final Context context, final String[] paths, final MediaScannerCallback callback, final boolean withNotification) {
//Log.i("FileOperation", "scanPaths(), paths: " + Arrays.toString(paths));
//Log.i("FileOperation", "scanPaths(), paths: " + Arrays.toString(paths));
if (paths == null) {
if (callback != null) {
callback.onAllPathsScanned();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public int getType() {
return FileOperation.NEW_DIR;
}

@Override
public void sendDoneBroadcast() {
sendDoneBroadcast(false);
}

private static boolean createNewFolder(String newFolderPath) {
File dir = new File(newFolderPath);
return !dir.exists() && dir.mkdirs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import us.koller.cameraroll.data.Settings;
import us.koller.cameraroll.data.provider.Provider;
import us.koller.cameraroll.themes.Theme;
import us.koller.cameraroll.util.ScrollIndicatorAdaptor;
import us.koller.cameraroll.util.SortUtil;

public class VirtualAlbum extends Album {
Expand Down Expand Up @@ -265,20 +266,7 @@ public void onVirtualAlbumSelected(VirtualAlbum virtualAlbum) {

final View scrollIndicatorTop = dialogLayout.findViewById(R.id.scroll_indicator_top);
final View scrollIndicatorBottom = dialogLayout.findViewById(R.id.scroll_indicator_bottom);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
scrollIndicatorTop.setVisibility(
recyclerView.canScrollVertically(-1) ?
View.VISIBLE : View.INVISIBLE);

scrollIndicatorBottom.setVisibility(
recyclerView.canScrollVertically(1) ?
View.VISIBLE : View.INVISIBLE);
}
});

new ScrollIndicatorAdaptor(recyclerView, scrollIndicatorTop, scrollIndicatorBottom);
return dialog;
}

Expand Down
36 changes: 19 additions & 17 deletions app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ public void deleteSelectedItems() {
public void onClick(DialogInterface dialogInterface, int i) {
deleteAlbumItemsSnackbar(selected_items);
}
}).create().show();
}).show();
}

public void fabClicked() {
Expand Down Expand Up @@ -1179,24 +1179,26 @@ public void onAlbumLoaded(Album album) {
}

private void removeAlbumItem(String path) {
//Log.d("AlbumActivity", "removeAlbumItem() called with: path = [" + path + "]");
int index = -1;
ArrayList<AlbumItem> items = album.getAlbumItems();
for (int i = 0; i < items.size(); i++) {
AlbumItem albumItem = items.get(i);
if (albumItem.getPath().equals(path)) {
index = i;
break;
//Log.d(TAG, "removeAlbumItem(" + path + ")");
ArrayList<AlbumItem> albumItems = album.getAlbumItems();
int size = albumItems.size();
for (int i = 0; i < size; ++i) {
String curPath = albumItems.get(i).getPath();
if (curPath.equals(path)) {
albumItems.remove(i);
if (size == 1)
supportFinishAfterTransition();
else
recyclerViewAdapter.notifyItemRemoved(i);
return;
}
}
if (items.size() == 0) {
supportFinishAfterTransition();
return;
}

if (index > -1) {
items.remove(index);
recyclerViewAdapter.notifyItemRemoved(index);
}
//todo: property 'album' is shared with ItemActivity. This can cause problems.
//Log.w(TAG, "todo: property 'album' is shared with ItemActivity. This can cause problems.");
if (size == 0)
supportFinishAfterTransition();
else
recyclerViewAdapter.notifyDataSetChanged();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@
import us.koller.cameraroll.data.provider.MediaProvider;
import us.koller.cameraroll.ui.widget.GridMarginDecoration;
import us.koller.cameraroll.util.MediaType;
import us.koller.cameraroll.util.ScrollIndicatorAdaptor;
import us.koller.cameraroll.util.Util;

public class FileOperationDialogActivity extends ThemeableActivity {
protected static final String TAG = FileOperationDialogActivity.class.getSimpleName();

public static String ACTION_COPY = "ACTION_COPY";
public static String ACTION_MOVE = "ACTION_MOVE";
Expand Down Expand Up @@ -96,14 +98,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
showFolderSelectorDialog(files);
}

private interface NewFolderCallback {
void newFolderCreated(String path);

void failed();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);

if (creatingNewFolder) {
Expand Down Expand Up @@ -133,33 +129,18 @@ protected void onDestroy() {

public void showFolderSelectorDialog(final File_POJO[] files) {
View v = LayoutInflater.from(this)
.inflate(R.layout.file_operation_dialog,
(ViewGroup) findViewById(R.id.root_view),
false);
.inflate(R.layout.file_operation_dialog, findViewById(R.id.root_view), false);

final RecyclerViewAdapter recyclerViewAdapter = new RecyclerViewAdapter();

RecyclerView recyclerView = v.findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
recyclerView.addItemDecoration(new GridMarginDecoration((int) getResources().getDimension(R.dimen.album_grid_spacing)));

final RecyclerViewAdapter recyclerViewAdapter = new RecyclerViewAdapter();
recyclerView.setAdapter(recyclerViewAdapter);

final View scrollIndicatorTop = v.findViewById(R.id.scroll_indicator_top);
final View scrollIndicatorBottom = v.findViewById(R.id.scroll_indicator_bottom);

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
scrollIndicatorTop.setVisibility(
recyclerView.canScrollVertically(-1) ?
View.VISIBLE : View.INVISIBLE);

scrollIndicatorBottom.setVisibility(
recyclerView.canScrollVertically(1) ?
View.VISIBLE : View.INVISIBLE);
}
});
new ScrollIndicatorAdaptor(recyclerView, scrollIndicatorTop, scrollIndicatorBottom);

int stringRes;
boolean oneItem = files.length == 1;
Expand Down Expand Up @@ -216,23 +197,8 @@ public void onDismiss(DialogInterface dialogInterface) {
}

public void createNewFolder(final File_POJO[] files) {
createNewFolderDialog(new NewFolderCallback() {
@Override
public void newFolderCreated(String path) {
executeAction(files, path);
}

@Override
public void failed() {
setResult(RESULT_CANCELED, null);
finish();
}
});
}

public void createNewFolderDialog(final NewFolderCallback callback) {
View dialogLayout = LayoutInflater.from(this).inflate(R.layout.input_dialog_layout,
(ViewGroup) findViewById(R.id.root_view), false);
View dialogLayout = LayoutInflater.from(this)
.inflate(R.layout.input_dialog_layout, findViewById(R.id.root_view), false);

final EditText editText = dialogLayout.findViewById(R.id.edit_text);

Expand All @@ -255,12 +221,9 @@ public void onReceive(Context context, Intent intent) {
unregisterLocalBroadcastReceiver(this);
switch (intent.getAction()) {
case FileOperation.RESULT_DONE:
creatingNewFolder = false;
callback.newFolderCreated(newFolder.getPath());
break;
case FileOperation.FAILED:
creatingNewFolder = false;
callback.failed();
executeAction(files, newFolder.getPath());
break;
default:
break;
Expand Down Expand Up @@ -295,6 +258,7 @@ public void onDismiss(DialogInterface dialogInterface) {
}

public void executeAction(File_POJO[] files, String target) {
//Log.i(TAG, "executeAction " + action);
int action = this.action.equals(ACTION_COPY) ? FileOperation.COPY : FileOperation.MOVE;
final Intent workIntent = FileOperation.getDefaultIntent(this, action, files);
workIntent.putExtra(FileOperation.TARGET, new File_POJO(target, false));
Expand All @@ -304,12 +268,8 @@ public void executeAction(File_POJO[] files, String target) {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case MainActivity.REMOVABLE_STORAGE_PERMISSION_REQUEST_CODE:
onDialogDismiss();
break;
default:
break;
if (requestCode == MainActivity.REMOVABLE_STORAGE_PERMISSION_REQUEST_CODE) {
onDialogDismiss();
}
}

Expand All @@ -336,7 +296,7 @@ private static class RecyclerViewAdapter extends RecyclerView.Adapter {

static class ViewHolder extends RecyclerView.ViewHolder {

public ViewHolder(View itemView) {
ViewHolder(View itemView) {
super(itemView);
}

Expand All @@ -355,30 +315,19 @@ private void setSelected(boolean selected) {
colorDrawable2 = new ColorDrawable(tintColor);
colorDrawable1.setAlpha(138);
colorDrawable2.setAlpha(138);
card.post(new Runnable() {
@Override
public void run() {
card.getOverlay().clear();
if (selectorOverlay != null) {
int width = card.getWidth(), height = card.getHeight();
int start = (width - height) / 2;
//noinspection SuspiciousNameCombination
selectorOverlay.setBounds(start, 0, start + height, height);
colorDrawable1.setBounds(0, 0, start, height);
colorDrawable2.setBounds(start + height, 0, width, height);
card.getOverlay().add(selectorOverlay);
card.getOverlay().add(colorDrawable1);
card.getOverlay().add(colorDrawable2);
}
}
card.post(() -> {
card.getOverlay().clear();
int width = card.getWidth(), height = card.getHeight();
int start = (width - height) / 2;
selectorOverlay.setBounds(start, 0, start + height, height);
colorDrawable1.setBounds(0, 0, start, height);
colorDrawable2.setBounds(start + height, 0, width, height);
card.getOverlay().add(selectorOverlay);
card.getOverlay().add(colorDrawable1);
card.getOverlay().add(colorDrawable2);
});
} else {
card.post(new Runnable() {
@Override
public void run() {
card.getOverlay().clear();
}
});
card.post(() -> card.getOverlay().clear());
}
}
}
Expand Down
Loading

1 comment on commit 89e7195

@Jahhow
Copy link
Owner Author

@Jahhow Jahhow commented on 89e7195 Apr 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.