Saves content warnings in drafts.

This commit is contained in:
Vavassor 2017-07-07 22:56:07 -04:00
parent 2c389dd147
commit 125c0e7e6c
6 changed files with 42 additions and 14 deletions

View File

@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
<uses-permission android:name="android.permission.VIBRATE" /> <!--For notifications--> <uses-permission android:name="android.permission.VIBRATE" /> <!--For notifications-->
<uses-permission android:name="android.permission.WAKE_LOCK" /> <!--Required by Eclipse Paho--> <uses-permission android:name="android.permission.WAKE_LOCK" /> <!--Required by Eclipse Paho-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!--Required by Eclipse Paho--> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!--Required by Eclipse Paho-->

View File

@ -201,7 +201,11 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
floatingBtn.setOnLongClickListener(new View.OnLongClickListener() { floatingBtn.setOnLongClickListener(new View.OnLongClickListener() {
@Override @Override
public boolean onLongClick(View v) { public boolean onLongClick(View v) {
boolean b = saveTheToot(textEditor.getText().toString()); String contentWarning = null;
if (statusHideText) {
contentWarning = contentWarningEditor.getText().toString();
}
boolean b = saveTheToot(textEditor.getText().toString(), contentWarning);
if (b) { if (b) {
Toast.makeText(ComposeActivity.this, R.string.action_save_one_toot, Toast.LENGTH_SHORT).show(); Toast.makeText(ComposeActivity.this, R.string.action_save_one_toot, Toast.LENGTH_SHORT).show();
} }
@ -269,6 +273,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
Intent intent = getIntent(); Intent intent = getIntent();
String[] mentionedUsernames = null; String[] mentionedUsernames = null;
ArrayList<String> loadedDraftMediaUris = null;
inReplyToId = null; inReplyToId = null;
if (intent != null) { if (intent != null) {
inReplyToId = intent.getStringExtra("in_reply_to_id"); inReplyToId = intent.getStringExtra("in_reply_to_id");
@ -294,10 +299,15 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
if (startingHideText) { if (startingHideText) {
startingContentWarning = intent.getStringExtra("content_warning"); startingContentWarning = intent.getStringExtra("content_warning");
} }
} else {
String contentWarning = intent.getStringExtra("saved_toot_content_warning");
startingHideText = !TextUtils.isEmpty(contentWarning);
if (startingHideText) {
startingContentWarning = contentWarning;
}
} }
/* If come from SavedTootActivity // If come from SavedTootActivity
* */
String savedTootText = intent.getStringExtra("saved_toot_text"); String savedTootText = intent.getStringExtra("saved_toot_text");
if (!TextUtils.isEmpty(savedTootText)) { if (!TextUtils.isEmpty(savedTootText)) {
textEditor.append(savedTootText); textEditor.append(savedTootText);
@ -306,7 +316,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
String savedJsonUrls = intent.getStringExtra("saved_json_urls"); String savedJsonUrls = intent.getStringExtra("saved_json_urls");
if (!TextUtils.isEmpty(savedJsonUrls)) { if (!TextUtils.isEmpty(savedJsonUrls)) {
// try to redo a list of media // try to redo a list of media
ArrayList<String> playersList = new Gson().fromJson(savedJsonUrls, loadedDraftMediaUris = new Gson().fromJson(savedJsonUrls,
new TypeToken<ArrayList<String>>() { new TypeToken<ArrayList<String>>() {
}.getType()); }.getType());
} }
@ -398,6 +408,13 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
statusAlreadyInFlight = false; statusAlreadyInFlight = false;
// These can only be added after everything affected by the media queue is initialized. // These can only be added after everything affected by the media queue is initialized.
/* if (loadedDraftMediaUris != null && !loadedDraftMediaUris.isEmpty()) {
for (String uriString : loadedDraftMediaUris) {
Uri uri = Uri.parse(uriString);
long mediaSize = MediaUtils.getMediaSize(getContentResolver(), uri);
pickMedia(uri, mediaSize);
}
} else */
if (savedMediaQueued != null) { if (savedMediaQueued != null) {
for (SavedQueuedMedia item : savedMediaQueued) { for (SavedQueuedMedia item : savedMediaQueued) {
addMediaToQueue(item.type, item.preview, item.uri, item.mediaSize); addMediaToQueue(item.type, item.preview, item.uri, item.mediaSize);
@ -530,16 +547,16 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
} }
} }
public boolean saveTheToot(String s) { public boolean saveTheToot(String s, @Nullable String contentWarning) {
if (TextUtils.isEmpty(s)) { if (TextUtils.isEmpty(s)) {
return false; return false;
} else { } else {
final TootEntity toot = new TootEntity(); final TootEntity toot = new TootEntity();
toot.setText(s); toot.setText(s);
toot.setContentWarning(contentWarning);
if (mediaQueued != null && mediaQueued.size() > 0) { if (mediaQueued != null && mediaQueued.size() > 0) {
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
for (QueuedMedia q : for (QueuedMedia q : mediaQueued) {
mediaQueued) {
list.add(q.uri.toString()); list.add(q.uri.toString());
} }
String json = new Gson().toJson(list); String json = new Gson().toJson(list);
@ -679,7 +696,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
} }
private boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, private boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags,
String[] mimeTypes) { String[] mimeTypes) {
try { try {
if (currentInputContentInfo != null) { if (currentInputContentInfo != null) {
currentInputContentInfo.releasePermission(); currentInputContentInfo.releasePermission();
@ -741,7 +758,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
} }
private void sendStatus(String content, String visibility, boolean sensitive, private void sendStatus(String content, String visibility, boolean sensitive,
String spoilerText) { String spoilerText) {
ArrayList<String> mediaIds = new ArrayList<>(); ArrayList<String> mediaIds = new ArrayList<>();
for (QueuedMedia item : mediaQueued) { for (QueuedMedia item : mediaQueued) {
@ -1240,7 +1257,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
} }
} }
void showMarkSensitive(boolean show) { private void showMarkSensitive(boolean show) {
showMarkSensitive = show; showMarkSensitive = show;
if (!showMarkSensitive) { if (!showMarkSensitive) {
@ -1256,7 +1273,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
} }
} }
void showContentWarning(boolean show) { private void showContentWarning(boolean show) {
statusHideText = show; statusHideText = show;
if (show) { if (show) {
contentWarningBar.setVisibility(View.VISIBLE); contentWarningBar.setVisibility(View.VISIBLE);

View File

@ -137,6 +137,7 @@ public class SavedTootActivity extends BaseActivity implements SavedTootAdapter.
Intent intent = new Intent(this, ComposeActivity.class); Intent intent = new Intent(this, ComposeActivity.class);
intent.putExtra("saved_toot_uid", item.getUid()); intent.putExtra("saved_toot_uid", item.getUid());
intent.putExtra("saved_toot_text", item.getText()); intent.putExtra("saved_toot_text", item.getText());
intent.putExtra("saved_toot_content_warning", item.getContentWarning());
intent.putExtra("saved_json_urls", item.getUrls()); intent.putExtra("saved_json_urls", item.getUrls());
startActivity(intent); startActivity(intent);
} }

View File

@ -7,7 +7,7 @@ import android.arch.persistence.room.RoomDatabase;
* DB version & declare DAO * DB version & declare DAO
*/ */
@Database(entities = {TootEntity.class}, version = 1, exportSchema = false) @Database(entities = {TootEntity.class}, version = 2, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase { public abstract class AppDatabase extends RoomDatabase {
public abstract TootDao tootDao(); public abstract TootDao tootDao();

View File

@ -3,7 +3,6 @@ package com.keylesspalace.tusky.db;
import android.arch.persistence.room.Dao; import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete; import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert; import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query; import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update; import android.arch.persistence.room.Update;

View File

@ -19,6 +19,9 @@ public class TootEntity {
@ColumnInfo(name = "urls") @ColumnInfo(name = "urls")
private String urls; private String urls;
@ColumnInfo(name = "contentWarning")
private String contentWarning;
// getter setter // getter setter
public String getText() { public String getText() {
return text; return text;
@ -28,6 +31,14 @@ public class TootEntity {
this.text = text; this.text = text;
} }
public String getContentWarning() {
return contentWarning;
}
public void setContentWarning(String contentWarning) {
this.contentWarning = contentWarning;
}
public int getUid() { public int getUid() {
return uid; return uid;
} }