From 302b3e47d4b9c815c5a65e8cbf40488b840c0148 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 15 Aug 2023 16:58:31 +0200 Subject: [PATCH] More place for media description --- .../mastodon/activities/ComposeActivity.java | 45 +++++++++++++++- .../mastodon/ui/drawer/ComposeAdapter.java | 45 +++++----------- .../mastodon/layout/activity_pagination.xml | 51 +++++++++++++++++++ 3 files changed, 106 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java index 45904a8b2..342eb0671 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java @@ -33,12 +33,14 @@ import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.text.Editable; +import android.text.InputFilter; import android.text.TextWatcher; import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; +import android.view.WindowManager; import android.widget.LinearLayout; import android.widget.Toast; @@ -55,6 +57,7 @@ import androidx.work.OneTimeWorkRequest; import androidx.work.OutOfQuotaPolicy; import androidx.work.WorkManager; +import com.bumptech.glide.Glide; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import java.io.File; @@ -64,6 +67,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; +import java.util.Objects; import java.util.Set; import java.util.Timer; import java.util.TimerTask; @@ -99,7 +103,7 @@ import app.fedilab.android.mastodon.viewmodel.mastodon.AccountsVM; import app.fedilab.android.mastodon.viewmodel.mastodon.StatusesVM; import es.dmoral.toasty.Toasty; -public class ComposeActivity extends BaseActivity implements ComposeAdapter.ManageDrafts, AccountsReplyAdapter.ActionDone, ComposeAdapter.promptDraftListener { +public class ComposeActivity extends BaseActivity implements ComposeAdapter.ManageDrafts, AccountsReplyAdapter.ActionDone, ComposeAdapter.promptDraftListener, ComposeAdapter.MediaDescriptionCallBack { public static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 754; @@ -206,7 +210,9 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana @Override public void onBackPressed() { - storeDraftWarning(); + if (binding.recyclerView.getVisibility() == View.VISIBLE) { + storeDraftWarning(); + } } private void storeDraftWarning() { @@ -290,6 +296,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana statusList.add(initialStatus); statusList.add(statusDraft.statusDraftList.get(0)); composeAdapter = new ComposeAdapter(statusList, context.ancestors.size(), account, accountMention, visibility, editMessageId); + composeAdapter.mediaDescriptionCallBack = this; composeAdapter.promptDraftListener = this; composeAdapter.manageDrafts = this; LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this); @@ -617,6 +624,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana int statusCount = statusList.size(); statusList.addAll(statusDraft.statusDraftList); composeAdapter = new ComposeAdapter(statusList, statusCount, account, accountMention, visibility, editMessageId); + composeAdapter.mediaDescriptionCallBack = this; composeAdapter.manageDrafts = this; composeAdapter.promptDraftListener = this; LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this); @@ -689,6 +697,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana //StatusDraftList at this point should only have one element statusList.addAll(statusDraftList); composeAdapter = new ComposeAdapter(statusList, statusCount, account, accountMention, visibility, editMessageId); + composeAdapter.mediaDescriptionCallBack = this; composeAdapter.manageDrafts = this; composeAdapter.promptDraftListener = this; LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this); @@ -703,6 +712,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana //StatusDraftList at this point should only have one element statusList.addAll(statusDraftList); composeAdapter = new ComposeAdapter(statusList, statusCount, account, accountMention, visibility, editMessageId); + composeAdapter.mediaDescriptionCallBack = this; composeAdapter.manageDrafts = this; composeAdapter.promptDraftListener = this; LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this); @@ -712,6 +722,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana //Compose without replying statusList.addAll(statusDraftList); composeAdapter = new ComposeAdapter(statusList, 0, account, accountMention, visibility, editMessageId); + composeAdapter.mediaDescriptionCallBack = this; composeAdapter.manageDrafts = this; composeAdapter.promptDraftListener = this; LinearLayoutManager mLayoutManager = new LinearLayoutManager(ComposeActivity.this); @@ -1010,6 +1021,36 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana promptSaveDraft = true; } + @Override + public void click(ComposeAdapter.ComposeViewHolder holder, Attachment attachment, int messagePosition, int mediaPosition) { + binding.description.setVisibility(View.VISIBLE); + binding.recyclerView.setVisibility(View.GONE); + binding.mediaDescription.setText(""); + String attachmentPath = attachment.local_path != null && !attachment.local_path.trim().isEmpty() ? attachment.local_path : attachment.preview_url; + Glide.with(binding.mediaPreview.getContext()) + .load(attachmentPath) + .into(binding.mediaPreview); + if (attachment.description != null) { + binding.mediaDescription.setText(attachment.description); + binding.mediaDescription.setSelection(binding.mediaDescription.getText().length()); + } + binding.mediaDescription.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1500)}); + binding.mediaDescription.requestFocus(); + Objects.requireNonNull(getWindow()).setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); + binding.mediaDescription.requestFocus(); + + binding.mediaSave.setOnClickListener(v -> { + binding.description.setVisibility(View.GONE); + binding.recyclerView.setVisibility(View.VISIBLE); + composeAdapter.openDescriptionActivity(true, binding.mediaDescription.getText().toString().trim(), holder, attachment, messagePosition, mediaPosition); + }); + binding.mediaCancel.setOnClickListener(v -> { + binding.description.setVisibility(View.GONE); + binding.recyclerView.setVisibility(View.VISIBLE); + composeAdapter.openDescriptionActivity(false, binding.mediaDescription.getText().toString().trim(), holder, attachment, messagePosition, mediaPosition); + }); + } + public enum mediaType { PHOTO, diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java index 541242a01..65f73bd89 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java @@ -46,7 +46,6 @@ import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.WindowManager; import android.view.accessibility.AccessibilityEvent; import android.view.inputmethod.InputMethodManager; import android.widget.ArrayAdapter; @@ -69,7 +68,6 @@ import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; import com.bumptech.glide.load.engine.DiskCacheStrategy; -import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.bumptech.glide.request.RequestOptions; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.gson.Gson; @@ -91,7 +89,6 @@ import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; -import java.util.Objects; import java.util.Random; import java.util.Set; import java.util.regex.Matcher; @@ -105,7 +102,6 @@ import app.fedilab.android.databinding.ComposePollBinding; import app.fedilab.android.databinding.ComposePollItemBinding; import app.fedilab.android.databinding.DrawerStatusComposeBinding; import app.fedilab.android.databinding.DrawerStatusSimpleBinding; -import app.fedilab.android.databinding.PopupMediaDescriptionBinding; import app.fedilab.android.mastodon.activities.ComposeActivity; import app.fedilab.android.mastodon.client.entities.api.Account; import app.fedilab.android.mastodon.client.entities.api.Attachment; @@ -170,6 +166,8 @@ public class ComposeAdapter extends RecyclerView.Adapter statusList, int statusCount, BaseAccount account, Account mentionedAccount, String visibility, String editMessageId) { this.statusList = statusList; @@ -1146,7 +1144,7 @@ public class ComposeAdapter extends RecyclerView.Adapter openDescription(holder, attachment, position, finalMediaPosition)); + composeAttachmentItemBinding.buttonDescription.setOnClickListener(v -> mediaDescriptionCallBack.click(holder, attachment, position, finalMediaPosition)); composeAttachmentItemBinding.buttonOrderUp.setOnClickListener(v -> { if (finalMediaPosition > 0 && attachmentList.size() > 1) { @@ -1235,7 +1233,7 @@ public class ComposeAdapter extends RecyclerView.Adapter dialog.dismiss()); - if (attachment.description != null) { - popupMediaDescriptionBinding.mediaDescription.setText(attachment.description); - popupMediaDescriptionBinding.mediaDescription.setSelection(popupMediaDescriptionBinding.mediaDescription.getText().length()); - } - builderInner.setPositiveButton(R.string.validate, (dialog, which) -> { - attachment.description = popupMediaDescriptionBinding.mediaDescription.getText().toString(); + public void openDescriptionActivity(boolean saved, String content, ComposeViewHolder holder, Attachment attachment, int messagePosition, int mediaPosition) { + if (saved) { + attachment.description = content; displayAttachments(holder, messagePosition, mediaPosition); - dialog.dismiss(); - }); - AlertDialog alertDialog = builderInner.create(); - Objects.requireNonNull(alertDialog.getWindow()).setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); - alertDialog.show(); - popupMediaDescriptionBinding.mediaDescription.requestFocus(); + } + } + + public interface MediaDescriptionCallBack { + void click(ComposeViewHolder holder, Attachment attachment, int messagePosition, int mediaPosition); } /** diff --git a/app/src/main/res/layouts/mastodon/layout/activity_pagination.xml b/app/src/main/res/layouts/mastodon/layout/activity_pagination.xml index 535953b38..dda566c64 100644 --- a/app/src/main/res/layouts/mastodon/layout/activity_pagination.xml +++ b/app/src/main/res/layouts/mastodon/layout/activity_pagination.xml @@ -66,5 +66,56 @@ android:scrollbars="none" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> + + + + + + + + + + + + + + + + + \ No newline at end of file