diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt index 5f7be9d..8aa3b96 100644 --- a/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/activities/MainActivity.kt @@ -3,6 +3,7 @@ package org.foxarmy.barcodescannerforemployees.activities import android.app.Activity import android.content.DialogInterface import android.content.Intent +import android.content.SharedPreferences import android.os.Bundle import android.util.Log import android.view.Menu @@ -43,12 +44,22 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte private var actionBarDrawerToggle: ActionBarDrawerToggle? = null private lateinit var ws: WebSocketClient + private lateinit var sharedPreferences: SharedPreferences + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) + sharedPreferences = EncryptedSharedPreferences.create( + "sensitive", + MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC), + applicationContext, + EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, + EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM + ) + setSupportActionBar(binding.toolbar) setupViewPager(binding.tabViewpager) binding.tabTablayout.setupWithViewPager(binding.tabViewpager) @@ -123,15 +134,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte } private fun synchronize() { - - val sharedPreferences = EncryptedSharedPreferences.create( - "sensitive", - MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC), - applicationContext, - EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, - EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM - ) - if (sharedPreferences.getString("currentGroup", "offline")!! == "offline") return val net = Net() @@ -346,13 +348,6 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte } private fun isOffline(): Boolean { - val sharedPreferences = EncryptedSharedPreferences.create( - "sensitive", - MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC), - applicationContext, - EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, - EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM - ) return sharedPreferences.getString("currentGroup", "") == "offline" } @@ -380,6 +375,15 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte R.id.nav_settings -> { intent = Intent(this, SettingsActivity::class.java) } + + R.id.nav_logout -> { + sharedPreferences.edit().putString("currentGroup", "").apply() + sharedPreferences.edit().putStringSet("groups", emptySet()).apply() + sharedPreferences.edit().putString("token", "").apply() + sharedPreferences.edit().putString("server", "").apply() + + intent = Intent(this, LoginActivity::class.java) + } } startActivity(intent) diff --git a/app/src/main/res/menu/drawer_menu.xml b/app/src/main/res/menu/drawer_menu.xml index 8cb05ef..eaf8fab 100644 --- a/app/src/main/res/menu/drawer_menu.xml +++ b/app/src/main/res/menu/drawer_menu.xml @@ -12,4 +12,5 @@ + \ No newline at end of file