Consolidate the two media buttons in the composer.

This commit is contained in:
Vavassor 2017-07-27 22:40:58 -04:00
parent 368d8e5901
commit 239ebaf9b2
2 changed files with 38 additions and 40 deletions

View file

@ -51,6 +51,7 @@ import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider; import android.support.v4.content.FileProvider;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.content.res.AppCompatResources; import android.support.v7.content.res.AppCompatResources;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.Editable; import android.text.Editable;
@ -137,8 +138,7 @@ 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 takeBtn; private ImageButton pickButton;
private ImageButton pickBtn;
private ImageButton visibilityBtn; private ImageButton visibilityBtn;
private ImageButton saveButton; private ImageButton saveButton;
private ImageButton hideMediaToggle; private ImageButton hideMediaToggle;
@ -175,8 +175,7 @@ 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);
takeBtn = (ImageButton) findViewById(R.id.compose_photo_take); pickButton = (ImageButton) findViewById(R.id.compose_photo_pick);
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); saveButton = (ImageButton) findViewById(R.id.compose_save_draft);
hideMediaToggle = (ImageButton) findViewById(R.id.action_hide_media); hideMediaToggle = (ImageButton) findViewById(R.id.action_hide_media);
@ -208,16 +207,10 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
return saveDraft(); return saveDraft();
} }
}); });
takeBtn.setOnClickListener(new View.OnClickListener() { pickButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
initiateCameraApp(); openPickDialog();
}
});
pickBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onMediaPick();
} }
}); });
visibilityBtn.setOnClickListener(new View.OnClickListener() { visibilityBtn.setOnClickListener(new View.OnClickListener() {
@ -527,8 +520,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
} }
private void disableButtons() { private void disableButtons() {
takeBtn.setClickable(false); pickButton.setClickable(false);
pickBtn.setClickable(false);
visibilityBtn.setClickable(false); visibilityBtn.setClickable(false);
saveButton.setClickable(false); saveButton.setClickable(false);
hideMediaToggle.setClickable(false); hideMediaToggle.setClickable(false);
@ -536,8 +528,7 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
} }
private void enableButtons() { private void enableButtons() {
takeBtn.setClickable(true); pickButton.setClickable(true);
pickBtn.setClickable(true);
visibilityBtn.setClickable(true); visibilityBtn.setClickable(true);
saveButton.setClickable(true); saveButton.setClickable(true);
hideMediaToggle.setClickable(true); hideMediaToggle.setClickable(true);
@ -1039,6 +1030,33 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
setStateToNotReadying(); setStateToNotReadying();
} }
private void openPickDialog() {
final int CHOICE_TAKE = 0;
final int CHOICE_PICK = 1;
CharSequence[] choices = new CharSequence[2];
choices[CHOICE_TAKE] = getString(R.string.action_photo_take);
choices[CHOICE_PICK] = getString(R.string.action_photo_pick);
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case CHOICE_TAKE: {
initiateCameraApp();
break;
}
case CHOICE_PICK: {
onMediaPick();
break;
}
}
}
};
AlertDialog dialog = new AlertDialog.Builder(this)
.setItems(choices, listener)
.create();
dialog.show();
}
private void onMediaPick() { private void onMediaPick() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN &&
ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
@ -1123,20 +1141,14 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
} }
private void enableMediaButtons() { private void enableMediaButtons() {
pickBtn.setEnabled(true); pickButton.setEnabled(true);
ThemeUtils.setDrawableTint(this, pickBtn.getDrawable(), ThemeUtils.setDrawableTint(this, pickButton.getDrawable(),
R.attr.compose_media_button_tint);
takeBtn.setEnabled(true);
ThemeUtils.setDrawableTint(this, takeBtn.getDrawable(),
R.attr.compose_media_button_tint); R.attr.compose_media_button_tint);
} }
private void disableMediaButtons() { private void disableMediaButtons() {
pickBtn.setEnabled(false); pickButton.setEnabled(false);
ThemeUtils.setDrawableTint(this, pickBtn.getDrawable(), ThemeUtils.setDrawableTint(this, pickButton.getDrawable(),
R.attr.compose_media_button_disabled_tint);
takeBtn.setEnabled(false);
ThemeUtils.setDrawableTint(this, takeBtn.getDrawable(),
R.attr.compose_media_button_disabled_tint); R.attr.compose_media_button_disabled_tint);
} }

View file

@ -102,20 +102,6 @@
android:paddingRight="16dp" android:paddingRight="16dp"
android:paddingTop="4dp"> android:paddingTop="4dp">
<ImageButton
android:id="@+id/compose_photo_take"
style="?attr/image_button_style"
android:layout_width="40dp"
android:layout_height="40dp"
android:paddingStart="4dp"
android:paddingLeft="4dp"
android:paddingTop="4dp"
android:paddingEnd="4dp"
android:paddingRight="4dp"
android:paddingBottom="4dp"
app:srcCompat="@drawable/ic_camera_24dp"
android:contentDescription="@string/action_photo_take" />
<ImageButton <ImageButton
android:id="@+id/compose_photo_pick" android:id="@+id/compose_photo_pick"
style="?attr/image_button_style" style="?attr/image_button_style"