mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-29 15:51:17 +00:00
* 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:
parent
055a72c390
commit
dde8d24e0c
9 changed files with 59 additions and 21 deletions
|
@ -12,6 +12,7 @@ import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -41,9 +42,16 @@ import java.util.Iterator;
|
||||||
public class FolderPickerActivity extends SyncthingActivity
|
public class FolderPickerActivity extends SyncthingActivity
|
||||||
implements AdapterView.OnItemClickListener {
|
implements AdapterView.OnItemClickListener {
|
||||||
|
|
||||||
|
private static final String TAG = "FolderPickerActivity";
|
||||||
|
|
||||||
private static final String EXTRA_INITIAL_DIRECTORY =
|
private static final String EXTRA_INITIAL_DIRECTORY =
|
||||||
"com.github.catfriend1.syncthingandroid.activities.FolderPickerActivity.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 =
|
private static final String EXTRA_ROOT_DIRECTORY =
|
||||||
"com.github.catfriend1.syncthingandroid.activities.FolderPickerActivity.ROOT_DIRECTORY";
|
"com.github.catfriend1.syncthingandroid.activities.FolderPickerActivity.ROOT_DIRECTORY";
|
||||||
|
|
||||||
|
@ -89,12 +97,12 @@ public class FolderPickerActivity extends SyncthingActivity
|
||||||
mListView.setAdapter(mFilesAdapter);
|
mListView.setAdapter(mFilesAdapter);
|
||||||
|
|
||||||
populateRoots();
|
populateRoots();
|
||||||
|
|
||||||
if (getIntent().hasExtra(EXTRA_INITIAL_DIRECTORY)) {
|
if (getIntent().hasExtra(EXTRA_INITIAL_DIRECTORY)) {
|
||||||
displayFolder(new File(getIntent().getStringExtra(EXTRA_INITIAL_DIRECTORY)));
|
String initialDirectory = getIntent().getStringExtra(EXTRA_INITIAL_DIRECTORY);
|
||||||
} else {
|
displayFolder(new File(initialDirectory));
|
||||||
displayRoot();
|
return;
|
||||||
}
|
}
|
||||||
|
displayRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -105,16 +113,15 @@ public class FolderPickerActivity extends SyncthingActivity
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
private void populateRoots() {
|
private void populateRoots() {
|
||||||
ArrayList<File> roots = new ArrayList<>();
|
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);
|
String rootDir = getIntent().getStringExtra(EXTRA_ROOT_DIRECTORY);
|
||||||
if (getIntent().hasExtra(EXTRA_ROOT_DIRECTORY) && !TextUtils.isEmpty(rootDir)) {
|
if (getIntent().hasExtra(EXTRA_ROOT_DIRECTORY) && !TextUtils.isEmpty(rootDir)) {
|
||||||
roots.add(new File(rootDir));
|
roots.add(new File(rootDir));
|
||||||
} else {
|
} 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.getExternalStorageDirectory());
|
||||||
roots.add(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC));
|
roots.add(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC));
|
||||||
roots.add(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES));
|
roots.add(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES));
|
||||||
|
@ -167,6 +174,11 @@ public class FolderPickerActivity extends SyncthingActivity
|
||||||
.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT));
|
.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT));
|
||||||
dialog.show();
|
dialog.show();
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.folder_go_up:
|
||||||
|
if (canGoUpToSubDir() || canGoUpToRootDir()) {
|
||||||
|
goUpToParentDir();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
case R.id.select:
|
case R.id.select:
|
||||||
Intent intent = new Intent()
|
Intent intent = new Intent()
|
||||||
.putExtra(EXTRA_RESULT_DIRECTORY, Util.formatPath(mLocation.getAbsolutePath()));
|
.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.
|
* Creates a new folder with the given name and enters it.
|
||||||
*/
|
*/
|
||||||
|
@ -287,14 +319,8 @@ public class FolderPickerActivity extends SyncthingActivity
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (!mRootsAdapter.contains(mLocation) && mLocation != null) {
|
setResult(Activity.RESULT_CANCELED);
|
||||||
displayFolder(mLocation.getParentFile());
|
finish();
|
||||||
} else if (mRootsAdapter.contains(mLocation) && mRootsAdapter.getCount() > 1) {
|
|
||||||
displayRoot();
|
|
||||||
} else {
|
|
||||||
setResult(Activity.RESULT_CANCELED);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -185,9 +185,11 @@ public class ShareActivity extends SyncthingActivity
|
||||||
browseButton.setOnClickListener(view -> {
|
browseButton.setOnClickListener(view -> {
|
||||||
Folder folder = (Folder) mFoldersSpinner.getSelectedItem();
|
Folder folder = (Folder) mFoldersSpinner.getSelectedItem();
|
||||||
File initialDirectory = new File(folder.path, getSavedSubDirectory());
|
File initialDirectory = new File(folder.path, getSavedSubDirectory());
|
||||||
startActivityForResult(FolderPickerActivity.createIntent(getApplicationContext(),
|
Intent intent = FolderPickerActivity.createIntent(
|
||||||
initialDirectory.getAbsolutePath(), folder.path),
|
getApplicationContext(),
|
||||||
FolderPickerActivity.DIRECTORY_REQUEST_CODE);
|
initialDirectory.getAbsolutePath(), folder.path
|
||||||
|
);
|
||||||
|
startActivityForResult(intent, FolderPickerActivity.DIRECTORY_REQUEST_CODE);
|
||||||
});
|
});
|
||||||
|
|
||||||
mCancelButton.setOnClickListener(view -> finish());
|
mCancelButton.setOnClickListener(view -> finish());
|
||||||
|
|
BIN
app/src/main/res/drawable-hdpi/ic_arrow_upward_white_24.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_arrow_upward_white_24.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 205 B |
BIN
app/src/main/res/drawable-mdpi/ic_arrow_upward_white_24.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_arrow_upward_white_24.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 185 B |
BIN
app/src/main/res/drawable-xhdpi/ic_arrow_upward_white_24.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_arrow_upward_white_24.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 246 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_arrow_upward_white_24.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_arrow_upward_white_24.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 301 B |
BIN
app/src/main/res/drawable-xxxhdpi/ic_arrow_upward_white_24.png
Normal file
BIN
app/src/main/res/drawable-xxxhdpi/ic_arrow_upward_white_24.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 392 B |
|
@ -6,6 +6,13 @@
|
||||||
<item
|
<item
|
||||||
android:id="@+id/select"
|
android:id="@+id/select"
|
||||||
android:title="@string/select_folder"
|
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" />
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
|
|
|
@ -704,6 +704,9 @@ Please report any problems you encounter via Github.</string>
|
||||||
|
|
||||||
<string name="create_folder_failed">Failed to create folder</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 -->
|
<!-- LogActivity -->
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue