.
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.SettingsActivity
|
||||||
import com.deniscerri.ytdl.ui.more.settings.advanced.generateyoutubepotokens.webview.PoTokenWebViewLoginActivity
|
import com.deniscerri.ytdl.ui.more.settings.advanced.generateyoutubepotokens.webview.PoTokenWebViewLoginActivity
|
||||||
import com.deniscerri.ytdl.util.Extensions.enableTextHighlight
|
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.Extensions.isYoutubeURL
|
||||||
import com.deniscerri.ytdl.util.UiUtil
|
import com.deniscerri.ytdl.util.UiUtil
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
|
|
@ -210,15 +211,50 @@ class GenerateYoutubePoTokensFragment : Fragment() {
|
||||||
|
|
||||||
No Auth
|
No Auth
|
||||||
-----------------------
|
-----------------------
|
||||||
1. Click 'No Auth' to open the video in WebView.
|
1. Click 'No Auth'.
|
||||||
2. Play the video for at least 3 seconds.
|
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.
|
3. Click OK.
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
dialog.setMessage(text)
|
dialog.setMessage(text)
|
||||||
dialog.setNegativeButton("No Auth") { dialogInterface: DialogInterface, _: Int ->
|
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")
|
val layout = BottomSheetDialog(requireContext())
|
||||||
webPoTokenResultLauncher.launch(intent)
|
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 ->
|
dialog.setPositiveButton("Auth") { dialogInterface: DialogInterface, _: Int ->
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.webkit.CookieManager
|
import android.webkit.CookieManager
|
||||||
import android.webkit.WebSettings
|
import android.webkit.WebSettings
|
||||||
|
|
@ -59,6 +61,7 @@ class PoTokenWebViewLoginActivity : BaseActivity() {
|
||||||
setContentView(R.layout.webview_activity)
|
setContentView(R.layout.webview_activity)
|
||||||
|
|
||||||
val url = intent.getStringExtra("url")!!
|
val url = intent.getStringExtra("url")!!
|
||||||
|
var redirectUrl = intent.getStringExtra("redirect_url")
|
||||||
|
|
||||||
cookiesViewModel = ViewModelProvider(this)[CookieViewModel::class.java]
|
cookiesViewModel = ViewModelProvider(this)[CookieViewModel::class.java]
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
|
|
@ -98,6 +101,18 @@ class PoTokenWebViewLoginActivity : BaseActivity() {
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
toolbar.title = view?.title ?: ""
|
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