Android: Convert AdHocStringSetting to Kotlin

This commit is contained in:
Charles Lombardo 2023-03-15 03:24:27 -04:00
parent a8f3d4291a
commit 84c23c14db
2 changed files with 36 additions and 61 deletions

View File

@ -1,61 +0,0 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.features.settings.model;
import androidx.annotation.NonNull;
public class AdHocStringSetting implements AbstractStringSetting
{
private final String mFile;
private final String mSection;
private final String mKey;
private final String mDefaultValue;
public AdHocStringSetting(String file, String section, String key, String defaultValue)
{
mFile = file;
mSection = section;
mKey = key;
mDefaultValue = defaultValue;
if (!NativeConfig.isSettingSaveable(file, section, key))
{
throw new IllegalArgumentException("File/section/key is unknown or legacy");
}
}
@Override
public boolean isOverridden()
{
return NativeConfig.isOverridden(mFile, mSection, mKey);
}
@Override
public boolean isRuntimeEditable()
{
return true;
}
@Override
public boolean delete(@NonNull Settings settings)
{
return NativeConfig.deleteKey(settings.getWriteLayer(), mFile, mSection, mKey);
}
@NonNull @Override
public String getString()
{
return NativeConfig.getString(NativeConfig.LAYER_ACTIVE, mFile, mSection, mKey, mDefaultValue);
}
@Override
public void setString(@NonNull Settings settings, @NonNull String newValue)
{
NativeConfig.setString(settings.getWriteLayer(), mFile, mSection, mKey, newValue);
}
public static String getStringGlobal(String file, String section, String key, String defaultValue)
{
return NativeConfig.getString(NativeConfig.LAYER_ACTIVE, file, section, key, defaultValue);
}
}

View File

@ -0,0 +1,36 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.features.settings.model
class AdHocStringSetting(
private val file: String,
private val section: String,
private val key: String,
private val defaultValue: String
) : AbstractStringSetting {
init {
require(
NativeConfig.isSettingSaveable(
file,
section,
key
)
) { "File/section/key is unknown or legacy" }
}
override val isOverridden: Boolean
get() = NativeConfig.isOverridden(file, section, key)
override val isRuntimeEditable: Boolean = true
override fun delete(settings: Settings): Boolean {
return NativeConfig.deleteKey(settings.writeLayer, file, section, key)
}
override val string: String
get() = NativeConfig.getString(NativeConfig.LAYER_ACTIVE, file, section, key, defaultValue)
override fun setString(settings: Settings, newValue: String) {
NativeConfig.setString(settings.writeLayer, file, section, key, newValue)
}
}