remove icon preferences on Android 8, show info on how to use notification channels on Android 8

This commit is contained in:
Philipp Crocoll
2018-02-10 21:06:50 +01:00
parent 7b63346bd0
commit 6fc4741c9a
4 changed files with 110 additions and 6 deletions

View File

@@ -53,6 +53,7 @@ namespace keepass2android
{ Resource.Id.cancel_insert_element, 20 },
{ Resource.Id.insert_element, 20 },
{ Resource.Id.autofill_infotext, 10 },
{ Resource.Id.notification_info_android8_infotext, 10 },
{ Resource.Id.infotext, 11 },
{ Resource.Id.select_other_entry, 20},
{ Resource.Id.add_url_entry, 20},
@@ -240,9 +241,26 @@ namespace keepass2android
UpdateAutofillInfo();
UpdateAndroid8NotificationInfo();
RefreshIfDirty();
}
private void UpdateAndroid8NotificationInfo(bool hideForever = false)
{
const string prefsKey = "DidShowAndroid8NotificationInfo";
bool canShowNotificationInfo = (Build.VERSION.SdkInt >= BuildVersionCodes.O) && (!_prefs.GetBoolean(prefsKey, false));
if ((canShowNotificationInfo) && hideForever)
{
_prefs.Edit().PutBoolean(prefsKey, true).Commit();
canShowNotificationInfo = false;
}
UpdateBottomBarElementVisibility(Resource.Id.notification_info_android8_infotext, canShowNotificationInfo);
}
public override bool OnSearchRequested()
@@ -340,6 +358,35 @@ namespace keepass2android
Util.MoveBottomBarButtons(Resource.Id.show_autofill_info, Resource.Id.enable_autofill, Resource.Id.autofill_buttons, this);
}
if (FindViewById(Resource.Id.configure_notification_channels) != null)
{
FindViewById(Resource.Id.configure_notification_channels).Click += (sender, args) =>
{
Intent intent = new Intent(Settings.ActionChannelNotificationSettings);
intent.PutExtra(Settings.ExtraChannelId, App.NotificationChannelIdQuicklocked);
intent.PutExtra(Settings.ExtraAppPackage, PackageName);
try
{
StartActivity(intent);
}
catch (Exception e)
{
new AlertDialog.Builder(this)
.SetTitle("Unexpected error")
.SetMessage(
"Opening the settings failed. Please report this to crocoapps@gmail.com including information about your device vendor and OS. Please try to configure the notifications by long pressing a KP2A notification. Details: " + e.ToString())
.Show();
}
UpdateAndroid8NotificationInfo(true);
};
FindViewById(Resource.Id.ignore_notification_channel).Click += (sender, args) =>
{
UpdateAndroid8NotificationInfo(true);
};
}
string lastInfoText;
if (IsTimeForInfotext(out lastInfoText))

View File

@@ -77,7 +77,47 @@
style="@style/BottomBarButton" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/notification_info_android8_infotext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:orientation="vertical">
<TextView android:id="@+id/myinfotext" android:text="@string/IconVisibilityInfo_Android8_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_margin="6dp"
android:layout_marginBottom="2dp"
/>
<RelativeLayout
android:id="@+id/notification_channels_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:baselineAligned="false">
<Button
android:id="@+id/configure_notification_channels"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingTop="4dp"
android:text="@string/IconVisibilityInfo_Android8_btnSettings"
style="@style/BottomBarButton" />
<Button
android:id="@+id/ignore_notification_channel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingTop="4dp"
android:text="@string/DontCare"
style="@style/BottomBarButton" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/infotext"
android:layout_width="match_parent"

View File

@@ -398,6 +398,10 @@
<string name="ShowUnlockedNotification_title">Notification icon while unlocked</string>
<string name="ShowUnlockedNotification_summary">Show a notification icon while the database is unlocked.</string>
<string name="IconVisibilityInfo_Android8_text">Android 8 has introduced new behavior for notifications. If you want to hide the icon for Keepass2Android\'s notifications, please configure this through the system settings. Set the importance of the notification category to Minimum.</string>
<string name="IconVisibilityInfo_Android8_btnSettings">Open settings</string>
<string name="DontCare">I don\'t care</string>
<string name="PreloadDatabaseEnabled_title">Pre-load database file</string>
<string name="PreloadDatabaseEnabled_summary">Start background loading or downloading of the database file during password entry.</string>

View File

@@ -364,9 +364,16 @@ namespace keepass2android
// Re-use the change handlers for the application settings
FindPreference(GetString(Resource.String.keyfile_key)).PreferenceChange += OnRememberKeyFileHistoryChanged;
FindPreference(GetString(Resource.String.ShowUnlockedNotification_key)).PreferenceChange += OnShowUnlockedNotificationChanged;
FindPreference(GetString(Resource.String.ShowUnlockedNotification_key)).PreferenceChange += OnShowUnlockedNotificationChanged;
FindPreference(GetString(Resource.String.DebugLog_key)).PreferenceChange += OnDebugLogChanged;
var unlockedNotificationPref = FindPreference(GetString(Resource.String.ShowUnlockedNotification_key));
unlockedNotificationPref.PreferenceChange += OnShowUnlockedNotificationChanged;
if ((int)Build.VERSION.SdkInt >= 26)
{
//use system notification channels to control notification visibility
unlockedNotificationPref.Parent.RemovePreference(unlockedNotificationPref);
}
FindPreference(GetString(Resource.String.DebugLog_key)).PreferenceChange += OnDebugLogChanged;
FindPreference(GetString(Resource.String.DebugLog_send_key)).PreferenceClick += OnSendDebug;
UpdateAutofillPref();
@@ -422,10 +429,16 @@ namespace keepass2android
Preference hideQuickUnlockTranspIconPref = FindPreference(GetString(Resource.String.QuickUnlockIconHidden_key));
Preference hideQuickUnlockIconPref = FindPreference(GetString(Resource.String.QuickUnlockIconHidden16_key));
var quickUnlockScreen = ((PreferenceScreen)FindPreference(GetString(Resource.String.QuickUnlock_prefs_key)));
if ((int)Android.OS.Build.VERSION.SdkInt >= 16)
if ((int)Android.OS.Build.VERSION.SdkInt >= 26)
{
//use notification channels
quickUnlockScreen.RemovePreference(hideQuickUnlockTranspIconPref);
quickUnlockScreen.RemovePreference(hideQuickUnlockIconPref);
}
else if ((int)Android.OS.Build.VERSION.SdkInt >= 16)
{
quickUnlockScreen.RemovePreference(hideQuickUnlockTranspIconPref);
FindPreference(GetString(Resource.String.ShowUnlockedNotification_key)).PreferenceChange += (sender, args) => App.Kp2a.UpdateOngoingNotification();
unlockedNotificationPref.PreferenceChange += (sender, args) => App.Kp2a.UpdateOngoingNotification();
hideQuickUnlockIconPref.PreferenceChange += delegate { App.Kp2a.UpdateOngoingNotification(); };
}
else
@@ -436,7 +449,7 @@ namespace keepass2android
delegate { App.Kp2a.UpdateOngoingNotification(); };
((PreferenceScreen)FindPreference(GetString(Resource.String.display_prefs_key))).RemovePreference(
FindPreference(GetString(Resource.String.ShowUnlockedNotification_key)));
unlockedNotificationPref);
}
}
catch (Exception ex)