|
|
@ -42,12 +42,15 @@ import android.support.annotation.DrawableRes; |
|
|
|
import android.support.annotation.NonNull; |
|
|
|
import android.support.annotation.NonNull; |
|
|
|
import android.support.annotation.Nullable; |
|
|
|
import android.support.annotation.Nullable; |
|
|
|
import android.support.annotation.StringRes; |
|
|
|
import android.support.annotation.StringRes; |
|
|
|
|
|
|
|
import android.support.design.widget.FloatingActionButton; |
|
|
|
import android.support.design.widget.Snackbar; |
|
|
|
import android.support.design.widget.Snackbar; |
|
|
|
import android.support.v13.view.inputmethod.EditorInfoCompat; |
|
|
|
import android.support.v13.view.inputmethod.EditorInfoCompat; |
|
|
|
import android.support.v13.view.inputmethod.InputConnectionCompat; |
|
|
|
import android.support.v13.view.inputmethod.InputConnectionCompat; |
|
|
|
import android.support.v13.view.inputmethod.InputContentInfoCompat; |
|
|
|
import android.support.v13.view.inputmethod.InputContentInfoCompat; |
|
|
|
import android.support.v4.app.ActivityCompat; |
|
|
|
import android.support.v4.app.ActivityCompat; |
|
|
|
import android.support.v4.content.ContextCompat; |
|
|
|
import android.support.v4.content.ContextCompat; |
|
|
|
|
|
|
|
import android.support.v7.app.ActionBar; |
|
|
|
|
|
|
|
import android.support.v7.widget.Toolbar; |
|
|
|
import android.text.Editable; |
|
|
|
import android.text.Editable; |
|
|
|
import android.text.InputType; |
|
|
|
import android.text.InputType; |
|
|
|
import android.text.Spannable; |
|
|
|
import android.text.Spannable; |
|
|
@ -55,6 +58,8 @@ import android.text.Spanned; |
|
|
|
import android.text.TextWatcher; |
|
|
|
import android.text.TextWatcher; |
|
|
|
import android.text.style.ForegroundColorSpan; |
|
|
|
import android.text.style.ForegroundColorSpan; |
|
|
|
import android.view.Gravity; |
|
|
|
import android.view.Gravity; |
|
|
|
|
|
|
|
import android.view.Menu; |
|
|
|
|
|
|
|
import android.view.MenuItem; |
|
|
|
import android.view.View; |
|
|
|
import android.view.View; |
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.view.inputmethod.EditorInfo; |
|
|
|
import android.view.inputmethod.EditorInfo; |
|
|
@ -105,7 +110,6 @@ public class ComposeActivity extends BaseActivity { |
|
|
|
private String domain; |
|
|
|
private String domain; |
|
|
|
private String accessToken; |
|
|
|
private String accessToken; |
|
|
|
private EditText textEditor; |
|
|
|
private EditText textEditor; |
|
|
|
private ImageButton mediaPick; |
|
|
|
|
|
|
|
private LinearLayout mediaPreviewBar; |
|
|
|
private LinearLayout mediaPreviewBar; |
|
|
|
private ArrayList<QueuedMedia> mediaQueued; |
|
|
|
private ArrayList<QueuedMedia> mediaQueued; |
|
|
|
private CountUpDownLatch waitForMediaLatch; |
|
|
|
private CountUpDownLatch waitForMediaLatch; |
|
|
@ -118,6 +122,8 @@ public class ComposeActivity extends BaseActivity { |
|
|
|
private InputContentInfoCompat currentInputContentInfo; |
|
|
|
private InputContentInfoCompat currentInputContentInfo; |
|
|
|
private int currentFlags; |
|
|
|
private int currentFlags; |
|
|
|
private ProgressDialog finishingUploadDialog; |
|
|
|
private ProgressDialog finishingUploadDialog; |
|
|
|
|
|
|
|
private EditText contentWarningEditor; |
|
|
|
|
|
|
|
private boolean mediaPickEnabled; |
|
|
|
|
|
|
|
|
|
|
|
private static class QueuedMedia { |
|
|
|
private static class QueuedMedia { |
|
|
|
enum Type { |
|
|
|
enum Type { |
|
|
@ -317,9 +323,30 @@ public class ComposeActivity extends BaseActivity { |
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
setContentView(R.layout.activity_compose); |
|
|
|
setContentView(R.layout.activity_compose); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); |
|
|
|
|
|
|
|
setSupportActionBar(toolbar); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ActionBar actionBar = getSupportActionBar(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (actionBar != null) { |
|
|
|
|
|
|
|
actionBar.setTitle(null); |
|
|
|
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true); |
|
|
|
|
|
|
|
actionBar.setDisplayShowHomeEnabled(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SharedPreferences preferences = getSharedPreferences( |
|
|
|
SharedPreferences preferences = getSharedPreferences( |
|
|
|
getString(R.string.preferences_file_key), Context.MODE_PRIVATE); |
|
|
|
getString(R.string.preferences_file_key), Context.MODE_PRIVATE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mediaPickEnabled = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FloatingActionButton floatingBtn = (FloatingActionButton) findViewById(R.id.floating_btn); |
|
|
|
|
|
|
|
floatingBtn.setOnClickListener(new View.OnClickListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onClick(View v) { |
|
|
|
|
|
|
|
sendStatus(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
ArrayList<SavedQueuedMedia> savedMediaQueued = null; |
|
|
|
ArrayList<SavedQueuedMedia> savedMediaQueued = null; |
|
|
|
if (savedInstanceState != null) { |
|
|
|
if (savedInstanceState != null) { |
|
|
|
showMarkSensitive = savedInstanceState.getBoolean("showMarkSensitive"); |
|
|
|
showMarkSensitive = savedInstanceState.getBoolean("showMarkSensitive"); |
|
|
@ -399,83 +426,65 @@ public class ComposeActivity extends BaseActivity { |
|
|
|
waitForMediaLatch = new CountUpDownLatch(); |
|
|
|
waitForMediaLatch = new CountUpDownLatch(); |
|
|
|
|
|
|
|
|
|
|
|
contentWarningBar = findViewById(R.id.compose_content_warning_bar); |
|
|
|
contentWarningBar = findViewById(R.id.compose_content_warning_bar); |
|
|
|
@DrawableRes int drawableId = ThemeUtils.getDrawableId(this, |
|
|
|
contentWarningEditor = (EditText) findViewById(R.id.field_content_warning); |
|
|
|
R.attr.compose_content_warning_bar_background, R.drawable.border_background_dark); |
|
|
|
|
|
|
|
contentWarningBar.setBackgroundResource(drawableId); |
|
|
|
|
|
|
|
final EditText contentWarningEditor = (EditText) findViewById(R.id.field_content_warning); |
|
|
|
|
|
|
|
showContentWarning(false); |
|
|
|
showContentWarning(false); |
|
|
|
|
|
|
|
|
|
|
|
statusAlreadyInFlight = false; |
|
|
|
statusAlreadyInFlight = false; |
|
|
|
final Button sendButton = (Button) findViewById(R.id.button_send); |
|
|
|
|
|
|
|
sendButton.setOnClickListener(new View.OnClickListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onClick(View v) { |
|
|
|
|
|
|
|
if (statusAlreadyInFlight) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Editable editable = textEditor.getText(); |
|
|
|
|
|
|
|
if (editable.length() <= STATUS_CHARACTER_LIMIT) { |
|
|
|
|
|
|
|
statusAlreadyInFlight = true; |
|
|
|
|
|
|
|
String spoilerText = ""; |
|
|
|
|
|
|
|
if (statusHideText) { |
|
|
|
|
|
|
|
spoilerText = contentWarningEditor.getText().toString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
readyStatus(editable.toString(), statusVisibility, statusMarkSensitive, |
|
|
|
|
|
|
|
spoilerText); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
textEditor.setError(getString(R.string.error_compose_character_limit)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mediaPick = (ImageButton) findViewById(R.id.compose_photo_pick); |
|
|
|
// These can only be added after everything affected by the media queue is initialized.
|
|
|
|
mediaPick.setOnClickListener(new View.OnClickListener() { |
|
|
|
if (savedMediaQueued != null) { |
|
|
|
@Override |
|
|
|
for (SavedQueuedMedia item : savedMediaQueued) { |
|
|
|
public void onClick(View v) { |
|
|
|
addMediaToQueue(item.type, item.preview, item.uri, item.mediaSize); |
|
|
|
onMediaPick(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ImageButton options = (ImageButton) findViewById(R.id.compose_options); |
|
|
|
private void showComposeOptions() { |
|
|
|
options.setOnClickListener(new View.OnClickListener() { |
|
|
|
ComposeOptionsFragment fragment = ComposeOptionsFragment.newInstance( |
|
|
|
@Override |
|
|
|
statusVisibility, statusMarkSensitive, statusHideText, |
|
|
|
public void onClick(View v) { |
|
|
|
showMarkSensitive, inReplyToId != null, |
|
|
|
ComposeOptionsFragment fragment = ComposeOptionsFragment.newInstance( |
|
|
|
new ComposeOptionsFragment.Listener() { |
|
|
|
statusVisibility, statusMarkSensitive, statusHideText, |
|
|
|
@Override |
|
|
|
showMarkSensitive, inReplyToId != null, |
|
|
|
public int describeContents() { |
|
|
|
new ComposeOptionsFragment.Listener() { |
|
|
|
return 0; |
|
|
|
@Override |
|
|
|
} |
|
|
|
public int describeContents() { |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void writeToParcel(Parcel dest, int flags) {} |
|
|
|
public void writeToParcel(Parcel dest, int flags) {} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onVisibilityChanged(String visibility) { |
|
|
|
public void onVisibilityChanged(String visibility) { |
|
|
|
statusVisibility = visibility; |
|
|
|
statusVisibility = visibility; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onMarkSensitiveChanged(boolean markSensitive) { |
|
|
|
public void onMarkSensitiveChanged(boolean markSensitive) { |
|
|
|
statusMarkSensitive = markSensitive; |
|
|
|
statusMarkSensitive = markSensitive; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onContentWarningChanged(boolean hideText) { |
|
|
|
public void onContentWarningChanged(boolean hideText) { |
|
|
|
showContentWarning(hideText); |
|
|
|
showContentWarning(hideText); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
fragment.show(getSupportFragmentManager(), null); |
|
|
|
fragment.show(getSupportFragmentManager(), null); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// These can only be added after everything affected by the media queue is initialized.
|
|
|
|
private void sendStatus() { |
|
|
|
if (savedMediaQueued != null) { |
|
|
|
if (statusAlreadyInFlight) { |
|
|
|
for (SavedQueuedMedia item : savedMediaQueued) { |
|
|
|
return; |
|
|
|
addMediaToQueue(item.type, item.preview, item.uri, item.mediaSize); |
|
|
|
} |
|
|
|
|
|
|
|
Editable editable = textEditor.getText(); |
|
|
|
|
|
|
|
if (editable.length() <= STATUS_CHARACTER_LIMIT) { |
|
|
|
|
|
|
|
statusAlreadyInFlight = true; |
|
|
|
|
|
|
|
String spoilerText = ""; |
|
|
|
|
|
|
|
if (statusHideText) { |
|
|
|
|
|
|
|
spoilerText = contentWarningEditor.getText().toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
readyStatus(editable.toString(), statusVisibility, statusMarkSensitive, |
|
|
|
|
|
|
|
spoilerText); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
textEditor.setError(getString(R.string.error_compose_character_limit)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -530,7 +539,7 @@ public class ComposeActivity extends BaseActivity { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
mimeTypes = Arrays.copyOf(contentMimeTypes, contentMimeTypes.length); |
|
|
|
mimeTypes = Arrays.copyOf(contentMimeTypes, contentMimeTypes.length); |
|
|
|
} |
|
|
|
} |
|
|
|
EditText editText = new EditText(this) { |
|
|
|
EditText editText = new android.support.v7.widget.AppCompatEditText(this) { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public InputConnection onCreateInputConnection(EditorInfo editorInfo) { |
|
|
|
public InputConnection onCreateInputConnection(EditorInfo editorInfo) { |
|
|
|
final InputConnection ic = super.onCreateInputConnection(editorInfo); |
|
|
|
final InputConnection ic = super.onCreateInputConnection(editorInfo); |
|
|
@ -783,15 +792,24 @@ public class ComposeActivity extends BaseActivity { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void enableMediaPicking() { |
|
|
|
private void enableMediaPicking() { |
|
|
|
mediaPick.setEnabled(true); |
|
|
|
mediaPickEnabled = true; |
|
|
|
ThemeUtils.setImageViewTint(mediaPick, R.attr.compose_media_button_tint); |
|
|
|
invalidateOptionsMenu(); |
|
|
|
mediaPick.setImageResource(R.drawable.ic_media); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void disableMediaPicking() { |
|
|
|
private void disableMediaPicking() { |
|
|
|
mediaPick.setEnabled(false); |
|
|
|
mediaPickEnabled = false; |
|
|
|
ThemeUtils.setImageViewTint(mediaPick, R.attr.compose_media_button_disabled_tint); |
|
|
|
invalidateOptionsMenu(); |
|
|
|
mediaPick.setImageResource(R.drawable.ic_media_disabled); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) { |
|
|
|
|
|
|
|
if (mediaPickEnabled) { |
|
|
|
|
|
|
|
menu.findItem(R.id.compose_photo_pick).setEnabled(true); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
menu.findItem(R.id.compose_photo_pick).setEnabled(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return super.onPrepareOptionsMenu(menu); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize) { |
|
|
|
private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize) { |
|
|
@ -1103,4 +1121,32 @@ public class ComposeActivity extends BaseActivity { |
|
|
|
contentWarningBar.setVisibility(View.GONE); |
|
|
|
contentWarningBar.setVisibility(View.GONE); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) { |
|
|
|
|
|
|
|
getMenuInflater().inflate(R.menu.compose_toolbar, menu); |
|
|
|
|
|
|
|
return super.onCreateOptionsMenu(menu); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) { |
|
|
|
|
|
|
|
switch (item.getItemId()) { |
|
|
|
|
|
|
|
case android.R.id.home: { |
|
|
|
|
|
|
|
onBackPressed(); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case R.id.compose_photo_pick: { |
|
|
|
|
|
|
|
onMediaPick(); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case R.id.compose_options: { |
|
|
|
|
|
|
|
showComposeOptions(); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|