.
This commit is contained in:
parent
b628c88eb2
commit
3ce4247da9
2 changed files with 56 additions and 5 deletions
|
|
@ -31,6 +31,7 @@ import com.deniscerri.ytdl.ui.more.WebViewActivity
|
|||
import com.deniscerri.ytdl.ui.more.settings.SettingsActivity
|
||||
import com.deniscerri.ytdl.ui.more.settings.advanced.generateyoutubepotokens.webview.PoTokenWebViewLoginActivity
|
||||
import com.deniscerri.ytdl.util.Extensions.enableTextHighlight
|
||||
import com.deniscerri.ytdl.util.Extensions.getIDFromYoutubeURL
|
||||
import com.deniscerri.ytdl.util.Extensions.isYoutubeURL
|
||||
import com.deniscerri.ytdl.util.UiUtil
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
|
|
@ -210,15 +211,50 @@ class GenerateYoutubePoTokensFragment : Fragment() {
|
|||
|
||||
No Auth
|
||||
-----------------------
|
||||
1. Click 'No Auth' to open the video in WebView.
|
||||
2. Play the video for at least 3 seconds.
|
||||
1. Click 'No Auth'.
|
||||
2. Write any youtube video url
|
||||
3. Wait for the video to load and 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/embed/aqz-KE-bpKQ")
|
||||
webPoTokenResultLauncher.launch(intent)
|
||||
|
||||
val layout = BottomSheetDialog(requireContext())
|
||||
layout.requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||
layout.setContentView(R.layout.generate_po_token_url_bottom_sheet)
|
||||
|
||||
val editText = layout.findViewById<EditText>(R.id.url_edittext)!!
|
||||
editText.setSelection(editText.text.length)
|
||||
|
||||
val regenerateBtn = layout.findViewById<MaterialButton>(R.id.getPoTokenBtn)!!
|
||||
regenerateBtn.isEnabled = false
|
||||
|
||||
editText.doOnTextChanged { text, start, before, count ->
|
||||
regenerateBtn.isEnabled = editText.text.toString().isYoutubeURL()
|
||||
}
|
||||
|
||||
regenerateBtn.setOnClickListener {
|
||||
layout.dismiss()
|
||||
|
||||
val intent = Intent(requireContext(), PoTokenWebViewLoginActivity::class.java)
|
||||
intent.putExtra("url", "https://www.youtube.com")
|
||||
intent.putExtra("redirect_url", "https://www.youtube.com/embed/${editText.text.toString().getIDFromYoutubeURL()}")
|
||||
webPoTokenResultLauncher.launch(intent)
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
)
|
||||
}
|
||||
|
||||
dialog.setPositiveButton("Auth") { dialogInterface: DialogInterface, _: Int ->
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import android.content.Intent
|
|||
import android.content.SharedPreferences
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.MenuItem
|
||||
import android.webkit.CookieManager
|
||||
import android.webkit.WebSettings
|
||||
|
|
@ -59,6 +61,7 @@ class PoTokenWebViewLoginActivity : BaseActivity() {
|
|||
setContentView(R.layout.webview_activity)
|
||||
|
||||
val url = intent.getStringExtra("url")!!
|
||||
var redirectUrl = intent.getStringExtra("redirect_url")
|
||||
|
||||
cookiesViewModel = ViewModelProvider(this)[CookieViewModel::class.java]
|
||||
lifecycleScope.launch {
|
||||
|
|
@ -98,6 +101,18 @@ class PoTokenWebViewLoginActivity : BaseActivity() {
|
|||
kotlin.runCatching {
|
||||
toolbar.title = view?.title ?: ""
|
||||
}
|
||||
|
||||
webView.evaluateJavascript("(function(){return document.readyState;})()") { value ->
|
||||
if (value?.trim('"') == "complete") {
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
redirectUrl?.apply {
|
||||
webView.loadUrl(this)
|
||||
}
|
||||
redirectUrl = null
|
||||
}, 2500)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue