mirror of
https://github.com/moparisthebest/android-app
synced 2024-08-13 16:53:46 -04:00
61 lines
2.0 KiB
Java
61 lines
2.0 KiB
Java
|
package fr.gaulupeau.apps.Poche;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.content.SharedPreferences;
|
||
|
import android.database.sqlite.SQLiteDatabase;
|
||
|
import android.database.sqlite.SQLiteOpenHelper;
|
||
|
import static fr.gaulupeau.apps.Poche.Helpers.PREFS_NAME;
|
||
|
import static fr.gaulupeau.apps.Poche.Helpers.zeroUpdate;
|
||
|
|
||
|
|
||
|
public class ArticlesSQLiteOpenHelper extends SQLiteOpenHelper {
|
||
|
|
||
|
|
||
|
public static final int VERSION = 1;
|
||
|
public static final String DB_NAME = "article_db.sqlite";
|
||
|
public static String MY_ID = "my_id";
|
||
|
public static String ARTICLE_TABLE = "article";
|
||
|
public static String ARTICLE_ID = "article_id";
|
||
|
public static String ARTICLE_AUTHOR = "author";
|
||
|
public static String ARTICLE_CONTENT = "content";
|
||
|
public static String ARTICLE_TITLE = "title";
|
||
|
public static String ARTICLE_URL = "url";
|
||
|
Context c;
|
||
|
|
||
|
public ArticlesSQLiteOpenHelper(Context context) {
|
||
|
super(context, DB_NAME, null, VERSION);
|
||
|
c = context;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onCreate(SQLiteDatabase db) {
|
||
|
createTables(db);
|
||
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||
|
db.delete(ARTICLE_TABLE, null, null);
|
||
|
SharedPreferences preferences = c.getSharedPreferences(PREFS_NAME, 0);
|
||
|
SharedPreferences.Editor editor = preferences.edit();
|
||
|
editor.putString("previous_update", zeroUpdate);
|
||
|
editor.commit();
|
||
|
}
|
||
|
|
||
|
protected void createTables(SQLiteDatabase db) {
|
||
|
db.execSQL(
|
||
|
"create table " + ARTICLE_TABLE + " (" +
|
||
|
MY_ID + " integer primary key autoincrement not null, " +
|
||
|
ARTICLE_AUTHOR + " text, " +
|
||
|
ARTICLE_CONTENT + " text, " +
|
||
|
ARTICLE_TITLE + " text, " +
|
||
|
ARTICLE_URL + " text, " +
|
||
|
ARTICLE_ID + " integer, " +
|
||
|
");"
|
||
|
);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|