Search in sources :

Example 1 with FileNameView

use of com.keepassdroid.view.FileNameView in project KeePassDX by Kunzisoft.

the class FileSelectActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        if (AutofillHelper.isIntentContainsExtraAssistStructureKey(getIntent()))
            consultationMode = true;
    }
    fileHistory = App.getFileHistory();
    setContentView(R.layout.file_selection);
    fileListTitle = findViewById(R.id.file_list_title);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.app_name));
    setSupportActionBar(toolbar);
    openFileNameView = (EditText) findViewById(R.id.file_filename);
    fileNameView = (FileNameView) findViewById(R.id.file_select);
    // Set the initial value of the filename
    defaultPath = Environment.getExternalStorageDirectory().getAbsolutePath() + getString(R.string.database_file_path_default) + getString(R.string.database_file_name_default) + getString(R.string.database_file_extension_default);
    openFileNameView.setHint(defaultPath);
    RecyclerView mListFiles = (RecyclerView) findViewById(R.id.file_list);
    mListFiles.setLayoutManager(new LinearLayoutManager(this));
    // To retrieve info for AutoFill
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        autofillHelper = new AutofillHelper();
        autofillHelper.retrieveAssistStructure(getIntent());
    }
    // Open button
    View openButton = findViewById(R.id.open_database);
    openButton.setOnClickListener(v -> {
        String fileName = openFileNameView.getText().toString();
        if (fileName.isEmpty())
            fileName = defaultPath;
        launchPasswordActivityWithPath(fileName);
    });
    // Create button
    View createButton = findViewById(R.id.create_database);
    createButton.setOnClickListener(v -> FileSelectActivityPermissionsDispatcher.openCreateFileDialogFragmentWithPermissionCheck(FileSelectActivity.this));
    keyFileHelper = new KeyFileHelper(this);
    View browseButton = findViewById(R.id.browse_button);
    browseButton.setOnClickListener(keyFileHelper.getOpenFileOnClickViewListener(() -> Uri.parse("file://" + openFileNameView.getText().toString())));
    // Construct adapter with listeners
    mAdapter = new FileSelectAdapter(FileSelectActivity.this, fileHistory.getDbList());
    mAdapter.setOnItemClickListener(this);
    mAdapter.setFileSelectClearListener(this);
    mAdapter.setFileInformationShowListener(this);
    mListFiles.setAdapter(mAdapter);
    // Load default database if not an orientation change
    if (!(savedInstanceState != null && savedInstanceState.containsKey(EXTRA_STAY) && savedInstanceState.getBoolean(EXTRA_STAY, false))) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        String fileName = prefs.getString(PasswordActivity.KEY_DEFAULT_FILENAME, "");
        if (fileName.length() > 0) {
            Uri dbUri = UriUtil.parseDefaultFile(fileName);
            String scheme = null;
            if (dbUri != null)
                scheme = dbUri.getScheme();
            if (!EmptyUtils.isNullOrEmpty(scheme) && scheme.equalsIgnoreCase("file")) {
                String path = dbUri.getPath();
                File db = new File(path);
                if (db.exists()) {
                    launchPasswordActivityWithPath(path);
                }
            } else {
                if (dbUri != null)
                    launchPasswordActivityWithPath(dbUri.toString());
            }
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) FileNameView(com.keepassdroid.view.FileNameView) RecyclerView(android.support.v7.widget.RecyclerView) Uri(android.net.Uri) File(java.io.File) AutofillHelper(com.keepassdroid.autofill.AutofillHelper) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

SharedPreferences (android.content.SharedPreferences)1 Uri (android.net.Uri)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 AutofillHelper (com.keepassdroid.autofill.AutofillHelper)1 FileNameView (com.keepassdroid.view.FileNameView)1 File (java.io.File)1