From cbc88f57e1f2748e5cb66b2f7db67ecb321527cc Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 11 Jun 2015 01:05:31 +0300 Subject: remove some db field remnants --- .../fox/ttrss/offline/OfflineDownloadService.java | 53 +++++++++------------- .../fox/ttrss/offline/OfflineUploadService.java | 33 ++++---------- 2 files changed, 31 insertions(+), 55 deletions(-) (limited to 'org.fox.ttrss/src/main/java') diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineDownloadService.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineDownloadService.java index 6d485e65..e2bb20e1 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineDownloadService.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineDownloadService.java @@ -52,8 +52,6 @@ public class OfflineDownloadService extends Service { private static final int OFFLINE_SYNC_SEQ = 50; private static final int OFFLINE_SYNC_MAX = OFFLINE_SYNC_SEQ * 10; - private SQLiteDatabase m_writableDb; - private SQLiteDatabase m_readableDb; private int m_articleOffset = 0; private String m_sessionId; private NotificationManager m_nmgr; @@ -66,8 +64,9 @@ public class OfflineDownloadService extends Service { private boolean m_canProceed = true; private final IBinder m_binder = new LocalBinder(); - - public class LocalBinder extends Binder { + private DatabaseHelper m_databaseHelper; + + public class LocalBinder extends Binder { OfflineDownloadService getService() { return OfflineDownloadService.this; } @@ -128,9 +127,6 @@ public class OfflineDownloadService extends Service { } private void downloadFailed() { - m_readableDb.close(); - m_writableDb.close(); - m_nmgr.cancel(NOTIFY_DOWNLOADING); // TODO send notification to activity? @@ -172,25 +168,20 @@ public class OfflineDownloadService extends Service { } else { updateNotification(getString(R.string.notify_downloading_images, 0), 0, 0, true); } - - m_readableDb.close(); - m_writableDb.close(); - + stopSelf(); } private void initDatabase() { - DatabaseHelper dh = DatabaseHelper.getInstance(this); - m_writableDb = dh.getWritableDatabase(); - m_readableDb = dh.getReadableDatabase(); + m_databaseHelper = DatabaseHelper.getInstance(this); } /* private synchronized SQLiteDatabase getReadableDb() { return m_readableDb; } */ - private synchronized SQLiteDatabase getWritableDb() { - return m_writableDb; + private synchronized SQLiteDatabase getDatabase() { + return m_databaseHelper.getWritableDatabase(); } @SuppressWarnings("unchecked") @@ -221,7 +212,7 @@ public class OfflineDownloadService extends Service { updateNotification(R.string.notify_downloading_feeds, 0, 0, true); - getWritableDb().execSQL("DELETE FROM feeds;"); + getDatabase().execSQL("DELETE FROM feeds;"); ApiRequest req = new ApiRequest(getApplicationContext()) { @Override @@ -234,9 +225,9 @@ public class OfflineDownloadService extends Service { Type listType = new TypeToken>() {}.getType(); List feeds = new Gson().fromJson(content, listType); - SQLiteStatement stmtInsert = getWritableDb().compileStatement("INSERT INTO feeds " + - "("+BaseColumns._ID+", title, feed_url, has_icon, cat_id) " + - "VALUES (?, ?, ?, ?, ?);"); + SQLiteStatement stmtInsert = getDatabase().compileStatement("INSERT INTO feeds " + + "(" + BaseColumns._ID + ", title, feed_url, has_icon, cat_id) " + + "VALUES (?, ?, ?, ?, ?);"); for (Feed feed : feeds) { stmtInsert.bindLong(1, feed.id); @@ -254,7 +245,7 @@ public class OfflineDownloadService extends Service { m_articleOffset = 0; - getWritableDb().execSQL("DELETE FROM articles;"); + getDatabase().execSQL("DELETE FROM articles;"); } catch (Exception e) { e.printStackTrace(); updateNotification(R.string.offline_switch_error, 0, 0, false); @@ -298,7 +289,7 @@ public class OfflineDownloadService extends Service { updateNotification(R.string.notify_downloading_categories, 0, 0, true); - getWritableDb().execSQL("DELETE FROM categories;"); + getDatabase().execSQL("DELETE FROM categories;"); ApiRequest req = new ApiRequest(getApplicationContext()) { protected JsonElement doInBackground(HashMap... params) { @@ -309,9 +300,9 @@ public class OfflineDownloadService extends Service { Type listType = new TypeToken>() {}.getType(); List cats = new Gson().fromJson(content, listType); - SQLiteStatement stmtInsert = getWritableDb().compileStatement("INSERT INTO categories " + - "("+BaseColumns._ID+", title) " + - "VALUES (?, ?);"); + SQLiteStatement stmtInsert = getDatabase().compileStatement("INSERT INTO categories " + + "(" + BaseColumns._ID + ", title) " + + "VALUES (?, ?);"); for (FeedCategory cat : cats) { stmtInsert.bindLong(1, cat.id); @@ -370,9 +361,7 @@ public class OfflineDownloadService extends Service { m_canProceed = false; Log.d(TAG, "onDestroy"); - - //m_readableDb.close(); - //m_writableDb.close(); + } public class OfflineArticlesRequest extends ApiRequest { @@ -392,9 +381,9 @@ public class OfflineDownloadService extends Service { Type listType = new TypeToken>() {}.getType(); m_articles = new Gson().fromJson(content, listType); - SQLiteStatement stmtInsert = getWritableDb().compileStatement("INSERT INTO articles " + - "("+BaseColumns._ID+", unread, marked, published, score, updated, is_updated, title, link, feed_id, tags, content, author) " + - "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); + SQLiteStatement stmtInsert = getDatabase().compileStatement("INSERT INTO articles " + + "(" + BaseColumns._ID + ", unread, marked, published, score, updated, is_updated, title, link, feed_id, tags, content, author) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); for (Article article : m_articles) { @@ -494,7 +483,7 @@ public class OfflineDownloadService extends Service { @Override public void onStart(Intent intent, int startId) { try { - if (getWritableDb().isDbLockedByCurrentThread() || getWritableDb().isDbLockedByOtherThreads()) { + if (getDatabase().isDbLockedByCurrentThread() || getDatabase().isDbLockedByOtherThreads()) { return; } diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineUploadService.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineUploadService.java index 8f9f742d..04effd7f 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineUploadService.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineUploadService.java @@ -29,13 +29,12 @@ public class OfflineUploadService extends IntentService { public static final int NOTIFY_UPLOADING = 2; public static final String INTENT_ACTION_SUCCESS = "org.fox.ttrss.intent.action.UploadComplete"; - private SQLiteDatabase m_writableDb; - private SQLiteDatabase m_readableDb; private String m_sessionId; private NotificationManager m_nmgr; private boolean m_uploadInProgress = false; private boolean m_batchMode = false; - + private DatabaseHelper m_databaseHelper; + public OfflineUploadService() { super("OfflineUploadService"); } @@ -89,17 +88,11 @@ public class OfflineUploadService extends IntentService { } private void initDatabase() { - DatabaseHelper dh = DatabaseHelper.getInstance(this); - m_writableDb = dh.getWritableDatabase(); - m_readableDb = dh.getReadableDatabase(); + m_databaseHelper = DatabaseHelper.getInstance(this); } - - private synchronized SQLiteDatabase getReadableDb() { - return m_readableDb; - } - - private synchronized SQLiteDatabase getWritableDb() { - return m_writableDb; + + private synchronized SQLiteDatabase getDatabase() { + return m_databaseHelper.getWritableDatabase(); } private void uploadRead() { @@ -157,7 +150,7 @@ public class OfflineUploadService extends IntentService { break; } - Cursor c = getReadableDb().query("articles", null, + Cursor c = getDatabase().query("articles", null, "modified = 1 AND " + criteriaStr, null, null, null, null); String tmp = ""; @@ -209,16 +202,13 @@ public class OfflineUploadService extends IntentService { } private void uploadFailed() { - m_readableDb.close(); - m_writableDb.close(); - // TODO send notification to activity? m_uploadInProgress = false; } private void uploadSuccess() { - getWritableDb().execSQL("UPDATE articles SET modified = 0"); + getDatabase().execSQL("UPDATE articles SET modified = 0"); if (m_batchMode) { @@ -233,10 +223,7 @@ public class OfflineUploadService extends IntentService { intent.addCategory(Intent.CATEGORY_DEFAULT); sendBroadcast(intent); } - - m_readableDb.close(); - m_writableDb.close(); - + m_uploadInProgress = false; m_nmgr.cancel(NOTIFY_UPLOADING); @@ -281,7 +268,7 @@ public class OfflineUploadService extends IntentService { @Override protected void onHandleIntent(Intent intent) { try { - if (getWritableDb().isDbLockedByCurrentThread() || getWritableDb().isDbLockedByOtherThreads()) { + if (getDatabase().isDbLockedByCurrentThread() || getDatabase().isDbLockedByOtherThreads()) { return; } -- cgit v1.2.3