Made compose form more material

This commit is contained in:
Eugen Rochko 2017-03-07 14:09:33 +01:00
parent ce04c7ab2b
commit d067c8bf27
7 changed files with 236 additions and 151 deletions

View File

@ -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,47 +426,20 @@ 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() {
@Override
public void onClick(View v) {
ComposeOptionsFragment fragment = ComposeOptionsFragment.newInstance( ComposeOptionsFragment fragment = ComposeOptionsFragment.newInstance(
statusVisibility, statusMarkSensitive, statusHideText, statusVisibility, statusMarkSensitive, statusHideText,
showMarkSensitive, inReplyToId != null, showMarkSensitive, inReplyToId != null,
@ -469,13 +469,22 @@ public class ComposeActivity extends BaseActivity {
}); });
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);
}
} }

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -1,49 +1,42 @@
<?xml version="1.0" encoding="utf-8"?> <?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:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_compose" android:id="@+id/activity_compose"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<android.support.v7.widget.Toolbar
<LinearLayout android:id="@+id/toolbar"
android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="?attr/actionBarSize"
android:elevation="4dp"
<ImageButton android:layout_marginBottom="16dp"
android:layout_width="48dp" android:background="?attr/toolbar_background_color" />
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>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/compose_content_warning_bar" android:id="@+id/compose_content_warning_bar"
android:layout_margin="8dp" android:paddingTop="0dp"
android:paddingLeft="8dp" android:paddingLeft="16dp"
android:paddingRight="8dp"> android:paddingRight="16dp"
android:layout_marginBottom="4dp">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText <EditText
android:id="@+id/field_content_warning"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="text"
android:ems="10" android:ems="10"
android:id="@+id/field_content_warning" android:hint="@string/hint_content_warning"
android:hint="@string/hint_content_warning" /> android:inputType="text" />
</android.support.design.widget.TextInputLayout>
</LinearLayout> </LinearLayout>
@ -51,6 +44,9 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="1"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingBottom="16dp"
android:id="@+id/compose_edit_area"> android:id="@+id/compose_edit_area">
<!--An special EditText is created at runtime here, because it has to be a modified <!--An special EditText is created at runtime here, because it has to be a modified
@ -71,25 +67,26 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:paddingTop="4dp"
android:paddingLeft="16dp"
android:paddingBottom="16dp"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<TextView <TextView
android:id="@+id/characters_left" android:id="@+id/characters_left"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary"
android:text="500" /> android:text="500" />
</LinearLayout>
<Button
android:text="@string/action_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button_send" />
</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>

View File

@ -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>

View File

@ -121,8 +121,8 @@
<string name="confirmation_reported">Sent!</string> <string name="confirmation_reported">Sent!</string>
<string name="hint_domain">Which Site?</string> <string name="hint_domain">Which Site?</string>
<string name="hint_compose">What\'s Happening?</string> <string name="hint_compose">What\'s happening?</string>
<string name="hint_content_warning">Beware, folks</string> <string name="hint_content_warning">Content warning</string>
<string name="link_no_account">No account?</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_notification_style_light">Notify with light</string>
<string name="pref_title_appearance_settings">Appearance</string> <string name="pref_title_appearance_settings">Appearance</string>
<string name="pref_title_light_theme">Use The Light Theme</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> </resources>