diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/SliderAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/SliderAdapter.java new file mode 100644 index 00000000..de0975c4 --- /dev/null +++ b/app/src/main/java/app/fedilab/android/ui/drawer/SliderAdapter.java @@ -0,0 +1,97 @@ +package app.fedilab.android.ui.drawer; +/* Copyright 2023 Thomas Schneider + * + * This file is a part of Fedilab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Fedilab; if not, + * see . */ + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.ViewGroup; + +import androidx.core.app.ActivityOptionsCompat; + +import com.bumptech.glide.Glide; +import com.smarteist.autoimageslider.SliderViewAdapter; + +import java.util.ArrayList; +import java.util.List; + +import app.fedilab.android.activities.MediaActivity; +import app.fedilab.android.client.entities.api.Attachment; +import app.fedilab.android.client.entities.api.Status; +import app.fedilab.android.databinding.DrawerSliderBinding; +import app.fedilab.android.helper.Helper; + +public class SliderAdapter extends SliderViewAdapter { + + private final Status status; + private final List mSliderItems; + private Context context; + + public SliderAdapter(Status status) { + this.status = status; + this.mSliderItems = status.media_attachments; + } + + + public void addItem(Attachment sliderItem) { + this.mSliderItems.add(sliderItem); + notifyDataSetChanged(); + } + + @Override + public SliderAdapterVH onCreateViewHolder(ViewGroup parent) { + context = parent.getContext(); + DrawerSliderBinding itemBinding = DrawerSliderBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); + return new SliderAdapterVH(itemBinding); + } + + @Override + public void onBindViewHolder(SliderAdapterVH viewHolder, final int position) { + + Attachment sliderItem = mSliderItems.get(position); + + Glide.with(viewHolder.itemView) + .load(sliderItem.preview_url) + .centerCrop() + .into(viewHolder.binding.ivAutoImageSlider); + viewHolder.itemView.setOnClickListener(v -> { + 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); + ActivityOptionsCompat options = ActivityOptionsCompat + .makeSceneTransitionAnimation((Activity) context, viewHolder.binding.ivAutoImageSlider, status.media_attachments.get(0).url); + // start the new activity + context.startActivity(mediaIntent, options.toBundle()); + }); + } + + @Override + public int getCount() { + return mSliderItems.size(); + } + + static class SliderAdapterVH extends ViewHolder { + DrawerSliderBinding binding; + + SliderAdapterVH(DrawerSliderBinding itemView) { + super(itemView.getRoot()); + binding = itemView; + } + } +} diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index a7fc576c..37695146 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -87,6 +87,8 @@ import com.bumptech.glide.RequestBuilder; import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.bumptech.glide.request.RequestOptions; import com.github.stom79.mytransl.MyTransL; +import com.smarteist.autoimageslider.SliderAnimations; +import com.smarteist.autoimageslider.SliderView; import com.vanniktech.emoji.EmojiManager; import com.vanniktech.emoji.EmojiPopup; import com.vanniktech.emoji.one.EmojiOneProvider; @@ -128,6 +130,7 @@ import app.fedilab.android.databinding.DrawerStatusFilteredBinding; import app.fedilab.android.databinding.DrawerStatusFilteredHideBinding; import app.fedilab.android.databinding.DrawerStatusHiddenBinding; import app.fedilab.android.databinding.DrawerStatusNotificationBinding; +import app.fedilab.android.databinding.DrawerStatusPixelfedBinding; import app.fedilab.android.databinding.DrawerStatusReportBinding; import app.fedilab.android.databinding.LayoutMediaBinding; import app.fedilab.android.databinding.LayoutPollItemBinding; @@ -157,6 +160,7 @@ public class StatusAdapter extends RecyclerView.Adapter public static final int STATUS_ART = 2; public static final int STATUS_FILTERED = 3; public static final int STATUS_FILTERED_HIDE = 4; + public static final int STATUS_PIXELFED = 5; private final List statusList; private final boolean minified; private final Timeline.TimeLineEnum timelineType; @@ -164,6 +168,7 @@ public class StatusAdapter extends RecyclerView.Adapter private final boolean checkRemotely; public FetchMoreCallBack fetchMoreCallBack; private Context context; + private boolean visiblePixelfed; private RecyclerView mRecyclerView; @@ -188,6 +193,11 @@ public class StatusAdapter extends RecyclerView.Adapter return -1; } + + private static boolean isVisiblePixelfed(Status status) { + return status.media_attachments != null && status.media_attachments.size() > 0; + } + private static boolean isVisible(Timeline.TimeLineEnum timelineType, Status status) { if (timelineType == Timeline.TimeLineEnum.HOME && !show_boosts && status.reblog != null) { return false; @@ -2370,7 +2380,15 @@ public class StatusAdapter extends RecyclerView.Adapter } } } else { - return isVisible(timelineType, statusList.get(position)) ? STATUS_VISIBLE : STATUS_HIDDEN; + if (isVisible(timelineType, statusList.get(position))) { + if (visiblePixelfed && isVisiblePixelfed(statusList.get(position)) && timelineType != Timeline.TimeLineEnum.UNKNOWN) { + return STATUS_PIXELFED; + } else { + return STATUS_VISIBLE; + } + } else { + return STATUS_HIDDEN; + } } } @@ -2380,12 +2398,17 @@ public class StatusAdapter extends RecyclerView.Adapter @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { context = parent.getContext(); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); + visiblePixelfed = sharedpreferences.getBoolean(context.getString(R.string.SET_PIXELFED_PRESENTATION) + MainActivity.currentUserID + MainActivity.currentInstance, false); if (viewType == STATUS_HIDDEN) { //Hidden statuses - ie: filtered DrawerStatusHiddenBinding itemBinding = DrawerStatusHiddenBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); return new StatusViewHolder(itemBinding); } else if (viewType == STATUS_ART) { //Art statuses DrawerStatusArtBinding itemBinding = DrawerStatusArtBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); return new StatusViewHolder(itemBinding); + } else if (viewType == STATUS_PIXELFED) { //Art statuses + DrawerStatusPixelfedBinding itemBinding = DrawerStatusPixelfedBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); + return new StatusViewHolder(itemBinding); } else if (viewType == STATUS_FILTERED) { //Filtered warn DrawerStatusFilteredBinding itemBinding = DrawerStatusFilteredBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false); return new StatusViewHolder(itemBinding); @@ -2582,6 +2605,35 @@ public class StatusAdapter extends RecyclerView.Adapter intent.putExtra(Helper.ARG_STATUS, status); context.startActivity(intent); }); + } else if (viewHolder.getItemViewType() == STATUS_PIXELFED) { + StatusViewHolder holder = (StatusViewHolder) viewHolder; + MastodonHelper.loadPPMastodon(holder.bindingPixelfed.artPp, status.account); + SliderAdapter adapter = new SliderAdapter(status); + holder.bindingPixelfed.artMedia.setSliderAdapter(adapter); + holder.bindingPixelfed.artMedia.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION); + holder.bindingPixelfed.artMedia.setAutoCycleDirection(SliderView.AUTO_CYCLE_DIRECTION_BACK_AND_FORTH); + holder.bindingPixelfed.artMedia.setScrollTimeInSec(4); + holder.bindingPixelfed.artMedia.startAutoCycle(); + holder.bindingPixelfed.commentNumber.setText(String.valueOf(status.replies_count)); + holder.bindingPixelfed.artUsername.setText( + status.account.getSpanDisplayName(context, + new WeakReference<>(holder.bindingPixelfed.artUsername)), + TextView.BufferType.SPANNABLE); + holder.bindingPixelfed.artAcct.setText(String.format(Locale.getDefault(), "@%s", status.account.acct)); + holder.bindingPixelfed.artPp.setOnClickListener(v -> { + Intent intent = new Intent(context, ProfileActivity.class); + Bundle b = new Bundle(); + b.putSerializable(Helper.ARG_ACCOUNT, status.account); + intent.putExtras(b); + ActivityOptionsCompat options = ActivityOptionsCompat + .makeSceneTransitionAnimation((Activity) context, holder.bindingPixelfed.artPp, context.getString(R.string.activity_porfile_pp)); + context.startActivity(intent, options.toBundle()); + }); + holder.bindingPixelfed.bottomBanner.setOnClickListener(v -> { + Intent intent = new Intent(context, ContextActivity.class); + intent.putExtra(Helper.ARG_STATUS, status); + context.startActivity(intent); + }); } } @@ -2607,6 +2659,7 @@ public class StatusAdapter extends RecyclerView.Adapter DrawerStatusReportBinding bindingReport; DrawerStatusNotificationBinding bindingNotification; DrawerStatusArtBinding bindingArt; + DrawerStatusPixelfedBinding bindingPixelfed; DrawerStatusFilteredBinding bindingFiltered; DrawerStatusFilteredHideBinding bindingFilteredHide; @@ -2638,6 +2691,11 @@ public class StatusAdapter extends RecyclerView.Adapter bindingArt = itemView; } + StatusViewHolder(DrawerStatusPixelfedBinding itemView) { + super(itemView.getRoot()); + bindingPixelfed = itemView; + } + StatusViewHolder(DrawerStatusFilteredBinding itemView) { super(itemView.getRoot()); bindingFiltered = itemView; diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentTimelinesSettings.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentTimelinesSettings.java index 49867c7f..05606bc6 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentTimelinesSettings.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentTimelinesSettings.java @@ -73,6 +73,12 @@ public class FragmentTimelinesSettings extends PreferenceFragmentCompat implemen boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_DISPLAY_TRANSLATE) + MainActivity.currentUserID + MainActivity.currentInstance, false); SET_DISPLAY_TRANSLATE.setChecked(checked); } + + SwitchPreferenceCompat SET_PIXELFED_PRESENTATION = findPreference(getString(R.string.SET_PIXELFED_PRESENTATION)); + if (SET_PIXELFED_PRESENTATION != null) { + boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_PIXELFED_PRESENTATION) + MainActivity.currentUserID + MainActivity.currentInstance, false); + SET_PIXELFED_PRESENTATION.setChecked(checked); + } } @Override @@ -95,6 +101,12 @@ public class FragmentTimelinesSettings extends PreferenceFragmentCompat implemen editor.putBoolean(getString(R.string.SET_DISPLAY_TRANSLATE) + MainActivity.currentUserID + MainActivity.currentInstance, SET_DISPLAY_TRANSLATE.isChecked()); } } + if (key.compareToIgnoreCase(getString(R.string.SET_PIXELFED_PRESENTATION)) == 0) { + SwitchPreferenceCompat SET_PIXELFED_PRESENTATION = findPreference(getString(R.string.SET_PIXELFED_PRESENTATION)); + if (SET_PIXELFED_PRESENTATION != null) { + editor.putBoolean(getString(R.string.SET_PIXELFED_PRESENTATION) + MainActivity.currentUserID + MainActivity.currentInstance, SET_PIXELFED_PRESENTATION.isChecked()); + } + } editor.apply(); } } diff --git a/app/src/main/res/layout/drawer_slider.xml b/app/src/main/res/layout/drawer_slider.xml new file mode 100644 index 00000000..33f3f330 --- /dev/null +++ b/app/src/main/res/layout/drawer_slider.xml @@ -0,0 +1,8 @@ + + \ No newline at end of file diff --git a/app/src/main/res/layout/drawer_status_pixelfed.xml b/app/src/main/res/layout/drawer_status_pixelfed.xml new file mode 100644 index 00000000..317c14b3 --- /dev/null +++ b/app/src/main/res/layout/drawer_status_pixelfed.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 84aaab18..9068bf22 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1440,6 +1440,7 @@ SET_FILTER_REGEX_PUBLIC SET_NOTIF_VALIDATION SET_DISPLAY_BOOKMARK + SET_PIXELFED_PRESENTATION SET_DISPLAY_QUOTES SET_DISPLAY_REACTIONS @@ -2199,4 +2200,5 @@ The app will display publicly profiles to get all messages. Interactions will need an extra step to federate messages. Local only Display \"Local only\" button + Pixelfed presentation for media \ No newline at end of file diff --git a/app/src/main/res/xml/pref_timelines.xml b/app/src/main/res/xml/pref_timelines.xml index 34ea407f..f78ff5ad 100644 --- a/app/src/main/res/xml/pref_timelines.xml +++ b/app/src/main/res/xml/pref_timelines.xml @@ -46,7 +46,12 @@ app:key="@string/SET_DISPLAY_BOOKMARK" app:singleLineTitle="false" app:title="@string/set_display_bookmark_indication" /> - +