Skip to content

Commit

Permalink
Mise en place d'un indicateur lu / non lu
Browse files Browse the repository at this point in the history
Close #12
  • Loading branch information
AnaelMobilia committed Feb 11, 2015
1 parent a8c86d2 commit 04c7a49
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 14 deletions.
1 change: 1 addition & 0 deletions res/layout-large/liste_articles_item_article.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
-->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayoutArticle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
Expand Down
11 changes: 6 additions & 5 deletions res/layout-normal/liste_articles_item_article.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,25 @@
-->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayoutArticle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:paddingBottom="5dp"
android:paddingStart="5dp"
android:paddingLeft="5dp"
android:paddingEnd="?android:attr/scrollbarSize"
android:paddingLeft="5dp"
android:paddingRight="?android:attr/scrollbarSize"
android:paddingStart="5dp"
android:paddingTop="5dp" >

<ImageView
android:id="@+id/imageArticle"
android:layout_width="70dp"
android:layout_height="53dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:contentDescription="@string/contentDescriptionImageArticle"
android:src="@drawable/logo_nextinpact" />
Expand Down Expand Up @@ -87,8 +88,8 @@
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@id/titreArticle"
android:drawableStart="@drawable/small_comms"
android:drawableLeft="@drawable/small_comms"
android:drawableStart="@drawable/small_comms"
android:textAppearance="@style/textAppearanceMicro" />

<TextView
Expand Down
4 changes: 3 additions & 1 deletion res/layout/liste_articles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
<ListView
android:id="@+id/listeArticles"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:divider="#8A979D"
android:dividerHeight="1px" />
</LinearLayout>

</android.support.v4.widget.SwipeRefreshLayout>
8 changes: 8 additions & 0 deletions src/com/pcinpact/Constantes.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package com.pcinpact;

import android.graphics.Color;

/**
* Constantes de l'application (onfiguration des URL, ...)
*
Expand Down Expand Up @@ -114,4 +116,10 @@ public class Constantes {
public final static int TEXT_SIZE_MEDIUM = 18;
public final static int TEXT_SIZE_LARGE = 22;
public final static int TEXT_SIZE_XLARGE = 26;

/**
* COULEUR D'AFFICHAGE
*/
public final static int COULEUR_ARTICLE_NON_LU = Color.WHITE;
public final static int COULEUR_ARTICLE_LU = Color.parseColor("#D3D3D3");
}
11 changes: 10 additions & 1 deletion src/com/pcinpact/ListeArticlesActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,24 @@ public boolean onCreateOptionsMenu(Menu menu) {
}

/**
* Gestion du clic sur un article => l'ouvrir
* Gestion du clic sur un article => l'ouvrir + marquer comme lu
*/
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Récupère l'article en question
ArticleItem monArticle = (ArticleItem) monItemsAdapter.getItem(position);

// Lance l'ouverture de l'article
Intent monIntent = new Intent(getApplicationContext(), ArticleActivity.class);
monIntent.putExtra("ARTICLE_ID", monArticle.getId());
startActivity(monIntent);

// Marque l'article comme lu
monArticle.setLu(true);
// Mise à jour en DB
monDAO.marquerArticleLu(monArticle);
// Mise à jour graphique
monItemsAdapter.notifyDataSetChanged();
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/com/pcinpact/adapters/ItemsAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
Expand Down Expand Up @@ -140,6 +141,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
convertView = monLayoutInflater.inflate(R.layout.liste_articles_item_article, parent, false);

// Je prépare mon holder
monHolder.relativeLayout = (RelativeLayout) convertView.findViewById(R.id.relativeLayoutArticle);
monHolder.imageArticle = (ImageView) convertView.findViewById(R.id.imageArticle);
monHolder.labelAbonne = (TextView) convertView.findViewById(R.id.labelAbonne);
monHolder.titreArticle = (TextView) convertView.findViewById(R.id.titreArticle);
Expand Down Expand Up @@ -196,6 +198,15 @@ public View getView(int position, View convertView, ViewGroup parent) {
else if (i.getType() == Item.TYPE_ARTICLE) {
ArticleItem ai = (ArticleItem) i;

// L'article est-il déjà lu ?
if(ai.isLu()) {
// Couleur lu
monHolder.relativeLayout.setBackgroundColor(Constantes.COULEUR_ARTICLE_LU);
} else {
// Couleur non lu
monHolder.relativeLayout.setBackgroundColor(Constantes.COULEUR_ARTICLE_NON_LU);
}

// Gestion du badge abonné
if (ai.isAbonne()) {
monHolder.labelAbonne.setVisibility(View.VISIBLE);
Expand Down
2 changes: 2 additions & 0 deletions src/com/pcinpact/adapters/ItemsViewHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.pcinpact.adapters;

import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
Expand All @@ -42,6 +43,7 @@ public class ItemsViewHolder {
public TextView heureArticle;
public TextView sousTitreArticle;
public TextView commentairesArticle;
public RelativeLayout relativeLayout;

/**
* Commentaire
Expand Down
35 changes: 28 additions & 7 deletions src/com/pcinpact/database/DAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
public final class DAO extends SQLiteOpenHelper {
// Version de la DB (à mettre à jour à chaque changement du schéma)
private static final int DB_VERSION = 1;
private static final int DB_VERSION = 2;
// Nom de la BDD
private static final String DB_NAME = "nxidb";

Expand All @@ -54,6 +54,7 @@ public final class DAO extends SQLiteOpenHelper {
private static final String ARTICLE_CONTENU = "contenu";
private static final String ARTICLE_NB_COMMS = "nbcomms";
private static final String ARTICLE_IS_ABONNE = "isabonne";
private static final String ARTICLE_IS_LU = "islu";

private static final String DB_TABLE_COMMENTAIRES = "commentaires";
private static final String COMMENTAIRE_ID = "id";
Expand Down Expand Up @@ -103,7 +104,7 @@ public void onCreate(SQLiteDatabase db) {
String reqCreateArticles = "CREATE TABLE " + DB_TABLE_ARTICLES + " (" + ARTICLE_ID + " INTEGER PRIMARY KEY,"
+ ARTICLE_TITRE + " TEXT NOT NULL," + ARTICLE_SOUS_TITRE + " TEXT," + ARTICLE_TIMESTAMP + " INTEGER NOT NULL,"
+ ARTICLE_URL + " TEXT NOT NULL," + ARTICLE_ILLUSTRATION_URL + " TEXT," + ARTICLE_CONTENU + " TEXT,"
+ ARTICLE_NB_COMMS + " INTEGER," + ARTICLE_IS_ABONNE + " BOOLEAN);";
+ ARTICLE_NB_COMMS + " INTEGER," + ARTICLE_IS_ABONNE + " BOOLEAN," + ARTICLE_IS_LU + " BOOLEAN);";
db.execSQL(reqCreateArticles);

// Table des commentaires
Expand All @@ -124,7 +125,11 @@ public void onCreate(SQLiteDatabase db) {
*/
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Penser à passer par chaque étape de mise à jour successivement... !
switch(oldVersion) {
case 1:
String reqUpdateFrom1 = "ALTER TABLE " + DB_TABLE_ARTICLES + " ADD COLUMN " + ARTICLE_IS_LU + " BOOLEAN;";
db.execSQL(reqUpdateFrom1);
}

}

Expand All @@ -146,6 +151,7 @@ public void enregistrerArticle(ArticleItem unArticle) {
insertValues.put(ARTICLE_CONTENU, unArticle.getContenu());
insertValues.put(ARTICLE_NB_COMMS, unArticle.getNbCommentaires());
insertValues.put(ARTICLE_IS_ABONNE, unArticle.isAbonne());
insertValues.put(ARTICLE_IS_LU, unArticle.isLu());

maDB.insert(DB_TABLE_ARTICLES, null, insertValues);
}
Expand Down Expand Up @@ -184,6 +190,18 @@ public void updateNbCommentairesArticle(ArticleItem unArticle) {

maDB.update(DB_TABLE_ARTICLES, updateValues, ARTICLE_ID + "=?", new String[] { String.valueOf(unArticle.getId()) });
}

/**
* Taggue un article comme étant lu
* @param unArticle
*/
public void marquerArticleLu(ArticleItem unArticle) {
// Les datas à MàJ
ContentValues updateValues = new ContentValues();
updateValues.put(ARTICLE_IS_LU, unArticle.isLu());

maDB.update(DB_TABLE_ARTICLES, updateValues, ARTICLE_ID + "=?", new String[] { String.valueOf(unArticle.getId()) });
}

/**
* Supprimer un article de la DB
Expand All @@ -203,7 +221,7 @@ public void supprimerArticle(ArticleItem unArticle) {
public ArticleItem chargerArticle(int idArticle) {
// Les colonnes à récupérer
String[] mesColonnes = new String[] { ARTICLE_ID, ARTICLE_TITRE, ARTICLE_SOUS_TITRE, ARTICLE_TIMESTAMP, ARTICLE_URL,
ARTICLE_ILLUSTRATION_URL, ARTICLE_CONTENU, ARTICLE_NB_COMMS, ARTICLE_IS_ABONNE };
ARTICLE_ILLUSTRATION_URL, ARTICLE_CONTENU, ARTICLE_NB_COMMS, ARTICLE_IS_ABONNE, ARTICLE_IS_LU };

String[] idString = { String.valueOf(idArticle) };

Expand All @@ -223,6 +241,7 @@ public ArticleItem chargerArticle(int idArticle) {
monArticle.setContenu(monCursor.getString(6));
monArticle.setNbCommentaires(monCursor.getInt(7));
monArticle.setAbonne((monCursor.getInt(8) > 0));
monArticle.setLu((monCursor.getInt(9) > 0));
}
// Fermeture du curseur
monCursor.close();
Expand All @@ -239,7 +258,7 @@ public ArticleItem chargerArticle(int idArticle) {
public ArrayList<ArticleItem> chargerArticlesTriParDate(int nbVoulu) {
// Les colonnes à récupérer
String[] mesColonnes = new String[] { ARTICLE_ID, ARTICLE_TITRE, ARTICLE_SOUS_TITRE, ARTICLE_TIMESTAMP, ARTICLE_URL,
ARTICLE_ILLUSTRATION_URL, ARTICLE_CONTENU, ARTICLE_NB_COMMS, ARTICLE_IS_ABONNE };
ARTICLE_ILLUSTRATION_URL, ARTICLE_CONTENU, ARTICLE_NB_COMMS, ARTICLE_IS_ABONNE, ARTICLE_IS_LU };

// Requête sur la DB
Cursor monCursor = maDB.query(DB_TABLE_ARTICLES, mesColonnes, null, null, null, null, "4 DESC", String.valueOf(nbVoulu));
Expand All @@ -259,6 +278,7 @@ public ArrayList<ArticleItem> chargerArticlesTriParDate(int nbVoulu) {
monArticle.setContenu(monCursor.getString(6));
monArticle.setNbCommentaires(monCursor.getInt(7));
monArticle.setAbonne((monCursor.getInt(8) > 0));
monArticle.setLu((monCursor.getInt(9) > 0));

// Et l'enregistre
mesArticles.add(monArticle);
Expand Down Expand Up @@ -301,7 +321,7 @@ public ArrayList<ArticleItem> chargerArticlesASupprimer(int nbMaxArticles) {
*/
// Les colonnes à récupérer
String[] mesColonnes = new String[] { ARTICLE_ID, ARTICLE_TITRE, ARTICLE_SOUS_TITRE, ARTICLE_TIMESTAMP, ARTICLE_URL,
ARTICLE_ILLUSTRATION_URL, ARTICLE_CONTENU, ARTICLE_NB_COMMS, ARTICLE_IS_ABONNE };
ARTICLE_ILLUSTRATION_URL, ARTICLE_CONTENU, ARTICLE_NB_COMMS, ARTICLE_IS_ABONNE, ARTICLE_IS_LU };

// Préparation de la requête
String pointInterrogation = "";
Expand All @@ -328,7 +348,8 @@ public ArrayList<ArticleItem> chargerArticlesASupprimer(int nbMaxArticles) {
monArticle.setUrlIllustration(monCursor.getString(5));
monArticle.setContenu(monCursor.getString(6));
monArticle.setNbCommentaires(monCursor.getInt(7));
monArticle.setAbonne(Boolean.valueOf(monCursor.getString(8)));
monArticle.setAbonne((monCursor.getInt(8) > 0));
monArticle.setLu((monCursor.getInt(9) > 0));

// Et l'enregistre
mesArticles.add(monArticle);
Expand Down
11 changes: 11 additions & 0 deletions src/com/pcinpact/items/ArticleItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

/**
* Objet Article
*
* @author Anael
*
*/
Expand All @@ -41,6 +42,7 @@ public class ArticleItem implements Item {
private String urlIllustration = "";
private String contenu = "";
private long timeStampPublication;
private boolean isLu;

@Override
public int getType() {
Expand Down Expand Up @@ -79,6 +81,7 @@ public String getDatePublication() {

/**
* image.ext
*
* @return
*/
public String getImageName() {
Expand Down Expand Up @@ -158,4 +161,12 @@ public void setTimeStampPublication(long timeStampPublication) {
this.timeStampPublication = timeStampPublication;
}

public boolean isLu() {
return isLu;
}

public void setLu(boolean isLu) {
this.isLu = isLu;
}

}

0 comments on commit 04c7a49

Please sign in to comment.