diff --git a/.idea/misc.xml b/.idea/misc.xml index af0bbdde..703e5d4b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,7 +5,7 @@ - + diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/StatusLoader.java b/app/src/main/java/org/nuclearfog/twidda/backend/StatusLoader.java index b680fd78..9f137266 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/StatusLoader.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/StatusLoader.java @@ -45,7 +45,7 @@ import static org.nuclearfog.twidda.window.TweetDetail.KEY_TWEET_ID; import static org.nuclearfog.twidda.window.TweetDetail.KEY_TWEET_NAME; -public class StatusLoader extends AsyncTask { +public class StatusLoader extends AsyncTask { public enum Mode { LOAD, @@ -62,7 +62,6 @@ public class StatusLoader extends AsyncTask { private WeakReference ui; private SimpleDateFormat sdf; private NumberFormat formatter; - private Tweet tweet; private long homeId; private int font_color, highlight; private boolean toggleImg; @@ -84,6 +83,7 @@ public class StatusLoader extends AsyncTask { @Override protected Void doInBackground(Long... data) { + Tweet tweet; final long TWEETID = data[0]; boolean updateStatus = false; DatabaseAdapter db = new DatabaseAdapter(ui.get()); @@ -92,11 +92,11 @@ public class StatusLoader extends AsyncTask { case LOAD: tweet = db.getStatus(TWEETID); if (tweet != null) { - publishProgress(); + publishProgress(tweet); updateStatus = true; } tweet = mTwitter.getStatus(TWEETID); - publishProgress(); + publishProgress(tweet); if (updateStatus) db.updateStatus(tweet); break; @@ -108,7 +108,7 @@ public class StatusLoader extends AsyncTask { case RETWEET: tweet = mTwitter.retweet(TWEETID); - publishProgress(); + publishProgress(tweet); if (!tweet.retweeted()) db.removeRetweet(TWEETID); @@ -117,10 +117,10 @@ public class StatusLoader extends AsyncTask { case FAVORITE: tweet = mTwitter.favorite(TWEETID); - publishProgress(); + publishProgress(tweet); if (tweet.favored()) - db.storeFavorite(TWEETID); + db.storeFavorite(tweet); else db.removeFavorite(TWEETID); break; @@ -141,7 +141,7 @@ public class StatusLoader extends AsyncTask { @Override - protected void onProgressUpdate(Void... v) { + protected void onProgressUpdate(Tweet[] tweets) { if (ui.get() == null) return; TextView username = ui.get().findViewById(R.id.usernamedetail); @@ -151,6 +151,7 @@ public class StatusLoader extends AsyncTask { Button retweetButton = ui.get().findViewById(R.id.tweet_retweet); Button favoriteButton = ui.get().findViewById(R.id.tweet_favorit); + final Tweet tweet = tweets[0]; if (mode == Mode.LOAD) { View tweet_header = ui.get().findViewById(R.id.tweet_head); if (tweet_header.getVisibility() != VISIBLE) { diff --git a/app/src/main/java/org/nuclearfog/twidda/database/DatabaseAdapter.java b/app/src/main/java/org/nuclearfog/twidda/database/DatabaseAdapter.java index 9ae67ae8..4146ff98 100644 --- a/app/src/main/java/org/nuclearfog/twidda/database/DatabaseAdapter.java +++ b/app/src/main/java/org/nuclearfog/twidda/database/DatabaseAdapter.java @@ -143,23 +143,20 @@ public class DatabaseAdapter { /** * store tweet ID of a favored tweet by the current user * - * @param tweetID Tweet ID + * @param tweet favored tweet */ - public void storeFavorite(long tweetID) { + public void storeFavorite(Tweet tweet) { SQLiteDatabase db = getDbWrite(); - ContentValues favTable = new ContentValues(); - ContentValues status = new ContentValues(); - + long tweetID = tweet.getId(); int register = getTweetStatus(db, tweetID); register |= FAV_MASK; + ContentValues favTable = new ContentValues(); favTable.put("tweetID", tweetID); favTable.put("ownerID", homeId); - status.put("statusregister", register); - db.insertWithOnConflict("favorit", null, favTable, CONFLICT_IGNORE); - db.update("tweet", status, "tweet.tweetID=" + tweetID, null); + storeStatus(tweet, register, db); commit(db); }