use of com.nutomic.syncthingandroid.model.Folder in project syncthing-android by syncthing.
the class FolderActivity method onApiChange.
@Override
public void onApiChange(SyncthingService.State currentState) {
if (currentState != ACTIVE) {
finish();
return;
}
if (!mIsCreateMode) {
List<Folder> folders = getApi().getFolders();
String passedId = getIntent().getStringExtra(EXTRA_FOLDER_ID);
mFolder = null;
for (Folder currentFolder : folders) {
if (currentFolder.id.equals(passedId)) {
mFolder = currentFolder;
break;
}
}
if (mFolder == null) {
Log.w(TAG, "Folder not found in API update, maybe it was deleted?");
finish();
return;
}
}
if (getIntent().hasExtra(EXTRA_DEVICE_ID)) {
mFolder.addDevice(getIntent().getStringExtra(EXTRA_DEVICE_ID));
mFolderNeedsToUpdate = true;
}
attemptToApplyVersioningConfig();
updateViewsAndSetListeners();
}
use of com.nutomic.syncthingandroid.model.Folder in project syncthing-android by syncthing.
the class RestApi method getDeviceCompletion.
/**
* Calculates completion percentage for the given device using {@link #mCachedModelInfo}.
*/
private int getDeviceCompletion(String deviceId) {
int folderCount = 0;
float percentageSum = 0;
// Syncthing UI limits pending deletes to 95% completion of a device
int maxPercentage = 100;
for (Map.Entry<String, Model> modelInfo : mCachedModelInfo.entrySet()) {
boolean isShared = false;
for (Folder r : getFolders()) {
if (r.getDevice(deviceId) != null) {
isShared = true;
break;
}
}
if (isShared) {
long global = modelInfo.getValue().globalBytes;
long local = modelInfo.getValue().inSyncBytes;
if (modelInfo.getValue().needFiles == 0 && modelInfo.getValue().needDeletes > 0)
maxPercentage = 95;
percentageSum += (global != 0) ? (local * 100f) / global : 100f;
folderCount++;
}
}
return (folderCount != 0) ? Math.min(Math.round(percentageSum / folderCount), maxPercentage) : 100;
}
use of com.nutomic.syncthingandroid.model.Folder in project syncthing-android by syncthing.
the class SyncthingService method onSyncthingStarted.
private void onSyncthingStarted() {
onApiChange(State.ACTIVE);
Handler handler = new Handler();
new Thread(() -> {
for (Folder r : mApi.getFolders()) {
try {
mObservers.add(new FolderObserver(mApi, r, handler));
} catch (FolderObserver.FolderNotExistingException e) {
Log.w(TAG, "Failed to add observer for folder", e);
} catch (StackOverflowError e) {
Log.w(TAG, "Failed to add folder observer", e);
Toast.makeText(SyncthingService.this, R.string.toast_folder_observer_stack_overflow, Toast.LENGTH_LONG).show();
}
}
}).start();
}
use of com.nutomic.syncthingandroid.model.Folder in project syncthing-android by syncthing.
the class FoldersAdapter method getView.
@Override
@NonNull
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
ItemFolderListBinding binding = (convertView == null) ? DataBindingUtil.inflate(LayoutInflater.from(mContext), R.layout.item_folder_list, parent, false) : DataBindingUtil.bind(convertView);
Folder folder = getItem(position);
binding.label.setText(TextUtils.isEmpty(folder.label) ? folder.id : folder.label);
binding.directory.setText(folder.path);
binding.override.setOnClickListener(v -> {
// Send "Override changes" through our service to the REST API.
Intent intent = new Intent(mContext, SyncthingService.class).putExtra(SyncthingService.EXTRA_FOLDER_ID, folder.id);
intent.setAction(SyncthingService.ACTION_OVERRIDE_CHANGES);
mContext.startService(intent);
});
binding.openFolder.setOnClickListener(v -> {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(folder.path)), "resource/folder");
intent.putExtra("org.openintents.extra.ABSOLUTE_PATH", folder.path);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK);
if (intent.resolveActivity(mContext.getPackageManager()) != null) {
mContext.startActivity(intent);
} else {
// Try a second way to find a compatible file explorer app.
Log.v(TAG, "openFolder: Fallback to application chooser to open folder.");
intent.setDataAndType(Uri.parse(folder.path), "application/*");
Intent chooserIntent = Intent.createChooser(intent, mContext.getString(R.string.open_file_manager));
if (chooserIntent != null) {
mContext.startActivity(chooserIntent);
} else {
Toast.makeText(mContext, R.string.toast_no_file_manager, Toast.LENGTH_SHORT).show();
}
}
});
updateFolderStatusView(binding, folder);
return binding.getRoot();
}
use of com.nutomic.syncthingandroid.model.Folder in project syncthing-android by syncthing.
the class FolderActivity method onServiceStateChange.
@Override
public void onServiceStateChange(SyncthingService.State currentState) {
if (currentState != ACTIVE) {
finish();
return;
}
if (!mIsCreateMode) {
List<Folder> folders = getApi().getFolders();
String passedId = getIntent().getStringExtra(EXTRA_FOLDER_ID);
mFolder = null;
for (Folder currentFolder : folders) {
if (currentFolder.id.equals(passedId)) {
mFolder = currentFolder;
break;
}
}
if (mFolder == null) {
Log.w(TAG, "Folder not found in API update, maybe it was deleted?");
finish();
return;
}
checkWriteAndUpdateUI();
}
if (getIntent().hasExtra(EXTRA_DEVICE_ID)) {
mFolder.addDevice(getIntent().getStringExtra(EXTRA_DEVICE_ID));
mFolderNeedsToUpdate = true;
}
attemptToApplyVersioningConfig();
updateViewsAndSetListeners();
}
Aggregations