Skip to content

Commit

Permalink
Remember which draft we're working with
Browse files Browse the repository at this point in the history
  • Loading branch information
charlag committed Nov 14, 2017
1 parent 24704ba commit b2dad97
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java
Expand Up @@ -134,6 +134,8 @@ public final class ComposeActivity extends BaseActivity
private static final String REPLYING_STATUS_AUTHOR_USERNAME_EXTRA = "replying_author_nickname_extra";
private static final String REPLYING_STATUS_CONTENT_EXTRA = "replying_status_content";

private static final String SAVED_TOOT_UID_STATE = "draft_uid";

private static final String REMEMBERED_VISIBILITY_PREF = "rememberedVisibilityNum";
private static TootDao tootDao = TuskyApplication.getDB().tootDao();

Expand Down Expand Up @@ -163,7 +165,7 @@ public final class ComposeActivity extends BaseActivity
private InputContentInfoCompat currentInputContentInfo;
private int currentFlags;
private Uri photoUploadUri;
private int savedTootUid = 0;
private volatile int savedTootUid = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -265,6 +267,7 @@ public void onClick(View v) {
onCommitContentInternal(previousInputContentInfo, previousFlags);
}
photoUploadUri = savedInstanceState.getParcelable("photoUploadUri");
savedTootUid = savedInstanceState.getInt(SAVED_TOOT_UID_STATE, 0);
} else {
showMarkSensitive = false;
startingVisibility = Status.Visibility.byNum(
Expand Down Expand Up @@ -314,9 +317,10 @@ public void onClick(View v) {
}.getType());
}

int savedTootUid = intent.getIntExtra(SAVED_TOOT_UID_EXTRA, 0);
if (savedTootUid != 0) {
this.savedTootUid = savedTootUid;

// saved instance state should have higher priority
if (savedTootUid == 0) {
savedTootUid = intent.getIntExtra(SAVED_TOOT_UID_EXTRA, 0);
}

if (intent.hasExtra(REPLYING_STATUS_AUTHOR_USERNAME_EXTRA)) {
Expand Down Expand Up @@ -488,6 +492,7 @@ protected void onSaveInstanceState(Bundle outState) {
outState.putBoolean("showMarkSensitive", showMarkSensitive);
outState.putBoolean("statusMarkSensitive", statusMarkSensitive);
outState.putBoolean("statusHideText", statusHideText);
outState.putInt(SAVED_TOOT_UID_STATE, savedTootUid);
if (currentInputContentInfo != null) {
outState.putParcelable("commitContentInputContentInfo",
(Parcelable) currentInputContentInfo.unwrap());
Expand Down Expand Up @@ -719,7 +724,7 @@ private boolean saveTheToot(String s, @Nullable String contentWarning) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
tootDao.insertOrReplace(toot);
savedTootUid = (int) tootDao.insertOrReplace(toot);
return null;
}
}.execute();
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/keylesspalace/tusky/db/TootDao.java
Expand Up @@ -33,7 +33,7 @@
@Dao
public interface TootDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertOrReplace(TootEntity users);
long insertOrReplace(TootEntity users);

@Query("SELECT * FROM TootEntity ORDER BY uid DESC")
List<TootEntity> loadAll();
Expand Down

0 comments on commit b2dad97

Please sign in to comment.