Adds save draft button to composer.

This commit is contained in:
Vavassor 2017-07-27 00:56:53 -04:00
parent c6242dd5ef
commit 33a7e3bfed
2 changed files with 57 additions and 32 deletions

View File

@ -137,10 +137,11 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
private EditText contentWarningEditor; private EditText contentWarningEditor;
private TextView charactersLeft; private TextView charactersLeft;
private Button floatingBtn; private Button floatingBtn;
private ImageButton pickBtn;
private ImageButton takeBtn; private ImageButton takeBtn;
private ImageButton hideMediaToggle; private ImageButton pickBtn;
private ImageButton visibilityBtn; private ImageButton visibilityBtn;
private ImageButton saveButton;
private ImageButton hideMediaToggle;
private ProgressBar postProgress; private ProgressBar postProgress;
// this only exists when a status is trying to be sent, but uploads are still occurring // this only exists when a status is trying to be sent, but uploads are still occurring
private ProgressDialog finishingUploadDialog; private ProgressDialog finishingUploadDialog;
@ -174,10 +175,11 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
contentWarningEditor = (EditText) findViewById(R.id.field_content_warning); contentWarningEditor = (EditText) findViewById(R.id.field_content_warning);
charactersLeft = (TextView) findViewById(R.id.characters_left); charactersLeft = (TextView) findViewById(R.id.characters_left);
floatingBtn = (Button) findViewById(R.id.floating_btn); floatingBtn = (Button) findViewById(R.id.floating_btn);
pickBtn = (ImageButton) findViewById(R.id.compose_photo_pick);
takeBtn = (ImageButton) findViewById(R.id.compose_photo_take); takeBtn = (ImageButton) findViewById(R.id.compose_photo_take);
hideMediaToggle = (ImageButton) findViewById(R.id.action_hide_media); pickBtn = (ImageButton) findViewById(R.id.compose_photo_pick);
visibilityBtn = (ImageButton) findViewById(R.id.action_toggle_visibility); visibilityBtn = (ImageButton) findViewById(R.id.action_toggle_visibility);
saveButton = (ImageButton) findViewById(R.id.compose_save_draft);
hideMediaToggle = (ImageButton) findViewById(R.id.action_hide_media);
postProgress = (ProgressBar) findViewById(R.id.postProgress); postProgress = (ProgressBar) findViewById(R.id.postProgress);
// Setup the toolbar. // Setup the toolbar.
@ -203,28 +205,7 @@ 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) {
String contentWarning = null; return saveDraft();
if (statusHideText) {
contentWarning = contentWarningEditor.getText().toString();
}
/* Discard any upload URLs embedded in the text because they'll be re-uploaded when
* the draft is loaded and replaced with new URLs. */
if (mediaQueued != null) {
for (QueuedMedia item : mediaQueued) {
removeUrlFromEditable(textEditor.getEditableText(), item.uploadUrl);
}
}
boolean b = saveTheToot(textEditor.getText().toString(), contentWarning);
if (b) {
Toast.makeText(ComposeActivity.this, R.string.action_save_one_toot, Toast.LENGTH_SHORT).show();
}
return b;
}
});
pickBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onMediaPick();
} }
}); });
takeBtn.setOnClickListener(new View.OnClickListener() { takeBtn.setOnClickListener(new View.OnClickListener() {
@ -233,10 +214,10 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
initiateCameraApp(); initiateCameraApp();
} }
}); });
hideMediaToggle.setOnClickListener(new View.OnClickListener() { pickBtn.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
toggleHideMedia(); onMediaPick();
} }
}); });
visibilityBtn.setOnClickListener(new View.OnClickListener() { visibilityBtn.setOnClickListener(new View.OnClickListener() {
@ -245,6 +226,18 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
showComposeOptions(); showComposeOptions();
} }
}); });
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveDraft();
}
});
hideMediaToggle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toggleHideMedia();
}
});
/* Initialise all the state, or restore it from a previous run, to determine a "starting" /* Initialise all the state, or restore it from a previous run, to determine a "starting"
* state. */ * state. */
@ -534,21 +527,43 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
} }
private void disableButtons() { private void disableButtons() {
pickBtn.setClickable(false);
takeBtn.setClickable(false); takeBtn.setClickable(false);
hideMediaToggle.setClickable(false); pickBtn.setClickable(false);
visibilityBtn.setClickable(false); visibilityBtn.setClickable(false);
saveButton.setClickable(false);
hideMediaToggle.setClickable(false);
floatingBtn.setEnabled(false); floatingBtn.setEnabled(false);
} }
private void enableButtons() { private void enableButtons() {
pickBtn.setClickable(true);
takeBtn.setClickable(true); takeBtn.setClickable(true);
hideMediaToggle.setClickable(true); pickBtn.setClickable(true);
visibilityBtn.setClickable(true); visibilityBtn.setClickable(true);
saveButton.setClickable(true);
hideMediaToggle.setClickable(true);
floatingBtn.setEnabled(true); floatingBtn.setEnabled(true);
} }
private boolean saveDraft() {
String contentWarning = null;
if (statusHideText) {
contentWarning = contentWarningEditor.getText().toString();
}
/* Discard any upload URLs embedded in the text because they'll be re-uploaded when
* the draft is loaded and replaced with new URLs. */
if (mediaQueued != null) {
for (QueuedMedia item : mediaQueued) {
removeUrlFromEditable(textEditor.getEditableText(), item.uploadUrl);
}
}
boolean b = saveTheToot(textEditor.getText().toString(), contentWarning);
if (b) {
Toast.makeText(ComposeActivity.this, R.string.action_save_one_toot, Toast.LENGTH_SHORT)
.show();
}
return b;
}
private static boolean copyToFile(ContentResolver contentResolver, Uri uri, File file) { private static boolean copyToFile(ContentResolver contentResolver, Uri uri, File file) {
InputStream from; InputStream from;
FileOutputStream to; FileOutputStream to;

View File

@ -130,6 +130,16 @@
app:srcCompat="@drawable/ic_public_24dp" app:srcCompat="@drawable/ic_public_24dp"
android:contentDescription="@string/action_compose_options" /> android:contentDescription="@string/action_compose_options" />
<ImageButton
android:id="@+id/compose_save_draft"
style="?attr/image_button_style"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:srcCompat="@drawable/ic_save_24dp"
android:contentDescription="@string/action_save" />
<ImageButton <ImageButton
android:id="@+id/action_hide_media" android:id="@+id/action_hide_media"
style="?attr/image_button_style" style="?attr/image_button_style"