mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
FileSelect as RecyclerView
This commit is contained in:
@@ -33,20 +33,14 @@ import android.os.Environment;
|
|||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.ContextMenu;
|
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.BaseAdapter;
|
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.keepassdroid.AssignMasterKeyDialog;
|
import com.keepassdroid.AssignMasterKeyDialog;
|
||||||
@@ -79,15 +73,14 @@ import java.net.URLDecoder;
|
|||||||
|
|
||||||
public class FileSelectActivity extends StylishActivity implements
|
public class FileSelectActivity extends StylishActivity implements
|
||||||
CreateFileDialog.DefinePathDialogListener ,
|
CreateFileDialog.DefinePathDialogListener ,
|
||||||
AssignMasterKeyDialog.AssignPasswordDialogListener {
|
AssignMasterKeyDialog.AssignPasswordDialogListener,
|
||||||
|
FileSelectViewHolder.FileSelectClearListener {
|
||||||
|
|
||||||
private static final String TAG = "FileSelectActivity";
|
private static final String TAG = "FileSelectActivity";
|
||||||
|
|
||||||
private static final int MY_PERMISSIONS_REQUEST_EXTERNAL_STORAGE = 111;
|
private static final int MY_PERMISSIONS_REQUEST_EXTERNAL_STORAGE = 111;
|
||||||
private ListView mList;
|
private RecyclerView mListFiles;
|
||||||
private BaseAdapter mAdapter;
|
private FileSelectAdapter mAdapter;
|
||||||
|
|
||||||
private static final int CMENU_CLEAR = Menu.FIRST;
|
|
||||||
|
|
||||||
public static final int FILE_BROWSE = 1;
|
public static final int FILE_BROWSE = 1;
|
||||||
public static final int GET_CONTENT = 2;
|
public static final int GET_CONTENT = 2;
|
||||||
@@ -119,15 +112,8 @@ public class FileSelectActivity extends StylishActivity implements
|
|||||||
toolbar.setTitle(getString(R.string.app_name));
|
toolbar.setTitle(getString(R.string.app_name));
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
mList = (ListView)findViewById(R.id.file_list);
|
mListFiles = (RecyclerView) findViewById(R.id.file_list);
|
||||||
|
mListFiles.setLayoutManager(new LinearLayoutManager(this));
|
||||||
mList.setOnItemClickListener(
|
|
||||||
new AdapterView.OnItemClickListener() {
|
|
||||||
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
|
|
||||||
onListItemClick((ListView)parent, v, position, id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Open button
|
// Open button
|
||||||
View openButton = findViewById(R.id.open_database);
|
View openButton = findViewById(R.id.open_database);
|
||||||
@@ -218,8 +204,6 @@ public class FileSelectActivity extends StylishActivity implements
|
|||||||
|
|
||||||
fillData();
|
fillData();
|
||||||
|
|
||||||
registerForContextMenu(mList);
|
|
||||||
|
|
||||||
// Load default database
|
// Load default database
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
String fileName = prefs.getString(PasswordActivity.KEY_DEFAULT_FILENAME, "");
|
String fileName = prefs.getString(PasswordActivity.KEY_DEFAULT_FILENAME, "");
|
||||||
@@ -396,12 +380,23 @@ public class FileSelectActivity extends StylishActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void fillData() {
|
private void fillData() {
|
||||||
mAdapter = new ArrayAdapter<>(FileSelectActivity.this, R.layout.file_row, R.id.file_filename, fileHistory.getDbList());
|
mAdapter = new FileSelectAdapter(FileSelectActivity.this, fileHistory.getDbList());
|
||||||
mList.setAdapter(mAdapter);
|
mAdapter.setOnItemClickListener(
|
||||||
|
new View.OnClickListener() {
|
||||||
|
public void onClick(View view) {
|
||||||
|
int itemPosition = mListFiles.getChildLayoutPosition(view);
|
||||||
|
new OpenFileHistoryAsyncTask(FileSelectActivity.this, fileHistory).execute(itemPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
mAdapter.setFileSelectClearListener(this);
|
||||||
|
mListFiles.setAdapter(mAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
@Override
|
||||||
new OpenFileHistoryAsyncTask(this, fileHistory).execute(position);
|
public boolean onFileSelectClearListener(String fileName) {
|
||||||
|
new DeleteFileHistoryAsyncTask(fileHistory, mAdapter).execute(fileName);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -535,30 +530,6 @@ public class FileSelectActivity extends StylishActivity implements
|
|||||||
&& super.onOptionsItemSelected(item);
|
&& super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreateContextMenu(ContextMenu menu, View v,
|
|
||||||
ContextMenuInfo menuInfo) {
|
|
||||||
super.onCreateContextMenu(menu, v, menuInfo);
|
|
||||||
|
|
||||||
menu.add(0, CMENU_CLEAR, 0, R.string.remove_from_filelist);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
|
||||||
super.onContextItemSelected(item);
|
|
||||||
|
|
||||||
if ( item.getItemId() == CMENU_CLEAR ) {
|
|
||||||
AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) item.getMenuInfo();
|
|
||||||
|
|
||||||
TextView tv = (TextView) acmi.targetView;
|
|
||||||
String filename = tv.getText().toString();
|
|
||||||
new DeleteFileHistoryAsyncTask(fileHistory, mAdapter).execute(filename);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class OpenFileHistoryAsyncTask extends AsyncTask<Integer, Void, Void> {
|
private static class OpenFileHistoryAsyncTask extends AsyncTask<Integer, Void, Void> {
|
||||||
|
|
||||||
private WeakReference<Activity> weakActivity;
|
private WeakReference<Activity> weakActivity;
|
||||||
@@ -596,9 +567,9 @@ public class FileSelectActivity extends StylishActivity implements
|
|||||||
private static class DeleteFileHistoryAsyncTask extends AsyncTask<String, Void, Void> {
|
private static class DeleteFileHistoryAsyncTask extends AsyncTask<String, Void, Void> {
|
||||||
|
|
||||||
private RecentFileHistory fileHistory;
|
private RecentFileHistory fileHistory;
|
||||||
private BaseAdapter adapter;
|
private FileSelectAdapter adapter;
|
||||||
|
|
||||||
DeleteFileHistoryAsyncTask(RecentFileHistory fileHistory, BaseAdapter adapter) {
|
DeleteFileHistoryAsyncTask(RecentFileHistory fileHistory, FileSelectAdapter adapter) {
|
||||||
this.fileHistory = fileHistory;
|
this.fileHistory = fileHistory;
|
||||||
this.adapter = adapter;
|
this.adapter = adapter;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 Jeremy Jamet / Kunzisoft.
|
||||||
|
*
|
||||||
|
* This file is part of KeePass DX.
|
||||||
|
*
|
||||||
|
* KeePass DX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* KeePass DX is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.keepassdroid.fileselect;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.R;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class FileSelectAdapter extends RecyclerView.Adapter<FileSelectViewHolder> {
|
||||||
|
|
||||||
|
private LayoutInflater inflater;
|
||||||
|
private List<String> listFiles;
|
||||||
|
private View.OnClickListener mOnClickListener;
|
||||||
|
private FileSelectViewHolder.FileSelectClearListener fileSelectClearListener;
|
||||||
|
|
||||||
|
public FileSelectAdapter(Context context, List<String> listFiles) {
|
||||||
|
inflater = LayoutInflater.from(context);
|
||||||
|
this.listFiles=listFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileSelectViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
View view = inflater.inflate(R.layout.file_row, parent, false);
|
||||||
|
view.setOnClickListener(mOnClickListener);
|
||||||
|
return new FileSelectViewHolder(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(FileSelectViewHolder holder, int position) {
|
||||||
|
holder.fileName.setText(listFiles.get(position));
|
||||||
|
holder.setFileSelectClearListener(fileSelectClearListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return listFiles.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnItemClickListener(View.OnClickListener onItemClickListener) {
|
||||||
|
this.mOnClickListener = onItemClickListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileSelectClearListener(FileSelectViewHolder.FileSelectClearListener fileSelectClearListener) {
|
||||||
|
this.fileSelectClearListener = fileSelectClearListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 Jeremy Jamet / Kunzisoft.
|
||||||
|
*
|
||||||
|
* This file is part of KeePass DX.
|
||||||
|
*
|
||||||
|
* KeePass DX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* KeePass DX is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.keepassdroid.fileselect;
|
||||||
|
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
|
public class FileSelectBeen {
|
||||||
|
|
||||||
|
private String fileName;
|
||||||
|
private Uri fileUri;
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileName(String fileName) {
|
||||||
|
this.fileName = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Uri getFileUri() {
|
||||||
|
return fileUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileUri(Uri fileUri) {
|
||||||
|
this.fileUri = fileUri;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 Jeremy Jamet / Kunzisoft.
|
||||||
|
*
|
||||||
|
* This file is part of KeePass DX.
|
||||||
|
*
|
||||||
|
* KeePass DX is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* KeePass DX is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.keepassdroid.fileselect;
|
||||||
|
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.ContextMenu;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.kunzisoft.keepass.R;
|
||||||
|
|
||||||
|
class FileSelectViewHolder extends RecyclerView.ViewHolder implements View.OnCreateContextMenuListener {
|
||||||
|
private static final int MENU_CLEAR = 1;
|
||||||
|
View fileContainer;
|
||||||
|
TextView fileName;
|
||||||
|
private FileSelectClearListener fileSelectClearListener;
|
||||||
|
|
||||||
|
FileSelectViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
fileContainer = itemView.findViewById(R.id.file_container);
|
||||||
|
fileContainer.setOnCreateContextMenuListener(this);
|
||||||
|
fileName = (TextView) itemView.findViewById(R.id.file_filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
|
||||||
|
MenuItem clearMenu = contextMenu.add(Menu.NONE, MENU_CLEAR, Menu.NONE, R.string.remove_from_filelist);
|
||||||
|
clearMenu.setOnMenuItemClickListener(mOnMyActionClickListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final MenuItem.OnMenuItemClickListener mOnMyActionClickListener = new MenuItem.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
if (item.getItemId() == MENU_CLEAR) {
|
||||||
|
String filename = fileName.getText().toString();
|
||||||
|
return fileSelectClearListener.onFileSelectClearListener(filename);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public void setFileSelectClearListener(FileSelectClearListener fileSelectClearListener) {
|
||||||
|
this.fileSelectClearListener = fileSelectClearListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface FileSelectClearListener {
|
||||||
|
boolean onFileSelectClearListener(String fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,11 +17,18 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
|
||||||
-->
|
-->
|
||||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/file_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?android:attr/selectableItemBackground">
|
||||||
|
<android.support.v7.widget.AppCompatTextView
|
||||||
android:id="@+id/file_filename"
|
android:id="@+id/file_filename"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingTop="8dp"
|
android:paddingTop="18dp"
|
||||||
android:paddingLeft="18dp"
|
android:paddingLeft="18dp"
|
||||||
android:paddingRight="18dp"
|
android:paddingRight="18dp"
|
||||||
android:paddingBottom="8dp" />
|
android:paddingBottom="18dp"
|
||||||
|
style="@style/KeepassDXStyle.TextAppearance.Default"/>
|
||||||
|
</RelativeLayout>
|
||||||
@@ -95,7 +95,7 @@
|
|||||||
style="@style/KeepassDXStyle.TextAppearance.Title"
|
style="@style/KeepassDXStyle.TextAppearance.Title"
|
||||||
android:text="@string/open_recent" />
|
android:text="@string/open_recent" />
|
||||||
|
|
||||||
<ListView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/file_list"
|
android:id="@+id/file_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|||||||
Reference in New Issue
Block a user