From 4d1aff63a89314982776a44d0837445b7e1732cf Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 16 Oct 2022 11:29:24 +0200 Subject: [PATCH] Fix issue #353 - Add a message that allows to open context when media are in fullscreen. --- .../android/activities/MediaActivity.java | 17 ++++++++++++++++ .../android/helper/PinnedTimelineHelper.java | 1 + .../android/ui/drawer/ImageAdapter.java | 1 + .../main/res/layout/activity_media_pager.xml | 20 +++++++++++++++++-- app/src/main/res/values/strings.xml | 1 + 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/MediaActivity.java b/app/src/main/java/app/fedilab/android/activities/MediaActivity.java index 02ee94a1..75b469cc 100644 --- a/app/src/main/java/app/fedilab/android/activities/MediaActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/MediaActivity.java @@ -58,6 +58,7 @@ import java.util.ArrayList; import app.fedilab.android.R; import app.fedilab.android.client.entities.api.Attachment; +import app.fedilab.android.client.entities.api.Status; import app.fedilab.android.databinding.ActivityMediaPagerBinding; import app.fedilab.android.helper.Helper; import app.fedilab.android.helper.MediaHelper; @@ -106,6 +107,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface { private float startY; private ActivityMediaPagerBinding binding; private FragmentMedia mCurrentFragment; + private Status status; @Override protected void onCreate(Bundle savedInstanceState) { @@ -123,6 +125,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface { if (b != null) { mediaPosition = b.getInt(Helper.ARG_MEDIA_POSITION, 1); attachments = (ArrayList) b.getSerializable(Helper.ARG_MEDIA_ARRAY); + status = (Status) b.getSerializable(Helper.ARG_STATUS); } if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -143,6 +146,14 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface { registerReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); String description = attachments.get(mediaPosition - 1).description; handler = new Handler(); + if (status != null) { + binding.originalMessage.setOnClickListener(v -> { + Intent intentContext = new Intent(MediaActivity.this, ContextActivity.class); + intentContext.putExtra(Helper.ARG_STATUS, status); + intentContext.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intentContext); + }); + } if (description != null && description.trim().length() > 0 && description.trim().compareTo("null") != 0) { binding.mediaDescription.setText(description); binding.translate.setOnClickListener(v -> { @@ -377,10 +388,12 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface { } } else { binding.translate.setVisibility(View.GONE); + binding.originalMessage.setVisibility(View.GONE); binding.mediaDescriptionTranslated.setVisibility(View.GONE); binding.mediaDescription.setVisibility(View.GONE); } } else { + binding.originalMessage.setVisibility(View.GONE); binding.translate.setVisibility(View.GONE); binding.mediaDescriptionTranslated.setVisibility(View.GONE); binding.mediaDescription.setVisibility(View.GONE); @@ -437,9 +450,13 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface { showSystemUI(); binding.mediaDescription.setVisibility(View.VISIBLE); binding.translate.setVisibility(View.VISIBLE); + if (status != null) { + binding.originalMessage.setVisibility(View.VISIBLE); + } } else { binding.mediaDescription.setVisibility(View.GONE); binding.translate.setVisibility(View.GONE); + binding.originalMessage.setVisibility(View.GONE); hideSystemUI(); } } diff --git a/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java b/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java index 3293a9c2..9c62ca9c 100644 --- a/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/PinnedTimelineHelper.java @@ -458,6 +458,7 @@ public class PinnedTimelineHelper { activityMainBinding.tabLayout.clearOnTabSelectedListeners(); FedilabPageAdapter fedilabPageAdapter = new FedilabPageAdapter(activity, activity.getSupportFragmentManager(), pinned, bottomMenu); activityMainBinding.viewPager.setAdapter(fedilabPageAdapter); + activityMainBinding.viewPager.setOffscreenPageLimit(tabStrip.getChildCount()); activityMainBinding.viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(activityMainBinding.tabLayout)); if (!singleBar) { activityMainBinding.viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ImageAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ImageAdapter.java index f4f8f270..1497f97d 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/ImageAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/ImageAdapter.java @@ -83,6 +83,7 @@ public class ImageAdapter extends RecyclerView.Adapter for (Status status1 : statuses) { attachmentsTmp.add(status1.art_attachment); } + b.putSerializable(Helper.ARG_STATUS, status); b.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(attachmentsTmp)); mediaIntent.putExtras(b); ActivityOptionsCompat options = ActivityOptionsCompat diff --git a/app/src/main/res/layout/activity_media_pager.xml b/app/src/main/res/layout/activity_media_pager.xml index 11821418..458fed4d 100644 --- a/app/src/main/res/layout/activity_media_pager.xml +++ b/app/src/main/res/layout/activity_media_pager.xml @@ -43,14 +43,13 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center_horizontal|bottom" - android:layout_marginBottom="70dp" android:background="#AA000000" android:gravity="center" android:padding="12dp" android:textColor="#ffffffff" android:textIsSelectable="true" android:visibility="gone" - app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintBottom_toTopOf="@+id/original_message" app:layout_constraintEnd_toStartOf="@+id/translate" app:layout_constraintStart_toStartOf="parent" tools:visibility="visible" /> @@ -85,6 +84,23 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/media_description" tools:visibility="visible" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 94b9396c..b74c404e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1478,4 +1478,5 @@ Fetch notifications Display counters Will display a bubble counter in tab timelines for new messages + Open the original message