introduce vdots for file select list, prepare GUI for editing of storage locations
This commit is contained in:
@@ -112,5 +112,6 @@ namespace keepass2android
|
||||
#if !NoNet
|
||||
ICertificateErrorHandler CertificateErrorHandler { get; }
|
||||
#endif
|
||||
bool CanEditIoc(IOConnectionInfo ioc);
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,28 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<TextView android:id="@+id/file_filename" xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#cccccc"
|
||||
android:paddingTop="4sp"
|
||||
android:paddingBottom="4sp"
|
||||
/>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/groupname_container"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<ImageView
|
||||
android:id="@+id/group_name_vdots"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="20dp"
|
||||
android:src="@drawable/vdots"
|
||||
android:gravity="right|bottom"
|
||||
android:layout_alignParentRight="true"
|
||||
android:paddingTop="4sp"/>
|
||||
|
||||
<TextView android:id="@+id/file_filename"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#cccccc"
|
||||
android:paddingTop="4sp"
|
||||
android:paddingBottom="4sp"
|
||||
android:layout_toLeftOf="@id/group_name_vdots"
|
||||
|
||||
/>
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -218,6 +218,7 @@
|
||||
<string name="remember_keyfile_summary">Remembers the location of key files</string>
|
||||
<string name="remember_keyfile_title">Save key file</string>
|
||||
<string name="remove_from_filelist">Remove</string>
|
||||
<string name="edit">Edit</string>
|
||||
<string name="rijndael">Rijndael (AES)</string>
|
||||
<string name="root">Root</string>
|
||||
|
||||
|
||||
@@ -611,9 +611,13 @@ namespace keepass2android
|
||||
{
|
||||
get { return new CertificateErrorHandlerImpl(this); }
|
||||
}
|
||||
public bool CanEditIoc(IOConnectionInfo ioc)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public class CertificateErrorHandlerImpl : Java.Lang.Object, Keepass2android.Javafilestorage.ICertificateErrorHandler
|
||||
public class CertificateErrorHandlerImpl : Java.Lang.Object, Keepass2android.Javafilestorage.ICertificateErrorHandler
|
||||
{
|
||||
private readonly Kp2aApp _app;
|
||||
|
||||
|
||||
@@ -200,35 +200,89 @@ namespace keepass2android
|
||||
outState.PutBoolean(BundleKeyRecentMode, _recentMode);
|
||||
|
||||
}
|
||||
|
||||
|
||||
class MyViewBinder: Java.Lang.Object, SimpleCursorAdapter.IViewBinder
|
||||
{
|
||||
private readonly Kp2aApp _app;
|
||||
|
||||
public MyViewBinder(Kp2aApp app)
|
||||
{
|
||||
_app = app;
|
||||
}
|
||||
class MyCursorAdapter: CursorAdapter
|
||||
{
|
||||
private LayoutInflater cursorInflater;
|
||||
private IKp2aApp _app;
|
||||
|
||||
public bool SetViewValue(View view, ICursor cursor, int columnIndex)
|
||||
{
|
||||
if (columnIndex == 1)
|
||||
{
|
||||
String path = cursor.GetString(columnIndex);
|
||||
TextView textView = (TextView)view;
|
||||
IOConnectionInfo ioc = new IOConnectionInfo {Path = path};
|
||||
var fileStorage = _app.GetFileStorage(ioc);
|
||||
textView.Text = fileStorage.GetDisplayName(ioc);
|
||||
textView.Tag = ioc.Path;
|
||||
return true;
|
||||
}
|
||||
public MyCursorAdapter(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
|
||||
{
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void FillData()
|
||||
public MyCursorAdapter(Context context, ICursor c, IKp2aApp app) : base(context, c)
|
||||
{
|
||||
_app = app;
|
||||
}
|
||||
|
||||
public MyCursorAdapter(Context context, ICursor c, bool autoRequery) : base(context, c, autoRequery)
|
||||
{
|
||||
}
|
||||
|
||||
public MyCursorAdapter(Context context, ICursor c, CursorAdapterFlags flags) : base(context, c, flags)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void BindView(View view, Context context, ICursor cursor)
|
||||
{
|
||||
String path = cursor.GetString(1);
|
||||
|
||||
TextView textView = view.FindViewById<TextView>(Resource.Id.file_filename);
|
||||
IOConnectionInfo ioc = new IOConnectionInfo { Path = path };
|
||||
var fileStorage = _app.GetFileStorage(ioc);
|
||||
textView.Text = fileStorage.GetDisplayName(ioc);
|
||||
textView.Tag = ioc.Path;
|
||||
|
||||
}
|
||||
|
||||
public override View NewView(Context context, ICursor cursor, ViewGroup parent)
|
||||
{
|
||||
if (cursorInflater == null)
|
||||
cursorInflater = (LayoutInflater)context.GetSystemService( Context.LayoutInflaterService);
|
||||
View view = cursorInflater.Inflate(Resource.Layout.file_row, parent, false);
|
||||
|
||||
view.FindViewById(Resource.Id.group_name_vdots).Click += (sender, args) =>
|
||||
{
|
||||
Handler handler = new Handler(Looper.MainLooper);
|
||||
handler.Post(() =>
|
||||
{
|
||||
PopupMenu popupMenu = new PopupMenu(context, view.FindViewById(Resource.Id.group_name_vdots));
|
||||
|
||||
AccessManager.PreparePopup(popupMenu);
|
||||
int remove = 0;
|
||||
int edit = 1;
|
||||
popupMenu.Menu.Add(0, remove, 0, context.GetString(Resource.String.remove_from_filelist)).SetIcon(Resource.Drawable.ic_menu_delete_grey);
|
||||
|
||||
TextView textView = view.FindViewById<TextView>(Resource.Id.file_filename);
|
||||
|
||||
String filename = (string)textView.Tag;
|
||||
IOConnectionInfo ioc = new IOConnectionInfo { Path = filename };
|
||||
if (_app.CanEditIoc(ioc))
|
||||
{
|
||||
popupMenu.Menu.Add(0, edit, 0, context.GetString(Resource.String.edit)).SetIcon(Resource.Drawable.ic_menu_edit_grey);
|
||||
}
|
||||
|
||||
|
||||
popupMenu.MenuItemClick += delegate (object sender2, PopupMenu.MenuItemClickEventArgs args2)
|
||||
{
|
||||
if (args2.Item.ItemId == remove)
|
||||
{
|
||||
App.Kp2a.FileDbHelper.DeleteFile(filename);
|
||||
|
||||
cursor.Requery();
|
||||
}
|
||||
};
|
||||
popupMenu.Show();
|
||||
});
|
||||
};
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void FillData()
|
||||
{
|
||||
// Get all of the rows from the database and create the item list
|
||||
ICursor filesCursor = _dbHelper.FetchAllFiles();
|
||||
@@ -241,15 +295,15 @@ namespace keepass2android
|
||||
// and an array of the fields we want to bind those fields to (in this
|
||||
// case just text1)
|
||||
int[] to = new[] { Resource.Id.file_filename };
|
||||
|
||||
/*
|
||||
// Now create a simple cursor adapter and set it to display
|
||||
SimpleCursorAdapter recentFilesAdapter = new SimpleCursorAdapter(this,
|
||||
Resource.Layout.file_row, filesCursor, from, to);
|
||||
|
||||
|
||||
recentFilesAdapter.ViewBinder = new MyViewBinder(App.Kp2a);
|
||||
|
||||
FragmentManager.FindFragmentById<RecentFilesFragment>(Resource.Id.recent_files).SetAdapter(recentFilesAdapter);
|
||||
*/
|
||||
FragmentManager.FindFragmentById<RecentFilesFragment>(Resource.Id.recent_files).SetAdapter(new MyCursorAdapter(this, filesCursor,App.Kp2a));
|
||||
|
||||
|
||||
}
|
||||
@@ -284,9 +338,9 @@ namespace keepass2android
|
||||
Finish();
|
||||
}
|
||||
|
||||
public void OnListItemClick(ListView l, View v, int position, long id) {
|
||||
|
||||
ICursor cursor = _dbHelper.FetchFile(id);
|
||||
public void OnListItemClick(ListView l, View v, int position, long id)
|
||||
{
|
||||
ICursor cursor = _dbHelper.FetchFile(id);
|
||||
StartManagingCursor(cursor);
|
||||
|
||||
IOConnectionInfo ioc = _dbHelper.CursorToIoc(cursor);
|
||||
@@ -462,30 +516,7 @@ namespace keepass2android
|
||||
cursor.Requery();
|
||||
}
|
||||
|
||||
public override void OnCreateContextMenu(IContextMenu menu, View v, IContextMenuContextMenuInfo menuInfo)
|
||||
{
|
||||
base.OnCreateContextMenu(menu, v, menuInfo);
|
||||
menu.Add(0, Menu.First, 0, Resource.String.remove_from_filelist);
|
||||
}
|
||||
|
||||
public override bool OnContextItemSelected(IMenuItem item)
|
||||
{
|
||||
if (item.ItemId == Menu.First)
|
||||
{
|
||||
AdapterView.AdapterContextMenuInfo acmi = (AdapterView.AdapterContextMenuInfo)item.MenuInfo;
|
||||
|
||||
TextView tv = (TextView)acmi.TargetView;
|
||||
String filename = (string)tv.Tag;
|
||||
App.Kp2a.FileDbHelper.DeleteFile(filename);
|
||||
|
||||
RefreshList();
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
return base.OnContextItemSelected(item);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user