Address CR + Code formatting

This commit is contained in:
sspacelynx 2021-08-29 15:27:31 +02:00 committed by ◱ Mark
parent ca97517d81
commit 4d20d7a4d0
6 changed files with 44 additions and 86 deletions

View File

@ -54,7 +54,8 @@ static std::string GetTimeZoneName() {
}
extern "C" JNIEXPORT void Java_emu_skyline_EmulationActivity_executeApplication(
JNIEnv *env, jobject instance,
JNIEnv *env,
jobject instance,
jstring romUriJstring,
jint romType,
jint romFd,
@ -84,8 +85,7 @@ extern "C" JNIEXPORT void Java_emu_skyline_EmulationActivity_executeApplication(
perfetto::TrackEvent::Register();
try {
auto os{
std::make_shared<skyline::kernel::OS>(
auto os{std::make_shared<skyline::kernel::OS>(
jvmManager,
logger,
settings,

View File

@ -54,7 +54,7 @@ extern "C" JNIEXPORT jint JNICALL Java_emu_skyline_loader_RomFile_populate(JNIEn
if (loader->nacp) {
auto language{skyline::languages::GetApplicationLanguage(static_cast<skyline::languages::SystemLanguage>(systemLanguage))};
if ((1 << static_cast<skyline::u32>(language) & loader->nacp->supportedTitleLanguages) == 0)
if (((1 << static_cast<skyline::u32>(language)) & loader->nacp->supportedTitleLanguages) == 0)
language = loader->nacp->GetFirstSupportedTitleLanguage();
env->SetObjectField(thiz, applicationNameField, env->NewStringUTF(loader->nacp->GetApplicationName(language).c_str()));

View File

@ -21,8 +21,7 @@ namespace skyline::kernel {
std::string deviceTimeZone,
languages::SystemLanguage systemLanguage,
std::shared_ptr<vfs::FileSystem> assetFileSystem
)
: state(this, jvmManager, settings, logger),
) : state(this, jvmManager, settings, logger),
appFilesPath(std::move(appFilesPath)),
deviceTimeZone(std::move(deviceTimeZone)),
assetFileSystem(std::move(assetFileSystem)),

View File

@ -11,8 +11,7 @@
#include "IApplicationFunctions.h"
namespace skyline::service::am {
IApplicationFunctions::IApplicationFunctions(const DeviceState &state, ServiceManager &manager)
: gpuErrorEvent(std::make_shared<type::KEvent>(state, false)), BaseService(state, manager) {}
IApplicationFunctions::IApplicationFunctions(const DeviceState &state, ServiceManager &manager) : gpuErrorEvent(std::make_shared<type::KEvent>(state, false)), BaseService(state, manager) {}
Result IApplicationFunctions::PopLaunchParameter(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
constexpr u32 LaunchParameterMagic{0xC79497CA}; //!< The magic of the application launch parameters
@ -36,7 +35,8 @@ namespace skyline::service::am {
Result IApplicationFunctions::GetDesiredLanguage(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
auto desiredLanguage{languages::GetApplicationLanguage(state.os->systemLanguage)};
if ((1 << static_cast<u32>(desiredLanguage) & state.loader->nacp->nacpContents.supportedLanguageFlag) == 0)
// In the future we might want to trigger an UI dialog if the user selected languages is not available, for now it will use the first available
if (((1 << static_cast<u32>(desiredLanguage)) & state.loader->nacp->nacpContents.supportedLanguageFlag) == 0)
desiredLanguage = state.loader->nacp->GetFirstSupportedLanguage();
response.Push(languages::GetLanguageCode(languages::GetSystemLanguage(desiredLanguage)));

View File

@ -60,10 +60,9 @@ class SettingsActivity : AppCompatActivity() {
override fun onDisplayPreferenceDialog(preference : Preference?) {
if (preference is IntegerListPreference) {
// check if dialog is already showing
if (parentFragmentManager.findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) {
// Check if dialog is already showing
if (parentFragmentManager.findFragmentByTag(DIALOG_FRAGMENT_TAG) != null)
return
}
val f = IntegerListPreference.IntegerListPreferenceDialogFragmentCompat.newInstance(preference.getKey())
f.setTargetFragment(this, 0)

View File

@ -25,11 +25,10 @@ import emu.skyline.R as sR
import emu.skyline.di.getSettings
/**
* A Preference that displays a list of entries as a dialog.
* This preference saves an integer value instead of a string one.
* A Preference that displays a list of strings in a dialog and saves an integer that corresponds to the selected entry (as specified by entryValues or the index of the selected entry)
* @see androidx.preference.ListPreference
*/
@SuppressLint("RestrictedApi", "ResourceType")
@SuppressLint("RestrictedApi")
class IntegerListPreference @JvmOverloads constructor(
context : Context,
attrs : AttributeSet? = null,
@ -40,66 +39,48 @@ class IntegerListPreference @JvmOverloads constructor(
defStyleRes : Int = 0
) : DialogPreference(context, attrs, defStyleAttr, defStyleRes) {
/**
* The list of entries to be shown in the list in subsequent dialogs.
* The list of entries to be shown in the list in subsequent dialogs
*/
var entries : Array<CharSequence>?
/**
* The array to find the value to save for a preference when an entry from entries is
* selected. If a user clicks on the second item in entries, the second item in this array
* will be saved to the preference.
* will be saved to the preference
*/
var entryValues : IntArray?
private var value : Int? = null
set(value) {
// Always persist/notify the first time.
// Always persist/notify the first time
val changed = field != value
if (changed || !isValueSet) {
field = value
isValueSet = true
value?.let { persistInt(it) }
if (changed) {
if (changed)
notifyChanged()
}
}
}
private var isValueSet = false
val refreshRequired : Boolean
init {
val res : Resources = context.resources
val styledAttrs = context.obtainStyledAttributes(attrs, sR.styleable.IntegerListPreference, defStyleAttr, defStyleRes)
val a = context.obtainStyledAttributes(
attrs, sR.styleable.IntegerListPreference, defStyleAttr, defStyleRes
)
entries = TypedArrayUtils.getTextArray(styledAttrs, sR.styleable.IntegerListPreference_entries, sR.styleable.IntegerListPreference_android_entries)
entries = TypedArrayUtils.getTextArray(
a, sR.styleable.IntegerListPreference_entries,
sR.styleable.IntegerListPreference_android_entries
)
val entryValuesId = TypedArrayUtils.getResourceId(
a, sR.styleable.IntegerListPreference_android_entryValues,
sR.styleable.IntegerListPreference_android_entryValues, 0
)
val entryValuesId = TypedArrayUtils.getResourceId(styledAttrs, sR.styleable.IntegerListPreference_android_entryValues, sR.styleable.IntegerListPreference_android_entryValues, 0)
entryValues = if (entryValuesId != 0) res.getIntArray(entryValuesId) else null
if (TypedArrayUtils.getBoolean(
a, sR.styleable.IntegerListPreference_useSimpleSummaryProvider,
sR.styleable.IntegerListPreference_useSimpleSummaryProvider, false
)
) {
if (TypedArrayUtils.getBoolean(styledAttrs, sR.styleable.IntegerListPreference_useSimpleSummaryProvider, sR.styleable.IntegerListPreference_useSimpleSummaryProvider, false))
summaryProvider = SimpleSummaryProvider.instance
}
refreshRequired = TypedArrayUtils.getBoolean(
a, sR.styleable.IntegerListPreference_refreshRequired,
sR.styleable.IntegerListPreference_refreshRequired, false
)
refreshRequired = TypedArrayUtils.getBoolean(styledAttrs, sR.styleable.IntegerListPreference_refreshRequired, sR.styleable.IntegerListPreference_refreshRequired, false)
a.recycle()
styledAttrs.recycle()
}
/**
@ -124,25 +105,22 @@ class IntegerListPreference @JvmOverloads constructor(
}
/**
* @param value The value whose index should be returned
* @return The index of the value, or -1 if not found
*/
private fun findIndexOfValue(value : Int?) : Int {
entryValues?.let {
if (value != null) {
for (i in it.indices.reversed()) {
if (it[i] == value) {
if (it[i] == value)
return i
}
}
}
}
return value ?: -1
}
/**
* Sets the value to the given index from the entry values.
* @param index The index of the value to set
* Sets the value to the given index from the entry values
*/
fun setValueIndex(index : Int) {
value = entryValues?.get(index) ?: index
@ -157,22 +135,19 @@ class IntegerListPreference @JvmOverloads constructor(
}
override fun onSetInitialValue(defaultValue : Any?) {
// `Preference` superclass passes a null defaultValue if it is sure there
// is already a persisted value, se we have to account for that here by
// passing a random number as default value.
value = if (defaultValue != null) {
// `Preference` superclass passes a null defaultValue if it is sure there is already a persisted value
// We have to account for that here by passing a random number as default value
value = if (defaultValue != null)
getPersistedInt(defaultValue as Int)
} else {
else
getPersistedInt(0)
}
}
override fun onSaveInstanceState() : Parcelable {
val superState = super.onSaveInstanceState()
if (isPersistent) {
if (isPersistent)
// No need to save instance state since it's persistent
return superState
}
val myState = SavedState(superState)
myState.value = value
return myState
@ -218,9 +193,8 @@ class IntegerListPreference @JvmOverloads constructor(
}
/**
* A simple [androidx.preference.Preference.SummaryProvider] implementation for a
* [IntegerListPreference]. If no value has been set, the summary displayed will be 'Not set',
* otherwise the summary displayed will be the entry set for this preference.
* A simple [androidx.preference.Preference.SummaryProvider] implementation
* If no value has been set, the summary displayed will be 'Not set', otherwise the summary displayed will be the entry set for this preference
*/
class SimpleSummaryProvider private constructor() : SummaryProvider<IntegerListPreference> {
override fun provideSummary(preference : IntegerListPreference) : CharSequence {
@ -230,18 +204,10 @@ class IntegerListPreference @JvmOverloads constructor(
companion object {
private var simpleSummaryProvider : SimpleSummaryProvider? = null
/**
* Retrieve a singleton instance of this simple
* [androidx.preference.Preference.SummaryProvider] implementation.
*
* @return a singleton instance of this simple
* [androidx.preference.Preference.SummaryProvider] implementation
*/
val instance : SimpleSummaryProvider?
get() {
if (simpleSummaryProvider == null) {
if (simpleSummaryProvider == null)
simpleSummaryProvider = SimpleSummaryProvider()
}
return simpleSummaryProvider
}
}
@ -288,17 +254,12 @@ class IntegerListPreference @JvmOverloads constructor(
context?.getSettings()?.refreshRequired = true
}
// Clicking on an item simulates the positive button click, and dismisses
// the dialog.
onClick(
dialog,
DialogInterface.BUTTON_POSITIVE
)
// Clicking on an item simulates the positive button click, and dismisses the dialog
onClick(dialog, DialogInterface.BUTTON_POSITIVE)
dialog.dismiss()
}
// The typical interaction for list-based dialogs is to have click-on-an-item dismiss the
// dialog instead of the user having to press 'Ok'.
// The typical interaction for list-based dialogs is to have click-on-an-item dismiss the dialog instead of the user having to press 'Ok'
builder.setPositiveButton(null, null)
}
@ -306,11 +267,10 @@ class IntegerListPreference @JvmOverloads constructor(
if (positiveResult && clickedDialogEntryIndex >= 0) {
val value = entryValues?.get(clickedDialogEntryIndex) ?: clickedDialogEntryIndex
val preference = listPreference
if (preference.callChangeListener(value)) {
if (preference.callChangeListener(value))
preference.value = value
}
}
}
companion object {
private const val SAVE_STATE_INDEX = "ListPreferenceDialogFragment.index"
@ -319,9 +279,9 @@ class IntegerListPreference @JvmOverloads constructor(
fun newInstance(key : String?) : IntegerListPreferenceDialogFragmentCompat {
val fragment = IntegerListPreferenceDialogFragmentCompat()
val b = Bundle(1)
b.putString(ARG_KEY, key)
fragment.arguments = b
val bundle = Bundle(1)
bundle.putString(ARG_KEY, key)
fragment.arguments = bundle
return fragment
}
}