Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uv-amse-android
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
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
Lucas NAURY
uv-amse-android
Commits
b08731d7
Commit
b08731d7
authored
Feb 21, 2024
by
Lucas NAURY
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Création d'une annonce dans la DB
parent
6d5bca27
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
6 deletions
+31
-6
AjoutAnnonceFragment.java
...le/tpleboncoin/ui/ajout_annonce/AjoutAnnonceFragment.java
+16
-4
HomeFragment.java
...in/java/com/example/tpleboncoin/ui/home/HomeFragment.java
+15
-2
No files found.
app/src/main/java/com/example/tpleboncoin/ui/ajout_annonce/AjoutAnnonceFragment.java
View file @
b08731d7
...
...
@@ -26,6 +26,7 @@ import androidx.navigation.Navigation;
import
com.example.tpleboncoin.R
;
import
com.example.tpleboncoin.databinding.FragmentAjoutAnnonceBinding
;
import
com.example.tpleboncoin.db.DBManager
;
import
com.example.tpleboncoin.models.Annonce
;
import
com.google.android.material.snackbar.Snackbar
;
...
...
@@ -35,6 +36,7 @@ public class AjoutAnnonceFragment extends Fragment {
private
ActivityResultLauncher
<
Intent
>
activityResultLauncher
;
public
View
onCreateView
(
@NonNull
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
AjoutAnnonceViewModel
ajout_annonceViewModel
=
...
...
@@ -49,6 +51,11 @@ public class AjoutAnnonceFragment extends Fragment {
final
EditText
prixAnnonce
=
binding
.
prixAnnonce
;
final
Button
boutonCreation
=
binding
.
boutonAjoutAnnonce
;
// Initialisation de la DB
DBManager
dbManager
=
DBManager
.
getDBManager
(
this
.
getContext
());
dbManager
.
open
();
boutonCreation
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
...
...
@@ -61,12 +68,17 @@ public class AjoutAnnonceFragment extends Fragment {
}
// On créé l'objet de la nouvelle annonce
Annonce
nouvelleAnnonce
=
new
Annonce
(
titreAnnonce
.
getText
().
toString
(),
adresseAnnonce
.
getText
().
toString
(),
0
,
Double
.
parseDouble
(
prixAnnonce
.
getText
().
toString
()));
Annonce
nouvelleAnnonce
=
new
Annonce
(
titreAnnonce
.
getText
().
toString
(),
adresseAnnonce
.
getText
().
toString
(),
""
,
Double
.
parseDouble
(
prixAnnonce
.
getText
().
toString
()));
// On navigue vers la page d'accueil en passant la nouvelle annonce comme paramètre
Bundle
bundle
=
new
Bundle
();
bundle
.
putParcelable
(
"nouvelleAnnonce"
,
nouvelleAnnonce
);
Navigation
.
findNavController
(
view
).
navigate
(
R
.
id
.
navigation_home
,
bundle
);
// Bundle bundle = new Bundle();
// bundle.putParcelable("nouvelleAnnonce", nouvelleAnnonce);
// Navigation.findNavController(view).navigate(R.id.navigation_home, bundle);
//On ajoute la nouvelle annonce à la DB
dbManager
.
insert
(
nouvelleAnnonce
);
//On navigue vers la page de liste des annonces
Navigation
.
findNavController
(
view
).
navigate
(
R
.
id
.
navigation_home
);
}
});
...
...
app/src/main/java/com/example/tpleboncoin/ui/home/HomeFragment.java
View file @
b08731d7
...
...
@@ -28,7 +28,6 @@ public class HomeFragment extends Fragment {
private
static
final
String
TAG
=
"RecyclerViewFragment"
;
private
static
final
String
KEY_LAYOUT_MANAGER
=
"layoutManager"
;
private
static
final
int
SPAN_COUNT
=
2
;
private
static
final
int
DATASET_COUNT
=
60
;
private
enum
LayoutManagerType
{
GRID_LAYOUT_MANAGER
,
...
...
@@ -167,7 +166,21 @@ public class HomeFragment extends Fragment {
dbManager
.
open
();
// On récupère toutes les annonces de la DB
mDataset
=
dbManager
.
getAll
(
);
mDataset
=
reverseArrayList
(
dbManager
.
getAll
()
);
}
public
ArrayList
<
Annonce
>
reverseArrayList
(
ArrayList
<
Annonce
>
alist
)
{
// Arraylist for storing reversed elements
ArrayList
<
Annonce
>
revArrayList
=
new
ArrayList
<
Annonce
>();
for
(
int
i
=
alist
.
size
()
-
1
;
i
>=
0
;
i
--)
{
// Append the elements in reverse order
revArrayList
.
add
(
alist
.
get
(
i
));
}
// Return the reversed arraylist
return
revArrayList
;
}
}
\ 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