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
a7b30035
Commit
a7b30035
authored
Feb 16, 2024
by
m-spi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
marche pas...
parent
6c2fff6d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
17 deletions
+59
-17
AddFragment.kt
...c/main/java/com/example/elbuenopeso/ui/add/AddFragment.kt
+39
-13
activity_main.xml
app/src/main/res/layout/activity_main.xml
+3
-1
fragment_add.xml
app/src/main/res/layout/fragment_add.xml
+14
-3
strings.xml
app/src/main/res/values/strings.xml
+3
-0
No files found.
app/src/main/java/com/example/elbuenopeso/ui/add/AddFragment.kt
View file @
a7b30035
...
...
@@ -4,20 +4,19 @@ import android.app.Activity
import
android.content.Intent
import
android.graphics.Bitmap
import
android.net.Uri
import
android.os.Build
import
android.os.Bundle
import
android.provider.MediaStore
import
android.util.Log
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.Button
import
android.widget.
Image
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
...
...
@@ -29,23 +28,42 @@ class AddFragment : Fragment() {
// onDestroyView.
private
val
binding
get
()
=
_binding
!!
var
camera_open_id
:
Button
?
=
null
var
gallery_open_id
:
Button
?
=
null
var
click_image_id
:
ImageView
?
=
null
lateinit
var
camera_open_id
:
ImageButton
lateinit
var
click_image_id
:
ImageView
private
val
galleryActivityResultLauncher
:
ActivityResultLauncher
<
Intent
>
=
registerForActivityResult
(
ActivityResultContracts
.
StartActivityForResult
(),
ActivityResultCallback
{
fun
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
?
data
:
Intent
)
{
if
(
resultCode
==
Activity
.
RESULT_OK
)
{
val
image
=
data
?
.
data
as
Uri
click_image_id
!!
.
setImageURI
(
image
)
val
image
=
data
.
data
as
Uri
click_image_id
.
setImageURI
(
image
)
}
}}
)
private
var
cameraActivityResultLauncher
:
ActivityResultLauncher
<
Intent
>
=
registerForActivityResult
(
ActivityResultContracts
.
StartActivityForResult
(),
ActivityResultCallback
{
fun
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
)
{
Log
.
d
(
"tag"
,
"$resultCode"
)
if
(
resultCode
==
Activity
.
RESULT_OK
)
{
val
image
=
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
TIRAMISU
)
{
data
.
extras
?.
getParcelable
(
"data"
,
Bitmap
::
class
.
java
)
}
else
{
throw
Exception
(
"Oups, en fait c'est pas Android 14..."
)
}
camera_open_id
.
setImageBitmap
(
image
)
binding
.
title
.
setText
(
"aaa"
)
}
}}
)
override
fun
onCreateView
(
...
...
@@ -53,17 +71,25 @@ class AddFragment : Fragment() {
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?
):
View
{
val
notificationsViewModel
=
ViewModelProvider
(
this
).
get
(
AddViewModel
::
class
.
java
)
//
val notificationsViewModel =
// ViewModelProvider(this)[AddViewModel::class.java]
_binding
=
FragmentAddBinding
.
inflate
(
inflater
,
container
,
false
)
val
root
:
View
=
binding
.
root
click_image_id
=
binding
.
image
camera_open_id
=
binding
.
cameraButton
binding
.
image
.
setOnClickListener
{
val
gallery
=
Intent
(
Intent
.
ACTION_PICK
,
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
)
galleryActivityResultLauncher
.
launch
(
gallery
)
}
binding
.
cameraButton
.
setOnClickListener
{
val
camera
=
Intent
(
MediaStore
.
ACTION_IMAGE_CAPTURE
)
galleryActivityResultLauncher
.
launch
(
camera
)
}
// val textView: TextView = binding.textNotifications
// notificationsViewModel.text.observe(viewLifecycleOwner) {
// textView.text = it
...
...
app/src/main/res/layout/activity_main.xml
View file @
a7b30035
<?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:id=
"@+id/container"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
...
...
@@ -28,6 +29,7 @@
app:layout_constraintLeft_toLeftOf=
"parent"
app:layout_constraintRight_toRightOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:navGraph=
"@navigation/mobile_navigation"
/>
app:navGraph=
"@navigation/mobile_navigation"
tools:ignore=
"FragmentTagUsage"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
app/src/main/res/layout/fragment_add.xml
View file @
a7b30035
...
...
@@ -15,7 +15,18 @@
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:srcCompat=
"@android:drawable/ic_menu_report_image"
android:contentDescription=
"@string/todo"
/>
android:contentDescription=
"@string/gallery"
/>
<ImageButton
android:id=
"@+id/cameraButton"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"16dp"
android:src=
"@android:drawable/ic_menu_camera"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/image"
android:contentDescription=
"@string/camera"
/>
<com.google.android.material.textfield.TextInputLayout
android:id=
"@+id/titleLayout"
...
...
@@ -23,9 +34,9 @@
android:layout_height=
"wrap_content"
android:layout_marginHorizontal=
"20dp"
android:layout_marginVertical=
"20dp"
android:hint=
"
T
itle"
android:hint=
"
@string/t
itle"
android:textColorHint=
"#6E6E6E"
app:layout_constraintTop_toBottomOf=
"@+id/
image
"
app:layout_constraintTop_toBottomOf=
"@+id/
cameraButton
"
tools:layout_editor_absoluteX=
"20dp"
>
<com.google.android.material.textfield.TextInputEditText
...
...
app/src/main/res/values/strings.xml
View file @
a7b30035
...
...
@@ -6,4 +6,7 @@
<string
name=
"todo"
>
TODO
</string>
<string
name=
"address"
>
Address
</string>
<string
name=
"send"
>
Send
</string>
<string
name=
"camera"
>
Camera
</string>
<string
name=
"title"
>
Title
</string>
<string
name=
"gallery"
>
Gallery
</string>
</resources>
\ 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