diff --git a/app/WikiSpot/app/src/main/java/com/example/wikispot/Extentions.kt b/app/WikiSpot/app/src/main/java/com/example/wikispot/Extentions.kt index cc26a32..f0f6e8e 100644 --- a/app/WikiSpot/app/src/main/java/com/example/wikispot/Extentions.kt +++ b/app/WikiSpot/app/src/main/java/com/example/wikispot/Extentions.kt @@ -25,17 +25,9 @@ fun Context.showSnack(message: String, view: View, length: Int = Snackbar.LENGTH fun Context.getThemeId(): Int { if (ThemeOptions.darkTheme) { - if (ThemeOptions.actionBar) { - return R.style.Theme_WikiSpotWithActionBarDark - } else { - return R.style.Theme_WikiSpotDark - } + return R.style.Theme_WikiSpotDark } else { - if (ThemeOptions.actionBar) { - return R.style.Theme_WikiSpotWithActionBar - } else { - return R.style.Theme_WikiSpot - } + return R.style.Theme_WikiSpot } } diff --git a/app/WikiSpot/app/src/main/java/com/example/wikispot/activities/MainActivity.kt b/app/WikiSpot/app/src/main/java/com/example/wikispot/activities/MainActivity.kt index 0b55dc7..f71cd19 100644 --- a/app/WikiSpot/app/src/main/java/com/example/wikispot/activities/MainActivity.kt +++ b/app/WikiSpot/app/src/main/java/com/example/wikispot/activities/MainActivity.kt @@ -1,8 +1,10 @@ package com.example.wikispot.activities +import android.content.Intent import android.os.Bundle import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.app.AppCompatDelegate import androidx.navigation.findNavController import androidx.navigation.ui.setupWithNavController import com.example.wikispot.* @@ -24,8 +26,8 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { loadSettings() - setTheme(getThemeId()) + super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) @@ -42,18 +44,20 @@ class MainActivity : AppCompatActivity() { val dataReceiver: (String) -> Unit = {data: String -> println("Data here: $data") - when (mainFragmentHost.childFragmentManager.fragments[0]) { - is chatFragment -> {} - is exploreFragment -> {} - is homeFragment -> { - val view = mainFragmentHost.childFragmentManager.fragments[0].homeFragmentTextIdTest - view.post { - view.text = data + try { + when (mainFragmentHost.childFragmentManager.fragments[0]) { + is chatFragment -> {} + is exploreFragment -> {} + is homeFragment -> { + val view = mainFragmentHost.childFragmentManager.fragments[0].homeFragmentTextIdTest + view.post { + view.text = data + } } + is mapFragment -> {} + is settingsFragment -> {} } - is mapFragment -> {} - is settingsFragment -> {} - } + } catch (e: Throwable) { println(e) } } @@ -76,7 +80,17 @@ class MainActivity : AppCompatActivity() { } private fun loadSettings() { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) val settingsSaveManager = SettingsSaveManager(this) settingsSaveManager.loadSettings() } + + private fun restartAppPartially() { + val intent = Intent(applicationContext, MainActivity::class.java) + + intent.putExtra(IntentsKeys.startFragment, "settingsFragment") + + startActivity(intent) + finish() + } } diff --git a/app/WikiSpot/app/src/main/java/com/example/wikispot/fragments/settingsFragment.kt b/app/WikiSpot/app/src/main/java/com/example/wikispot/fragments/settingsFragment.kt index fb2ed9f..4e05b5e 100644 --- a/app/WikiSpot/app/src/main/java/com/example/wikispot/fragments/settingsFragment.kt +++ b/app/WikiSpot/app/src/main/java/com/example/wikispot/fragments/settingsFragment.kt @@ -7,8 +7,10 @@ import android.view.View import androidx.navigation.Navigation import com.example.wikispot.IntentsKeys import com.example.wikispot.R +import com.example.wikispot.ServerManagement import com.example.wikispot.ThemeOptions import com.example.wikispot.activities.MainActivity +import com.example.wikispot.modelClasses.ServerManager import com.example.wikispot.modelClasses.SettingsSaveManager import kotlinx.android.synthetic.main.fragment_settings.* @@ -33,22 +35,12 @@ class settingsFragment : Fragment(R.layout.fragment_settings) { settingsSaveManager.saveSettings() restartAppPartially() } - - actionBarSwitch.setOnCheckedChangeListener { _, isChecked -> - ThemeOptions.actionBar = isChecked - settingsSaveManager.saveSettings() - restartAppPartially() - } } private fun loadSettings() { if (ThemeOptions.darkTheme) { darkThemeSwitch.isChecked = true } - - if (ThemeOptions.actionBar) { - actionBarSwitch.isChecked = true - } } private fun restartAppPartially() { @@ -56,6 +48,8 @@ class settingsFragment : Fragment(R.layout.fragment_settings) { intent.putExtra(IntentsKeys.startFragment, "settingsFragment") + ServerManagement.serverManager.clearConnections() + startActivity(intent) activity?.finish() } diff --git a/app/WikiSpot/app/src/main/java/com/example/wikispot/modelClasses/ServerManager.kt b/app/WikiSpot/app/src/main/java/com/example/wikispot/modelClasses/ServerManager.kt index 0c4f388..36be32e 100644 --- a/app/WikiSpot/app/src/main/java/com/example/wikispot/modelClasses/ServerManager.kt +++ b/app/WikiSpot/app/src/main/java/com/example/wikispot/modelClasses/ServerManager.kt @@ -88,6 +88,17 @@ class ServerManager { // connections + fun clearConnections() { + for (i in 0 until receiverConnections.size) { + receiverConnections[i].running = false + receiverConnections.removeAt(i) + } + for (i in 0 until viewConnections.size) { + viewConnections[i].running = false + viewConnections.removeAt(i) + } + } + fun deleteConnection(connectionName: String, connectionType: String="any") { // other types are any, activity and view if ((connectionType == "any") or (connectionType == "activity")) { for (i in 0 until receiverConnections.size) { // checking in connections diff --git a/app/WikiSpot/app/src/main/java/com/example/wikispot/modelClasses/SettingsSaveManager.kt b/app/WikiSpot/app/src/main/java/com/example/wikispot/modelClasses/SettingsSaveManager.kt index 221c1be..1e4bf4f 100644 --- a/app/WikiSpot/app/src/main/java/com/example/wikispot/modelClasses/SettingsSaveManager.kt +++ b/app/WikiSpot/app/src/main/java/com/example/wikispot/modelClasses/SettingsSaveManager.kt @@ -1,7 +1,13 @@ package com.example.wikispot.modelClasses import android.content.Context +import android.content.Intent +import android.content.res.Configuration +import androidx.appcompat.app.AppCompatDelegate +import com.example.wikispot.GeneralVariables +import com.example.wikispot.IntentsKeys import com.example.wikispot.ThemeOptions +import com.example.wikispot.activities.MainActivity class SettingsSaveManager(val context: Context) { @@ -9,7 +15,20 @@ class SettingsSaveManager(val context: Context) { val sharedPreferences = context.getSharedPreferences("settings", Context.MODE_PRIVATE) ThemeOptions.darkTheme = sharedPreferences.getBoolean("darkMode", ThemeOptions.darkTheme) - ThemeOptions.actionBar = sharedPreferences.getBoolean("actionBar", ThemeOptions.actionBar) + + // checking if we want to use system default theme + try { + GeneralVariables.appRunningFirstTime = sharedPreferences.getBoolean("appRunningFirstTime", true) + + if (GeneralVariables.appRunningFirstTime) { + ThemeOptions.darkTheme = (context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES) + } + } catch (e: Throwable) { + println(e) + } + + // saving settings cause some things might change based on system preferences + saveSettings() } fun saveSettings() { @@ -17,8 +36,8 @@ class SettingsSaveManager(val context: Context) { val editor = sharedPreferences.edit() editor.apply{ + putBoolean("appRunningFirstTime", false) putBoolean("darkMode", ThemeOptions.darkTheme) - putBoolean("actionBar", ThemeOptions.actionBar) }.apply() } diff --git a/app/WikiSpot/app/src/main/java/com/example/wikispot/projectScopeVariables.kt b/app/WikiSpot/app/src/main/java/com/example/wikispot/projectScopeVariables.kt index 0e5e98d..ac96a1a 100644 --- a/app/WikiSpot/app/src/main/java/com/example/wikispot/projectScopeVariables.kt +++ b/app/WikiSpot/app/src/main/java/com/example/wikispot/projectScopeVariables.kt @@ -9,6 +9,12 @@ object ManifestRelatedVariables { } +object GeneralVariables { + + var appRunningFirstTime = true + +} + object IntentsKeys { const val startFragment = "start_fragment" @@ -17,7 +23,7 @@ object IntentsKeys { object ServerManagement { - val serverManager = ServerManager() + var serverManager = ServerManager() const val activityConnectionOnCheckWait: Long = 4000 const val viewConnectionOnCheckWait: Long = 5000 const val dataRequestOnAttemptWait: Long = 2000 @@ -28,6 +34,5 @@ object ServerManagement { object ThemeOptions { var darkTheme = false - var actionBar = false } diff --git a/app/WikiSpot/app/src/main/res/color/bottom_nav_bar_item_color.xml b/app/WikiSpot/app/src/main/res/color/bottom_nav_bar_item_color.xml new file mode 100644 index 0000000..92c5e32 --- /dev/null +++ b/app/WikiSpot/app/src/main/res/color/bottom_nav_bar_item_color.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/WikiSpot/app/src/main/res/layout/activity_main.xml b/app/WikiSpot/app/src/main/res/layout/activity_main.xml index 91e90b0..0bdbd95 100644 --- a/app/WikiSpot/app/src/main/res/layout/activity_main.xml +++ b/app/WikiSpot/app/src/main/res/layout/activity_main.xml @@ -10,10 +10,12 @@ android:id="@+id/mainBottomNavigationView" android:layout_width="match_parent" android:layout_height="70dp" - app:itemRippleColor="#43E8E8E8" + app:itemRippleColor="?attr/bottomNavBarRippleColor" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" + app:itemIconTint="@color/bottom_nav_bar_item_color" + app:itemTextColor="@color/bottom_nav_bar_item_color" app:menu="@menu/main_bottom_nav_menu" /> - - - - + app:layout_constraintTop_toTopOf="@+id/darkThemeSwitchText" + tools:ignore="UseSwitchCompatOrMaterialXml" /> \ No newline at end of file diff --git a/app/WikiSpot/app/src/main/res/values-night/themes.xml b/app/WikiSpot/app/src/main/res/values-night/themes.xml index e69a2ce..ffd7ee6 100644 --- a/app/WikiSpot/app/src/main/res/values-night/themes.xml +++ b/app/WikiSpot/app/src/main/res/values-night/themes.xml @@ -1,33 +1,39 @@ - + - + + \ No newline at end of file diff --git a/app/WikiSpot/app/src/main/res/values/attrs.xml b/app/WikiSpot/app/src/main/res/values/attrs.xml new file mode 100644 index 0000000..095c445 --- /dev/null +++ b/app/WikiSpot/app/src/main/res/values/attrs.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/WikiSpot/app/src/main/res/values/colors.xml b/app/WikiSpot/app/src/main/res/values/colors.xml index 4c29f1f..b3ac9b4 100644 --- a/app/WikiSpot/app/src/main/res/values/colors.xml +++ b/app/WikiSpot/app/src/main/res/values/colors.xml @@ -8,10 +8,22 @@ #FF000000 #FFFFFFFF + #E11976D2 #2EBFB2 #7CB342 #FBC02D #F57C00 + #ECB269C8 + #43E8E8E8 + + + #422DA9 + #5829B1 + #6A1B9A + #AD1457 + #C62845 + #D7BEDE + #33222222 \ No newline at end of file diff --git a/app/WikiSpot/app/src/main/res/values/themes.xml b/app/WikiSpot/app/src/main/res/values/themes.xml index cfe8f9a..20a7a5b 100644 --- a/app/WikiSpot/app/src/main/res/values/themes.xml +++ b/app/WikiSpot/app/src/main/res/values/themes.xml @@ -1,22 +1,8 @@ - + + + - - - + + + + + + - + + \ No newline at end of file