Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ElBuenoPeso
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Matis SPINELLI
ElBuenoPeso
Commits
b2bc3455
Commit
b2bc3455
authored
Feb 20, 2024
by
Timothé KOBAK
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dark mode implemented
parent
d1ee753c
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
146 additions
and
3 deletions
+146
-3
build.gradle.kts
app/build.gradle.kts
+2
-0
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+5
-2
MainActivity.kt
app/src/main/java/com/example/elbuenopeso/MainActivity.kt
+7
-1
settingActivity.kt
app/src/main/java/com/example/elbuenopeso/settingActivity.kt
+62
-0
activity_setting.xml
app/src/main/res/layout/activity_setting.xml
+57
-0
colors.xml
app/src/main/res/values/colors.xml
+2
-0
styles.xml
app/src/main/res/values/styles.xml
+10
-0
build.gradle.kts
build.gradle.kts
+1
-0
No files found.
app/build.gradle.kts
View file @
b2bc3455
...
...
@@ -40,6 +40,7 @@ android {
dependencies
{
implementation
(
"androidx.preference:preference-ktx:1.1.1"
)
implementation
(
"androidx.core:core-ktx:1.12.0"
)
implementation
(
"androidx.appcompat:appcompat:1.6.1"
)
implementation
(
"com.google.android.material:material:1.11.0"
)
...
...
@@ -48,6 +49,7 @@ dependencies {
implementation
(
"androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0"
)
implementation
(
"androidx.navigation:navigation-fragment-ktx:2.7.7"
)
implementation
(
"androidx.navigation:navigation-ui-ktx:2.7.7"
)
implementation
(
"androidx.preference:preference:1.2.1"
)
testImplementation
(
"junit:junit:4.13.2"
)
androidTestImplementation
(
"androidx.test.ext:junit:1.1.5"
)
androidTestImplementation
(
"androidx.test.espresso:espresso-core:3.5.1"
)
...
...
app/src/main/AndroidManifest.xml
View file @
b2bc3455
...
...
@@ -13,10 +13,13 @@
android:theme=
"@style/Theme.ElBuenoPeso"
tools:targetApi=
"31"
>
<activity
android:name=
"
.About
Activity"
android:name=
"
setting
Activity"
android:exported=
"false"
/>
<activity
android:name=
".MainActivity"
android:name=
"AboutActivity"
android:exported=
"false"
/>
<activity
android:name=
"MainActivity"
android:exported=
"true"
android:label=
"@string/app_name"
>
<intent-filter>
...
...
app/src/main/java/com/example/elbuenopeso/MainActivity.kt
View file @
b2bc3455
...
...
@@ -11,6 +11,10 @@ import androidx.navigation.ui.AppBarConfiguration
import
androidx.navigation.ui.setupActionBarWithNavController
import
androidx.navigation.ui.setupWithNavController
import
com.example.elbuenopeso.databinding.ActivityMainBinding
import
androidx.appcompat.widget.SwitchCompat
import
androidx.preference.SwitchPreferenceCompat;
import
com.google.android.material.bottomnavigation.BottomNavigationView
class
MainActivity
:
AppCompatActivity
()
{
...
...
@@ -53,10 +57,12 @@ class MainActivity : AppCompatActivity() {
}
R
.
id
.
settings
->
{
Toast
.
makeText
(
this
,
"Settings Selected"
,
Toast
.
LENGTH_SHORT
).
show
()
startActivity
(
Intent
(
this
,
settingActivity
::
class
.
java
))
return
true
}
R
.
id
.
exit
->
{
Toast
.
makeText
(
this
,
"Exit Selected"
,
Toast
.
LENGTH_SHORT
).
show
()
finish
()
return
true
}
else
->
return
super
.
onOptionsItemSelected
(
item
)
...
...
app/src/main/java/com/example/elbuenopeso/settingActivity.kt
0 → 100644
View file @
b2bc3455
package
com.example.elbuenopeso
import
android.content.SharedPreferences
import
android.os.Bundle
import
android.widget.TextView
import
androidx.appcompat.app.AppCompatActivity
import
androidx.appcompat.app.AppCompatDelegate
import
androidx.appcompat.widget.SwitchCompat
import
androidx.preference.PreferenceManager
import
androidx.core.content.ContextCompat
import
com.example.elbuenopeso.R
class
settingActivity
:
AppCompatActivity
()
{
private
lateinit
var
themeSwitch
:
SwitchCompat
private
lateinit
var
titleTextView
:
TextView
private
lateinit
var
descriptionTextView
:
TextView
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_setting
)
themeSwitch
=
findViewById
(
R
.
id
.
themeSwitch
)
titleTextView
=
findViewById
(
R
.
id
.
titleTextView
)
descriptionTextView
=
findViewById
(
R
.
id
.
descriptionTextView
)
// Retrieve the current theme setting
val
sharedPreferences
=
PreferenceManager
.
getDefaultSharedPreferences
(
this
)
val
isNightMode
=
sharedPreferences
.
getBoolean
(
"night_mode"
,
false
)
themeSwitch
.
isChecked
=
isNightMode
// Set up click listener for theme switch
themeSwitch
.
setOnCheckedChangeListener
{
_
,
isChecked
->
applyTheme
(
isChecked
)
}
// Apply initial theme
applyTheme
(
isNightMode
)
// Listen for changes in night mode
delegate
.
localNightMode
=
AppCompatDelegate
.
MODE_NIGHT_FOLLOW_SYSTEM
}
private
fun
applyTheme
(
isNightMode
:
Boolean
)
{
// Update the theme setting
val
sharedPreferences
=
PreferenceManager
.
getDefaultSharedPreferences
(
this
)
sharedPreferences
.
edit
().
putBoolean
(
"night_mode"
,
isNightMode
).
apply
()
// Apply the selected theme
if
(
isNightMode
)
{
AppCompatDelegate
.
setDefaultNightMode
(
AppCompatDelegate
.
MODE_NIGHT_YES
)
titleTextView
.
setTextColor
(
ContextCompat
.
getColor
(
this
,
R
.
color
.
text_color_dark
))
descriptionTextView
.
setTextColor
(
ContextCompat
.
getColor
(
this
,
R
.
color
.
text_color_dark
))
}
else
{
AppCompatDelegate
.
setDefaultNightMode
(
AppCompatDelegate
.
MODE_NIGHT_NO
)
titleTextView
.
setTextColor
(
ContextCompat
.
getColor
(
this
,
R
.
color
.
text_color
))
descriptionTextView
.
setTextColor
(
ContextCompat
.
getColor
(
this
,
R
.
color
.
text_color
))
}
}
}
app/src/main/res/layout/activity_setting.xml
0 → 100644
View file @
b2bc3455
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@android:color/white"
tools:context=
".MainActivity"
>
<!-- Title -->
<TextView
android:id=
"@+id/titleTextView"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Theme Settings"
android:textSize=
"24sp"
android:textStyle=
"bold"
android:textColor=
"@color/text_color"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
android:layout_marginTop=
"32dp"
android:layout_marginStart=
"16dp"
android:layout_marginEnd=
"16dp"
/>
<!-- Description -->
<TextView
android:id=
"@+id/descriptionTextView"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"Choose your preferred theme"
android:textSize=
"16sp"
android:textColor=
"@color/text_color"
app:layout_constraintTop_toBottomOf=
"@id/titleTextView"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
android:layout_marginTop=
"8dp"
android:layout_marginStart=
"16dp"
android:layout_marginEnd=
"16dp"
/>
<!-- Switch -->
<com.google.android.material.switchmaterial.SwitchMaterial
android:id=
"@+id/themeSwitch"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:checked=
"false"
android:text=
"Dark Mode"
android:textSize=
"18sp"
app:layout_constraintTop_toBottomOf=
"@id/descriptionTextView"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
android:layout_marginTop=
"16dp"
android:layout_marginStart=
"16dp"
android:layout_marginEnd=
"16dp"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
app/src/main/res/values/colors.xml
View file @
b2bc3455
...
...
@@ -10,5 +10,7 @@
<color
name=
"bluee"
>
#284B63
</color>
<color
name=
"blueee"
>
#284B63
</color>
<color
name=
"navy"
>
#3C6E71
</color>
<color
name=
"text_color"
>
#000000
</color>
<!-- Default text color -->
<color
name=
"text_color_dark"
>
#FFFFFF
</color>
<!-- Text color for dark mode -->
</resources>
\ No newline at end of file
app/src/main/res/values/styles.xml
0 → 100644
View file @
b2bc3455
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style
name=
"AppTheme.Light"
parent=
"Theme.AppCompat.Light"
>
<!-- Customize light theme attributes here -->
</style>
<style
name=
"AppTheme.Dark"
parent=
"Theme.AppCompat"
>
<!-- Customize dark theme attributes here -->
</style>
</resources>
\ No newline at end of file
build.gradle.kts
View file @
b2bc3455
...
...
@@ -2,4 +2,5 @@
plugins
{
id
(
"com.android.application"
)
version
"8.2.2"
apply
false
id
(
"org.jetbrains.kotlin.android"
)
version
"1.9.22"
apply
false
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment