mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2024-12-23 01:00:04 +02:00
Improve art timeline
This commit is contained in:
parent
539acd053b
commit
209d698223
3 changed files with 64 additions and 47 deletions
|
@ -48,6 +48,7 @@ import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.GridView;
|
import android.widget.GridView;
|
||||||
|
@ -62,6 +63,7 @@ import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.PopupMenu;
|
import androidx.appcompat.widget.PopupMenu;
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
import androidx.core.app.ActivityOptionsCompat;
|
import androidx.core.app.ActivityOptionsCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
@ -2113,6 +2115,35 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
StatusViewHolder holder = (StatusViewHolder) viewHolder;
|
StatusViewHolder holder = (StatusViewHolder) viewHolder;
|
||||||
MastodonHelper.loadPPMastodon(holder.bindingArt.artPp, status.account);
|
MastodonHelper.loadPPMastodon(holder.bindingArt.artPp, status.account);
|
||||||
if (status.art_attachment != null) {
|
if (status.art_attachment != null) {
|
||||||
|
|
||||||
|
holder.bindingArt.artMedia.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
|
@Override
|
||||||
|
public void onGlobalLayout() {
|
||||||
|
holder.bindingArt.artMedia.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||||
|
float viewWidth = holder.bindingArt.artMedia.getWidth();
|
||||||
|
ConstraintLayout.LayoutParams lp;
|
||||||
|
float mediaH = status.art_attachment.meta.small.height;
|
||||||
|
float mediaW = status.art_attachment.meta.small.width;
|
||||||
|
float ratio = 1.0f;
|
||||||
|
if (mediaW != 0) {
|
||||||
|
ratio = viewWidth / mediaW;
|
||||||
|
}
|
||||||
|
lp = new ConstraintLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, (int) (mediaH * ratio));
|
||||||
|
holder.bindingArt.artMedia.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||||
|
holder.bindingArt.artMedia.setLayoutParams(lp);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
float viewWidth = holder.bindingArt.artMedia.getWidth();
|
||||||
|
ConstraintLayout.LayoutParams lp;
|
||||||
|
float mediaH = status.art_attachment.meta.small.height;
|
||||||
|
float mediaW = status.art_attachment.meta.small.width;
|
||||||
|
float ratio = 1.0f;
|
||||||
|
if (mediaW != 0) {
|
||||||
|
ratio = viewWidth / mediaW;
|
||||||
|
}
|
||||||
|
lp = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, (int) (mediaH * ratio));
|
||||||
|
holder.bindingArt.artMedia.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||||
|
holder.bindingArt.artMedia.setLayoutParams(lp);
|
||||||
Glide.with(holder.bindingArt.artMedia.getContext())
|
Glide.with(holder.bindingArt.artMedia.getContext())
|
||||||
.load(status.art_attachment.preview_url)
|
.load(status.art_attachment.preview_url)
|
||||||
.apply(new RequestOptions().transform(new RoundedCorners((int) Helper.convertDpToPixel(3, context))))
|
.apply(new RequestOptions().transform(new RoundedCorners((int) Helper.convertDpToPixel(3, context))))
|
||||||
|
|
|
@ -342,19 +342,28 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
flagLoading = fetched_statuses.pagination.max_id == null;
|
flagLoading = fetched_statuses.pagination.max_id == null;
|
||||||
binding.noAction.setVisibility(View.GONE);
|
binding.noAction.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
|
||||||
if (timelineType == Timeline.TimeLineEnum.ART) {
|
if (timelineType == Timeline.TimeLineEnum.ART) {
|
||||||
//We have to split media in different statuses
|
//We have to split media in different statuses
|
||||||
List<Status> mediaStatuses = new ArrayList<>();
|
List<Status> mediaStatuses = new ArrayList<>();
|
||||||
for (Status status : fetched_statuses.statuses) {
|
for (Status status : fetched_statuses.statuses) {
|
||||||
if (status.media_attachments.size() > 1) {
|
if (!tagTimeline.isNSFW && status.sensitive) {
|
||||||
for (Attachment attachment : status.media_attachments) {
|
continue;
|
||||||
status.media_attachments = new ArrayList<>();
|
}
|
||||||
status.media_attachments.add(0, attachment);
|
for (Attachment attachment : status.media_attachments) {
|
||||||
mediaStatuses.add(status);
|
try {
|
||||||
|
Status statusTmp = (Status) status.clone();
|
||||||
|
statusTmp.art_attachment = attachment;
|
||||||
|
mediaStatuses.add(statusTmp);
|
||||||
|
} catch (CloneNotSupportedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fetched_statuses.statuses = mediaStatuses;
|
if (mediaStatuses.size() > 0) {
|
||||||
|
fetched_statuses.statuses = mediaStatuses;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//Update the timeline with new statuses
|
//Update the timeline with new statuses
|
||||||
int insertedStatus = updateStatusListWith(fetched_statuses.statuses);
|
int insertedStatus = updateStatusListWith(fetched_statuses.statuses);
|
||||||
|
@ -622,14 +631,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
}
|
}
|
||||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
||||||
boolean useCache = sharedpreferences.getBoolean(getString(R.string.SET_USE_CACHE), true);
|
boolean useCache = sharedpreferences.getBoolean(getString(R.string.SET_USE_CACHE), true);
|
||||||
/*Handler handler = new Handler();
|
|
||||||
handler.postDelayed(() -> {
|
|
||||||
if (useCache && direction != DIRECTION.SCROLL_TOP && direction != DIRECTION.FETCH_NEW) {
|
|
||||||
getCachedStatus(direction, fetchingMissing, timelineParams);
|
|
||||||
} else {
|
|
||||||
getLiveStatus(direction, fetchingMissing, timelineParams, status);
|
|
||||||
}
|
|
||||||
}, slug.compareTo(Helper.getSlugOfFirstFragment(requireActivity(), currentUserID, currentInstance)) == 0 ? 0 : 1000);*/
|
|
||||||
if (useCache && direction != DIRECTION.SCROLL_TOP && direction != DIRECTION.FETCH_NEW) {
|
if (useCache && direction != DIRECTION.SCROLL_TOP && direction != DIRECTION.FETCH_NEW) {
|
||||||
getCachedStatus(direction, fetchingMissing, timelineParams);
|
getCachedStatus(direction, fetchingMissing, timelineParams);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -14,47 +14,32 @@
|
||||||
You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||||
see <http://www.gnu.org/licenses>.
|
see <http://www.gnu.org/licenses>.
|
||||||
-->
|
-->
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/art_container"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<RelativeLayout
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
android:id="@+id/art_media"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
android:scaleType="fitCenter"
|
||||||
android:id="@+id/art_media"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
android:layout_width="match_parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
android:layout_height="wrap_content"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
android:adjustViewBounds="true"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
android:scaleType="centerInside" />
|
tools:src="@tools:sample/backgrounds/scenic" />
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:id="@+id/status_show_more"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_alignParentTop="true"
|
|
||||||
android:background="@color/mastodonC1"
|
|
||||||
android:visibility="gone">
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
|
||||||
android:id="@+id/show_more_button_art"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentStart="true"
|
|
||||||
android:layout_alignParentTop="true"
|
|
||||||
android:layout_marginStart="10dp"
|
|
||||||
android:layout_marginTop="10dp"
|
|
||||||
android:src="@drawable/ic_outline_remove_red_eye_24" />
|
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.LinearLayoutCompat
|
<androidx.appcompat.widget.LinearLayoutCompat
|
||||||
android:id="@+id/bottom_banner"
|
android:id="@+id/bottom_banner"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"
|
app:layout_constraintBottom_toBottomOf="@+id/art_media"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
android:background="#44000000"
|
android:background="#44000000"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:padding="10dp">
|
android:padding="10dp">
|
||||||
|
@ -88,4 +73,4 @@
|
||||||
android:textColor="@color/white" />
|
android:textColor="@color/white" />
|
||||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||||
</RelativeLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in a new issue