1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
| public class ProduitActivity extends Activity {
private static final int CODE_DE_MON_ACTIVITE = 3;
static Integer actualiser; // Définit si on actualise on si on affiche juste les infos
static Integer id_recherche_courant;
private String terme_recherche_courant;
//private Integer id_produit_courant;
private TextView adapterview_terme_recherche = null;
private ImageView adapterview_retourAcceuil = null;
private ImageView adapterview_gestionRecherche = null;
private ImageView adapterview_actualiser = null;
static gestion_affichageProduit_CustomAdapter adapterview_liste_produitView = null;
static gestion_affichageProduit_CustomAdapter adapterview_grille_produitView = null;
public static final int ID_NOTIFICATION = 1985;// l'id unique correspondant à notre notification (bon moi j'ai choisi ma date de naissance :P)
FrameworkBase framework = new FrameworkBase();
private RechercheBdd rechercheBdd = new RechercheBdd(ProduitActivity.this);
Context context_local;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_affichage_produits);
adapterview_terme_recherche = (TextView) findViewById(R.id.terme_recherche); /* c'est la vue qui représente le terme de la recherche */
//GESTION : affichage liste des produits
gestion_affichageProduits();
// EVENEMENTS Lorsqu'on clique sur le bouton de retour à l'accueil
navigation_accueil();
// EVENEMENTS Lorsqu'on clique sur le bouton de gestion de la recherche en cours
navigation_gestionRecherche();
// EVENEMENTS Lorsqu'on clique sur le bouton d'actualisation
navigation_actualiser();
}
/* EVENEMENTS Lorsqu'on clique sur le bouton de retour é l'accueil */
private void navigation_accueil(){
/* EVENEMENTS Lorsqu'on clique sur le bouton pour retourner sur l'accueil */
adapterview_retourAcceuil = (ImageView) findViewById(R.id.bouton_retour_mainActivity); /* C'est le bouton d'action */
adapterview_retourAcceuil.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//On créé l'Intent qui va nous permettre d'afficher l'autre Activity
Intent intent = new Intent(ProduitActivity.this, MainActivity.class);
startActivityForResult(intent, CODE_DE_MON_ACTIVITE);//On démarre l'autre Activity
}
});
}
/* EVENEMENTS Lorsqu'on clique sur le bouton de gestion de la recherche en cours */
private void navigation_gestionRecherche(){
/* EVENEMENTS Lorsqu'on clique sur le bouton pour retourner sur l'accueil */
adapterview_gestionRecherche = (ImageView) findViewById(R.id.bouton_gestion_rechercheActivity); /* C'est le bouton d'action */
adapterview_gestionRecherche.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//On re-bascule sur la vue principal en transmettant l'id de la recherche nouvellement enregistré/modifié
Bundle objet_bunble = new Bundle(); // On créé le bundle pour envoyer les paramétres
//objet_bunble.putInt("id", 1);
objet_bunble.putInt("id", id_recherche_courant);
objet_bunble.putString("terme", terme_recherche_courant);
Intent intent = new Intent(ProduitActivity.this, RechercheActivity.class); //On créé l'Intent qui va nous permettre d'afficher l'autre Activity
intent.putExtras(objet_bunble); // On pousse le bundle dans l'intent pour envoyé les paramétres é l'autre vue
startActivityForResult(intent, CODE_DE_MON_ACTIVITE);//On démarre l'autre Activity
}
});
}
/* EVENEMENTS Lorsqu'on clique sur le bouton d'actualisation */
private void navigation_actualiser(){
/* EVENEMENTS Lorsqu'on clique sur le bouton pour retourner sur l'accueil */
adapterview_actualiser = (ImageView) findViewById(R.id.bouton_actualiser); /* C'est le bouton d'action */
adapterview_actualiser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//On re-bascule sur la vue principal en transmettant l'id de la recherche nouvellement enregistré/modifié
Bundle objet_bunble = new Bundle(); // On créé le bundle pour envoyer les paramétres
//objet_bunble.putInt("id", 1);
objet_bunble.putInt("id", id_recherche_courant);
objet_bunble.putString("terme", terme_recherche_courant);
objet_bunble.putInt("actualiser", '1');
Intent intent = new Intent(ProduitActivity.this, ProduitActivity.class); //On créé l'Intent qui va nous permettre d'afficher l'autre Activity
intent.putExtras(objet_bunble); // On pousse le bundle dans l'intent pour envoyé les paramétres é l'autre vue
startActivityForResult(intent, CODE_DE_MON_ACTIVITE);//On démarre l'autre Activity
}
});
}
/* Affichage des recherches enregistré */
private void gestion_affichageProduits() { /* Adaptater Gestion de la liste des produit */
// Déclaration
ArrayList<ProduitObjet> listeObjet_produit = new ArrayList<ProduitObjet>();
Bundle objet_bunble = this.getIntent().getExtras(); //On récupére l'objet Bundle envoyé par l'Activity de recherche
if (objet_bunble != null) { // Si on est sur une recherche précise
id_recherche_courant = this.getIntent().getIntExtra("id", 0);
terme_recherche_courant = this.getIntent().getStringExtra("terme");
actualiser = this.getIntent().getIntExtra("actualiser", 0);
// On affecte la valeur du terme de la recherche dans la case adapté
adapterview_terme_recherche.setText(URLDecoder.decode(terme_recherche_courant));
// on parse et on affiche
context_local = this;
ClassActualiseProduitAsyn_local tache_async = new ClassActualiseProduitAsyn_local();
//ClassActualiseProduitAsyn_local_old tache_async = new ClassActualiseProduitAsyn_local_old(context_local);
//ClassActualiseProduitAsyn tache_async = new ClassActualiseProduitAsyn(context);
tache_async.execute();
}
else{ // On re-dirige sur l'activité principal en indiquant l'erreur
Toast.makeText(getApplicationContext(), "Aucune recherche n'a était sélectionné", Toast.LENGTH_LONG).show();
//On créé l'Intent qui va nous permettre d'afficher l'autre Activity
startActivityForResult(intent, CODE_DE_MON_ACTIVITE);//On démarre l'autre Activity
}
}
class gestion_affichageProduit_CustomAdapter extends ArrayAdapter<ProduitObjet> { // AdaptaterView personnalisé pour la liste des produits
private ArrayList<ProduitObjet> listeObjet_produit;
public gestion_affichageProduit_CustomAdapter(Context context, int textViewResourceId, ArrayList<ProduitObjet> listeObjet_produit) {
super(context, textViewResourceId, listeObjet_produit);
this.listeObjet_produit = new ArrayList<ProduitObjet>();
this.listeObjet_produit.addAll(listeObjet_produit);
}
private class ViewHolder {
TextView nom_recherche;
RelativeLayout bloc_produit;
RelativeLayout bloc_produit_text;
TextView titre_produit;
TextView prix_haut_produit;
TextView prix_bas_produit;
ImageView image_produit;
ImageView logo_support;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
try {
ViewHolder holder = null;
if (convertView == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.element_produit_bloc, null);
// Récupération éléments
holder = new ViewHolder();
holder.bloc_produit = (RelativeLayout) convertView.findViewById(R.id.bloc_produit);
holder.bloc_produit_text = (RelativeLayout) convertView.findViewById(R.id.bloc_produit_text);
holder.titre_produit = (TextView) convertView.findViewById(R.id.titre_produit);
holder.prix_haut_produit = (TextView) convertView.findViewById(R.id.prix_haut_produit);
holder.prix_bas_produit = (TextView) convertView.findViewById(R.id.prix_bas_produit);
holder.image_produit = (ImageView) convertView.findViewById(R.id.image_produit);
holder.logo_support = (ImageView) convertView.findViewById(R.id.logo_support);
convertView.setTag(holder);
// Au clic on re-dirige vers le lien du site
holder.bloc_produit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
RelativeLayout produit_clic = (RelativeLayout)v;
ProduitObjet produit_courant = (ProduitObjet) produit_clic.getTag();
//id_produit_courant = produit_courant.getId();
Uri uri = Uri.parse(produit_courant.getLien());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
}
else { holder = (ViewHolder) convertView.getTag(); }
// AFFICHAGE
ProduitObjet produit = listeObjet_produit.get(position);
holder.bloc_produit_text.getBackground().setAlpha(100); // Gestion opacité
if(produit.getTitre().length() > 45){ holder.titre_produit.setText(produit.getTitre().substring(0, 45) + "..."); }
else{ holder.titre_produit.setText(produit.getTitre()); }
if(produit.getPrix_haut().length()!=0){
holder.prix_haut_produit.setText(produit.getPrix_haut() + " EUR");
holder.prix_haut_produit.getPaint().setStrikeThruText(true);
}
holder.prix_bas_produit.setText(produit.getPrix_bas() + " EUR");
int id_logo_support_drawable = getApplicationContext().getResources().getIdentifier(produit.getSupport(),"drawable", getApplicationContext().getPackageName());
holder.logo_support.setImageResource(id_logo_support_drawable);
if(produit.getPhoto().trim().compareTo("") != 0){ // Si l'image n'est pas vide on l'affichage, sinon on laisse l'image par défaut
Drawable drawable = framework.ImageOperations(produit.getPhoto());// Récupération du Drawable avec l'URL associée.
holder.image_produit.setImageDrawable(drawable);
//holder.image_produit.setScaleType(ImageView.ScaleType.CENTER_CROP); // Zoom centre
//holder.image_produit.setLayoutParams(new GridView.LayoutParams(90, 90)); // Zoom centre
}
//holder.titre_produit.setTag(produit);
holder.bloc_produit.setTag(produit);
}
catch (Exception e) { Log.i("gestion_affichageProduit_CustomAdapter", e.toString()); }
return convertView;
}
}
// Tache asynchrone parser
public class ClassActualiseProduitAsyn_local extends AsyncTask<Integer, Integer, String>{
// Declaration liste de recherche
ArrayList<ProduitObjet> listeObjet_produit = new ArrayList<ProduitObjet>();
String texte_progressCourant;
String date_recherche;
TextView date_actualise = (TextView) findViewById(R.id.date_actualise);
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View convertView2 = vi.inflate(R.layout.element_progress_bar, null);
Dialog box_progress = new Dialog(ProduitActivity.this);
TextView mTexte_progressBar;
ProgressBar mProgressBar;
String prix_bas_recherche = "0.0"; // Prix le plus bas de la recherche
private RechercheBdd rechercheBdd = new RechercheBdd(ProduitActivity.this);
private ProduitBdd produitBdd = new ProduitBdd(ProduitActivity.this);
private SupportBdd supportBdd = new SupportBdd(ProduitActivity.this);
private RechercheObjet recherche_courante = new RechercheObjet();
// Ne pas oublier de déclarer l'action dans l'intent-filter du Manifest
private static final String ACTION_START_ALARM = "fr.miximum.widget.START_ALARM";
@Override
protected void onPreExecute() {
super.onPreExecute();
// Ouverture bdd
rechercheBdd.open();
produitBdd.open();
supportBdd.open();
// Initialisation de la box progress
box_progress.setContentView(convertView2);
//box_progress.setTitle("Progress");
mTexte_progressBar = (TextView) box_progress.findViewById(R.id.texte_progressBar);
mProgressBar = (ProgressBar) box_progress.findViewById(R.id.ProgressBar);
/* DEBUT On définit la couleur de la progress bar*/
final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };// On définit des bords arondis
ShapeDrawable pgDrawable = new ShapeDrawable (new RoundRectShape(roundedCorners, null, null));
pgDrawable.getPaint ().setColor (Color.GRAY);// On change la couleur en gris
ClipDrawable progress_draw = new ClipDrawable (pgDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);// On crée l'image de la progress bar
mProgressBar.setProgressDrawable (progress_draw); // On intégre l'image et Android s'occupe de dimensionner comme il faut
/* FIN On définit la couleur de la progress bar*/
mProgressBar.setMax(100);
//Toast.makeText(getApplicationContext(), "Début du traitement asynchrone", Toast.LENGTH_LONG).show();
}
@Override
protected void onProgressUpdate(Integer... values) { //
super.onProgressUpdate(values);
// S'il existe au moins un produit on affiche la liste
if(listeObjet_produit != null){
//ADAPTATERVIEW
adapterview_grille_produitView = new gestion_affichageProduit_CustomAdapter(ProduitActivity.this,
R.layout.element_produit_bloc, listeObjet_produit);
GridView gridView = (GridView) findViewById(R.id.grille_produitView);
gridView.setAdapter(adapterview_grille_produitView); // Assign adapter to GridView
}
// Mise é jour de la ProgressBar
date_actualise.setText("Derniére actualisation : "+date_recherche);
mTexte_progressBar.setText(texte_progressCourant);
mProgressBar.setProgress(values[0]);
box_progress.show();
}
@Override
protected String doInBackground(Integer... sInteger) {
try{
// Déclaration
Integer progress = 0;
//ON PASSE ICI QUE POUR LES NOUVELLES RECHERCHES OU LES DEMANDES D'ACTUALISATION
if(actualiser == '1'){
// On récupére la recherche courante
recherche_courante = rechercheBdd.getRechercheWithId(id_recherche_courant.intValue());
String[] liste_urlSupport = recherche_courante.getListe_url_supports().split(Pattern.quote("|SEP|"));
String[] liste_support = recherche_courante.getSupports().split(Pattern.quote("|"));
int indice_etape_chargement = 100 / (liste_urlSupport.length * 2);
// Affectation date
date_recherche = recherche_courante.getDate_recherche();
// BUGG Initialise la progressBar
//box_progress.setTitle("En cours de recherche...");
//publishProgress(0);
// On purge la table produit en fonction de la recherche courante
produitBdd.delete_by_recherche(recherche_courante.getId());
// On met à jour par produit en croix la barre de progression
box_progress.setTitle("Récupération offres");
texte_progressCourant = liste_support[0];
progress = 0;
publishProgress(progress);
// Pour chaque support
for(int i = 0; i < liste_urlSupport.length; i++){
// Récupération de l'objet support courant
SupportObjet support_url_courant = new SupportObjet();
support_url_courant = supportBdd.getSupportWithNom(liste_support[i]);
// On met à jour par produit en croix la barre de progression
texte_progressCourant = liste_support[i];
progress = progress + indice_etape_chargement;
publishProgress(progress);
// On appel la fonction pour enregistrer les nouveaux produit 'cron'
//recuperation_rechercheProduits(liste_urlSupport[i], support_url_courant, recherche_courante, ProduitActivity.this, produitBdd);
ClassParserHtml parser_html = new ClassParserHtml();
parser_html.recuperation_rechercheProduits(liste_urlSupport[i], support_url_courant, recherche_courante, ProduitActivity.this, produitBdd);
// ON RECHARGE LA VUE A CHAQUE PASSAGE On récupére la liste des produits associés é la recherche courante
listeObjet_produit = produitBdd.getAll_produit_by_recherche(id_recherche_courant);
// On met é jour par produit en croix la barre de progression
texte_progressCourant = liste_support[i];
//progress = ((i+1) * 100) / liste_urlSupport.length;
progress = progress + indice_etape_chargement;
publishProgress(progress);
}
}
else{
// Bug
box_progress.setTitle("Récupération produits en cours...");
publishProgress(0);
// On récupére la date de recherche
recherche_courante = rechercheBdd.getRechercheWithId(id_recherche_courant.intValue());
date_recherche = recherche_courante.getDate_recherche();
// On récupére la liste des produits associés é la recherche courante
listeObjet_produit = produitBdd.getAll_produit_by_recherche(id_recherche_courant);
//mTexte_progressBar.setText("Récupération produits en cours..."); // Fais bugger l'afichage produit
publishProgress(0);
}
}
catch (Exception e) { Log.i("classActualiseProduitAsync", "classActualiseProduitAsync toto : "+e.toString()); }
return null;
}
@Override
protected void onPostExecute(String result) {
// On ferme la connection
supportBdd.close();
produitBdd.close();
rechercheBdd.close();
// On supprime la box de progress barre
box_progress.cancel();
}
}
} |
Partager