Made compose form more material
This commit is contained in:
parent
ce04c7ab2b
commit
d067c8bf27
|
@ -42,12 +42,15 @@ import android.support.annotation.DrawableRes;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v13.view.inputmethod.EditorInfoCompat;
|
||||
import android.support.v13.view.inputmethod.InputConnectionCompat;
|
||||
import android.support.v13.view.inputmethod.InputContentInfoCompat;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
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.InputType;
|
||||
import android.text.Spannable;
|
||||
|
@ -55,6 +58,8 @@ import android.text.Spanned;
|
|||
import android.text.TextWatcher;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.Gravity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
|
@ -105,7 +110,6 @@ public class ComposeActivity extends BaseActivity {
|
|||
private String domain;
|
||||
private String accessToken;
|
||||
private EditText textEditor;
|
||||
private ImageButton mediaPick;
|
||||
private LinearLayout mediaPreviewBar;
|
||||
private ArrayList<QueuedMedia> mediaQueued;
|
||||
private CountUpDownLatch waitForMediaLatch;
|
||||
|
@ -118,6 +122,8 @@ public class ComposeActivity extends BaseActivity {
|
|||
private InputContentInfoCompat currentInputContentInfo;
|
||||
private int currentFlags;
|
||||
private ProgressDialog finishingUploadDialog;
|
||||
private EditText contentWarningEditor;
|
||||
private boolean mediaPickEnabled;
|
||||
|
||||
private static class QueuedMedia {
|
||||
enum Type {
|
||||
|
@ -317,9 +323,30 @@ public class ComposeActivity extends BaseActivity {
|
|||
super.onCreate(savedInstanceState);
|
||||
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(
|
||||
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;
|
||||
if (savedInstanceState != null) {
|
||||
showMarkSensitive = savedInstanceState.getBoolean("showMarkSensitive");
|
||||
|
@ -399,77 +426,10 @@ public class ComposeActivity extends BaseActivity {
|
|||
waitForMediaLatch = new CountUpDownLatch();
|
||||
|
||||
contentWarningBar = findViewById(R.id.compose_content_warning_bar);
|
||||
@DrawableRes int drawableId = ThemeUtils.getDrawableId(this,
|
||||
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);
|
||||
contentWarningEditor = (EditText) findViewById(R.id.field_content_warning);
|
||||
showContentWarning(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);
|
||||
mediaPick.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onMediaPick();
|
||||
}
|
||||
});
|
||||
|
||||
ImageButton options = (ImageButton) findViewById(R.id.compose_options);
|
||||
options.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
ComposeOptionsFragment fragment = ComposeOptionsFragment.newInstance(
|
||||
statusVisibility, statusMarkSensitive, statusHideText,
|
||||
showMarkSensitive, inReplyToId != null,
|
||||
new ComposeOptionsFragment.Listener() {
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {}
|
||||
|
||||
@Override
|
||||
public void onVisibilityChanged(String visibility) {
|
||||
statusVisibility = visibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMarkSensitiveChanged(boolean markSensitive) {
|
||||
statusMarkSensitive = markSensitive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContentWarningChanged(boolean hideText) {
|
||||
showContentWarning(hideText);
|
||||
}
|
||||
});
|
||||
fragment.show(getSupportFragmentManager(), null);
|
||||
}
|
||||
});
|
||||
|
||||
// These can only be added after everything affected by the media queue is initialized.
|
||||
if (savedMediaQueued != null) {
|
||||
|
@ -479,6 +439,55 @@ public class ComposeActivity extends BaseActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private void showComposeOptions() {
|
||||
ComposeOptionsFragment fragment = ComposeOptionsFragment.newInstance(
|
||||
statusVisibility, statusMarkSensitive, statusHideText,
|
||||
showMarkSensitive, inReplyToId != null,
|
||||
new ComposeOptionsFragment.Listener() {
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {}
|
||||
|
||||
@Override
|
||||
public void onVisibilityChanged(String visibility) {
|
||||
statusVisibility = visibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMarkSensitiveChanged(boolean markSensitive) {
|
||||
statusMarkSensitive = markSensitive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContentWarningChanged(boolean hideText) {
|
||||
showContentWarning(hideText);
|
||||
}
|
||||
});
|
||||
fragment.show(getSupportFragmentManager(), null);
|
||||
}
|
||||
|
||||
private void sendStatus() {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
ArrayList<SavedQueuedMedia> savedMediaQueued = new ArrayList<>();
|
||||
|
@ -530,7 +539,7 @@ public class ComposeActivity extends BaseActivity {
|
|||
} else {
|
||||
mimeTypes = Arrays.copyOf(contentMimeTypes, contentMimeTypes.length);
|
||||
}
|
||||
EditText editText = new EditText(this) {
|
||||
EditText editText = new android.support.v7.widget.AppCompatEditText(this) {
|
||||
@Override
|
||||
public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
|
||||
final InputConnection ic = super.onCreateInputConnection(editorInfo);
|
||||
|
@ -783,15 +792,24 @@ public class ComposeActivity extends BaseActivity {
|
|||
}
|
||||
|
||||
private void enableMediaPicking() {
|
||||
mediaPick.setEnabled(true);
|
||||
ThemeUtils.setImageViewTint(mediaPick, R.attr.compose_media_button_tint);
|
||||
mediaPick.setImageResource(R.drawable.ic_media);
|
||||
mediaPickEnabled = true;
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
private void disableMediaPicking() {
|
||||
mediaPick.setEnabled(false);
|
||||
ThemeUtils.setImageViewTint(mediaPick, R.attr.compose_media_button_disabled_tint);
|
||||
mediaPick.setImageResource(R.drawable.ic_media_disabled);
|
||||
mediaPickEnabled = false;
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
@ -1103,4 +1121,32 @@ public class ComposeActivity extends BaseActivity {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="@color/toolbar_icon_dark"
|
||||
android:pathData="M16.5,6v11.5c0,2.21 -1.79,4 -4,4s-4,-1.79 -4,-4V5c0,-1.38 1.12,-2.5 2.5,-2.5s2.5,1.12 2.5,2.5v10.5c0,0.55 -0.45,1 -1,1s-1,-0.45 -1,-1V6H10v9.5c0,1.38 1.12,2.5 2.5,2.5s2.5,-1.12 2.5,-2.5V5c0,-2.21 -1.79,-4 -4,-4S7,2.79 7,5v12.5c0,3.04 2.46,5.5 5.5,5.5s5.5,-2.46 5.5,-5.5V6h-1.5z"/>
|
||||
</vector>
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="@color/toolbar_icon_dark"
|
||||
android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z"/>
|
||||
</vector>
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="@color/toolbar_icon_dark"
|
||||
android:pathData="M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z"/>
|
||||
</vector>
|
|
@ -1,95 +1,92 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/activity_compose"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageButton
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
app:srcCompat="@drawable/ic_media"
|
||||
style="?attr/image_button_style"
|
||||
android:id="@+id/compose_photo_pick"
|
||||
android:layout_marginLeft="8dp" />
|
||||
|
||||
<ImageButton
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:id="@+id/compose_options"
|
||||
app:srcCompat="@drawable/ic_options"
|
||||
style="?attr/image_button_style"
|
||||
android:layout_marginLeft="8dp" />
|
||||
|
||||
</LinearLayout>
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/compose_content_warning_bar"
|
||||
android:layout_margin="8dp"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp">
|
||||
|
||||
<EditText
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:ems="10"
|
||||
android:id="@+id/field_content_warning"
|
||||
android:hint="@string/hint_content_warning" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:id="@+id/compose_edit_area">
|
||||
|
||||
<!--An special EditText is created at runtime here, because it has to be a modified
|
||||
* anonymous class to support image/GIF picking from the soft keyboard.-->
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:elevation="4dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:background="?attr/toolbar_background_color" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:id="@+id/compose_media_preview_bar"
|
||||
android:layout_alignParentBottom="true">
|
||||
|
||||
<!--This is filled at runtime with ImageView's for each preview in the upload queue.-->
|
||||
android:id="@+id/compose_content_warning_bar"
|
||||
android:paddingTop="0dp"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:layout_marginBottom="4dp">
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<EditText
|
||||
android:id="@+id/field_content_warning"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:hint="@string/hint_content_warning"
|
||||
android:inputType="text" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:id="@+id/compose_edit_area">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<!--An special EditText is created at runtime here, because it has to be a modified
|
||||
* anonymous class to support image/GIF picking from the soft keyboard.-->
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:id="@+id/compose_media_preview_bar"
|
||||
android:layout_alignParentBottom="true">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/characters_left"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="500" />
|
||||
<!--This is filled at runtime with ImageView's for each preview in the upload queue.-->
|
||||
|
||||
<Button
|
||||
android:text="@string/action_send"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/button_send" />
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/characters_left"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:text="500" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/floating_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="16dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:srcCompat="@drawable/ic_send_24dp"/>
|
||||
|
||||
</FrameLayout>
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item android:id="@+id/compose_photo_pick"
|
||||
android:title="@string/action_photo_pick"
|
||||
android:icon="@drawable/ic_attach_file_24dp"
|
||||
app:showAsAction="always"/>
|
||||
<item android:id="@+id/compose_options"
|
||||
android:title="@string/action_compose_options"
|
||||
android:icon="@drawable/ic_visibility_24dp"
|
||||
app:showAsAction="always"/>
|
||||
</menu>
|
|
@ -121,8 +121,8 @@
|
|||
<string name="confirmation_reported">Sent!</string>
|
||||
|
||||
<string name="hint_domain">Which Site?</string>
|
||||
<string name="hint_compose">What\'s Happening?</string>
|
||||
<string name="hint_content_warning">Beware, folks</string>
|
||||
<string name="hint_compose">What\'s happening?</string>
|
||||
<string name="hint_content_warning">Content warning</string>
|
||||
|
||||
<string name="link_no_account">No account?</string>
|
||||
|
||||
|
@ -152,5 +152,8 @@
|
|||
<string name="pref_title_notification_style_light">Notify with light</string>
|
||||
<string name="pref_title_appearance_settings">Appearance</string>
|
||||
<string name="pref_title_light_theme">Use The Light Theme</string>
|
||||
<string name="action_submit">Submit</string>
|
||||
<string name="action_photo_pick">Add media</string>
|
||||
<string name="action_compose_options">Privacy options</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue