Commit 6c2fff6d authored by m-spi's avatar m-spi

J'ai fini ma journée ciao

parent a90963cf
......@@ -26,7 +26,7 @@ class MainActivity : AppCompatActivity() {
// menu should be considered as top level destinations.
val appBarConfiguration = AppBarConfiguration(
setOf(
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_add
)
)
setupActionBarWithNavController(navController, appBarConfiguration)
......
package com.example.elbuenopeso.ui.add
import android.app.Activity
import android.content.Intent
import android.graphics.Bitmap
import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultCallback
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.result.registerForActivityResult
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.example.elbuenopeso.databinding.FragmentAddBinding
class AddFragment : Fragment() {
private var _binding: FragmentAddBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
var camera_open_id: Button? = null
var gallery_open_id: Button? = null
var click_image_id: ImageView? = null
private val galleryActivityResultLauncher: ActivityResultLauncher<Intent> =
registerForActivityResult(ActivityResultContracts.StartActivityForResult(),
ActivityResultCallback { fun onActivityResult(
requestCode: Int,
resultCode: Int,
data: Intent?
) {
if (resultCode == Activity.RESULT_OK) {
val image = data?.data as Uri
click_image_id!!.setImageURI(image)
}
}
}
)
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val notificationsViewModel =
ViewModelProvider(this).get(AddViewModel::class.java)
_binding = FragmentAddBinding.inflate(inflater, container, false)
val root: View = binding.root
binding.image.setOnClickListener {
val gallery = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
galleryActivityResultLauncher.launch(gallery)
}
// val textView: TextView = binding.textNotifications
// notificationsViewModel.text.observe(viewLifecycleOwner) {
// textView.text = it
// }
return root
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
\ No newline at end of file
package com.example.elbuenopeso.ui.notifications
package com.example.elbuenopeso.ui.add
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
class NotificationsViewModel : ViewModel() {
class AddViewModel : ViewModel() {
private val _text = MutableLiveData<String>().apply {
value = "This is notifications Fragment"
......
package com.example.elbuenopeso.ui.notifications
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.example.elbuenopeso.databinding.FragmentNotificationsBinding
class NotificationsFragment : Fragment() {
private var _binding: FragmentNotificationsBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val notificationsViewModel =
ViewModelProvider(this).get(NotificationsViewModel::class.java)
_binding = FragmentNotificationsBinding.inflate(inflater, container, false)
val root: View = binding.root
val textView: TextView = binding.textNotifications
notificationsViewModel.text.observe(viewLifecycleOwner) {
textView.text = it
}
return root
}
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"
tools:context=".ui.add.AddFragment">
<ImageView
android:id="@+id/image"
android:layout_width="334dp"
android:layout_height="334dp"
android:layout_marginTop="50dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@android:drawable/ic_menu_report_image"
android:contentDescription="@string/todo" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/titleLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginVertical="20dp"
android:hint="Title"
android:textColorHint="#6E6E6E"
app:layout_constraintTop_toBottomOf="@+id/image"
tools:layout_editor_absoluteX="20dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="36dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/addressLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginVertical="10dp"
android:hint="@string/address"
android:textColorHint="#6E6E6E"
app:layout_constraintTop_toBottomOf="@+id/titleLayout"
tools:layout_editor_absoluteX="20dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="36dp" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/send"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/addressLayout" />
</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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.notifications.NotificationsFragment">
<TextView
android:id="@+id/text_notifications"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -12,7 +12,7 @@
android:title="Market" />
<item
android:id="@+id/navigation_notifications"
android:id="@+id/navigation_add"
android:icon="@drawable/baseline_add_24"
android:title="Add" />
......
......@@ -18,8 +18,8 @@
tools:layout="@layout/fragment_dashboard" />
<fragment
android:id="@+id/navigation_notifications"
android:name="com.example.elbuenopeso.ui.notifications.NotificationsFragment"
android:id="@+id/navigation_add"
android:name="com.example.elbuenopeso.ui.add.AddFragment"
android:label="@string/title_notifications"
tools:layout="@layout/fragment_notifications" />
tools:layout="@layout/fragment_add" />
</navigation>
\ No newline at end of file
......@@ -3,4 +3,7 @@
<string name="title_home">Home</string>
<string name="title_dashboard">Dashboard</string>
<string name="title_notifications">Notifications</string>
<string name="todo">TODO</string>
<string name="address">Address</string>
<string name="send">Send</string>
</resources>
\ 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