mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-23 11:21:29 +00:00
Added button to open folder from list (fixes #770)
This commit is contained in:
parent
e0412ec51b
commit
ea9af597a5
3 changed files with 20 additions and 15 deletions
|
@ -1,7 +1,6 @@
|
||||||
package com.nutomic.syncthingandroid.fragments;
|
package com.nutomic.syncthingandroid.fragments;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.ListFragment;
|
import android.support.v4.app.ListFragment;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
@ -27,7 +26,7 @@ import java.util.TimerTask;
|
||||||
* Displays a list of all existing folders.
|
* Displays a list of all existing folders.
|
||||||
*/
|
*/
|
||||||
public class FolderListFragment extends ListFragment implements SyncthingService.OnApiChangeListener,
|
public class FolderListFragment extends ListFragment implements SyncthingService.OnApiChangeListener,
|
||||||
AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener {
|
AdapterView.OnItemClickListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares folders by labels, uses the folder ID as fallback if the label is empty
|
* Compares folders by labels, uses the folder ID as fallback if the label is empty
|
||||||
|
@ -76,7 +75,6 @@ public class FolderListFragment extends ListFragment implements SyncthingService
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
setEmptyText(getString(R.string.folder_list_empty));
|
setEmptyText(getString(R.string.folder_list_empty));
|
||||||
getListView().setOnItemClickListener(this);
|
getListView().setOnItemClickListener(this);
|
||||||
getListView().setOnItemLongClickListener(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,18 +111,6 @@ public class FolderListFragment extends ListFragment implements SyncthingService
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Opens the folder path with a user selected app.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
||||||
Uri uri = Uri.parse(mAdapter.getItem(i).path);
|
|
||||||
intent.setDataAndType(uri, "*/*");
|
|
||||||
startActivity(intent);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
inflater.inflate(R.menu.folder_list, menu);
|
inflater.inflate(R.menu.folder_list, menu);
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package com.nutomic.syncthingandroid.views;
|
package com.nutomic.syncthingandroid.views;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.databinding.DataBindingUtil;
|
import android.databinding.DataBindingUtil;
|
||||||
|
import android.net.Uri;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
@ -19,6 +21,7 @@ import com.nutomic.syncthingandroid.model.Model;
|
||||||
import com.nutomic.syncthingandroid.service.RestApi;
|
import com.nutomic.syncthingandroid.service.RestApi;
|
||||||
import com.nutomic.syncthingandroid.util.Util;
|
import com.nutomic.syncthingandroid.util.Util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import static android.view.View.GONE;
|
import static android.view.View.GONE;
|
||||||
|
@ -47,6 +50,12 @@ public class FoldersAdapter extends ArrayAdapter<Folder> {
|
||||||
binding.label.setText(TextUtils.isEmpty(folder.label) ? folder.id : folder.label);
|
binding.label.setText(TextUtils.isEmpty(folder.label) ? folder.id : folder.label);
|
||||||
binding.state.setTextColor(ContextCompat.getColor(getContext(), R.color.text_green));
|
binding.state.setTextColor(ContextCompat.getColor(getContext(), R.color.text_green));
|
||||||
binding.directory.setText(folder.path);
|
binding.directory.setText(folder.path);
|
||||||
|
binding.openFolder.setOnClickListener(v -> {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
|
intent.setDataAndType(Uri.fromFile(new File(folder.path)), "resource/folder");
|
||||||
|
getContext().startActivity(intent);
|
||||||
|
});
|
||||||
|
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
int percentage = (model.globalBytes != 0)
|
int percentage = (model.globalBytes != 0)
|
||||||
? Math.round(100 * model.inSyncBytes / model.globalBytes)
|
? Math.round(100 * model.inSyncBytes / model.globalBytes)
|
||||||
|
|
|
@ -31,6 +31,16 @@
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:textAppearance="?textAppearanceListItemSmall" />
|
android:textAppearance="?textAppearanceListItemSmall" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/open_folder"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:src="@drawable/ic_folder_black_24dp"
|
||||||
|
android:background="@null"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/directory"
|
android:id="@+id/directory"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
Loading…
Reference in a new issue