Add stats to community "about" tab

This commit is contained in:
Balazs Toldi 2023-08-20 14:51:57 +02:00
parent 267570d7b4
commit ce7c284c6b
No known key found for this signature in database
GPG Key ID: 6C7D440036F99D58
2 changed files with 184 additions and 9 deletions

View File

@ -2,6 +2,7 @@ package eu.toldi.infinityforlemmy.fragments;
import android.content.Context;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@ -9,15 +10,19 @@ import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.evernote.android.state.State;
import java.util.concurrent.Executor;
import javax.inject.Inject;
@ -34,6 +39,7 @@ import eu.toldi.infinityforlemmy.activities.ViewSubredditDetailActivity;
import eu.toldi.infinityforlemmy.asynctasks.InsertSubredditData;
import eu.toldi.infinityforlemmy.bottomsheetfragments.CopyTextBottomSheetFragment;
import eu.toldi.infinityforlemmy.bottomsheetfragments.UrlMenuBottomSheetFragment;
import eu.toldi.infinityforlemmy.community.CommunityStats;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
@ -60,6 +66,27 @@ public class SidebarFragment extends Fragment {
SwipeRefreshLayout swipeRefreshLayout;
@BindView(R.id.markdown_recycler_view_sidebar_fragment)
RecyclerView recyclerView;
@BindView(R.id.subscriber_count_text_view_sidebar_fragment)
TextView nSubscribersTextView;
@BindView(R.id.active_user_count_text_view_sidebar_fragment)
TextView nActiveUsersTextView;
@BindView(R.id.post_count_text_view_sidebar_fragment)
TextView nPostsTextView;
@BindView(R.id.comment_count_text_view_sidebar_fragment)
TextView nCommentsTextView;
@BindView(R.id.subscriber_count_image_view_sidebar_fragment)
ImageView nSubscribersImageView;
@BindView(R.id.active_user_count_image_view_sidebar_fragment)
ImageView nActiveUsersImageView;
@BindView(R.id.post_count_image_view_sidebar_fragment)
ImageView nPostsImageView;
@BindView(R.id.comment_count_image_view_sidebar_fragment)
ImageView nCommentsImageView;
@BindView(R.id.community_statistics_block_sidebar_fragment)
ConstraintLayout communityStatisticsBlock;
@Inject
@Named("no_oauth")
RetrofitHolder mRetrofit;
@ -81,6 +108,9 @@ public class SidebarFragment extends Fragment {
private int markdownColor;
private String sidebarDescription;
@State
CommunityStats mCommunityStats;
public SidebarFragment() {
// Required empty public constructor
}
@ -105,6 +135,16 @@ public class SidebarFragment extends Fragment {
swipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground());
swipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent());
int primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
nSubscribersTextView.setTextColor(primaryTextColor);
nActiveUsersTextView.setTextColor(primaryTextColor);
nPostsTextView.setTextColor(primaryTextColor);
nCommentsTextView.setTextColor(primaryTextColor);
nSubscribersImageView.setColorFilter(mCustomThemeWrapper.getPrimaryTextColor(), PorterDuff.Mode.SRC_IN);
nActiveUsersImageView.setColorFilter(mCustomThemeWrapper.getPrimaryTextColor(), PorterDuff.Mode.SRC_IN);
nPostsImageView.setColorFilter(mCustomThemeWrapper.getPrimaryTextColor(), PorterDuff.Mode.SRC_IN);
nCommentsImageView.setColorFilter(mCustomThemeWrapper.getPrimaryTextColor(), PorterDuff.Mode.SRC_IN);
markdownColor = mCustomThemeWrapper.getPrimaryTextColor();
int spoilerBackgroundColor = markdownColor | 0xFF000000;
@ -180,6 +220,16 @@ public class SidebarFragment extends Fragment {
} else {
fetchSubredditData();
}
if (mCommunityStats != null) {
communityStatisticsBlock.setVisibility(View.VISIBLE);
nSubscribersTextView.setText(getString(R.string.subscribers_number_detail, mCommunityStats.getSubscribers()));
nActiveUsersTextView.setText(getString(R.string.active_users_number_detail, mCommunityStats.getActiveUsers()));
nPostsTextView.setText(getString(R.string.post_count_detail, mCommunityStats.getPosts()));
nCommentsTextView.setText(getString(R.string.comment_count_detail, mCommunityStats.getComments()));
} else {
fetchSubredditData();
}
});
swipeRefreshLayout.setOnRefreshListener(this::fetchSubredditData);
@ -199,6 +249,7 @@ public class SidebarFragment extends Fragment {
@Override
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
swipeRefreshLayout.setRefreshing(false);
mCommunityStats = subredditData.getCommunityStats();
InsertSubredditData.insertSubredditData(mExecutor, new Handler(), mRedditDataRoomDatabase,
subredditData, () -> swipeRefreshLayout.setRefreshing(false));
}

View File

@ -8,19 +8,143 @@
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout_sidebar_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
android:orientation="vertical">
<com.google.android.material.card.MaterialCardView
style="?attr/materialCardViewElevatedStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:cardCornerRadius="16dp"
app:cardElevation="2dp">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/markdown_recycler_view_sidebar_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="8dp"
android:paddingBottom="144dp"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingStart="8dp"
android:paddingTop="8dp"
android:paddingEnd="8dp"
android:clipToPadding="false" />
android:paddingBottom="144dp" />
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
style="?attr/materialCardViewElevatedStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:cardCornerRadius="16dp"
app:cardElevation="2dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/community_statistics_block_sidebar_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:visibility="gone"
android:layout_marginBottom="16dp">
<ImageView
android:id="@+id/subscriber_count_image_view_sidebar_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_person_24" />
<TextView
android:id="@+id/subscriber_count_text_view_sidebar_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="10dp"
android:text="@string/subscribers_number_detail"
app:layout_constraintStart_toEndOf="@+id/subscriber_count_image_view_sidebar_fragment"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5" />
<ImageView
android:id="@+id/active_user_count_image_view_sidebar_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="@+id/guideline7"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_bolt_24" />
<TextView
android:id="@+id/active_user_count_text_view_sidebar_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="10dp"
android:text="@string/active_users_number_detail"
app:layout_constraintStart_toEndOf="@+id/active_user_count_image_view_sidebar_fragment"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/post_count_image_view_sidebar_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/subscriber_count_image_view_sidebar_fragment"
app:srcCompat="@drawable/ic_post_add_24" />
<TextView
android:id="@+id/post_count_text_view_sidebar_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="18dp"
android:text="@string/post_count_detail"
app:layout_constraintStart_toEndOf="@+id/post_count_image_view_sidebar_fragment"
app:layout_constraintTop_toBottomOf="@+id/subscriber_count_image_view_sidebar_fragment" />
<ImageView
android:id="@+id/comment_count_image_view_sidebar_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
app:layout_constraintStart_toStartOf="@+id/guideline7"
app:layout_constraintTop_toBottomOf="@+id/active_user_count_image_view_sidebar_fragment"
app:srcCompat="@drawable/ic_comment_black_24" />
<TextView
android:id="@+id/comment_count_text_view_sidebar_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="18dp"
android:text="@string/comment_count_detail"
app:layout_constraintStart_toEndOf="@+id/comment_count_image_view_sidebar_fragment"
app:layout_constraintTop_toBottomOf="@+id/active_user_count_image_view_sidebar_fragment" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>