From 53bad09fb1e5bf1458ee823e23237f98d441d441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=A4nge?= Date: Mon, 8 Apr 2024 15:35:26 +0200 Subject: [PATCH 1/2] Fix some lint errors --- app/build.gradle | 2 +- app/lint.xml | 10 ++++++ app/src/main/AndroidManifest.xml | 8 ++--- .../activities/DiaryEntryActivity.java | 2 ++ .../res/layout-land/diaryentry_slide3.xml | 8 ++--- app/src/main/res/layout/diaryentry_slide3.xml | 8 ++--- .../main/res/layout/diaryentry_summary.xml | 10 +++--- app/src/main/res/layout/pdf_person.xml | 35 +++++++++---------- 8 files changed, 46 insertions(+), 37 deletions(-) create mode 100644 app/lint.xml diff --git a/app/build.gradle b/app/build.gradle index daa1c9f..fe21eb4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -23,7 +23,7 @@ android { } namespace 'org.secuso.privacyfriendlypaindiary' lint { - abortOnError false + lintConfig = file("lint.xml") } compileOptions { diff --git a/app/lint.xml b/app/lint.xml new file mode 100644 index 0000000..e0fb1a8 --- /dev/null +++ b/app/lint.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 94f07ae..a69551b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,9 @@ + + + - - - - - \ No newline at end of file diff --git a/app/src/main/java/org/secuso/privacyfriendlypaindiary/activities/DiaryEntryActivity.java b/app/src/main/java/org/secuso/privacyfriendlypaindiary/activities/DiaryEntryActivity.java index 35bc446..38012c0 100644 --- a/app/src/main/java/org/secuso/privacyfriendlypaindiary/activities/DiaryEntryActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlypaindiary/activities/DiaryEntryActivity.java @@ -16,6 +16,7 @@ License, or (at your option) any later version. */ package org.secuso.privacyfriendlypaindiary.activities; +import android.annotation.SuppressLint; import android.app.AlertDialog; import android.app.FragmentManager; import android.content.DialogInterface; @@ -1156,6 +1157,7 @@ public boolean onOptionsItemSelected(MenuItem item) { } + @SuppressLint("MissingSuperCall") @Override public void onBackPressed() { if (changesMade) { diff --git a/app/src/main/res/layout-land/diaryentry_slide3.xml b/app/src/main/res/layout-land/diaryentry_slide3.xml index 3e66b4e..c0ddedf 100644 --- a/app/src/main/res/layout-land/diaryentry_slide3.xml +++ b/app/src/main/res/layout-land/diaryentry_slide3.xml @@ -78,9 +78,9 @@ android:layout_width="wrap_content" android:layout_height="match_parent" android:adjustViewBounds="true" - android:tint="@color/yellow" app:srcCompat="@drawable/paindiary_person_fullbody" - android:visibility="gone"/> + android:visibility="gone" + app:tint="@color/yellow" /> @@ -109,9 +109,9 @@ android:layout_width="wrap_content" android:layout_height="match_parent" android:adjustViewBounds="true" - android:tint="@color/yellow" app:srcCompat="@drawable/paindiary_person_fullbody" - android:visibility="gone"/> + android:visibility="gone" + app:tint="@color/yellow" /> diff --git a/app/src/main/res/layout/diaryentry_slide3.xml b/app/src/main/res/layout/diaryentry_slide3.xml index 0de9fdd..8283974 100644 --- a/app/src/main/res/layout/diaryentry_slide3.xml +++ b/app/src/main/res/layout/diaryentry_slide3.xml @@ -63,9 +63,9 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" - android:tint="@color/yellow" app:srcCompat="@drawable/paindiary_person_fullbody" - android:visibility="gone"/> + android:visibility="gone" + app:tint="@color/yellow" /> @@ -100,9 +100,9 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" - android:tint="@color/yellow" app:srcCompat="@drawable/paindiary_person_fullbody" - android:visibility="gone"/> + android:visibility="gone" + app:tint="@color/yellow" /> diff --git a/app/src/main/res/layout/diaryentry_summary.xml b/app/src/main/res/layout/diaryentry_summary.xml index 560876c..f750c5a 100644 --- a/app/src/main/res/layout/diaryentry_summary.xml +++ b/app/src/main/res/layout/diaryentry_summary.xml @@ -1,5 +1,5 @@ - + android:visibility="gone" + app:tint="@color/yellow" /> @@ -193,9 +193,9 @@ android:layout_width="90dp" android:layout_height="220dp" android:scaleType="centerCrop" - android:tint="@color/yellow" app:srcCompat="@drawable/paindiary_person_fullbody" - android:visibility="gone" /> + android:visibility="gone" + app:tint="@color/yellow" /> diff --git a/app/src/main/res/layout/pdf_person.xml b/app/src/main/res/layout/pdf_person.xml index c990d44..2f6cbef 100644 --- a/app/src/main/res/layout/pdf_person.xml +++ b/app/src/main/res/layout/pdf_person.xml @@ -1,26 +1,25 @@ - + android:orientation="vertical"> - + - + \ No newline at end of file From 377bbeb4155798abeb87393e0f0a18d280e0af03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=A4nge?= Date: Mon, 8 Apr 2024 17:00:11 +0200 Subject: [PATCH 2/2] Fix notification permission Add alert to request permission on setting change --- app/src/main/AndroidManifest.xml | 1 + .../activities/SettingsActivity.kt | 29 +++++++++++++++++++ app/src/main/res/values-de/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 34 insertions(+) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 23bc3da..85aedd8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,7 @@ + diff --git a/app/src/main/java/org/secuso/privacyfriendlypaindiary/activities/SettingsActivity.kt b/app/src/main/java/org/secuso/privacyfriendlypaindiary/activities/SettingsActivity.kt index 18a0fde..30b3b43 100644 --- a/app/src/main/java/org/secuso/privacyfriendlypaindiary/activities/SettingsActivity.kt +++ b/app/src/main/java/org/secuso/privacyfriendlypaindiary/activities/SettingsActivity.kt @@ -16,13 +16,18 @@ */ package org.secuso.privacyfriendlypaindiary.activities +import android.Manifest import android.app.AlertDialog import android.content.SharedPreferences import android.content.SharedPreferences.OnSharedPreferenceChangeListener +import android.content.pm.PackageManager +import android.os.Build import android.os.Bundle import android.preference.Preference.OnPreferenceClickListener import android.preference.PreferenceFragment import android.preference.PreferenceManager +import androidx.core.app.ActivityCompat +import androidx.core.content.ContextCompat import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking @@ -56,6 +61,10 @@ class SettingsActivity : BaseActivity() { } class GeneralPreferenceFragment : PreferenceFragment(), OnSharedPreferenceChangeListener { + companion object { + const val REQUEST_CODE_POST_NOTIFICATION = 3 + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) initPreferences() @@ -87,6 +96,7 @@ class SettingsActivity : BaseActivity() { } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String?) { + checkPermission() if (key == KEY_PREF_REMINDER) { val enabled = sharedPreferences.getBoolean(KEY_PREF_REMINDER, false) if (enabled) { @@ -103,6 +113,25 @@ class SettingsActivity : BaseActivity() { } } + private fun checkPermission(): Boolean { + //Check for notification permission and exact alarm permission + if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU + && ContextCompat.checkSelfPermission(this.context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) + ) { + AlertDialog.Builder(this.context) + .setMessage(R.string.dialog_need_permission_for_notifications) + .setPositiveButton(android.R.string.ok) { _, _ -> + ActivityCompat.requestPermissions(this.activity, arrayOf(Manifest.permission.POST_NOTIFICATIONS), REQUEST_CODE_POST_NOTIFICATION) + } + .setTitle(R.string.dialog_need_permission_for_notifications_title) + .setCancelable(true) + .create() + .show() + return false + } + return true + } + private fun resetApp() { runBlocking { launch(Dispatchers.IO) { diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 0d1e8b2..72920bc 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -164,6 +164,8 @@ PDF wurde im Dokumenten-Ordner gespeichert. Unbekannter Fehler: PDF konnte nicht gespeichert werden. Seien Sie vorsichtig, mit wem Sie Ihre medizinischen Informationen teilen. + Für diese Funktion ist die Berechtigung zum Senden von Benachrichtigungen erforderlich. + Benachrichtigungen aktivieren diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 219e90e..48fb00a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -169,5 +169,7 @@ PDF was saved to documents folder. Unknown Error: PDF could not be saved. Be careful who you share your medical information with. + Permission to send notifications is needed for this feature. + Enable notifications \ No newline at end of file