Compose close dialog + focus fix (#539)

main
Ivan Kupalov 7 years ago committed by Konrad Pozniak
parent 6b8c334f96
commit 8aeaa23b55
  1. 75
      app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java
  2. 21
      app/src/main/res/layout/activity_compose.xml

@ -207,11 +207,11 @@ public final class ComposeActivity extends BaseActivity
// setup the account image // setup the account image
AccountEntity activeAccount = TuskyApplication.getAccountManager().getActiveAccount(); AccountEntity activeAccount = TuskyApplication.getAccountManager().getActiveAccount();
if(activeAccount != null) { if (activeAccount != null) {
ImageView composeAvatar = findViewById(R.id.composeAvatar); ImageView composeAvatar = findViewById(R.id.composeAvatar);
if(TextUtils.isEmpty(activeAccount.getProfilePictureUrl())) { if (TextUtils.isEmpty(activeAccount.getProfilePictureUrl())) {
composeAvatar.setImageResource(R.drawable.avatar_default); composeAvatar.setImageResource(R.drawable.avatar_default);
} else { } else {
Picasso.with(this).load(activeAccount.getProfilePictureUrl()) Picasso.with(this).load(activeAccount.getProfilePictureUrl())
@ -476,6 +476,7 @@ public final class ComposeActivity extends BaseActivity
} }
} }
textEditor.requestFocus();
} }
@Override @Override
@ -1058,7 +1059,7 @@ public final class ComposeActivity extends BaseActivity
private void onMediaPick() { private void onMediaPick() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) { != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE); PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
@ -1239,9 +1240,30 @@ public final class ComposeActivity extends BaseActivity
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
input.setText(item.description); input.setText(item.description);
DialogInterface.OnClickListener okListener = (dialog, which) -> {
mastodonApi.updateMedia(item.id, input.getText().toString())
.enqueue(new Callback<Attachment>() {
@Override
public void onResponse(@NonNull Call<Attachment> call, @NonNull Response<Attachment> response) {
Attachment attachment = response.body();
if (response.isSuccessful() && attachment != null) {
item.description = attachment.getDescription();
dialog.dismiss();
} else {
showFailedCaptionMessage();
}
}
@Override
public void onFailure(@NonNull Call<Attachment> call, @NonNull Throwable t) {
showFailedCaptionMessage();
}
});
};
AlertDialog dialog = new AlertDialog.Builder(this) AlertDialog dialog = new AlertDialog.Builder(this)
.setView(dialogLayout) .setView(dialogLayout)
.setPositiveButton(android.R.string.ok, null) .setPositiveButton(android.R.string.ok, okListener)
.setNegativeButton(android.R.string.cancel, null) .setNegativeButton(android.R.string.cancel, null)
.create(); .create();
@ -1252,26 +1274,6 @@ public final class ComposeActivity extends BaseActivity
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
} }
dialog.setOnShowListener(dialogInterface -> {
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(view -> mastodonApi.updateMedia(item.id,
input.getText().toString()).enqueue(new Callback<Attachment>() {
@Override
public void onResponse(@NonNull Call<Attachment> call, @NonNull Response<Attachment> response) {
Attachment attachment = response.body();
if (response.isSuccessful() && attachment != null) {
item.description = attachment.getDescription();
dialog.dismiss();
} else {
showFailedCaptionMessage();
}
}
@Override
public void onFailure(@NonNull Call<Attachment> call, @NonNull Throwable t) {
showFailedCaptionMessage();
}
}));
});
dialog.show(); dialog.show();
} }
@ -1547,15 +1549,34 @@ public final class ComposeActivity extends BaseActivity
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case android.R.id.home: { case android.R.id.home:
onBackPressed(); handleCloseButton();
return true; return true;
}
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@Override
public void onBackPressed() {
// Acting like a teen: deliberately ignoring parent.
handleCloseButton();
}
private void handleCloseButton() {
if (!TextUtils.isEmpty(textEditor.getText())
|| !TextUtils.isEmpty(contentWarningEditor.getText())
|| !mediaQueued.isEmpty()) {
new AlertDialog.Builder(this)
.setTitle("Close the toot without saving?")
.setPositiveButton(android.R.string.yes, (d, w) -> finish())
.setNegativeButton(android.R.string.no, null)
.show();
} else {
finish();
}
}
@Override @Override
public List<Account> searchAccounts(String mention) { public List<Account> searchAccounts(String mention) {
ArrayList<Account> resultList = new ArrayList<>(); ArrayList<Account> resultList = new ArrayList<>();

@ -17,31 +17,31 @@
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:background="@android:color/transparent"> android:background="@android:color/transparent">
<ImageView <ImageView
android:id="@+id/composeAvatar" android:id="@+id/composeAvatar"
android:padding="8dp"
android:layout_gravity="right|end"
android:layout_width="?attr/actionBarSize" android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
android:layout_gravity="right|end"
android:padding="8dp"
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
<!--content description will be set in code --> <!--content description will be set in code -->
</android.support.v7.widget.Toolbar> </android.support.v7.widget.Toolbar>
<TextView <TextView
android:textSize="?attr/status_text_small"
android:id="@+id/reply_tv" android:id="@+id/reply_tv"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="6dp" android:layout_marginBottom="6dp"
android:layout_marginLeft="16dp" android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:textSize="?attr/status_text_small"
android:textStyle="bold" android:textStyle="bold"
android:visibility="gone" android:visibility="gone"
tools:text="Reply to @username" tools:text="Reply to @username"
tools:visibility="visible" /> tools:visibility="visible" />
<TextView <TextView
android:textSize="?attr/status_text_small"
android:id="@+id/reply_content_tv" android:id="@+id/reply_content_tv"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -51,6 +51,7 @@
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingRight="16dp" android:paddingRight="16dp"
android:paddingTop="4dp" android:paddingTop="4dp"
android:textSize="?attr/status_text_small"
android:visibility="gone" android:visibility="gone"
tools:text="Post content which may be preeettyy long, so please, make sure there's enough room for everything, okay? Not kidding. I wish Eugen answered me more often, sigh." tools:text="Post content which may be preeettyy long, so please, make sure there's enough room for everything, okay? Not kidding. I wish Eugen answered me more often, sigh."
tools:visibility="visible" /> tools:visibility="visible" />
@ -63,7 +64,6 @@
android:orientation="vertical"> android:orientation="vertical">
<EditText <EditText
android:textSize="?attr/status_text_medium"
android:id="@+id/field_content_warning" 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"
@ -73,7 +73,8 @@
android:inputType="text|textCapSentences" android:inputType="text|textCapSentences"
android:maxLines="1" android:maxLines="1"
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingRight="16dp" /> android:paddingRight="16dp"
android:textSize="?attr/status_text_medium" />
<View <View
android:layout_width="match_parent" android:layout_width="match_parent"
@ -204,19 +205,19 @@
<TextView <TextView
android:id="@+id/characters_left" android:id="@+id/characters_left"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:textSize="?attr/status_text_medium"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary" /> android:textColor="?android:textColorPrimary"
android:textSize="?attr/status_text_medium" />
<Button <Button
android:id="@+id/floating_btn" android:id="@+id/floating_btn"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:textSize="?attr/status_text_medium"
android:background="@drawable/compose_button_colors" android:background="@drawable/compose_button_colors"
android:text="@string/action_send" android:text="@string/action_send"
android:textColor="@android:color/white" /> android:textColor="@android:color/white"
android:textSize="?attr/status_text_medium" />
</LinearLayout> </LinearLayout>

Loading…
Cancel
Save