add auth and not auth method for generating po tokens

pull/933/head
deniscerri 10 months ago
parent 67cdbb5155
commit fb1801cc4f
No known key found for this signature in database
GPG Key ID: 95C43D517D830350

@ -2,6 +2,7 @@ package com.deniscerri.ytdl.ui.more.settings.advanced.generateyoutubepotokens
import android.app.Activity import android.app.Activity
import android.content.Context.INPUT_METHOD_SERVICE import android.content.Context.INPUT_METHOD_SERVICE
import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.os.Bundle import android.os.Bundle
@ -194,41 +195,39 @@ class GenerateYoutubePoTokensFragment : Fragment() {
private fun showBottomSheet(){ private fun showBottomSheet(){
lifecycleScope.launch { lifecycleScope.launch {
val layout = BottomSheetDialog(requireContext()) val dialog = MaterialAlertDialogBuilder(requireContext())
layout.requestWindowFeature(Window.FEATURE_NO_TITLE) dialog.setTitle(getString(R.string.generate_potokens))
layout.setContentView(R.layout.generate_po_token_url_bottom_sheet)
val text = """
val editText = layout.findViewById<EditText>(R.id.url_edittext)!! Auth
val text = preferences.getString("genenerate_youtube_po_token_preferred_url", "https://youtube.com/account") -----------------------
editText.setText(text) 1. Click 'Auth' to open the sign in page in WebView.
editText.setSelection(editText.text.length) 2. Sign in to your Google Account.
3. Play any video that supports auto-translated subtitles.
val regenerateBtn = layout.findViewById<MaterialButton>(R.id.getPoTokenBtn)!! 4. Turn on auto-translated subtitles and see if it works.
4.1 If auto-translated subtitles don't work, switch to another video that supports auto-translated subtitles and try step 4 again.
editText.doOnTextChanged { text, start, before, count -> 5. Click OK.
regenerateBtn.isEnabled = editText.text.toString().isYoutubeURL()
No Auth
-----------------------
1. Click 'No Auth' to open the video in WebView.
2. Play the video for at least 3 seconds.
3. Click OK.
""".trimIndent()
dialog.setMessage(text)
dialog.setNegativeButton("No Auth") { dialogInterface: DialogInterface, _: Int ->
val intent = Intent(requireContext(), PoTokenWebViewLoginActivity::class.java)
intent.putExtra("url", "https://www.youtube.com/watch?v=aqz-KE-bpKQ")
webPoTokenResultLauncher.launch(intent)
} }
regenerateBtn.setOnClickListener { dialog.setPositiveButton("Auth") { dialogInterface: DialogInterface, _: Int ->
layout.dismiss()
val intent = Intent(requireContext(), PoTokenWebViewLoginActivity::class.java) val intent = Intent(requireContext(), PoTokenWebViewLoginActivity::class.java)
intent.putExtra("url", editText.text.toString()) intent.putExtra("url", "https://www.youtube.com/account")
webPoTokenResultLauncher.launch(intent) webPoTokenResultLauncher.launch(intent)
} }
dialog.show()
val imm = requireActivity().getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
editText.postDelayed({
editText.requestFocus()
imm.showSoftInput(editText, 0)
}, 300)
layout.show()
layout.behavior.state = BottomSheetBehavior.STATE_EXPANDED
layout.window!!.setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
} }
} }

Loading…
Cancel
Save