If an author is deleted and is clicked, don't switch to view user (#1287)

* If an author is deleted and is clicked, don't switch to the view user detail activity, since it'll just error.

* Fix a canStartActivity check.
This commit is contained in:
cmp 2022-12-23 15:38:00 -06:00 committed by GitHub
parent 206296db5e
commit c0deb78734
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 68 additions and 32 deletions

View File

@ -195,6 +195,9 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
if (privateMessage.getAuthor().equals(mAccountName)) {
setTitle(privateMessage.getDestination());
mToolbar.setOnClickListener(view -> {
if (privateMessage.isDestinationDeleted()) {
return;
}
Intent intent = new Intent(this, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, privateMessage.getDestination());
startActivity(intent);
@ -202,6 +205,9 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
} else {
setTitle(privateMessage.getAuthor());
mToolbar.setOnClickListener(view -> {
if (privateMessage.isAuthorDeleted()) {
return;
}
Intent intent = new Intent(this, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, privateMessage.getAuthor());
startActivity(intent);

View File

@ -1584,11 +1584,12 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
authorTextView.setOnClickListener(view -> {
Comment comment = getCurrentComment(this);
if (comment != null) {
if (comment == null || comment.isAuthorDeleted()) {
return;
}
Intent intent = new Intent(mActivity, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, comment.getAuthor());
mActivity.startActivity(intent);
}
});
authorIconImageView.setOnClickListener(view -> {

View File

@ -565,8 +565,8 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
}
} else {
if (post.getAuthorIconUrl() == null) {
String authorName = post.getAuthor().equals("[deleted]") ? post.getSubredditName() : post.getAuthor();
mFragment.loadIcon(authorName, post.getAuthor().equals("[deleted]"), (subredditOrUserName, iconUrl) -> {
String authorName = post.isAuthorDeleted() ? post.getSubredditName() : post.getAuthor();
mFragment.loadIcon(authorName, post.isAuthorDeleted(), (subredditOrUserName, iconUrl) -> {
if (mActivity != null && getItemCount() > 0) {
if (iconUrl == null || iconUrl.equals("") && authorName.equals(subredditOrUserName)) {
mGlide.load(R.drawable.subreddit_default_icon)
@ -1118,8 +1118,8 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
}
} else {
if (post.getAuthorIconUrl() == null) {
String authorName = post.getAuthor().equals("[deleted]") ? post.getSubredditName() : post.getAuthor();
mFragment.loadIcon(authorName, post.getAuthor().equals("[deleted]"), (subredditOrUserName, iconUrl) -> {
String authorName = post.isAuthorDeleted() ? post.getSubredditName() : post.getAuthor();
mFragment.loadIcon(authorName, post.isAuthorDeleted(), (subredditOrUserName, iconUrl) -> {
if (mActivity != null && getItemCount() > 0 && authorName.equals(subredditOrUserName)) {
if (iconUrl == null || iconUrl.equals("")) {
mGlide.load(R.drawable.subreddit_default_icon)
@ -2219,13 +2219,14 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
return;
}
Post post = getItem(position);
if (post != null) {
if (post == null || post.isAuthorDeleted()) {
return;
}
canStartActivity = false;
Intent intent = new Intent(mActivity, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, post.getAuthor());
mActivity.startActivity(intent);
}
}
});
if (mDisplaySubredditName) {
@ -3496,7 +3497,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY,
post.getSubredditName());
mActivity.startActivity(intent);
} else {
} else if (!post.isAuthorDeleted()) {
Intent intent = new Intent(mActivity, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, post.getAuthor());
mActivity.startActivity(intent);

View File

@ -219,6 +219,9 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
});
((DataViewHolder) holder).authorTextView.setOnClickListener(view -> {
if (message.isAuthorDeleted()) {
return;
}
Intent intent = new Intent(mActivity, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, message.getAuthor());
mActivity.startActivity(intent);

View File

@ -466,7 +466,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailBaseViewHolder) holder).mTitleTextView.setText(mPost.getTitle());
if (mPost.getSubredditNamePrefixed().startsWith("u/")) {
if (mPost.getAuthorIconUrl() == null) {
String authorName = mPost.getAuthor().equals("[deleted]") ? mPost.getSubredditNamePrefixed().substring(2) : mPost.getAuthor();
String authorName = mPost.isAuthorDeleted() ? mPost.getSubredditNamePrefixed().substring(2) : mPost.getAuthor();
LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, authorName, mOauthRetrofit, iconImageUrl -> {
if (mActivity != null && getItemCount() > 0) {
if (iconImageUrl == null || iconImageUrl.equals("")) {
@ -1110,6 +1110,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
});
mUserTextView.setOnClickListener(view -> {
if (mPost.isAuthorDeleted()) {
return;
}
Intent intent = new Intent(mActivity, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mPost.getAuthor());
mActivity.startActivity(intent);

View File

@ -596,8 +596,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
} else {
if (post.getAuthorIconUrl() == null) {
String authorName = post.getAuthor().equals("[deleted]") ? post.getSubredditName() : post.getAuthor();
mFragment.loadIcon(authorName, post.getAuthor().equals("[deleted]"), (subredditOrUserName, iconUrl) -> {
String authorName = post.isAuthorDeleted() ? post.getSubredditName() : post.getAuthor();
mFragment.loadIcon(authorName, post.isAuthorDeleted(), (subredditOrUserName, iconUrl) -> {
if (mActivity != null && getItemCount() > 0) {
if (iconUrl == null || iconUrl.equals("") && authorName.equals(subredditOrUserName)) {
mGlide.load(R.drawable.subreddit_default_icon)
@ -1171,8 +1171,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
} else {
if (post.getAuthorIconUrl() == null) {
String authorName = post.getAuthor().equals("[deleted]") ? post.getSubredditName() : post.getAuthor();
mFragment.loadIcon(authorName, post.getAuthor().equals("[deleted]"), (subredditOrUserName, iconUrl) -> {
String authorName = post.isAuthorDeleted() ? post.getSubredditName() : post.getAuthor();
mFragment.loadIcon(authorName, post.isAuthorDeleted(), (subredditOrUserName, iconUrl) -> {
if (mActivity != null && getItemCount() > 0 && authorName.equals(subredditOrUserName)) {
if (iconUrl == null || iconUrl.equals("")) {
mGlide.load(R.drawable.subreddit_default_icon)
@ -2316,19 +2316,21 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
});
userTextView.setOnClickListener(view -> {
if (canStartActivity) {
if (!canStartActivity) {
return;
}
int position = getBindingAdapterPosition();
if (position < 0) {
return;
}
Post post = getItem(position);
if (post != null) {
if (post == null || post.isAuthorDeleted()) {
return;
}
canStartActivity = false;
Intent intent = new Intent(mActivity, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, post.getAuthor());
mActivity.startActivity(intent);
}
}
});
if (mDisplaySubredditName) {
@ -3635,7 +3637,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY,
post.getSubredditName());
mActivity.startActivity(intent);
} else {
} else if (!post.isAuthorDeleted()) {
Intent intent = new Intent(mActivity, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, post.getAuthor());
mActivity.startActivity(intent);

View File

@ -182,6 +182,9 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
});
((ReceivedMessageViewHolder) holder).userAvatarImageView.setOnClickListener(view -> {
if (message.isAuthorDeleted()) {
return;
}
Intent intent = new Intent(mViewPrivateMessagesActivity, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, message.getAuthor());
mViewPrivateMessagesActivity.startActivity(intent);

View File

@ -159,6 +159,10 @@ public class Comment implements Parcelable {
return author;
}
public boolean isAuthorDeleted() {
return author != null && author.equals("[deleted]");
}
public void setAuthor(String author) {
this.author = author;
}

View File

@ -123,10 +123,19 @@ public class Message implements Parcelable {
return author;
}
public boolean isAuthorDeleted() {
return author != null && author.equals("[deleted]");
}
public String getDestination() {
return destination;
}
public boolean isDestinationDeleted()
{
return destination != null && destination.equals("[deleted]");
}
public String getParentFullName() {
return parentFullName;
}

View File

@ -230,6 +230,10 @@ public class Post implements Parcelable {
return author;
}
public boolean isAuthorDeleted() {
return author != null && author.equals("[deleted]");
}
public void setAuthor(String author) {
this.author = author;
this.authorNamePrefixed = "u/" + author;