From 5b164d60da480cb8bddb0355d5df649d748b8cde Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 17 Nov 2022 09:37:49 +0100 Subject: [PATCH] Fix issue #473 - Transparent background --- .../android/client/entities/app/Timeline.java | 2 + .../app/fedilab/android/helper/Helper.java | 2 + .../android/ui/drawer/InstanceRegAdapter.java | 40 +++++++++++-------- .../FragmentLoginPickInstanceMastodon.java | 23 +++++++++-- .../timeline/FragmentMastodonTimeline.java | 15 +++++++ .../main/res/layout/drawer_instance_reg.xml | 13 ++++++ app/src/main/res/values/strings.xml | 1 + 7 files changed, 77 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/client/entities/app/Timeline.java b/app/src/main/java/app/fedilab/android/client/entities/app/Timeline.java index a02a60ae..dc0aad32 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/app/Timeline.java +++ b/app/src/main/java/app/fedilab/android/client/entities/app/Timeline.java @@ -378,6 +378,8 @@ public class Timeline { TREND_TAG("TREND_TAG"), @SerializedName("TREND_MESSAGE") TREND_MESSAGE("TREND_MESSAGE"), + @SerializedName("PUBLIC_TREND_MESSAGE") + PUBLIC_TREND_MESSAGE("PUBLIC_TREND_MESSAGE"), @SerializedName("STATUS_HISTORY") STATUS_HISTORY("STATUS_HISTORY"), @SerializedName("ACCOUNT_TIMELINE") diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java index 7a71a73b..05352d7d 100644 --- a/app/src/main/java/app/fedilab/android/helper/Helper.java +++ b/app/src/main/java/app/fedilab/android/helper/Helper.java @@ -213,6 +213,8 @@ public class Helper { public static final String RECEIVE_REDRAW_PROFILE = "RECEIVE_REDRAW_PROFILE"; public static final String ARG_TIMELINE_TYPE = "ARG_TIMELINE_TYPE"; + public static final String ARG_REMOTE_INSTANCE_STRING = "ARG_REMOTE_INSTANCE_STRING"; + public static final String ARG_NOTIFICATION_TYPE = "ARG_NOTIFICATION_TYPE"; public static final String ARG_EXCLUDED_NOTIFICATION_TYPE = "ARG_EXCLUDED_NOTIFICATION_TYPE"; public static final String ARG_STATUS = "ARG_STATUS"; diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/InstanceRegAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/InstanceRegAdapter.java index e661a478..a88c24ad 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/InstanceRegAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/InstanceRegAdapter.java @@ -38,9 +38,28 @@ import app.fedilab.android.helper.Helper; public class InstanceRegAdapter extends RecyclerView.Adapter { private final List joinMastodonInstanceList; - public RecyclerViewClickListener itemListener; private Context context; - private ViewHolder holder; + public ActionClick actionClick; + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) { + JoinMastodonInstance joinMastodonInstance = joinMastodonInstanceList.get(position); + + ViewHolder holder = (ViewHolder) viewHolder; + holder.binding.instanceCountUser.setText(context.getString(R.string.users, Helper.withSuffix(joinMastodonInstance.total_users))); + holder.binding.instanceDescription.setText(joinMastodonInstance.description); + holder.binding.instanceHost.setText(joinMastodonInstance.domain); + holder.binding.instanceVersion.setText(String.format("%s - %s", joinMastodonInstance.categories, joinMastodonInstance.version)); + Glide.with(context) + .load(joinMastodonInstance.proxied_thumbnail) + .apply(new RequestOptions().transform(new FitCenter(), new RoundedCorners(10))) + .into(holder.binding.instancePp); + + holder.binding.getRoot().setOnClickListener(v -> actionClick.instance(position)); + + holder.binding.watchTrendig.setOnClickListener(v -> actionClick.trends(position)); + } + public InstanceRegAdapter(List joinMastodonInstanceList) { this.joinMastodonInstanceList = joinMastodonInstanceList; @@ -62,21 +81,10 @@ public class InstanceRegAdapter extends RecyclerView.Adapter itemListener.recyclerViewListClicked(v, position)); + void trends(int position); } public long getItemId(int position) { diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginPickInstanceMastodon.java b/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginPickInstanceMastodon.java index f4eaca56..8a4c7441 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginPickInstanceMastodon.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginPickInstanceMastodon.java @@ -31,12 +31,14 @@ import java.util.List; import app.fedilab.android.R; import app.fedilab.android.client.entities.api.JoinMastodonInstance; +import app.fedilab.android.client.entities.app.Timeline; import app.fedilab.android.databinding.FragmentLoginPickInstanceMastodonBinding; import app.fedilab.android.helper.Helper; import app.fedilab.android.ui.drawer.InstanceRegAdapter; +import app.fedilab.android.ui.fragment.timeline.FragmentMastodonTimeline; import app.fedilab.android.viewmodel.mastodon.JoinInstancesVM; -public class FragmentLoginPickInstanceMastodon extends Fragment implements InstanceRegAdapter.RecyclerViewClickListener { +public class FragmentLoginPickInstanceMastodon extends Fragment implements InstanceRegAdapter.ActionClick { private List joinMastodonInstanceList; @@ -94,7 +96,7 @@ public class FragmentLoginPickInstanceMastodon extends Fragment implements Insta joinMastodonInstanceList = instances; if (instances != null) { InstanceRegAdapter instanceRegAdapter = new InstanceRegAdapter(instances); - instanceRegAdapter.itemListener = currentFragment; + instanceRegAdapter.actionClick = currentFragment; LinearLayoutManager mLayoutManager = new LinearLayoutManager(requireActivity()); binding.regCategoryView.setLayoutManager(mLayoutManager); binding.regCategoryView.setNestedScrollingEnabled(false); @@ -122,7 +124,7 @@ public class FragmentLoginPickInstanceMastodon extends Fragment implements Insta @Override - public void recyclerViewListClicked(View v, int position) { + public void instance(int position) { if (joinMastodonInstanceList != null) { JoinMastodonInstance clickedInstance = joinMastodonInstanceList.get(position); Bundle args = new Bundle(); @@ -132,4 +134,19 @@ public class FragmentLoginPickInstanceMastodon extends Fragment implements Insta args, null, FragmentLoginRegisterMastodon.class.getName()); } } + + @Override + public void trends(int position) { + if (joinMastodonInstanceList != null) { + JoinMastodonInstance clickedInstance = joinMastodonInstanceList.get(position); + Bundle args = new Bundle(); + args.putBoolean(Helper.ARG_MINIFIED, true); + args.putSerializable(Helper.ARG_REMOTE_INSTANCE_STRING, clickedInstance.domain); + args.putSerializable(Helper.ARG_TIMELINE_TYPE, Timeline.TimeLineEnum.TREND_MESSAGE); + + Helper.addFragment( + getParentFragmentManager(), android.R.id.content, new FragmentMastodonTimeline(), + args, null, FragmentLoginRegisterMastodon.class.getName()); + } + } } \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index d2fa1322..9fe8c6e2 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -166,6 +166,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. private String slug; private boolean canBeFederated; private boolean rememberPosition; + private String publicTrendsDomain; //Allow to recreate data when detaching/attaching fragment public void recreate() { @@ -298,6 +299,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. canBeFederated = false; } } + publicTrendsDomain = getArguments().getString(Helper.ARG_REMOTE_INSTANCE_STRING, null); isViewInitialized = getArguments().getBoolean(Helper.ARG_INITIALIZE_VIEW, true); tagTimeline = (TagTimeline) getArguments().getSerializable(Helper.ARG_TAG_TIMELINE); accountTimeline = (Account) getArguments().getSerializable(Helper.ARG_ACCOUNT); @@ -986,6 +988,19 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. initializeStatusesCommonView(statuses); }); } + } else if (timelineType == Timeline.TimeLineEnum.PUBLIC_TREND_MESSAGE) { + if (direction == null) { + timelinesVM.getStatusTrends(null, publicTrendsDomain) + .observe(getViewLifecycleOwner(), statusesTrends -> { + Statuses statuses = new Statuses(); + statuses.statuses = new ArrayList<>(); + if (statusesTrends != null) { + statuses.statuses.addAll(statusesTrends); + } + statuses.pagination = new Pagination(); + initializeStatusesCommonView(statuses); + }); + } } } diff --git a/app/src/main/res/layout/drawer_instance_reg.xml b/app/src/main/res/layout/drawer_instance_reg.xml index be7ec8a0..2d508e28 100644 --- a/app/src/main/res/layout/drawer_instance_reg.xml +++ b/app/src/main/res/layout/drawer_instance_reg.xml @@ -82,6 +82,19 @@ app:layout_constraintTop_toBottomOf="@id/instance_pp" tools:text="General-purpose server run by the lead developer of Mastodon" /> + + \ 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 f6699542..7c2bb9ff 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1986,4 +1986,5 @@ Edit list Profiles Your instance does not seem to support that feature! + Watch trends for this instance