mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 06:21:31 +01:00
Set theme and onClicks in the UIObject interfaces onStart
Also: - Introduce a new temporary bug: The themes do not change anymore, as they will be switched dynamically soon (before I request pull) - Start adding good documentation - Speed up the apps list a little
This commit is contained in:
parent
5d71cf7113
commit
90e1f8893b
15 changed files with 54 additions and 110 deletions
|
@ -12,6 +12,7 @@ import android.net.Uri
|
|||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.View
|
||||
import android.view.animation.*
|
||||
import android.widget.Button
|
||||
|
@ -27,6 +28,8 @@ import kotlin.math.roundToInt
|
|||
lateinit var launcherPreferences: SharedPreferences
|
||||
|
||||
/** Variables containing settings */
|
||||
val displayMetrics = DisplayMetrics()
|
||||
|
||||
var upApp = ""
|
||||
var downApp = ""
|
||||
var rightApp = ""
|
||||
|
|
|
@ -6,11 +6,9 @@ import android.net.Uri
|
|||
import android.os.AsyncTask
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.*
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.GestureDetectorCompat
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.finnmglas.launcher.list.apps.AppsRecyclerAdapter
|
||||
import com.finnmglas.launcher.tutorial.TutorialActivity
|
||||
import kotlinx.android.synthetic.main.home.*
|
||||
|
@ -19,20 +17,16 @@ import java.util.*
|
|||
import kotlin.concurrent.fixedRateTimer
|
||||
import kotlin.math.abs
|
||||
|
||||
// used for the apps drawer / menu (ChooseActivity)
|
||||
lateinit var viewAdapter: RecyclerView.Adapter<*>
|
||||
// used in `ListFragmentApps`
|
||||
lateinit var appListViewAdapter: AppsRecyclerAdapter
|
||||
|
||||
class HomeActivity: UIObject, AppCompatActivity(),
|
||||
GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
|
||||
|
||||
private var currentTheme = "" // keep track of theme changes
|
||||
|
||||
/** Variables for this activity */
|
||||
private lateinit var mDetector: GestureDetectorCompat
|
||||
|
||||
// get device dimensions
|
||||
private val displayMetrics = DisplayMetrics()
|
||||
|
||||
// timers
|
||||
private var clockTimer = Timer()
|
||||
private var tooltipTimer = Timer()
|
||||
|
@ -43,48 +37,38 @@ class HomeActivity: UIObject, AppCompatActivity(),
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// Initialise globals
|
||||
launcherPreferences = this.getSharedPreferences(
|
||||
getString(R.string.preference_file_key), Context.MODE_PRIVATE)
|
||||
|
||||
loadSettings()
|
||||
currentTheme = getSavedTheme(this)
|
||||
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
||||
|
||||
// TODO: Don't use actual themes, rather create them on the fly
|
||||
setTheme(
|
||||
when (getSavedTheme(this)) {
|
||||
"dark" -> R.style.darkTheme
|
||||
"finn" -> R.style.finnmglasTheme
|
||||
else -> R.style.customTheme
|
||||
loadSettings()
|
||||
|
||||
// Preload list of apps (speed up loading time)
|
||||
AsyncTask.execute {
|
||||
appListViewAdapter = AppsRecyclerAdapter(this)
|
||||
}
|
||||
)
|
||||
|
||||
// First time opening the app: show Tutorial
|
||||
if (!launcherPreferences.getBoolean("startedBefore", false))
|
||||
startActivity(Intent(this, TutorialActivity::class.java))
|
||||
|
||||
// Initialise layout
|
||||
setContentView(R.layout.home)
|
||||
|
||||
// Load apps list first - speed up settings that way
|
||||
AsyncTask.execute { viewAdapter =
|
||||
AppsRecyclerAdapter(this, "", "")
|
||||
}
|
||||
|
||||
// First Startup
|
||||
if (!launcherPreferences.getBoolean("startedBefore", false)){
|
||||
startActivity(Intent(this, TutorialActivity::class.java))
|
||||
tooltipTimer.cancel()
|
||||
}
|
||||
currentTheme = getSavedTheme(this)
|
||||
}
|
||||
|
||||
override fun onStart(){
|
||||
super<AppCompatActivity>.onStart()
|
||||
super<UIObject>.onStart()
|
||||
|
||||
mDetector = GestureDetectorCompat(this, this)
|
||||
mDetector.setOnDoubleTapListener(this)
|
||||
|
||||
windowManager.defaultDisplay.getMetrics(displayMetrics)
|
||||
|
||||
// for if the settings changed
|
||||
loadSettings()
|
||||
|
||||
setTheme()
|
||||
setOnClicks()
|
||||
super<UIObject>.onStart()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
@ -124,14 +108,10 @@ class HomeActivity: UIObject, AppCompatActivity(),
|
|||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) { if (settingsIconShown) hideSettingsIcon() }
|
||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
|
||||
launch(volumeUpApp, this)
|
||||
overridePendingTransition(0, 0)
|
||||
}
|
||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
||||
launch(volumeDownApp, this)
|
||||
overridePendingTransition(0, 0)
|
||||
}
|
||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP)
|
||||
launch(volumeUpApp, this,0, 0)
|
||||
else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
|
||||
launch(volumeDownApp, this,0, 0)
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -10,9 +10,14 @@ interface UIObject {
|
|||
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
|
||||
setTheme()
|
||||
setOnClicks()
|
||||
configure()
|
||||
}
|
||||
|
||||
fun setTheme()
|
||||
fun setOnClicks()
|
||||
fun configure() {}
|
||||
// Don't use actual themes, rather create them on the fly for faster theme-switching
|
||||
fun setTheme() { } // colors
|
||||
fun setOnClicks() { } // onClicks
|
||||
fun configure() { } // layoutElements
|
||||
}
|
|
@ -30,19 +30,8 @@ class ListActivity : AppCompatActivity(), UIObject {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// TODO: Don't use actual themes, rather create them on the fly
|
||||
setTheme(
|
||||
when (getSavedTheme(this)) {
|
||||
"dark" -> R.style.darkTheme
|
||||
"finn" -> R.style.finnmglasTheme
|
||||
else -> R.style.finnmglasTheme
|
||||
}
|
||||
)
|
||||
// Initialise layout
|
||||
setContentView(R.layout.list)
|
||||
|
||||
setTheme()
|
||||
setOnClicks()
|
||||
configure()
|
||||
}
|
||||
|
||||
override fun onStart(){
|
||||
|
|
|
@ -2,6 +2,9 @@ package com.finnmglas.launcher.list.apps
|
|||
|
||||
import android.graphics.drawable.Drawable
|
||||
|
||||
/**
|
||||
* Stores information used in [AppsRecyclerAdapter] rows.
|
||||
*/
|
||||
class AppInfo {
|
||||
var label: CharSequence? = null
|
||||
var packageName: CharSequence? = null
|
||||
|
|
|
@ -16,7 +16,7 @@ import com.finnmglas.launcher.*
|
|||
import com.finnmglas.launcher.libraries.*
|
||||
import com.finnmglas.launcher.list.intendedChoosePause
|
||||
|
||||
class AppsRecyclerAdapter(val activity: Activity, val action: String?, val forApp: String?):
|
||||
class AppsRecyclerAdapter(val activity: Activity, val action: String? = "view", val forApp: String? = ""):
|
||||
RecyclerView.Adapter<AppsRecyclerAdapter.ViewHolder>() {
|
||||
|
||||
private val appsList: MutableList<AppInfo>
|
||||
|
|
|
@ -31,9 +31,6 @@ class ListFragmentApps : Fragment(), UIObject {
|
|||
override fun onStart() {
|
||||
super<Fragment>.onStart()
|
||||
super<UIObject>.onStart()
|
||||
|
||||
setTheme()
|
||||
configure()
|
||||
}
|
||||
|
||||
override fun setTheme() {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package com.finnmglas.launcher.list.other
|
||||
|
||||
/**
|
||||
* Stores information used in [OtherRecyclerAdapter] rows.
|
||||
*/
|
||||
class OtherInfo(label: String, data: String, icon: String) {
|
||||
var label: CharSequence? = label
|
||||
var data: CharSequence? = data
|
||||
|
|
|
@ -26,25 +26,15 @@ class SettingsActivity: AppCompatActivity(), UIObject {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// TODO: Don't use actual themes, rather create them on the fly
|
||||
setTheme(
|
||||
when (getSavedTheme(this)) {
|
||||
"dark" -> R.style.darkTheme
|
||||
"finn" -> R.style.finnmglasTheme
|
||||
else -> R.style.customTheme
|
||||
}
|
||||
)
|
||||
|
||||
// Initialise layout
|
||||
setContentView(R.layout.settings)
|
||||
setTheme()
|
||||
setOnClicks()
|
||||
|
||||
// set up tabs and swiping in settings
|
||||
val sectionsPagerAdapter = SettingsSectionsPagerAdapter(this, supportFragmentManager)
|
||||
val viewPager: ViewPager = findViewById(R.id.settings_viewpager)
|
||||
viewPager.adapter = sectionsPagerAdapter
|
||||
val tabs: TabLayout = findViewById(R.id.settings_tabs)
|
||||
tabs.setupWithViewPager(viewPager)
|
||||
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package com.finnmglas.launcher.settings.actions
|
||||
|
||||
/**
|
||||
* Stores information used in [ActionsRecyclerAdapter] rows.
|
||||
*/
|
||||
class ActionInfo(actionText: CharSequence, actionName: CharSequence, content: CharSequence) {
|
||||
var actionName: CharSequence? = actionName
|
||||
var actionText: CharSequence? = actionText
|
||||
var content: CharSequence? = content
|
||||
val actionName: CharSequence? = actionName
|
||||
val actionText: CharSequence? = actionText
|
||||
val content: CharSequence? = content
|
||||
}
|
|
@ -29,9 +29,7 @@ class ActionsRecyclerAdapter(val activity: Activity):
|
|||
var chooseButton: Button = itemView.findViewById(R.id.settings_actions_row_button_choose)
|
||||
var removeAction: FontAwesome = itemView.findViewById(R.id.settings_actions_row_remove)
|
||||
|
||||
override fun onClick(v: View) {
|
||||
val pos = adapterPosition
|
||||
}
|
||||
override fun onClick(v: View) { }
|
||||
|
||||
init { itemView.setOnClickListener(this) }
|
||||
}
|
||||
|
|
|
@ -33,9 +33,6 @@ class SettingsFragmentActions : Fragment(), UIObject {
|
|||
super<Fragment>.onStart()
|
||||
super<UIObject>.onStart()
|
||||
|
||||
setTheme()
|
||||
setOnClicks()
|
||||
|
||||
// set up the list / recycler
|
||||
val actionViewManager = LinearLayoutManager(context)
|
||||
val actionViewAdapter = ActionsRecyclerAdapter( activity!! )
|
||||
|
|
|
@ -33,9 +33,6 @@ class SettingsFragmentMeta : Fragment(), UIObject {
|
|||
override fun onStart() {
|
||||
super<Fragment>.onStart()
|
||||
super<UIObject>.onStart()
|
||||
|
||||
setTheme()
|
||||
setOnClicks()
|
||||
}
|
||||
|
||||
/** Extra functions */
|
||||
|
|
|
@ -33,9 +33,6 @@ class SettingsFragmentTheme : Fragment(), UIObject {
|
|||
override fun onStart(){
|
||||
super<Fragment>.onStart()
|
||||
super<UIObject>.onStart()
|
||||
|
||||
setTheme()
|
||||
setOnClicks()
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
|
|
|
@ -11,39 +11,22 @@ import kotlinx.android.synthetic.main.tutorial.*
|
|||
|
||||
class TutorialActivity : AppCompatActivity(), UIObject {
|
||||
|
||||
/** Variables for this activity */
|
||||
|
||||
private var menuNumber = 0
|
||||
private var defaultApps = mutableListOf<String>()
|
||||
private var isFirstTime = false
|
||||
|
||||
/** Activity Lifecycle functions */
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// TODO: Don't use actual themes, rather create them on the fly
|
||||
setTheme(
|
||||
when (getSavedTheme(this)) {
|
||||
"dark" -> R.style.darkTheme
|
||||
"finn" -> R.style.finnmglasTheme
|
||||
else -> R.style.finnmglasTheme
|
||||
}
|
||||
)
|
||||
|
||||
// Initialise layout
|
||||
setContentView(R.layout.tutorial)
|
||||
setTheme()
|
||||
setOnClicks()
|
||||
|
||||
|
||||
loadMenu(this)
|
||||
|
||||
// Check if it is the first time starting the app
|
||||
isFirstTime = !launcherPreferences.getBoolean("startedBefore", false)
|
||||
|
||||
if (isFirstTime)
|
||||
defaultApps = resetSettings(this) // UP, DOWN, RIGHT, LEFT, VOLUME_UP, VOLUME_DOWN
|
||||
else
|
||||
tutorial_appbar.visibility = View.VISIBLE
|
||||
else tutorial_appbar.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
|
@ -51,7 +34,6 @@ class TutorialActivity : AppCompatActivity(), UIObject{
|
|||
super<UIObject>.onStart()
|
||||
}
|
||||
|
||||
/** Touch- and Key-related functions to navigate */
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP){
|
||||
menuNumber++
|
||||
|
|
Loading…
Add table
Reference in a new issue