Pixelfed view

maths
Thomas 2 years ago
parent c052e376e2
commit d77f1fc9f6

@ -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 <http://www.gnu.org/licenses>. */
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<SliderAdapter.SliderAdapterVH> {
private final Status status;
private final List<Attachment> 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;
}
}
}

@ -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<RecyclerView.ViewHolder>
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<Status> statusList;
private final boolean minified;
private final Timeline.TimeLineEnum timelineType;
@ -164,6 +168,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
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<RecyclerView.ViewHolder>
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<RecyclerView.ViewHolder>
}
}
} 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<RecyclerView.ViewHolder>
@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<RecyclerView.ViewHolder>
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<RecyclerView.ViewHolder>
DrawerStatusReportBinding bindingReport;
DrawerStatusNotificationBinding bindingNotification;
DrawerStatusArtBinding bindingArt;
DrawerStatusPixelfedBinding bindingPixelfed;
DrawerStatusFilteredBinding bindingFiltered;
DrawerStatusFilteredHideBinding bindingFilteredHide;
@ -2638,6 +2691,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
bindingArt = itemView;
}
StatusViewHolder(DrawerStatusPixelfedBinding itemView) {
super(itemView.getRoot());
bindingPixelfed = itemView;
}
StatusViewHolder(DrawerStatusFilteredBinding itemView) {
super(itemView.getRoot());
bindingFiltered = itemView;

@ -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();
}
}

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.AppCompatImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/iv_auto_image_slider"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
tools:src="@tools:sample/backgrounds/scenic" />

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2022 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 <http://www.gnu.org/licenses>.
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/art_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.smarteist.autoimageslider.SliderView
android:id="@+id/art_media"
android:layout_width="match_parent"
android:layout_height="300dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:sliderAnimationDuration="200"
app:sliderAutoCycleDirection="back_and_forth"
app:sliderAutoCycleEnabled="true"
app:sliderIndicatorAnimationDuration="200"
app:sliderIndicatorGravity="center_horizontal|top"
app:sliderIndicatorMargin="15dp"
app:sliderIndicatorOrientation="horizontal"
app:sliderIndicatorPadding="3dp"
app:sliderIndicatorRadius="2dp"
app:sliderIndicatorSelectedColor="?colorPrimary"
app:sliderIndicatorUnselectedColor="?colorControlNormal"
app:sliderScrollTimeInSec="1"
app:sliderStartAutoCycle="true" />
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/bottom_banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#44000000"
android:orientation="horizontal"
android:padding="10dp"
app:layout_constraintBottom_toBottomOf="@+id/art_media"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/art_pp"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center" />
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/art_author"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/art_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/art_acct"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white" />
</androidx.appcompat.widget.LinearLayoutCompat>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/comment_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:drawableStart="@drawable/ic_baseline_chat_bubble_24"
android:drawablePadding="5dp"
android:textSize="16sp"
tools:text="23" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.constraintlayout.widget.ConstraintLayout>

@ -1440,6 +1440,7 @@
<string name="SET_FILTER_REGEX_PUBLIC" translatable="false">SET_FILTER_REGEX_PUBLIC</string>
<string name="SET_NOTIF_VALIDATION" translatable="false">SET_NOTIF_VALIDATION</string>
<string name="SET_DISPLAY_BOOKMARK" translatable="false">SET_DISPLAY_BOOKMARK</string>
<string name="SET_PIXELFED_PRESENTATION" translatable="false">SET_PIXELFED_PRESENTATION</string>
<string name="SET_DISPLAY_QUOTES" translatable="false">SET_DISPLAY_QUOTES</string>
<string name="SET_DISPLAY_REACTIONS" translatable="false">SET_DISPLAY_REACTIONS</string>
@ -2199,4 +2200,5 @@
<string name="set_remote_profile">The app will display publicly profiles to get all messages. Interactions will need an extra step to federate messages.</string>
<string name="local_only">Local only</string>
<string name="set_display_local_only">Display \"Local only\" button</string>
<string name="set_pixelfed_presentation">Pixelfed presentation for media</string>
</resources>

@ -46,7 +46,12 @@
app:key="@string/SET_DISPLAY_BOOKMARK"
app:singleLineTitle="false"
app:title="@string/set_display_bookmark_indication" />
<SwitchPreferenceCompat
android:defaultValue="false"
app:iconSpaceReserved="false"
app:key="@string/SET_PIXELFED_PRESENTATION"
app:singleLineTitle="false"
app:title="@string/set_pixelfed_presentation" />
<SwitchPreferenceCompat
android:defaultValue="false"
app:iconSpaceReserved="false"

@ -2,11 +2,11 @@ apply plugin: 'com.android.library'
android {
compileSdkVersion 31
compileSdkVersion 33
defaultConfig {
minSdkVersion 15
targetSdkVersion 31
targetSdkVersion 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@ -29,9 +29,9 @@ configurations {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.appcompat:appcompat:1.5.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
}

Loading…
Cancel
Save