diff --git a/org.fox.ttrss/src/main/AndroidManifest.xml b/org.fox.ttrss/src/main/AndroidManifest.xml index 960c3a10..2f5131c8 100755 --- a/org.fox.ttrss/src/main/AndroidManifest.xml +++ b/org.fox.ttrss/src/main/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="350" + android:versionName="1.123" > >() {}.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; }