mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-25 02:18:23 +01:00
Click subreddit names and user names in post content and comment content to start ViewSubredditDetailActiviy and ViewUserDetailActivity respectively. Use Chrome custom tab to open URL in post content and comment content.
This commit is contained in:
parent
047e31936f
commit
86bc381906
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@ -14,9 +14,9 @@ public interface SubredditDao {
|
||||
@Query("DELETE FROM subreddits")
|
||||
void deleteAllSubreddits();
|
||||
|
||||
@Query("SELECT * from subreddits WHERE name = :namePrefixed LIMIT 1")
|
||||
@Query("SELECT * from subreddits WHERE name = :namePrefixed COLLATE NOCASE LIMIT 1")
|
||||
LiveData<SubredditData> getSubredditLiveDataByName(String namePrefixed);
|
||||
|
||||
@Query("SELECT * from subreddits WHERE name = :namePrefixed LIMIT 1")
|
||||
@Query("SELECT * from subreddits WHERE name = :namePrefixed COLLATE NOCASE LIMIT 1")
|
||||
SubredditData getSubredditData(String namePrefixed);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public interface SubscribedSubredditDao {
|
||||
@Query("SELECT * from subscribed_subreddits ORDER BY name COLLATE NOCASE ASC")
|
||||
LiveData<List<SubscribedSubredditData>> getAllSubscribedSubreddits();
|
||||
|
||||
@Query("SELECT * from subscribed_subreddits WHERE name = :subredditName LIMIT 1")
|
||||
@Query("SELECT * from subscribed_subreddits WHERE name = :subredditName COLLATE NOCASE LIMIT 1")
|
||||
SubscribedSubredditData getSubscribedSubreddit(String subredditName);
|
||||
|
||||
@Query("DELETE FROM subscribed_subreddits WHERE name = :subredditName")
|
||||
|
@ -19,7 +19,7 @@ public interface SubscribedUserDao {
|
||||
@Query("SELECT * FROM subscribed_users ORDER BY name COLLATE NOCASE ASC")
|
||||
LiveData<List<SubscribedUserData>> getAllSubscribedUsers();
|
||||
|
||||
@Query("SELECT * FROM subscribed_users WHERE name = :userName LIMIT 1")
|
||||
@Query("SELECT * FROM subscribed_users WHERE name = :userName COLLATE NOCASE LIMIT 1")
|
||||
SubscribedUserData getSubscribedUser(String userName);
|
||||
|
||||
@Query("DELETE FROM subscribed_users WHERE name = :userName")
|
||||
|
@ -14,9 +14,9 @@ public interface UserDao {
|
||||
@Query("DELETE FROM users")
|
||||
void deleteAllUsers();
|
||||
|
||||
@Query("SELECT * FROM users WHERE name = :userName LIMIT 1")
|
||||
@Query("SELECT * FROM users WHERE name = :userName COLLATE NOCASE LIMIT 1")
|
||||
LiveData<UserData> getUserLiveData(String userName);
|
||||
|
||||
@Query("SELECT * FROM users WHERE name = :userName LIMIT 1")
|
||||
@Query("SELECT * FROM users WHERE name = :userName COLLATE NOCASE LIMIT 1")
|
||||
UserData getUserData(String userName);
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package ml.docilealligator.infinityforreddit;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.customtabs.CustomTabsIntent;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
@ -25,6 +28,7 @@ import java.util.Locale;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import retrofit2.Retrofit;
|
||||
import ru.noties.markwon.SpannableConfiguration;
|
||||
import ru.noties.markwon.view.MarkwonView;
|
||||
|
||||
class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
||||
@ -66,7 +70,26 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
||||
|
||||
((CommentViewHolder) holder).authorTextView.setText(commentItem.getAuthor());
|
||||
((CommentViewHolder) holder).commentTimeTextView.setText(commentItem.getCommentTime());
|
||||
((CommentViewHolder) holder).commentMarkdownView.setMarkdown(commentItem.getCommentContent());
|
||||
SpannableConfiguration spannableConfiguration = SpannableConfiguration.builder(mContext).linkResolver((view, link) -> {
|
||||
if(link.startsWith("/u/")) {
|
||||
Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
|
||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, link.substring(3));
|
||||
mContext.startActivity(intent);
|
||||
} else if(link.startsWith("/r/")) {
|
||||
Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
|
||||
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, link.substring(3));
|
||||
mContext.startActivity(intent);
|
||||
} else {
|
||||
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
|
||||
// add share action to menu list
|
||||
builder.addDefaultShareMenuItem();
|
||||
builder.setToolbarColor(mContext.getResources().getColor(R.color.colorPrimary));
|
||||
CustomTabsIntent customTabsIntent = builder.build();
|
||||
customTabsIntent.launchUrl(mContext, Uri.parse(link));
|
||||
}
|
||||
}).build();
|
||||
|
||||
((CommentViewHolder) holder).commentMarkdownView.setMarkdown(spannableConfiguration, commentItem.getCommentContent());
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore()));
|
||||
|
||||
((CommentViewHolder) holder).verticalBlock.getLayoutParams().width = commentItem.getDepth() * 16;
|
||||
@ -74,9 +97,7 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
||||
setExpandButton(((CommentViewHolder) holder).expandButton, commentItem.isExpanded());
|
||||
}
|
||||
|
||||
((CommentViewHolder) holder).expandButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
((CommentViewHolder) holder).expandButton.setOnClickListener(view -> {
|
||||
if(commentItem.hasChildren() && commentItem.getChildren().size() > 0) {
|
||||
mMultiLevelRecyclerView.toggleItemsGroup(holder.getAdapterPosition());
|
||||
setExpandButton(((CommentViewHolder) holder).expandButton, commentItem.isExpanded());
|
||||
@ -112,7 +133,6 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
switch (commentItem.getVoteType()) {
|
||||
@ -126,9 +146,7 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
||||
break;
|
||||
}
|
||||
|
||||
((CommentViewHolder) holder).upvoteButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
((CommentViewHolder) holder).upvoteButton.setOnClickListener(view -> {
|
||||
final boolean isDownvotedBefore = ((CommentViewHolder) holder).downvoteButton.getColorFilter() != null;
|
||||
final ColorFilter minusButtonColorFilter = ((CommentViewHolder) holder).downvoteButton.getColorFilter();
|
||||
((CommentViewHolder) holder).downvoteButton.clearColorFilter();
|
||||
@ -143,7 +161,7 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
||||
|
||||
VoteThing.voteThing(mOauthRetrofit,mSharedPreferences, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position) {
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
commentItem.setVoteType(1);
|
||||
if(isDownvotedBefore) {
|
||||
commentItem.setScore(commentItem.getScore() + 2);
|
||||
@ -153,7 +171,7 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVoteThingFail(int position) {
|
||||
public void onVoteThingFail(int position1) {
|
||||
Toast.makeText(mContext, "Cannot upvote this comment", Toast.LENGTH_SHORT).show();
|
||||
((CommentViewHolder) holder).upvoteButton.clearColorFilter();
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore()));
|
||||
@ -167,13 +185,13 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
||||
|
||||
VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position) {
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
commentItem.setVoteType(0);
|
||||
commentItem.setScore(commentItem.getScore() - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVoteThingFail(int position) {
|
||||
public void onVoteThingFail(int position1) {
|
||||
Toast.makeText(mContext, "Cannot unvote this comment", Toast.LENGTH_SHORT).show();
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore() + 1));
|
||||
((CommentViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
@ -181,12 +199,9 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
||||
}
|
||||
}, commentItem.getFullName(), RedditUtils.DIR_UNVOTE, ((CommentViewHolder) holder).getAdapterPosition());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
((CommentViewHolder) holder).downvoteButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
((CommentViewHolder) holder).downvoteButton.setOnClickListener(view -> {
|
||||
final boolean isUpvotedBefore = ((CommentViewHolder) holder).upvoteButton.getColorFilter() != null;
|
||||
|
||||
final ColorFilter upvoteButtonColorFilter = ((CommentViewHolder) holder).upvoteButton.getColorFilter();
|
||||
@ -202,7 +217,7 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
||||
|
||||
VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position) {
|
||||
public void onVoteThingSuccess(int position12) {
|
||||
commentItem.setVoteType(-1);
|
||||
if(isUpvotedBefore) {
|
||||
commentItem.setScore(commentItem.getScore() - 2);
|
||||
@ -212,7 +227,7 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVoteThingFail(int position) {
|
||||
public void onVoteThingFail(int position12) {
|
||||
Toast.makeText(mContext, "Cannot downvote this comment", Toast.LENGTH_SHORT).show();
|
||||
((CommentViewHolder) holder).downvoteButton.clearColorFilter();
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore()));
|
||||
@ -226,13 +241,13 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
||||
|
||||
VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position) {
|
||||
public void onVoteThingSuccess(int position12) {
|
||||
commentItem.setVoteType(0);
|
||||
commentItem.setScore(commentItem.getScore());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVoteThingFail(int position) {
|
||||
public void onVoteThingFail(int position12) {
|
||||
Toast.makeText(mContext, "Cannot unvote this comment", Toast.LENGTH_SHORT).show();
|
||||
((CommentViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore()));
|
||||
@ -240,7 +255,6 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
|
||||
}
|
||||
}, commentItem.getFullName(), RedditUtils.DIR_UNVOTE, holder.getAdapterPosition());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -43,20 +43,27 @@ class ParseSubredditData {
|
||||
String id = data.getString(JSONUtils.NAME_KEY);
|
||||
String subredditFullName = data.getString(JSONUtils.DISPLAY_NAME);
|
||||
String description = data.getString(JSONUtils.PUBLIC_DESCRIPTION_KEY).trim();
|
||||
String bannerImageUrl = data.getString(JSONUtils.BANNER_BACKGROUND_IMAGE_KEY);
|
||||
if(bannerImageUrl.equals("") || bannerImageUrl.equals("null")) {
|
||||
bannerImageUrl= data.getString(JSONUtils.BANNER_IMG_KEY);
|
||||
if(bannerImageUrl.equals("null")) {
|
||||
|
||||
String bannerImageUrl;
|
||||
if(data.isNull(JSONUtils.BANNER_BACKGROUND_IMAGE_KEY)) {
|
||||
bannerImageUrl = "";
|
||||
} else {
|
||||
bannerImageUrl = data.getString(JSONUtils.BANNER_BACKGROUND_IMAGE_KEY);
|
||||
}
|
||||
if(bannerImageUrl.equals("") && !data.isNull(JSONUtils.BANNER_IMG_KEY)) {
|
||||
bannerImageUrl= data.getString(JSONUtils.BANNER_IMG_KEY);
|
||||
}
|
||||
String iconUrl = data.getString(JSONUtils.COMMUNITY_ICON_KEY);
|
||||
if(iconUrl.equals("") || iconUrl.equals("null")) {
|
||||
iconUrl = data.getString(JSONUtils.ICON_IMG_KEY);
|
||||
if(iconUrl.equals("null")) {
|
||||
|
||||
String iconUrl;
|
||||
if(data.isNull(JSONUtils.COMMUNITY_ICON_KEY)) {
|
||||
iconUrl = "";
|
||||
} else {
|
||||
iconUrl = data.getString(JSONUtils.COMMUNITY_ICON_KEY);
|
||||
}
|
||||
if(iconUrl.equals("") && !data.isNull(JSONUtils.ICON_IMG_KEY)) {
|
||||
iconUrl = data.getString(JSONUtils.ICON_IMG_KEY);
|
||||
}
|
||||
|
||||
int nSubscribers = data.getInt(JSONUtils.SUBSCRIBERS_KEY);
|
||||
int nCurrentOnlineSubscribers = data.getInt(JSONUtils.ACTIVE_USER_COUNT_KEY);
|
||||
subredditData = new SubredditData(id, subredditFullName, iconUrl, bannerImageUrl, description, nSubscribers);
|
||||
|
@ -49,6 +49,7 @@ import butterknife.ButterKnife;
|
||||
import de.hdodenhof.circleimageview.CircleImageView;
|
||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||
import retrofit2.Retrofit;
|
||||
import ru.noties.markwon.SpannableConfiguration;
|
||||
import ru.noties.markwon.view.MarkwonView;
|
||||
|
||||
public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
@ -269,7 +270,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
mTypeChip.setText("LINK");
|
||||
if(!mPost.getSelfText().equals("")) {
|
||||
mContentMarkdownView.setVisibility(View.VISIBLE);
|
||||
mContentMarkdownView.setMarkdown(mPost.getSelfText());
|
||||
mContentMarkdownView.setMarkdown(getCustomSpannableConfiguration(), mPost.getSelfText());
|
||||
}
|
||||
mNoPreviewLinkImageView.setVisibility(View.VISIBLE);
|
||||
mNoPreviewLinkImageView.setOnClickListener(view -> {
|
||||
@ -285,7 +286,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
mTypeChip.setVisibility(View.GONE);
|
||||
if(!mPost.getSelfText().equals("")) {
|
||||
mContentMarkdownView.setVisibility(View.VISIBLE);
|
||||
mContentMarkdownView.setMarkdown(mPost.getSelfText());
|
||||
mContentMarkdownView.setMarkdown(getCustomSpannableConfiguration(), mPost.getSelfText());
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -482,6 +483,27 @@ public class ViewPostDetailActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private SpannableConfiguration getCustomSpannableConfiguration() {
|
||||
return SpannableConfiguration.builder(this).linkResolver((view, link) -> {
|
||||
if(link.startsWith("/u/")) {
|
||||
Intent intent = new Intent(ViewPostDetailActivity.this, ViewUserDetailActivity.class);
|
||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, link.substring(3));
|
||||
startActivity(intent);
|
||||
} else if(link.startsWith("/r/")) {
|
||||
Intent intent = new Intent(ViewPostDetailActivity.this, ViewSubredditDetailActivity.class);
|
||||
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, link.substring(3));
|
||||
startActivity(intent);
|
||||
} else {
|
||||
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
|
||||
// add share action to menu list
|
||||
builder.addDefaultShareMenuItem();
|
||||
builder.setToolbarColor(getResources().getColor(R.color.colorPrimary));
|
||||
CustomTabsIntent customTabsIntent = builder.build();
|
||||
customTabsIntent.launchUrl(ViewPostDetailActivity.this, Uri.parse(link));
|
||||
}
|
||||
}).build();
|
||||
}
|
||||
|
||||
private void showRetrySnackbar() {
|
||||
Snackbar snackbar = Snackbar.make(mCoordinatorLayout, R.string.load_comment_failed, Snackbar.LENGTH_INDEFINITE);
|
||||
snackbar.setAction(R.string.retry, new View.OnClickListener() {
|
||||
|
@ -104,8 +104,9 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
|
||||
params.topMargin = statusBarHeight;
|
||||
|
||||
String subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME_KEY);
|
||||
|
||||
String title = "r/" + subredditName;
|
||||
subredditNameTextView.setText(title);
|
||||
|
||||
CollapsingToolbarLayout collapsingToolbarLayout = findViewById(R.id.collapsing_toolbar_layout_view_subreddit_detail_activity);
|
||||
AppBarLayout appBarLayout = findViewById(R.id.app_bar_layout_view_subreddit_detail_activity);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user