Android Open Source - karin Database






From Project

Back to project page karin.

License

The source code is released under:

MIT License

If you think the Android project karin listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package cc.wanko.karin.app.database;
/*w  w w  . j  a  va2s.c  om*/
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by eagletmt on 14/05/05.
 */
public class Database {

    private static final String TOP_IDS_TABLE = "top_ids";
    private static final String KEY_COLUMN = "key";
    private static final String TOP_ID_COLUMN = "top_id";

    private static class Helper extends SQLiteOpenHelper {
        private static final String DB_NAME = "karin.db";
        private static final int DB_VERSION = 1;

        public Helper(Context context) {
            super(context, DB_NAME, null, DB_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            db.execSQL("CREATE TABLE " + TOP_IDS_TABLE
                    + " (" + KEY_COLUMN + " varchar(128) PRIMARY KEY,"
                    + TOP_ID_COLUMN + " integer NOT NULL)");
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            db.execSQL("DROP TABLE " + TOP_IDS_TABLE);
            onCreate(db);
        }
    }

    private final SQLiteDatabase db;

    public Database(Context context) {
        db = new Helper(context).getWritableDatabase();
    }

    public void storeTopId(String key, long topId) {
        ContentValues values = new ContentValues();
        values.put(KEY_COLUMN, key);
        values.put(TOP_ID_COLUMN, topId);
        db.insertWithOnConflict(TOP_IDS_TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE);
    }

    public long getTopId(String key) {
        Cursor cursor = db.rawQuery(
                "SELECT " + TOP_ID_COLUMN + " FROM " + TOP_IDS_TABLE
                        + " WHERE " + KEY_COLUMN + " = ? LIMIT 1", new String[]{key}
        );
        long topId = -1;
        if (cursor.moveToNext()) {
            topId = cursor.getLong(0);
        }
        cursor.close();
        return topId;
    }
}




Java Source Code List

cc.wanko.karin.app.activities.MainActivity.java
cc.wanko.karin.app.activities.OAuthActivity.java
cc.wanko.karin.app.activities.UserListActivity.java
cc.wanko.karin.app.activities.UserStatusesActivity.java
cc.wanko.karin.app.adapters.MainPagerAdapter.java
cc.wanko.karin.app.adapters.StatusListAdapter.java
cc.wanko.karin.app.adapters.UserListListAdapter.java
cc.wanko.karin.app.client.HomeTimelineSource.java
cc.wanko.karin.app.client.StatusSource.java
cc.wanko.karin.app.client.TwitterProvider.java
cc.wanko.karin.app.client.UserListSource.java
cc.wanko.karin.app.client.UserStatusSource.java
cc.wanko.karin.app.database.Database.java
cc.wanko.karin.app.fragments.StatusListFragment.java
cc.wanko.karin.app.fragments.UserListListFragment.java
cc.wanko.karin.app.textbuilder.MediaSegment.java
cc.wanko.karin.app.textbuilder.MentionSegment.java
cc.wanko.karin.app.textbuilder.Segment.java
cc.wanko.karin.app.textbuilder.StatusTextBuilder.java
cc.wanko.karin.app.textbuilder.UrlSegment.java
cc.wanko.karin.app.utils.LruImageCache.java
cc.wanko.karin.app.utils.RoboViewHolder.java