Search in sources :

Example 6 with OperationData

use of com.amaze.filemanager.database.models.OperationData in project AmazeFileManager by TeamAmaze.

the class MainActivity method onOptionsItemSelected.

// called when the user exits the action mode
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // ActionBarDrawerToggle will take care of this.
    if (drawer.onOptionsItemSelected(item))
        return true;
    // If they have handled the options, we don't need to.
    if (getFragmentAtFrame().onOptionsItemSelected(item))
        return true;
    // Handle action buttons
    executeWithMainFragment(mainFragment -> {
        switch(item.getItemId()) {
            case R.id.home:
                mainFragment.home();
                break;
            case R.id.history:
                GeneralDialogCreation.showHistoryDialog(dataUtils, getPrefs(), mainFragment, getAppTheme());
                break;
            case R.id.sethome:
                if (mainFragment.getMainFragmentViewModel().getOpenMode() != OpenMode.FILE && mainFragment.getMainFragmentViewModel().getOpenMode() != OpenMode.ROOT) {
                    Toast.makeText(mainActivity, R.string.not_allowed, Toast.LENGTH_SHORT).show();
                    break;
                }
                final MaterialDialog dialog = GeneralDialogCreation.showBasicDialog(mainActivity, R.string.question_set_path_as_home, R.string.set_as_home, R.string.yes, R.string.no);
                dialog.getActionButton(DialogAction.POSITIVE).setOnClickListener((v) -> {
                    mainFragment.getMainFragmentViewModel().setHome(mainFragment.getCurrentPath());
                    updatePaths(mainFragment.getMainFragmentViewModel().getNo());
                    dialog.dismiss();
                });
                dialog.show();
                break;
            case R.id.exit:
                finish();
                break;
            case R.id.sortby:
                GeneralDialogCreation.showSortDialog(mainFragment, getAppTheme(), getPrefs());
                break;
            case R.id.dsort:
                String[] sort = getResources().getStringArray(R.array.directorysortmode);
                MaterialDialog.Builder builder = new MaterialDialog.Builder(mainActivity);
                builder.theme(getAppTheme().getMaterialDialogTheme());
                builder.title(R.string.directorysort);
                int current = Integer.parseInt(getPrefs().getString(PreferencesConstants.PREFERENCE_DIRECTORY_SORT_MODE, "0"));
                builder.items(sort).itemsCallbackSingleChoice(current, (dialog1, view, which, text) -> {
                    getPrefs().edit().putString(PreferencesConstants.PREFERENCE_DIRECTORY_SORT_MODE, "" + which).commit();
                    mainFragment.getMainFragmentViewModel().initSortModes(SortHandler.getSortType(this, mainFragment.getMainFragmentViewModel().getCurrentPath()), getPrefs());
                    mainFragment.updateList();
                    dialog1.dismiss();
                    return true;
                });
                builder.build().show();
                break;
            case R.id.hiddenitems:
                GeneralDialogCreation.showHiddenDialog(dataUtils, getPrefs(), mainFragment, getAppTheme());
                break;
            case R.id.view:
                int pathLayout = dataUtils.getListOrGridForPath(mainFragment.getCurrentPath(), DataUtils.LIST);
                if (mainFragment.getMainFragmentViewModel().isList()) {
                    if (pathLayout == DataUtils.LIST) {
                        AppConfig.getInstance().runInBackground(() -> {
                            utilsHandler.removeFromDatabase(new OperationData(UtilsHandler.Operation.LIST, mainFragment.getCurrentPath()));
                        });
                    }
                    utilsHandler.saveToDatabase(new OperationData(UtilsHandler.Operation.GRID, mainFragment.getCurrentPath()));
                    dataUtils.setPathAsGridOrList(mainFragment.getCurrentPath(), DataUtils.GRID);
                } else {
                    if (pathLayout == DataUtils.GRID) {
                        AppConfig.getInstance().runInBackground(() -> {
                            utilsHandler.removeFromDatabase(new OperationData(UtilsHandler.Operation.GRID, mainFragment.getCurrentPath()));
                        });
                    }
                    utilsHandler.saveToDatabase(new OperationData(UtilsHandler.Operation.LIST, mainFragment.getCurrentPath()));
                    dataUtils.setPathAsGridOrList(mainFragment.getCurrentPath(), DataUtils.LIST);
                }
                mainFragment.switchView();
                break;
            case R.id.extract:
                Fragment fragment1 = getFragmentAtFrame();
                if (fragment1 instanceof CompressedExplorerFragment) {
                    mainActivityHelper.extractFile(((CompressedExplorerFragment) fragment1).compressedFile);
                }
                break;
            case R.id.search:
                getAppbar().getSearchView().revealSearchView();
                break;
        }
        return null;
    }, false);
    return super.onOptionsItemSelected(item);
}
Also used : OperationData(com.amaze.filemanager.database.models.OperationData) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) CompressedExplorerFragment(com.amaze.filemanager.ui.fragments.CompressedExplorerFragment) Fragment(androidx.fragment.app.Fragment) CompressedExplorerFragment(com.amaze.filemanager.ui.fragments.CompressedExplorerFragment) CloudSheetFragment(com.amaze.filemanager.ui.fragments.CloudSheetFragment) SearchWorkerFragment(com.amaze.filemanager.ui.fragments.SearchWorkerFragment) TabFragment(com.amaze.filemanager.ui.fragments.TabFragment) FtpServerFragment(com.amaze.filemanager.ui.fragments.FtpServerFragment) MainFragment(com.amaze.filemanager.ui.fragments.MainFragment) ProcessViewerFragment(com.amaze.filemanager.ui.fragments.ProcessViewerFragment) AppsListFragment(com.amaze.filemanager.ui.fragments.AppsListFragment) BottomSheetDialogFragment(com.google.android.material.bottomsheet.BottomSheetDialogFragment)

Example 7 with OperationData

use of com.amaze.filemanager.database.models.OperationData in project AmazeFileManager by TeamAmaze.

the class MainActivity method delete.

@Override
public void delete(String title, String path) {
    utilsHandler.removeFromDatabase(new OperationData(UtilsHandler.Operation.BOOKMARKS, title, path));
    drawer.refreshDrawer();
}
Also used : OperationData(com.amaze.filemanager.database.models.OperationData)

Example 8 with OperationData

use of com.amaze.filemanager.database.models.OperationData in project AmazeFileManager by TeamAmaze.

the class UtilsHandlerTest method testRepeatedSaveBookmarkShouldNeverThrowException.

@Test
public void testRepeatedSaveBookmarkShouldNeverThrowException() {
    OperationData operationData = new OperationData(UtilsHandler.Operation.BOOKMARKS, "My Documents", new File(Environment.getExternalStorageDirectory(), "My Documents").getAbsolutePath());
    utilsHandler.addCommonBookmarks();
    await().atMost(10, TimeUnit.SECONDS).until(() -> {
        List<String[]> verify = utilsHandler.getBookmarksList();
        assertEquals(5, verify.size());
        return true;
    });
    for (int i = 0; i < 5; i++) {
        utilsHandler.saveToDatabase(operationData);
        await().atMost(10, TimeUnit.SECONDS).until(() -> {
            List<String[]> verify = utilsHandler.getBookmarksList();
            assertEquals(6, verify.size());
            return true;
        });
    }
}
Also used : OperationData(com.amaze.filemanager.database.models.OperationData) File(java.io.File) Test(org.junit.Test)

Example 9 with OperationData

use of com.amaze.filemanager.database.models.OperationData in project AmazeFileManager by TeamAmaze.

the class ShadowCryptUtilTest method testWithUtilsHandler.

@Test
public void testWithUtilsHandler() {
    UtilitiesDatabase utilitiesDatabase = UtilitiesDatabase.initialize(ApplicationProvider.getApplicationContext());
    UtilsHandler utilsHandler = new UtilsHandler(ApplicationProvider.getApplicationContext(), utilitiesDatabase);
    String fingerprint = "00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff";
    String url = "ssh://test:test@127.0.0.1:22";
    utilsHandler.saveToDatabase(new OperationData(UtilsHandler.Operation.SFTP, SshClientUtils.encryptSshPathAsNecessary(url), "Test", fingerprint, null, null));
    await().atMost(10, TimeUnit.SECONDS).until(() -> {
        assertEquals(fingerprint, utilsHandler.getSshHostKey(SshClientUtils.encryptSshPathAsNecessary(url)));
        utilitiesDatabase.close();
        return true;
    });
}
Also used : OperationData(com.amaze.filemanager.database.models.OperationData) UtilitiesDatabase(com.amaze.filemanager.database.UtilitiesDatabase) UtilsHandler(com.amaze.filemanager.database.UtilsHandler) Test(org.junit.Test)

Aggregations

OperationData (com.amaze.filemanager.database.models.OperationData)9 UtilsHandler (com.amaze.filemanager.database.UtilsHandler)2 File (java.io.File)2 Test (org.junit.Test)2 Fragment (androidx.fragment.app.Fragment)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 UtilitiesDatabase (com.amaze.filemanager.database.UtilitiesDatabase)1 AppsListFragment (com.amaze.filemanager.ui.fragments.AppsListFragment)1 CloudSheetFragment (com.amaze.filemanager.ui.fragments.CloudSheetFragment)1 CompressedExplorerFragment (com.amaze.filemanager.ui.fragments.CompressedExplorerFragment)1 FtpServerFragment (com.amaze.filemanager.ui.fragments.FtpServerFragment)1 MainFragment (com.amaze.filemanager.ui.fragments.MainFragment)1 ProcessViewerFragment (com.amaze.filemanager.ui.fragments.ProcessViewerFragment)1 SearchWorkerFragment (com.amaze.filemanager.ui.fragments.SearchWorkerFragment)1 TabFragment (com.amaze.filemanager.ui.fragments.TabFragment)1 BookSorter (com.amaze.filemanager.utils.BookSorter)1 BottomSheetDialogFragment (com.google.android.material.bottomsheet.BottomSheetDialogFragment)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 JcaPEMWriter (org.bouncycastle.openssl.jcajce.JcaPEMWriter)1