mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-04-30 05:14:26 +02:00
feat: Add function to reset options to their default value
This commit is contained in:
parent
c7922e90d0
commit
e6de90d300
@ -370,6 +370,7 @@ public abstract class app/revanced/patcher/patch/options/PatchOption {
|
|||||||
public final fun getValidator ()Lkotlin/jvm/functions/Function1;
|
public final fun getValidator ()Lkotlin/jvm/functions/Function1;
|
||||||
public final fun getValue ()Ljava/lang/Object;
|
public final fun getValue ()Ljava/lang/Object;
|
||||||
public final fun getValue (Ljava/lang/Object;Lkotlin/reflect/KProperty;)Ljava/lang/Object;
|
public final fun getValue (Ljava/lang/Object;Lkotlin/reflect/KProperty;)Ljava/lang/Object;
|
||||||
|
public fun reset ()V
|
||||||
public final fun setValue (Ljava/lang/Object;)V
|
public final fun setValue (Ljava/lang/Object;)V
|
||||||
public final fun setValue (Ljava/lang/Object;Lkotlin/reflect/KProperty;Ljava/lang/Object;)V
|
public final fun setValue (Ljava/lang/Object;Lkotlin/reflect/KProperty;Ljava/lang/Object;)V
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ abstract class PatchOption<T>(
|
|||||||
/**
|
/**
|
||||||
* The value of the [PatchOption].
|
* The value of the [PatchOption].
|
||||||
*/
|
*/
|
||||||
var value: T? = default
|
var value: T?
|
||||||
/**
|
/**
|
||||||
* Set the value of the [PatchOption].
|
* Set the value of the [PatchOption].
|
||||||
*
|
*
|
||||||
@ -37,7 +37,7 @@ abstract class PatchOption<T>(
|
|||||||
assertRequiredButNotNull(value)
|
assertRequiredButNotNull(value)
|
||||||
assertValid(value)
|
assertValid(value)
|
||||||
|
|
||||||
field = value
|
uncheckedValue = value
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get the value of the [PatchOption].
|
* Get the value of the [PatchOption].
|
||||||
@ -48,10 +48,20 @@ abstract class PatchOption<T>(
|
|||||||
* @throws PatchOptionException.ValueValidationException If the value is invalid.
|
* @throws PatchOptionException.ValueValidationException If the value is invalid.
|
||||||
*/
|
*/
|
||||||
get() {
|
get() {
|
||||||
assertRequiredButNotNull(field)
|
assertRequiredButNotNull(uncheckedValue)
|
||||||
assertValid(field)
|
assertValid(uncheckedValue)
|
||||||
|
|
||||||
return field
|
return uncheckedValue
|
||||||
|
}
|
||||||
|
|
||||||
|
// The unchecked value is used to allow setting the value without validation.
|
||||||
|
private var uncheckedValue = default
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the [PatchOption] to its default value.
|
||||||
|
*/
|
||||||
|
open fun reset() {
|
||||||
|
uncheckedValue = default
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun assertRequiredButNotNull(value: T?) {
|
private fun assertRequiredButNotNull(value: T?) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user