Commit 496cbd67 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Reload the menu when changing the query logging setting

parent 60879205
......@@ -106,7 +106,7 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0-M2'
implementation 'com.frostnerd.utilskt:preferences:1.5.14' // https://git.frostnerd.com/AndroidUtils/preferenceskt (Accessible after logging in [free of charge])
implementation 'com.frostnerd.utilskt:navigationdraweractivity:1.3.19' // https://git.frostnerd.com/AndroidUtils/navigationdraweractivity (Accessible after logging in [free of charge])
implementation 'com.frostnerd.utilskt:navigationdraweractivity:1.3.20' // https://git.frostnerd.com/AndroidUtils/navigationdraweractivity (Accessible after logging in [free of charge])
implementation 'com.frostnerd.utilskt:encrypteddnstunnelproxy:1.5.137' // https://git.frostnerd.com/AndroidUtils/encrypteddnstunnelproxy
implementation 'com.frostnerd.utilskt:general:1.0.16' // https://git.frostnerd.com/AndroidUtils/generalkt (Accessible after logging in [free of charge])
implementation 'com.frostnerd.utilskt:adapters:1.1.1' // https://git.frostnerd.com/AndroidUtils/Adapters (Accessible after logging in [free of charge])
......
......@@ -13,7 +13,11 @@ import android.net.NetworkCapabilities
import android.net.Uri
import android.os.Build
import android.os.PowerManager
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.frostnerd.dnstunnelproxy.Decision
import com.frostnerd.dnstunnelproxy.DnsServerConfiguration
......@@ -119,6 +123,32 @@ fun Context.registerLocalReceiver(
return actualReceiver
}
fun AppCompatActivity.registerLocalReceiver(
filteredActions: List<String>,
unregisterOnDestroy:Boolean,
receiver: (intent: Intent?) -> Unit
): BroadcastReceiver {
val filter = IntentFilter()
for (filteredAction in filteredActions) {
filter.addAction(filteredAction)
}
val actualReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
receiver(intent)
}
}
val mgr = LocalBroadcastManager.getInstance(this)
mgr.registerReceiver(actualReceiver, filter)
if(unregisterOnDestroy) lifecycle.addObserver(object:LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
fun onDestroy() {
mgr.unregisterReceiver(actualReceiver)
}
})
return actualReceiver
}
fun Context.sendLocalBroadcast(intent: Intent) {
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
}
......
......@@ -48,11 +48,13 @@ import kotlin.random.Random
* You can contact the developer at daniel.wolf@frostnerd.com.
*/
class MainActivity : NavigationDrawerActivity() {
companion object {
const val BROADCAST_RELOAD_MENU = "main.reloadMenu"
}
override val drawerOverActionBar: Boolean = true
private var textColor: Int = 0
private var backgroundColor: Int = 0
private var inputElementColor: Int = 0
private var startedActivity = false
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(getPreferences().theme.layoutStyle)
......@@ -140,6 +142,9 @@ class MainActivity : NavigationDrawerActivity() {
getPreferences().vpnServiceState = VpnServiceState.STOPPED
BatteryOptimizationInfoDialog(this).show()
}
registerLocalReceiver(listOf(BROADCAST_RELOAD_MENU), true) {
reloadMenuItems()
}
}
private fun handleDeepAction() {
......@@ -175,6 +180,7 @@ class MainActivity : NavigationDrawerActivity() {
fragmentCreator = {
QueryLogFragment()
})
}
divider()
clickableItem(getString(R.string.menu_create_shortcut),
......
......@@ -163,6 +163,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
queryLogging.setOnPreferenceChangeListener { _, newValue ->
requireContext().getPreferences().queryLoggingEnabled = newValue as Boolean
context?.sendLocalBroadcast(Intent(MainActivity.BROADCAST_RELOAD_MENU))
true
}
exportQueries.summary =
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment