Favorite and unfavorite subscribed users are now available.

This commit is contained in:
Alex Ning 2019-10-10 17:09:29 +08:00
parent 77a31056b2
commit d82b1e6305
11 changed files with 395 additions and 69 deletions

View File

@ -252,6 +252,7 @@ public class SubscribedThingListingActivity extends BaseActivity {
FollowedUsersListingFragment fragment = new FollowedUsersListingFragment(); FollowedUsersListingFragment fragment = new FollowedUsersListingFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(FollowedUsersListingFragment.EXTRA_ACCOUNT_NAME, mAccountName); bundle.putString(FollowedUsersListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putString(FollowedUsersListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
fragment.setArguments(bundle); fragment.setArguments(bundle);
return fragment; return fragment;
} }

View File

@ -5,6 +5,7 @@ import android.content.Intent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -16,52 +17,243 @@ import com.bumptech.glide.request.RequestOptions;
import java.util.List; import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity;
import ml.docilealligator.infinityforreddit.FavoriteThing;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData; import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
import pl.droidsonroids.gif.GifImageView; import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int VIEW_TYPE_FAVORITE_USER_DIVIDER = 0;
private static final int VIEW_TYPE_FAVORITE_USER = 1;
private static final int VIEW_TYPE_USER_DIVIDER = 2;
private static final int VIEW_TYPE_USER = 3;
private List<SubscribedUserData> mSubscribedUserData; private List<SubscribedUserData> mSubscribedUserData;
private List<SubscribedUserData> mFavoriteSubscribedUserData;
private Context mContext; private Context mContext;
private Retrofit mOauthRetrofit;
private RedditDataRoomDatabase mRedditDataRoomDatabase;
private String mAccessToken;
private RequestManager glide; private RequestManager glide;
public FollowedUsersRecyclerViewAdapter(Context context) { public FollowedUsersRecyclerViewAdapter(Context context, Retrofit oauthRetrofit,
RedditDataRoomDatabase redditDataRoomDatabase,
String accessToken) {
mContext = context; mContext = context;
mOauthRetrofit = oauthRetrofit;
mRedditDataRoomDatabase = redditDataRoomDatabase;
mAccessToken = accessToken;
glide = Glide.with(context.getApplicationContext()); glide = Glide.with(context.getApplicationContext());
} }
@Override
public int getItemViewType(int position) {
if (mFavoriteSubscribedUserData != null && mFavoriteSubscribedUserData.size() > 0) {
if (position == 0) {
return VIEW_TYPE_FAVORITE_USER_DIVIDER;
} else if (position == mFavoriteSubscribedUserData.size() + 1) {
return VIEW_TYPE_USER_DIVIDER;
} else if (position <= mFavoriteSubscribedUserData.size()) {
return VIEW_TYPE_FAVORITE_USER;
} else {
return VIEW_TYPE_USER;
}
} else {
return VIEW_TYPE_USER;
}
}
@NonNull @NonNull
@Override @Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
return new UserViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_subscribed_thing, viewGroup, false)); switch (i) {
case VIEW_TYPE_FAVORITE_USER_DIVIDER:
return new FavoriteUsersDividerViewHolder(LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.item_favorite_thing_divider, viewGroup, false));
case VIEW_TYPE_FAVORITE_USER:
return new FavoriteUserViewHolder(LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.item_subscribed_thing, viewGroup, false));
case VIEW_TYPE_USER_DIVIDER:
return new AllUsersDividerViewHolder(LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.item_favorite_thing_divider, viewGroup, false));
default:
return new UserViewHolder(LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.item_subscribed_thing, viewGroup, false));
}
} }
@Override @Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int i) { public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int i) {
viewHolder.itemView.setOnClickListener(view -> { if (viewHolder instanceof UserViewHolder) {
Intent intent = new Intent(mContext, ViewUserDetailActivity.class); int offset = (mFavoriteSubscribedUserData != null && mFavoriteSubscribedUserData.size() > 0) ?
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mSubscribedUserData.get(viewHolder.getAdapterPosition()).getName()); mFavoriteSubscribedUserData.size() + 2 : 0;
mContext.startActivity(intent);
}); viewHolder.itemView.setOnClickListener(view -> {
if (!mSubscribedUserData.get(i).getIconUrl().equals("")) { Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
glide.load(mSubscribedUserData.get(i).getIconUrl()) intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mSubscribedUserData.get(viewHolder.getAdapterPosition() - offset).getName());
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) mContext.startActivity(intent);
.error(glide.load(R.drawable.subreddit_default_icon) });
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) if (!mSubscribedUserData.get(viewHolder.getAdapterPosition() - offset).getIconUrl().equals("")) {
.into(((UserViewHolder) viewHolder).iconGifImageView); glide.load(mSubscribedUserData.get(viewHolder.getAdapterPosition() - offset).getIconUrl())
} else { .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
glide.load(R.drawable.subreddit_default_icon) .error(glide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
.into(((UserViewHolder) viewHolder).iconGifImageView); .into(((UserViewHolder) viewHolder).iconGifImageView);
} else {
glide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.into(((UserViewHolder) viewHolder).iconGifImageView);
}
((UserViewHolder) viewHolder).userNameTextView.setText(mSubscribedUserData.get(viewHolder.getAdapterPosition() - offset).getName());
if(mSubscribedUserData.get(viewHolder.getAdapterPosition() - offset).isFavorite()) {
((UserViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
} else {
((UserViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
}
((UserViewHolder) viewHolder).favoriteImageView.setOnClickListener(view -> {
if(mSubscribedUserData.get(viewHolder.getAdapterPosition() - offset).isFavorite()) {
((UserViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
mSubscribedUserData.get(viewHolder.getAdapterPosition() - offset).setFavorite(false);
FavoriteThing.unfavoriteUser(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
mSubscribedUserData.get(viewHolder.getAdapterPosition() - offset),
new FavoriteThing.FavoriteThingListener() {
@Override
public void success() {
int position = viewHolder.getAdapterPosition() - offset;
if(position >= 0 && mFavoriteSubscribedUserData.size() > position) {
mFavoriteSubscribedUserData.get(position).setFavorite(false);
}
((UserViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
}
@Override
public void failed() {
int position = viewHolder.getAdapterPosition() - offset;
if(position >= 0 && mFavoriteSubscribedUserData.size() > position) {
mFavoriteSubscribedUserData.get(position).setFavorite(true);
}
((UserViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
}
});
} else {
((UserViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
mSubscribedUserData.get(viewHolder.getAdapterPosition() - offset).setFavorite(true);
FavoriteThing.favoriteUser(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
mSubscribedUserData.get(viewHolder.getAdapterPosition() - offset),
new FavoriteThing.FavoriteThingListener() {
@Override
public void success() {
int position = viewHolder.getAdapterPosition() - offset;
if(position >= 0 && mFavoriteSubscribedUserData.size() > position) {
mFavoriteSubscribedUserData.get(position).setFavorite(true);
}
((UserViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
}
@Override
public void failed() {
int position = viewHolder.getAdapterPosition() - offset;
if(position >= 0 && mFavoriteSubscribedUserData.size() > position) {
mFavoriteSubscribedUserData.get(position).setFavorite(false);
}
((UserViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
}
});
}
});
} else if (viewHolder instanceof FavoriteUserViewHolder) {
viewHolder.itemView.setOnClickListener(view -> {
Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mFavoriteSubscribedUserData.get(viewHolder.getAdapterPosition() - 1).getName());
mContext.startActivity(intent);
});
if (!mFavoriteSubscribedUserData.get(viewHolder.getAdapterPosition() - 1).getIconUrl().equals("")) {
glide.load(mFavoriteSubscribedUserData.get(viewHolder.getAdapterPosition() - 1).getIconUrl())
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(glide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
.into(((FavoriteUserViewHolder) viewHolder).iconGifImageView);
} else {
glide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.into(((FavoriteUserViewHolder) viewHolder).iconGifImageView);
}
((FavoriteUserViewHolder) viewHolder).userNameTextView.setText(mFavoriteSubscribedUserData.get(viewHolder.getAdapterPosition() - 1).getName());
if(mFavoriteSubscribedUserData.get(viewHolder.getAdapterPosition() - 1).isFavorite()) {
((FavoriteUserViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
} else {
((FavoriteUserViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
}
((FavoriteUserViewHolder) viewHolder).favoriteImageView.setOnClickListener(view -> {
if(mFavoriteSubscribedUserData.get(viewHolder.getAdapterPosition() - 1).isFavorite()) {
((FavoriteUserViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
mFavoriteSubscribedUserData.get(viewHolder.getAdapterPosition() - 1).setFavorite(false);
FavoriteThing.unfavoriteUser(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
mFavoriteSubscribedUserData.get(viewHolder.getAdapterPosition() - 1),
new FavoriteThing.FavoriteThingListener() {
@Override
public void success() {
int position = viewHolder.getAdapterPosition() - 1;
if(position >= 0 && mFavoriteSubscribedUserData.size() > position) {
mFavoriteSubscribedUserData.get(position).setFavorite(false);
}
((FavoriteUserViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
}
@Override
public void failed() {
int position = viewHolder.getAdapterPosition() - 1;
if(position >= 0 && mFavoriteSubscribedUserData.size() > position) {
mFavoriteSubscribedUserData.get(position).setFavorite(true);
}
((FavoriteUserViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
}
});
} else {
((FavoriteUserViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
mFavoriteSubscribedUserData.get(viewHolder.getAdapterPosition() - 1).setFavorite(true);
FavoriteThing.favoriteUser(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
mFavoriteSubscribedUserData.get(viewHolder.getAdapterPosition() - 1),
new FavoriteThing.FavoriteThingListener() {
@Override
public void success() {
int position = viewHolder.getAdapterPosition() - 1;
if(position >= 0 && mFavoriteSubscribedUserData.size() > position) {
mFavoriteSubscribedUserData.get(position).setFavorite(true);
}
((FavoriteUserViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
}
@Override
public void failed() {
int position = viewHolder.getAdapterPosition() - 1;
if(position >= 0 && mFavoriteSubscribedUserData.size() > position) {
mFavoriteSubscribedUserData.get(position).setFavorite(false);
}
((FavoriteUserViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
}
});
}
});
} }
((UserViewHolder) viewHolder).subredditNameTextView.setText(mSubscribedUserData.get(i).getName());
} }
@Override @Override
public int getItemCount() { public int getItemCount() {
if (mSubscribedUserData != null) { if (mSubscribedUserData != null && mSubscribedUserData.size() > 0) {
if(mFavoriteSubscribedUserData != null && mFavoriteSubscribedUserData.size() > 0) {
return mSubscribedUserData.size() + mFavoriteSubscribedUserData.size() + 2;
}
return mSubscribedUserData.size(); return mSubscribedUserData.size();
} }
return 0; return 0;
@ -69,7 +261,11 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
@Override @Override
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) { public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
glide.clear(((UserViewHolder) holder).iconGifImageView); if(holder instanceof UserViewHolder) {
glide.clear(((UserViewHolder) holder).iconGifImageView);
} else if (holder instanceof FavoriteUserViewHolder) {
glide.clear(((FavoriteUserViewHolder) holder).iconGifImageView);
}
} }
public void setSubscribedUsers(List<SubscribedUserData> subscribedUsers) { public void setSubscribedUsers(List<SubscribedUserData> subscribedUsers) {
@ -77,15 +273,56 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
notifyDataSetChanged(); notifyDataSetChanged();
} }
public void setFavoriteSubscribedUsers(List<SubscribedUserData> favoriteSubscribedUsers) {
mFavoriteSubscribedUserData = favoriteSubscribedUsers;
notifyDataSetChanged();
}
private class UserViewHolder extends RecyclerView.ViewHolder { class FavoriteUserViewHolder extends RecyclerView.ViewHolder {
private final GifImageView iconGifImageView; @BindView(R.id.thing_icon_gif_image_view_item_subscribed_thing)
private final TextView subredditNameTextView; GifImageView iconGifImageView;
@BindView(R.id.thing_name_text_view_item_subscribed_thing)
TextView userNameTextView;
@BindView(R.id.favorite_image_view_item_subscribed_thing)
ImageView favoriteImageView;
public UserViewHolder(View itemView) { FavoriteUserViewHolder(View itemView) {
super(itemView); super(itemView);
iconGifImageView = itemView.findViewById(R.id.subreddit_icon_gif_image_view_item_subscribed_subreddit); ButterKnife.bind(this, itemView);
subredditNameTextView = itemView.findViewById(R.id.subreddit_name_text_view_item_subscribed_subreddit); }
}
class UserViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.thing_icon_gif_image_view_item_subscribed_thing)
GifImageView iconGifImageView;
@BindView(R.id.thing_name_text_view_item_subscribed_thing)
TextView userNameTextView;
@BindView(R.id.favorite_image_view_item_subscribed_thing)
ImageView favoriteImageView;
UserViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
class FavoriteUsersDividerViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.divider_text_view_item_favorite_thing_divider) TextView dividerTextView;
FavoriteUsersDividerViewHolder(@NonNull View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
dividerTextView.setText(R.string.favorites);
}
}
class AllUsersDividerViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.divider_text_view_item_favorite_thing_divider) TextView dividerTextView;
AllUsersDividerViewHolder(@NonNull View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
dividerTextView.setText(R.string.all);
} }
} }
} }

View File

@ -92,13 +92,13 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
switch (i) { switch (i) {
case VIEW_TYPE_FAVORITE_SUBREDDIT_DIVIDER: case VIEW_TYPE_FAVORITE_SUBREDDIT_DIVIDER:
return new FavoriteSubredditsDividerViewHolder(LayoutInflater.from(viewGroup.getContext()) return new FavoriteSubredditsDividerViewHolder(LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.item_favorite_subreddits_divider, viewGroup, false)); .inflate(R.layout.item_favorite_thing_divider, viewGroup, false));
case VIEW_TYPE_FAVORITE_SUBREDDIT: case VIEW_TYPE_FAVORITE_SUBREDDIT:
return new FavoriteSubredditViewHolder(LayoutInflater.from(viewGroup.getContext()) return new FavoriteSubredditViewHolder(LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.item_subscribed_thing, viewGroup, false)); .inflate(R.layout.item_subscribed_thing, viewGroup, false));
case VIEW_TYPE_SUBREDDIT_DIVIDER: case VIEW_TYPE_SUBREDDIT_DIVIDER:
return new AllSubredditsDividerViewHolder(LayoutInflater.from(viewGroup.getContext()) return new AllSubredditsDividerViewHolder(LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.item_favorite_subreddits_divider, viewGroup, false)); .inflate(R.layout.item_favorite_thing_divider, viewGroup, false));
default: default:
return new SubredditViewHolder(LayoutInflater.from(viewGroup.getContext()) return new SubredditViewHolder(LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.item_subscribed_thing, viewGroup, false)); .inflate(R.layout.item_subscribed_thing, viewGroup, false));
@ -153,8 +153,8 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
if(mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).isFavorite()) { if(mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).isFavorite()) {
((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); ((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).setFavorite(false); mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).setFavorite(false);
FavoriteThing.unfavoriteThing(mOauthRetrofit, mRedditDataRoomDatabase, accessToken, FavoriteThing.unfavoriteSubreddit(mOauthRetrofit, mRedditDataRoomDatabase, accessToken,
mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset), false, mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset),
new FavoriteThing.FavoriteThingListener() { new FavoriteThing.FavoriteThingListener() {
@Override @Override
public void success() { public void success() {
@ -177,8 +177,8 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
} else { } else {
((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); ((SubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).setFavorite(true); mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset).setFavorite(true);
FavoriteThing.favoriteThing(mOauthRetrofit, mRedditDataRoomDatabase, accessToken, FavoriteThing.favoriteSubreddit(mOauthRetrofit, mRedditDataRoomDatabase, accessToken,
mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset), false, mSubscribedSubredditData.get(viewHolder.getAdapterPosition() - offset),
new FavoriteThing.FavoriteThingListener() { new FavoriteThing.FavoriteThingListener() {
@Override @Override
public void success() { public void success() {
@ -232,8 +232,8 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
if(mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - 1).isFavorite()) { if(mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - 1).isFavorite()) {
((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp); ((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - 1).setFavorite(false); mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - 1).setFavorite(false);
FavoriteThing.unfavoriteThing(mOauthRetrofit, mRedditDataRoomDatabase, accessToken, FavoriteThing.unfavoriteSubreddit(mOauthRetrofit, mRedditDataRoomDatabase, accessToken,
mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - 1), false, mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - 1),
new FavoriteThing.FavoriteThingListener() { new FavoriteThing.FavoriteThingListener() {
@Override @Override
public void success() { public void success() {
@ -256,8 +256,8 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
} else { } else {
((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp); ((FavoriteSubredditViewHolder) viewHolder).favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - 1).setFavorite(true); mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - 1).setFavorite(true);
FavoriteThing.favoriteThing(mOauthRetrofit, mRedditDataRoomDatabase, accessToken, FavoriteThing.favoriteSubreddit(mOauthRetrofit, mRedditDataRoomDatabase, accessToken,
mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - 1), false, mFavoriteSubscribedSubredditData.get(viewHolder.getAdapterPosition() - 1),
new FavoriteThing.FavoriteThingListener() { new FavoriteThing.FavoriteThingListener() {
@Override @Override
public void success() { public void success() {
@ -350,11 +350,11 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
} }
class SubredditViewHolder extends RecyclerView.ViewHolder { class SubredditViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.subreddit_icon_gif_image_view_item_subscribed_subreddit) @BindView(R.id.thing_icon_gif_image_view_item_subscribed_thing)
GifImageView iconGifImageView; GifImageView iconGifImageView;
@BindView(R.id.subreddit_name_text_view_item_subscribed_subreddit) @BindView(R.id.thing_name_text_view_item_subscribed_thing)
TextView subredditNameTextView; TextView subredditNameTextView;
@BindView(R.id.favorite_image_view_item_subscribed_subreddit) @BindView(R.id.favorite_image_view_item_subscribed_thing)
ImageView favoriteImageView; ImageView favoriteImageView;
SubredditViewHolder(View itemView) { SubredditViewHolder(View itemView) {
@ -364,11 +364,11 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
} }
class FavoriteSubredditViewHolder extends RecyclerView.ViewHolder { class FavoriteSubredditViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.subreddit_icon_gif_image_view_item_subscribed_subreddit) @BindView(R.id.thing_icon_gif_image_view_item_subscribed_thing)
GifImageView iconGifImageView; GifImageView iconGifImageView;
@BindView(R.id.subreddit_name_text_view_item_subscribed_subreddit) @BindView(R.id.thing_name_text_view_item_subscribed_thing)
TextView subredditNameTextView; TextView subredditNameTextView;
@BindView(R.id.favorite_image_view_item_subscribed_subreddit) @BindView(R.id.favorite_image_view_item_subscribed_thing)
ImageView favoriteImageView; ImageView favoriteImageView;
FavoriteSubredditViewHolder(View itemView) { FavoriteSubredditViewHolder(View itemView) {
@ -378,7 +378,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
} }
class FavoriteSubredditsDividerViewHolder extends RecyclerView.ViewHolder { class FavoriteSubredditsDividerViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.divider_text_view_item_favorite_subreddits_divider) TextView dividerTextView; @BindView(R.id.divider_text_view_item_favorite_thing_divider) TextView dividerTextView;
FavoriteSubredditsDividerViewHolder(@NonNull View itemView) { FavoriteSubredditsDividerViewHolder(@NonNull View itemView) {
super(itemView); super(itemView);
@ -388,7 +388,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
} }
class AllSubredditsDividerViewHolder extends RecyclerView.ViewHolder { class AllSubredditsDividerViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.divider_text_view_item_favorite_subreddits_divider) TextView dividerTextView; @BindView(R.id.divider_text_view_item_favorite_thing_divider) TextView dividerTextView;
AllSubredditsDividerViewHolder(@NonNull View itemView) { AllSubredditsDividerViewHolder(@NonNull View itemView) {
super(itemView); super(itemView);

View File

@ -19,13 +19,15 @@ public class InsertSubscribedThingsAsyncTask extends AsyncTask<Void, Void, Void>
private RedditDataRoomDatabase mRedditDataRoomDatabase; private RedditDataRoomDatabase mRedditDataRoomDatabase;
private String mAccountName; private String mAccountName;
private SubscribedSubredditDao mSubscribedSubredditDao; private SubscribedSubredditDao mSubscribedSubredditDao;
private SubscribedUserDao mUserDao; private SubscribedUserDao mSubscribedUserDao;
private SubredditDao mSubredditDao; private SubredditDao mSubredditDao;
private SubscribedSubredditData mSingleSubscribedSubredditData; private SubscribedSubredditData mSingleSubscribedSubredditData;
private SubscribedUserData mSingleSubscribedUserData;
private List<SubscribedSubredditData> subscribedSubredditData; private List<SubscribedSubredditData> subscribedSubredditData;
private List<SubscribedUserData> subscribedUserData; private List<SubscribedUserData> subscribedUserData;
private List<SubredditData> subredditData; private List<SubredditData> subredditData;
private InsertSubscribedThingListener mInsertSubscribedThingListener; private InsertSubscribedThingListener mInsertSubscribedThingListener;
public InsertSubscribedThingsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, @Nullable String accountName, public InsertSubscribedThingsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, @Nullable String accountName,
List<SubscribedSubredditData> subscribedSubredditData, List<SubscribedSubredditData> subscribedSubredditData,
List<SubscribedUserData> subscribedUserData, List<SubscribedUserData> subscribedUserData,
@ -34,7 +36,7 @@ public class InsertSubscribedThingsAsyncTask extends AsyncTask<Void, Void, Void>
mRedditDataRoomDatabase = redditDataRoomDatabase; mRedditDataRoomDatabase = redditDataRoomDatabase;
mAccountName = accountName; mAccountName = accountName;
mSubscribedSubredditDao = redditDataRoomDatabase.subscribedSubredditDao(); mSubscribedSubredditDao = redditDataRoomDatabase.subscribedSubredditDao();
mUserDao = redditDataRoomDatabase.subscribedUserDao(); mSubscribedUserDao = redditDataRoomDatabase.subscribedUserDao();
mSubredditDao = redditDataRoomDatabase.subredditDao(); mSubredditDao = redditDataRoomDatabase.subredditDao();
this.subscribedSubredditData = subscribedSubredditData; this.subscribedSubredditData = subscribedSubredditData;
@ -53,14 +55,26 @@ public class InsertSubscribedThingsAsyncTask extends AsyncTask<Void, Void, Void>
mInsertSubscribedThingListener = insertSubscribedThingListener; mInsertSubscribedThingListener = insertSubscribedThingListener;
} }
public InsertSubscribedThingsAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase,
SubscribedUserData subscribedUserData,
InsertSubscribedThingListener insertSubscribedThingListener) {
mRedditDataRoomDatabase = redditDataRoomDatabase;
mSubscribedUserDao = redditDataRoomDatabase.subscribedUserDao();
mAccountName = subscribedUserData.getUsername();
mSingleSubscribedUserData = subscribedUserData;
mInsertSubscribedThingListener = insertSubscribedThingListener;
}
@Override @Override
protected Void doInBackground(final Void... params) { protected Void doInBackground(final Void... params) {
if (mAccountName != null && mRedditDataRoomDatabase.accountDao().getAccountData(mAccountName) == null) { if (mAccountName != null && mRedditDataRoomDatabase.accountDao().getAccountData(mAccountName) == null) {
return null; return null;
} }
if(mSingleSubscribedSubredditData != null) { if (mSingleSubscribedSubredditData != null) {
mSubscribedSubredditDao.insert(mSingleSubscribedSubredditData); mSubscribedSubredditDao.insert(mSingleSubscribedSubredditData);
} else if (mSingleSubscribedUserData != null) {
mSubscribedUserDao.insert(mSingleSubscribedUserData);
} else { } else {
if (subscribedSubredditData != null) { if (subscribedSubredditData != null) {
for (SubscribedSubredditData s : subscribedSubredditData) { for (SubscribedSubredditData s : subscribedSubredditData) {
@ -70,7 +84,7 @@ public class InsertSubscribedThingsAsyncTask extends AsyncTask<Void, Void, Void>
if (subscribedUserData != null) { if (subscribedUserData != null) {
for (SubscribedUserData s : subscribedUserData) { for (SubscribedUserData s : subscribedUserData) {
mUserDao.insert(s); mSubscribedUserDao.insert(s);
} }
} }

View File

@ -7,21 +7,18 @@ import java.util.Map;
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData; import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class FavoriteThing { public class FavoriteThing {
public static void favoriteThing(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, public static void favoriteSubreddit(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase,
String accessToken, SubscribedSubredditData subscribedSubredditData, String accessToken, SubscribedSubredditData subscribedSubredditData,
boolean isUser, FavoriteThingListener favoriteThingListener) { FavoriteThingListener favoriteThingListener) {
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
if (isUser) { params.put(RedditUtils.SR_NAME_KEY, subscribedSubredditData.getName());
params.put(RedditUtils.SR_NAME_KEY, "u_" + subscribedSubredditData.getName());
} else {
params.put(RedditUtils.SR_NAME_KEY, subscribedSubredditData.getName());
}
params.put(RedditUtils.MAKE_FAVORITE_KEY, "true"); params.put(RedditUtils.MAKE_FAVORITE_KEY, "true");
oauthRetrofit.create(RedditAPI.class).favoriteThing(RedditUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() { oauthRetrofit.create(RedditAPI.class).favoriteThing(RedditUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() {
@Override @Override
@ -41,15 +38,11 @@ public class FavoriteThing {
}); });
} }
public static void unfavoriteThing(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, public static void unfavoriteSubreddit(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase,
String accessToken, SubscribedSubredditData subscribedSubredditData, String accessToken, SubscribedSubredditData subscribedSubredditData,
boolean isUser, FavoriteThingListener favoriteThingListener) { FavoriteThingListener favoriteThingListener) {
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
if (isUser) { params.put(RedditUtils.SR_NAME_KEY, subscribedSubredditData.getName());
params.put(RedditUtils.SR_NAME_KEY, "u_" + subscribedSubredditData.getName());
} else {
params.put(RedditUtils.SR_NAME_KEY, subscribedSubredditData.getName());
}
params.put(RedditUtils.MAKE_FAVORITE_KEY, "false"); params.put(RedditUtils.MAKE_FAVORITE_KEY, "false");
oauthRetrofit.create(RedditAPI.class).favoriteThing(RedditUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() { oauthRetrofit.create(RedditAPI.class).favoriteThing(RedditUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() {
@Override @Override
@ -69,6 +62,54 @@ public class FavoriteThing {
}); });
} }
public static void favoriteUser(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase,
String accessToken, SubscribedUserData subscribedUserData,
FavoriteThingListener favoriteThingListener) {
Map<String, String> params = new HashMap<>();
params.put(RedditUtils.SR_NAME_KEY, "u_" + subscribedUserData.getName());
params.put(RedditUtils.MAKE_FAVORITE_KEY, "true");
oauthRetrofit.create(RedditAPI.class).favoriteThing(RedditUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if (response.isSuccessful()) {
new InsertSubscribedThingsAsyncTask(redditDataRoomDatabase, subscribedUserData,
favoriteThingListener::success).execute();
} else {
favoriteThingListener.failed();
}
}
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
favoriteThingListener.failed();
}
});
}
public static void unfavoriteUser(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase,
String accessToken, SubscribedUserData subscribedUserData,
FavoriteThingListener favoriteThingListener) {
Map<String, String> params = new HashMap<>();
params.put(RedditUtils.SR_NAME_KEY, "u_" + subscribedUserData.getName());
params.put(RedditUtils.MAKE_FAVORITE_KEY, "false");
oauthRetrofit.create(RedditAPI.class).favoriteThing(RedditUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if (response.isSuccessful()) {
new InsertSubscribedThingsAsyncTask(redditDataRoomDatabase, subscribedUserData,
favoriteThingListener::success).execute();
} else {
favoriteThingListener.failed();
}
}
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
favoriteThingListener.failed();
}
});
}
public interface FavoriteThingListener { public interface FavoriteThingListener {
void success(); void success();

View File

@ -21,6 +21,7 @@ import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager; import com.bumptech.glide.RequestManager;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
@ -29,6 +30,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserViewModel; import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserViewModel;
import retrofit2.Retrofit;
/** /**
@ -37,6 +39,7 @@ import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUse
public class FollowedUsersListingFragment extends Fragment { public class FollowedUsersListingFragment extends Fragment {
public static final String EXTRA_ACCOUNT_NAME = "EAN"; public static final String EXTRA_ACCOUNT_NAME = "EAN";
public static final String EXTRA_ACCESS_TOKEN = "EAT";
@BindView(R.id.recycler_view_followed_users_listing_fragment) @BindView(R.id.recycler_view_followed_users_listing_fragment)
RecyclerView mRecyclerView; RecyclerView mRecyclerView;
@ -45,6 +48,9 @@ public class FollowedUsersListingFragment extends Fragment {
@BindView(R.id.no_subscriptions_image_view_followed_users_listing_fragment) @BindView(R.id.no_subscriptions_image_view_followed_users_listing_fragment)
ImageView mImageView; ImageView mImageView;
@Inject @Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
RedditDataRoomDatabase mRedditDataRoomDatabase; RedditDataRoomDatabase mRedditDataRoomDatabase;
private Activity mActivity; private Activity mActivity;
private RequestManager mGlide; private RequestManager mGlide;
@ -79,12 +85,14 @@ public class FollowedUsersListingFragment extends Fragment {
mGlide = Glide.with(this); mGlide = Glide.with(this);
mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity)); mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
FollowedUsersRecyclerViewAdapter adapter = new FollowedUsersRecyclerViewAdapter(mActivity); FollowedUsersRecyclerViewAdapter adapter = new FollowedUsersRecyclerViewAdapter(mActivity,
mOauthRetrofit, mRedditDataRoomDatabase, getArguments().getString(EXTRA_ACCESS_TOKEN));
mRecyclerView.setAdapter(adapter); mRecyclerView.setAdapter(adapter);
mSubscribedUserViewModel = new ViewModelProvider(this, mSubscribedUserViewModel = new ViewModelProvider(this,
new SubscribedUserViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, getArguments().getString(EXTRA_ACCOUNT_NAME))) new SubscribedUserViewModel.Factory(mActivity.getApplication(), mRedditDataRoomDatabase, getArguments().getString(EXTRA_ACCOUNT_NAME)))
.get(SubscribedUserViewModel.class); .get(SubscribedUserViewModel.class);
mSubscribedUserViewModel.getAllSubscribedUsers().observe(this, subscribedUserData -> { mSubscribedUserViewModel.getAllSubscribedUsers().observe(this, subscribedUserData -> {
if (subscribedUserData == null || subscribedUserData.size() == 0) { if (subscribedUserData == null || subscribedUserData.size() == 0) {
mRecyclerView.setVisibility(View.GONE); mRecyclerView.setVisibility(View.GONE);
@ -93,10 +101,20 @@ public class FollowedUsersListingFragment extends Fragment {
} else { } else {
mLinearLayout.setVisibility(View.GONE); mLinearLayout.setVisibility(View.GONE);
mRecyclerView.setVisibility(View.VISIBLE); mRecyclerView.setVisibility(View.VISIBLE);
mGlide.clear(mImageView);
} }
adapter.setSubscribedUsers(subscribedUserData); adapter.setSubscribedUsers(subscribedUserData);
}); });
mSubscribedUserViewModel.getAllFavoriteSubscribedUsers().observe(this, favoriteSubscribedUserData -> {
if (favoriteSubscribedUserData != null && favoriteSubscribedUserData.size() > 0) {
mLinearLayout.setVisibility(View.GONE);
mRecyclerView.setVisibility(View.VISIBLE);
mGlide.clear(mImageView);
}
adapter.setFavoriteSubscribedUsers(favoriteSubscribedUserData);
});
return rootView; return rootView;
} }

View File

@ -19,6 +19,9 @@ public interface SubscribedUserDao {
@Query("SELECT * FROM subscribed_users WHERE username = :accountName ORDER BY name COLLATE NOCASE ASC") @Query("SELECT * FROM subscribed_users WHERE username = :accountName ORDER BY name COLLATE NOCASE ASC")
LiveData<List<SubscribedUserData>> getAllSubscribedUsers(String accountName); LiveData<List<SubscribedUserData>> getAllSubscribedUsers(String accountName);
@Query("SELECT * FROM subscribed_users WHERE username = :accountName AND is_favorite = 1 ORDER BY name COLLATE NOCASE ASC")
LiveData<List<SubscribedUserData>> getAllFavoriteSubscribedUsers(String accountName);
@Query("SELECT * FROM subscribed_users WHERE name = :name AND username = :accountName COLLATE NOCASE LIMIT 1") @Query("SELECT * FROM subscribed_users WHERE name = :name AND username = :accountName COLLATE NOCASE LIMIT 1")
SubscribedUserData getSubscribedUser(String name, String accountName); SubscribedUserData getSubscribedUser(String name, String accountName);

View File

@ -11,16 +11,22 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
public class SubscribedUserRepository { public class SubscribedUserRepository {
private SubscribedUserDao mSubscribedUserDao; private SubscribedUserDao mSubscribedUserDao;
private LiveData<List<SubscribedUserData>> mAllSubscribedUsers; private LiveData<List<SubscribedUserData>> mAllSubscribedUsers;
private LiveData<List<SubscribedUserData>> mAllFavoriteSubscribedUsers;
SubscribedUserRepository(RedditDataRoomDatabase redditDataRoomDatabase, String accountName) { SubscribedUserRepository(RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
mSubscribedUserDao = redditDataRoomDatabase.subscribedUserDao(); mSubscribedUserDao = redditDataRoomDatabase.subscribedUserDao();
mAllSubscribedUsers = mSubscribedUserDao.getAllSubscribedUsers(accountName); mAllSubscribedUsers = mSubscribedUserDao.getAllSubscribedUsers(accountName);
mAllFavoriteSubscribedUsers = mSubscribedUserDao.getAllFavoriteSubscribedUsers(accountName);
} }
LiveData<List<SubscribedUserData>> getAllSubscribedSubreddits() { LiveData<List<SubscribedUserData>> getAllSubscribedSubreddits() {
return mAllSubscribedUsers; return mAllSubscribedUsers;
} }
LiveData<List<SubscribedUserData>> getAllFavoriteSubscribedSubreddits() {
return mAllFavoriteSubscribedUsers;
}
public void insert(SubscribedUserData subscribedUserData) { public void insert(SubscribedUserData subscribedUserData) {
new SubscribedUserRepository.insertAsyncTask(mSubscribedUserDao).execute(subscribedUserData); new SubscribedUserRepository.insertAsyncTask(mSubscribedUserDao).execute(subscribedUserData);
} }

View File

@ -15,17 +15,23 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
public class SubscribedUserViewModel extends AndroidViewModel { public class SubscribedUserViewModel extends AndroidViewModel {
private SubscribedUserRepository mSubscribedUserRepository; private SubscribedUserRepository mSubscribedUserRepository;
private LiveData<List<SubscribedUserData>> mAllSubscribedUsers; private LiveData<List<SubscribedUserData>> mAllSubscribedUsers;
private LiveData<List<SubscribedUserData>> mAllFavoriteSubscribedUsers;
public SubscribedUserViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) { public SubscribedUserViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String accountName) {
super(application); super(application);
mSubscribedUserRepository = new SubscribedUserRepository(redditDataRoomDatabase, accountName); mSubscribedUserRepository = new SubscribedUserRepository(redditDataRoomDatabase, accountName);
mAllSubscribedUsers = mSubscribedUserRepository.getAllSubscribedSubreddits(); mAllSubscribedUsers = mSubscribedUserRepository.getAllSubscribedSubreddits();
mAllFavoriteSubscribedUsers = mSubscribedUserRepository.getAllFavoriteSubscribedSubreddits();
} }
public LiveData<List<SubscribedUserData>> getAllSubscribedUsers() { public LiveData<List<SubscribedUserData>> getAllSubscribedUsers() {
return mAllSubscribedUsers; return mAllSubscribedUsers;
} }
public LiveData<List<SubscribedUserData>> getAllFavoriteSubscribedUsers() {
return mAllFavoriteSubscribedUsers;
}
public void insert(SubscribedUserData subscribedUserData) { public void insert(SubscribedUserData subscribedUserData) {
mSubscribedUserRepository.insert(subscribedUserData); mSubscribedUserRepository.insert(subscribedUserData);
} }

View File

@ -5,7 +5,7 @@
android:padding="16dp"> android:padding="16dp">
<TextView <TextView
android:id="@+id/divider_text_view_item_favorite_subreddits_divider" android:id="@+id/divider_text_view_item_favorite_thing_divider"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />

View File

@ -9,14 +9,14 @@
android:background="?attr/selectableItemBackground"> android:background="?attr/selectableItemBackground">
<pl.droidsonroids.gif.GifImageView <pl.droidsonroids.gif.GifImageView
android:id="@+id/subreddit_icon_gif_image_view_item_subscribed_subreddit" android:id="@+id/thing_icon_gif_image_view_item_subscribed_thing"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginEnd="32dp" /> android:layout_marginEnd="32dp" />
<TextView <TextView
android:id="@+id/subreddit_name_text_view_item_subscribed_subreddit" android:id="@+id/thing_name_text_view_item_subscribed_thing"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
@ -25,7 +25,7 @@
android:layout_gravity="center_vertical" /> android:layout_gravity="center_vertical" />
<ImageView <ImageView
android:id="@+id/favorite_image_view_item_subscribed_subreddit" android:id="@+id/favorite_image_view_item_subscribed_thing"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_gravity="end|center_vertical" android:layout_gravity="end|center_vertical"