mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-28 07:45:37 +03: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) {
|
private fun loadRoms(loadFromFile : Boolean) {
|
||||||
viewModel.loadRoms(this, loadFromFile, Uri.parse(settings.searchLocation))
|
viewModel.loadRoms(loadFromFile, Uri.parse(settings.searchLocation))
|
||||||
settings.refreshRequired = false
|
settings.refreshRequired = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
package emu.skyline
|
package emu.skyline
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.*
|
||||||
import androidx.lifecycle.MutableLiveData
|
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import androidx.lifecycle.viewModelScope
|
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import emu.skyline.loader.AppEntry
|
import emu.skyline.loader.AppEntry
|
||||||
import emu.skyline.loader.RomFormat
|
import emu.skyline.loader.RomFormat
|
||||||
import emu.skyline.utils.fromFile
|
import emu.skyline.utils.fromFile
|
||||||
@ -26,7 +25,7 @@ sealed class MainState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@HiltViewModel
|
@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 {
|
companion object {
|
||||||
private val TAG = MainViewModel::class.java.simpleName
|
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
|
* @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
|
if (state == MainState.Loading) return
|
||||||
state = MainState.Loading
|
state = MainState.Loading
|
||||||
|
|
||||||
val romsFile = File(context.filesDir.canonicalPath + "/roms.bin")
|
val romsFile = File(getApplication<SkylineApplication>().filesDir.canonicalPath + "/roms.bin")
|
||||||
|
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
if (loadFromFile && romsFile.exists()) {
|
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.R
|
||||||
import emu.skyline.adapter.GenericAdapter
|
import emu.skyline.adapter.GenericAdapter
|
||||||
import emu.skyline.adapter.GenericListItem
|
import emu.skyline.adapter.GenericListItem
|
||||||
import emu.skyline.adapter.HeaderViewItem
|
|
||||||
import emu.skyline.adapter.controller.*
|
import emu.skyline.adapter.controller.*
|
||||||
import emu.skyline.databinding.ControllerActivityBinding
|
import emu.skyline.databinding.ControllerActivityBinding
|
||||||
import emu.skyline.input.dialog.ButtonDialog
|
import emu.skyline.input.dialog.ButtonDialog
|
||||||
@ -38,9 +37,6 @@ class ControllerActivity : AppCompatActivity() {
|
|||||||
*/
|
*/
|
||||||
val id by lazy { intent.getIntExtra("index", 0) }
|
val id by lazy { intent.getIntExtra("index", 0) }
|
||||||
|
|
||||||
/**
|
|
||||||
* The adapter used by [controller_list] to hold all the items
|
|
||||||
*/
|
|
||||||
private val adapter = GenericAdapter()
|
private val adapter = GenericAdapter()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,7 +70,7 @@ class ControllerActivity : AppCompatActivity() {
|
|||||||
return
|
return
|
||||||
|
|
||||||
if (id == 0) {
|
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) }
|
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 ->
|
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()) {
|
for (item in GeneralType.values()) {
|
||||||
if (item.compatibleControllers == null || item.compatibleControllers.contains(controller.type)) {
|
if (item.compatibleControllers == null || item.compatibleControllers.contains(controller.type)) {
|
||||||
if (!wroteTitle) {
|
if (!wroteTitle) {
|
||||||
items.add(HeaderViewItem(getString(R.string.general)))
|
items.add(ControllerHeaderItem(getString(R.string.general)))
|
||||||
wroteTitle = true
|
wroteTitle = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +106,7 @@ class ControllerActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
for (stick in controller.type.sticks) {
|
for (stick in controller.type.sticks) {
|
||||||
if (!wroteTitle) {
|
if (!wroteTitle) {
|
||||||
items.add(HeaderViewItem(getString(R.string.sticks)))
|
items.add(ControllerHeaderItem(getString(R.string.sticks)))
|
||||||
wroteTitle = true
|
wroteTitle = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +130,7 @@ class ControllerActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
for (button in controller.type.buttons.filter { it in buttonArray.second }) {
|
for (button in controller.type.buttons.filter { it in buttonArray.second }) {
|
||||||
if (!wroteTitle) {
|
if (!wroteTitle) {
|
||||||
items.add(HeaderViewItem(getString(buttonArray.first)))
|
items.add(ControllerHeaderItem(getString(buttonArray.first)))
|
||||||
wroteTitle = true
|
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)) {
|
for (button in controller.type.buttons.filterNot { item -> buttonArrays.any { item in it.second } }.plus(ButtonId.Menu)) {
|
||||||
if (!wroteTitle) {
|
if (!wroteTitle) {
|
||||||
items.add(HeaderViewItem(getString(R.string.misc_buttons)))
|
items.add(ControllerHeaderItem(getString(R.string.misc_buttons)))
|
||||||
wroteTitle = true
|
wroteTitle = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,29 +205,29 @@ class ControllerActivity : AppCompatActivity() {
|
|||||||
val typeNames = types.map { getString(it.stringRes) }.toTypedArray()
|
val typeNames = types.map { getString(it.stringRes) }.toTypedArray()
|
||||||
|
|
||||||
MaterialAlertDialogBuilder(this)
|
MaterialAlertDialogBuilder(this)
|
||||||
.setTitle(item.content)
|
.setTitle(item.content)
|
||||||
.setSingleChoiceItems(typeNames, types.indexOf(controller.type)) { dialog, typeIndex ->
|
.setSingleChoiceItems(typeNames, types.indexOf(controller.type)) { dialog, typeIndex ->
|
||||||
val selectedType = types[typeIndex]
|
val selectedType = types[typeIndex]
|
||||||
if (controller.type != selectedType) {
|
if (controller.type != selectedType) {
|
||||||
if (controller is JoyConLeftController)
|
if (controller is JoyConLeftController)
|
||||||
controller.partnerId?.let { (inputManager.controllers[it] as JoyConRightController).partnerId = null }
|
controller.partnerId?.let { (inputManager.controllers[it] as JoyConRightController).partnerId = null }
|
||||||
else if (controller is JoyConRightController)
|
else if (controller is JoyConRightController)
|
||||||
controller.partnerId?.let { (inputManager.controllers[it] as JoyConLeftController).partnerId = null }
|
controller.partnerId?.let { (inputManager.controllers[it] as JoyConLeftController).partnerId = null }
|
||||||
|
|
||||||
inputManager.controllers[id] = when (selectedType) {
|
inputManager.controllers[id] = when (selectedType) {
|
||||||
ControllerType.None -> Controller(id, ControllerType.None)
|
ControllerType.None -> Controller(id, ControllerType.None)
|
||||||
ControllerType.HandheldProController -> HandheldController(id)
|
ControllerType.HandheldProController -> HandheldController(id)
|
||||||
ControllerType.ProController -> ProController(id)
|
ControllerType.ProController -> ProController(id)
|
||||||
ControllerType.JoyConLeft -> JoyConLeftController(id)
|
ControllerType.JoyConLeft -> JoyConLeftController(id)
|
||||||
ControllerType.JoyConRight -> JoyConRightController(id)
|
ControllerType.JoyConRight -> JoyConRightController(id)
|
||||||
}
|
|
||||||
|
|
||||||
update()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dialog.dismiss()
|
update()
|
||||||
}
|
}
|
||||||
.show()
|
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
.show()
|
||||||
Unit
|
Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,20 +244,20 @@ class ControllerActivity : AppCompatActivity() {
|
|||||||
} ?: 0
|
} ?: 0
|
||||||
|
|
||||||
MaterialAlertDialogBuilder(this)
|
MaterialAlertDialogBuilder(this)
|
||||||
.setTitle(item.content)
|
.setTitle(item.content)
|
||||||
.setSingleChoiceItems(rJoyConNames, partnerNameIndex) { dialog, index ->
|
.setSingleChoiceItems(rJoyConNames, partnerNameIndex) { dialog, index ->
|
||||||
(inputManager.controllers[controller.partnerId ?: -1] as JoyConRightController?)?.partnerId = null
|
(inputManager.controllers[controller.partnerId ?: -1] as JoyConRightController?)?.partnerId = null
|
||||||
|
|
||||||
controller.partnerId = if (index == 0) null else rJoyCons[index - 1].id
|
controller.partnerId = if (index == 0) null else rJoyCons[index - 1].id
|
||||||
|
|
||||||
if (controller.partnerId != null)
|
if (controller.partnerId != null)
|
||||||
(inputManager.controllers[controller.partnerId ?: -1] as JoyConRightController?)?.partnerId = controller.id
|
(inputManager.controllers[controller.partnerId ?: -1] as JoyConRightController?)?.partnerId = controller.id
|
||||||
|
|
||||||
item.update()
|
item.update()
|
||||||
|
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
GeneralType.RumbleDevice -> {
|
GeneralType.RumbleDevice -> {
|
||||||
|
@ -14,5 +14,6 @@
|
|||||||
android:id="@+id/controller_list"
|
android:id="@+id/controller_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:clipToPadding="false"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
|
@ -1,42 +1,50 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="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
|
<LinearLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="16dp"
|
android:ellipsize="marquee"
|
||||||
android:layout_marginTop="16dp"
|
android:singleLine="true"
|
||||||
android:layout_marginBottom="16dp"
|
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||||
android:layout_weight="1"
|
tools:text="Title" />
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text_title"
|
android:id="@+id/text_subtitle"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
android:maxLines="10"
|
||||||
tools:text="Title" />
|
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||||
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
<TextView
|
tools:text="Summary" />
|
||||||
android:id="@+id/text_subtitle"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
|
||||||
android:textColor="@android:color/tertiary_text_light"
|
|
||||||
tools:text="Summary" />
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<com.google.android.material.checkbox.MaterialCheckBox
|
<com.google.android.material.checkbox.MaterialCheckBox
|
||||||
android:id="@+id/checkbox"
|
android:id="@+id/checkbox"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="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>
|
</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"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
android:id="@+id/controller_item"
|
||||||
android:id="@+id/controller_item"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="match_parent"
|
android:layout_height="wrap_content"
|
||||||
|
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: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_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:ellipsize="marquee"
|
||||||
android:clickable="true"
|
android:singleLine="true"
|
||||||
android:focusable="true"
|
android:textAppearance="?android:attr/textAppearanceListItem" />
|
||||||
android:orientation="vertical"
|
|
||||||
android:paddingVertical="8dp"
|
|
||||||
android:paddingHorizontal="16dp">
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/text_title"
|
android:id="@+id/text_subtitle"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentStart="true"
|
android:maxLines="10"
|
||||||
android:layout_alignParentTop="false"
|
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
android:textColor="?android:attr/textColorSecondary" />
|
||||||
tools:ignore="RelativeOverlap" />
|
</LinearLayout>
|
||||||
|
|
||||||
<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:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
|
||||||
android:textColor="@android:color/tertiary_text_light" />
|
|
||||||
</RelativeLayout>
|
|
||||||
|
Loading…
Reference in New Issue
Block a user