From 47dccd81e7dfcdeb70974de694c0328b14c3ad23 Mon Sep 17 00:00:00 2001 From: torrentcome Date: Fri, 7 Jul 2017 12:32:47 +0200 Subject: [PATCH] (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 61bf956d4..81c8d69b3 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 19461984a..b3779af52 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