Cached intent for media

This commit is contained in:
Thomas 2024-01-12 10:36:29 +01:00
parent 09a8b6c43c
commit 504e30c44a
13 changed files with 188 additions and 160 deletions

View file

@ -500,7 +500,7 @@ public class ProfileActivity extends BaseActivity {
binding.accountPp.setOnClickListener(v -> {
Intent intent = new Intent(ProfileActivity.this, MediaActivity.class);
Bundle b = new Bundle();
Bundle args = new Bundle();
Attachment attachment = new Attachment();
attachment.description = account.acct;
attachment.preview_url = account.avatar;
@ -509,14 +509,18 @@ public class ProfileActivity extends BaseActivity {
attachment.type = "image";
ArrayList<Attachment> attachments = new ArrayList<>();
attachments.add(attachment);
b.putSerializable(Helper.ARG_MEDIA_ARRAY, attachments);
b.putInt(Helper.ARG_MEDIA_POSITION, 1);
intent.putExtras(b);
args.putSerializable(Helper.ARG_MEDIA_ARRAY, attachments);
args.putInt(Helper.ARG_MEDIA_POSITION, 1);
new CachedBundle(ProfileActivity.this).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation(ProfileActivity.this, binding.accountPp, attachment.url);
// start the new activity
startActivity(intent, options.toBundle());
});
});
binding.accountFollow.setOnClickListener(v -> {

View file

@ -344,7 +344,7 @@ public class AdminAccountActivity extends BaseActivity {
MastodonHelper.loadPPMastodon(binding.accountPp, adminAccount.account);
binding.accountPp.setOnClickListener(v -> {
Intent intent = new Intent(AdminAccountActivity.this, MediaActivity.class);
Bundle b = new Bundle();
Bundle args = new Bundle();
Attachment attachment = new Attachment();
attachment.description = adminAccount.account.acct;
attachment.preview_url = adminAccount.account.avatar;
@ -353,14 +353,18 @@ public class AdminAccountActivity extends BaseActivity {
attachment.type = "image";
ArrayList<Attachment> attachments = new ArrayList<>();
attachments.add(attachment);
b.putSerializable(Helper.ARG_MEDIA_ARRAY, attachments);
b.putInt(Helper.ARG_MEDIA_POSITION, 1);
intent.putExtras(b);
args.putSerializable(Helper.ARG_MEDIA_ARRAY, attachments);
args.putInt(Helper.ARG_MEDIA_POSITION, 1);
new CachedBundle(AdminAccountActivity.this).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation(AdminAccountActivity.this, binding.accountPp, attachment.url);
// start the new activity
startActivity(intent, options.toBundle());
});
});
binding.accountDate.setText(Helper.shortDateToString(adminAccount.created_at));

View file

@ -357,7 +357,7 @@ public class AdminReportActivity extends BaseBarActivity {
MastodonHelper.loadPPMastodon(binding.accountPp, account);
binding.accountPp.setOnClickListener(v -> {
Intent intent = new Intent(AdminReportActivity.this, MediaActivity.class);
Bundle b = new Bundle();
Bundle args = new Bundle();
Attachment attachment = new Attachment();
attachment.description = account.acct;
attachment.preview_url = account.avatar;
@ -366,14 +366,17 @@ public class AdminReportActivity extends BaseBarActivity {
attachment.type = "image";
ArrayList<Attachment> attachments = new ArrayList<>();
attachments.add(attachment);
b.putSerializable(Helper.ARG_MEDIA_ARRAY, attachments);
b.putInt(Helper.ARG_MEDIA_POSITION, 1);
intent.putExtras(b);
args.putSerializable(Helper.ARG_MEDIA_ARRAY, attachments);
args.putInt(Helper.ARG_MEDIA_POSITION, 1);
new CachedBundle(AdminReportActivity.this).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
intent.putExtras(bundle);
ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation(AdminReportActivity.this, binding.accountPp, attachment.url);
// start the new activity
startActivity(intent, options.toBundle());
});
});
binding.accountDate.setText(Helper.shortDateToString(account.created_at));

View file

@ -118,6 +118,7 @@ import app.fedilab.android.mastodon.client.entities.api.Poll;
import app.fedilab.android.mastodon.client.entities.api.Status;
import app.fedilab.android.mastodon.client.entities.api.Tag;
import app.fedilab.android.mastodon.client.entities.app.BaseAccount;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.client.entities.app.CamelTag;
import app.fedilab.android.mastodon.client.entities.app.Languages;
import app.fedilab.android.mastodon.client.entities.app.Quotes;
@ -1366,15 +1367,19 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
}
drawerMediaListBinding.getRoot().setOnClickListener(v -> {
Intent mediaIntent = new Intent(context, MediaActivity.class);
Bundle b = new Bundle();
Bundle args = new Bundle();
ArrayList<Attachment> attachments = new ArrayList<>();
attachments.add(attachment);
b.putSerializable(Helper.ARG_MEDIA_ARRAY, attachments);
mediaIntent.putExtras(b);
args.putSerializable(Helper.ARG_MEDIA_ARRAY, attachments);
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
mediaIntent.putExtras(bundle);
ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation((Activity) context, drawerMediaListBinding.media, attachment.url);
context.startActivity(mediaIntent, options.toBundle());
});
});
holder.binding.simpleMedia.addView(drawerMediaListBinding.getRoot());
}

View file

@ -75,20 +75,21 @@ public class ImageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}
holder.binding.media.setOnClickListener(v -> {
Intent mediaIntent = new Intent(context, MediaActivity.class);
Bundle b = new Bundle();
b.putInt(Helper.ARG_MEDIA_POSITION, position + 1);
b.putBoolean(Helper.ARG_MEDIA_ARRAY_PROFILE, true);
mediaIntent.putExtras(b);
ActivityOptionsCompat options = null;
Bundle args = new Bundle();
args.putInt(Helper.ARG_MEDIA_POSITION, position + 1);
args.putBoolean(Helper.ARG_MEDIA_ARRAY_PROFILE, true);
if (attachment != null) {
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
mediaIntent.putExtras(bundle);
ActivityOptionsCompat options = null;
options = ActivityOptionsCompat
.makeSceneTransitionAnimation((Activity) context, holder.binding.media, attachment.url);
} else {
return;
}
// start the new activity
context.startActivity(mediaIntent, options.toBundle());
});
}
});
holder.binding.media.setOnLongClickListener(v -> {
Intent intentContext = new Intent(context, ContextActivity.class);

View file

@ -14,6 +14,8 @@ package app.fedilab.android.mastodon.ui.drawer;
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
@ -38,6 +40,7 @@ import app.fedilab.android.databinding.DrawerSliderBinding;
import app.fedilab.android.mastodon.activities.MediaActivity;
import app.fedilab.android.mastodon.client.entities.api.Attachment;
import app.fedilab.android.mastodon.client.entities.api.Status;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.helper.Helper;
import jp.wasabeef.glide.transformations.BlurTransformation;
@ -102,14 +105,17 @@ public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapter
}
} else {
Intent mediaIntent = new Intent(context, MediaActivity.class);
Bundle b = new Bundle();
b.putInt(Helper.ARG_MEDIA_POSITION, position + 1);
b.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(status.media_attachments));
mediaIntent.putExtras(b);
Bundle args = new Bundle();
args.putInt(Helper.ARG_MEDIA_POSITION, position + 1);
args.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(status.media_attachments));
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
mediaIntent.putExtras(bundle);
ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation((Activity) context, viewHolder.binding.ivAutoImageSlider, status.media_attachments.get(0).url);
// start the new activity
context.startActivity(mediaIntent, options.toBundle());
});
}
});
}

View file

@ -1674,15 +1674,18 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
return;
}
Intent mediaIntent = new Intent(context, MediaActivity.class);
Bundle b = new Bundle();
b.putInt(Helper.ARG_MEDIA_POSITION, finalMediaPosition);
b.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(statusToDeal.media_attachments));
mediaIntent.putExtras(b);
Bundle args = new Bundle();
args.putInt(Helper.ARG_MEDIA_POSITION, finalMediaPosition);
args.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(statusToDeal.media_attachments));
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
mediaIntent.putExtras(bundle);
ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation((Activity) context, layoutMediaBinding.media, statusToDeal.media_attachments.get(0).url);
// start the new activity
context.startActivity(mediaIntent, options.toBundle());
});
});
layoutMediaBinding.viewHide.setOnClickListener(v -> {
statusToDeal.sensitive = !statusToDeal.sensitive;
adapter.notifyItemChanged(holder.getBindingAdapterPosition());
@ -1742,15 +1745,18 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
return;
}
Intent mediaIntent = new Intent(context, MediaActivity.class);
Bundle b = new Bundle();
b.putInt(Helper.ARG_MEDIA_POSITION, finalMediaPosition);
b.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(statusToDeal.media_attachments));
mediaIntent.putExtras(b);
Bundle args = new Bundle();
args.putInt(Helper.ARG_MEDIA_POSITION, finalMediaPosition);
args.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(statusToDeal.media_attachments));
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
mediaIntent.putExtras(bundle);
ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation((Activity) context, layoutMediaBinding.media, statusToDeal.media_attachments.get(0).url);
// start the new activity
context.startActivity(mediaIntent, options.toBundle());
});
});
layoutMediaBinding.viewHide.setOnClickListener(v -> {
statusToDeal.sensitive = !statusToDeal.sensitive;
adapter.notifyItemChanged(holder.getBindingAdapterPosition());
@ -2782,15 +2788,18 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
return;
}
Intent mediaIntent = new Intent(context, MediaActivity.class);
Bundle b = new Bundle();
b.putInt(Helper.ARG_MEDIA_POSITION, mediaPosition);
b.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(statusToDeal.media_attachments));
mediaIntent.putExtras(b);
Bundle args = new Bundle();
args.putInt(Helper.ARG_MEDIA_POSITION, mediaPosition);
args.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(statusToDeal.media_attachments));
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
mediaIntent.putExtras(bundle);
ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation((Activity) context, layoutMediaBinding.media, statusToDeal.media_attachments.get(0).url);
// start the new activity
context.startActivity(mediaIntent, options.toBundle());
});
});
layoutMediaBinding.viewHide.setOnClickListener(v -> {
statusToDeal.sensitive = !statusToDeal.sensitive;
adapter.notifyItemChanged(holder.getBindingAdapterPosition());
@ -3251,15 +3260,19 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.bindingArt.artMedia.setOnClickListener(v -> {
if (status.art_attachment != null) {
Intent mediaIntent = new Intent(context, MediaActivity.class);
Bundle b = new Bundle();
b.putInt(Helper.ARG_MEDIA_POSITION, 1);
Bundle args = new Bundle();
args.putInt(Helper.ARG_MEDIA_POSITION, 1);
ArrayList<Attachment> attachments = new ArrayList<>();
attachments.add(status.art_attachment);
b.putSerializable(Helper.ARG_MEDIA_ARRAY, attachments);
mediaIntent.putExtras(b);
args.putSerializable(Helper.ARG_MEDIA_ARRAY, attachments);
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
mediaIntent.putExtras(bundle);
ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation((Activity) context, holder.bindingArt.artMedia, status.art_attachment.url);
context.startActivity(mediaIntent, options.toBundle());
});
} else {
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}

View file

@ -15,6 +15,7 @@ package app.fedilab.android.mastodon.ui.drawer;
* see <http://www.gnu.org/licenses>. */
import static app.fedilab.android.BaseMainActivity.currentAccount;
import static app.fedilab.android.mastodon.ui.drawer.StatusAdapter.prepareRequestBuilder;
import android.app.Activity;
@ -77,6 +78,7 @@ import app.fedilab.android.mastodon.activities.MediaActivity;
import app.fedilab.android.mastodon.client.entities.api.Attachment;
import app.fedilab.android.mastodon.client.entities.api.Poll;
import app.fedilab.android.mastodon.client.entities.api.Status;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.helper.CacheDataSourceFactory;
import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.helper.LongClickLinkMovementMethod;
@ -191,15 +193,18 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
return;
}
Intent mediaIntent = new Intent(context, MediaActivity.class);
Bundle b = new Bundle();
b.putInt(Helper.ARG_MEDIA_POSITION, mediaPosition);
b.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(status.media_attachments));
mediaIntent.putExtras(b);
Bundle args = new Bundle();
args.putInt(Helper.ARG_MEDIA_POSITION, mediaPosition);
args.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(status.media_attachments));
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
mediaIntent.putExtras(bundle);
ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation((Activity) context, layoutMediaBinding.media, status.media_attachments.get(0).url);
// start the new activity
context.startActivity(mediaIntent, options.toBundle());
});
});
layoutMediaBinding.viewHide.setOnClickListener(v -> {
status.sensitive = !status.sensitive;
adapter.notifyItemChanged(holder.getBindingAdapterPosition());
@ -667,15 +672,18 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
return;
}
Intent mediaIntent = new Intent(context, MediaActivity.class);
Bundle b = new Bundle();
b.putInt(Helper.ARG_MEDIA_POSITION, finalMediaPosition);
b.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(status.media_attachments));
mediaIntent.putExtras(b);
Bundle args = new Bundle();
args.putInt(Helper.ARG_MEDIA_POSITION, finalMediaPosition);
args.putSerializable(Helper.ARG_MEDIA_ARRAY, new ArrayList<>(status.media_attachments));
new CachedBundle(context).insertBundle(args, currentAccount, bundleId -> {
Bundle bundle = new Bundle();
bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
mediaIntent.putExtras(bundle);
ActivityOptionsCompat options = ActivityOptionsCompat
.makeSceneTransitionAnimation((Activity) context, layoutMediaBinding.media, status.media_attachments.get(0).url);
// start the new activity
context.startActivity(mediaIntent, options.toBundle());
});
});
layoutMediaBinding.viewHide.setOnClickListener(v -> {
status.sensitive = !status.sensitive;
notifyItemChanged(holder.getBindingAdapterPosition());

View file

@ -95,7 +95,6 @@ public class FragmentMastodonAccount extends Fragment {
}
}
initializeAfterBundle(getArguments());
}
} else {
initializeAfterBundle(null);

View file

@ -382,7 +382,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
}
}
initializeAfterBundle(getArguments());
}
}
return binding.getRoot();

View file

@ -114,42 +114,42 @@ public class FragmentNotificationContainer extends Fragment {
String[] categoriesArray = excludedCategories.split("\\|");
for (String category : categoriesArray) {
switch (category) {
case "mention":
case "mention" -> {
excludedCategoriesList.add("mention");
dialogView.displayMentions.setChecked(false);
break;
case "favourite":
}
case "favourite" -> {
excludedCategoriesList.add("favourite");
dialogView.displayFavourites.setChecked(false);
break;
case "reblog":
}
case "reblog" -> {
excludedCategoriesList.add("reblog");
dialogView.displayReblogs.setChecked(false);
break;
case "poll":
}
case "poll" -> {
excludedCategoriesList.add("poll");
dialogView.displayPollResults.setChecked(false);
break;
case "status":
}
case "status" -> {
excludedCategoriesList.add("status");
dialogView.displayUpdatesFromPeople.setChecked(false);
break;
case "follow":
}
case "follow" -> {
excludedCategoriesList.add("follow");
dialogView.displayFollows.setChecked(false);
break;
case "update":
}
case "update" -> {
excludedCategoriesList.add("update");
dialogView.displayUpdates.setChecked(false);
break;
case "admin.sign_up":
}
case "admin.sign_up" -> {
excludedCategoriesList.add("admin.sign_up");
dialogView.displaySignups.setChecked(false);
break;
case "admin.report":
}
case "admin.report" -> {
excludedCategoriesList.add("admin.report");
dialogView.displayReports.setChecked(false);
break;
}
}
}
}

View file

@ -53,45 +53,33 @@ public class FedilabNotificationPageAdapter extends FragmentStatePagerAdapter {
FragmentMastodonNotification fragmentMastodonNotification = new FragmentMastodonNotification();
if (!extended) {
switch (position) {
case 0:
case 0 ->
bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.ALL);
break;
case 1:
case 1 ->
bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.MENTIONS);
break;
}
} else {
switch (position) {
case 0:
case 0 ->
bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.ALL);
break;
case 1:
case 1 ->
bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.MENTIONS);
break;
case 2:
case 2 ->
bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.FAVOURITES);
break;
case 3:
case 3 ->
bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.REBLOGS);
break;
case 4:
case 4 ->
bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.POLLS);
break;
case 5:
case 5 ->
bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.TOOTS);
break;
case 6:
case 6 ->
bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.FOLLOWS);
break;
case 7:
case 7 ->
bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.UPDATES);
break;
case 8:
case 8 ->
bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.ADMIN_SIGNUP);
break;
case 9:
case 9 ->
bundle.putSerializable(Helper.ARG_NOTIFICATION_TYPE, FragmentMastodonNotification.NotificationTypeEnum.ADMIN_REPORT);
break;
}
}
fragmentMastodonNotification.setArguments(bundle);

View file

@ -52,13 +52,11 @@ public class FedilabScheduledPageAdapter extends FragmentStatePagerAdapter {
bundle.putString(Helper.ARG_VIEW_MODEL_KEY, "FEDILAB_" + position);
FragmentScheduled fragmentScheduled = new FragmentScheduled();
switch (position) {
case 1:
case 1 ->
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.SCHEDULED_TOOT_CLIENT);
break;
case 2:
case 2 ->
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.SCHEDULED_BOOST);
break;
default:
default ->
bundle.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.SCHEDULED_TOOT_SERVER);
}
fragmentScheduled.setArguments(bundle);