Adding early new page for app list and app detail with back to last page support (+settings support everywhere)
This commit is contained in:
parent
4590c20ccb
commit
5e08d2f240
4 changed files with 66 additions and 10 deletions
|
@ -31,10 +31,15 @@ import java.util.*
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
private var settingsButton: Menu? = null // before starting the app there is no settings button
|
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 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 var prefs: SharedPreferences? = null // first run detection
|
||||||
private val sharedPref = "com.mylloon.MobiDL" // shared pref name
|
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 {
|
companion object {
|
||||||
private var instance: MainActivity? = null
|
private var instance: MainActivity? = null
|
||||||
|
@ -49,8 +54,8 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleSettingsButtonVisibility() { // Change Settings button visibility
|
private fun toggleSettingsButtonVisibility() { // Change Settings button visibility
|
||||||
val visibility: Boolean = settingsButton?.findItem(R.id.settingsButton)?.isVisible == true
|
settingsButtonVisible = settingsButton?.findItem(R.id.settingsButton)?.isVisible == false
|
||||||
settingsButton?.findItem(R.id.settingsButton)?.isVisible = !visibility
|
settingsButton?.findItem(R.id.settingsButton)?.isVisible = settingsButtonVisible
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getValuesRecyclerView(): MutableList<String> { // list of the apps (from the storage if exists)
|
private fun getValuesRecyclerView(): MutableList<String> { // list of the apps (from the storage if exists)
|
||||||
|
@ -121,10 +126,12 @@ class MainActivity : AppCompatActivity() {
|
||||||
private fun mainPage(toDelete: String? = null) {
|
private fun mainPage(toDelete: String? = null) {
|
||||||
if (toDelete == null) {
|
if (toDelete == null) {
|
||||||
setContentView(R.layout.activity_main) // display main page
|
setContentView(R.layout.activity_main) // display main page
|
||||||
|
if (!settingsButtonVisible) { // check if the settings button isn't already showed
|
||||||
Handler(Looper.getMainLooper()).postDelayed({
|
Handler(Looper.getMainLooper()).postDelayed({
|
||||||
toggleSettingsButtonVisibility()
|
toggleSettingsButtonVisibility()
|
||||||
}, 100) // delay to add button settings
|
}, 100) // delay to add button settings
|
||||||
}
|
}
|
||||||
|
}
|
||||||
val user = Credentials().get(0).toString()
|
val user = Credentials().get(0).toString()
|
||||||
this.title = "${getString(R.string.app_name)} (${getString(R.string.connected_as)} $user)"
|
this.title = "${getString(R.string.app_name)} (${getString(R.string.connected_as)} $user)"
|
||||||
val valuesRecyclerView = getValuesRecyclerView() // list of all the element in the main page
|
val valuesRecyclerView = getValuesRecyclerView() // list of all the element in the main page
|
||||||
|
@ -344,11 +351,26 @@ class MainActivity : AppCompatActivity() {
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).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")
|
@SuppressLint("SetTextI18n")
|
||||||
private fun settingsPage() {
|
private fun settingsPage() {
|
||||||
setContentView(R.layout.activity_settings)
|
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
|
override fun onBackPressed() { // allow user to use back button to go back to main page
|
||||||
if (inSettings) {
|
when {
|
||||||
mainPage()
|
inSettings -> {
|
||||||
inSettings = false
|
inSettings = false
|
||||||
} else super.onBackPressed()
|
return when {
|
||||||
|
inAppList -> showAppListPage()
|
||||||
|
inAppInfo -> showAppListPage()
|
||||||
|
else -> mainPage()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inAppList -> {
|
||||||
|
inAppList = false
|
||||||
|
return mainPage()
|
||||||
|
}
|
||||||
|
inAppInfo -> {
|
||||||
|
inAppInfo = false
|
||||||
|
return showAppInfoPage()
|
||||||
|
}
|
||||||
|
else -> super.onBackPressed()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
9
app/src/main/res/layout/activity_app_infos.xml
Normal file
9
app/src/main/res/layout/activity_app_infos.xml
Normal 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>
|
9
app/src/main/res/layout/activity_app_list.xml
Normal file
9
app/src/main/res/layout/activity_app_list.xml
Normal 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>
|
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
|
android:id="@+id/mainLayout"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
|
Reference in a new issue