Skip to content

Commit

Permalink
migrate preferences to AndroidX, separate one large settings fragment…
Browse files Browse the repository at this point in the history
… into many smaller ones to get rid of "ToolbarPreference" workaround
  • Loading branch information
PhilippC committed Dec 1, 2024
1 parent e873ed4 commit 52a62df
Show file tree
Hide file tree
Showing 25 changed files with 1,415 additions and 1,741 deletions.
5 changes: 1 addition & 4 deletions src/keepass2android-appSdkStyle/AboutActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ protected override void OnResume()
{
if ((_dialog == null) || (_dialog.IsShowing == false))
{
if (new ActivityDesign(this).UseDarkTheme)
_dialog = new AboutDialog(this, Android.Resource.Style.ThemeHoloNoActionBarFullscreen);
else
_dialog = new AboutDialog(this, Android.Resource.Style.ThemeHoloLightNoActionBarFullscreen);
_dialog = new AboutDialog(this);
_dialog.SetOnDismissListener(this);
_dialog.Show();
}
Expand Down
178 changes: 104 additions & 74 deletions src/keepass2android-appSdkStyle/LifecycleAwareActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,36 @@ You should have received a copy of the GNU General Public License

namespace keepass2android
{
public abstract class LifecycleAwareActivity : AndroidX.AppCompat.App.AppCompatActivity

public abstract class LifecycleAwareActivity : AndroidX.AppCompat.App.AppCompatActivity
{
protected override void AttachBaseContext(Context baseContext)
{
base.AttachBaseContext(LocaleManager.setLocale(baseContext));
}
protected LifecycleAwareActivity (IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{

}

protected LifecycleAwareActivity()
{
}


string _className;
string ClassName
{
get {
if (_className == null)
_className = GetType().Name;
return _className;
}
}
protected override void AttachBaseContext(Context baseContext)
{
base.AttachBaseContext(LocaleManager.setLocale(baseContext));
}

protected LifecycleAwareActivity(IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{

}

protected LifecycleAwareActivity()
{
}


string _className;

string ClassName
{
get
{
if (_className == null)
_className = GetType().Name;
return _className;
}
}

public string MyDebugName
{
Expand All @@ -60,60 +63,87 @@ public string MyDebugName
private static int staticCount = 0;

private int ID = staticCount++;

protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
Kp2aLog.Log(ClassName + ".OnNewIntent " + ID);
}
}

public Action<Bundle>? OnCreateListener { get; set; }
public Action<Bundle>? OnSaveInstanceStateListener { get; set; }

public Func<bool?>? OnSupportNavigateUpListener { get; set; }

public override bool OnSupportNavigateUp()
{
bool baseRes = base.OnSupportNavigateUp();
bool? res = OnSupportNavigateUpListener?.Invoke();
if (res != null)
return res.Value;
return baseRes;
}

public Action? OnResumeListener { get; set; }

protected override void OnResume()
{
base.OnResume();
Kp2aLog.Log(ClassName+".OnResume " + ID);
if (App.Kp2a.CurrentDb== null)
{
Kp2aLog.Log(" DB null" + " " + ID);
}
else
{
Kp2aLog.Log(" DatabaseIsUnlocked=" + App.Kp2a.DatabaseIsUnlocked + " " + ID);
}
}

protected override void OnStart()
{
ProgressTask.SetNewActiveActivity(this);
base.OnStart();
Kp2aLog.Log(ClassName+".OnStart" + " " + ID);
}

protected override void OnCreate(Bundle bundle)
{

base.OnCreate(bundle);

Kp2aLog.Log(ClassName+".OnCreate" + " " + ID);
Kp2aLog.Log(ClassName+":apptask="+Intent.GetStringExtra("KP2A_APP_TASK_TYPE") + " " + ID);
}

protected override void OnDestroy()
{
base.OnDestroy();
Kp2aLog.Log(ClassName+".OnDestroy"+IsFinishing.ToString() + " " + ID);
}

protected override void OnPause()
{
base.OnPause();
Kp2aLog.Log(ClassName+".OnPause" + " " + ID);
}

protected override void OnStop()
{
base.OnStop();
Kp2aLog.Log(ClassName+".OnStop" + " " + ID);
ProgressTask.RemoveActiveActivity(this);
{
base.OnResume();
OnResumeListener?.Invoke();

Kp2aLog.Log(ClassName + ".OnResume " + ID);
if (App.Kp2a.CurrentDb == null)
{
Kp2aLog.Log(" DB null" + " " + ID);
}
else
{
Kp2aLog.Log(" DatabaseIsUnlocked=" + App.Kp2a.DatabaseIsUnlocked + " " + ID);
}
}

protected override void OnStart()
{
ProgressTask.SetNewActiveActivity(this);
base.OnStart();
Kp2aLog.Log(ClassName + ".OnStart" + " " + ID);
}

protected override void OnCreate(Bundle bundle)
{

base.OnCreate(bundle);

OnCreateListener?.Invoke(bundle);

Kp2aLog.Log(ClassName + ".OnCreate" + " " + ID);
Kp2aLog.Log(ClassName + ":apptask=" + Intent.GetStringExtra("KP2A_APP_TASK_TYPE") + " " + ID);
}

protected override void OnDestroy()
{
base.OnDestroy();
Kp2aLog.Log(ClassName + ".OnDestroy" + IsFinishing.ToString() + " " + ID);
}

protected override void OnPause()
{
base.OnPause();
Kp2aLog.Log(ClassName + ".OnPause" + " " + ID);
}

protected override void OnStop()
{
base.OnStop();
Kp2aLog.Log(ClassName + ".OnStop" + " " + ID);
ProgressTask.RemoveActiveActivity(this);
}

protected override void OnSaveInstanceState(Bundle outState)
{
base.OnSaveInstanceState(outState);
OnSaveInstanceStateListener?.Invoke(outState);
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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/>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:id="@+id/rounds"
android:hint="@string/rounds_hint"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:inputType="number"/>
<TextView android:id="@+id/rounds_explaination"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@id/rounds"/>
</RelativeLayout>
23 changes: 8 additions & 15 deletions src/keepass2android-appSdkStyle/Resources/layout/preference.axml
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:id="@+id/settings"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bgColorLight"
android:orientation="vertical">
<include
android:id="@+id/mytoolbar"
layout="@layout/toolbar" />
<fragment
android:name="keepass2android.SettingsFragment"
android:id="@+id/settings_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/mytoolbar" />
</RelativeLayout>
android:layout_height="match_parent" />
</LinearLayout>
Loading

0 comments on commit 52a62df

Please sign in to comment.