Search in sources :

Example 16 with MainActivity

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);
    }
}
Also used : MainActivity(com.amaze.filemanager.ui.activities.MainActivity)

Example 17 with MainActivity

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;
}
Also used : CloudStorage(com.cloudrail.si.interfaces.CloudStorage) CloudPluginException(com.amaze.filemanager.file_operations.exceptions.CloudPluginException) OneDrive(com.cloudrail.si.services.OneDrive) AuthenticationException(com.cloudrail.si.exceptions.AuthenticationException) GoogleDrive(com.cloudrail.si.services.GoogleDrive) CloudEntry(com.amaze.filemanager.database.models.explorer.CloudEntry) Box(com.cloudrail.si.services.Box) MainActivity(com.amaze.filemanager.ui.activities.MainActivity) ParseException(com.cloudrail.si.exceptions.ParseException) Dropbox(com.cloudrail.si.services.Dropbox) AuthenticationException(com.cloudrail.si.exceptions.AuthenticationException) CloudPluginException(com.amaze.filemanager.file_operations.exceptions.CloudPluginException) ParseException(com.cloudrail.si.exceptions.ParseException) NonNull(androidx.annotation.NonNull)

Example 18 with MainActivity

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();
    });
}
Also used : HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) HybridFile(com.amaze.filemanager.filesystem.HybridFile) FragmentActivity(androidx.fragment.app.FragmentActivity) ArrayList(java.util.ArrayList) MainActivity(com.amaze.filemanager.ui.activities.MainActivity) HybridFile(com.amaze.filemanager.filesystem.HybridFile) File(java.io.File) DeleteTask(com.amaze.filemanager.asynchronous.asynctasks.DeleteTask)

Example 19 with MainActivity

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();
}
Also used : SpeedDialView(com.leinardi.android.speeddial.SpeedDialView) Bundle(android.os.Bundle) Operations(com.amaze.filemanager.filesystem.Operations) EncryptedEntry(com.amaze.filemanager.database.models.explorer.EncryptedEntry) ImageView(android.widget.ImageView) MainFragment(com.amaze.filemanager.ui.fragments.MainFragment) FileProperties(com.amaze.filemanager.filesystem.FileProperties) MainActivity(com.amaze.filemanager.ui.activities.MainActivity) CompressedHelper(com.amaze.filemanager.filesystem.compressed.CompressedHelper) CryptHandler(com.amaze.filemanager.database.CryptHandler) Fragment(androidx.fragment.app.Fragment) View(android.view.View) FolderState(com.amaze.filemanager.file_operations.filesystem.FolderState) Log(android.util.Log) GeneralDialogCreation(com.amaze.filemanager.ui.dialogs.GeneralDialogCreation) AsyncTask(android.os.AsyncTask) RENAME(com.amaze.filemanager.file_operations.filesystem.OperationTypeKt.RENAME) DOESNT_EXIST(com.amaze.filemanager.file_operations.filesystem.FolderStateKt.DOESNT_EXIST) FileUtils(com.amaze.filemanager.filesystem.files.FileUtils) BroadcastReceiver(android.content.BroadcastReceiver) NEW_FILE(com.amaze.filemanager.file_operations.filesystem.OperationTypeKt.NEW_FILE) StringRes(androidx.annotation.StringRes) TextView(android.widget.TextView) DocumentFile(androidx.documentfile.provider.DocumentFile) DELETE(com.amaze.filemanager.file_operations.filesystem.OperationTypeKt.DELETE) CloudHandler(com.amaze.filemanager.database.CloudHandler) CAN_CREATE_FILES(com.amaze.filemanager.file_operations.filesystem.FolderStateKt.CAN_CREATE_FILES) R(com.amaze.filemanager.R) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) AppConfig(com.amaze.filemanager.application.AppConfig) ServiceWatcherUtil(com.amaze.filemanager.asynchronous.management.ServiceWatcherUtil) Context(android.content.Context) HybridFile(com.amaze.filemanager.filesystem.HybridFile) COMPRESS(com.amaze.filemanager.file_operations.filesystem.OperationTypeKt.COMPRESS) Intent(android.content.Intent) OpenMode(com.amaze.filemanager.file_operations.filesystem.OpenMode) ArrayList(java.util.ArrayList) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) SshClientUtils(com.amaze.filemanager.filesystem.ssh.SshClientUtils) PreferencesConstants(com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants) SearchWorkerFragment(com.amaze.filemanager.ui.fragments.SearchWorkerFragment) Toast(android.widget.Toast) Build(android.os.Build) ZipService(com.amaze.filemanager.asynchronous.services.ZipService) TabFragment(com.amaze.filemanager.ui.fragments.TabFragment) DeleteTask(com.amaze.filemanager.asynchronous.asynctasks.DeleteTask) FragmentManager(androidx.fragment.app.FragmentManager) WRITABLE_OR_ON_SDCARD(com.amaze.filemanager.file_operations.filesystem.FolderStateKt.WRITABLE_OR_ON_SDCARD) ExternalSdCardOperation(com.amaze.filemanager.filesystem.ExternalSdCardOperation) LayoutInflater(android.view.LayoutInflater) NEW_FOLDER(com.amaze.filemanager.file_operations.filesystem.OperationTypeKt.NEW_FOLDER) SafRootHolder(com.amaze.filemanager.filesystem.SafRootHolder) WarnableTextInputValidator(com.amaze.filemanager.ui.views.WarnableTextInputValidator) File(java.io.File) EXTRACT(com.amaze.filemanager.file_operations.filesystem.OperationTypeKt.EXTRACT) SharedPreferences(android.content.SharedPreferences) CryptUtil(com.amaze.filemanager.filesystem.files.CryptUtil) PreferenceManager(androidx.preference.PreferenceManager) Activity(android.app.Activity) EditText(android.widget.EditText) Decompressor(com.amaze.filemanager.filesystem.compressed.showcontents.Decompressor) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) SpeedDialView(com.leinardi.android.speeddial.SpeedDialView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 20 with MainActivity

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);
}
Also used : MainActivity(com.amaze.filemanager.ui.activities.MainActivity) Uri(android.net.Uri) Test(org.junit.Test)

Aggregations

MainActivity (com.amaze.filemanager.ui.activities.MainActivity)20 HybridFile (com.amaze.filemanager.filesystem.HybridFile)9 ArrayList (java.util.ArrayList)9 View (android.view.View)8 NonNull (androidx.annotation.NonNull)8 R (com.amaze.filemanager.R)8 Intent (android.content.Intent)7 SharedPreferences (android.content.SharedPreferences)7 Log (android.util.Log)7 TextView (android.widget.TextView)7 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)7 OpenMode (com.amaze.filemanager.file_operations.filesystem.OpenMode)7 FileUtils (com.amaze.filemanager.filesystem.files.FileUtils)7 MainFragment (com.amaze.filemanager.ui.fragments.MainFragment)7 Utils (com.amaze.filemanager.utils.Utils)7 File (java.io.File)7 Objects (java.util.Objects)7 Context (android.content.Context)6 Color (android.graphics.Color)6 Uri (android.net.Uri)6