From 57a9a0e2ba5f2e873ac1a40af192eabfb1231642 Mon Sep 17 00:00:00 2001 From: henrikth93 Date: Fri, 11 Oct 2024 11:30:13 +0200 Subject: [PATCH 01/25] Add action for "rate scribe" This commit will add an action for "rate scribe" --- .../java/be/scri/fragments/AboutFragment.kt | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/be/scri/fragments/AboutFragment.kt b/app/src/main/java/be/scri/fragments/AboutFragment.kt index 98a343c9..f6dcf43f 100644 --- a/app/src/main/java/be/scri/fragments/AboutFragment.kt +++ b/app/src/main/java/be/scri/fragments/AboutFragment.kt @@ -1,10 +1,13 @@ package be.scri.fragments +import android.content.Context +import android.net.Uri import android.content.Intent import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Toast import androidx.activity.addCallback import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager @@ -104,15 +107,16 @@ class AboutFragment : Fragment() { ), ) - private fun getSecondRecyclerViewData(): List = - listOf( + private fun getSecondRecyclerViewData(): List { + val context = requireContext() + return listOf( ItemsViewModel( image = R.drawable.star, text = ItemsViewModel.Text(R.string.app_about_feedback_rate_scribe), image2 = R.drawable.external_link, url = null, activity = null, - action = null, + action = ::rateScribe, ), ItemsViewModel( image = R.drawable.bug_report_icon, @@ -147,6 +151,7 @@ class AboutFragment : Fragment() { action = null, ), ) + } private fun getThirdRecyclerViewData(): List = listOf( @@ -210,4 +215,37 @@ class AboutFragment : Fragment() { fragmentTransaction.addToBackStack(null) fragmentTransaction.commit() } + private fun getInstallSource(context: Context): String? { + return try { + val packageManager = context.packageManager + packageManager.getInstallerPackageName(context.packageName) + } catch (e: Exception) { + null + } + } + + private fun rateScribe() { + val context = requireContext() + var installSource = getInstallSource(context) + val url = null + //To be added later + /*var url = when (installSource) { + "com.android.vending" -> "https://play.google.com/store/apps/details?id=${context.packageName}" + "org.fdroid.fdroid" -> "https://f-droid.org/packages/${context.packageName}" + else -> null + } */ + + if (url != null) { + val intent = Intent(Intent.ACTION_VIEW).apply { + data = Uri.parse(url) + setPackage("com.android.chrome") + } + context.startActivity(intent) + } else { + Toast.makeText(context, "Unknown installation source", Toast.LENGTH_SHORT).show() + } + + + } + } From aab39dca3d5d8e4f09ab12cb9a98b610ae9528aa Mon Sep 17 00:00:00 2001 From: henrikth93 Date: Fri, 11 Oct 2024 11:37:19 +0200 Subject: [PATCH 02/25] Fix linting error Commented out the variable for installsource --- app/src/main/java/be/scri/fragments/AboutFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/be/scri/fragments/AboutFragment.kt b/app/src/main/java/be/scri/fragments/AboutFragment.kt index f6dcf43f..adfc28b0 100644 --- a/app/src/main/java/be/scri/fragments/AboutFragment.kt +++ b/app/src/main/java/be/scri/fragments/AboutFragment.kt @@ -226,7 +226,7 @@ class AboutFragment : Fragment() { private fun rateScribe() { val context = requireContext() - var installSource = getInstallSource(context) + // var installSource = getInstallSource(context) val url = null //To be added later /*var url = when (installSource) { From 34bb06a196d70deb41886dcdd2570131eaf456c5 Mon Sep 17 00:00:00 2001 From: henrikth93 Date: Fri, 11 Oct 2024 11:40:25 +0200 Subject: [PATCH 03/25] Comment out unused function Comment out unused function, which will later be used. --- app/src/main/java/be/scri/fragments/AboutFragment.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/be/scri/fragments/AboutFragment.kt b/app/src/main/java/be/scri/fragments/AboutFragment.kt index adfc28b0..155a8f98 100644 --- a/app/src/main/java/be/scri/fragments/AboutFragment.kt +++ b/app/src/main/java/be/scri/fragments/AboutFragment.kt @@ -215,14 +215,15 @@ class AboutFragment : Fragment() { fragmentTransaction.addToBackStack(null) fragmentTransaction.commit() } - private fun getInstallSource(context: Context): String? { + + /*private fun getInstallSource(context: Context): String? { return try { val packageManager = context.packageManager packageManager.getInstallerPackageName(context.packageName) } catch (e: Exception) { null } - } + }*/ private fun rateScribe() { val context = requireContext() From 3dbab3a58dd79c58da63bbcbf323b98e0b42df30 Mon Sep 17 00:00:00 2001 From: henrikth93 Date: Fri, 11 Oct 2024 11:43:06 +0200 Subject: [PATCH 04/25] Remove blank line Remove blank line --- app/src/main/java/be/scri/fragments/AboutFragment.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/be/scri/fragments/AboutFragment.kt b/app/src/main/java/be/scri/fragments/AboutFragment.kt index 155a8f98..74bbaa65 100644 --- a/app/src/main/java/be/scri/fragments/AboutFragment.kt +++ b/app/src/main/java/be/scri/fragments/AboutFragment.kt @@ -246,7 +246,5 @@ class AboutFragment : Fragment() { Toast.makeText(context, "Unknown installation source", Toast.LENGTH_SHORT).show() } - } - } From 94df7f1fab29bf3780f856b283f07f37953672cf Mon Sep 17 00:00:00 2001 From: henrikth93 Date: Fri, 11 Oct 2024 11:48:13 +0200 Subject: [PATCH 05/25] Fixing linting errors --- app/src/main/java/be/scri/fragments/AboutFragment.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/be/scri/fragments/AboutFragment.kt b/app/src/main/java/be/scri/fragments/AboutFragment.kt index 74bbaa65..fe3611af 100644 --- a/app/src/main/java/be/scri/fragments/AboutFragment.kt +++ b/app/src/main/java/be/scri/fragments/AboutFragment.kt @@ -1,6 +1,5 @@ package be.scri.fragments -import android.content.Context import android.net.Uri import android.content.Intent import android.os.Bundle @@ -227,9 +226,10 @@ class AboutFragment : Fragment() { private fun rateScribe() { val context = requireContext() - // var installSource = getInstallSource(context) + // var installSource = getInstallSource(context) val url = null - //To be added later + // To be added later + /*var url = when (installSource) { "com.android.vending" -> "https://play.google.com/store/apps/details?id=${context.packageName}" "org.fdroid.fdroid" -> "https://f-droid.org/packages/${context.packageName}" @@ -245,6 +245,5 @@ class AboutFragment : Fragment() { } else { Toast.makeText(context, "Unknown installation source", Toast.LENGTH_SHORT).show() } - } } From e9f381a0306e1199519cd601fb930849b83d0dfa Mon Sep 17 00:00:00 2001 From: henrikth93 Date: Fri, 11 Oct 2024 11:59:40 +0200 Subject: [PATCH 06/25] Fix linting errors Fixed multiline issue --- app/src/main/java/be/scri/fragments/AboutFragment.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/be/scri/fragments/AboutFragment.kt b/app/src/main/java/be/scri/fragments/AboutFragment.kt index fe3611af..e121f4b4 100644 --- a/app/src/main/java/be/scri/fragments/AboutFragment.kt +++ b/app/src/main/java/be/scri/fragments/AboutFragment.kt @@ -1,7 +1,7 @@ package be.scri.fragments -import android.net.Uri import android.content.Intent +import android.net.Uri import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -243,7 +243,11 @@ class AboutFragment : Fragment() { } context.startActivity(intent) } else { - Toast.makeText(context, "Unknown installation source", Toast.LENGTH_SHORT).show() + Toast.makeText( + context, + "Unknown installation source", + Toast.LENGTH_SHORT + ).show() } } } From e6adbceae9b159168018fd32207557bc3b655e72 Mon Sep 17 00:00:00 2001 From: Alicia Bendz Date: Fri, 11 Oct 2024 18:54:36 -0400 Subject: [PATCH 07/25] feat: Add unit testing dependencies Add Junit 5 and Mockk test dependencies with simple test --- app/build.gradle.kts | 9 +++++++++ .../helpers/AlphanumericComparatorTest.kt | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 app/src/test/kotlin/helpers/AlphanumericComparatorTest.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0aa7c870..3d62c00d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -15,8 +15,12 @@ plugins { id("org.jmailen.kotlinter") id("io.gitlab.arturbosch.detekt") id("com.google.devtools.ksp") version "2.0.0-1.0.22" apply true + id("de.mannodermaus.android-junit5") version "1.11.2.0" } + val kotlinVersion by extra("2.0.0") +val junit5Version by extra("5.11.2") +val mockkVersion by extra("1.13.13") android { compileSdk = 34 @@ -87,6 +91,7 @@ android { buildUponDefaultConfig = true allRules = false config = rootProject.files("detekt.yml") + } kotlinter { @@ -115,6 +120,10 @@ dependencies { implementation("androidx.cardview:cardview:1.0.0") implementation("androidx.viewpager2:viewpager2:1.1.0") + testImplementation("org.junit.jupiter:junit-jupiter-api:$junit5Version") + testImplementation("io.mockk:mockk:$mockkVersion") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junit5Version") + api("joda-time:joda-time:2.10.13") api("com.github.tibbi:RecyclerView-FastScroller:e7d3e150c4") api("com.github.tibbi:reprint:2cb206415d") diff --git a/app/src/test/kotlin/helpers/AlphanumericComparatorTest.kt b/app/src/test/kotlin/helpers/AlphanumericComparatorTest.kt new file mode 100644 index 00000000..964f3c00 --- /dev/null +++ b/app/src/test/kotlin/helpers/AlphanumericComparatorTest.kt @@ -0,0 +1,18 @@ +package helpers + +import be.scri.helpers.AlphanumericComparator +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class AlphanumericComparatorTest { + private val subject = AlphanumericComparator() + + @Test + fun testCompare() { + assertEquals(-1, subject.compare("IMG_10.png", "IMG_11.png")) + + assertEquals(0, subject.compare("IMG_10.png", "IMG_10.png")) + + assertEquals(1, subject.compare("IMG_11.png", "IMG_10.png")) + } +} From 5c16fc20354d15731f4937ddde7715250ec40948 Mon Sep 17 00:00:00 2001 From: Radovan Zajac Date: Sat, 12 Oct 2024 14:28:08 +0200 Subject: [PATCH 08/25] App hints and reset button --- .../java/be/scri/activities/MainActivity.kt | 32 ++++++++++++ .../java/be/scri/fragments/AboutFragment.kt | 18 ++++++- .../java/be/scri/fragments/MainFragment.kt | 23 ++++++++- .../be/scri/fragments/SettingsFragment.kt | 6 +++ .../main/java/be/scri/helpers/HintUtils.kt | 46 +++++++++++++++++ app/src/main/res/layout/activity_main.xml | 9 ++++ app/src/main/res/layout/hint_layout.xml | 50 +++++++++++++++++++ app/src/main/res/values-v31/colors.xml | 1 + app/src/main/res/values/strings.xml | 5 ++ 9 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/be/scri/helpers/HintUtils.kt create mode 100644 app/src/main/res/layout/hint_layout.xml diff --git a/app/src/main/java/be/scri/activities/MainActivity.kt b/app/src/main/java/be/scri/activities/MainActivity.kt index 172933d8..47dcad23 100644 --- a/app/src/main/java/be/scri/activities/MainActivity.kt +++ b/app/src/main/java/be/scri/activities/MainActivity.kt @@ -3,6 +3,7 @@ package be.scri.activities import android.app.UiModeManager import android.content.Context import android.os.Bundle +import android.util.Log import android.view.View import android.view.ViewGroup import android.widget.Button @@ -183,4 +184,35 @@ class MainActivity : SimpleActivity() { val uiModeManager = context.getSystemService(UI_MODE_SERVICE) as UiModeManager return uiModeManager.nightMode == UiModeManager.MODE_NIGHT_YES } + + fun showHint(sharedPrefsKey: String, hintMessageResId: Int) { + val sharedPref = getSharedPreferences("app_preferences", Context.MODE_PRIVATE) + val allEntries = sharedPref.all + for ((key, value) in allEntries) { + Log.i("hint", "$key = $value") + } + val isHintShown = sharedPref.getBoolean(sharedPrefsKey, false) + Log.i("hint", isHintShown.toString()) + if (!isHintShown) { + val hintLayout = findViewById(R.id.hint_layout) + val hintText = findViewById(R.id.hint_text) + hintText.text = getString(hintMessageResId) + + hintLayout.visibility = View.VISIBLE + + val okButton = findViewById