Swipe down to refresh is available in other activities.

This commit is contained in:
Alex Ning 2019-11-19 16:23:45 +08:00
parent 47b57fd50f
commit ca81ec49cf
13 changed files with 178 additions and 127 deletions

View File

@ -5,6 +5,7 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -22,12 +23,12 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@ -65,10 +66,10 @@ public class ViewMessageActivity extends BaseActivity {
AppBarLayout appBarLayout;
@BindView(R.id.toolbar_view_message_activity)
Toolbar toolbar;
@BindView(R.id.progress_bar_view_message_activity)
CircleProgressBar mProgressBar;
@BindView(R.id.swipe_refresh_layout_view_message_activity)
SwipeRefreshLayout mSwipeRefreshLayout;
@BindView(R.id.recycler_view_view_message_activity)
RecyclerView recyclerView;
RecyclerView mRecyclerView;
@BindView(R.id.fetch_messages_info_linear_layout_view_message_activity)
LinearLayout mFetchMessageInfoLinearLayout;
@BindView(R.id.fetch_messages_info_image_view_view_message_activity)
@ -146,7 +147,7 @@ public class ViewMessageActivity extends BaseActivity {
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) {
recyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
}
}
@ -211,10 +212,10 @@ public class ViewMessageActivity extends BaseActivity {
mAdapter = new MessageRecyclerViewAdapter(this, mOauthRetrofit, mAccessToken,
() -> mMessageViewModel.retryLoadingMore());
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(mAdapter);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setAdapter(mAdapter);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, layoutManager.getOrientation());
recyclerView.addItemDecoration(dividerItemDecoration);
mRecyclerView.addItemDecoration(dividerItemDecoration);
MessageViewModel.Factory factory = new MessageViewModel.Factory(mOauthRetrofit,
getResources().getConfiguration().locale, mAccessToken, FetchMessages.WHERE_INBOX);
@ -222,7 +223,7 @@ public class ViewMessageActivity extends BaseActivity {
mMessageViewModel.getMessages().observe(this, messages -> mAdapter.submitList(messages));
mMessageViewModel.hasMessage().observe(this, hasMessage -> {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
if (hasMessage) {
mFetchMessageInfoLinearLayout.setVisibility(View.GONE);
} else {
@ -235,9 +236,9 @@ public class ViewMessageActivity extends BaseActivity {
mMessageViewModel.getInitialLoadingState().observe(this, networkState -> {
if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
} else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
mFetchMessageInfoLinearLayout.setOnClickListener(view -> {
mFetchMessageInfoLinearLayout.setVisibility(View.GONE);
mMessageViewModel.refresh();
@ -245,17 +246,24 @@ public class ViewMessageActivity extends BaseActivity {
});
showErrorView(R.string.load_messages_failed);
} else {
mProgressBar.setVisibility(View.VISIBLE);
mSwipeRefreshLayout.setRefreshing(true);
}
});
mMessageViewModel.getPaginationNetworkState().observe(this, networkState -> {
mAdapter.setNetworkState(networkState);
});
mSwipeRefreshLayout.setOnRefreshListener(this::onRefresh);
TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true);
mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(typedValue.data);
mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent);
}
private void showErrorView(int stringResId) {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
mFetchMessageInfoLinearLayout.setVisibility(View.VISIBLE);
mFetchMessageInfoTextView.setText(stringResId);
mGlide.load(R.drawable.error_image).into(mFetchMessageInfoImageView);
@ -300,4 +308,8 @@ public class ViewMessageActivity extends BaseActivity {
finish();
}
}
private void onRefresh() {
mMessageViewModel.refresh();
}
}

View File

@ -6,6 +6,7 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
@ -15,7 +16,6 @@ import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
@ -26,6 +26,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSmoothScroller;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
@ -135,8 +136,8 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
AppBarLayout appBarLayout;
@BindView(R.id.toolbar_view_post_detail_activity)
Toolbar toolbar;
@BindView(R.id.progress_bar_view_post_detail_activity)
ProgressBar mProgressBar;
@BindView(R.id.swipe_refresh_layout_view_post_detail_activity)
SwipeRefreshLayout mSwipeRefreshLayout;
@BindView(R.id.recycler_view_view_post_detail)
RecyclerView mRecyclerView;
@BindView(R.id.fetch_post_info_linear_layout_view_post_detail_activity)
@ -311,6 +312,13 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
});
}
mSwipeRefreshLayout.setOnRefreshListener(() -> refresh(true, true));
TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true);
mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(typedValue.data);
mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent);
mSmoothScroller = new LinearSmoothScroller(this) {
@Override
protected int getVerticalSnapPreference() {
@ -510,7 +518,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
private void fetchPostAndCommentsById(String subredditId) {
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE);
mSwipeRefreshLayout.setRefreshing(true);
mGlide.clear(mFetchPostInfoImageView);
String sortType = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, SortType.Type.BEST.value).toLowerCase();
@ -537,7 +545,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
postAndComments.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
if (response.isSuccessful()) {
ParsePost.parsePost(response.body(), mLocale, new ParsePost.ParsePostListener() {
@ -860,6 +868,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mMenu.findItem(R.id.action_view_crosspost_parent_view_post_detail_activity).setVisible(mPost.getCrosspostParentId() != null);
}
mSwipeRefreshLayout.setRefreshing(false);
}
@Override
@ -873,7 +882,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
}
private void showErrorView(String subredditId) {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
mFetchPostInfoLinearLayout.setVisibility(View.VISIBLE);
mFetchPostInfoLinearLayout.setOnClickListener(view -> fetchPostAndCommentsById(subredditId));
mFetchPostInfoTextView.setText(R.string.load_post_error);

View File

@ -8,6 +8,7 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -21,10 +22,10 @@ import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
import javax.inject.Inject;
import javax.inject.Named;
@ -39,8 +40,8 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
@ -59,10 +60,10 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
@BindView(R.id.coordinator_layout_comments_listing_fragment)
CoordinatorLayout mCoordinatorLayout;
@BindView(R.id.swipe_refresh_layout_view_comments_listing_fragment)
SwipeRefreshLayout mSwipeRefreshLayout;
@BindView(R.id.recycler_view_comments_listing_fragment)
RecyclerView mCommentRecyclerView;
@BindView(R.id.progress_bar_comments_listing_fragment)
CircleProgressBar mProgressBar;
@BindView(R.id.fetch_comments_info_linear_layout_comments_listing_fragment)
LinearLayout mFetchCommentInfoLinearLayout;
@BindView(R.id.fetch_comments_info_image_view_comments_listing_fragment)
@ -179,7 +180,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
mCommentViewModel.getComments().observe(this, comments -> mAdapter.submitList(comments));
mCommentViewModel.hasComment().observe(this, hasComment -> {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
if (hasComment) {
mFetchCommentInfoLinearLayout.setVisibility(View.GONE);
} else {
@ -192,17 +193,24 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
mCommentViewModel.getInitialLoadingState().observe(this, networkState -> {
if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
} else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
mFetchCommentInfoLinearLayout.setOnClickListener(view -> refresh());
showErrorView(R.string.load_comments_failed);
} else {
mProgressBar.setVisibility(View.VISIBLE);
mSwipeRefreshLayout.setRefreshing(true);
}
});
mCommentViewModel.getPaginationNetworkState().observe(this, networkState -> mAdapter.setNetworkState(networkState));
mSwipeRefreshLayout.setOnRefreshListener(() -> mCommentViewModel.refresh());
TypedValue typedValue = new TypedValue();
mActivity.getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true);
mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(typedValue.data);
mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent);
}
public void changeSortType(SortType sortType) {
@ -231,7 +239,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
private void showErrorView(int stringResId) {
if (mActivity != null && isAdded()) {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
mFetchCommentInfoLinearLayout.setVisibility(View.VISIBLE);
mFetchCommentInfoTextView.setText(stringResId);
mGlide.load(R.drawable.error_image).into(mFetchCommentInfoImageView);

View File

@ -12,6 +12,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -25,6 +26,7 @@ import android.widget.Toast;
import androidx.annotation.DimenRes;
import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.paging.PagedList;
@ -233,6 +235,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mPostViewModel.refresh();
});
TypedValue typedValue = new TypedValue();
activity.getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true);
mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(typedValue.data);
mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent);
if (savedInstanceState != null) {

View File

@ -2,12 +2,14 @@ package ml.docilealligator.infinityforreddit.Fragment;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -21,9 +23,9 @@ import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.bumptech.glide.Glide;
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
import javax.inject.Inject;
import javax.inject.Named;
@ -38,9 +40,9 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SubredditListingViewModel;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
@ -58,8 +60,8 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
CoordinatorLayout mCoordinatorLayout;
@BindView(R.id.recycler_view_subreddit_listing_fragment)
RecyclerView mSubredditListingRecyclerView;
@BindView(R.id.progress_bar_subreddit_listing_fragment)
CircleProgressBar mProgressBar;
@BindView(R.id.swipe_refresh_layout_subreddit_listing_fragment)
SwipeRefreshLayout mSwipeRefreshLayout;
@BindView(R.id.fetch_subreddit_listing_info_linear_layout_subreddit_listing_fragment)
LinearLayout mFetchSubredditListingInfoLinearLayout;
@BindView(R.id.fetch_subreddit_listing_info_image_view_subreddit_listing_fragment)
@ -79,6 +81,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
SharedPreferences mSharedPreferences;
private LinearLayoutManager mLinearLayoutManager;
private SubredditListingRecyclerViewAdapter mAdapter;
private Activity mActivity;
public SubredditListingFragment() {
// Required empty public constructor
@ -91,9 +94,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_subreddit_listing, container, false);
Activity activity = getActivity();
((Infinity) activity.getApplication()).getAppComponent().inject(this);
((Infinity) mActivity.getApplication()).getAppComponent().inject(this);
ButterKnife.bind(this, rootView);
@ -119,7 +120,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT, SortType.Type.RELEVANCE.value);
SortType sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()));
mAdapter = new SubredditListingRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit,
mAdapter = new SubredditListingRecyclerViewAdapter(mActivity, mOauthRetrofit, mRetrofit,
accessToken, accountName, mRedditDataRoomDatabase,
new SubredditListingRecyclerViewAdapter.Callback() {
@Override
@ -130,11 +131,11 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
@Override
public void subredditSelected(String subredditName, String iconUrl) {
if (isPosting) {
((SearchSubredditsResultActivity) activity).getSelectedSubreddit(subredditName, iconUrl);
((SearchSubredditsResultActivity) mActivity).getSelectedSubreddit(subredditName, iconUrl);
} else {
Intent intent = new Intent(activity, ViewSubredditDetailActivity.class);
Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditName);
activity.startActivity(intent);
mActivity.startActivity(intent);
}
}
});
@ -146,7 +147,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
mSubredditListingViewModel.getSubreddits().observe(this, subredditData -> mAdapter.submitList(subredditData));
mSubredditListingViewModel.hasSubredditLiveData().observe(this, hasSubreddit -> {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
if (hasSubreddit) {
mFetchSubredditListingInfoLinearLayout.setVisibility(View.GONE);
} else {
@ -159,13 +160,13 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
mSubredditListingViewModel.getInitialLoadingState().observe(this, networkState -> {
if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
} else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
mFetchSubredditListingInfoLinearLayout.setOnClickListener(view -> refresh());
showErrorView(R.string.search_subreddits_error);
} else {
mProgressBar.setVisibility(View.VISIBLE);
mSwipeRefreshLayout.setRefreshing(true);
}
});
@ -173,12 +174,25 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
mAdapter.setNetworkState(networkState);
});
mSwipeRefreshLayout.setOnRefreshListener(() -> mSubredditListingViewModel.refresh());
TypedValue typedValue = new TypedValue();
mActivity.getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true);
mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(typedValue.data);
mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent);
return rootView;
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
mActivity = (Activity) context;
}
private void showErrorView(int stringResId) {
if (getActivity() != null && isAdded()) {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
mFetchSubredditListingInfoLinearLayout.setVisibility(View.VISIBLE);
mFetchSubredditListingInfoTextView.setText(stringResId);
Glide.with(this).load(R.drawable.error_image).into(mFetchSubredditListingInfoImageView);

View File

@ -1,11 +1,14 @@
package ml.docilealligator.infinityforreddit.Fragment;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -13,14 +16,15 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.bumptech.glide.Glide;
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
import javax.inject.Inject;
import javax.inject.Named;
@ -33,9 +37,9 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.UserListingViewModel;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
@ -52,8 +56,8 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
CoordinatorLayout mCoordinatorLayout;
@BindView(R.id.recycler_view_user_listing_fragment)
RecyclerView mUserListingRecyclerView;
@BindView(R.id.progress_bar_user_listing_fragment)
CircleProgressBar mProgressBar;
@BindView(R.id.swipe_refresh_layout_user_listing_fragment)
SwipeRefreshLayout mSwipeRefreshLayout;
@BindView(R.id.fetch_user_listing_info_linear_layout_user_listing_fragment)
LinearLayout mFetchUserListingInfoLinearLayout;
@BindView(R.id.fetch_user_listing_info_image_view_user_listing_fragment)
@ -74,6 +78,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
private LinearLayoutManager mLinearLayoutManager;
private String mQuery;
private UserListingRecyclerViewAdapter mAdapter;
private Activity mActivity;
public UserListingFragment() {
// Required empty public constructor
@ -86,7 +91,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_user_listing, container, false);
((Infinity) getActivity().getApplication()).getAppComponent().inject(this);
((Infinity) mActivity.getApplication()).getAppComponent().inject(this);
ButterKnife.bind(this, rootView);
@ -122,7 +127,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
mUserListingViewModel.getUsers().observe(this, UserData -> mAdapter.submitList(UserData));
mUserListingViewModel.hasUser().observe(this, hasUser -> {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
if (hasUser) {
mFetchUserListingInfoLinearLayout.setVisibility(View.GONE);
} else {
@ -135,13 +140,13 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
mUserListingViewModel.getInitialLoadingState().observe(this, networkState -> {
if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
} else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
mFetchUserListingInfoLinearLayout.setOnClickListener(view -> refresh());
showErrorView(R.string.search_users_error);
} else {
mProgressBar.setVisibility(View.VISIBLE);
mSwipeRefreshLayout.setRefreshing(true);
}
});
@ -149,12 +154,25 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
mAdapter.setNetworkState(networkState);
});
mSwipeRefreshLayout.setOnRefreshListener(() -> mUserListingViewModel.refresh());
TypedValue typedValue = new TypedValue();
mActivity.getTheme().resolveAttribute(R.attr.cardViewBackgroundColor, typedValue, true);
mSwipeRefreshLayout.setProgressBackgroundColorSchemeColor(typedValue.data);
mSwipeRefreshLayout.setColorSchemeResources(R.color.colorAccent);
return rootView;
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
mActivity = (Activity) context;
}
private void showErrorView(int stringResId) {
if (getActivity() != null && isAdded()) {
mProgressBar.setVisibility(View.GONE);
mSwipeRefreshLayout.setRefreshing(false);
mFetchUserListingInfoLinearLayout.setVisibility(View.VISIBLE);
mFetchUserListingInfoTextView.setText(stringResId);
Glide.with(this).load(R.drawable.error_image).into(mFetchUserListingInfoImageView);

View File

@ -38,16 +38,11 @@
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar
android:id="@+id/progress_bar_view_message_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:mlpb_progress_stoke_width="3dp"
app:mlpb_progress_color="@color/colorAccent"
app:mlpb_background_color="?attr/circularProgressBarBackground" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout_view_message_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_view_message_activity"
@ -55,6 +50,8 @@
android:layout_height="match_parent"
android:clipToPadding="false"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<LinearLayout
android:id="@+id/fetch_messages_info_linear_layout_view_message_activity"
android:layout_width="match_parent"

View File

@ -33,19 +33,19 @@
</com.google.android.material.appbar.AppBarLayout>
<ProgressBar
android:id="@+id/progress_bar_view_post_detail_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout_view_post_detail_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_view_post_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
android:clipToPadding="false" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<LinearLayout
android:id="@+id/fetch_post_info_linear_layout_view_post_detail_activity"

View File

@ -7,16 +7,10 @@
android:id="@+id/coordinator_layout_comments_listing_fragment"
tools:application="ml.docilealligator.infinityforreddit.Fragment.CommentsListingFragment">
<com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar
android:id="@+id/progress_bar_comments_listing_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:mlpb_progress_stoke_width="3dp"
app:mlpb_progress_color="@color/colorAccent"
app:mlpb_background_color="?attr/circularProgressBarBackground"
android:layout_gravity="center_horizontal"/>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout_view_comments_listing_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_comments_listing_fragment"
@ -24,6 +18,8 @@
android:layout_height="match_parent"
android:clipToPadding="false" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<LinearLayout
android:id="@+id/fetch_comments_info_linear_layout_comments_listing_fragment"
android:layout_width="match_parent"

View File

@ -8,8 +8,7 @@
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout_post_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundColor">
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_post_fragment"

View File

@ -7,16 +7,10 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:application=".SubredditListingFragment">
<com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar
android:id="@+id/progress_bar_subreddit_listing_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:mlpb_progress_stoke_width="3dp"
app:mlpb_progress_color="@color/colorAccent"
app:mlpb_background_color="?attr/circularProgressBarBackground"
android:layout_gravity="center_horizontal"/>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout_subreddit_listing_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_subreddit_listing_fragment"
@ -24,6 +18,8 @@
android:layout_height="match_parent"
android:clipToPadding="false" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<LinearLayout
android:id="@+id/fetch_subreddit_listing_info_linear_layout_subreddit_listing_fragment"
android:layout_width="match_parent"

View File

@ -7,16 +7,10 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:application=".UserListingFragment">
<com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar
android:id="@+id/progress_bar_user_listing_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:mlpb_progress_stoke_width="3dp"
app:mlpb_progress_color="@color/colorAccent"
app:mlpb_background_color="?attr/circularProgressBarBackground"
android:layout_gravity="center_horizontal"/>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout_user_listing_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_user_listing_fragment"
@ -24,6 +18,8 @@
android:layout_height="match_parent"
android:clipToPadding="false" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<LinearLayout
android:id="@+id/fetch_user_listing_info_linear_layout_user_listing_fragment"
android:layout_width="match_parent"

View File

@ -3,6 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="?attr/cardViewBackgroundColor"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout