mirror of
https://github.com/jrpie/Launcher.git
synced 2025-04-19 10:20:51 +02:00
Create a basic tabbed settings activity
Tabs: Apps, Theme, Launcher
This commit is contained in:
parent
75af3f2866
commit
abd7a44874
9 changed files with 126 additions and 305 deletions
|
@ -8,20 +8,27 @@ import android.provider.Settings
|
|||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.finnmglas.launcher.ui.main.SectionsPagerAdapter
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
|
||||
|
||||
//TODO Make Settings scrollable as soon as more are added
|
||||
|
||||
class SettingsActivity : AppCompatActivity() {
|
||||
|
||||
/** Activity Lifecycle functions */
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_settings)
|
||||
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
|
||||
setContentView(R.layout.activity_settings)
|
||||
val sectionsPagerAdapter = SectionsPagerAdapter(this, supportFragmentManager)
|
||||
val viewPager: ViewPager = findViewById(R.id.view_pager)
|
||||
viewPager.adapter = sectionsPagerAdapter
|
||||
val tabs: TabLayout = findViewById(R.id.tabs)
|
||||
tabs.setupWithViewPager(viewPager)
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.finnmglas.launcher.ui.main
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.Transformations
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
|
||||
class PageViewModel : ViewModel() {
|
||||
|
||||
private val _index = MutableLiveData<Int>()
|
||||
val text: LiveData<String> = Transformations.map(_index) {
|
||||
"Tab $it"
|
||||
}
|
||||
|
||||
fun setIndex(index: Int) {
|
||||
_index.value = index
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.finnmglas.launcher.ui.main
|
||||
|
||||
import android.content.Context
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentPagerAdapter
|
||||
import com.finnmglas.launcher.*
|
||||
|
||||
private val TAB_TITLES = arrayOf(
|
||||
R.string.settings_tab_app,
|
||||
R.string.settings_tab_theme,
|
||||
R.string.settings_tab_launcher
|
||||
)
|
||||
|
||||
/** Returns the fragment corresponding to the selected tab.*/
|
||||
class SectionsPagerAdapter(private val context: Context, fm: FragmentManager)
|
||||
: FragmentPagerAdapter(fm) {
|
||||
|
||||
override fun getItem(position: Int): Fragment {
|
||||
return when (position){
|
||||
else -> Fragment()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getPageTitle(position: Int): CharSequence? {
|
||||
return context.resources.getString(TAB_TITLES[position])
|
||||
}
|
||||
|
||||
override fun getCount(): Int {
|
||||
return 3
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue