mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-26 19:44:16 +01:00
Make controller layout more preferences like
This commit is contained in:
parent
4b7cb176f6
commit
e50f5a5d72
@ -282,7 +282,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun loadRoms(loadFromFile : Boolean) {
|
||||
viewModel.loadRoms(this, loadFromFile, Uri.parse(settings.searchLocation))
|
||||
viewModel.loadRoms(loadFromFile, Uri.parse(settings.searchLocation))
|
||||
settings.refreshRequired = false
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,12 @@
|
||||
package emu.skyline
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.*
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import emu.skyline.loader.AppEntry
|
||||
import emu.skyline.loader.RomFormat
|
||||
import emu.skyline.utils.fromFile
|
||||
@ -26,7 +25,7 @@ sealed class MainState {
|
||||
}
|
||||
|
||||
@HiltViewModel
|
||||
class MainViewModel @Inject constructor(private val romProvider : RomProvider) : ViewModel() {
|
||||
class MainViewModel @Inject constructor(@ApplicationContext context : Context, private val romProvider : RomProvider) : AndroidViewModel(context as Application) {
|
||||
companion object {
|
||||
private val TAG = MainViewModel::class.java.simpleName
|
||||
}
|
||||
@ -44,11 +43,11 @@ class MainViewModel @Inject constructor(private val romProvider : RomProvider) :
|
||||
*
|
||||
* @param loadFromFile If this is false then trying to load cached adapter data is skipped entirely
|
||||
*/
|
||||
fun loadRoms(context : Context, loadFromFile : Boolean, searchLocation : Uri) {
|
||||
fun loadRoms(loadFromFile : Boolean, searchLocation : Uri) {
|
||||
if (state == MainState.Loading) return
|
||||
state = MainState.Loading
|
||||
|
||||
val romsFile = File(context.filesDir.canonicalPath + "/roms.bin")
|
||||
val romsFile = File(getApplication<SkylineApplication>().filesDir.canonicalPath + "/roms.bin")
|
||||
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
if (loadFromFile && romsFile.exists()) {
|
||||
|
@ -0,0 +1,24 @@
|
||||
package emu.skyline.adapter.controller
|
||||
|
||||
import android.view.ViewGroup
|
||||
import emu.skyline.adapter.GenericListItem
|
||||
import emu.skyline.adapter.GenericViewHolder
|
||||
import emu.skyline.adapter.ViewBindingFactory
|
||||
import emu.skyline.adapter.inflater
|
||||
import emu.skyline.databinding.ControllerHeaderBinding
|
||||
|
||||
object ControllerHeaderBindingFactory : ViewBindingFactory {
|
||||
override fun createBinding(parent : ViewGroup) = ControllerHeaderBinding.inflate(parent.inflater(), parent, false)
|
||||
}
|
||||
|
||||
class ControllerHeaderItem(private val text : String) : GenericListItem<ControllerHeaderBinding>() {
|
||||
override fun getViewBindingFactory() = ControllerHeaderBindingFactory
|
||||
|
||||
override fun bind(holder : GenericViewHolder<ControllerHeaderBinding>, position : Int) {
|
||||
holder.binding.root.text = text
|
||||
}
|
||||
|
||||
override fun areItemsTheSame(other : GenericListItem<ControllerHeaderBinding>) = other is ControllerHeaderItem
|
||||
|
||||
override fun areContentsTheSame(other : GenericListItem<ControllerHeaderBinding>) = other is ControllerHeaderItem && text == other.text
|
||||
}
|
@ -16,7 +16,6 @@ import dagger.hilt.android.AndroidEntryPoint
|
||||
import emu.skyline.R
|
||||
import emu.skyline.adapter.GenericAdapter
|
||||
import emu.skyline.adapter.GenericListItem
|
||||
import emu.skyline.adapter.HeaderViewItem
|
||||
import emu.skyline.adapter.controller.*
|
||||
import emu.skyline.databinding.ControllerActivityBinding
|
||||
import emu.skyline.input.dialog.ButtonDialog
|
||||
@ -38,9 +37,6 @@ class ControllerActivity : AppCompatActivity() {
|
||||
*/
|
||||
val id by lazy { intent.getIntExtra("index", 0) }
|
||||
|
||||
/**
|
||||
* The adapter used by [controller_list] to hold all the items
|
||||
*/
|
||||
private val adapter = GenericAdapter()
|
||||
|
||||
/**
|
||||
@ -74,7 +70,7 @@ class ControllerActivity : AppCompatActivity() {
|
||||
return
|
||||
|
||||
if (id == 0) {
|
||||
items.add(HeaderViewItem(getString(R.string.osc)))
|
||||
items.add(ControllerHeaderItem(getString(R.string.osc)))
|
||||
|
||||
val oscSummary = { checked : Boolean -> getString(if (checked) R.string.osc_shown else R.string.osc_not_shown) }
|
||||
items.add(ControllerCheckBoxViewItem(getString(R.string.osc_enable), oscSummary.invoke(settings.onScreenControl), settings.onScreenControl) { item, position ->
|
||||
@ -98,7 +94,7 @@ class ControllerActivity : AppCompatActivity() {
|
||||
for (item in GeneralType.values()) {
|
||||
if (item.compatibleControllers == null || item.compatibleControllers.contains(controller.type)) {
|
||||
if (!wroteTitle) {
|
||||
items.add(HeaderViewItem(getString(R.string.general)))
|
||||
items.add(ControllerHeaderItem(getString(R.string.general)))
|
||||
wroteTitle = true
|
||||
}
|
||||
|
||||
@ -110,7 +106,7 @@ class ControllerActivity : AppCompatActivity() {
|
||||
|
||||
for (stick in controller.type.sticks) {
|
||||
if (!wroteTitle) {
|
||||
items.add(HeaderViewItem(getString(R.string.sticks)))
|
||||
items.add(ControllerHeaderItem(getString(R.string.sticks)))
|
||||
wroteTitle = true
|
||||
}
|
||||
|
||||
@ -134,7 +130,7 @@ class ControllerActivity : AppCompatActivity() {
|
||||
|
||||
for (button in controller.type.buttons.filter { it in buttonArray.second }) {
|
||||
if (!wroteTitle) {
|
||||
items.add(HeaderViewItem(getString(buttonArray.first)))
|
||||
items.add(ControllerHeaderItem(getString(buttonArray.first)))
|
||||
wroteTitle = true
|
||||
}
|
||||
|
||||
@ -149,7 +145,7 @@ class ControllerActivity : AppCompatActivity() {
|
||||
|
||||
for (button in controller.type.buttons.filterNot { item -> buttonArrays.any { item in it.second } }.plus(ButtonId.Menu)) {
|
||||
if (!wroteTitle) {
|
||||
items.add(HeaderViewItem(getString(R.string.misc_buttons)))
|
||||
items.add(ControllerHeaderItem(getString(R.string.misc_buttons)))
|
||||
wroteTitle = true
|
||||
}
|
||||
|
||||
|
@ -14,5 +14,6 @@
|
||||
android:id="@+id/controller_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
@ -6,12 +6,15 @@
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:orientation="horizontal">
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="72dp"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_weight="1"
|
||||
@ -21,6 +24,8 @@
|
||||
android:id="@+id/text_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="marquee"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||
tools:text="Title" />
|
||||
|
||||
@ -28,8 +33,9 @@
|
||||
android:id="@+id/text_subtitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="10"
|
||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||
android:textColor="@android:color/tertiary_text_light"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
tools:text="Summary" />
|
||||
</LinearLayout>
|
||||
|
||||
@ -37,6 +43,8 @@
|
||||
android:id="@+id/checkbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:clickable="false" />
|
||||
android:clickable="false"
|
||||
android:gravity="end|center_vertical"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="0dp" />
|
||||
</LinearLayout>
|
||||
|
12
app/src/main/res/layout/controller_header.xml
Normal file
12
app/src/main/res/layout/controller_header.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:paddingStart="72dp"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
|
||||
android:textColor="?attr/colorAccent"
|
||||
tools:text="Header" />
|
@ -1,31 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/controller_item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:baselineAligned="false"
|
||||
android:clickable="true"
|
||||
android:clipToPadding="false"
|
||||
android:focusable="true"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
||||
android:orientation="vertical"
|
||||
android:paddingVertical="8dp"
|
||||
android:paddingHorizontal="16dp">
|
||||
android:paddingStart="72dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:paddingBottom="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="false"
|
||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||
tools:ignore="RelativeOverlap" />
|
||||
android:ellipsize="marquee"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceListItem" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_subtitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/text_title"
|
||||
android:layout_alignStart="@id/text_title"
|
||||
android:maxLines="10"
|
||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||
android:textColor="@android:color/tertiary_text_light" />
|
||||
</RelativeLayout>
|
||||
android:textColor="?android:attr/textColorSecondary" />
|
||||
</LinearLayout>
|
||||
|
Loading…
Reference in New Issue
Block a user