Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aitorvs committed Mar 30, 2022
1 parent 2600e72 commit 18f24b0
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ import javax.inject.Inject
import kotlin.reflect.KClass

private const val REMOTE_FEATURE = "remote-feature"
private const val ON = "on"
private const val OFF = "off"
private const val TYPE = "type"

class VpnRemoteFeatureReceiver(
context: Context,
Expand All @@ -59,28 +62,28 @@ class VpnRemoteFeatureReceiver(

fun <T : AppTpConfig> enableIntent(type: KClass<T>): Intent {
return Intent(REMOTE_FEATURE).apply {
putExtra("type", type.nestedClassQualifiedName())
putExtra(type.qualifiedName, "on")
putExtra(TYPE, type.nestedClassQualifiedName())
putExtra(type.qualifiedName, ON)
}
}

fun <T : AppTpConfig> disableIntent(type: KClass<T>): Intent {
return Intent(REMOTE_FEATURE).apply {
putExtra("type", type.nestedClassQualifiedName())
putExtra(type.qualifiedName, "off")
putExtra(TYPE, type.nestedClassQualifiedName())
putExtra(type.qualifiedName, OFF)
}
}

fun isOnIntent(intent: Intent): Boolean {
return intent.getStringExtra(getType<AppTpConfig>(intent).qualifiedName)?.lowercase() == "on"
return intent.getStringExtra(getType<AppTpConfig>(intent).qualifiedName)?.lowercase() == ON
}

fun isOffIntent(intent: Intent): Boolean {
return intent.getStringExtra(getType<AppTpConfig>(intent).qualifiedName)?.lowercase() == "off"
return intent.getStringExtra(getType<AppTpConfig>(intent).qualifiedName)?.lowercase() == OFF
}

fun <T : AppTpConfig> getType(intent: Intent): KClass<T> {
return Class.forName(intent.getStringExtra("type")!!).kotlin as KClass<T>
return Class.forName(intent.getStringExtra(TYPE)!!).kotlin as KClass<T>
}

private fun KClass<*>.nestedClassQualifiedName(): String {
Expand Down

0 comments on commit 18f24b0

Please sign in to comment.