use of com.amaze.filemanager.ui.activities.MainActivity in project AmazeFileManager by TeamAmaze.
the class CloudLoaderAsyncTask method onCancelled.
@Override
protected void onCancelled() {
super.onCancelled();
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
mainActivity.getSupportLoaderManager().destroyLoader(MainActivity.REQUEST_CODE_CLOUD_LIST_KEY);
mainActivity.getSupportLoaderManager().destroyLoader(MainActivity.REQUEST_CODE_CLOUD_LIST_KEYS);
}
}
use of com.amaze.filemanager.ui.activities.MainActivity in project AmazeFileManager by TeamAmaze.
the class CloudLoaderAsyncTask method doInBackground.
@Override
@NonNull
public Boolean doInBackground(Void... voids) {
boolean hasUpdatedDrawer = false;
if (data == null)
return false;
if (data.getCount() > 0 && data.moveToFirst()) {
do {
if (mainActivity.get() == null || isCancelled()) {
cancel(true);
return false;
}
switch(data.getInt(0)) {
case 1:
try {
CloudRail.setAppKey(data.getString(1));
} catch (Exception e) {
// any other exception due to network conditions or other error
e.printStackTrace();
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.failed_cloud_api_key);
} else {
cancel(true);
}
return false;
}
break;
case 2:
// DRIVE
try {
CloudEntry cloudEntryGdrive = null;
CloudEntry savedCloudEntryGdrive;
GoogleDrive cloudStorageDrive;
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
cloudStorageDrive = new GoogleDrive(mainActivity.getApplicationContext(), data.getString(1), "", MainActivity.CLOUD_AUTHENTICATOR_REDIRECT_URI, data.getString(2));
} else {
cancel(true);
return false;
}
cloudStorageDrive.useAdvancedAuthentication();
if ((savedCloudEntryGdrive = cloudHandler.findEntry(OpenMode.GDRIVE)) != null) {
try {
cloudStorageDrive.loadAsString(savedCloudEntryGdrive.getPersistData().value);
} catch (ParseException e) {
e.printStackTrace();
// we need to update the persist string as existing one is been compromised
cloudStorageDrive.login();
cloudEntryGdrive = new CloudEntry(OpenMode.GDRIVE, cloudStorageDrive.saveAsString());
cloudHandler.updateEntry(OpenMode.GDRIVE, cloudEntryGdrive);
}
} else {
cloudStorageDrive.login();
cloudEntryGdrive = new CloudEntry(OpenMode.GDRIVE, cloudStorageDrive.saveAsString());
cloudHandler.addEntry(cloudEntryGdrive);
}
dataUtils.addAccount(cloudStorageDrive);
hasUpdatedDrawer = true;
} catch (CloudPluginException e) {
e.printStackTrace();
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.cloud_error_plugin);
mainActivity.deleteConnection(OpenMode.GDRIVE);
} else {
cancel(true);
}
return false;
} catch (AuthenticationException e) {
e.printStackTrace();
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.cloud_fail_authenticate);
mainActivity.deleteConnection(OpenMode.GDRIVE);
} else {
cancel(true);
}
return false;
} catch (Exception e) {
// any other exception due to network conditions or other error
e.printStackTrace();
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.failed_cloud_new_connection);
mainActivity.deleteConnection(OpenMode.GDRIVE);
} else {
cancel(true);
}
return false;
}
break;
case 3:
// DROPBOX
try {
CloudEntry cloudEntryDropbox = null;
CloudEntry savedCloudEntryDropbox;
CloudStorage cloudStorageDropbox;
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
cloudStorageDropbox = new Dropbox(mainActivity.getApplicationContext(), data.getString(1), data.getString(2));
} else {
cancel(true);
return false;
}
if ((savedCloudEntryDropbox = cloudHandler.findEntry(OpenMode.DROPBOX)) != null) {
// we already have the entry and saved state, get it
try {
cloudStorageDropbox.loadAsString(savedCloudEntryDropbox.getPersistData().value);
} catch (ParseException e) {
e.printStackTrace();
// we need to persist data again
cloudStorageDropbox.login();
cloudEntryDropbox = new CloudEntry(OpenMode.DROPBOX, cloudStorageDropbox.saveAsString());
cloudHandler.updateEntry(OpenMode.DROPBOX, cloudEntryDropbox);
}
} else {
cloudStorageDropbox.login();
cloudEntryDropbox = new CloudEntry(OpenMode.DROPBOX, cloudStorageDropbox.saveAsString());
cloudHandler.addEntry(cloudEntryDropbox);
}
dataUtils.addAccount(cloudStorageDropbox);
hasUpdatedDrawer = true;
} catch (CloudPluginException e) {
e.printStackTrace();
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.cloud_error_plugin);
mainActivity.deleteConnection(OpenMode.DROPBOX);
} else {
cancel(true);
}
return false;
} catch (AuthenticationException e) {
e.printStackTrace();
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.cloud_fail_authenticate);
mainActivity.deleteConnection(OpenMode.DROPBOX);
} else
cancel(true);
return false;
} catch (Exception e) {
// any other exception due to network conditions or other error
e.printStackTrace();
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.failed_cloud_new_connection);
mainActivity.deleteConnection(OpenMode.DROPBOX);
} else
cancel(true);
return false;
}
break;
case 4:
// BOX
try {
CloudEntry cloudEntryBox = null;
CloudEntry savedCloudEntryBox;
CloudStorage cloudStorageBox;
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
cloudStorageBox = new Box(mainActivity.getApplicationContext(), data.getString(1), data.getString(2));
} else {
cancel(true);
return false;
}
if ((savedCloudEntryBox = cloudHandler.findEntry(OpenMode.BOX)) != null) {
// we already have the entry and saved state, get it
try {
cloudStorageBox.loadAsString(savedCloudEntryBox.getPersistData().value);
} catch (ParseException e) {
e.printStackTrace();
// we need to persist data again
cloudStorageBox.login();
cloudEntryBox = new CloudEntry(OpenMode.BOX, cloudStorageBox.saveAsString());
cloudHandler.updateEntry(OpenMode.BOX, cloudEntryBox);
}
} else {
cloudStorageBox.login();
cloudEntryBox = new CloudEntry(OpenMode.BOX, cloudStorageBox.saveAsString());
cloudHandler.addEntry(cloudEntryBox);
}
dataUtils.addAccount(cloudStorageBox);
hasUpdatedDrawer = true;
} catch (CloudPluginException e) {
e.printStackTrace();
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.cloud_error_plugin);
mainActivity.deleteConnection(OpenMode.BOX);
} else
cancel(true);
return false;
} catch (AuthenticationException e) {
e.printStackTrace();
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.cloud_fail_authenticate);
mainActivity.deleteConnection(OpenMode.BOX);
} else
cancel(true);
return false;
} catch (Exception e) {
// any other exception due to network conditions or other error
e.printStackTrace();
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.failed_cloud_new_connection);
mainActivity.deleteConnection(OpenMode.BOX);
} else
cancel(true);
return false;
}
break;
case 5:
// ONEDRIVE
try {
CloudEntry cloudEntryOnedrive = null;
CloudEntry savedCloudEntryOnedrive;
CloudStorage cloudStorageOnedrive;
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
cloudStorageOnedrive = new OneDrive(mainActivity.getApplicationContext(), data.getString(1), data.getString(2));
} else {
cancel(true);
return false;
}
if ((savedCloudEntryOnedrive = cloudHandler.findEntry(OpenMode.ONEDRIVE)) != null) {
// we already have the entry and saved state, get it
try {
cloudStorageOnedrive.loadAsString(savedCloudEntryOnedrive.getPersistData().value);
} catch (ParseException e) {
e.printStackTrace();
// we need to persist data again
cloudStorageOnedrive.login();
cloudEntryOnedrive = new CloudEntry(OpenMode.ONEDRIVE, cloudStorageOnedrive.saveAsString());
cloudHandler.updateEntry(OpenMode.ONEDRIVE, cloudEntryOnedrive);
}
} else {
cloudStorageOnedrive.login();
cloudEntryOnedrive = new CloudEntry(OpenMode.ONEDRIVE, cloudStorageOnedrive.saveAsString());
cloudHandler.addEntry(cloudEntryOnedrive);
}
dataUtils.addAccount(cloudStorageOnedrive);
hasUpdatedDrawer = true;
} catch (CloudPluginException e) {
e.printStackTrace();
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.cloud_error_plugin);
mainActivity.deleteConnection(OpenMode.ONEDRIVE);
} else
cancel(true);
return false;
} catch (AuthenticationException e) {
e.printStackTrace();
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.cloud_fail_authenticate);
mainActivity.deleteConnection(OpenMode.ONEDRIVE);
} else
cancel(true);
return false;
} catch (Exception e) {
// any other exception due to network conditions or other error
e.printStackTrace();
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.failed_cloud_new_connection);
mainActivity.deleteConnection(OpenMode.ONEDRIVE);
} else
cancel(true);
return false;
}
break;
default:
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
Toast.makeText(mainActivity, R.string.cloud_error_failed_restart, Toast.LENGTH_LONG).show();
} else
cancel(true);
return false;
}
} while (data.moveToNext());
}
return hasUpdatedDrawer;
}
use of com.amaze.filemanager.ui.activities.MainActivity in project AmazeFileManager by TeamAmaze.
the class HiddenAdapter method onBindViewHolder.
@Override
// suppress varargs warnings
@SuppressWarnings("unchecked")
public void onBindViewHolder(HiddenViewHolder holder, int position) {
HybridFile file = hiddenFiles.get(position);
holder.textTitle.setText(file.getName(context));
holder.textDescription.setText(file.getReadablePath(file.getPath()));
if (hide) {
holder.deleteButton.setVisibility(View.GONE);
}
holder.deleteButton.setOnClickListener(view -> {
if (!file.isSmb() && file.isDirectory(context)) {
HybridFileParcelable nomediaFile = new HybridFileParcelable(hiddenFiles.get(position).getPath() + "/" + FileUtils.NOMEDIA_FILE);
nomediaFile.setMode(OpenMode.FILE);
ArrayList<HybridFileParcelable> filesToDelete = new ArrayList<>();
filesToDelete.add(nomediaFile);
DeleteTask task = new DeleteTask(context);
task.execute(filesToDelete);
}
dataUtils.removeHiddenFile(hiddenFiles.get(position).getPath());
hiddenFiles.remove(hiddenFiles.get(position));
notifyDataSetChanged();
});
holder.row.setOnClickListener(view -> {
// if the user taps on the hidden file, take the user there.
materialDialog.dismiss();
new Thread(() -> {
FragmentActivity fragmentActivity = mainFragment.getActivity();
if (fragmentActivity == null) {
// nullity check
return;
}
if (file.isDirectory(context)) {
fragmentActivity.runOnUiThread(() -> mainFragment.loadlist(file.getPath(), false, OpenMode.UNKNOWN));
} else if (!file.isSmb()) {
fragmentActivity.runOnUiThread(() -> FileUtils.openFile(new File(file.getPath()), (MainActivity) fragmentActivity, sharedPrefs));
} else {
Log.w(TAG, "User tapped on a directory but conditions not met; nothing is done.");
}
}).start();
});
}
use of com.amaze.filemanager.ui.activities.MainActivity in project AmazeFileManager by TeamAmaze.
the class MainActivityHelper method guideDialogForLEXA.
public void guideDialogForLEXA(String path, int requestCode) {
final MaterialDialog.Builder x = new MaterialDialog.Builder(mainActivity);
x.theme(mainActivity.getAppTheme().getMaterialDialogTheme());
x.title(R.string.needs_access);
LayoutInflater layoutInflater = (LayoutInflater) mainActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.lexadrawer, null);
x.customView(view, true);
// textView
TextView textView = view.findViewById(R.id.description);
textView.setText(mainActivity.getString(R.string.needs_access_summary) + path + mainActivity.getString(R.string.needs_access_summary1));
((ImageView) view.findViewById(R.id.icon)).setImageResource(R.drawable.sd_operate_step);
x.positiveText(R.string.open).negativeText(R.string.cancel).positiveColor(accentColor).negativeColor(accentColor).onPositive((dialog, which) -> triggerStorageAccessFramework(requestCode)).onNegative((dialog, which) -> Toast.makeText(mainActivity, R.string.error, Toast.LENGTH_SHORT).show());
final MaterialDialog y = x.build();
y.show();
}
use of com.amaze.filemanager.ui.activities.MainActivity in project AmazeFileManager by TeamAmaze.
the class SingletonUsbOtgTest method usbConnectionTest.
@Test
public void usbConnectionTest() {
ActivityController<MainActivity> controller = Robolectric.buildActivity(MainActivity.class).create();
addUsbOtgDevice(controller.get());
controller.resume().get();
Uri rootBefore = Uri.parse("ssh://testuser:testpassword@127.0.0.1:22222");
SingletonUsbOtg.getInstance().setUsbOtgRoot(rootBefore);
controller.pause().resume().get();
Uri rootAfter = SingletonUsbOtg.getInstance().getUsbOtgRoot();
assertEquals("Uris are different: (before:) " + rootBefore + " (after:) " + rootAfter, rootBefore, rootAfter);
}
Aggregations