mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 04:37:25 +01:00
Fix ArrayIndexOutOfBoundsException in FollowedUsersRecyclerViewAdapter. Minor bugs fixed.
This commit is contained in:
parent
37e7c87517
commit
a476d10151
@ -174,6 +174,10 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
||||
}
|
||||
|
||||
private void bindView(boolean initializeFragment) {
|
||||
if (isFinishing() || isDestroyed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
loadSubscriptions();
|
||||
|
||||
if (initializeFragment) {
|
||||
|
@ -901,9 +901,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
if (mMenu != null) {
|
||||
mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity).setTitle(R.string.action_start_lazy_mode);
|
||||
}
|
||||
sectionsPagerAdapter.refresh();
|
||||
mFetchSubredditInfoSuccess = false;
|
||||
fetchSubredditData();
|
||||
if (sectionsPagerAdapter != null) {
|
||||
sectionsPagerAdapter.refresh();
|
||||
mFetchSubredditInfoSuccess = false;
|
||||
fetchSubredditData();
|
||||
}
|
||||
return true;
|
||||
case R.id.action_lazy_mode_view_subreddit_detail_activity:
|
||||
if (sectionsPagerAdapter != null) {
|
||||
|
@ -102,11 +102,6 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
int offset = (mFavoriteSubscribedUserData != null && mFavoriteSubscribedUserData.size() > 0) ?
|
||||
mFavoriteSubscribedUserData.size() + 2 : 0;
|
||||
|
||||
viewHolder.itemView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
|
||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mSubscribedUserData.get(viewHolder.getAdapterPosition() - offset).getName());
|
||||
mContext.startActivity(intent);
|
||||
});
|
||||
if (!mSubscribedUserData.get(viewHolder.getAdapterPosition() - offset).getIconUrl().equals("")) {
|
||||
glide.load(mSubscribedUserData.get(viewHolder.getAdapterPosition() - offset).getIconUrl())
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
@ -125,66 +120,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
} 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() {
|
||||
Toast.makeText(mContext, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show();
|
||||
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() {
|
||||
Toast.makeText(mContext, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show();
|
||||
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)))
|
||||
@ -203,60 +139,6 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
} 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() {
|
||||
Toast.makeText(mContext, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show();
|
||||
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() {
|
||||
Toast.makeText(mContext, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show();
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -317,6 +199,72 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
userNameTextView.setTextColor(mPrimaryTextColor);
|
||||
|
||||
itemView.setOnClickListener(view -> {
|
||||
int position = getAdapterPosition() - 1;
|
||||
if(position >= 0 && mFavoriteSubscribedUserData.size() > position) {
|
||||
Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
|
||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mFavoriteSubscribedUserData.get(position).getName());
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
favoriteImageView.setOnClickListener(view -> {
|
||||
int position = getAdapterPosition() - 1;
|
||||
if(position >= 0 && mFavoriteSubscribedUserData.size() > position) {
|
||||
if(mFavoriteSubscribedUserData.get(position).isFavorite()) {
|
||||
favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
|
||||
mFavoriteSubscribedUserData.get(position).setFavorite(false);
|
||||
FavoriteThing.unfavoriteUser(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
|
||||
mFavoriteSubscribedUserData.get(position),
|
||||
new FavoriteThing.FavoriteThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
int position = getAdapterPosition() - 1;
|
||||
if(position >= 0 && mFavoriteSubscribedUserData.size() > position) {
|
||||
mFavoriteSubscribedUserData.get(position).setFavorite(false);
|
||||
}
|
||||
favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed() {
|
||||
Toast.makeText(mContext, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show();
|
||||
int position = getAdapterPosition() - 1;
|
||||
if(position >= 0 && mFavoriteSubscribedUserData.size() > position) {
|
||||
mFavoriteSubscribedUserData.get(position).setFavorite(true);
|
||||
}
|
||||
favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
|
||||
mFavoriteSubscribedUserData.get(position).setFavorite(true);
|
||||
FavoriteThing.favoriteUser(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
|
||||
mFavoriteSubscribedUserData.get(position),
|
||||
new FavoriteThing.FavoriteThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
int position = getAdapterPosition() - 1;
|
||||
if(position >= 0 && mFavoriteSubscribedUserData.size() > position) {
|
||||
mFavoriteSubscribedUserData.get(position).setFavorite(true);
|
||||
}
|
||||
favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed() {
|
||||
Toast.makeText(mContext, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show();
|
||||
int position = getAdapterPosition() - 1;
|
||||
if(position >= 0 && mFavoriteSubscribedUserData.size() > position) {
|
||||
mFavoriteSubscribedUserData.get(position).setFavorite(false);
|
||||
}
|
||||
favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -332,6 +280,77 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
userNameTextView.setTextColor(mPrimaryTextColor);
|
||||
|
||||
itemView.setOnClickListener(view -> {
|
||||
int offset = (mFavoriteSubscribedUserData != null && mFavoriteSubscribedUserData.size() > 0) ?
|
||||
mFavoriteSubscribedUserData.size() + 2 : 0;
|
||||
int position = getAdapterPosition() - offset;
|
||||
if(position >= 0 && mSubscribedUserData.size() > position) {
|
||||
Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
|
||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mSubscribedUserData.get(position).getName());
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
favoriteImageView.setOnClickListener(view -> {
|
||||
int offset = (mFavoriteSubscribedUserData != null && mFavoriteSubscribedUserData.size() > 0) ?
|
||||
mFavoriteSubscribedUserData.size() + 2 : 0;
|
||||
int position = getAdapterPosition() - offset;
|
||||
|
||||
if(position >= 0 && mSubscribedUserData.size() > position) {
|
||||
if(mSubscribedUserData.get(position).isFavorite()) {
|
||||
favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
|
||||
mSubscribedUserData.get(position).setFavorite(false);
|
||||
FavoriteThing.unfavoriteUser(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
|
||||
mSubscribedUserData.get(position),
|
||||
new FavoriteThing.FavoriteThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
int position = getAdapterPosition() - offset;
|
||||
if(position >= 0 && mSubscribedUserData.size() > position) {
|
||||
mSubscribedUserData.get(position).setFavorite(false);
|
||||
}
|
||||
favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed() {
|
||||
Toast.makeText(mContext, R.string.thing_unfavorite_failed, Toast.LENGTH_SHORT).show();
|
||||
int position = getAdapterPosition() - offset;
|
||||
if(position >= 0 && mSubscribedUserData.size() > position) {
|
||||
mSubscribedUserData.get(position).setFavorite(true);
|
||||
}
|
||||
favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
|
||||
mSubscribedUserData.get(position).setFavorite(true);
|
||||
FavoriteThing.favoriteUser(mOauthRetrofit, mRedditDataRoomDatabase, mAccessToken,
|
||||
mSubscribedUserData.get(position),
|
||||
new FavoriteThing.FavoriteThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
int position = getAdapterPosition() - offset;
|
||||
if(position >= 0 && mSubscribedUserData.size() > position) {
|
||||
mSubscribedUserData.get(position).setFavorite(true);
|
||||
}
|
||||
favoriteImageView.setImageResource(R.drawable.ic_favorite_24dp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed() {
|
||||
Toast.makeText(mContext, R.string.thing_favorite_failed, Toast.LENGTH_SHORT).show();
|
||||
int position = getAdapterPosition() - offset;
|
||||
if(position >= 0 && mSubscribedUserData.size() > position) {
|
||||
mSubscribedUserData.get(position).setFavorite(false);
|
||||
}
|
||||
favoriteImageView.setImageResource(R.drawable.ic_favorite_border_24dp);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -567,7 +567,7 @@ public class DownloadRedditVideoService extends Service {
|
||||
|
||||
muxer.stop();
|
||||
muxer.release();
|
||||
} catch (IllegalArgumentException ignore) {
|
||||
} catch (IllegalArgumentException | IllegalStateException ignore) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user