Optimizations and Bug Fix

This commit is contained in:
Mylloon 2021-08-30 09:24:05 +02:00
parent ba5a2b8552
commit e799e12961
3 changed files with 37 additions and 21 deletions

View file

@ -6,24 +6,22 @@ import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.text.Editable
import android.text.InputType
import android.text.TextWatcher
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import android.content.pm.PackageInfo
import android.net.Uri
import android.view.*
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.floatingactionbutton.FloatingActionButton
import android.text.InputType
import android.widget.EditText
import java.util.*
@ -71,7 +69,9 @@ class MainActivity : AppCompatActivity() {
} else {
mainPage() // if yes go to main page
}
} catch (_: Throwable) { loginPage() }
} catch (_: Throwable) {
loginPage()
}
}
private fun loginPage() {
@ -122,11 +122,16 @@ class MainActivity : AppCompatActivity() {
}
val valuesRecyclerView = getValuesRecyclerView() // list of all the element in the main page
class Adapter(private val values: List<String>): RecyclerView.Adapter<Adapter.ViewHolder>() {
class Adapter(private val values: List<String>) :
RecyclerView.Adapter<Adapter.ViewHolder>() {
override fun getItemCount() = values.size
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { // add viewHolder to the main page
val itemView = LayoutInflater.from(parent.context).inflate(R.layout.list_item_view, parent, false)
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): ViewHolder { // add viewHolder to the main page
val itemView = LayoutInflater.from(parent.context)
.inflate(R.layout.list_item_view, parent, false)
return ViewHolder(itemView)
}
@ -136,12 +141,18 @@ class MainActivity : AppCompatActivity() {
inner class ViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView!!) {
var button: Button? = null
init {
button = itemView?.findViewById(R.id.text_list_item)
button?.setOnLongClickListener {
val builder: android.app.AlertDialog.Builder = android.app.AlertDialog.Builder(instance)
builder.setTitle("${R.string.remove} ${button?.text} ?")
builder.setPositiveButton(R.string.remove) { _, _ -> instance?.mainPage(button?.text.toString()) }
val builder: android.app.AlertDialog.Builder =
android.app.AlertDialog.Builder(instance)
builder.setTitle("${getString(R.string.remove)} ${button?.text} ?")
builder.setPositiveButton(R.string.remove) { _, _ ->
instance?.mainPage(
button?.text.toString()
)
}
builder.setNeutralButton(R.string.cancel) { dialog, _ -> dialog.cancel() }
builder.show()
true
@ -223,9 +234,13 @@ class MainActivity : AppCompatActivity() {
val sourceCodeButton = findViewById<Button>(R.id.sourcecodeButton)
sourceCodeButton.setOnClickListener {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(
startActivity(
Intent(
Intent.ACTION_VIEW, Uri.parse(
"https://gitlab.com/Mylloon/mobilismScrap/-/tree/android"
)))
)
)
)
}
}
@ -233,7 +248,8 @@ class MainActivity : AppCompatActivity() {
if (ContextCompat.checkSelfPermission(this@MainActivity, Manifest.permission.INTERNET)
!= PackageManager.PERMISSION_GRANTED
) {
Toast.makeText(this@MainActivity, R.string.internetPermission, Toast.LENGTH_SHORT).show()
Toast.makeText(this@MainActivity, R.string.internetPermission, Toast.LENGTH_SHORT)
.show()
this.finishAffinity()
} else {
Scraper(user, password, app = app, debug = true).search()

View file

@ -11,7 +11,7 @@
<string name="credits">Crédits</string>
<string name="remove">Retirer</string>
<string name="cancel">Annuler</string>
<string name="newAppDialogTitle">Nom de l\'application</string>
<string name="newAppDialogTitle">Nom de la nouvelle app</string>
<string name="validate">Valider</string>
<string name="deletedCredentials">Identifiants supprimés</string>
<string name="dropBro">lâche frère</string>

View file

@ -8,7 +8,7 @@
<string name="buttonLogin">Login</string>
<!-- Main page -->
<string name="newAppDialogTitle">App Name</string>
<string name="newAppDialogTitle">New app name</string>
<string name="validate">Validate</string>
<string name="remove">Remove</string>
<string name="cancel">Cancel</string>