Show sign in button for HTTP 401

pull/1230/head
Alex Baker 5 years ago
parent f4a6deb93b
commit 5621a268d0

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools">
<string name="app_name" tools:ignore="PrivateResource">Tasks Debug</string> <string name="app_name" tools:ignore="PrivateResource">Tasks Debug</string>
<string name="tasks_caldav_url">https://192.168.1.120:8443</string> <string name="tasks_caldav_url">https://caldav.tasks.org</string>
<string name="debug_strict_mode_thread">Strict mode - Thread</string> <string name="debug_strict_mode_thread">Strict mode - Thread</string>
<string name="debug_strict_mode_vm">Strict mode - VM</string> <string name="debug_strict_mode_vm">Strict mode - VM</string>
<string name="debug_leakcanary">LeakCanary</string> <string name="debug_leakcanary">LeakCanary</string>

@ -20,7 +20,9 @@ import org.tasks.billing.PurchaseDialog
import org.tasks.data.CaldavAccount import org.tasks.data.CaldavAccount
import org.tasks.data.CaldavDao import org.tasks.data.CaldavDao
import org.tasks.injection.InjectingPreferenceFragment import org.tasks.injection.InjectingPreferenceFragment
import org.tasks.preferences.IconPreference
import java.net.HttpURLConnection.HTTP_PAYMENT_REQUIRED import java.net.HttpURLConnection.HTTP_PAYMENT_REQUIRED
import java.net.HttpURLConnection.HTTP_UNAUTHORIZED
import javax.inject.Inject import javax.inject.Inject
@AndroidEntryPoint @AndroidEntryPoint
@ -43,7 +45,7 @@ class TasksAccount : InjectingPreferenceFragment() {
caldavAccount.error = null caldavAccount.error = null
caldavDao.update(caldavAccount) caldavDao.update(caldavAccount)
} }
refreshSubscription() refreshUi()
} }
} }
} }
@ -78,6 +80,8 @@ class TasksAccount : InjectingPreferenceFragment() {
billingClient.queryPurchases() billingClient.queryPurchases()
false false
} }
refreshUi()
} }
private fun removeAccount() = lifecycleScope.launch { private fun removeAccount() = lifecycleScope.launch {
@ -92,7 +96,7 @@ class TasksAccount : InjectingPreferenceFragment() {
localBroadcastManager.registerPurchaseReceiver(purchaseReceiver) localBroadcastManager.registerPurchaseReceiver(purchaseReceiver)
localBroadcastManager.registerRefreshListReceiver(purchaseReceiver) localBroadcastManager.registerRefreshListReceiver(purchaseReceiver)
refreshSubscription() refreshUi()
} }
override fun onPause() { override fun onPause() {
@ -101,7 +105,12 @@ class TasksAccount : InjectingPreferenceFragment() {
localBroadcastManager.unregisterReceiver(purchaseReceiver) localBroadcastManager.unregisterReceiver(purchaseReceiver)
} }
private fun refreshSubscription() { private fun refreshUi() {
(findPreference(R.string.sign_in_with_google) as IconPreference).apply {
isVisible = caldavAccount.error.isLoggedOut()
iconVisible = true
}
if (BuildConfig.FLAVOR == "generic") { if (BuildConfig.FLAVOR == "generic") {
return return
} }
@ -158,6 +167,9 @@ class TasksAccount : InjectingPreferenceFragment() {
return fragment return fragment
} }
private fun String?.isLoggedOut(): Boolean =
this?.startsWith("HTTP $HTTP_UNAUTHORIZED") == true
private fun String?.isPaymentRequired(): Boolean = private fun String?.isPaymentRequired(): Boolean =
this?.startsWith("HTTP $HTTP_PAYMENT_REQUIRED") == true this?.startsWith("HTTP $HTTP_PAYMENT_REQUIRED") == true
} }

@ -667,4 +667,5 @@ File %1$s contained %2$s.\n\n
<string name="follow_reddit">Follow r/tasks</string> <string name="follow_reddit">Follow r/tasks</string>
<string name="authorization_cancelled">Authorization cancelled</string> <string name="authorization_cancelled">Authorization cancelled</string>
<string name="sign_in_with_google">Sign in with Google</string> <string name="sign_in_with_google">Sign in with Google</string>
<string name="authentication_required">Authentication required</string>
</resources> </resources>

@ -4,9 +4,11 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:key="@string/preference_screen"> android:key="@string/preference_screen">
<Preference <org.tasks.preferences.IconPreference
android:key="@string/sign_in_with_google" android:key="@string/sign_in_with_google"
android:layout="@layout/preference_icon"
android:title="@string/sign_in_with_google" android:title="@string/sign_in_with_google"
android:summary="@string/authentication_required"
app:isPreferenceVisible="false" app:isPreferenceVisible="false"
tools:isPreferenceVisible="true"/> tools:isPreferenceVisible="true"/>

Loading…
Cancel
Save