Clean up code in the Settings Activity

Extract all strings to the resource files (helpful for translations in 
the future), Move and simplify functions.
This commit is contained in:
Finn M Glas 2020-05-19 12:24:08 +02:00
parent 9e3cac35ae
commit b8d1880fbc
No known key found for this signature in database
GPG key ID: 25037A2E81AB459C
4 changed files with 118 additions and 92 deletions

View file

@ -8,6 +8,7 @@ import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.provider.Settings
import android.widget.Toast
@ -70,6 +71,15 @@ fun launchApp(packageName: String, context: Context) {
}
}
fun openNewTabWindow(urls: String, context : Context) {
val uris = Uri.parse(urls)
val intents = Intent(Intent.ACTION_VIEW, uris)
val b = Bundle()
b.putBoolean("new_window", true)
intents.putExtras(b)
context.startActivity(intents)
}
/** Settings related functions */
fun openAppSettings(pkg :String, context:Context){

View file

@ -1,9 +1,7 @@
package com.finnmglas.launcher
import android.annotation.SuppressLint
import android.app.AlertDialog
import android.content.*
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
@ -16,6 +14,17 @@ import androidx.appcompat.app.AppCompatActivity
//TODO Make Settings scrollable as soon as more are added
class SettingsActivity : AppCompatActivity() {
/** Activity Lifecycle functions */
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
setContentView(R.layout.activity_settings)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if(requestCode == 5000)
{
@ -37,6 +46,7 @@ class SettingsActivity : AppCompatActivity() {
}
}
/** onClick functions for Settings */
fun chooseDownApp(view: View) {chooseApp("downApp")}
fun chooseUpApp(view: View) {chooseApp("upApp")}
fun chooseLeftApp(view: View) {chooseApp("leftApp")}
@ -63,26 +73,9 @@ class SettingsActivity : AppCompatActivity() {
startActivity(intent)
}
fun openNewTabWindow(urls: String, context : Context) {
val uris = Uri.parse(urls)
val intents = Intent(Intent.ACTION_VIEW, uris)
val b = Bundle()
b.putBoolean("new_window", true)
intents.putExtras(b)
context.startActivity(intents)
}
fun openFinnWebsite(view: View) {
openNewTabWindow("https://www.finnmglas.com/", this)
}
fun openGithubRepo(view: View) {
openNewTabWindow("https://github.com/finnmglas/Launcher#en", this)
}
fun backHome(view: View) {
finish()
}
fun openFinnWebsite(view: View) { openNewTabWindow("https://www.finnmglas.com/", this) }
fun openGithubRepo(view: View) { openNewTabWindow("https://github.com/finnmglas/Launcher#en", this) }
fun backHome(view: View) { finish() }
fun setLauncher(view: View) {
// on newer sdk: choose launcher
@ -124,14 +117,4 @@ class SettingsActivity : AppCompatActivity() {
.setIcon(android.R.drawable.ic_dialog_alert)
.show()
}
@SuppressLint("SetTextI18n") // I do not care
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
setContentView(R.layout.activity_settings)
}
}