From 1c7664c11477fdd0324ad6a0b33cf4db0a44b687 Mon Sep 17 00:00:00 2001 From: zechs Date: Tue, 6 Dec 2022 18:03:17 +0530 Subject: [PATCH 1/7] change `redirect_uri` --- app/src/main/java/zechs/drive/stream/utils/util/Constants.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/zechs/drive/stream/utils/util/Constants.kt b/app/src/main/java/zechs/drive/stream/utils/util/Constants.kt index c31bf10..5050833 100644 --- a/app/src/main/java/zechs/drive/stream/utils/util/Constants.kt +++ b/app/src/main/java/zechs/drive/stream/utils/util/Constants.kt @@ -5,14 +5,14 @@ import zechs.drive.stream.BuildConfig class Constants { companion object { const val GITHUB_API = "https://api.github.com" - const val GOOGLE_API = "https://www.googleapis.com/" + const val GOOGLE_API = "https://www.googleapis.com" const val DRIVE_API = "${GOOGLE_API}/drive/v3" const val GOOGLE_ACCOUNTS_URL = "https://accounts.google.com" const val CLIENT_ID = BuildConfig.CLIENT_ID const val CLIENT_SECRET = BuildConfig.CLIENT_SECRET - const val REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob" + const val REDIRECT_URI = "http://127.0.0.1:53682" private const val SCOPES = "https://www.googleapis.com/auth/drive" const val AUTH_URL = "${GOOGLE_ACCOUNTS_URL}/o/oauth2/auth?" + From 1c5c4dfaaf9960ad3aab16a64fd950cfd21328ac Mon Sep 17 00:00:00 2001 From: zechs Date: Tue, 6 Dec 2022 18:03:53 +0530 Subject: [PATCH 2/7] additional ui hints for new auth-uri format --- app/src/main/res/layout/dialog_code.xml | 19 ++++++++++++++++++- app/src/main/res/values/strings.xml | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/layout/dialog_code.xml b/app/src/main/res/layout/dialog_code.xml index 337d8cf..14c6000 100644 --- a/app/src/main/res/layout/dialog_code.xml +++ b/app/src/main/res/layout/dialog_code.xml @@ -35,6 +35,23 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> + + app:layout_constraintTop_toBottomOf="@+id/tvExample"> Please enter authorization code Play using Newer version of app is available. Click to download. + Ex: http://127.0.0.1:53682/?code=4/0BX2XfWi1VC9Iadsaa1hIX80rd17crGFCgyHgR_8rwkrIRJJf18LlSGbBWeg0wbZJdEZ3tm3A \ No newline at end of file From 6a9f57ec0696d6cfd8d95ee91f69248268642faa Mon Sep 17 00:00:00 2001 From: zechs Date: Tue, 6 Dec 2022 18:04:49 +0530 Subject: [PATCH 3/7] handle auth-uri input --- .../zechs/drive/stream/ui/signin/SignInFragment.kt | 4 ++-- .../zechs/drive/stream/ui/signin/SignInViewModel.kt | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/zechs/drive/stream/ui/signin/SignInFragment.kt b/app/src/main/java/zechs/drive/stream/ui/signin/SignInFragment.kt index 993dbb7..e49a082 100644 --- a/app/src/main/java/zechs/drive/stream/ui/signin/SignInFragment.kt +++ b/app/src/main/java/zechs/drive/stream/ui/signin/SignInFragment.kt @@ -90,8 +90,8 @@ class SignInFragment : BaseFragment() { if (_codeDialog == null) { _codeDialog = DialogCode( context = requireContext(), - onSubmitClickListener = { code -> - viewModel.requestRefreshToken(code) + onSubmitClickListener = { codeUri -> + viewModel.requestRefreshToken(codeUri) codeDialog.dismiss() } ) diff --git a/app/src/main/java/zechs/drive/stream/ui/signin/SignInViewModel.kt b/app/src/main/java/zechs/drive/stream/ui/signin/SignInViewModel.kt index 6a4e553..d9f3550 100644 --- a/app/src/main/java/zechs/drive/stream/ui/signin/SignInViewModel.kt +++ b/app/src/main/java/zechs/drive/stream/ui/signin/SignInViewModel.kt @@ -1,5 +1,6 @@ package zechs.drive.stream.ui.signin +import android.net.Uri import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel @@ -22,11 +23,16 @@ class SignInViewModel @Inject constructor( get() = _loginStatus fun requestRefreshToken( - authCode: String + authCodeUri: String ) = viewModelScope.launch { _loginStatus.postValue(Resource.Loading()) - val response = driveRepository.get().fetchRefreshToken(authCode) - _loginStatus.postValue(response) + val authCode = Uri.parse(authCodeUri).getQueryParameter("code") + if (authCode == null) { + _loginStatus.postValue(Resource.Error("Authorization code not found, please check url")) + } else { + val response = driveRepository.get().fetchRefreshToken(authCode) + _loginStatus.postValue(response) + } } } From fc541218b747312dfcb88c632a5fb0f47c614ea8 Mon Sep 17 00:00:00 2001 From: zechs Date: Tue, 6 Dec 2022 18:05:13 +0530 Subject: [PATCH 4/7] use browser instead of chrome-tabs --- .../java/zechs/drive/stream/ui/signin/SignInFragment.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/zechs/drive/stream/ui/signin/SignInFragment.kt b/app/src/main/java/zechs/drive/stream/ui/signin/SignInFragment.kt index e49a082..8e5a389 100644 --- a/app/src/main/java/zechs/drive/stream/ui/signin/SignInFragment.kt +++ b/app/src/main/java/zechs/drive/stream/ui/signin/SignInFragment.kt @@ -1,5 +1,6 @@ package zechs.drive.stream.ui.signin +import android.content.Intent import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.net.Uri @@ -9,7 +10,6 @@ import android.view.View import android.view.ViewGroup import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.WRAP_CONTENT -import androidx.browser.customtabs.CustomTabsIntent import androidx.core.view.isVisible import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController @@ -53,9 +53,9 @@ class SignInFragment : BaseFragment() { _binding = FragmentSignInBinding.bind(view) binding.signInText.setOnClickListener { - CustomTabsIntent.Builder().build().also { - it.launchUrl(requireContext(), Uri.parse(AUTH_URL)) - } + Intent().setAction(Intent.ACTION_VIEW) + .setData(Uri.parse(AUTH_URL)) + .also { startActivity(it) } } binding.enterCode.setOnClickListener { From 1f83c8c2ca1f6d3cc34057fd49fb9f55c19a2232 Mon Sep 17 00:00:00 2001 From: zechs Date: Tue, 6 Dec 2022 18:05:52 +0530 Subject: [PATCH 5/7] remove dependency --- app/build.gradle | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a5153de..6930975 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -76,9 +76,6 @@ dependencies { def moshi_version = "1.13.0" def retrofit_version = "2.9.0" - // Custom Tabs - implementation "androidx.browser:browser:1.4.0" - // Gson implementation "com.google.code.gson:gson:2.9.0" From d5de97669c7edab13bea424fd8d42241461424f8 Mon Sep 17 00:00:00 2001 From: zechs Date: Tue, 6 Dec 2022 18:13:27 +0530 Subject: [PATCH 6/7] Added prompt for user --- .../java/zechs/drive/stream/ui/signin/SignInFragment.kt | 9 ++++++++- app/src/main/res/values/strings.xml | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/zechs/drive/stream/ui/signin/SignInFragment.kt b/app/src/main/java/zechs/drive/stream/ui/signin/SignInFragment.kt index 8e5a389..8447868 100644 --- a/app/src/main/java/zechs/drive/stream/ui/signin/SignInFragment.kt +++ b/app/src/main/java/zechs/drive/stream/ui/signin/SignInFragment.kt @@ -13,6 +13,7 @@ import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import androidx.core.view.isVisible import androidx.fragment.app.activityViewModels import androidx.navigation.fragment.findNavController +import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar import zechs.drive.stream.R import zechs.drive.stream.databinding.FragmentSignInBinding @@ -59,7 +60,13 @@ class SignInFragment : BaseFragment() { } binding.enterCode.setOnClickListener { - showCodeDialog() + MaterialAlertDialogBuilder(requireContext()) + .setTitle("Please note") + .setMessage(getString(R.string.important_note_message)) + .setPositiveButton("Continue") { dialog, _ -> + dialog.dismiss() + showCodeDialog() + }.show() } loginObserver() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 04e26b4..3d2bc7b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -44,4 +44,5 @@ Play using Newer version of app is available. Click to download. Ex: http://127.0.0.1:53682/?code=4/0BX2XfWi1VC9Iadsaa1hIX80rd17crGFCgyHgR_8rwkrIRJJf18LlSGbBWeg0wbZJdEZ3tm3A + Due to recent changes made by Google, it is no longer possible to direct to a page to directly copy authorization code.\n\nYou will need to copy the entire url from the browser address bar. This will page will not load and will show an error.\n\nPlease copy the entire url from the address bar and paste it in the dialog box. \ No newline at end of file From 92db0e7e58af3768bc6e57ab4a2503306fb6c40f Mon Sep 17 00:00:00 2001 From: zechs Date: Tue, 6 Dec 2022 18:16:40 +0530 Subject: [PATCH 7/7] updated strings --- app/src/main/java/zechs/drive/stream/ui/code/DialogCode.kt | 2 +- app/src/main/res/layout/dialog_code.xml | 4 ++-- app/src/main/res/values/strings.xml | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/zechs/drive/stream/ui/code/DialogCode.kt b/app/src/main/java/zechs/drive/stream/ui/code/DialogCode.kt index ad45902..27e99a2 100644 --- a/app/src/main/java/zechs/drive/stream/ui/code/DialogCode.kt +++ b/app/src/main/java/zechs/drive/stream/ui/code/DialogCode.kt @@ -32,7 +32,7 @@ class DialogCode( val authCode = codeText.editText!!.text.toString() if (authCode.isEmpty()) { - showToast(context.getString(R.string.please_enter_auth_code)) + showToast(context.getString(R.string.please_enter_auth_url)) } else { onSubmitClickListener.invoke(authCode) } diff --git a/app/src/main/res/layout/dialog_code.xml b/app/src/main/res/layout/dialog_code.xml index 14c6000..44c5047 100644 --- a/app/src/main/res/layout/dialog_code.xml +++ b/app/src/main/res/layout/dialog_code.xml @@ -27,7 +27,7 @@ android:clickable="false" android:focusable="false" android:fontFamily="@font/roboto_medium" - android:text="@string/authorization_code" + android:text="@string/authorization_url" android:textColor="@color/textColor" android:textSize="21sp" app:layout_constraintEnd_toEndOf="parent" @@ -61,7 +61,7 @@ android:layout_marginStart="24dp" android:layout_marginTop="16dp" android:layout_marginEnd="24dp" - android:hint="@string/authorization_code" + android:hint="@string/authorization_url_hint" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/tvExample"> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3d2bc7b..fcdd103 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -38,11 +38,12 @@ Video Sign in Enter authorization code? - Authorization code + Authorization url + Authorization url Submit - Please enter authorization code + Please enter authorization url Play using Newer version of app is available. Click to download. Ex: http://127.0.0.1:53682/?code=4/0BX2XfWi1VC9Iadsaa1hIX80rd17crGFCgyHgR_8rwkrIRJJf18LlSGbBWeg0wbZJdEZ3tm3A - Due to recent changes made by Google, it is no longer possible to direct to a page to directly copy authorization code.\n\nYou will need to copy the entire url from the browser address bar. This will page will not load and will show an error.\n\nPlease copy the entire url from the address bar and paste it in the dialog box. + Due to recent changes made by Google, it is no longer possible to directly copy authorization code from the webpage after completion of OAuth Flow.\n\nYou will need to copy the entire url from the browser address bar. This page will not load and will show an error.\n\nPlease copy the entire url from the address bar and paste it in the dialog box. \ No newline at end of file