use of com.nutomic.syncthingandroid.model.Folder in project syncthing-android by syncthing.
the class ShareActivity method getSavedSubDirectory.
/**
* Get the previously selected sub directory for the currently selected Syncthing folder.
*/
private String getSavedSubDirectory() {
Folder selectedFolder = (Folder) mFoldersSpinner.getSelectedItem();
String savedSubDirectory = "";
if (selectedFolder != null) {
savedSubDirectory = PreferenceManager.getDefaultSharedPreferences(this).getString(PREF_FOLDER_SAVED_SUBDIRECTORY + selectedFolder.id, "");
}
return savedSubDirectory;
}
use of com.nutomic.syncthingandroid.model.Folder in project syncthing-android by syncthing.
the class ShareActivity method onServiceStateChange.
@Override
public void onServiceStateChange(SyncthingService.State currentState) {
if (currentState != SyncthingService.State.ACTIVE || getApi() == null)
return;
List<Folder> folders = getApi().getFolders();
// Get the index of the previously selected folder.
int folderIndex = 0;
String savedFolderId = PreferenceManager.getDefaultSharedPreferences(this).getString(PREF_PREVIOUSLY_SELECTED_SYNCTHING_FOLDER, "");
for (Folder folder : folders) {
if (folder.id.equals(savedFolderId)) {
folderIndex = folders.indexOf(folder);
break;
}
}
ArrayAdapter<Folder> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, folders);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner sItems = findViewById(R.id.folders);
sItems.setAdapter(adapter);
sItems.setSelection(folderIndex);
}
use of com.nutomic.syncthingandroid.model.Folder in project syncthing-android by syncthing.
the class FolderListFragment method updateList.
/**
* Refreshes ListView by updating folders and info.
*
* Also creates adapter if it doesn't exist yet.
*/
private void updateList() {
SyncthingActivity activity = (SyncthingActivity) getActivity();
if (activity == null || getView() == null || activity.isFinishing()) {
return;
}
RestApi restApi = activity.getApi();
if (restApi == null || !restApi.isConfigLoaded()) {
return;
}
List<Folder> folders = restApi.getFolders();
if (folders == null) {
return;
}
if (mAdapter == null) {
mAdapter = new FoldersAdapter(activity);
setListAdapter(mAdapter);
}
// Prevent scroll position reset due to list update from clear().
mAdapter.setNotifyOnChange(false);
mAdapter.clear();
mAdapter.addAll(folders);
mAdapter.updateFolderStatus(restApi);
mAdapter.notifyDataSetChanged();
setListShown(true);
}
use of com.nutomic.syncthingandroid.model.Folder in project syncthing-android by syncthing.
the class EventProcessor method onEvent.
/**
* Performs the actual event handling.
*/
@Override
public void onEvent(Event event) {
switch(event.type) {
case "ConfigSaved":
if (mApi != null) {
Log.v(TAG, "Forwarding ConfigSaved event to RestApi to get the updated config.");
mApi.reloadConfig();
}
break;
case "PendingDevicesChanged":
mapNullable((List<Map<String, String>>) event.data.get("added"), this::onPendingDevicesChanged);
break;
case "FolderCompletion":
CompletionInfo completionInfo = new CompletionInfo();
completionInfo.completion = (Double) event.data.get("completion");
mApi.setCompletionInfo(// deviceId
(String) event.data.get("device"), // folderId
(String) event.data.get("folder"), completionInfo);
break;
case "PendingFoldersChanged":
mapNullable((List<Map<String, String>>) event.data.get("added"), this::onPendingFoldersChanged);
break;
case "ItemFinished":
String folder = (String) event.data.get("folder");
String folderPath = null;
for (Folder f : mApi.getFolders()) {
if (f.id.equals(folder)) {
folderPath = f.path;
}
}
File updatedFile = new File(folderPath, (String) event.data.get("item"));
if (!"delete".equals(event.data.get("action"))) {
Log.i(TAG, "Rescanned file via MediaScanner: " + updatedFile.toString());
MediaScannerConnection.scanFile(mContext, new String[] { updatedFile.getPath() }, null, null);
} else {
// https://stackoverflow.com/a/29881556/1837158
Log.i(TAG, "Deleted file from MediaStore: " + updatedFile.toString());
Uri contentUri = MediaStore.Files.getContentUri("external");
ContentResolver resolver = mContext.getContentResolver();
resolver.delete(contentUri, MediaStore.Images.ImageColumns.DATA + " LIKE ?", new String[] { updatedFile.getPath() });
}
break;
case "Ping":
// Ignored.
break;
case "DeviceConnected":
case "DeviceDisconnected":
case "DeviceDiscovered":
case "DownloadProgress":
case "FolderPaused":
case "FolderScanProgress":
case "FolderSummary":
case "ItemStarted":
case "LocalIndexUpdated":
case "LoginAttempt":
case "RemoteDownloadProgress":
case "RemoteIndexUpdated":
case "Starting":
case "StartupComplete":
case "StateChanged":
if (BuildConfig.DEBUG) {
Log.v(TAG, "Ignored event " + event.type + ", data " + event.data);
}
break;
default:
Log.v(TAG, "Unhandled event " + event.type);
}
}
Aggregations