Open web links in custom tabs

pull/1432/head
Alex Baker 4 years ago
parent 0cbab11d2c
commit d2c4f5bbe1

@ -6,9 +6,13 @@ import android.content.Intent
import android.content.Intent.ACTION_VIEW
import android.net.Uri
import android.widget.Toast
import androidx.browser.customtabs.CustomTabsIntent
import org.tasks.R
object Context {
private const val HTTP = "http"
private const val HTTPS = "https"
fun Context.safeStartActivity(intent: Intent) {
try {
startActivity(intent)
@ -20,7 +24,22 @@ object Context {
fun Context.openUri(resId: Int, vararg formatArgs: Any) = openUri(getString(resId, formatArgs))
fun Context.openUri(url: String?) =
url?.let { safeStartActivity(Intent(ACTION_VIEW, Uri.parse(it))) }
url?.let { Uri.parse(it) }?.let {
when {
it.scheme.equals(HTTPS, true) || it.scheme.equals(HTTP, true) ->
try {
CustomTabsIntent.Builder()
.setUrlBarHidingEnabled(true)
.setShowTitle(true)
.setShareState(CustomTabsIntent.SHARE_STATE_ON)
.build()
.launchUrl(this, it)
} catch (e: ActivityNotFoundException) {
toast(R.string.no_app_found)
}
else -> safeStartActivity(Intent(ACTION_VIEW, it))
}
}
fun Context.toast(resId: Int, vararg formatArgs: Any, duration: Int = Toast.LENGTH_LONG) =
toast(getString(resId, formatArgs), duration)

@ -10,6 +10,7 @@ import androidx.preference.PreferenceScreen
import kotlinx.coroutines.launch
import org.tasks.R
import org.tasks.dialogs.DialogBuilder
import org.tasks.extensions.Context.openUri
import org.tasks.preferences.Device
import org.tasks.themes.DrawableUtil
import javax.inject.Inject
@ -102,4 +103,10 @@ abstract class InjectingPreferenceFragment : PreferenceFragmentCompat() {
protected fun findPreference(@StringRes prefId: Int): Preference =
findPreference(getString(prefId))!!
protected fun openUrl(prefId: Int, url: Int) =
findPreference(prefId).setOnPreferenceClickListener {
context?.openUri(url)
false
}
}

@ -88,6 +88,8 @@ class Backups : InjectingPreferenceFragment() {
}
}
openUrl(R.string.documentation, R.string.url_backups)
viewModel.lastBackup.observe(this, this::updateLastBackup)
viewModel.lastDriveBackup.observe(this, this::updateDriveBackup)
viewModel.lastAndroidBackup.observe(this, this::updateAndroidBackup)

@ -60,7 +60,16 @@ class HelpAndFeedback : InjectingPreferenceFragment() {
)
} else if (!firebase.noChurn()) {
remove(R.string.rate_tasks)
} else {
openUrl(R.string.rate_tasks, R.string.market_url)
}
openUrl(R.string.documentation, R.string.url_documentation)
openUrl(R.string.issue_tracker, R.string.url_issue_tracker)
openUrl(R.string.follow_reddit, R.string.url_reddit)
openUrl(R.string.follow_twitter, R.string.url_twitter)
openUrl(R.string.source_code, R.string.url_source_code)
openUrl(R.string.privacy_policy, R.string.url_privacy_policy)
}
override fun getMenu() = 0

@ -124,6 +124,8 @@ class LookAndFeel : InjectingPreferenceFragment() {
dialog.show(parentFragmentManager, FRAG_TAG_LOCALE_PICKER)
false
}
openUrl(R.string.translations, R.string.url_translations)
}
override fun onResume() {

@ -131,6 +131,8 @@ class Notifications : InjectingPreferenceFragment() {
checkBatteryOptimizations()
openUrl(R.string.troubleshooting, R.string.url_notifications)
requires(AndroidUtilities.atLeastOreo(), R.string.more_settings)
requires(
AndroidUtilities.preOreo(),

@ -91,6 +91,8 @@ class TasksAccount : BaseAccountPreference() {
viewModel.requestNewPassword(caldavAccount, description as String)
false
}
openUrl(R.string.app_passwords_more_info, R.string.url_app_passwords)
}
override suspend fun removeAccount() {

@ -32,6 +32,13 @@
<string name="url_app_passwords">https://tasks.org/passwords</string>
<string name="url_sharing">https://tasks.org/sharing</string>
<string name="url_filters">https://tasks.org/filters</string>
<string name="url_documentation">https://tasks.org/</string>
<string name="url_issue_tracker">https://github.com/tasks/tasks/issues</string>
<string name="url_source_code">https://tasks.org/source</string>
<string name="url_privacy_policy">https://tasks.org/privacy.html</string>
<string name="url_backups">https://tasks.org/backups</string>
<string name="url_translations">https://tasks.org/translations</string>
<string name="url_notifications">https://tasks.org/notifications</string>
<string name="p_date_shortcut_morning">date_shortcut_morning</string>
<string name="p_date_shortcut_afternoon">date_shortcut_afternoon</string>

@ -10,30 +10,20 @@
<Preference
android:key="@string/rate_tasks"
android:title="@string/rate_tasks"
app:icon="@drawable/ic_outline_star_border_24px">
<intent
android:action="android.intent.action.VIEW"
android:data="@string/market_url" />
</Preference>
app:icon="@drawable/ic_outline_star_border_24px" />
<PreferenceCategory
android:title="@string/support">
<Preference
android:key="@string/documentation"
android:title="@string/documentation"
app:icon="@drawable/ic_outline_help_outline_24px">
<intent
android:action="android.intent.action.VIEW"
android:data="https://tasks.org" />
</Preference>
app:icon="@drawable/ic_outline_help_outline_24px"/>
<Preference
android:key="@string/issue_tracker"
android:title="@string/issue_tracker"
app:icon="@drawable/ic_outline_bug_report_24px">
<intent
android:action="android.intent.action.VIEW"
android:data="https://github.com/tasks/tasks/issues" />
</Preference>
app:icon="@drawable/ic_outline_bug_report_24px" />
<Preference
android:key="@string/contact_developer"
@ -48,20 +38,12 @@
<Preference
android:key="@string/follow_reddit"
android:title="@string/follow_reddit"
app:icon="@drawable/ic_reddit_share_silhouette">
<intent
android:action="android.intent.action.VIEW"
android:data="@string/url_reddit" />
</Preference>
app:icon="@drawable/ic_reddit_share_silhouette" />
<Preference
android:key="@string/follow_twitter"
android:title="@string/follow_twitter"
app:icon="@drawable/ic_twitter_logo_black">
<intent
android:action="android.intent.action.VIEW"
android:data="@string/url_twitter" />
</Preference>
app:icon="@drawable/ic_twitter_logo_black" />
<Preference
android:key="@string/chat_freenode"
@ -78,13 +60,10 @@
android:title="@string/open_source">
<Preference
android:key="@string/source_code"
android:summary="@string/license_summary"
android:title="@string/source_code"
app:icon="@drawable/ic_octocat">
<intent
android:action="android.intent.action.VIEW"
android:data="https://tasks.org/source" />
</Preference>
app:icon="@drawable/ic_octocat" />
<Preference
android:title="@string/third_party_licenses"
@ -99,12 +78,9 @@
<PreferenceCategory
android:title="@string/privacy">
<Preference
android:key="@string/privacy_policy"
android:title="@string/privacy_policy"
app:icon="@drawable/ic_outline_perm_identity_24px">
<intent
android:action="android.intent.action.VIEW"
android:data="https://tasks.org/privacy.html" />
</Preference>
app:icon="@drawable/ic_outline_perm_identity_24px" />
<SwitchPreferenceCompat
android:defaultValue="true"

@ -3,14 +3,9 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<Preference
android:key="@string/documentation"
android:title="@string/documentation"
android:icon="@drawable/ic_open_in_new_24px">
<intent
android:action="android.intent.action.VIEW"
android:data="https://tasks.org/backups" />
</Preference>
android:icon="@drawable/ic_open_in_new_24px" />
<Preference
android:key="@string/p_backup_dir"

@ -204,12 +204,9 @@
android:title="@string/language" />
<Preference
android:key="@string/translations"
android:title="@string/translations"
app:icon="@drawable/ic_open_in_new_24px">
<intent
android:action="android.intent.action.VIEW"
android:data="https://tasks.org/translations" />
</Preference>
app:icon="@drawable/ic_open_in_new_24px" />
</PreferenceCategory>

@ -3,15 +3,10 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<Preference
android:key="@string/troubleshooting"
android:icon="@drawable/ic_open_in_new_24px"
android:summary="@string/notification_troubleshooting_summary"
android:title="@string/troubleshooting">
<intent
android:action="android.intent.action.VIEW"
android:data="https://tasks.org/notifications" />
</Preference>
android:title="@string/troubleshooting" />
<Preference
android:key="@string/disable_battery_optimizations"

@ -31,11 +31,7 @@
<Preference
android:icon="@drawable/ic_open_in_new_24px"
android:key="@string/app_passwords_more_info"
android:summary="@string/app_passwords_more_info">
<intent
android:action="android.intent.action.VIEW"
android:data="@string/url_app_passwords" />
</Preference>
android:summary="@string/app_passwords_more_info" />
<EditTextPreference
android:icon="@drawable/ic_outline_add_24px"

Loading…
Cancel
Save