private void UpdateInfotexts() { string lastInfoText; if (IsTimeForInfotext(out lastInfoText) && (FindViewById <TextView>(Resource.Id.info_head) != null)) { FingerprintUnlockMode um; Enum.TryParse(_prefs.GetString(Database.GetFingerprintModePrefKey(App.Kp2a.GetDb().Ioc), ""), out um); bool isFingerprintEnabled = (um == FingerprintUnlockMode.FullUnlock); string masterKeyKey = "MasterKey" + isFingerprintEnabled; string emergencyKey = "Emergency"; string backupKey = "Backup"; List <string> applicableInfoTextKeys = new List <string> { masterKeyKey }; if (App.Kp2a.GetFileStorage(App.Kp2a.GetDb().Ioc).UserShouldBackup) { applicableInfoTextKeys.Add(backupKey); } if (App.Kp2a.GetDb().Entries.Count > 15) { applicableInfoTextKeys.Add(emergencyKey); } List <string> enabledInfoTextKeys = new List <string>(); foreach (string key in applicableInfoTextKeys) { if (!InfoTextWasDisabled(key)) { enabledInfoTextKeys.Add(key); } } if (enabledInfoTextKeys.Any()) { string infoTextKey = "", infoHead = "", infoMain = "", infoNote = ""; if (enabledInfoTextKeys.Count > 1) { foreach (string key in enabledInfoTextKeys) { if (key == lastInfoText) { enabledInfoTextKeys.Remove(key); break; } } infoTextKey = enabledInfoTextKeys[new Random().Next(enabledInfoTextKeys.Count)]; } if (infoTextKey == masterKeyKey) { infoHead = GetString(Resource.String.masterkey_infotext_head); infoMain = GetString(Resource.String.masterkey_infotext_main); if (isFingerprintEnabled) { infoNote = GetString(Resource.String.masterkey_infotext_fingerprint_note); } } else if (infoTextKey == emergencyKey) { infoHead = GetString(Resource.String.emergency_infotext_head); infoMain = GetString(Resource.String.emergency_infotext_main); } else if (infoTextKey == backupKey) { infoHead = GetString(Resource.String.backup_infotext_head); infoMain = GetString(Resource.String.backup_infotext_main); infoNote = GetString(Resource.String.backup_infotext_note, GetString(Resource.String.menu_app_settings), GetString(Resource.String.menu_db_settings), GetString(Resource.String.export_prefs)); } FindViewById <TextView>(Resource.Id.info_head).Text = infoHead; FindViewById <TextView>(Resource.Id.info_main).Text = infoMain; var additionalInfoText = FindViewById <TextView>(Resource.Id.info_additional); additionalInfoText.Text = infoNote; additionalInfoText.Visibility = string.IsNullOrEmpty(infoNote) ? ViewStates.Gone : ViewStates.Visible; if (infoTextKey != "") { RegisterInfoTextDisplay(infoTextKey); FindViewById(Resource.Id.info_ok).Click += (sender, args) => { UpdateBottomBarElementVisibility(Resource.Id.infotext, false); }; FindViewById(Resource.Id.info_dont_show_again).Click += (sender, args) => { UpdateBottomBarElementVisibility(Resource.Id.infotext, false); DisableInfoTextDisplay(infoTextKey); }; UpdateBottomBarElementVisibility(Resource.Id.infotext, true); } } } }
protected override void OnCreate(Bundle savedInstanceState) { _design.ApplyTheme(); base.OnCreate(savedInstanceState); Android.Util.Log.Debug("KP2A", "Creating GBA"); AppTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent); // Likely the app has been killed exit the activity if (!App.Kp2a.GetDb().Loaded) { Finish(); return; } _prefs = PreferenceManager.GetDefaultSharedPreferences(this); SetContentView(ContentResourceId); if (FindViewById(Resource.Id.enable_autofill) != null) { FindViewById(Resource.Id.enable_autofill).Click += (sender, args) => { var intent = new Intent(Settings.ActionRequestSetAutofillService); intent.SetData(Android.Net.Uri.Parse("package:" + PackageName)); try { StartActivity(intent); } catch (ActivityNotFoundException e) { //this exception was reported by many Huawei users Kp2aLog.LogUnexpectedError(e); new AlertDialog.Builder(this) .SetTitle(Resource.String.autofill_enable) .SetMessage(Resource.String.autofill_enable_failed) .SetPositiveButton(Resource.String.ok, (o, eventArgs) => { }) .Show(); const string autofillservicewasenabled = "AutofillServiceWasEnabled"; _prefs.Edit().PutBoolean(autofillservicewasenabled, true).Commit(); UpdateBottomBarElementVisibility(Resource.Id.autofill_infotext, false); } }; } if (FindViewById(Resource.Id.fabCancelAddNew) != null) { FindViewById(Resource.Id.fabAddNew).Click += (sender, args) => { FindViewById(Resource.Id.fabCancelAddNew).Visibility = ViewStates.Visible; FindViewById(Resource.Id.fabAddNewGroup).Visibility = AddGroupEnabled ? ViewStates.Visible : ViewStates.Gone; FindViewById(Resource.Id.fabAddNewEntry).Visibility = AddEntryEnabled ? ViewStates.Visible : ViewStates.Gone; FindViewById(Resource.Id.fabAddNew).Visibility = ViewStates.Gone; }; FindViewById(Resource.Id.fabCancelAddNew).Click += (sender, args) => { FindViewById(Resource.Id.fabCancelAddNew).Visibility = ViewStates.Gone; FindViewById(Resource.Id.fabAddNewGroup).Visibility = ViewStates.Gone; FindViewById(Resource.Id.fabAddNewEntry).Visibility = ViewStates.Gone; FindViewById(Resource.Id.fabAddNew).Visibility = ViewStates.Visible; }; } if (FindViewById(Resource.Id.cancel_insert_element) != null) { FindViewById(Resource.Id.cancel_insert_element).Click += (sender, args) => StopMovingElements(); FindViewById(Resource.Id.insert_element).Click += (sender, args) => InsertElements(); Util.MoveBottomBarButtons(Resource.Id.cancel_insert_element, Resource.Id.insert_element, Resource.Id.bottom_bar, this); } if (FindViewById(Resource.Id.show_autofill_info) != null) { FindViewById(Resource.Id.show_autofill_info).Click += (sender, args) => Util.GotoUrl(this, "https://philippc.github.io/keepass2android/OreoAutoFill.html"); 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 [email protected] 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)) { FingerprintUnlockMode um; Enum.TryParse(_prefs.GetString(Database.GetFingerprintModePrefKey(App.Kp2a.GetDb().Ioc), ""), out um); bool isFingerprintEnabled = (um == FingerprintUnlockMode.FullUnlock); string masterKeyKey = "MasterKey" + isFingerprintEnabled; string emergencyKey = "Emergency"; string backupKey = "Backup"; List <string> applicableInfoTextKeys = new List <string> { masterKeyKey }; if (App.Kp2a.GetFileStorage(App.Kp2a.GetDb().Ioc).UserShouldBackup) { applicableInfoTextKeys.Add(backupKey); } if (App.Kp2a.GetDb().Entries.Count > 15) { applicableInfoTextKeys.Add(emergencyKey); } List <string> enabledInfoTextKeys = new List <string>(); foreach (string key in applicableInfoTextKeys) { if (!InfoTextWasDisabled(key)) { enabledInfoTextKeys.Add(key); } } if (enabledInfoTextKeys.Any()) { string infoTextKey = "", infoHead = "", infoMain = "", infoNote = ""; if (enabledInfoTextKeys.Count > 1) { foreach (string key in enabledInfoTextKeys) { if (key == lastInfoText) { enabledInfoTextKeys.Remove(key); break; } } infoTextKey = enabledInfoTextKeys[new Random().Next(enabledInfoTextKeys.Count)]; } if (infoTextKey == masterKeyKey) { infoHead = GetString(Resource.String.masterkey_infotext_head); infoMain = GetString(Resource.String.masterkey_infotext_main); if (isFingerprintEnabled) { infoNote = GetString(Resource.String.masterkey_infotext_fingerprint_note); } } else if (infoTextKey == emergencyKey) { infoHead = GetString(Resource.String.emergency_infotext_head); infoMain = GetString(Resource.String.emergency_infotext_main); } else if (infoTextKey == backupKey) { infoHead = GetString(Resource.String.backup_infotext_head); infoMain = GetString(Resource.String.backup_infotext_main); infoNote = GetString(Resource.String.backup_infotext_note, GetString(Resource.String.menu_app_settings), GetString(Resource.String.menu_db_settings), GetString(Resource.String.export_prefs)); } FindViewById <TextView>(Resource.Id.info_head).Text = infoHead; FindViewById <TextView>(Resource.Id.info_main).Text = infoMain; var additionalInfoText = FindViewById <TextView>(Resource.Id.info_additional); additionalInfoText.Text = infoNote; additionalInfoText.Visibility = string.IsNullOrEmpty(infoNote) ? ViewStates.Gone : ViewStates.Visible; if (infoTextKey != "") { RegisterInfoTextDisplay(infoTextKey); FindViewById(Resource.Id.info_ok).Click += (sender, args) => { UpdateBottomBarElementVisibility(Resource.Id.infotext, false); }; FindViewById(Resource.Id.info_dont_show_again).Click += (sender, args) => { UpdateBottomBarElementVisibility(Resource.Id.infotext, false); DisableInfoTextDisplay(infoTextKey); }; UpdateBottomBarElementVisibility(Resource.Id.infotext, true); } } } SetResult(KeePass.ExitNormal); }