aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-12-01 09:51:43 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-12-01 09:51:43 +0000
commita476d101510ae4be4d63689d332512e0613104c2 (patch)
treeeacdf88fca019b118e859ab7d63b92c109ce9771 /app/src/main/java
parent37e7c8751721707fba066cf0ffaa3933bbf2740e (diff)
downloadinfinity-for-reddit-a476d101510ae4be4d63689d332512e0613104c2.tar
infinity-for-reddit-a476d101510ae4be4d63689d332512e0613104c2.tar.gz
infinity-for-reddit-a476d101510ae4be4d63689d332512e0613104c2.tar.bz2
infinity-for-reddit-a476d101510ae4be4d63689d332512e0613104c2.tar.lz
infinity-for-reddit-a476d101510ae4be4d63689d332512e0613104c2.tar.xz
infinity-for-reddit-a476d101510ae4be4d63689d332512e0613104c2.tar.zst
infinity-for-reddit-a476d101510ae4be4d63689d332512e0613104c2.zip
Fix ArrayIndexOutOfBoundsException in FollowedUsersRecyclerViewAdapter. Minor bugs fixed.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java255
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java2
4 files changed, 147 insertions, 122 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java
index 3a81c202..8742ad7c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java
@@ -174,6 +174,10 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
}
private void bindView(boolean initializeFragment) {
+ if (isFinishing() || isDestroyed()) {
+ return;
+ }
+
loadSubscriptions();
if (initializeFragment) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java
index ff6b6875..c62d4ae2 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java
@@ -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) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java
index 05c85ed1..40107a03 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/FollowedUsersRecyclerViewAdapter.java
@@ -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);
+ }
+ });
+ }
+ }
+ });
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java
index 091877cd..e661488c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java
@@ -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;