verify login data on start, added german translation
This commit is contained in:
parent
00a6981ae5
commit
9ec4c24e21
|
@ -76,15 +76,11 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
|
|||
private fun load() {
|
||||
EncryptedPreferences.readCredentials(this)
|
||||
|
||||
// make sure credentials are set and valid
|
||||
if (EncryptedPreferences.password.isEmpty()) {
|
||||
Log.i(javaClass.name, "please login!")
|
||||
|
||||
LoginDialog(this).positiveButton {
|
||||
EncryptedPreferences.saveCredentials(login, password, context)
|
||||
}.negativeButton {
|
||||
Log.i(javaClass.name, "Login canceled, exiting.")
|
||||
finish()
|
||||
}.show()
|
||||
showLoginDialog(true)
|
||||
} else if (!AoDParser().login()) {
|
||||
showLoginDialog(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,4 +103,18 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
|
|||
}
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
private fun showLoginDialog(firstTry: Boolean) {
|
||||
LoginDialog(this, firstTry).positiveButton {
|
||||
EncryptedPreferences.saveCredentials(login, password, context)
|
||||
|
||||
if (!AoDParser().login()) {
|
||||
showLoginDialog(false)
|
||||
Log.w(javaClass.name, "Login failed, please try again.")
|
||||
}
|
||||
}.negativeButton {
|
||||
Log.i(javaClass.name, "Login canceled, exiting.")
|
||||
finish()
|
||||
}.show()
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ class AoDParser {
|
|||
val mediaList = arrayListOf<Media>()
|
||||
}
|
||||
|
||||
private fun login() = runBlocking {
|
||||
fun login(): Boolean = runBlocking {
|
||||
|
||||
val userAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0"
|
||||
|
||||
|
@ -57,11 +57,12 @@ class AoDParser {
|
|||
.execute()
|
||||
|
||||
//println(resLogin.body())
|
||||
|
||||
loginSuccess = resLogin.body().contains("Hallo, du bist jetzt angemeldet.")
|
||||
println("Status: ${resLogin.statusCode()} (${resLogin.statusMessage()}), login successful: $loginSuccess")
|
||||
|
||||
sessionCookies = resLogin.cookies()
|
||||
loginSuccess = resLogin.body().contains("Hallo, du bist jetzt angemeldet.")
|
||||
|
||||
Log.i(javaClass.name, "Status: ${resLogin.statusCode()} (${resLogin.statusMessage()}), login successful: $loginSuccess")
|
||||
|
||||
loginSuccess
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,7 +97,7 @@ class AoDParser {
|
|||
mediaList.add(media)
|
||||
}
|
||||
|
||||
println("got ${mediaList.size} anime")
|
||||
Log.i(javaClass.name, "Total library size is: ${mediaList.size}")
|
||||
|
||||
return@withContext mediaList
|
||||
}
|
||||
|
@ -109,7 +110,7 @@ class AoDParser {
|
|||
if (sessionCookies.isEmpty()) login()
|
||||
|
||||
if (!loginSuccess) {
|
||||
println("please log in") // TODO
|
||||
Log.w(javaClass.name, "Login, was not successful.")
|
||||
return@runBlocking listOf()
|
||||
}
|
||||
|
||||
|
@ -127,7 +128,11 @@ class AoDParser {
|
|||
//println("first entry: ${playlists.first()}")
|
||||
//println("csrf token is: $csrfToken")
|
||||
|
||||
return@withContext loadStreamInfo(playlists.first(), csrfToken, media.type)
|
||||
return@withContext if (playlists.size > 0) {
|
||||
loadStreamInfo(playlists.first(), csrfToken, media.type)
|
||||
} else {
|
||||
listOf()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.mosad.teapod.ui.account
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
@ -9,6 +10,7 @@ import com.afollestad.materialdialogs.MaterialDialog
|
|||
import kotlinx.android.synthetic.main.fragment_account.*
|
||||
import org.mosad.teapod.BuildConfig
|
||||
import org.mosad.teapod.R
|
||||
import org.mosad.teapod.parser.AoDParser
|
||||
import org.mosad.teapod.preferences.EncryptedPreferences
|
||||
import org.mosad.teapod.ui.components.LoginDialog
|
||||
|
||||
|
@ -29,12 +31,7 @@ class AccountFragment : Fragment() {
|
|||
|
||||
private fun initActions() {
|
||||
linear_account_login.setOnClickListener {
|
||||
LoginDialog(requireContext()).positiveButton {
|
||||
EncryptedPreferences.saveCredentials(login, password, context)
|
||||
}.show {
|
||||
login = EncryptedPreferences.login
|
||||
password = ""
|
||||
}
|
||||
showLoginDialog(true)
|
||||
}
|
||||
|
||||
linear_about.setOnClickListener {
|
||||
|
@ -44,4 +41,18 @@ class AccountFragment : Fragment() {
|
|||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showLoginDialog(firstTry: Boolean) {
|
||||
LoginDialog(requireContext(), firstTry).positiveButton {
|
||||
EncryptedPreferences.saveCredentials(login, password, context)
|
||||
|
||||
if (!AoDParser().login()) {
|
||||
showLoginDialog(false)
|
||||
Log.w(javaClass.name, "Login failed, please try again.")
|
||||
}
|
||||
}.show {
|
||||
login = EncryptedPreferences.login
|
||||
password = ""
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ import com.afollestad.materialdialogs.customview.customView
|
|||
import com.afollestad.materialdialogs.customview.getCustomView
|
||||
import org.mosad.teapod.R
|
||||
|
||||
class LoginDialog(val context: Context) {
|
||||
class LoginDialog(val context: Context, firstTry: Boolean) {
|
||||
|
||||
private val dialog = MaterialDialog(context, BottomSheet())
|
||||
|
||||
|
@ -43,7 +43,7 @@ class LoginDialog(val context: Context) {
|
|||
|
||||
init {
|
||||
dialog.title(R.string.login)
|
||||
.message(R.string.login_desc)
|
||||
.message(if (firstTry) R.string.login_desc else R.string.login_failed_desc)
|
||||
.customView(R.layout.dialog_login)
|
||||
.positiveButton(R.string.save)
|
||||
.negativeButton(R.string.cancel)
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="title_home">Startseite</string>
|
||||
<string name="title_library">Übersicht</string>
|
||||
<string name="title_search">Suche</string>
|
||||
<string name="title_account">Account</string>
|
||||
|
||||
<!-- search fragment -->
|
||||
<string name="search_hint">Suche nach Filmen und Serien</string>
|
||||
|
||||
<!-- media fragment -->
|
||||
<string name="button_play">Abspielen</string>
|
||||
|
||||
<!-- settings fragment -->
|
||||
<string name="account">Account</string>
|
||||
<string name="account_login_desc">Zum bearbeiten tippen</string>
|
||||
<string name="info">Info</string>
|
||||
|
||||
<!-- dialogs -->
|
||||
<string name="save">speichern</string>
|
||||
<string name="cancel">\@android:string/cancel</string>
|
||||
|
||||
<!-- etc -->
|
||||
<string name="login">Login</string>
|
||||
<string name="login_desc">Um Teapod zu benutzen musst du eingeloggt sein. Die Login-Daten weden verschüsselt aud deinem Gerät gespeichert.</string>
|
||||
<string name="login_failed_desc">Login nicht erfolgreich. Bitte versuche es erneut.</string>
|
||||
<string name="password">Passwort</string>
|
||||
</resources>
|
|
@ -1,5 +1,5 @@
|
|||
<resources>
|
||||
<string name="app_name">Teapod</string>
|
||||
<string name="app_name" translatable="false">Teapod</string>
|
||||
<string name="title_home">Home</string>
|
||||
<string name="title_library">Library</string>
|
||||
<string name="title_search">Search</string>
|
||||
|
@ -10,17 +10,17 @@
|
|||
|
||||
<!-- media fragment -->
|
||||
<string name="button_play">Play</string>
|
||||
<string name="text_title_ex">A Silent Voice</string>
|
||||
<string name="text_overview_ex">Shouya Ishida ist ein sehr aktives Kind. Mit seinen Freunden …</string>
|
||||
<string name="text_title_ex" translatable="false">A Silent Voice</string>
|
||||
<string name="text_overview_ex" translatable="false">Shouya Ishida starts bullying the new girl in class …</string>
|
||||
|
||||
<!-- settings fragment -->
|
||||
<string name="account">Account</string>
|
||||
<string name="account_login_ex">user@example.com</string>
|
||||
<string name="account_login_ex" translatable="false">user@example.com</string>
|
||||
<string name="account_login_desc">Tap to edit</string>
|
||||
<string name="info">Info</string>
|
||||
<string name="info_about">Teapod by @Seil0</string>
|
||||
<string name="info_about" translatable="false">Teapod by @Seil0</string>
|
||||
<string name="info_about_desc" translatable="false">Version %1$s (%2$s)</string>
|
||||
<string name="info_about_dialog" translatable="false">This software is published under the terms and conditions of GPL 3. For further information visit git.mosad.xyz/Seil0 \n\n© 2020 seil0@mosad.xyz</string>
|
||||
<string name="info_about_dialog" translatable="false">This software is published under the terms and conditions of GPL 3. For further information visit: \ngit.mosad.xyz/Seil0/teapod \n\n© 2020 seil0@mosad.xyz</string>
|
||||
|
||||
<!-- dialogs -->
|
||||
<string name="save">save</string>
|
||||
|
@ -28,7 +28,8 @@
|
|||
|
||||
<!-- etc -->
|
||||
<string name="login">Login</string>
|
||||
<string name="login_desc">You need to login before you can use Teapod. Your Login-Data will be stored encrypted on your device.</string>
|
||||
<string name="login_desc">You need to login before you can use Teapod. The Login-Data will be stored encrypted on your device.</string>
|
||||
<string name="login_failed_desc">Could not login. Please try again.</string>
|
||||
<string name="password">Password</string>
|
||||
|
||||
<!-- save keys -->
|
||||
|
|
Loading…
Reference in New Issue