use of com.nutomic.syncthingandroid.databinding.ItemFolderListBinding 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();
}
Aggregations