From 60ba9b2b540bb1626449d251a010e9c527926325 Mon Sep 17 00:00:00 2001 From: domi04151309 <36272047+Domi04151309@users.noreply.github.com> Date: Tue, 26 Dec 2023 16:26:52 +0100 Subject: [PATCH] Clean up about screen --- app/build.gradle.kts | 1 - app/src/main/AndroidManifest.xml | 5 - .../powerapp/activities/AboutActivity.kt | 35 +++--- .../activities/ContributorActivity.kt | 113 ------------------ .../powerapp/activities/LibraryActivity.kt | 8 +- app/src/main/res/values-de/plurals.xml | 7 -- app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values/plurals.xml | 7 -- app/src/main/res/values/strings.xml | 14 ++- 9 files changed, 31 insertions(+), 161 deletions(-) delete mode 100644 app/src/main/java/io/github/domi04151309/powerapp/activities/ContributorActivity.kt delete mode 100644 app/src/main/res/values-de/plurals.xml delete mode 100644 app/src/main/res/values/plurals.xml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9a101bc..a25d64b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -85,5 +85,4 @@ dependencies { implementation("com.google.android.material:material:1.11.0") implementation("androidx.preference:preference-ktx:1.2.1") implementation("androidx.annotation:annotation:1.7.1") - implementation("com.android.volley:volley:1.2.1") } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 04594ec..4d114a2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -24,11 +24,6 @@ android:label="@string/about" android:launchMode="singleTop" android:parentActivityName=".activities.SettingsActivity" /> - - startActivity(Intent(requireContext(), ContributorActivity::class.java)) + startActivity( + Intent( + Intent.ACTION_VIEW, + Uri.parse(link), + ), + ) } .setNegativeButton(android.R.string.cancel) { _, _ -> } .setNeutralButton(R.string.about_privacy_policy) { _, _ -> @@ -83,36 +89,23 @@ class AboutActivity : BaseActivity() { BuildConfig.VERSION_CODE, ) setOnPreferenceClickListener { - startActivity( - Intent( - Intent.ACTION_VIEW, - Uri.parse("$REPOSITORY_URL/releases"), - ), - ) - true + onExternalClicked("$REPOSITORY_URL/releases") } } findPreference("github")?.apply { summary = REPOSITORY_URL setOnPreferenceClickListener { - startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(REPOSITORY_URL))) - true + onExternalClicked(REPOSITORY_URL) } } findPreference("license")?.setOnPreferenceClickListener { - startActivity( - Intent( - Intent.ACTION_VIEW, - Uri.parse("$REPOSITORY_URL/blob/master/LICENSE"), - ), - ) - true + onExternalClicked("$REPOSITORY_URL/blob/$BRANCH/LICENSE") } findPreference("icons")?.setOnPreferenceClickListener { onIconsClicked() } findPreference("contributors")?.setOnPreferenceClickListener { - onContributorsClicked() + onExternalClicked("$REPOSITORY_URL/graphs/contributors") } findPreference("libraries")?.setOnPreferenceClickListener { startActivity(Intent(requireContext(), LibraryActivity::class.java)) diff --git a/app/src/main/java/io/github/domi04151309/powerapp/activities/ContributorActivity.kt b/app/src/main/java/io/github/domi04151309/powerapp/activities/ContributorActivity.kt deleted file mode 100644 index 71ba84d..0000000 --- a/app/src/main/java/io/github/domi04151309/powerapp/activities/ContributorActivity.kt +++ /dev/null @@ -1,113 +0,0 @@ -package io.github.domi04151309.powerapp.activities - -import android.graphics.drawable.BitmapDrawable -import android.graphics.drawable.Drawable -import android.os.Bundle -import android.util.Log -import android.widget.ImageView -import androidx.core.content.res.ResourcesCompat -import androidx.preference.Preference -import androidx.preference.PreferenceFragmentCompat -import com.android.volley.Request -import com.android.volley.toolbox.ImageRequest -import com.android.volley.toolbox.JsonArrayRequest -import com.android.volley.toolbox.Volley -import io.github.domi04151309.powerapp.R -import org.json.JSONObject - -class ContributorActivity : BaseActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_settings) - supportFragmentManager - .beginTransaction() - .replace(R.id.settings, GeneralPreferenceFragment()) - .commit() - } - - class GeneralPreferenceFragment : PreferenceFragmentCompat() { - companion object { - private const val PICTURE_SIZE = 192 - } - - private var entries: Array = arrayOf() - - private fun addPreference( - i: Int, - contributor: JSONObject, - drawable: Drawable?, - ) { - entries[i] = - Preference(requireContext()).apply { - val contributions = contributor.optInt("contributions", -1) - icon = drawable - title = contributor.optString("login") - summary = - resources.getQuantityString( - R.plurals.about_contributions, - contributions, - contributions, - ) - } - } - - private fun loadPreferences() { - preferenceScreen.removeAll() - entries.forEach { - preferenceScreen.addPreference(it ?: return) - } - } - - override fun onCreatePreferences( - savedInstanceState: Bundle?, - rootKey: String?, - ) { - val queue = Volley.newRequestQueue(requireContext()) - addPreferencesFromResource(R.xml.pref_about_list) - queue.add( - JsonArrayRequest( - Request.Method.GET, - "https://api.github.com/repos/${AboutActivity.GITHUB_REPOSITORY}/contributors", - null, - { response -> - entries = Array(response.length()) { null } - for (i in 0 until response.length()) { - val currentContributor = response.getJSONObject(i) - queue.add( - ImageRequest( - currentContributor.optString("avatar_url"), - { image -> - addPreference( - i, - currentContributor, - BitmapDrawable(resources, image), - ) - if (i == response.length() - 1) loadPreferences() - }, - PICTURE_SIZE, - PICTURE_SIZE, - ImageView.ScaleType.CENTER_INSIDE, - null, - { error -> - Log.e(ContributorActivity::class.simpleName, error.toString()) - addPreference( - i, - currentContributor, - ResourcesCompat.getDrawable( - requireContext().resources, - R.drawable.ic_about_contributor, - requireContext().theme, - ), - ) - if (i == response.length() - 1) loadPreferences() - }, - ), - ) - } - }, - { }, - ), - ) - } - } -} diff --git a/app/src/main/java/io/github/domi04151309/powerapp/activities/LibraryActivity.kt b/app/src/main/java/io/github/domi04151309/powerapp/activities/LibraryActivity.kt index f63146b..36ccf0b 100644 --- a/app/src/main/java/io/github/domi04151309/powerapp/activities/LibraryActivity.kt +++ b/app/src/main/java/io/github/domi04151309/powerapp/activities/LibraryActivity.kt @@ -23,7 +23,10 @@ class LibraryActivity : BaseActivity() { ) { addPreferencesFromResource(R.xml.pref_about_list) preferenceScreen.removeAll() - resources.getStringArray(R.array.about_libraries).forEach { + val libraries = resources.getStringArray(R.array.about_libraries) + val licenses = resources.getStringArray(R.array.about_libraries_licenses) + if (libraries.size != licenses.size) error("Library array size does not match license array size.") + for (index in libraries.indices) { preferenceScreen.addPreference( Preference(requireContext()).apply { icon = @@ -32,7 +35,8 @@ class LibraryActivity : BaseActivity() { R.drawable.ic_about_library, requireContext().theme, ) - title = it + title = libraries[index] + summary = licenses[index] }, ) } diff --git a/app/src/main/res/values-de/plurals.xml b/app/src/main/res/values-de/plurals.xml deleted file mode 100644 index 5e33d2d..0000000 --- a/app/src/main/res/values-de/plurals.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - %1$d Beitrag - %1$d Beiträge - - diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index adb6af5..5d19d92 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -29,7 +29,7 @@ Über die App App-Version Externe Inhalte - Mitwirkende werden von GitHub geladen. Lesen Sie deren Datenschutzrichtlinie für weitere Informationen. + Externe Inhalte werden von GitHub geladen. Lesen Sie deren Datenschutzrichtlinie für weitere Informationen. Datenschutz-Bestimmungen Mitwirkende Eine Liste der Mitwirkenden diff --git a/app/src/main/res/values/plurals.xml b/app/src/main/res/values/plurals.xml deleted file mode 100644 index 613b8c8..0000000 --- a/app/src/main/res/values/plurals.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - %1$d contribution - %1$d contributions - - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e351d0b..a5a5bcb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -30,7 +30,7 @@ App version %1$s (%2$d) External Content - Contributors are loaded from GitHub. Read their privacy policy for further information. + External content will be loaded from GitHub. Read their privacy policy for further information. Privacy Policy Contributors A list of the contributors @@ -44,10 +44,16 @@ A list of all used libraries - Android AppCompat Library Android Preferences KTX - Android Support Library Annotations - Volley + Annotation + AppCompat + Material Components For Android + + + Apache 2.0 + Apache 2.0 + Apache 2.0 + Apache 2.0