mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-15 02:36:12 -04:00
Prevent app from crashing if no app to view urls is installed
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package eu.darken.capod.common.preferences
|
||||
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.AttributeSet
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.StyleRes
|
||||
import androidx.preference.Preference
|
||||
import eu.darken.capod.common.debug.logging.Logging.Priority.ERROR
|
||||
import eu.darken.capod.common.debug.logging.log
|
||||
import eu.darken.capod.common.debug.logging.logTag
|
||||
|
||||
|
||||
class IntentPreference @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
@AttrRes defStyleAttr: Int = androidx.preference.R.attr.preferenceStyle,
|
||||
@StyleRes defStyleRes: Int = 0,
|
||||
) : Preference(context, attrs, defStyleAttr, defStyleRes) {
|
||||
|
||||
override fun setIntent(_intent: Intent?) {
|
||||
super.setIntent(_intent)
|
||||
_intent?.let {
|
||||
intent
|
||||
setOnPreferenceClickListener {
|
||||
try {
|
||||
context.startActivity(intent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
log(TAG, ERROR) { "Failed to launch $intent: $e" }
|
||||
Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show()
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = logTag("IntentPreference")
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
<PreferenceCategory
|
||||
android:title="@string/general_thank_you_label"
|
||||
app:iconSpaceReserved="false">
|
||||
<Preference
|
||||
<eu.darken.capod.common.preferences.IntentPreference
|
||||
android:key="thanks.translators"
|
||||
android:summary="@string/translators_thanks_description"
|
||||
android:title="@string/translators_thanks_title"
|
||||
@@ -12,8 +12,8 @@
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://crowdin.com/project/capod/activity-stream" />
|
||||
</Preference>
|
||||
<Preference
|
||||
</eu.darken.capod.common.preferences.IntentPreference>
|
||||
<eu.darken.capod.common.preferences.IntentPreference
|
||||
android:key="thanks.maxpatchs"
|
||||
android:summary="Thanks for the lovely icons."
|
||||
android:title="Max Patchs"
|
||||
@@ -21,8 +21,8 @@
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://twitter.com/maxpatchs" />
|
||||
</Preference>
|
||||
<Preference
|
||||
</eu.darken.capod.common.preferences.IntentPreference>
|
||||
<eu.darken.capod.common.preferences.IntentPreference
|
||||
android:key="thanks.openpods"
|
||||
android:summary="Pioneering AirPod support on Android"
|
||||
android:title="OpenPods project"
|
||||
@@ -30,8 +30,8 @@
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://github.com/adolfintel/OpenPods" />
|
||||
</Preference>
|
||||
<Preference
|
||||
</eu.darken.capod.common.preferences.IntentPreference>
|
||||
<eu.darken.capod.common.preferences.IntentPreference
|
||||
android:key="thanks.furiousmac"
|
||||
android:summary="Research on the continuity protocol"
|
||||
android:title="FuriousMAC"
|
||||
@@ -39,13 +39,13 @@
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://github.com/furiousMAC/continuity" />
|
||||
</Preference>
|
||||
</eu.darken.capod.common.preferences.IntentPreference>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/settings_licenses_label"
|
||||
app:iconSpaceReserved="false">
|
||||
<Preference
|
||||
<eu.darken.capod.common.preferences.IntentPreference
|
||||
android:key="license.glide"
|
||||
android:summary="An image loading and caching library for Android focused on smooth scrolling. (Multiple licenses)"
|
||||
android:title="Glide"
|
||||
@@ -53,8 +53,8 @@
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://github.com/bumptech/glide" />
|
||||
</Preference>
|
||||
<Preference
|
||||
</eu.darken.capod.common.preferences.IntentPreference>
|
||||
<eu.darken.capod.common.preferences.IntentPreference
|
||||
android:key="license.materialdesignicons"
|
||||
android:summary="materialdesignicons.com (SIL Open Font License 1.1 / Attribution 4.0 International)"
|
||||
android:title="Material Design Icons"
|
||||
@@ -62,8 +62,8 @@
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://github.com/Templarian/MaterialDesign" />
|
||||
</Preference>
|
||||
<Preference
|
||||
</eu.darken.capod.common.preferences.IntentPreference>
|
||||
<eu.darken.capod.common.preferences.IntentPreference
|
||||
android:key="license.zwiconiconset"
|
||||
android:summary="Creative Commons Attribution 4.0 International"
|
||||
android:title="Zwicon Icon Set"
|
||||
@@ -71,8 +71,8 @@
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://iconduck.com/sets/zwicon-icon-set" />
|
||||
</Preference>
|
||||
<Preference
|
||||
</eu.darken.capod.common.preferences.IntentPreference>
|
||||
<eu.darken.capod.common.preferences.IntentPreference
|
||||
android:key="license.kotlin"
|
||||
android:summary="The Kotlin Programming Language. (APACHE 2.0)"
|
||||
android:title="Kotlin"
|
||||
@@ -80,8 +80,8 @@
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://github.com/JetBrains/kotlin" />
|
||||
</Preference>
|
||||
<Preference
|
||||
</eu.darken.capod.common.preferences.IntentPreference>
|
||||
<eu.darken.capod.common.preferences.IntentPreference
|
||||
android:key="license.dagger"
|
||||
android:summary="A fast dependency injector for Android and Java. (APACHE 2.0)"
|
||||
android:title="Dagger"
|
||||
@@ -89,8 +89,8 @@
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://github.com/google/dagger" />
|
||||
</Preference>
|
||||
<Preference
|
||||
</eu.darken.capod.common.preferences.IntentPreference>
|
||||
<eu.darken.capod.common.preferences.IntentPreference
|
||||
android:key="license.moshi"
|
||||
android:summary="A modern JSON library for Kotlin and Java. (APACHE 2.0)"
|
||||
android:title="Moshi"
|
||||
@@ -98,8 +98,8 @@
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://github.com/square/moshi" />
|
||||
</Preference>
|
||||
<Preference
|
||||
</eu.darken.capod.common.preferences.IntentPreference>
|
||||
<eu.darken.capod.common.preferences.IntentPreference
|
||||
android:key="android.android"
|
||||
android:summary="Android Open Source Project (APACHE 2.0)"
|
||||
android:title="Android"
|
||||
@@ -107,8 +107,8 @@
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://source.android.com/source/licenses.html" />
|
||||
</Preference>
|
||||
<Preference
|
||||
</eu.darken.capod.common.preferences.IntentPreference>
|
||||
<eu.darken.capod.common.preferences.IntentPreference
|
||||
android:key="android.logo"
|
||||
android:summary="The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License."
|
||||
android:title="Android"
|
||||
@@ -116,6 +116,6 @@
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://developer.android.com/distribute/tools/promote/brand.html" />
|
||||
</Preference>
|
||||
</eu.darken.capod.common.preferences.IntentPreference>
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
@@ -20,7 +20,7 @@
|
||||
app:title="@string/settings_support_label" />
|
||||
|
||||
<PreferenceCategory android:title="@string/settings_category_other_label">
|
||||
<Preference
|
||||
<eu.darken.capod.common.preferences.IntentPreference
|
||||
android:icon="@drawable/ic_changelog_onsurface"
|
||||
android:key="core.changelog"
|
||||
android:title="@string/changelog_label"
|
||||
@@ -28,9 +28,9 @@
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://github.com/d4rken-org/capod/releases/latest" />
|
||||
</Preference>
|
||||
</eu.darken.capod.common.preferences.IntentPreference>
|
||||
|
||||
<Preference
|
||||
<eu.darken.capod.common.preferences.IntentPreference
|
||||
android:icon="@drawable/ic_baseline_translate_24"
|
||||
android:key="core.translation"
|
||||
android:title="@string/help_translate_label"
|
||||
@@ -38,7 +38,7 @@
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://crowdin.com/project/capod" />
|
||||
</Preference>
|
||||
</eu.darken.capod.common.preferences.IntentPreference>
|
||||
|
||||
<Preference
|
||||
android:icon="@drawable/ic_heart"
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<Preference
|
||||
<eu.darken.capod.common.preferences.IntentPreference
|
||||
android:icon="@drawable/ic_discord_onsurface"
|
||||
android:summary="@string/discord_description"
|
||||
android:title="@string/discord_label">
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://discord.gg/rrxxng35jq" />
|
||||
</Preference>
|
||||
<Preference
|
||||
</eu.darken.capod.common.preferences.IntentPreference>
|
||||
<eu.darken.capod.common.preferences.IntentPreference
|
||||
android:icon="@drawable/ic_github_onsurface"
|
||||
android:summary="@string/issue_tracker_description"
|
||||
android:title="@string/issue_tracker_label">
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:data="https://github.com/d4rken-org/capod/issues" />
|
||||
</Preference>
|
||||
</eu.darken.capod.common.preferences.IntentPreference>
|
||||
|
||||
<PreferenceCategory app:title="@string/settings_category_other_label">
|
||||
<Preference
|
||||
|
||||
Reference in New Issue
Block a user