feat: add remote sync capability - add info button in login dialog

This commit is contained in:
Martin Filo 2023-05-08 20:24:15 +02:00
parent 0405cdca7f
commit 13d9cee89b
6 changed files with 36 additions and 4 deletions

View file

@ -23,6 +23,7 @@ interface InAppOAuth2API : OAuth2API {
val defaultFilenameValue: String
val defaultRedirectUrl: String
val infoUrl: String?
// should launch intent to acquire token

View file

@ -72,6 +72,7 @@ class GoogleDriveApi(index: Int) :
override val requiresClientId = true
override val defaultFilenameValue = "cloudstreamapp-sync-file"
override val defaultRedirectUrl = "https://chiff.github.io/cloudstream-sync/google-drive"
override val infoUrl = "https://chiff.github.io/cloudstream-sync/google-drive/help.html"
override var isActive: Boolean? = false
override var willQueueSoon: Boolean? = false

View file

@ -23,13 +23,13 @@ abstract class DialogBuilder(
private val btnApply: MaterialButton,
private val btnCancel: MaterialButton,
private val btnAccCreate: MaterialButton?,
private val btnConfirmOauth: MaterialButton?
private val btnInfo: MaterialButton?
) {
fun getTitle() = dialog.getCommonItem(title)!!
fun getBtnApply() = dialog.getCommonItem(btnApply)!!
fun getBtnCancel() = dialog.getCommonItem(btnCancel)!!
fun getBtnAccCreate() = dialog.getCommonItem(btnAccCreate)
fun getBtnConfirm() = dialog.getCommonItem(btnConfirmOauth)
fun getBtnInfo() = dialog.getCommonItem(btnInfo)
private fun <T : View> AlertDialog.getCommonItem(view: T?): T? {
return findViewById(view?.id ?: return null)
@ -122,6 +122,12 @@ abstract class DialogBuilder(
it.nextFocusUpId = createAccount.id
}
displayedItems.firstOrNull()?.let {
val infoButton = getCommonItems(dialog).getBtnInfo() ?: return@let
infoButton.nextFocusDownId = it.id
it.nextFocusUpId = infoButton.id
}
getCommonItems(dialog).getBtnApply().id.let {
displayedItems.lastOrNull()?.nextFocusDownId = it
}

View file

@ -1,14 +1,23 @@
package com.lagradost.cloudstream3.ui.settings.helpers.settings.account
import android.net.Uri
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.fragment.app.FragmentActivity
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.syncproviders.InAppOAuth2API
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
import kotlinx.android.synthetic.main.add_account_input_oauth.*
import kotlinx.android.synthetic.main.add_account_input_oauth.apply_btt
import kotlinx.android.synthetic.main.add_account_input_oauth.cancel_btt
import kotlinx.android.synthetic.main.add_account_input_oauth.info_button
import kotlinx.android.synthetic.main.add_account_input_oauth.login_client_id
import kotlinx.android.synthetic.main.add_account_input_oauth.login_client_secret
import kotlinx.android.synthetic.main.add_account_input_oauth.login_file_name
import kotlinx.android.synthetic.main.add_account_input_oauth.text1
class InAppOAuth2DialogBuilder(
@ -16,7 +25,7 @@ class InAppOAuth2DialogBuilder(
private val activity: FragmentActivity?,
) : DialogBuilder(api, activity, R.style.AlertDialogCustom, R.layout.add_account_input_oauth) {
override fun getCommonItems(dialog: AlertDialog) = with(dialog) {
CommonDialogItems(dialog, text1, apply_btt, cancel_btt, null, null)
CommonDialogItems(dialog, text1, apply_btt, cancel_btt, null, info_button)
}
override fun getVisibilityMap(dialog: AlertDialog): Map<View, Boolean> = with(dialog) {
@ -31,6 +40,12 @@ class InAppOAuth2DialogBuilder(
login_file_name?.isVisible = api.requiresFilename
login_client_id?.isVisible = api.requiresClientId
login_client_secret?.isVisible = api.requiresSecret
info_button?.isGone = api.infoUrl.isNullOrBlank()
info_button?.setOnClickListener {
val customTabIntent = CustomTabsIntent.Builder().setShowTitle(true).build()
customTabIntent.launchUrl(context, Uri.parse(api.infoUrl))
}
}

View file

@ -29,6 +29,14 @@
android:textStyle="bold"
tools:text="Test" />
<com.google.android.material.button.MaterialButton
android:id="@+id/info_button"
style="@style/WhiteButton"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical|end"
android:text="@string/info_button"
app:icon="@drawable/ic_outline_info_24" />
</LinearLayout>

View file

@ -667,4 +667,5 @@
<string name="example_login_file_name_full">Sync file name (optional)</string>
<string name="example_login_redirect_url_full">Oauth redirect url (optional)</string>
<string name="example_redirect_url" translatable="false">https://chiff.github.io/cloudstream-sync/google-drive</string>
<string name="info_button">Info</string>
</resources>