1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-26 06:11:19 +00:00

Fix selecting parent folder after "Sharing to Syncthing" subfolder (fixes #365) (#366)

* folder_picker: Add icon on action bar to select

* Add drawable: ic_arrow_upward_white_24

* layout/folder_picker: Add folder_go_up (fixes #365)

* Reindent code

* Fix selecting parent folder after "Sharing to Syncthing" subfolder (fixes #365)
This commit is contained in:
Catfriend1 2019-03-11 09:43:50 +01:00 committed by GitHub
parent 055a72c390
commit dde8d24e0c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 59 additions and 21 deletions

View file

@ -12,6 +12,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -41,9 +42,16 @@ import java.util.Iterator;
public class FolderPickerActivity extends SyncthingActivity
implements AdapterView.OnItemClickListener {
private static final String TAG = "FolderPickerActivity";
private static final String EXTRA_INITIAL_DIRECTORY =
"com.github.catfriend1.syncthingandroid.activities.FolderPickerActivity.INITIAL_DIRECTORY";
/**
* If requested by {@link #createIntent}, we'll only use one root dir and enforce
* the user stays within that. {@link #populateRoots} will respect this extra.
* See issue #366.
*/
private static final String EXTRA_ROOT_DIRECTORY =
"com.github.catfriend1.syncthingandroid.activities.FolderPickerActivity.ROOT_DIRECTORY";
@ -89,12 +97,12 @@ public class FolderPickerActivity extends SyncthingActivity
mListView.setAdapter(mFilesAdapter);
populateRoots();
if (getIntent().hasExtra(EXTRA_INITIAL_DIRECTORY)) {
displayFolder(new File(getIntent().getStringExtra(EXTRA_INITIAL_DIRECTORY)));
} else {
displayRoot();
String initialDirectory = getIntent().getStringExtra(EXTRA_INITIAL_DIRECTORY);
displayFolder(new File(initialDirectory));
return;
}
displayRoot();
}
/**
@ -105,16 +113,15 @@ public class FolderPickerActivity extends SyncthingActivity
@SuppressLint("NewApi")
private void populateRoots() {
ArrayList<File> roots = new ArrayList<>();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
roots.addAll(Arrays.asList(getExternalFilesDirs(null)));
roots.remove(getExternalFilesDir(null));
roots.remove(null); // getExternalFilesDirs may return null for an ejected SDcard.
}
String rootDir = getIntent().getStringExtra(EXTRA_ROOT_DIRECTORY);
if (getIntent().hasExtra(EXTRA_ROOT_DIRECTORY) && !TextUtils.isEmpty(rootDir)) {
roots.add(new File(rootDir));
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
roots.addAll(Arrays.asList(getExternalFilesDirs(null)));
roots.remove(getExternalFilesDir(null));
roots.remove(null); // getExternalFilesDirs may return null for an ejected SDcard.
}
roots.add(Environment.getExternalStorageDirectory());
roots.add(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC));
roots.add(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES));
@ -167,6 +174,11 @@ public class FolderPickerActivity extends SyncthingActivity
.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT));
dialog.show();
return true;
case R.id.folder_go_up:
if (canGoUpToSubDir() || canGoUpToRootDir()) {
goUpToParentDir();
}
return true;
case R.id.select:
Intent intent = new Intent()
.putExtra(EXTRA_RESULT_DIRECTORY, Util.formatPath(mLocation.getAbsolutePath()));
@ -181,6 +193,26 @@ public class FolderPickerActivity extends SyncthingActivity
}
}
public Boolean canGoUpToSubDir() {
return mLocation != null && !mRootsAdapter.contains(mLocation);
}
public Boolean canGoUpToRootDir() {
return mRootsAdapter.contains(mLocation) && mRootsAdapter.getCount() > 1;
}
public void goUpToParentDir() {
if (canGoUpToSubDir()) {
displayFolder(mLocation.getParentFile());
return;
}
if (canGoUpToRootDir()) {
displayRoot();
return;
}
Log.e(TAG, "goUpToParentDir: Cannot go up.");
}
/**
* Creates a new folder with the given name and enters it.
*/
@ -287,14 +319,8 @@ public class FolderPickerActivity extends SyncthingActivity
*/
@Override
public void onBackPressed() {
if (!mRootsAdapter.contains(mLocation) && mLocation != null) {
displayFolder(mLocation.getParentFile());
} else if (mRootsAdapter.contains(mLocation) && mRootsAdapter.getCount() > 1) {
displayRoot();
} else {
setResult(Activity.RESULT_CANCELED);
finish();
}
setResult(Activity.RESULT_CANCELED);
finish();
}
/**

View file

@ -185,9 +185,11 @@ public class ShareActivity extends SyncthingActivity
browseButton.setOnClickListener(view -> {
Folder folder = (Folder) mFoldersSpinner.getSelectedItem();
File initialDirectory = new File(folder.path, getSavedSubDirectory());
startActivityForResult(FolderPickerActivity.createIntent(getApplicationContext(),
initialDirectory.getAbsolutePath(), folder.path),
FolderPickerActivity.DIRECTORY_REQUEST_CODE);
Intent intent = FolderPickerActivity.createIntent(
getApplicationContext(),
initialDirectory.getAbsolutePath(), folder.path
);
startActivityForResult(intent, FolderPickerActivity.DIRECTORY_REQUEST_CODE);
});
mCancelButton.setOnClickListener(view -> finish());

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 B

View file

@ -6,6 +6,13 @@
<item
android:id="@+id/select"
android:title="@string/select_folder"
android:icon="@drawable/ic_done_white_24dp"
app:showAsAction="ifRoom" />
<item
android:id="@+id/folder_go_up"
android:title="@string/folder_go_up"
android:icon="@drawable/ic_arrow_upward_white_24"
app:showAsAction="ifRoom" />
<item

View file

@ -704,6 +704,9 @@ Please report any problems you encounter via Github.</string>
<string name="create_folder_failed">Failed to create folder</string>
<!-- Menu item to go up to parent folder -->
<string name="folder_go_up">Go up</string>
<!-- LogActivity -->