diff --git a/app/src/main/java/com/mylloon/mobidl/MainActivity.kt b/app/src/main/java/com/mylloon/mobidl/MainActivity.kt index b2ca396..8cbdee6 100644 --- a/app/src/main/java/com/mylloon/mobidl/MainActivity.kt +++ b/app/src/main/java/com/mylloon/mobidl/MainActivity.kt @@ -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>? = 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 { // 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() + } } } diff --git a/app/src/main/res/layout/activity_app_infos.xml b/app/src/main/res/layout/activity_app_infos.xml new file mode 100644 index 0000000..f80df9c --- /dev/null +++ b/app/src/main/res/layout/activity_app_infos.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_app_list.xml b/app/src/main/res/layout/activity_app_list.xml new file mode 100644 index 0000000..f80df9c --- /dev/null +++ b/app/src/main/res/layout/activity_app_list.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 1a1daa0..917cfde 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,5 +1,6 @@