🆕 Settings Menu
This commit is contained in:
parent
785d51d70c
commit
0d281fd0dd
6 changed files with 173 additions and 81 deletions
|
@ -2,20 +2,26 @@ package com.mylloon.mobidl
|
|||
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.pm.PackageManager
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.text.Editable
|
||||
|
||||
import android.text.TextWatcher
|
||||
import android.view.MenuItem
|
||||
import android.view.Menu
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import android.content.SharedPreferences
|
||||
import android.content.pm.PackageInfo
|
||||
import android.net.Uri
|
||||
import android.widget.TextView
|
||||
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
@ -30,7 +36,7 @@ class MainActivity : AppCompatActivity() {
|
|||
companion object {
|
||||
private var instance: MainActivity? = null
|
||||
|
||||
fun applicationContext() : Context {
|
||||
fun applicationContext(): Context {
|
||||
return instance!!.applicationContext
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +50,14 @@ class MainActivity : AppCompatActivity() {
|
|||
super.onCreate(savedInstanceState)
|
||||
prefs = getSharedPreferences("com.mylloon.MobiDL", MODE_PRIVATE)
|
||||
|
||||
fun loginPage() {
|
||||
if (Credentials().get(0) == null) { // test if credentials have already been registered
|
||||
loginPage() // if no ask for
|
||||
} else {
|
||||
mainPage() // if yes go to main page
|
||||
}
|
||||
}
|
||||
|
||||
private fun loginPage() {
|
||||
setContentView(R.layout.activity_login) // show login page
|
||||
|
||||
val userInput = findViewById<EditText>(R.id.usernameInput)
|
||||
|
@ -82,28 +95,64 @@ class MainActivity : AppCompatActivity() {
|
|||
mainPage()
|
||||
}
|
||||
}
|
||||
if (Credentials().get(0) == null) { // test if credentials have already been registered
|
||||
loginPage() // if no ask for
|
||||
} else {
|
||||
mainPage() // if yes go to main page
|
||||
}
|
||||
}
|
||||
|
||||
private fun mainPage() {
|
||||
setContentView(R.layout.activity_main)
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
toggleSettingsButtonVisibility()
|
||||
}, 50)
|
||||
// user = Credentials().get(0).toString()
|
||||
// password = Credentials().get(1).toString()
|
||||
// callScript(user, password) // call script
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private fun settingsPage() {
|
||||
setContentView(R.layout.activity_settings)
|
||||
toggleSettingsButtonVisibility()
|
||||
inSettings = true
|
||||
val pInfo: PackageInfo =
|
||||
applicationContext().packageManager.getPackageInfo(applicationContext().packageName, 0)
|
||||
val stringVersion = findViewById<TextView>(R.id.version)
|
||||
stringVersion.text = "v${pInfo.versionName}"
|
||||
|
||||
val credentialsButton = findViewById<Button>(R.id.changeCredentialsButton)
|
||||
credentialsButton.setOnClickListener { // show main page when clicking the login button
|
||||
Credentials().delete()
|
||||
Toast.makeText(this@MainActivity, "Deleted credentials", Toast.LENGTH_LONG)
|
||||
.show()
|
||||
toggleSettingsButtonVisibility()
|
||||
loginPage()
|
||||
}
|
||||
|
||||
val sourceCodeButton = findViewById<Button>(R.id.sourcecodeButton)
|
||||
sourceCodeButton.setOnClickListener {
|
||||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(
|
||||
"https://gitlab.com/Mylloon/mobilismScrap/-/tree/android"
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
private fun callScript(user: String, password: String) {
|
||||
if (ContextCompat.checkSelfPermission(this@MainActivity, Manifest.permission.INTERNET)
|
||||
!= PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
Toast.makeText(this@MainActivity, "No permission to use the internet", Toast.LENGTH_SHORT).show()
|
||||
this.finishAffinity()
|
||||
} else {
|
||||
println("test du script")
|
||||
Scraper(user, password, app = "Plex", debug = true).search()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (prefs!!.getBoolean("firstrun", true)) {
|
||||
println("Generate RSA keys...")
|
||||
Credentials().generateKey()
|
||||
println("Done!")
|
||||
prefs!!.edit().putBoolean("firstrun", false).apply() // first run done, now the next ones won't be "first".
|
||||
prefs!!.edit().putBoolean("firstrun", false)
|
||||
.apply() // first run done, now the next ones won't be "first".
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,9 +165,7 @@ class MainActivity : AppCompatActivity() {
|
|||
override fun onOptionsItemSelected(item: MenuItem): Boolean { // go to settings page when clicking on settings button
|
||||
when (item.itemId) {
|
||||
R.id.settingsButton -> {
|
||||
setContentView(R.layout.activity_settings)
|
||||
toggleSettingsButtonVisibility()
|
||||
inSettings = true
|
||||
settingsPage()
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
|
@ -130,15 +177,4 @@ class MainActivity : AppCompatActivity() {
|
|||
inSettings = false
|
||||
} else super.onBackPressed()
|
||||
}
|
||||
|
||||
private fun callScript(user: String, password: String) {
|
||||
if(ContextCompat.checkSelfPermission(this@MainActivity, Manifest.permission.INTERNET)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
Toast.makeText(this@MainActivity, "No permission to use internet", Toast.LENGTH_SHORT).show()
|
||||
this.finishAffinity()
|
||||
} else {
|
||||
println("test du script")
|
||||
Scraper(user, password, app = "Plex", debug = true).search()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,66 +8,67 @@
|
|||
tools:context=".MainActivity">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/exo_2_light"
|
||||
android:text="@string/titleLogin"
|
||||
android:textAlignment="center"
|
||||
android:textSize="34sp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/usernameInput"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.692" />
|
||||
app:layout_constraintVertical_bias="0.111" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/usernameInput"
|
||||
android:layout_width="331dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="60dp"
|
||||
android:autofillHints="username"
|
||||
android:ems="10"
|
||||
android:fontFamily="@font/exo_2_light"
|
||||
android:hint="@string/userLogin"
|
||||
android:inputType="textPersonName"
|
||||
app:layout_constraintBottom_toTopOf="@+id/passwordInput"
|
||||
app:layout_constraintHorizontal_bias="0.504"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.864"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView2"
|
||||
app:layout_constraintVertical_bias="0.0"
|
||||
tools:ignore="TextContrastCheck" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/passwordInput"
|
||||
android:layout_width="331dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="23dp"
|
||||
android:autofillHints="password"
|
||||
android:ems="10"
|
||||
android:fontFamily="@font/exo_2_light"
|
||||
android:hint="@string/passwordLogin"
|
||||
android:inputType="textPassword"
|
||||
app:layout_constraintBottom_toTopOf="@+id/loginButton"
|
||||
app:layout_constraintHorizontal_bias="0.504"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.88"
|
||||
app:layout_constraintTop_toBottomOf="@+id/usernameInput"
|
||||
app:layout_constraintVertical_bias="0.007"
|
||||
tools:ignore="TextContrastCheck" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/loginButton"
|
||||
android:layout_width="345dp"
|
||||
android:layout_height="102dp"
|
||||
android:layout_marginTop="65dp"
|
||||
android:enabled="false"
|
||||
android:fontFamily="@font/exo_2_medium"
|
||||
android:text="@string/buttonLogin"
|
||||
android:textSize="34sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.505"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.54" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/passwordInput"
|
||||
app:layout_constraintVertical_bias="0.0" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -8,11 +8,53 @@
|
|||
tools:context=".MainActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="256dp"
|
||||
android:text="SETTINGS"
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="232dp"
|
||||
android:layout_height="47dp"
|
||||
android:fontFamily="@font/exo_2_medium"
|
||||
android:text="@string/titleSettings"
|
||||
android:textAlignment="center"
|
||||
android:textSize="34sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.497"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
/>
|
||||
app:layout_constraintVertical_bias="0.131" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/changeCredentialsButton"
|
||||
android:layout_width="198dp"
|
||||
android:layout_height="85dp"
|
||||
android:layout_marginTop="99dp"
|
||||
android:text="@string/changeCredentials"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.497"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView"
|
||||
app:layout_constraintVertical_bias="0.099" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/sourcecodeButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="43dp"
|
||||
android:text="@string/sourceCode"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.498"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/changeCredentialsButton"
|
||||
app:layout_constraintVertical_bias="0.0" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/version"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/sourcecodeButton"
|
||||
app:layout_constraintVertical_bias="0.08" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -5,7 +5,7 @@
|
|||
<item
|
||||
android:id="@+id/settingsButton"
|
||||
android:icon="@drawable/ic_settings"
|
||||
android:title="Settings"
|
||||
android:title="@string/titleSettings"
|
||||
android:visible="false"
|
||||
app:showAsAction="always" />
|
||||
</menu>
|
|
@ -4,4 +4,9 @@
|
|||
<string name="userLogin" translatable="true">Identifiant</string>
|
||||
<string name="passwordLogin" translatable="true">Mot de passe</string>
|
||||
<string name="buttonLogin" translatable="true">Connexion</string>
|
||||
|
||||
<string name="titleSettings" translatable="true">Paramètres</string>
|
||||
<string name="changeCredentials">Change les identifiants</string>
|
||||
<string name="sourceCode">Code source</string>
|
||||
<string name="credits">Crédits</string>
|
||||
</resources>
|
|
@ -1,7 +1,15 @@
|
|||
<resources>
|
||||
<string name="app_name" translatable="false">MobiDL</string>
|
||||
|
||||
<!-- Login page -->
|
||||
<string name="titleLogin">Login to your Mobilism account</string>
|
||||
<string name="userLogin">Username</string>
|
||||
<string name="passwordLogin">Password</string>
|
||||
<string name="buttonLogin">Login</string>
|
||||
|
||||
<!-- Settings page -->
|
||||
<string name="titleSettings">Settings</string>
|
||||
<string name="changeCredentials">Change credentials</string>
|
||||
<string name="sourceCode">Source code</string>
|
||||
<string name="credits">Credits</string>
|
||||
</resources>
|
Reference in a new issue