Commit 24cf71fb authored by m-spi's avatar m-spi

merge

parents b716a458 d95f8def
......@@ -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")
......
......@@ -13,10 +13,13 @@
android:theme="@style/Theme.ElBuenoPeso"
tools:targetApi="31">
<activity
android:name=".AboutActivity"
android:name="settingActivity"
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>
......
......@@ -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)
......
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))
}
}
}
......@@ -5,7 +5,9 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.GridView
import android.widget.ListView
import android.widget.ToggleButton
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.example.elbuenopeso.databinding.FragmentMarketBinding
......@@ -15,25 +17,30 @@ import com.example.elbuenopeso.R
class MarketFragment : Fragment() {
private var _binding: FragmentMarketBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
private lateinit var listView: ListView
private lateinit var gridView: GridView
private lateinit var toggleButton: ToggleButton
private lateinit var adAdapter: AdAdapter
private var isGridViewEnabled = false
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val marketViewModel =
ViewModelProvider(this)[MarketViewModel::class.java]
_binding = FragmentMarketBinding.inflate(inflater, container, false)
val root: View = binding.root
val listView: ListView = binding.listView
// seed market items
var annonces: List<AdModel> = listOf<AdModel>(
listView = binding.listView
gridView = binding.gridView
toggleButton = binding.toggleButton
val annonces: List<AdModel> = listOf(
AdModel("Poutre", "1 rue Jean-Pierre", R.drawable.pichu, 25.0),
AdModel("Briques", "2 rue Jean-Michel", R.drawable.pichu, 16.0),
AdModel("Poutre", "1 rue Jean-Pierre", R.drawable.pichu, 25.0),
AdModel("Briques", "2 rue Jean-Michel", R.drawable.pichu, 16.0),
AdModel("Mur en bois", "4 rue Alain-Juju", R.drawable.pichu, 7.2),
......@@ -43,19 +50,43 @@ class MarketFragment : Fragment() {
AdModel("Charnières", "22 rue Jeanne-Marie", R.drawable.pichu, 2648.97),
AdModel("Porte en marbre", "1 rue Jean-Pierre", R.drawable.pichu, 480.0),
AdModel("Cheminée", "33 rue du Gouvernement", R.drawable.pichu, 800.0),
AdModel("Poutre", "1 rue Jean-Pierre", R.drawable.pichu, 25.0),
AdModel("Briques", "2 rue Jean-Michel", R.drawable.pichu, 16.0),
AdModel("Mur en bois", "4 rue Alain-Juju", R.drawable.pichu, 7.2),
AdModel("Maison de pierre", "7 rue Joris Belhomme", R.drawable.pichu, 3.99),
AdModel("Téléphone de Timothé", "8 rue de Timothé", R.drawable.pichu, 0.85),
AdModel("Oridnateur", "10 rue Jean-Charles", R.drawable.pichu, 104.98),
AdModel("Charnières", "22 rue Jeanne-Marie", R.drawable.pichu, 2648.97),
AdModel("Porte en marbre", "1 rue Jean-Pierre", R.drawable.pichu, 480.0),
AdModel("Cheminée", "33 rue du Gouvernement", R.drawable.pichu, 800.0),
// Add more AdModel items as needed
)
var adAdapter: AdAdapter = AdAdapter(requireContext(), annonces)
adAdapter = AdAdapter(requireContext(), annonces)
listView.adapter = adAdapter
/*marketViewModel.text.observe(viewLifecycleOwner) {
textView.text = it
}*/
toggleButton.setOnCheckedChangeListener { _, isChecked ->
isGridViewEnabled = isChecked
updateView()
}
return root
}
private fun updateView() {
if (isGridViewEnabled) {
listView.visibility = View.GONE
gridView.visibility = View.VISIBLE
gridView.adapter = adAdapter
} else {
gridView.visibility = View.GONE
listView.visibility = View.VISIBLE
listView.adapter = adAdapter
}
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
\ No newline at end of file
}
<?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>
......@@ -6,12 +6,37 @@
android:layout_height="match_parent"
tools:context=".ui.market.MarketFragment">
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toggle View"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toBottomOf="@id/toggleButton" />
<GridView
android:id="@+id/gridView"
android:layout_width="0dp"
android:layout_height="0dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:gravity="center"
android:horizontalSpacing="8dp"
android:verticalSpacing="8dp"
android:padding="8dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toggleButton" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
</androidx.constraintlayout.widget.ConstraintLayout>
<?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"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/itemListViewTitleView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="20sp"
app:layout_constraintStart_toEndOf="@+id/itemListViewImageView"
app:layout_constraintTop_toTopOf="parent" />
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
<ImageView
android:id="@+id/itemListViewImageView"
android:layout_width="117dp"
android:layout_height="94dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@drawable/pichu" />
android:layout_gravity="center_horizontal"
android:src="@drawable/pichu" />
<TextView
android:id="@+id/itemListViewTextView"
android:layout_width="wrap_content"
android:id="@+id/itemListViewTitleView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="@+id/itemListViewImageView"
app:layout_constraintStart_toEndOf="@+id/itemListViewImageView" />
android:textSize="20sp"
android:textStyle="bold"
android:maxLines="2"
android:ellipsize="end"
android:paddingTop="8dp"
android:paddingBottom="4dp" />
<TextView
android:id="@+id/itemListViewPrixView"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:paddingBottom="4dp" />
<TextView
android:id="@+id/itemListViewTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toTopOf="@+id/itemListViewTextView"
app:layout_constraintStart_toEndOf="@+id/itemListViewImageView"
app:layout_constraintTop_toBottomOf="@+id/itemListViewTitleView" />
android:textSize="14sp"
android:maxLines="3"
android:ellipsize="end" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
</LinearLayout>
......@@ -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
<?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
......@@ -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
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