Skip to content

Commit

Permalink
Add ability to delete files from a multi select dialog.
Browse files Browse the repository at this point in the history
Issue #928
  • Loading branch information
mendhak committed Dec 20, 2021
1 parent acbf321 commit 57d82c6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class PreferenceNames {
public static final String LOG_SATELLITE_LOCATIONS = "log_satellite_locations";
public static final String LOG_NETWORK_LOCATIONS="log_network_locations";
public static final String NEW_FILE_CREATION_MODE = "new_file_creation";
public static final String LOG_DELETE_FILES = "delete_files";
public static final String CUSTOM_FILE_NAME = "new_file_custom_name";
public static final String CUSTOM_FILE_NAME_KEEP_CHANGING = "new_file_custom_keep_changing";
public static final String ASK_CUSTOM_FILE_NAME = "new_file_custom_each_time";
Expand Down
15 changes: 10 additions & 5 deletions gpslogger/src/main/java/com/mendhak/gpslogger/ui/Dialogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import com.codekidlabs.storagechooser.StorageChooser;
import com.mendhak.gpslogger.R;
import com.mendhak.gpslogger.common.PreferenceHelper;
import com.mendhak.gpslogger.common.Strings;
import com.mendhak.gpslogger.common.Systems;
import com.mendhak.gpslogger.loggers.Files;
Expand Down Expand Up @@ -84,18 +85,18 @@ protected static String getFormattedErrorMessageForPlainText(String message, Thr
}

public static StorageChooser directoryChooser(Activity activity){
return storageChooser(StorageChooser.DIRECTORY_CHOOSER, false, (FragmentActivity) activity);
return storageChooser(StorageChooser.DIRECTORY_CHOOSER, false, null, (FragmentActivity) activity);
}

public static StorageChooser filePicker(FragmentActivity activity){
return storageChooser(StorageChooser.FILE_PICKER, false, (FragmentActivity) activity);
return storageChooser(StorageChooser.FILE_PICKER, false, null, (FragmentActivity) activity);
}

public static StorageChooser multiFilePicker(FragmentActivity activity){
return storageChooser(StorageChooser.FILE_PICKER, true, (FragmentActivity) activity);
public static StorageChooser multiFilePicker(FragmentActivity activity, String startingPath){
return storageChooser(StorageChooser.FILE_PICKER, true, startingPath, (FragmentActivity) activity);
}

private static StorageChooser storageChooser(String chooserType, boolean allowMultiSelect, FragmentActivity activity){
private static StorageChooser storageChooser(String chooserType, boolean allowMultiSelect, String startingPath, FragmentActivity activity){
com.codekidlabs.storagechooser.Content scContent = new com.codekidlabs.storagechooser.Content();
scContent.setCreateLabel(activity.getString(R.string.storage_chooser_create_label));
scContent.setInternalStorageText(activity.getString(R.string.storage_chooser_internal_storage_text));
Expand Down Expand Up @@ -140,6 +141,10 @@ private static StorageChooser storageChooser(String chooserType, boolean allowMu
.setType(chooserType) //File picker or folder picker
;

if(!Strings.isNullOrEmpty(startingPath)){
builder.skipOverview(true, startingPath);
}

if(!allowMultiSelect){
builder.disableMultiSelect();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ public void onCreate(Bundle savedInstanceState) {
findPreference("log_plain_text_csv_advanced").setOnPreferenceClickListener(this);
setPreferenceCsvSummary(preferenceHelper.getCSVDelimiter(), preferenceHelper.shouldCSVUseCommaInsteadOfPoint());

findPreference("delete_files").setOnPreferenceClickListener(this);

}

private void setPreferenceCsvSummary(String delimiter, Boolean useComma){
Expand Down Expand Up @@ -247,6 +249,21 @@ public boolean onPreferenceClick(Preference preference) {
.show(this,PreferenceNames.CUSTOM_FILE_NAME);
}

if(preference.getKey().equalsIgnoreCase(PreferenceNames.LOG_DELETE_FILES)){
StorageChooser chooser = Dialogs.multiFilePicker(getActivity(), PreferenceHelper.getInstance().getGpsLoggerFolder());
chooser.setOnMultipleSelectListener(selectedFilePaths -> {
Dialogs.progress(getActivity(), getString(R.string.please_wait));
for(String filePath : selectedFilePaths){
LOG.debug(filePath);
File f = new File(filePath);
f.delete();
}
Dialogs.hideProgress();
});

chooser.show();
}

return false;
}

Expand Down
5 changes: 5 additions & 0 deletions gpslogger/src/main/res/xml/pref_logging.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
android:defaultValue=","
app:iconSpaceReserved="false" />

<Preference
android:title="Delete selected files"
android:key="delete_files"
app:iconSpaceReserved="false" />

</PreferenceCategory>

</PreferenceScreen>

0 comments on commit 57d82c6

Please sign in to comment.