Move away KEY_OPERATING_CHANNEL
This commit is contained in:
@@ -23,8 +23,6 @@ import java.util.*
|
|||||||
|
|
||||||
class App : Application() {
|
class App : Application() {
|
||||||
companion object {
|
companion object {
|
||||||
const val KEY_OPERATING_CHANNEL = "service.repeater.oc"
|
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
lateinit var app: App
|
lateinit var app: App
|
||||||
}
|
}
|
||||||
@@ -80,10 +78,6 @@ class App : Application() {
|
|||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
val operatingChannel: Int get() {
|
|
||||||
val result = pref.getString(KEY_OPERATING_CHANNEL, null)?.toIntOrNull() ?: 0
|
|
||||||
return if (result in 1..165) result else 0
|
|
||||||
}
|
|
||||||
val masquerade get() = pref.getBoolean("service.masquerade", true)
|
val masquerade get() = pref.getBoolean("service.masquerade", true)
|
||||||
val dhcpWorkaround get() = pref.getBoolean("service.dhcpWorkaround", false)
|
val dhcpWorkaround get() = pref.getBoolean("service.dhcpWorkaround", false)
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ import java.lang.reflect.InvocationTargetException
|
|||||||
class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "RepeaterService"
|
private const val TAG = "RepeaterService"
|
||||||
|
const val KEY_OPERATING_CHANNEL = "service.repeater.oc"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is only a "ServiceConnection" to system service and its impact on system is minimal.
|
* This is only a "ServiceConnection" to system service and its impact on system is minimal.
|
||||||
*/
|
*/
|
||||||
@@ -49,6 +51,11 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere
|
|||||||
}
|
}
|
||||||
val supported get() = p2pManager != null
|
val supported get() = p2pManager != null
|
||||||
var persistentSupported = false
|
var persistentSupported = false
|
||||||
|
|
||||||
|
val operatingChannel: Int get() {
|
||||||
|
val result = app.pref.getString(KEY_OPERATING_CHANNEL, null)?.toIntOrNull() ?: 0
|
||||||
|
return if (result in 1..165) result else 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class Status {
|
enum class Status {
|
||||||
@@ -156,7 +163,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere
|
|||||||
|
|
||||||
override fun onBind(intent: Intent) = binder
|
override fun onBind(intent: Intent) = binder
|
||||||
|
|
||||||
private fun setOperatingChannel(oc: Int = app.operatingChannel) = try {
|
private fun setOperatingChannel(oc: Int = operatingChannel) = try {
|
||||||
val channel = channel
|
val channel = channel
|
||||||
if (channel == null) SmartSnackbar.make(R.string.repeater_failure_disconnected).show()
|
if (channel == null) SmartSnackbar.make(R.string.repeater_failure_disconnected).show()
|
||||||
// we don't care about listening channel
|
// we don't care about listening channel
|
||||||
@@ -186,7 +193,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||||
if (key == App.KEY_OPERATING_CHANNEL) setOperatingChannel()
|
if (key == KEY_OPERATING_CHANNEL) setOperatingChannel()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onPersistentGroupsChanged() {
|
private fun onPersistentGroupsChanged() {
|
||||||
|
|||||||
@@ -61,10 +61,10 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
|||||||
}
|
}
|
||||||
var oc: CharSequence
|
var oc: CharSequence
|
||||||
@Bindable get() {
|
@Bindable get() {
|
||||||
val oc = app.operatingChannel
|
val oc = RepeaterService.operatingChannel
|
||||||
return if (oc in 1..165) oc.toString() else ""
|
return if (oc in 1..165) oc.toString() else ""
|
||||||
}
|
}
|
||||||
set(value) = app.pref.edit().putString(App.KEY_OPERATING_CHANNEL, value.toString()).apply()
|
set(value) = app.pref.edit().putString(RepeaterService.KEY_OPERATING_CHANNEL, value.toString()).apply()
|
||||||
|
|
||||||
fun onStatusChanged() {
|
fun onStatusChanged() {
|
||||||
notifyPropertyChanged(BR.switchEnabled)
|
notifyPropertyChanged(BR.switchEnabled)
|
||||||
|
|||||||
Reference in New Issue
Block a user