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
8395ef26
Commit
8395ef26
authored
Feb 22, 2024
by
m-spi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Je pense on tient le bon bout
parent
2d98e570
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
92 additions
and
17 deletions
+92
-17
DBHelper.kt
...rc/main/java/com/example/elbuenopeso/database/DBHelper.kt
+0
-1
DBManager.kt
...c/main/java/com/example/elbuenopeso/database/DBManager.kt
+0
-1
AddFragment.kt
...c/main/java/com/example/elbuenopeso/ui/add/AddFragment.kt
+66
-11
MarketFragment.kt
.../java/com/example/elbuenopeso/ui/market/MarketFragment.kt
+2
-1
fragment_add.xml
app/src/main/res/layout/fragment_add.xml
+23
-3
strings.xml
app/src/main/res/values/strings.xml
+1
-0
No files found.
app/src/main/java/com/example/elbuenopeso/database/DBHelper.kt
View file @
8395ef26
...
@@ -21,7 +21,6 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
...
@@ -21,7 +21,6 @@ class DBHelper(context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_V
}
}
override
fun
onCreate
(
db
:
SQLiteDatabase
)
{
override
fun
onCreate
(
db
:
SQLiteDatabase
)
{
Log
.
i
(
null
,
"table sql create : $CREATE_TABLE"
)
db
.
execSQL
(
CREATE_TABLE
)
db
.
execSQL
(
CREATE_TABLE
)
}
}
...
...
app/src/main/java/com/example/elbuenopeso/database/DBManager.kt
View file @
8395ef26
...
@@ -69,7 +69,6 @@ private constructor(private val context: Context) {
...
@@ -69,7 +69,6 @@ private constructor(private val context: Context) {
fun
fetch
():
Cursor
?
{
fun
fetch
():
Cursor
?
{
val
columns
:
Array
<
String
>
=
val
columns
:
Array
<
String
>
=
arrayOf
(
DBHelper
.
_ID
,
DBHelper
.
TITLE
,
DBHelper
.
ADDRESS
,
DBHelper
.
IMAGE
,
DBHelper
.
PRIX
)
arrayOf
(
DBHelper
.
_ID
,
DBHelper
.
TITLE
,
DBHelper
.
ADDRESS
,
DBHelper
.
IMAGE
,
DBHelper
.
PRIX
)
columns
.
forEach
{
e
->
Log
.
i
(
null
,
e
)
}
val
cursor
=
this
.
database
!!
.
query
(
DBHelper
.
TABLE_NAME
,
columns
,
null
,
null
,
null
,
null
,
null
)
val
cursor
=
this
.
database
!!
.
query
(
DBHelper
.
TABLE_NAME
,
columns
,
null
,
null
,
null
,
null
,
null
)
cursor
?.
moveToFirst
()
cursor
?.
moveToFirst
()
return
cursor
return
cursor
...
...
app/src/main/java/com/example/elbuenopeso/ui/add/AddFragment.kt
View file @
8395ef26
package
com.example.elbuenopeso.ui.add
package
com.example.elbuenopeso.ui.add
import
android.app.Activity
import
android.app.Activity
import
android.content.Context
import
android.content.ContextWrapper
import
android.content.Intent
import
android.content.Intent
import
android.graphics.Bitmap
import
android.graphics.Bitmap
import
android.net.Uri
import
android.net.Uri
import
android.os.Bundle
import
android.os.Bundle
import
android.provider.MediaStore
import
android.provider.MediaStore
import
android.util.Log
import
android.view.LayoutInflater
import
android.view.LayoutInflater
import
android.view.View
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewGroup
import
android.widget.Button
import
android.widget.ImageButton
import
android.widget.ImageButton
import
android.widget.ImageView
import
android.widget.ImageView
import
androidx.activity.result.ActivityResultLauncher
import
androidx.activity.result.ActivityResultLauncher
import
androidx.activity.result.contract.ActivityResultContracts
import
androidx.activity.result.contract.ActivityResultContracts
import
androidx.fragment.app.Fragment
import
androidx.fragment.app.Fragment
import
com.example.elbuenopeso.R
import
com.example.elbuenopeso.database.DBManager
import
com.example.elbuenopeso.databinding.FragmentAddBinding
import
com.example.elbuenopeso.databinding.FragmentAddBinding
import
com.example.elbuenopeso.models.AdModel
import
java.io.File
import
java.io.FileOutputStream
import
java.io.IOException
@Suppress
(
"DEPRECATION"
)
@Suppress
(
"DEPRECATION"
)
...
@@ -28,12 +38,15 @@ class AddFragment : Fragment() {
...
@@ -28,12 +38,15 @@ class AddFragment : Fragment() {
private
lateinit
var
cameraButton
:
ImageButton
private
lateinit
var
cameraButton
:
ImageButton
private
lateinit
var
image
:
ImageView
private
lateinit
var
image
:
ImageView
private
lateinit
var
sendButton
:
Button
private
var
filePath
:
String
=
""
private
val
galleryActivityResultLauncher
:
ActivityResultLauncher
<
Intent
>
=
private
val
galleryActivityResultLauncher
:
ActivityResultLauncher
<
Intent
>
=
registerForActivityResult
(
ActivityResultContracts
.
StartActivityForResult
())
{
registerForActivityResult
(
ActivityResultContracts
.
StartActivityForResult
())
{
result
->
run
{
result
->
run
{
if
(
result
.
resultCode
==
Activity
.
RESULT_OK
)
{
if
(
result
.
resultCode
==
Activity
.
RESULT_OK
)
{
val
image
=
result
?.
data
?.
data
as
Uri
val
image
=
result
?.
data
?.
data
as
Uri
this
.
filePath
=
image
.
path
!!
this
.
image
.
setImageURI
(
image
)
this
.
image
.
setImageURI
(
image
)
}
}
}
}
...
@@ -41,11 +54,28 @@ class AddFragment : Fragment() {
...
@@ -41,11 +54,28 @@ class AddFragment : Fragment() {
private
val
cameraActivityResultLauncher
:
ActivityResultLauncher
<
Intent
>
=
private
val
cameraActivityResultLauncher
:
ActivityResultLauncher
<
Intent
>
=
registerForActivityResult
(
ActivityResultContracts
.
StartActivityForResult
())
{
registerForActivityResult
(
ActivityResultContracts
.
StartActivityForResult
())
{
result
->
run
{
result
->
if
(
result
.
resultCode
==
Activity
.
RESULT_OK
)
{
if
(
result
.
resultCode
==
Activity
.
RESULT_OK
)
{
val
data
=
result
.
data
val
image
=
result
.
data
?.
extras
?.
get
(
"data"
)
as
Bitmap
?
val
bitmap
=
data
!!
.
extras
!!
[
"data"
]
as
Bitmap
?
this
.
image
.
setImageBitmap
(
image
)
val
cw
=
ContextWrapper
(
requireContext
())
val
directory
=
cw
.
getDir
(
"imageDir"
,
Context
.
MODE_PRIVATE
)
val
tsLong
=
System
.
currentTimeMillis
()
/
1000
val
ts
=
tsLong
.
toString
()
val
file
=
File
(
directory
,
"$ts.jpg"
)
if
(!
file
.
exists
())
{
Log
.
d
(
"path"
,
file
.
toString
())
var
fos
:
FileOutputStream
?
=
null
try
{
fos
=
FileOutputStream
(
file
)
bitmap
!!
.
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
100
,
fos
)
fos
.
flush
()
fos
.
close
()
}
catch
(
e
:
IOException
)
{
e
.
printStackTrace
()
}
}
}
this
.
filePath
=
file
.
toString
()
this
.
image
.
setImageBitmap
(
bitmap
)
}
}
}
}
...
@@ -54,27 +84,52 @@ class AddFragment : Fragment() {
...
@@ -54,27 +84,52 @@ class AddFragment : Fragment() {
container
:
ViewGroup
?,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?
savedInstanceState
:
Bundle
?
):
View
{
):
View
{
// val notificationsViewModel =
// ViewModelProvider(this)[AddViewModel::class.java]
_binding
=
FragmentAddBinding
.
inflate
(
inflater
,
container
,
false
)
_binding
=
FragmentAddBinding
.
inflate
(
inflater
,
container
,
false
)
val
root
:
View
=
binding
.
root
val
root
:
View
=
binding
.
root
image
=
binding
.
image
image
=
binding
.
image
cameraButton
=
binding
.
cameraButton
cameraButton
=
binding
.
cameraButton
sendButton
=
binding
.
sendButton
// DB manager :
val
dbManager
=
DBManager
.
getDBManager
(
requireContext
())
dbManager
!!
.
open
()
binding
.
image
.
setOnClickListener
{
image
.
setOnClickListener
{
val
gallery
=
Intent
(
Intent
.
ACTION_PICK
,
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
)
val
gallery
=
Intent
(
Intent
.
ACTION_PICK
,
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
)
galleryActivityResultLauncher
.
launch
(
gallery
)
galleryActivityResultLauncher
.
launch
(
gallery
)
}
}
binding
.
cameraButton
.
setOnClickListener
{
cameraButton
.
setOnClickListener
{
val
camera
=
Intent
(
MediaStore
.
ACTION_IMAGE_CAPTURE
)
val
camera
=
Intent
(
MediaStore
.
ACTION_IMAGE_CAPTURE
)
cameraActivityResultLauncher
.
launch
(
camera
)
cameraActivityResultLauncher
.
launch
(
camera
)
}
}
binding
.
sendButton
.
setOnClickListener
{
sendButton
.
setOnClickListener
{
if
(
binding
.
title
.
text
.
toString
().
isEmpty
()
||
binding
.
price
.
text
.
toString
().
isEmpty
()){
return
@setOnClickListener
}
val
ad
=
AdModel
(
binding
.
title
.
text
.
toString
(),
binding
.
address
.
text
.
toString
(),
this
.
filePath
,
binding
.
price
.
text
.
toString
().
toDouble
()
)
dbManager
.
insert
(
ad
);
image
.
setImageResource
(
R
.
drawable
.
baseline_add_24
)
binding
.
title
.
setText
(
""
)
binding
.
address
.
setText
(
""
)
binding
.
price
.
setText
(
""
)
this
.
filePath
=
""
// Je sais pas trop ce que c'est mais dans le doute je laisse ça là...
// val intent: Intent = Intent(
// this@AddFragment,
// DbAdListViewActivity::class.java
// )
// startActivity(intent)
}
}
return
root
return
root
...
...
app/src/main/java/com/example/elbuenopeso/ui/market/MarketFragment.kt
View file @
8395ef26
...
@@ -68,7 +68,8 @@ class MarketFragment : Fragment() {
...
@@ -68,7 +68,8 @@ class MarketFragment : Fragment() {
}
}
val
dbManager
:
DBManager
?
=
DBManager
.
getDBManager
(
requireContext
())
val
dbManager
:
DBManager
?
=
DBManager
.
getDBManager
(
requireContext
())
dbManager
!!
.
init
()
//dbManager!!.init()
dbManager
!!
.
open
()
val
cursor
=
dbManager
.
fetch
()
val
cursor
=
dbManager
.
fetch
()
adapter
=
DbAdapter
(
requireContext
(),
cursor
!!
,
R
.
layout
.
item_listview_ad
)
adapter
=
DbAdapter
(
requireContext
(),
cursor
!!
,
R
.
layout
.
item_listview_ad
)
adapter
.
notifyDataSetChanged
()
adapter
.
notifyDataSetChanged
()
...
...
app/src/main/res/layout/fragment_add.xml
View file @
8395ef26
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:srcCompat=
"@
android:drawable/ic_menu_report_image
"
/>
app:srcCompat=
"@
drawable/baseline_add_24
"
/>
<ImageButton
<ImageButton
android:id=
"@+id/cameraButton"
android:id=
"@+id/cameraButton"
...
@@ -76,18 +76,38 @@
...
@@ -76,18 +76,38 @@
android:paddingHorizontal=
"36dp"
/>
android:paddingHorizontal=
"36dp"
/>
</com.google.android.material.textfield.TextInputLayout>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id=
"@+id/priceLayout"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_marginHorizontal=
"20dp"
android:layout_marginVertical=
"10dp"
android:hint=
"@string/price"
android:textColorHint=
"#6E6E6E"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/addressLayout"
tools:ignore=
"MissingConstraints"
>
<com.google.android.material.textfield.TextInputEditText
android:id=
"@+id/price"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:paddingHorizontal=
"36dp"
/>
</com.google.android.material.textfield.TextInputLayout>
<Button
<Button
android:id=
"@+id/sendButton"
android:id=
"@+id/sendButton"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"
32
dp"
android:layout_marginTop=
"
24
dp"
android:layout_marginBottom=
"8dp"
android:layout_marginBottom=
"8dp"
android:text=
"@string/send"
android:text=
"@string/send"
android:textSize=
"20sp"
android:textSize=
"20sp"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/
address
Layout"
app:layout_constraintTop_toBottomOf=
"@+id/
price
Layout"
tools:ignore=
"MissingConstraints"
/>
tools:ignore=
"MissingConstraints"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
...
...
app/src/main/res/values/strings.xml
View file @
8395ef26
...
@@ -9,4 +9,5 @@
...
@@ -9,4 +9,5 @@
<string
name=
"camera"
>
Camera
</string>
<string
name=
"camera"
>
Camera
</string>
<string
name=
"title"
>
Title
</string>
<string
name=
"title"
>
Title
</string>
<string
name=
"gallery"
>
Gallery
</string>
<string
name=
"gallery"
>
Gallery
</string>
<string
name=
"price"
>
Price
</string>
</resources>
</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