Open web links in custom tabs

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

@ -6,9 +6,13 @@ import android.content.Intent
import android.content.Intent.ACTION_VIEW import android.content.Intent.ACTION_VIEW
import android.net.Uri import android.net.Uri
import android.widget.Toast import android.widget.Toast
import androidx.browser.customtabs.CustomTabsIntent
import org.tasks.R import org.tasks.R
object Context { object Context {
private const val HTTP = "http"
private const val HTTPS = "https"
fun Context.safeStartActivity(intent: Intent) { fun Context.safeStartActivity(intent: Intent) {
try { try {
startActivity(intent) startActivity(intent)
@ -20,7 +24,22 @@ object Context {
fun Context.openUri(resId: Int, vararg formatArgs: Any) = openUri(getString(resId, formatArgs)) fun Context.openUri(resId: Int, vararg formatArgs: Any) = openUri(getString(resId, formatArgs))
fun Context.openUri(url: String?) = 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) = fun Context.toast(resId: Int, vararg formatArgs: Any, duration: Int = Toast.LENGTH_LONG) =
toast(getString(resId, formatArgs), duration) toast(getString(resId, formatArgs), duration)

@ -10,6 +10,7 @@ import androidx.preference.PreferenceScreen
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.tasks.R import org.tasks.R
import org.tasks.dialogs.DialogBuilder import org.tasks.dialogs.DialogBuilder
import org.tasks.extensions.Context.openUri
import org.tasks.preferences.Device import org.tasks.preferences.Device
import org.tasks.themes.DrawableUtil import org.tasks.themes.DrawableUtil
import javax.inject.Inject import javax.inject.Inject
@ -102,4 +103,10 @@ abstract class InjectingPreferenceFragment : PreferenceFragmentCompat() {
protected fun findPreference(@StringRes prefId: Int): Preference = protected fun findPreference(@StringRes prefId: Int): Preference =
findPreference(getString(prefId))!! 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.lastBackup.observe(this, this::updateLastBackup)
viewModel.lastDriveBackup.observe(this, this::updateDriveBackup) viewModel.lastDriveBackup.observe(this, this::updateDriveBackup)
viewModel.lastAndroidBackup.observe(this, this::updateAndroidBackup) viewModel.lastAndroidBackup.observe(this, this::updateAndroidBackup)

@ -60,7 +60,16 @@ class HelpAndFeedback : InjectingPreferenceFragment() {
) )
} else if (!firebase.noChurn()) { } else if (!firebase.noChurn()) {
remove(R.string.rate_tasks) 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 override fun getMenu() = 0

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

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

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

@ -32,6 +32,13 @@
<string name="url_app_passwords">https://tasks.org/passwords</string> <string name="url_app_passwords">https://tasks.org/passwords</string>
<string name="url_sharing">https://tasks.org/sharing</string> <string name="url_sharing">https://tasks.org/sharing</string>
<string name="url_filters">https://tasks.org/filters</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_morning">date_shortcut_morning</string>
<string name="p_date_shortcut_afternoon">date_shortcut_afternoon</string> <string name="p_date_shortcut_afternoon">date_shortcut_afternoon</string>

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

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

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

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

@ -31,11 +31,7 @@
<Preference <Preference
android:icon="@drawable/ic_open_in_new_24px" android:icon="@drawable/ic_open_in_new_24px"
android:key="@string/app_passwords_more_info" android:key="@string/app_passwords_more_info"
android:summary="@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>
<EditTextPreference <EditTextPreference
android:icon="@drawable/ic_outline_add_24px" android:icon="@drawable/ic_outline_add_24px"

Loading…
Cancel
Save