Update sync process
This commit is contained in:
parent
9264e91360
commit
140d2592bb
6 changed files with 42 additions and 32 deletions
|
@ -1,12 +1,3 @@
|
|||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:+'
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'android'
|
||||
|
||||
android {
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:debuggable="false"
|
||||
android:debuggable="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
|
|
|
@ -30,14 +30,11 @@ import android.util.Log;
|
|||
import android.util.SparseArray;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.Constants;
|
||||
import de.luhmer.owncloudnewsreader.ListView.UnreadFolderCount;
|
||||
import de.luhmer.owncloudnewsreader.data.ConcreteFeedItem;
|
||||
import de.luhmer.owncloudnewsreader.data.DatabaseFeedItem;
|
||||
import de.luhmer.owncloudnewsreader.data.RssFile;
|
||||
|
||||
import static de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_ITEMS;
|
||||
|
@ -877,11 +874,12 @@ public class DatabaseConnection {
|
|||
return database.update(SUBSCRIPTION_TABLE, contentValues, SUBSCRIPTION_ID + "= ?", new String[] { subscription_id });
|
||||
}
|
||||
|
||||
public void insertNewItems(List<RssFile> items) {
|
||||
public void insertNewItems(RssFile[] items) {
|
||||
database.beginTransaction();
|
||||
try {
|
||||
for(RssFile item : items) {
|
||||
insertNewItem(item, true);
|
||||
Boolean isFeedAlreadyInDatabase = doesRssItemAlreadyExsists(item.getItem_Id());
|
||||
insertNewItem(item, isFeedAlreadyInDatabase);
|
||||
}
|
||||
database.setTransactionSuccessful();
|
||||
} catch (SQLException e) {
|
||||
|
|
|
@ -23,25 +23,23 @@ package de.luhmer.owncloudnewsreader.reader.owncloud;
|
|||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.Override;
|
||||
import java.util.Date;
|
||||
|
||||
import de.luhmer.owncloudnewsreader.data.RssFile;
|
||||
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
|
||||
import de.luhmer.owncloudnewsreader.reader.InsertIntoDatabase;
|
||||
|
||||
public class InsertItemIntoDatabase implements IHandleJsonObject {
|
||||
|
||||
|
||||
DatabaseConnection dbConn;
|
||||
List<RssFile> buffer;
|
||||
RssFile[] buffer;
|
||||
static final short bufferSize = 200;
|
||||
int count = 0;
|
||||
int index = 0;
|
||||
|
||||
public InsertItemIntoDatabase(DatabaseConnection dbConn) {
|
||||
this.dbConn = dbConn;
|
||||
buffer = ArrayList<RssFile>(bufferSize);
|
||||
buffer = new RssFile[bufferSize];
|
||||
}
|
||||
|
||||
|
||||
private static RssFile parseItem(JSONObject e)
|
||||
{
|
||||
Date date = new Date(e.optLong("pubDate") * 1000);
|
||||
|
@ -58,26 +56,41 @@ public class InsertItemIntoDatabase implements IHandleJsonObject {
|
|||
!e.optBoolean("unread"), null,
|
||||
e.optString("feedId"), null,
|
||||
date, e.optBoolean("starred"),
|
||||
e.optString("guid"), e.optString("guidHash"),
|
||||
e.optString("guid"),
|
||||
e.optString("guidHash"),
|
||||
e.optString("lastModified"),
|
||||
e.optString("author"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performAction(JSONObject jObj) {
|
||||
RssFile rssFile = parseItem(jObj);
|
||||
buffer.add(rssFile);
|
||||
count++;
|
||||
boolean result = false;
|
||||
|
||||
if(count >= bufferSize) {
|
||||
RssFile rssFile = parseItem(jObj);
|
||||
buffer[index] = rssFile;
|
||||
index++;
|
||||
|
||||
String FeedId_Db = dbConn.getRowIdBySubscriptionID(String.valueOf(rssFile.getFeedID()));
|
||||
if(FeedId_Db != null) {
|
||||
rssFile.setFeedID_Db(FeedId_Db);
|
||||
result = !rssFile.getRead();
|
||||
}
|
||||
|
||||
if(index >= bufferSize) {
|
||||
performDatabaseBatchInsert();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public boolean performDatabaseBatchInsert() {
|
||||
dbConn.insertNewItems(buffer);
|
||||
count = 0;
|
||||
buffer.clear();
|
||||
if(index > 0) {
|
||||
dbConn.insertNewItems(buffer);
|
||||
index = 0;
|
||||
buffer = new RssFile[bufferSize];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -195,6 +195,10 @@ public class OwnCloudReaderMethods {
|
|||
//reader.endObject();
|
||||
count++;
|
||||
}
|
||||
|
||||
if(iJoBj instanceof InsertItemIntoDatabase)
|
||||
((InsertItemIntoDatabase) iJoBj).performDatabaseBatchInsert(); //Save pending buffer
|
||||
|
||||
//reader.endArray();
|
||||
//reader.endObject();
|
||||
reader.close();
|
||||
|
@ -237,6 +241,10 @@ public class OwnCloudReaderMethods {
|
|||
//reader.endObject();
|
||||
count++;
|
||||
}
|
||||
|
||||
if(iJoBj instanceof InsertItemIntoDatabase)
|
||||
((InsertItemIntoDatabase) iJoBj).performDatabaseBatchInsert(); //Save pending buffer
|
||||
|
||||
//reader.endArray();
|
||||
//reader.endObject();
|
||||
reader.close();
|
||||
|
|
|
@ -5,7 +5,7 @@ buildscript {
|
|||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:0.11.+'
|
||||
classpath 'com.android.tools.build:gradle:0.10.+'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue