diff options
author | David Development <david-dev@live.de> | 2014-06-13 08:53:07 +0400 |
---|---|---|
committer | David Development <david-dev@live.de> | 2014-06-13 08:53:07 +0400 |
commit | d5c2328e4a7441ab63364dc03aff2dcdd13b40b1 (patch) | |
tree | 39ca8d532543152c0df0456209f6eb6848796489 /News-Android-App/src/main/java | |
parent | 0dae3347fe1a11b689d7f861560a6a73d3f04180 (diff) |
Update sync process
Diffstat (limited to 'News-Android-App/src/main/java')
7 files changed, 98 insertions, 94 deletions
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/Constants.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/Constants.java index 24c4aa16..09bbd2f7 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/Constants.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/Constants.java @@ -3,41 +3,41 @@ package de.luhmer.owncloudnewsreader; public class Constants { public static final Boolean DEBUG_MODE = true; public static final Boolean debugModeWidget = true; - - + + public static final String _TAG_LABEL_UNREAD = "stream/contents/user/-/state/com.google/reading-list?n=1000&r=n&xt=user/-/state/com.google/read"; public static final String _TAG_LABEL_STARRED = "stream/contents/user/-/state/com.google/starred?n=20"; - + //public static final String LAST_SYNC = "LAST_SYNC"; - - public static final int maxItemsCount = 1000; - - + + public static final int maxItemsCount = 1500; + + public static final int TaskID_GetVersion = -10; public static final int TaskID_GetFolder = 1; public static final int TaskID_GetFeeds = 2; public static final int TaskID_GetItems = 3; public static final int TaskID_PerformStateChange = -1; - + public enum SYNC_TYPES { SYNC_TYPE__ITEM_STATES, - SYNC_TYPE__FOLDER, + SYNC_TYPE__FOLDER, SYNC_TYPE__FEEDS, SYNC_TYPE__ITEMS, SYNC_TYPE__GET_API}; public static final String LAST_UPDATE_NEW_ITEMS_COUNT_STRING = "LAST_UPDATE_NEW_ITEMS_COUNT_STRING"; - + /* private static final String _P_KEY_PART1 = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgNmCsMj6M4zkjpKRG8MG5+yIAyqSQE2etVkZsc3s"; private static final String _P_KEY_PART2 = "V5zLoQ/NUOVC0fS2tj8IWk6UYqQGk9rmVold3sDGiTCvWGFecjwel3qxzz23hKLlemrv2+0WPrZ5KOqiaCEMi"; private static final String _P_KEY_PART3 = "CeQ7zgpcytcQdD9Y/aeaHJ9P27ntn0ub6H1Bx3VDRHm4Jkg6LQnqmdIpEmeIztnoMFlLXTaVKapaFmqJGX9ar"; private static final String _P_KEY_PART4 = "RizGd9kqtgAqIP7YnGGDV1vP/MqYpegJkOMOlxhuVvXUsg7t7hBLdGXsJ572DzUK/2/fbZ+PIcG7OF4RgJV7Yb"; private static final String _P_KEY_PART5 = "/AVD0ssqydMlwuheOG82FCqhBtw2vShAz7mkWgL0l0u5HQIDAQAB"; - + public static String getBase64EncodedPublicKey() { - return _P_KEY_PART1 + _P_KEY_PART2 + _P_KEY_PART3 + _P_KEY_PART4 + _P_KEY_PART5; + return _P_KEY_PART1 + _P_KEY_PART2 + _P_KEY_PART3 + _P_KEY_PART4 + _P_KEY_PART5; } */ } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/async_tasks/GetImageAsyncTask.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/async_tasks/GetImageAsyncTask.java index 4030f546..5d9487f0 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/async_tasks/GetImageAsyncTask.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/async_tasks/GetImageAsyncTask.java @@ -27,6 +27,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; import android.os.AsyncTask; +import android.util.Log; import org.apache.http.util.ByteArrayBuffer; @@ -43,26 +44,26 @@ import de.luhmer.owncloudnewsreader.helper.ImageHandler; public class GetImageAsyncTask extends AsyncTask<Void, Void, String> { - //private static final String TAG = "GetImageAsyncTask"; + private static final String TAG = "GetImageAsyncTask"; //private static int count = 0; - + private URL WEB_URL_TO_FILE; private ImageDownloadFinished imageDownloadFinished; private int AsyncTaskId; private String rootPath; private Context cont; - + private BitmapDrawableLruCache lruCache; - + public String feedID = null; public boolean scaleImage = false; public int dstHeight; // height in pixels public int dstWidth; // width in pixels - + //private ImageView imgView; //private WeakReference<ImageView> imageViewReference; - + public GetImageAsyncTask(String WEB_URL_TO_FILE, ImageDownloadFinished imgDownloadFinished, int AsynkTaskId, String rootPath, Context cont/*, ImageView imageView*/, BitmapDrawableLruCache lruCache) { try { @@ -70,7 +71,8 @@ public class GetImageAsyncTask extends AsyncTask<Void, Void, String> } catch(Exception ex) { - ex.printStackTrace(); + Log.d(TAG, ex.getLocalizedMessage() + " - URL: " + WEB_URL_TO_FILE); + //ex.printStackTrace(); } this.lruCache = lruCache; this.cont = cont; @@ -79,7 +81,7 @@ public class GetImageAsyncTask extends AsyncTask<Void, Void, String> this.rootPath = rootPath; //this.imageViewReference = new WeakReference<ImageView>(imageView); } - + @Override protected void onPostExecute(String result) { if(imageDownloadFinished != null) @@ -101,15 +103,15 @@ public class GetImageAsyncTask extends AsyncTask<Void, Void, String> dir.mkdirs(); cacheFile = ImageHandler.getFullPathOfCacheFile(WEB_URL_TO_FILE.toString(), rootPath); //cacheFile.createNewFile(); - - - + + + /* Open a connection to that URL. */ URLConnection urlConn = WEB_URL_TO_FILE.openConnection(); urlConn.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2"); - - + + /* * Define InputStreams to read from the URLConnection. */ @@ -136,18 +138,18 @@ public class GetImageAsyncTask extends AsyncTask<Void, Void, String> FileOutputStream fos = new FileOutputStream(cacheFile); fos.write(baf.toByteArray()); fos.close(); - - + + /* FileOutputStream fOut = new FileOutputStream(cacheFile); Bitmap mBitmap = BitmapFactory.decodeStream(WEB_URL_TO_FILE.openStream()); - + Log.d(TAG, "Downloading image: " + WEB_URL_TO_FILE.toString()); - - if(mBitmap != null) { + + if(mBitmap != null) { if(scaleImage) mBitmap = Bitmap.createScaledBitmap(mBitmap, dstWidth, dstHeight, true); - + mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut); } fOut.close(); @@ -161,7 +163,7 @@ public class GetImageAsyncTask extends AsyncTask<Void, Void, String> HashMap<File, Long> files; long size = ImageHandler.getFolderSize(new File(ImageHandler.getPath(cont))); size = (long) (size / 1024d / 1024d); - + SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(cont); int max_allowed_size = Integer.parseInt(mPrefs.getString(SettingsActivity.SP_MAX_CACHE_SIZE, "1000"));//Default is 1Gb --> 1000mb if(size > max_allowed_size) @@ -171,7 +173,7 @@ public class GetImageAsyncTask extends AsyncTask<Void, Void, String> { files.put(file, file.lastModified()); } - + for(Object itemObj : sortHashMapByValuesD(files).entrySet()) { File file = (File) itemObj; @@ -187,11 +189,11 @@ public class GetImageAsyncTask extends AsyncTask<Void, Void, String> } catch(Exception ex) { - ex.printStackTrace(); + //ex.printStackTrace(); } return null; } - + } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnection.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnection.java index f780e0b8..acfd7b0d 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnection.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnection.java @@ -876,10 +876,15 @@ public class DatabaseConnection { public void insertNewItems(RssFile[] items) { database.beginTransaction(); + + List<Integer> rssItems = getRssItemsIds(); + try { for(RssFile item : items) { - Boolean isFeedAlreadyInDatabase = doesRssItemAlreadyExsists(item.getItem_Id()); - insertNewItem(item, isFeedAlreadyInDatabase); + if(item != null) { + boolean isFeedAlreadyInDatabase = rssItems.contains(item.getItem_Id()); //doesRssItemAlreadyExsists(item.getItem_Id()); + insertNewItem(item, !isFeedAlreadyInDatabase); + } } database.setTransactionSuccessful(); } catch (SQLException e) { @@ -913,7 +918,7 @@ public class DatabaseConnection { else result = database.update(RSS_ITEM_TABLE, contentValues, RSS_ITEM_RSSITEM_ID + "=?", new String[] { item.getItem_Id() }); - Log.d("DatabaseConnection", "Inserted Rows: " + result); + //Log.d("DatabaseConnection", "Inserted Rows: " + result); } public HashMap<String, String> getListOfFolders () { @@ -953,7 +958,7 @@ public class DatabaseConnection { public SparseArray<String> getFeedIds() { String buildSQL = "SELECT " + SUBSCRIPTION_ID + ", rowid as _id FROM " + SUBSCRIPTION_TABLE; - return getSparseArrayFromSQL(buildSQL); + return getSparseArrayFromSQL(buildSQL, 0, 1); } public String getRowIdBySubscriptionID (String StreamID) { @@ -1013,6 +1018,33 @@ public class DatabaseConnection { return false; } + public List<Integer> getRssItemsIds() { + String buildSQL = "SELECT " + RSS_ITEM_RSSITEM_ID + " FROM " + RSS_ITEM_TABLE; + Cursor cursor = database.rawQuery(buildSQL, null); + return convertCursorToIntArray(cursor, 0); + } + + public List<Integer> convertCursorToIntArray(Cursor cursor, int column_id) + { + List<Integer> items = new ArrayList<Integer>(); + try + { + if(cursor != null) + { + if(cursor.getCount() > 0) + { + cursor.moveToFirst(); + do { + items.add(cursor.getInt(column_id)); + } while(cursor.moveToNext()); + } + } + } finally { + cursor.close(); + } + return items; + } + public List<String> convertCursorToStringArray(Cursor cursor, int column_id) { List<String> items = new ArrayList<String>(); @@ -1032,7 +1064,6 @@ public class DatabaseConnection { cursor.close(); } return items; - } private String getStringValueBySQL(String buildSQL) diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/FavIconHandler.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/FavIconHandler.java index 4830fa92..9f2ac621 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/FavIconHandler.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/helper/FavIconHandler.java @@ -40,23 +40,15 @@ import de.luhmer.owncloudnewsreader.async_tasks.GetImageAsyncTask; import de.luhmer.owncloudnewsreader.database.DatabaseConnection; public class FavIconHandler { - public static Drawable GetFavIconFromCache(String URL_TO_PAGE, Context context, String feedID) + private static final String TAG = "FavIconHandler"; + + public static Drawable GetFavIconFromCache(String URL_TO_PAGE, Context context, String feedID) { try { File favIconFile = ImageHandler.getFullPathOfCacheFile(URL_TO_PAGE, ImageHandler.getPathFavIcons(context)); if(favIconFile.isFile() && favIconFile.length() > 0) { - /* - InputStream fs = new FileInputStream(favIconFile); - BufferedInputStream is = new BufferedInputStream(fs, 32*1024); - Bitmap bitmap = GetScaledImage(is, 50, 50); - if(bitmap != null) - return new BitmapDrawable(context.getResources(), bitmap); - else - return null; - */ - if(feedID != null) { DatabaseConnection dbConn = new DatabaseConnection(context); try { @@ -75,7 +67,8 @@ public class FavIconHandler { } catch(Exception ex) { - ex.printStackTrace(); + //Log.d(TAG, ex.getMessage()); + //ex.printStackTrace(); } return null; } @@ -89,44 +82,9 @@ public class FavIconHandler { } - /* - private static Bitmap GetScaledImage(BufferedInputStream is, int minimumDesiredBitmapWidth, int minimumDesiredBitmapHeight) - { - try { - final Options decodeBitmapOptions = new Options(); - // For further memory savings, you may want to consider using this option - // decodeBitmapOptions.inPreferredConfig = Config.RGB_565; // Uses 2-bytes instead of default 4 per pixel - - if(minimumDesiredBitmapWidth > 0 && minimumDesiredBitmapHeight > 0 ) { - final Options decodeBoundsOptions = new Options(); - decodeBoundsOptions.inJustDecodeBounds = true; - is.mark(32*1024); // 32k is probably overkill, but 8k is insufficient for some jpgs - BitmapFactory.decodeStream(is,null,decodeBoundsOptions); - is.reset(); - - final int originalWidth = decodeBoundsOptions.outWidth; - final int originalHeight = decodeBoundsOptions.outHeight; - - // inSampleSize prefers multiples of 2, but we prefer to prioritize memory savings - decodeBitmapOptions.inSampleSize= Math.max(1,Math.min(originalWidth / minimumDesiredBitmapWidth, originalHeight / minimumDesiredBitmapHeight)); - } - - return BitmapFactory.decodeStream(is,null,decodeBitmapOptions); - - } catch( IOException e ) { - throw new RuntimeException(e); // this shouldn't happen - } finally { - try { - is.close(); - } catch( IOException ignored ) {} - } - }*/ - - static SparseArray<FavIconCache> imageViewReferences = new SparseArray<FavIconCache>(); String feedID; - static SparseArray<FavIconCache> favIconToFeedId = new SparseArray<FavIconCache>(); public static void PreCacheFavIcon(String WEB_URL_TO_FILE, Context context, String feedID) { diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/owncloud/AsyncTask_GetItems.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/owncloud/AsyncTask_GetItems.java index e369c36c..f22cfd40 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/owncloud/AsyncTask_GetItems.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/owncloud/AsyncTask_GetItems.java @@ -31,6 +31,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.preference.PreferenceManager; import android.support.v4.app.NotificationCompat; +import android.widget.Toast; import de.luhmer.owncloudnewsreader.Constants; import de.luhmer.owncloudnewsreader.DownloadImagesActivity; @@ -46,13 +47,23 @@ import de.luhmer.owncloudnewsreader.services.DownloadImagesService; public class AsyncTask_GetItems extends AsyncTask_Reader { private long highestItemIdBeforeSync; private API api; + int totalCount; public AsyncTask_GetItems(final int task_id, final Context context, final OnAsyncTaskCompletedListener[] listener, API api) { super(task_id, context, listener); this.api = api; + + totalCount = 0; + } + + @Override + protected void onProgressUpdate(Void... values) { + Toast.makeText(context, "Fetched " + totalCount + " items so far..", Toast.LENGTH_SHORT).show(); + + super.onProgressUpdate(values); } - @Override + @Override protected Exception doInBackground(Object... params) { DatabaseConnection dbConn = new DatabaseConnection(context); try { @@ -78,16 +89,16 @@ public class AsyncTask_GetItems extends AsyncTask_Reader { { int maxItemsInDatabase = Constants.maxItemsCount; - int totalCount = 0; do { requestCount = api.GetItems(TAGS.ALL, context, String.valueOf(offset), false, "0", "3", api); if(requestCount > 0) offset = dbConn.getLowestItemId(false); totalCount += requestCount; - } while(requestCount == maxSyncSize); - mPrefs.edit().putInt(Constants.LAST_UPDATE_NEW_ITEMS_COUNT_STRING, totalCount).commit(); + publishProgress((Void) null); + } while(requestCount == maxSyncSize); + mPrefs.edit().putInt(Constants.LAST_UPDATE_NEW_ITEMS_COUNT_STRING, totalCount).commit(); do { offset = dbConn.getLowestItemId(true); diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/owncloud/InsertItemIntoDatabase.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/owncloud/InsertItemIntoDatabase.java index 77d5be99..812a118e 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/owncloud/InsertItemIntoDatabase.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/owncloud/InsertItemIntoDatabase.java @@ -21,6 +21,8 @@ package de.luhmer.owncloudnewsreader.reader.owncloud; +import android.util.SparseArray; + import org.json.JSONObject; import java.util.Date; @@ -34,7 +36,7 @@ public class InsertItemIntoDatabase implements IHandleJsonObject { RssFile[] buffer; static final short bufferSize = 200; int index = 0; - SparseArray<Integer> feedIds; + SparseArray<String> feedIds; public InsertItemIntoDatabase(DatabaseConnection dbConn) { this.dbConn = dbConn; @@ -73,7 +75,7 @@ public class InsertItemIntoDatabase implements IHandleJsonObject { buffer[index] = rssFile; index++; - String FeedId_Db = feedIds.get(rssFile.getFeedID()); + String FeedId_Db = feedIds.get(Integer.parseInt(rssFile.getFeedID())); if(FeedId_Db != null) { rssFile.setFeedID_Db(FeedId_Db); result = !rssFile.getRead(); diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/owncloud/OwnCloudReaderMethods.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/owncloud/OwnCloudReaderMethods.java index d915f2c3..58a215d4 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/owncloud/OwnCloudReaderMethods.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/reader/owncloud/OwnCloudReaderMethods.java @@ -51,7 +51,7 @@ import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2; public class OwnCloudReaderMethods { //private static final String TAG = "OwnCloudReaderMethods"; - public static String maxSizePerSync = "200"; + public static String maxSizePerSync = "300"; public static int[] GetUpdatedItems(TAGS tag, Context cont, long lastSync, API api) throws Exception { |