Skip to content

Commit

Permalink
#169: Refresh gallery-view after copy/move/delete
Browse files Browse the repository at this point in the history
  • Loading branch information
k3b committed Apr 2, 2021
1 parent 244316d commit 626da66
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import com.nostra13.universalimageloader.core.assist.LoadedFrom;
import com.nostra13.universalimageloader.core.display.BitmapDisplayer;
import com.nostra13.universalimageloader.core.imageaware.ImageAware;

import java.util.Date;

Expand Down Expand Up @@ -298,92 +300,24 @@ public int getPositionFromPath(IFile file) {
return result;
}

@NonNull
protected View createViewWithContent(
int position, ViewGroup container, IFile imageFile, Uri imageUri, String debugContext, int size) {
final Context context = container.getContext();

final boolean useLayout = true;

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

PhotoViewEx photoView;
View root;
TextView contextTextView = null;

if (useLayout) {
root = inflater.inflate(R.layout.pager_item_image, container, false);

photoView = (PhotoViewEx) root.findViewById(R.id.image);
mImageButtonController.create((ImageButton) root.findViewById(R.id.cmd_any));
contextTextView = (TextView) root.findViewById(R.id.text);

} else {
photoView = new PhotoViewEx(context);
root = photoView;
}

if (contextTextView != null) {
String contextText = DBUtils.getString(getCursorAt(position), CONTEXT_COLUMN_FIELD, null);

if ((contextText != null) && (contextText.length() > 0)) {
contextTextView.setVisibility(View.VISIBLE);
contextTextView.setText(ImageContextController.sqlFormat(contextText));
} else {
contextTextView.setVisibility(View.INVISIBLE);
}
}

photoView.setMaximumScale(20);
photoView.setMediumScale(5);

String loadType;

if (imageFile != null) {
// if image is big use memoryefficient, fast, low-quality thumbnail (old code)
if (size > Global.imageDetailThumbnailIfBiggerThan) {
loadType = "image too big using thumb ";
setImageFromThumbnail(photoView, imageFile);
} else {
try {
// #53 Optimisation: no need for thumbnail - saves cache memory but may throw OutOfMemoryError
loadType = "image small enough ";
Bitmap bitmap = HugeImageLoader.loadImage(imageFile, MAX_IMAGE_DIMENSION, MAX_IMAGE_DIMENSION);
// rotation is done by photoView
photoView.setImageBitmap(bitmap);
photoView.setImageReloadFile((IFile) null);
photoView.setDebugPrefix(imageFile.getName());
} catch (OutOfMemoryError err) {
loadType = "small image out of memory using thumb ";
setImageFromThumbnail(photoView, imageFile);
}
}
final int rotationInDegrees = PhotoPropertiesBulkUpdateService.getRotationFromExifOrientation(imageFile, null);
if (Global.debugEnabledViewItem) {
Log.i(Global.LOG_CONTEXT, mDebugPrefix + debugContext + position + ", rotation=" +
rotationInDegrees + ", "
+ loadType + ") => " + imageFile + " => " + photoView);
}
photoView.setRotationTo(rotationInDegrees);
} else if (imageUri != null) {
if (Global.debugEnabledViewItem) {
Log.i(Global.LOG_CONTEXT, mDebugPrefix + debugContext + ") => " + imageUri + " => " + photoView);
}
photoView.setImageURI(imageUri);
} else if (Global.debugEnabledViewItem) {
Log.w(Global.LOG_CONTEXT, mDebugPrefix + debugContext + ") no ifile and no imageUri " + photoView);
}

container.addView(root, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
return root;
}

private void setImageFromThumbnail(PhotoViewEx photoView, IFile imageFile) {
/** k3b 20150913 #10: Faster initial loading: initially the view is loaded with low res image.
* on first zoom it is reloaded with this uri */
photoView.setImageReloadFile(imageFile);

ImageLoader.getInstance().displayImage(imageFile.getAsUriString(), photoView, mDisplayImageOptions);
String uri = imageFile.getAsUriString();
ImageLoader.getInstance().displayImage(uri, photoView, mDisplayImageOptions);
}

/**
* debug only to allow setting a breakpoint. Copy of original code
*/
private static class SimpleBitmapDisplayer implements BitmapDisplayer {
@Override
public void display(Bitmap bitmap, ImageAware imageAware, LoadedFrom loadedFrom) {
imageAware.setImageBitmap(bitmap);
}

}

/**
Expand Down Expand Up @@ -447,7 +381,7 @@ public boolean isInSingleImageMode() {

private class ImageButtonControllerImpl {
private MenuItem mMenuItem = null;
private View.OnClickListener mClickListener;
private final View.OnClickListener mClickListener;
private final View.OnLongClickListener mLongClickListener;

public ImageButtonControllerImpl() {
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/de/k3b/android/io/AndroidFileCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ public void onMoveOrCopyDirectoryPick(boolean move, SelectedFiles selectedFiles,
// public int moveOrCopyFilesTo(boolean move, SelectedFiles selectedFiles, File destDirFolder, IProgessListener progessListener) {

moveOrCopyFilesTo(move, selectedFiles, destDirFolder, null);
PhotoChangeNotifyer.onNotifyPhotoChanged();
}
}

Expand Down Expand Up @@ -471,13 +472,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View result = super.onCreateView(inflater, container, savedInstanceState);

chkFullScan = (CheckBox) result.findViewById(R.id.chkFullScan);
chkFullScan = result.findViewById(R.id.chkFullScan);
chkFullScan.setVisibility(View.VISIBLE);

chkRescanNeverScannedByAPM = (CheckBox) result.findViewById(R.id.chkRescanNeverScannedByAPM);
chkRescanNeverScannedByAPM = result.findViewById(R.id.chkRescanNeverScannedByAPM);
chkRescanNeverScannedByAPM.setVisibility(View.VISIBLE);

chkScanForDeleted = (CheckBox) result.findViewById(R.id.chkScanForDeleted);
chkScanForDeleted = result.findViewById(R.id.chkScanForDeleted);
chkScanForDeleted.setVisibility(View.VISIBLE);

chkFullScan.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/de/k3b/android/io/DocumentFileCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public DocumentFile findFile(DocumentFile parentDoc, File parentFile, String dis
if (!parentFile.equals(currentFileCache.lastParentFile)) {
currentFileCache.lastParentFile = parentFile;
currentFileCache.lastChildDocFiles.clear();
for (DocumentFile childDoc : parentDoc.listFiles()) {
DocumentFile[] childDocuments = parentDoc.listFiles();
for (DocumentFile childDoc : childDocuments) {
if (childDoc.isFile()) {
String childDocName = childDoc.getName().toLowerCase();
if (PhotoPropertiesUtil.isImage(childDocName, PhotoPropertiesUtil.IMG_TYPE_ALL | PhotoPropertiesUtil.IMG_TYPE_XMP)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public static void setPhotoChangedListener(PhotoChangedListener photoChangedList
PhotoChangeNotifyer.photoChangedListener = photoChangedListener;
}

public static void onNotifyPhotoChanged() {
if (photoChangedListener != null) photoChangedListener.onNotifyPhotoChanged();
}

public static void notifyPhotoChanged(Context context, PhotoChangedListener adapter) {
if (adapter != null) adapter.onNotifyPhotoChanged();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public long length() {

@Override
public String toString() {
return String.format("%s: %i-%s", this.getClass().getSimpleName(), strategyID, file.getAbsoluteFile());
return String.format("%s: %d-%s", this.getClass().getSimpleName(), strategyID, file.getAbsoluteFile());
}

@Override
Expand Down

0 comments on commit 626da66

Please sign in to comment.