Adding early new page for app list and app detail with back to last page support (+settings support everywhere)

This commit is contained in:
Mylloon 2021-09-02 11:47:54 +02:00
parent 4590c20ccb
commit 5e08d2f240
4 changed files with 66 additions and 10 deletions

View file

@ -31,10 +31,15 @@ import java.util.*
class MainActivity : AppCompatActivity() {
private var settingsButton: Menu? = null // before starting the app there is no settings button
private var settingsButtonVisible: Boolean = false
private var inSettings: Boolean = false // by default your not in settings page
private var inAppList: Boolean = false // by default your not in app list page
private var inAppInfo: Boolean = false // by default your not in app info page
private var prefs: SharedPreferences? = null // first run detection
private val sharedPref = "com.mylloon.MobiDL" // shared pref name
var timeOfLastToast: Long = System.currentTimeMillis() - 2000
private var timeOfLastToast: Long = System.currentTimeMillis() - 2000
private var listInfos: MutableList<Map<String, String?>>? = null
private var urlInfos: String? = null
companion object {
private var instance: MainActivity? = null
@ -49,8 +54,8 @@ class MainActivity : AppCompatActivity() {
}
private fun toggleSettingsButtonVisibility() { // Change Settings button visibility
val visibility: Boolean = settingsButton?.findItem(R.id.settingsButton)?.isVisible == true
settingsButton?.findItem(R.id.settingsButton)?.isVisible = !visibility
settingsButtonVisible = settingsButton?.findItem(R.id.settingsButton)?.isVisible == false
settingsButton?.findItem(R.id.settingsButton)?.isVisible = settingsButtonVisible
}
private fun getValuesRecyclerView(): MutableList<String> { // list of the apps (from the storage if exists)
@ -121,9 +126,11 @@ class MainActivity : AppCompatActivity() {
private fun mainPage(toDelete: String? = null) {
if (toDelete == null) {
setContentView(R.layout.activity_main) // display main page
Handler(Looper.getMainLooper()).postDelayed({
toggleSettingsButtonVisibility()
}, 100) // delay to add button settings
if (!settingsButtonVisible) { // check if the settings button isn't already showed
Handler(Looper.getMainLooper()).postDelayed({
toggleSettingsButtonVisibility()
}, 100) // delay to add button settings
}
}
val user = Credentials().get(0).toString()
this.title = "${getString(R.string.app_name)} (${getString(R.string.connected_as)} $user)"
@ -344,11 +351,26 @@ class MainActivity : AppCompatActivity() {
Toast.LENGTH_SHORT
).show()
}
listInfos = returns
showAppListPage()
}
}
}
}
private fun showAppListPage() {
setContentView(R.layout.activity_app_list) // display main page
inAppList = true
urlInfos = "XD"
println(listInfos)
}
private fun showAppInfoPage() {
setContentView(R.layout.activity_app_infos) // display main page
inAppInfo = true
println(urlInfos)
}
@SuppressLint("SetTextI18n")
private fun settingsPage() {
setContentView(R.layout.activity_settings)
@ -404,9 +426,24 @@ class MainActivity : AppCompatActivity() {
}
override fun onBackPressed() { // allow user to use back button to go back to main page
if (inSettings) {
mainPage()
inSettings = false
} else super.onBackPressed()
when {
inSettings -> {
inSettings = false
return when {
inAppList -> showAppListPage()
inAppInfo -> showAppListPage()
else -> mainPage()
}
}
inAppList -> {
inAppList = false
return mainPage()
}
inAppInfo -> {
inAppInfo = false
return showAppInfoPage()
}
else -> super.onBackPressed()
}
}
}

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:id="@+id/mainLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"