Skip to content

Commit

Permalink
Merge branch '169Write-sdcard-support' of https://github.com/k3b/APho…
Browse files Browse the repository at this point in the history
…toManager into 169Write-sdcard-support
  • Loading branch information
k3b committed Aug 19, 2020
2 parents ffb8009 + ded2719 commit 708d746
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ public class GalleryCursorFragment extends Fragment implements Queryable, Direct

// multi selection support
private final SelectedItemIds mSelectedItemIds = new SelectedItemIds();
private String mOldTitle = null;

private String mOldAppTitleBeforeMultiselectionStarts = null;
private boolean mShowSelectedOnly = false;
private boolean isMultiSelectionMenuVisible = false;
private final AndroidFileCommands mFileCommands = new LocalFileCommands();
private MenuItem mShareOnlyToggle;
private MenuItem mMenuRemoveAllSelected = null;
Expand Down Expand Up @@ -319,11 +321,11 @@ public void onCreate(Bundle savedInstanceState) {
if (savedInstanceState != null) {
this.mLastVisiblePosition = savedInstanceState.getInt(INSTANCE_STATE_LAST_VISIBLE_POSITION, this.mLastVisiblePosition);
this.loaderID = savedInstanceState.getInt(INSTANCE_STATE_LOADER_ID, this.loaderID);
//!!!
String old = mSelectedItemIds.toString();

String oldIds = mSelectedItemIds.toString();
mSelectedItemIds.clear();
mSelectedItemIds.parse(savedInstanceState.getString(INSTANCE_STATE_SELECTED_ITEM_IDS, old));
this.mOldTitle = savedInstanceState.getString(INSTANCE_STATE_OLD_TITLE, this.mOldTitle);
mSelectedItemIds.parse(savedInstanceState.getString(INSTANCE_STATE_SELECTED_ITEM_IDS, oldIds));
this.mOldAppTitleBeforeMultiselectionStarts = savedInstanceState.getString(INSTANCE_STATE_OLD_TITLE, this.mOldAppTitleBeforeMultiselectionStarts);
this.mShowSelectedOnly = savedInstanceState.getBoolean(INSTANCE_STATE_SEL_ONLY, this.mShowSelectedOnly);
if (isMultiSelectionActive()) {
mMustReplaceMenue = true;
Expand All @@ -346,7 +348,7 @@ public void onSaveInstanceState(Bundle outState) {
outState.putInt(INSTANCE_STATE_LAST_VISIBLE_POSITION, mLastVisiblePosition);
outState.putInt(INSTANCE_STATE_LOADER_ID, loaderID);
outState.putString(INSTANCE_STATE_SELECTED_ITEM_IDS, this.mSelectedItemIds.toString());
outState.putString(INSTANCE_STATE_OLD_TITLE, this.mOldTitle);
outState.putString(INSTANCE_STATE_OLD_TITLE, this.mOldAppTitleBeforeMultiselectionStarts);
outState.putBoolean(INSTANCE_STATE_SEL_ONLY, this.mShowSelectedOnly);
}

Expand Down Expand Up @@ -791,7 +793,9 @@ private boolean onGalleryLongImageClick(final GalleryCursorAdapter.GridCellViewH

private void startMultiSelectionMode() {
// multi selection not active yet: start multi selection
mOldTitle = getActivity().getTitle().toString();
if (mOldAppTitleBeforeMultiselectionStarts == null) {
mOldAppTitleBeforeMultiselectionStarts = getActivity().getTitle().toString();
}
mMustReplaceMenue = true;
mShowSelectedOnly = false;
getActivity().invalidateOptionsMenu();
Expand Down Expand Up @@ -820,6 +824,7 @@ private void startMultiSelectionMode() {
*/
@Override
public void onPrepareOptionsMenu(Menu menu) {
this.isMultiSelectionMenuVisible = false;
super.onPrepareOptionsMenu(menu);
final boolean locked = LockScreen.isLocked(this.getActivity());
if (mMustReplaceMenue || (locked != this.locked)) {
Expand All @@ -840,6 +845,7 @@ public void onPrepareOptionsMenu(Menu menu) {
AboutDialogPreference.onPrepareOptionsMenu(getActivity(), menu);
} else if (this.isMultiSelectionActive()) { // view-multiselect
inflater.inflate(R.menu.menu_gallery_multiselect_mode_all, menu);
this.isMultiSelectionMenuVisible = true;
if (Global.allowRenameMultible) {
inflater.inflate(R.menu.menu_gallery_multiselect_rename, menu);
}
Expand Down Expand Up @@ -1259,7 +1265,9 @@ private void clearSelections() {

private void multiSelectionReplaceTitleIfNecessary() {
if (isMultiSelectionActive()) {
mOldTitle = getActivity().getTitle().toString();
if (mOldAppTitleBeforeMultiselectionStarts == null) {
mOldAppTitleBeforeMultiselectionStarts = getActivity().getTitle().toString();
}
multiSelectionUpdateActionbar("selection my have changed");
}

Expand All @@ -1269,21 +1277,23 @@ private void multiSelectionReplaceTitleIfNecessary() {
private void multiSelectionUpdateActionbar(String why) {
String newTitle = null;
if (!isMultiSelectionActive()) {

// lost last selection. revert mShowSelectedOnly if neccessary
if (mShowSelectedOnly) {
mShowSelectedOnly = false;
requery(why + "-lost multisel");
}

// lost last selection. revert title if neccessary
if (mOldTitle != null) {
if (mOldAppTitleBeforeMultiselectionStarts != null) {
// last is deselected. Restore title and menu;
newTitle = mOldTitle;
mOldTitle = null;
newTitle = mOldAppTitleBeforeMultiselectionStarts;
mOldAppTitleBeforeMultiselectionStarts = null;
getActivity().invalidateOptionsMenu();
}
} else {
if (!this.isMultiSelectionMenuVisible) {
startMultiSelectionMode();
}
// multi selection is active: update title and data for share menue
newTitle = getActivity().getString(R.string.selection_status_format, mSelectedItemIds.size());
multiSelectionUpdateShareIntent();
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/java/de/k3b/android/io/AndroidFileFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import de.k3b.io.filefacade.IFile;

/**
* de.k3b.android.io.AndroidFileFacade havs the same methods as java.io.File
* de.k3b.android.io.AndroidFileFacade has the same methods as java.io.File
* but is implemented through Android specific {@link DocumentFile}
*/
public class AndroidFileFacade extends FileFacade {
Expand Down Expand Up @@ -92,6 +92,19 @@ public AndroidFileFacade(@NonNull File file) {
this(null, file);
}

@Override
public void set(IFile src) {
if (src != null) {
if (src instanceof AndroidFileFacade) {
AndroidFileFacade androidSrc = (AndroidFileFacade) src;
this.androidFile = androidSrc.androidFile;
this.androidFileMayExist = androidSrc.androidFileMayExist;
this.readUri = androidSrc.readUri;
}
}
super.set(src);
}

public static DocumentFile getDocumentFileOrDirOrNull(@NonNull File file) {
return documentFileTranslator.getDocumentFileOrDirOrNull(file, null);
}
Expand Down
11 changes: 11 additions & 0 deletions fotolib2/src/main/java/de/k3b/io/filefacade/FileFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,19 @@ public IFile convert(String dbgContext, File file) {
return result;
}
};

private File file;

@Override
public void set(IFile src) {
if (src != null) {
if (src instanceof FileWrapper) {
set(((FileWrapper) src).child);
}
setFile(src.getFile());
}
}

@Override
public boolean equals(Object o) {
if (o instanceof File) return this.file.equals(o);
Expand Down
5 changes: 5 additions & 0 deletions fotolib2/src/main/java/de/k3b/io/filefacade/FileWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public FileWrapper(IFile child) {
this.child = child;
}

@Override
public void set(IFile src) {
child.set(src);
}

@Override
public boolean renameTo(IFile newName) {
return child.renameTo(newName);
Expand Down
4 changes: 4 additions & 0 deletions fotolib2/src/main/java/de/k3b/io/filefacade/IFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
* Goal: to become an android independant replacement for java.io.File
* that can be implemented by android independant de.k3b.io.File
* and android specific de.k3b.android.io....
*
* This interface has the similar method names/sinatures as de.k3b.io.File
*/
public interface IFile {
void set(IFile src);

@Deprecated
boolean renameTo(IFile newName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public String getOutputString() {
}


@Override
public void set(IFile src) {

}

@Override
public boolean renameTo(IFile newName) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// startParameter.offline = true
startParameter.offline = true

// include ':app', 'fotolib2', 'fotoview.library', ':osmdroid-android' , ':k3b-geoHelper' , ':fotoview.library'
include ':app', ':fotolib2', ':showexif'

0 comments on commit 708d746

Please sign in to comment.