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);
}
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();
}
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;
});
}
}
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;
});
}
Aggregations