2013-02-23 11:43:42 -05:00
|
|
|
/*
|
|
|
|
This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file is based on Keepassdroid, Copyright Brian Pellin.
|
|
|
|
|
|
|
|
Keepass2Android 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.
|
|
|
|
|
|
|
|
Keepass2Android 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 Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using Android.App;
|
|
|
|
using Android.Content;
|
|
|
|
using Android.OS;
|
|
|
|
using Android.Runtime;
|
|
|
|
using Android.Views;
|
|
|
|
using Android.Widget;
|
|
|
|
using KeePassLib;
|
|
|
|
using Android.Preferences;
|
2013-08-28 08:00:54 -04:00
|
|
|
using KeePassLib.Interfaces;
|
|
|
|
using KeePassLib.Utility;
|
2013-08-14 00:05:25 -04:00
|
|
|
using keepass2android.Io;
|
2013-08-28 08:00:54 -04:00
|
|
|
using keepass2android.database.edit;
|
2013-02-23 11:43:42 -05:00
|
|
|
using keepass2android.view;
|
2013-04-12 23:28:15 -04:00
|
|
|
using Android.Graphics.Drawables;
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
namespace keepass2android
|
|
|
|
{
|
|
|
|
|
|
|
|
public abstract class GroupBaseActivity : LockCloseListActivity {
|
2013-06-15 06:40:01 -04:00
|
|
|
public const String KeyEntry = "entry";
|
|
|
|
public const String KeyMode = "mode";
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
public virtual void LaunchActivityForEntry(PwEntry pwEntry, int pos)
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2013-06-15 06:40:01 -04:00
|
|
|
EntryActivity.Launch(this, pwEntry, pos, AppTask);
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
2013-06-15 06:40:01 -04:00
|
|
|
|
|
|
|
protected GroupBaseActivity ()
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
protected GroupBaseActivity (IntPtr javaReference, JniHandleOwnership transfer)
|
2013-02-23 11:43:42 -05:00
|
|
|
: base(javaReference, transfer)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2013-05-30 00:54:25 -04:00
|
|
|
|
|
|
|
protected override void OnSaveInstanceState(Bundle outState)
|
|
|
|
{
|
|
|
|
base.OnSaveInstanceState(outState);
|
2013-06-15 06:40:01 -04:00
|
|
|
AppTask.ToBundle(outState);
|
2013-05-30 00:54:25 -04:00
|
|
|
}
|
2013-06-01 09:51:54 -04:00
|
|
|
|
2013-08-28 08:00:54 -04:00
|
|
|
public virtual void SetupNormalButtons()
|
|
|
|
{
|
|
|
|
GroupView.SetNormalButtonVisibility(true, true);
|
|
|
|
}
|
2013-06-01 09:51:54 -04:00
|
|
|
|
|
|
|
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
|
|
|
|
{
|
|
|
|
base.OnActivityResult(requestCode, resultCode, data);
|
|
|
|
|
2013-08-28 08:00:54 -04:00
|
|
|
AppTask.TryGetFromActivityResult(data, ref AppTask);
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
if (resultCode == KeePass.ExitCloseAfterTaskComplete)
|
2013-06-01 09:51:54 -04:00
|
|
|
{
|
2013-08-28 08:00:54 -04:00
|
|
|
AppTask.SetActivityResult(this, KeePass.ExitCloseAfterTaskComplete);
|
2013-06-01 09:51:54 -04:00
|
|
|
Finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
private ISharedPreferences _prefs;
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
protected PwGroup Group;
|
2013-05-30 00:54:25 -04:00
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
internal AppTask AppTask;
|
2013-08-28 08:00:54 -04:00
|
|
|
protected GroupView GroupView;
|
2013-08-16 08:26:06 -04:00
|
|
|
|
2013-02-23 11:43:42 -05:00
|
|
|
protected override void OnResume() {
|
|
|
|
base.OnResume();
|
2013-08-28 08:00:54 -04:00
|
|
|
|
|
|
|
AppTask.SetupGroupBaseActivityButtons(this);
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
RefreshIfDirty();
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public override bool OnSearchRequested()
|
|
|
|
{
|
|
|
|
StartActivityForResult(typeof(SearchActivity), 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
public void RefreshIfDirty() {
|
2013-06-14 00:14:50 -04:00
|
|
|
Database db = App.Kp2a.GetDb();
|
2013-06-15 06:40:01 -04:00
|
|
|
if ( db.Dirty.Contains(Group) ) {
|
|
|
|
db.Dirty.Remove(Group);
|
2013-02-23 11:43:42 -05:00
|
|
|
BaseAdapter adapter = (BaseAdapter) ListAdapter;
|
|
|
|
adapter.NotifyDataSetChanged();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnListItemClick(ListView l, View v, int position, long id) {
|
|
|
|
base.OnListItemClick(l, v, position, id);
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
IListAdapter adapt = ListAdapter;
|
2013-02-23 11:43:42 -05:00
|
|
|
ClickView cv = (ClickView) adapt.GetView(position, null, null);
|
|
|
|
cv.OnClick();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnCreate(Bundle savedInstanceState) {
|
|
|
|
base.OnCreate(savedInstanceState);
|
2013-05-30 00:54:25 -04:00
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
AppTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent);
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
// Likely the app has been killed exit the activity
|
2013-06-14 00:14:50 -04:00
|
|
|
if ( ! App.Kp2a.GetDb().Loaded ) {
|
2013-02-23 11:43:42 -05:00
|
|
|
Finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
_prefs = PreferenceManager.GetDefaultSharedPreferences(this);
|
2013-08-16 08:26:06 -04:00
|
|
|
|
2013-08-28 08:00:54 -04:00
|
|
|
GroupView = new GroupView(this);
|
|
|
|
SetContentView(GroupView);
|
|
|
|
|
|
|
|
FindViewById(Resource.Id.cancel_insert_element).Click += (sender, args) => StopMovingElement();
|
|
|
|
FindViewById(Resource.Id.insert_element).Click += (sender, args) => InsertElement();
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
SetResult(KeePass.ExitNormal);
|
2013-02-23 11:43:42 -05:00
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
StyleScrollBars();
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
}
|
2013-08-28 08:00:54 -04:00
|
|
|
|
|
|
|
protected override void OnStart()
|
|
|
|
{
|
|
|
|
base.OnStart();
|
|
|
|
AppTask.StartInGroupActivity(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void InsertElement()
|
|
|
|
{
|
|
|
|
MoveElementTask moveElementTask = (MoveElementTask)AppTask;
|
|
|
|
IStructureItem elementToMove = App.Kp2a.GetDb().KpDatabase.RootGroup.FindObject(moveElementTask.Uuid, true, null);
|
|
|
|
|
|
|
|
|
2013-08-30 16:58:29 -04:00
|
|
|
var moveElement = new MoveElement(elementToMove, Group, this, App.Kp2a, new ActionOnFinish((success, message) => { StopMovingElement(); if (!String.IsNullOrEmpty(message)) Toast.MakeText(this, message, ToastLength.Long).Show();}));
|
2013-08-28 08:00:54 -04:00
|
|
|
var progressTask = new ProgressTask(App.Kp2a, this, moveElement);
|
|
|
|
progressTask.Run();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
protected void StyleScrollBars() {
|
2013-02-23 11:43:42 -05:00
|
|
|
ListView lv = ListView;
|
|
|
|
lv.ScrollBarStyle =ScrollbarStyles.InsideInset;
|
|
|
|
lv.TextFilterEnabled = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
protected void SetGroupTitle()
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2013-06-15 06:40:01 -04:00
|
|
|
String name = Group.Name;
|
2013-04-12 23:28:15 -04:00
|
|
|
String titleText;
|
2013-06-15 06:40:01 -04:00
|
|
|
bool clickable = (Group != null) && (Group.IsVirtual == false) && (Group.ParentGroup != null);
|
2013-04-12 23:28:15 -04:00
|
|
|
if (!String.IsNullOrEmpty(name))
|
|
|
|
{
|
|
|
|
titleText = name;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
titleText = GetText(Resource.String.root);
|
|
|
|
}
|
|
|
|
|
|
|
|
//see if the button for SDK Version < 11 is there
|
2013-02-23 11:43:42 -05:00
|
|
|
Button tv = (Button)FindViewById(Resource.Id.group_name);
|
2013-04-12 23:28:15 -04:00
|
|
|
if (tv != null)
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2013-06-15 06:40:01 -04:00
|
|
|
if (Group != null)
|
2013-04-12 23:28:15 -04:00
|
|
|
{
|
|
|
|
tv.Text = titleText;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clickable)
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2013-06-15 06:40:01 -04:00
|
|
|
tv.Click += (sender, e) =>
|
2013-04-12 23:28:15 -04:00
|
|
|
{
|
|
|
|
Finish();
|
|
|
|
};
|
2013-02-23 11:43:42 -05:00
|
|
|
} else
|
|
|
|
{
|
2013-04-12 23:28:15 -04:00
|
|
|
tv.SetCompoundDrawables(null, null, null, null);
|
|
|
|
tv.Clickable = false;
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
}
|
2013-04-12 23:28:15 -04:00
|
|
|
//ICS?
|
2013-04-28 16:46:31 -04:00
|
|
|
if (Util.HasActionBar(this))
|
2013-02-23 11:43:42 -05:00
|
|
|
{
|
2013-04-12 23:28:15 -04:00
|
|
|
ActionBar.Title = titleText;
|
|
|
|
if (clickable)
|
|
|
|
ActionBar.SetDisplayHomeAsUpEnabled(true);
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
protected void SetGroupIcon() {
|
|
|
|
if (Group != null) {
|
|
|
|
Drawable drawable = App.Kp2a.GetDb().DrawableFactory.GetIconDrawable(Resources, App.Kp2a.GetDb().KpDatabase, Group.IconId, Group.CustomIconUuid);
|
2013-02-23 11:43:42 -05:00
|
|
|
ImageView iv = (ImageView) FindViewById(Resource.Id.icon);
|
2013-04-12 23:28:15 -04:00
|
|
|
if (iv != null)
|
|
|
|
iv.SetImageDrawable(drawable);
|
2013-04-28 16:46:31 -04:00
|
|
|
if (Util.HasActionBar(this))
|
2013-04-12 23:28:15 -04:00
|
|
|
ActionBar.SetIcon(drawable);
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool OnCreateOptionsMenu(IMenu menu) {
|
|
|
|
base.OnCreateOptionsMenu(menu);
|
|
|
|
|
|
|
|
MenuInflater inflater = MenuInflater;
|
|
|
|
inflater.Inflate(Resource.Menu.group, menu);
|
2013-07-21 15:47:20 -04:00
|
|
|
if (Util.HasActionBar(this))
|
|
|
|
{
|
|
|
|
var searchManager = (SearchManager) GetSystemService(Context.SearchService);
|
|
|
|
var searchView = (SearchView) menu.FindItem(Resource.Id.menu_search).ActionView;
|
2013-06-19 13:44:35 -04:00
|
|
|
|
2013-07-21 15:47:20 -04:00
|
|
|
searchView.SetSearchableInfo(searchManager.GetSearchableInfo(ComponentName));
|
|
|
|
}
|
2013-08-14 00:05:25 -04:00
|
|
|
var item = menu.FindItem(Resource.Id.menu_sync);
|
|
|
|
if (item != null)
|
|
|
|
{
|
|
|
|
if (App.Kp2a.GetDb().Ioc.IsLocalFile())
|
|
|
|
item.SetVisible(false);
|
|
|
|
else
|
|
|
|
item.SetVisible(true);
|
|
|
|
}
|
2013-02-23 11:43:42 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
private void SetSortMenuText(IMenu menu) {
|
|
|
|
bool sortByName = _prefs.GetBoolean(GetString(Resource.String.sort_key), Resources.GetBoolean(Resource.Boolean.sort_default));
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
int resId;
|
|
|
|
if ( sortByName ) {
|
|
|
|
resId = Resource.String.sort_db;
|
|
|
|
} else {
|
|
|
|
resId = Resource.String.sort_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
menu.FindItem(Resource.Id.menu_sort).SetTitle(resId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool OnPrepareOptionsMenu(IMenu menu) {
|
|
|
|
if ( ! base.OnPrepareOptionsMenu(menu) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
SetSortMenuText(menu);
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool OnOptionsItemSelected(IMenuItem item) {
|
|
|
|
switch ( item.ItemId ) {
|
2013-04-06 14:26:16 -04:00
|
|
|
case Resource.Id.menu_donate:
|
2013-02-23 11:43:42 -05:00
|
|
|
try {
|
2013-04-09 16:59:33 -04:00
|
|
|
Util.gotoDonateUrl(this);
|
2013-02-23 11:43:42 -05:00
|
|
|
} catch (ActivityNotFoundException) {
|
|
|
|
Toast.MakeText(this, Resource.String.error_failed_to_launch_link, ToastLength.Long).Show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-06 14:26:16 -04:00
|
|
|
return true;
|
2013-02-23 11:43:42 -05:00
|
|
|
case Resource.Id.menu_lock:
|
2013-07-25 08:47:05 -04:00
|
|
|
App.Kp2a.LockDatabase();
|
2013-02-23 11:43:42 -05:00
|
|
|
return true;
|
2013-06-19 13:44:35 -04:00
|
|
|
|
2013-02-23 11:43:42 -05:00
|
|
|
case Resource.Id.menu_search:
|
2013-06-19 13:44:35 -04:00
|
|
|
case Resource.Id.menu_search_advanced:
|
2013-02-23 11:43:42 -05:00
|
|
|
OnSearchRequested();
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case Resource.Id.menu_app_settings:
|
2013-07-26 15:10:03 -04:00
|
|
|
DatabaseSettingsActivity.Launch(this);
|
2013-02-23 11:43:42 -05:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case Resource.Id.menu_change_master_key:
|
2013-06-15 06:40:01 -04:00
|
|
|
SetPassword();
|
2013-02-23 11:43:42 -05:00
|
|
|
return true;
|
2013-08-14 00:05:25 -04:00
|
|
|
|
|
|
|
case Resource.Id.menu_sync:
|
|
|
|
Synchronize();
|
|
|
|
return true;
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
case Resource.Id.menu_sort:
|
2013-06-15 06:40:01 -04:00
|
|
|
ToggleSort();
|
2013-02-23 11:43:42 -05:00
|
|
|
return true;
|
2013-03-23 16:19:37 -04:00
|
|
|
case Resource.Id.menu_rate:
|
|
|
|
try {
|
|
|
|
Util.gotoMarket(this);
|
|
|
|
} catch (ActivityNotFoundException) {
|
|
|
|
Toast.MakeText(this, Resource.String.no_url_handler, ToastLength.Long).Show();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case Resource.Id.menu_suggest_improvements:
|
|
|
|
try {
|
|
|
|
Util.gotoUrl(this, Resource.String.SuggestionsURL);
|
|
|
|
} catch (ActivityNotFoundException) {
|
|
|
|
Toast.MakeText(this, Resource.String.no_url_handler, ToastLength.Long).Show();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case Resource.Id.menu_translate:
|
|
|
|
try {
|
|
|
|
Util.gotoUrl(this, Resource.String.TranslationURL);
|
|
|
|
} catch (ActivityNotFoundException) {
|
|
|
|
Toast.MakeText(this, Resource.String.no_url_handler, ToastLength.Long).Show();
|
|
|
|
}
|
|
|
|
return true;
|
2013-04-12 23:28:15 -04:00
|
|
|
case Android.Resource.Id.Home:
|
|
|
|
//Currently the action bar only displays the home button when we come from a previous activity.
|
|
|
|
//So we can simply Finish. See this page for information on how to do this in more general (future?) cases:
|
|
|
|
//http://developer.android.com/training/implementing-navigation/ancestral.html
|
2013-08-28 08:00:54 -04:00
|
|
|
AppTask.SetActivityResult(this, KeePass.ExitNormal);
|
2013-04-12 23:28:15 -04:00
|
|
|
Finish();
|
2013-05-17 00:53:58 -04:00
|
|
|
OverridePendingTransition(Resource.Animation.anim_enter_back, Resource.Animation.anim_leave_back);
|
|
|
|
|
2013-04-12 23:28:15 -04:00
|
|
|
return true;
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return base.OnOptionsItemSelected(item);
|
|
|
|
}
|
2013-08-14 00:05:25 -04:00
|
|
|
|
|
|
|
private void Synchronize()
|
|
|
|
{
|
|
|
|
var filestorage = App.Kp2a.GetFileStorage(App.Kp2a.GetDb().Ioc);
|
|
|
|
RunnableOnFinish task;
|
|
|
|
ActionOnFinish onFinishShowMessage = new ActionOnFinish((success, message) =>
|
|
|
|
{
|
|
|
|
if (!String.IsNullOrEmpty(message))
|
|
|
|
Toast.MakeText(this, message, ToastLength.Long).Show();
|
|
|
|
});
|
|
|
|
if (filestorage is CachingFileStorage)
|
|
|
|
{
|
|
|
|
|
|
|
|
task = new SynchronizeCachedDatabase(this, App.Kp2a, onFinishShowMessage);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
task = new CheckDatabaseForChanges(this, App.Kp2a, onFinishShowMessage);
|
|
|
|
}
|
|
|
|
var progressTask = new ProgressTask(App.Kp2a, this, task);
|
|
|
|
progressTask.Run();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-08-28 08:00:54 -04:00
|
|
|
public override void OnBackPressed()
|
|
|
|
{
|
|
|
|
AppTask.SetActivityResult(this, KeePass.ExitNormal);
|
|
|
|
base.OnBackPressed();
|
|
|
|
}
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
private void ToggleSort() {
|
2013-02-23 11:43:42 -05:00
|
|
|
// Toggle setting
|
|
|
|
String sortKey = GetString(Resource.String.sort_key);
|
2013-06-15 06:40:01 -04:00
|
|
|
bool sortByName = _prefs.GetBoolean(sortKey, Resources.GetBoolean(Resource.Boolean.sort_default));
|
|
|
|
ISharedPreferencesEditor editor = _prefs.Edit();
|
2013-02-23 11:43:42 -05:00
|
|
|
editor.PutBoolean(sortKey, ! sortByName);
|
2013-06-15 06:40:01 -04:00
|
|
|
EditorCompat.Apply(editor);
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
// Refresh menu titles
|
2013-06-15 06:40:01 -04:00
|
|
|
ActivityCompat.InvalidateOptionsMenu(this);
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
// Mark all groups as dirty now to refresh them on load
|
2013-06-14 00:14:50 -04:00
|
|
|
Database db = App.Kp2a.GetDb();
|
2013-06-15 06:40:01 -04:00
|
|
|
db.MarkAllGroupsAsDirty();
|
2013-02-23 11:43:42 -05:00
|
|
|
// We'll manually refresh this group so we can remove it
|
2013-06-15 06:40:01 -04:00
|
|
|
db.Dirty.Remove(Group);
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
// Tell the adapter to refresh it's list
|
|
|
|
BaseAdapter adapter = (BaseAdapter) ListAdapter;
|
|
|
|
adapter.NotifyDataSetChanged();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
private void SetPassword() {
|
2013-02-23 11:43:42 -05:00
|
|
|
SetPasswordDialog dialog = new SetPasswordDialog(this);
|
|
|
|
dialog.Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
public class RefreshTask : OnFinish {
|
2013-06-15 06:40:01 -04:00
|
|
|
readonly GroupBaseActivity _act;
|
2013-02-23 11:43:42 -05:00
|
|
|
public RefreshTask(Handler handler, GroupBaseActivity act):base(handler) {
|
2013-06-15 06:40:01 -04:00
|
|
|
_act = act;
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
public override void Run() {
|
|
|
|
if ( Success) {
|
|
|
|
_act.RefreshIfDirty();
|
2013-02-23 11:43:42 -05:00
|
|
|
} else {
|
2013-06-15 06:40:01 -04:00
|
|
|
DisplayMessage(_act);
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public class AfterDeleteGroup : OnFinish {
|
2013-06-15 06:40:01 -04:00
|
|
|
readonly GroupBaseActivity _act;
|
2013-02-23 11:43:42 -05:00
|
|
|
|
|
|
|
public AfterDeleteGroup(Handler handler, GroupBaseActivity act):base(handler) {
|
2013-06-15 06:40:01 -04:00
|
|
|
_act = act;
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-15 06:40:01 -04:00
|
|
|
public override void Run() {
|
|
|
|
if ( Success) {
|
|
|
|
_act.RefreshIfDirty();
|
2013-02-23 11:43:42 -05:00
|
|
|
} else {
|
2013-06-15 06:40:01 -04:00
|
|
|
Handler.Post( () => {
|
|
|
|
Toast.MakeText(_act, "Unrecoverable error: " + Message, ToastLength.Long).Show();
|
2013-02-23 11:43:42 -05:00
|
|
|
});
|
|
|
|
|
2013-08-09 15:25:54 -04:00
|
|
|
App.Kp2a.LockDatabase(false);
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-08-28 08:00:54 -04:00
|
|
|
public bool IsBeingMoved(PwUuid uuid)
|
|
|
|
{
|
|
|
|
MoveElementTask moveElementTask = AppTask as MoveElementTask;
|
|
|
|
if (moveElementTask != null)
|
|
|
|
{
|
|
|
|
if (moveElementTask.Uuid.EqualsValue(uuid))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void StartTask(AppTask task)
|
|
|
|
{
|
|
|
|
AppTask = task;
|
|
|
|
task.StartInGroupActivity(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void StartMovingElement()
|
|
|
|
{
|
|
|
|
ShowInsertElementButtons();
|
|
|
|
GroupView.ListView.InvalidateViews();
|
|
|
|
BaseAdapter adapter = (BaseAdapter)ListAdapter;
|
|
|
|
adapter.NotifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ShowInsertElementButtons()
|
|
|
|
{
|
|
|
|
GroupView.ShowInsertButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void StopMovingElement()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
MoveElementTask moveElementTask = (MoveElementTask)AppTask;
|
|
|
|
IStructureItem elementToMove = App.Kp2a.GetDb().KpDatabase.RootGroup.FindObject(moveElementTask.Uuid, true, null);
|
|
|
|
if (elementToMove.ParentGroup != Group)
|
|
|
|
App.Kp2a.GetDb().Dirty.Add(elementToMove.ParentGroup);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
//don't crash if adding to dirty fails but log the exception:
|
|
|
|
Kp2aLog.Log(e.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
AppTask = new NullTask();
|
|
|
|
AppTask.SetupGroupBaseActivityButtons(this);
|
|
|
|
GroupView.ListView.InvalidateViews();
|
|
|
|
BaseAdapter adapter = (BaseAdapter)ListAdapter;
|
|
|
|
adapter.NotifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-23 11:43:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|