Clean up code in the FirstStartup Activity

Move all the strings into the string resources xml file. Way cleaner. 
Can also be translated.
This commit is contained in:
Finn M Glas 2020-05-19 15:26:30 +02:00
parent 12357583c6
commit 9dd663d279
No known key found for this signature in database
GPG key ID: 25037A2E81AB459C
3 changed files with 57 additions and 79 deletions

View file

@ -1,6 +1,5 @@
package com.finnmglas.launcher
import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import android.os.Bundle
@ -30,12 +29,13 @@ fun View.blink(
class FirstStartupActivity : AppCompatActivity(){
var menuNumber = 0
var defaultApps = mutableListOf<String>()
/** Variables for this activity */
/* Overrides */
private var menuNumber = 0
private var defaultApps = mutableListOf<String>()
/** Activity Lifecycle functions */
@SuppressLint("SetTextI18n") // I do not care
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -48,14 +48,14 @@ class FirstStartupActivity : AppCompatActivity(){
setContentView(R.layout.activity_firststartup)
continue_text.blink() // animate
hintText.blink() // animate
loadMenu(this)
val sharedPref = this.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE)
defaultApps = resetSettings(sharedPref, this) // UP, DOWN, RIGHT, LEFT, VOLUME_UP, VOLUME_DOWN
}
fun clickAnywhere(view: View){
menuNumber++
loadMenu(this)
}
/** Touch- and Key-related functions to navigate */
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP){
@ -73,68 +73,30 @@ class FirstStartupActivity : AppCompatActivity(){
return true
}
@SuppressLint("SetTextI18n") // I don't care! (Yet)
fun loadMenu(context :Context) { // Context needed for packageManager
fun clickAnywhere(view: View){
menuNumber++
loadMenu(this)
}
val sharedPref = this.getSharedPreferences(
getString(R.string.preference_file_key), Context.MODE_PRIVATE)
/** Touch- and Key-related functions to navigate */
// Intro
if (menuNumber == 0){
heading.text = ""
description.text = "Take a few seconds to learn how to use this Launcher!\n\n"
continue_text.text = "-- Tap anywhere to continue --"
private fun loadMenu(context :Context) { // Context needed for packageManager
val intro = resources.getStringArray(R.array.intro)
if (menuNumber < intro.size){
val entry = intro[menuNumber].split("|").toTypedArray() //heading|infoText|hintText|size
heading.text = entry[0]
if (entry[4] == "1")infoText.text = String.format(entry[1],
defaultApps[0], defaultApps[1], defaultApps[2], defaultApps[3], defaultApps[4], defaultApps[5])
else infoText.text = entry[1]
hintText.text = entry[2]
infoText.setTextSize(TypedValue.COMPLEX_UNIT_SP, entry[3].toFloat())
} else { // End intro
val sharedPref = this.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE)
defaultApps = resetSettings(sharedPref, context) // UP, DOWN, RIGHT, LEFT, VOLUME_UP, VOLUME_DOWN
}
// Concept
else if (menuNumber == 1){
heading.text = "Concept"
description.text = "It is designed to be minimal, efficient and free of distraction."
}
else if (menuNumber == 2){
heading.text = "Concept"
description.text = "It is free of payments, ads and tracking services."
continue_text.text = "-- Tap anywhere to continue --"
}
// Usage
else if (menuNumber == 3){
heading.text = "Usage"
description.text = "Your home screen contains the local date and time. No distraction."
continue_text.text = "-- Use volume keys to navigate --"
}
else if (menuNumber == 4){
heading.text = "Usage"
description.text = "You can open your apps with a single swipe or button press."
}
// Setup
else if (menuNumber == 5){
heading.text = "Setup"
description.setTextSize(TypedValue.COMPLEX_UNIT_SP,36F)
description.text = "We have set up some default actions for you..."
}
else if (menuNumber == 6){
description.setTextSize(TypedValue.COMPLEX_UNIT_SP,18F)
description.text = "Swipe Up: Open a Browser (" + defaultApps[0] + ")\n\n" +
"Swipe Down: Open internal Search App (" + defaultApps[1] + ")\n\n" +
"Swipe Right: Open Mail (" + defaultApps[2] + ")\n\n" +
"Swipe Left: Open Calendar (" + defaultApps[3] + ")\n\n" +
"Volume Up: Open a messenger (" + defaultApps[4] + ")\n\n" +
"Volume Down: Open Utilities (" + defaultApps[5] + ")"
}
else if (menuNumber == 7){
heading.text = "Setup"
description.setTextSize(TypedValue.COMPLEX_UNIT_SP,36F)
description.text = "You can choose your own apps:\n\nOpen settings by tapping and holding the home screen."
continue_text.text = "-- Use volume keys to navigate --"
}
else if (menuNumber == 8){
heading.text = ""
description.text = "You are ready to get started!\n\n I hope this provides great value to you!\n\n- Finn M Glas\n\n"
continue_text.text = "-- Launcher by Finn M Glas --"
}
// End Intro
else {
val editor: SharedPreferences.Editor = sharedPref.edit()
editor.putBoolean("startedBefore", true) // never run this again
editor.putLong("firstStartup", System.currentTimeMillis() / 1000L) // record first startup timestamp
@ -142,6 +104,5 @@ class FirstStartupActivity : AppCompatActivity(){
finish()
}
}
}

View file

@ -24,7 +24,7 @@
app:layout_constraintVertical_bias="0.100000024" />
<TextView
android:id="@+id/description"
android:id="@+id/infoText"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="32dp"
@ -43,7 +43,7 @@
app:layout_constraintTop_toBottomOf="@id/heading" />
<TextView
android:id="@+id/continue_text"
android:id="@+id/hintText"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="32dp"
@ -60,6 +60,6 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.6"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/description" />
app:layout_constraintTop_toBottomOf="@id/infoText" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -3,6 +3,13 @@
<string name="app_name">Launcher</string>
<string name="preference_file_key">V3RYR4ND0MK3YCR4P</string>
<!-- Errors, Exceptions (Alerts, Toasts ...) -->
<string name="none_found">None found</string>
<string name="alert_cant_open_title">Can\'t open app</string>
<string name="alert_cant_open_message">Want to change its settings (\'add it to the apps screen\')?</string>
<string name="toast_cant_open_message">Open settings to choose an app for this action</string>
<!-- Settings -->
<string name="settings_title">Settings</string>
<string name="settings_sub_title1">Applications</string>
@ -34,12 +41,22 @@
<string name="choose_removed_toast">Removed the selected application</string>
<string name="choose_not_removed_toast">Unable to remove application</string>
<!-- Errors, Exceptions (Alerts, Toasts ...) -->
<string name="none_found">None found</string>
<string name="alert_cant_open_title">Can\'t open app</string>
<string name="alert_cant_open_message">Want to change its settings (\'add it to the apps screen\')?</string>
<string name="toast_cant_open_message">Open settings to choose an app for this action</string>
<!-- FirstStartup Activity -->
<string-array name="intro">
<!--item> heading | infoText | hintText | size | format </item-->
<item>|Take a few seconds to learn how to use this Launcher!\n\n|— Tap anywhere to continue —|36F|0</item>
<item>Concept|It is designed to be minimal, efficient and free of distraction.|— Tap anywhere to continue —|36F|0</item>
<item>Concept|It is free of payments, ads and tracking services.|— Tap anywhere to continue —|36F|0</item>
<item>Usage|Your home screen contains the local date and time. No distraction.|— Tap anywhere to continue —|36F|0</item>
<item>Usage|You can open your apps with a single swipe or button press.|— Tap anywhere to continue —|36F|0</item>
<item>Setup|We have set up some default actions for you…|— Use volume keys to navigate —|36F|0</item>
<item>Setup|Swipe Up: Open a Browser (%1$s)\n\nSwipe Down: Open internal Search App (%2$s)\n\n
Swipe Right: Open Mail (%3$s)\n\nSwipe Left: Open Calendar (%4$s)\n\n
Volume Up: Open a messenger (%5$s)\n\nVolume Down: Open Utilities (%6$s)|— Use volume keys to navigate —|18F|1
</item>
<item>Setup|You can choose your own apps:\n\nOpen settings by tapping and holding the home screen.|— Use volume keys to navigate —|36F|0</item>
<item>|You are ready to get started!\n\n I hope this provides great value to you!\n\n- Finn M Glas\n\n|— Launcher by Finn M Glas —|36F|0</item>
</string-array>
<!-- Default Apps for different actions (button-press, swipes ...) -->
<string-array name="default_up">