Search in sources :

Example 11 with Folder

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;
}
Also used : Folder(com.nutomic.syncthingandroid.model.Folder)

Example 12 with Folder

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);
}
Also used : Spinner(android.widget.Spinner) Folder(com.nutomic.syncthingandroid.model.Folder) ArrayAdapter(android.widget.ArrayAdapter)

Example 13 with Folder

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);
}
Also used : FoldersAdapter(com.nutomic.syncthingandroid.views.FoldersAdapter) SyncthingActivity(com.nutomic.syncthingandroid.activities.SyncthingActivity) RestApi(com.nutomic.syncthingandroid.service.RestApi) Folder(com.nutomic.syncthingandroid.model.Folder)

Example 14 with Folder

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);
    }
}
Also used : CompletionInfo(com.nutomic.syncthingandroid.model.CompletionInfo) Folder(com.nutomic.syncthingandroid.model.Folder) Map(java.util.Map) File(java.io.File) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Aggregations

Folder (com.nutomic.syncthingandroid.model.Folder)14 File (java.io.File)3 Uri (android.net.Uri)2 ArrayAdapter (android.widget.ArrayAdapter)2 Spinner (android.widget.Spinner)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ContentResolver (android.content.ContentResolver)1 Intent (android.content.Intent)1 Handler (android.os.Handler)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 EditText (android.widget.EditText)1 TextView (android.widget.TextView)1 NonNull (androidx.annotation.NonNull)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 SyncthingActivity (com.nutomic.syncthingandroid.activities.SyncthingActivity)1 ItemFolderListBinding (com.nutomic.syncthingandroid.databinding.ItemFolderListBinding)1 CompletionInfo (com.nutomic.syncthingandroid.model.CompletionInfo)1