more changes

This commit is contained in:
Tucan444 2021-03-23 12:03:56 +01:00
parent 8932c4b612
commit 47935a1b5b
17 changed files with 195 additions and 118 deletions

@ -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
}
}

@ -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()
}
}

@ -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()
}

@ -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

@ -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()
}

@ -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
}

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="?attr/bottomNavBarCheckedItemColor" />
<item android:color="?attr/colorOnPrimary" />
</selector>

@ -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" />
<fragment

@ -4,7 +4,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/chatFragmentBackground"
android:background="?attr/chatFragmentBg"
tools:background="@color/chatFragmentBackground"
tools:context=".fragments.chatFragment">
<TextView

@ -4,7 +4,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/exploreFragmentBackground"
android:background="?attr/exploreFragmentBg"
tools:background="@color/exploreFragmentBackground"
tools:context=".fragments.exploreFragment">
<TextView

@ -4,7 +4,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/homeFragmentBackground"
android:background="?attr/homeFragmentBg"
tools:background="@color/homeFragmentBackground"
tools:context=".fragments.homeFragment">
<TextView

@ -4,7 +4,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/mapFragmentBackground"
android:background="?attr/mapFragmentBg"
tools:background="@color/mapFragmentBackground"
tools:context=".fragments.mapFragment">
<TextView

@ -4,23 +4,10 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/settingsFragmentBackground"
android:background="?attr/settingsFragmentBg"
tools:background="@color/settingsFragmentBackground"
tools:context=".fragments.settingsFragment">
<TextView
android:id="@+id/actionBarThemeSwitchText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="64dp"
android:layout_marginLeft="64dp"
android:layout_marginTop="32dp"
android:text="Action Bar"
android:textColor="#FFFFFF"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/darkThemeSwitchText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -64,15 +51,7 @@
android:layout_marginLeft="16dp"
app:layout_constraintBottom_toBottomOf="@+id/darkThemeSwitchText"
app:layout_constraintStart_toEndOf="@+id/darkThemeSwitchText"
app:layout_constraintTop_toTopOf="@+id/darkThemeSwitchText" />
<Switch
android:id="@+id/actionBarSwitch"
android:layout_width="50dp"
android:layout_height="21dp"
app:layout_constraintBottom_toBottomOf="@+id/actionBarThemeSwitchText"
app:layout_constraintEnd_toEndOf="@+id/darkThemeSwitch"
app:layout_constraintStart_toStartOf="@+id/darkThemeSwitch"
app:layout_constraintTop_toTopOf="@+id/actionBarThemeSwitchText" />
app:layout_constraintTop_toTopOf="@+id/darkThemeSwitchText"
tools:ignore="UseSwitchCompatOrMaterialXml" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -1,33 +1,39 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<!-- Dark themes below -->
<style name="Theme.WikiSpot" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorPrimary">#B078F4</item>
<item name="colorPrimaryVariant">#5100B3</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<!-- Backgrounds -->
<item name="chatFragmentBg">#3A4460</item>
<item name="exploreFragmentBg">#2E3E43</item>
<item name="homeFragmentBg">#424F34</item>
<item name="mapFragmentBg">#48443B</item>
<item name="settingsFragmentBg">#453C32</item>
<item name="android:windowFullscreen">true</item>
<!-- BottomNavCheckedItemColor -->
<item name="bottomNavBarCheckedItemColor">@color/bottomNavBarCheckedItemColorDark</item>
<!-- Other items -->
<item name="bottomNavigationStyle">@style/Widget.App.BottomNavigationViewDark</item>
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
</style>
<style name="Theme.WikiSpotWithActionBar" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<style name="Widget.App.BottomNavigationViewDark" parent="Widget.MaterialComponents.BottomNavigationView.Colored">
<item name="materialThemeOverlay">@style/ThemeOverlay.App.BottomNavigationViewDark</item>
</style>
<style name="ThemeOverlay.App.BottomNavigationViewDark" parent="">
<item name="colorPrimary">#9758BC</item>
<item name="colorOnPrimary">#41254E</item>
</style>
</resources>

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Backgrounds -->
<attr name="chatFragmentBg" format="color"/>
<attr name="exploreFragmentBg" format="color"/>
<attr name="homeFragmentBg" format="color"/>
<attr name="mapFragmentBg" format="color"/>
<attr name="settingsFragmentBg" format="color"/>
<!-- For bottomNavBar -->
<attr name="bottomNavBarCheckedItemColor" format="color"/>
<attr name="bottomNavBarRippleColor" format="color"/>
</resources>

@ -8,10 +8,22 @@
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<!-- Light Theme -->
<color name="chatFragmentBackground">#E11976D2</color>
<color name="exploreFragmentBackground">#2EBFB2</color>
<color name="homeFragmentBackground">#7CB342</color>
<color name="mapFragmentBackground">#FBC02D</color>
<color name="settingsFragmentBackground">#F57C00</color>
<color name="bottomNavBarCheckedItemColor">#ECB269C8</color>
<color name="bottomNavBarRippleColor">#43E8E8E8</color>
<!-- Dark Theme -->
<color name="chatFragmentBackgroundDark">#422DA9</color>
<color name="exploreFragmentBackgroundDark">#5829B1</color>
<color name="homeFragmentBackgroundDark">#6A1B9A</color>
<color name="mapFragmentBackgroundDark">#AD1457</color>
<color name="settingsFragmentBackgroundDark">#C62845</color>
<color name="bottomNavBarCheckedItemColorDark">#D7BEDE</color>
<color name="bottomNavBarRippleColorDark">#33222222</color>
</resources>

@ -1,22 +1,8 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<!-- Light theme -->
<style name="Theme.WikiSpot" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#8BC34A</item>
<item name="colorPrimaryVariant">#388E3C</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#E91E63</item>
<item name="colorSecondaryVariant">#F48FB1</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<item name="android:windowFullscreen">true</item>
</style>
<style name="Theme.WikiSpotWithActionBar" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#4CAF50</item>
<item name="colorPrimaryVariant">#388E3C</item>
@ -26,12 +12,34 @@
<item name="colorSecondaryVariant">#F48FB1</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<!-- Backgrounds -->
<item name="chatFragmentBg">@color/chatFragmentBackground</item>
<item name="exploreFragmentBg">@color/exploreFragmentBackground</item>
<item name="homeFragmentBg">@color/homeFragmentBackground</item>
<item name="mapFragmentBg">@color/mapFragmentBackground</item>
<item name="settingsFragmentBg">@color/settingsFragmentBackground</item>
<!-- BottomNavCheckedItemColor -->
<item name="bottomNavBarCheckedItemColor">@color/bottomNavBarCheckedItemColor</item>
<item name="bottomNavBarRippleColor">@color/bottomNavBarRippleColor</item>
<!-- Other items -->
<item name="bottomNavigationStyle">@style/Widget.App.BottomNavigationView</item>
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
<!-- Dark themes below -->
<style name="Widget.App.BottomNavigationView" parent="Widget.MaterialComponents.BottomNavigationView.Colored">
<item name="materialThemeOverlay">@style/ThemeOverlay.App.BottomNavigationView</item>
</style>
<style name="ThemeOverlay.App.BottomNavigationView" parent="">
<item name="colorPrimary">#EDD9F8</item>
<item name="colorOnPrimary">#C788EB</item>
</style>
<!-- Dark theme-->
<style name="Theme.WikiSpotDark" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#B078F4</item>
@ -41,22 +49,31 @@
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<item name="android:windowFullscreen">true</item>
<!-- Backgrounds -->
<item name="chatFragmentBg">@color/chatFragmentBackgroundDark</item>
<item name="exploreFragmentBg">@color/exploreFragmentBackgroundDark</item>
<item name="homeFragmentBg">@color/homeFragmentBackgroundDark</item>
<item name="mapFragmentBg">@color/mapFragmentBackgroundDark</item>
<item name="settingsFragmentBg">@color/settingsFragmentBackgroundDark</item>
<!-- for BottomNavBar -->
<item name="bottomNavBarCheckedItemColor">@color/bottomNavBarCheckedItemColorDark</item>
<item name="bottomNavBarRippleColor">@color/bottomNavBarRippleColorDark</item>
<!-- Other items -->
<item name="bottomNavigationStyle">@style/Widget.App.BottomNavigationViewDark</item>
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
</style>
<style name="Theme.WikiSpotWithActionBarDark" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#B078F4</item>
<item name="colorPrimaryVariant">#5100B3</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<style name="Widget.App.BottomNavigationViewDark" parent="Widget.MaterialComponents.BottomNavigationView.Colored">
<item name="materialThemeOverlay">@style/ThemeOverlay.App.BottomNavigationViewDark</item>
</style>
<style name="ThemeOverlay.App.BottomNavigationViewDark" parent="">
<item name="colorPrimary">#9758BC</item>
<item name="colorOnPrimary">#41254E</item>
</style>
</resources>