From 42d94633cf63d14f765532e5a89b8995f60b6861 Mon Sep 17 00:00:00 2001 From: torrentcome Date: Fri, 7 Jul 2017 12:32:04 +0200 Subject: [PATCH 1/3] (ui) fix bug that when we comeback from the Composer , there is no update of the view --- .../com/keylesspalace/tusky/SavedTootActivity.java | 12 +++++++++++- .../tusky/adapter/SavedTootAdapter.java | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/SavedTootActivity.java b/app/src/main/java/com/keylesspalace/tusky/SavedTootActivity.java index 88560dab..385fa52e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/SavedTootActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/SavedTootActivity.java @@ -72,6 +72,12 @@ public class SavedTootActivity extends BaseActivity implements SavedTootAdapter. adapter = new SavedTootAdapter(this); recyclerView.setAdapter(adapter); + } + + @Override + protected void onResume() { + super.onResume(); + // req getAllToot(); } @@ -99,7 +105,10 @@ public class SavedTootActivity extends BaseActivity implements SavedTootAdapter. super.onPostExecute(tootEntities); // set ui setNoContent(tootEntities.size()); - adapter.addItems(tootEntities); + if (adapter != null) { + adapter.setItems(tootEntities); + adapter.notifyDataSetChanged(); + } } }.execute(); } @@ -126,6 +135,7 @@ public class SavedTootActivity extends BaseActivity implements SavedTootAdapter. @Override public void click(int position, TootEntity item) { Intent intent = new Intent(this, ComposeActivity.class); + intent.putExtra("saved_toot_uid", item.getUid()); intent.putExtra("saved_toot_text", item.getText()); intent.putExtra("saved_json_urls", item.getUrls()); startActivity(intent); diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/SavedTootAdapter.java b/app/src/main/java/com/keylesspalace/tusky/adapter/SavedTootAdapter.java index 3db08bc0..12a55467 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/SavedTootAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/SavedTootAdapter.java @@ -59,6 +59,11 @@ public class SavedTootAdapter extends RecyclerView.Adapter { return list.size(); } + public void setItems(List newToot) { + list = new ArrayList<>(); + list.addAll(newToot); + } + public void addItems(List newToot) { int end = list.size(); list.addAll(newToot); From 47dccd81e7dfcdeb70974de694c0328b14c3ad23 Mon Sep 17 00:00:00 2001 From: torrentcome Date: Fri, 7 Jul 2017 12:32:47 +0200 Subject: [PATCH 2/3] (db) add the Update feature for each Draft we already have --- .../com/keylesspalace/tusky/ComposeActivity.java | 15 ++++++++++++--- .../java/com/keylesspalace/tusky/db/TootDao.java | 6 ++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index 61bf956d..81c8d69b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -158,7 +158,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm private InputContentInfoCompat currentInputContentInfo; private int currentFlags; private Uri photoUploadUri; - + private int savedTootUid = 0; /** * The Target object must be stored as a member field or method and cannot be an anonymous class otherwise this won't work as expected. The reason is that Picasso accepts this parameter as a weak memory reference. Because anonymous classes are eligible for garbage collection when there are no more references, the network request to fetch the image may finish after this anonymous class has already been reclaimed. See this Stack Overflow discussion for more details. @@ -311,8 +311,12 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm // try to redo a list of media ArrayList playersList = new Gson().fromJson(savedJsonUrls, new TypeToken>() { - }.getType()); + }.getType()); + } + int savedTootUid = intent.getIntExtra("saved_toot_uid", 0); + if (savedTootUid != 0) { + this.savedTootUid = savedTootUid; } } @@ -547,7 +551,12 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm new AsyncTask() { @Override protected Void doInBackground(Void... params) { - tootDao.insert(toot); + if (savedTootUid != 0) { + toot.setUid(savedTootUid); + tootDao.updateToot(toot); + } else { + tootDao.insert(toot); + } return null; } }.execute(); diff --git a/app/src/main/java/com/keylesspalace/tusky/db/TootDao.java b/app/src/main/java/com/keylesspalace/tusky/db/TootDao.java index 19461984..b3779af5 100644 --- a/app/src/main/java/com/keylesspalace/tusky/db/TootDao.java +++ b/app/src/main/java/com/keylesspalace/tusky/db/TootDao.java @@ -3,6 +3,7 @@ package com.keylesspalace.tusky.db; import android.arch.persistence.room.Dao; import android.arch.persistence.room.Delete; import android.arch.persistence.room.Insert; +import android.arch.persistence.room.OnConflictStrategy; import android.arch.persistence.room.Query; import android.arch.persistence.room.Update; @@ -23,12 +24,9 @@ public interface TootDao { @Query("SELECT * FROM TootEntity") List loadAll(); - @Query("SELECT * FROM TootEntity WHERE uid IN (:uid)") - List loadAllByTootId(int... uid); - // u @Update - void updateToot(TootEntity... toot); + void updateToot(TootEntity toot); // d @Delete From 65c274d2911d9742b93ef08fc55fbfa77acbfbf4 Mon Sep 17 00:00:00 2001 From: torrentcome Date: Fri, 7 Jul 2017 13:36:39 +0200 Subject: [PATCH 3/3] (gradle) remove useless rx room stuff --- app/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 46db1be3..ae008c98 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -59,6 +59,5 @@ dependencies { //room compile "android.arch.persistence.room:runtime:1.0.0-alpha3" annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha3" - compile "android.arch.persistence.room:rxjava2:1.0.0-alpha2" }