Add option to share links on local instance

This commit is contained in:
Balazs Toldi 2023-08-23 21:14:53 +02:00
parent d9f9fb51db
commit a09d6f85f8
No known key found for this signature in database
GPG Key ID: 6C7D440036F99D58
17 changed files with 94 additions and 63 deletions

View File

@ -504,7 +504,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
}
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, mAccessToken, mOauthRetrofit, mRetrofit.getRetrofit(), iconImageUrl -> {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, mAccessToken, mRetrofit.getRetrofit(), iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;

View File

@ -511,7 +511,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
}
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, communityData.getQualified_name(), mAccessToken, mOauthRetrofit, mRetrofit.getRetrofit(), iconImageUrl -> {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, communityData.getQualified_name(), mAccessToken, mRetrofit.getRetrofit(), iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;

View File

@ -489,7 +489,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, communityData.getQualified_name(),
mAccessToken, mOauthRetrofit, mRetrofit.getRetrofit(), iconImageUrl -> {
mAccessToken, mRetrofit.getRetrofit(), iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;

View File

@ -500,7 +500,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
}
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, mAccessToken, mOauthRetrofit, mRetrofit.getRetrofit(), iconImageUrl -> {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName, mAccessToken, mRetrofit.getRetrofit(), iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;

View File

@ -451,7 +451,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, communityData.getQualified_name(),
mAccessToken, mOauthRetrofit, mRetrofit.getRetrofit(), iconImageUrl -> {
mAccessToken, mRetrofit.getRetrofit(), iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;

View File

@ -486,7 +486,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName,
mAccessToken, mOauthRetrofit, mRetrofit.getRetrofit(), iconImageUrl -> {
mAccessToken, mRetrofit.getRetrofit(), iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;

View File

@ -499,7 +499,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
private void loadSubredditIcon() {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase, subredditName,
mAccessToken, mOauthRetrofit, mRetrofit.getRetrofit(), iconImageUrl -> {
mAccessToken, mRetrofit.getRetrofit(), iconImageUrl -> {
iconUrl = iconImageUrl;
displaySubredditIcon();
loadSubredditIconSuccessful = true;

View File

@ -67,6 +67,7 @@ import eu.toldi.infinityforlemmy.FetchGfycatOrRedgifsVideoLinks;
import eu.toldi.infinityforlemmy.FetchStreamableVideo;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
import eu.toldi.infinityforlemmy.RetrofitHolder;
import eu.toldi.infinityforlemmy.SaveMemoryCenterInisdeDownsampleStrategy;
import eu.toldi.infinityforlemmy.SavePost;
import eu.toldi.infinityforlemmy.SaveThing;
@ -135,8 +136,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private BaseActivity mActivity;
private ViewPostDetailFragment mFragment;
private Executor mExecutor;
private Retrofit mRetrofit;
private Retrofit mOauthRetrofit;
private RetrofitHolder mRetrofit;
private Retrofit mGfycatRetrofit;
private Retrofit mRedgifsRetrofit;
private final Provider<StreamableAPI> mStreamableApiProvider;
@ -172,6 +172,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
private boolean mHideUpvoteRatio;
private boolean mHideTheNumberOfAwards;
private boolean mHideSubredditAndUserPrefix;
private boolean mShareOnLocalInstance;
private boolean mShowDisplayNames;
private boolean mHideTheNumberOfVotes;
@ -223,7 +224,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
public PostDetailRecyclerViewAdapter(BaseActivity activity, ViewPostDetailFragment fragment,
Executor executor, CustomThemeWrapper customThemeWrapper,
Retrofit retrofit, Retrofit gfycatRetrofit,
RetrofitHolder retrofit, Retrofit gfycatRetrofit,
Retrofit redgifsRetrofit, Provider<StreamableAPI> streamableApiProvider,
RedditDataRoomDatabase redditDataRoomDatabase, RequestManager glide,
boolean separatePostAndComments, String accessToken,
@ -347,6 +348,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mHideUpvoteRatio = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_UPVOTE_RATIO, false);
mHideTheNumberOfAwards = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_AWARDS, false);
mHideSubredditAndUserPrefix = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_SUBREDDIT_AND_USER_PREFIX, false);
mShareOnLocalInstance = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.SHARE_LINK_ON_LOCAL_INSTANCE, false);
mShowDisplayNames = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.POST_DETAIL_DISPLAY_NAME_INSTEAD_OF_USERNAME, true);
mHideTheNumberOfVotes = postDetailsSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES, false);
mHideDownvotes = !currentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, true);
@ -485,7 +487,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailBaseViewHolder) holder).mTitleTextView.setText(mPost.getTitle());
if (mPost.getSubredditNamePrefixed().startsWith("u/")) {
if (mPost.getAuthorIconUrl() == null) {
LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase,mPost.getAuthorNamePrefixed(), mOauthRetrofit, iconImageUrl -> {
LoadUserData.loadUserData(mExecutor, new Handler(), mRedditDataRoomDatabase, mPost.getAuthorNamePrefixed(), mRetrofit.getRetrofit(), iconImageUrl -> {
if (mActivity != null && getItemCount() > 0) {
if (iconImageUrl == null || iconImageUrl.equals("")) {
mGlide.load(R.drawable.subreddit_default_icon)
@ -519,7 +521,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
if (mPost.getSubredditIconUrl() == null) {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(),
mRedditDataRoomDatabase, mPost.getSubredditNamePrefixed(),
mAccessToken, mOauthRetrofit, mRetrofit, iconImageUrl -> {
mAccessToken, mRetrofit.getRetrofit(), iconImageUrl -> {
if (iconImageUrl == null || iconImageUrl.equals("")) {
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
@ -1385,7 +1387,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
VoteThing.votePost(mActivity, mRetrofit, mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
VoteThing.votePost(mActivity, mRetrofit.getRetrofit(), mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
@Override
public void onVoteThingSuccess() {
if (newVoteType == Integer.parseInt(APIUtils.DIR_UPVOTE)) {
@ -1491,13 +1493,13 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mPostDetailRecyclerViewAdapterCallback.updatePost(mPost);
VoteThing.votePost(mActivity, mRetrofit, mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
VoteThing.votePost(mActivity, mRetrofit.getRetrofit(), mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
@Override
public void onVoteThingSuccess() {
if (newVoteType == Integer.parseInt(APIUtils.DIR_DOWNVOTE)) {
mPost.setVoteType(-1);
mDownvoteButton.setColorFilter(mDownvotedColor, PorterDuff.Mode.SRC_IN);
if(mSeperateUpvoteAndDownvote) {
if (mSeperateUpvoteAndDownvote) {
mDownvoteTextView.setTextColor(mDownvotedColor);
} else {
mScoreTextView.setTextColor(mDownvotedColor);
@ -1587,7 +1589,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
SavePost savePost = new SavePost();
if (mPost.isSaved()) {
mSaveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
savePost.unsaveThing(mRetrofit, mAccessToken, mPost.getId(),
savePost.unsaveThing(mRetrofit.getRetrofit(), mAccessToken, mPost.getId(),
new SaveThing.SaveThingListener() {
@Override
public void success() {
@ -1607,7 +1609,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
});
} else {
mSaveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
savePost.saveThing(mRetrofit, mAccessToken, mPost.getId(),
savePost.saveThing(mRetrofit.getRetrofit(), mAccessToken, mPost.getId(),
new SaveThing.SaveThingListener() {
@Override
public void success() {
@ -1629,8 +1631,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
});
mShareButton.setOnClickListener(view -> {
String link = (mShareOnLocalInstance) ? mRetrofit.getBaseURL() + "/post/" + mPost.getId() : mPost.getPermalink();
Bundle bundle = new Bundle();
bundle.putString(ShareLinkBottomSheetFragment.EXTRA_POST_LINK, mPost.getPermalink());
bundle.putString(ShareLinkBottomSheetFragment.EXTRA_POST_LINK, link);
if (mPost.getPostType() != Post.TEXT_TYPE) {
bundle.putInt(ShareLinkBottomSheetFragment.EXTRA_MEDIA_TYPE, mPost.getPostType());
switch (mPost.getPostType()) {
@ -1651,7 +1654,8 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
});
mShareButton.setOnLongClickListener(view -> {
mActivity.copyLink(mPost.getPermalink());
String link = (mShareOnLocalInstance) ? mRetrofit.getBaseURL() + "/post/" + mPost.getId() : mPost.getPermalink();
mActivity.copyLink(link);
return true;
});

View File

@ -71,6 +71,7 @@ import eu.toldi.infinityforlemmy.FetchGfycatOrRedgifsVideoLinks;
import eu.toldi.infinityforlemmy.FetchStreamableVideo;
import eu.toldi.infinityforlemmy.MarkPostAsReadInterface;
import eu.toldi.infinityforlemmy.R;
import eu.toldi.infinityforlemmy.RetrofitHolder;
import eu.toldi.infinityforlemmy.SaveMemoryCenterInisdeDownsampleStrategy;
import eu.toldi.infinityforlemmy.SavePost;
import eu.toldi.infinityforlemmy.SaveThing;
@ -150,7 +151,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
private SharedPreferences mSharedPreferences;
private SharedPreferences mCurrentAccountSharedPreferences;
private Executor mExecutor;
private Retrofit retrofit;
private RetrofitHolder retrofit;
private Retrofit mGfycatRetrofit;
private Retrofit mRedgifsRetrofit;
private Provider<StreamableAPI> mStreamableApiProvider;
@ -230,6 +231,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
private boolean mShowDisplayNames;
private boolean mHideTheNumberOfVotes;
private boolean mShareLinkOnLocalInstance;
private boolean mSeparateUpandDownVotes;
private boolean mHideDownvotes;
@ -244,7 +247,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
private boolean canPlayVideo = true;
private RecyclerView.RecycledViewPool mGalleryRecycledViewPool;
public PostRecyclerViewAdapter(BaseActivity activity, PostFragment fragment, Executor executor, Retrofit oauthRetrofit,
public PostRecyclerViewAdapter(BaseActivity activity, PostFragment fragment, Executor executor, RetrofitHolder retrofit,
Retrofit gfycatRetrofit, Retrofit redgifsRetrofit, Provider<StreamableAPI> streamableApiProvider,
CustomThemeWrapper customThemeWrapper, Locale locale,
String accessToken, String accountName, int postType, int postLayout, boolean displaySubredditName,
@ -259,7 +262,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
mSharedPreferences = sharedPreferences;
mCurrentAccountSharedPreferences = currentAccountSharedPreferences;
mExecutor = executor;
retrofit = oauthRetrofit;
this.retrofit = retrofit;
mGfycatRetrofit = gfycatRetrofit;
mRedgifsRetrofit = redgifsRetrofit;
mStreamableApiProvider = streamableApiProvider;
@ -316,6 +319,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
mHideSubredditAndUserPrefix = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_SUBREDDIT_AND_USER_PREFIX, false);
mShowDisplayNames = sharedPreferences.getBoolean(SharedPreferencesUtils.POST_DISPLAY_NAME_INSTEAD_OF_USERNAME, true);
mHideTheNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_VOTES, false);
mShareLinkOnLocalInstance = sharedPreferences.getBoolean(SharedPreferencesUtils.SHARE_LINK_ON_LOCAL_INSTANCE, false);
mHideDownvotes = !currentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, true);
mSeparateUpandDownVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.POST_SEPARATE_UP_AND_DOWN_VOTES, true) && !mHideDownvotes;
mHideTheNumberOfComments = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_THE_NUMBER_OF_COMMENTS, false);
@ -1893,8 +1897,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
private void shareLink(Post post) {
String link = (mShareLinkOnLocalInstance) ? retrofit.getBaseURL() + "/post/" + post.getId() : post.getPermalink();
Bundle bundle = new Bundle();
bundle.putString(ShareLinkBottomSheetFragment.EXTRA_POST_LINK, post.getPermalink());
bundle.putString(ShareLinkBottomSheetFragment.EXTRA_POST_LINK, link);
if (post.getPostType() != Post.TEXT_TYPE) {
bundle.putInt(ShareLinkBottomSheetFragment.EXTRA_MEDIA_TYPE, post.getPostType());
switch (post.getPostType()) {
@ -2666,7 +2671,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
}
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.votePost(mActivity, retrofit.getRetrofit(), mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();
@ -2782,7 +2787,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
}
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.votePost(mActivity, retrofit.getRetrofit(), mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();
@ -2790,9 +2795,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
post.setVoteType(-1);
if (currentPosition == position) {
downvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
if(mSeparateUpandDownVotes){
if (mSeparateUpandDownVotes) {
downvoteTextView.setTextColor(mDownvotedColor);
}else {
} else {
scoreTextView.setTextColor(mDownvotedColor);
}
}
@ -2855,7 +2860,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
SavePost savePost = new SavePost();
if (post.isSaved()) {
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
savePost.unsaveThing(retrofit, mAccessToken, post.getId(),
savePost.unsaveThing(retrofit.getRetrofit(), mAccessToken, post.getId(),
new SaveThing.SaveThingListener() {
@Override
public void success() {
@ -2879,7 +2884,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
});
} else {
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
savePost.saveThing(retrofit, mAccessToken, post.getId(),
savePost.saveThing(retrofit.getRetrofit(), mAccessToken, post.getId(),
new SaveThing.SaveThingListener() {
@Override
public void success() {
@ -2923,7 +2928,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
Post post = getItem(position);
if (post != null) {
mActivity.copyLink(post.getPermalink());
String link = (mShareLinkOnLocalInstance) ? retrofit.getBaseURL() + "/post/" + post.getId() : post.getPermalink();
mActivity.copyLink(link);
return true;
}
return false;
@ -4118,7 +4124,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
}
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.votePost(mActivity, retrofit.getRetrofit(), mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();
@ -4224,7 +4230,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
}
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
VoteThing.votePost(mActivity, retrofit.getRetrofit(), mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
int currentPosition = getBindingAdapterPosition();
@ -4232,7 +4238,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
post.setVoteType(-1);
if (currentPosition == position) {
downvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
if(mSeparateUpandDownVotes) {
if (mSeparateUpandDownVotes) {
downvoteTextView.setTextColor(mDownvotedColor);
} else {
scoreTextView.setTextColor(mDownvotedColor);
@ -4297,7 +4303,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
SavePost postSave = new SavePost();
if (post.isSaved()) {
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
postSave.unsaveThing(retrofit, mAccessToken, post.getId(),
postSave.unsaveThing(retrofit.getRetrofit(), mAccessToken, post.getId(),
new SaveThing.SaveThingListener() {
@Override
public void success() {
@ -4321,7 +4327,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
});
} else {
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
postSave.saveThing(retrofit, mAccessToken, post.getId(),
postSave.saveThing(retrofit.getRetrofit(), mAccessToken, post.getId(),
new SaveThing.SaveThingListener() {
@Override
public void success() {
@ -4365,7 +4371,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
Post post = getItem(position);
if (post != null) {
mActivity.copyLink(post.getPermalink());
String link = (mShareLinkOnLocalInstance) ? retrofit.getBaseURL() + "/post/" + post.getId() : post.getPermalink();
mActivity.copyLink(link);
return true;
}
return false;

View File

@ -15,7 +15,7 @@ import retrofit2.Retrofit;
public class LoadSubredditIcon {
public static void loadSubredditIcon(Executor executor, Handler handler, RedditDataRoomDatabase redditDataRoomDatabase,
String subredditName, String accessToken, Retrofit oauthRetrofit, Retrofit retrofit,
String subredditName, String accessToken, Retrofit retrofit,
LoadSubredditIconAsyncTaskListener loadSubredditIconAsyncTaskListener) {
executor.execute(() -> {
SubredditDao subredditDao = redditDataRoomDatabase.subredditDao();

View File

@ -4,6 +4,7 @@ package eu.toldi.infinityforlemmy.bottomsheetfragments;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
@ -23,6 +24,7 @@ import androidx.fragment.app.Fragment;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
@ -37,6 +39,7 @@ import eu.toldi.infinityforlemmy.comment.Comment;
import eu.toldi.infinityforlemmy.comment.LemmyCommentAPI;
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils;
@ -72,8 +75,14 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
@Inject
CustomThemeWrapper mCustomThemeWrapper;
@Inject
@Named("default")
SharedPreferences mSharedPreferences;
private BaseActivity activity;
private boolean mShareLinksOnLocalInstance;
public CommentMoreBottomSheetFragment() {
// Required empty public constructor
}
@ -103,6 +112,7 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
String accessToken = bundle.getString(EXTRA_ACCESS_TOKEN);
boolean editAndDeleteAvailable = bundle.getBoolean(EXTRA_EDIT_AND_DELETE_AVAILABLE, false);
boolean showReplyAndSaveOption = bundle.getBoolean(EXTRA_SHOW_REPLY_AND_SAVE_OPTION, false);
mShareLinksOnLocalInstance = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHARE_LINK_ON_LOCAL_INSTANCE, false);
if (accessToken != null && !accessToken.equals("")) {
@ -167,13 +177,13 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
dismiss();
});
}
String link = (mShareLinksOnLocalInstance) ? lemmyCommentAPI.getRetrofitHolder().getBaseURL() + "/comment/" + comment.getId() : comment.getPermalink();
shareTextView.setOnClickListener(view -> {
dismiss();
try {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, comment.getPermalink());
intent.putExtra(Intent.EXTRA_TEXT, link);
activity.startActivity(Intent.createChooser(intent, getString(R.string.share)));
} catch (ActivityNotFoundException e) {
Toast.makeText(activity, R.string.no_activity_found_for_share, Toast.LENGTH_SHORT).show();
@ -182,7 +192,7 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
shareTextView.setOnLongClickListener(view -> {
dismiss();
activity.copyLink(comment.getPermalink());
activity.copyLink(link);
return true;
});

View File

@ -933,7 +933,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
} else {
if (isSubreddit) {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase,
subredditOrUserName, accessToken, mOauthRetrofit, mRetrofit.getRetrofit(),
subredditOrUserName, accessToken, mRetrofit.getRetrofit(),
iconImageUrl -> {
subredditOrUserIcons.put(subredditOrUserName, iconImageUrl);
loadIconListener.loadIconSuccess(subredditOrUserName, iconImageUrl);

View File

@ -465,7 +465,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
sortType = new SortType(st == null ? SortType.Type.TOP_ALL : st,sortTime != null ? SortType.Time.valueOf(sortTime) : null);
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, defaultPostLayout);
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit.getRetrofit(), mGfycatRetrofit,
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
accessToken, accountName, postType, postLayout, true,
mSharedPreferences, mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
@ -542,7 +542,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
sortType = new SortType(SortType.Type.valueOf(sort));
}
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit.getRetrofit(), mGfycatRetrofit,
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
accessToken, accountName, postType, postLayout, displaySubredditName,
mSharedPreferences, mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
@ -613,7 +613,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
sortType = new SortType(SortType.Type.valueOf(sort));
}
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit.getRetrofit(), mGfycatRetrofit,
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
accessToken, accountName, postType, postLayout, true,
mSharedPreferences, mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
@ -678,7 +678,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, defaultPostLayout);
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit.getRetrofit(), mGfycatRetrofit,
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
accessToken, accountName, postType, postLayout, true,
mSharedPreferences, mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
@ -741,7 +741,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit.getRetrofit(), mGfycatRetrofit,
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
accessToken, accountName, postType, postLayout, true,
mSharedPreferences, mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
@ -801,7 +801,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath, defaultPostLayout);
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit.getRetrofit(), mGfycatRetrofit,
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
accessToken, accountName, postType, postLayout, true,
mSharedPreferences, mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
@ -858,7 +858,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit.getRetrofit(), mGfycatRetrofit,
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
accessToken, accountName, postType, postLayout, true,
mSharedPreferences, mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
@ -1750,7 +1750,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
} else {
if (isSubreddit) {
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(), mRedditDataRoomDatabase,
subredditOrUserName, accessToken, mRetrofit.getRetrofit(), mRetrofit.getRetrofit(),
subredditOrUserName, accessToken, mRetrofit.getRetrofit(),
iconImageUrl -> {
subredditOrUserIcons.put(subredditOrUserName, iconImageUrl);
loadIconListener.loadIconSuccess(subredditOrUserName, iconImageUrl);

View File

@ -614,7 +614,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
setupMenu();
mPostAdapter = new PostDetailRecyclerViewAdapter(activity,
this, mExecutor, mCustomThemeWrapper, mRetrofit.getRetrofit(), mGfycatRetrofit,
this, mExecutor, mCustomThemeWrapper, mRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mStreamableApiProvider, mRedditDataRoomDatabase, mGlide,
mSeparatePostAndComments, mAccessToken, mAccountName, mPost, mLocale,
mSharedPreferences, mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostDetailsSharedPreferences,
@ -1338,7 +1338,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
mPost = post;
mPostAdapter = new PostDetailRecyclerViewAdapter(activity,
ViewPostDetailFragment.this, mExecutor, mCustomThemeWrapper,
mRetrofit.getRetrofit(), mGfycatRetrofit, mRedgifsRetrofit,
mRetrofit, mGfycatRetrofit, mRedgifsRetrofit,
mStreamableApiProvider, mRedditDataRoomDatabase, mGlide, mSeparatePostAndComments,
mAccessToken, mAccountName, mPost, mLocale, mSharedPreferences,
mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences,

View File

@ -416,4 +416,6 @@ public class SharedPreferencesUtils {
public static final String CAN_DOWNVOTE = "can_downvote";
public static final String SHOW_STATISTICS = "show_statistics";
public static final String SHOW_POST_AND_COMMENT_SCORE = "show_score";
public static final String SHARE_LINK_ON_LOCAL_INSTANCE = "share_link_on_local_instance";
}

View File

@ -1383,4 +1383,6 @@
<string name="moderators">Moderators</string>
<string name="admins">Admins</string>
<string name="settings_hide_user_instance">Hide user instance</string>
<string name="share_links_on_your_local_instance_rather_than_the_original_creation_instance">Share links on your local instance rather than the original creation instance.</string>
<string name="share_links_on_your_local_instance">Share links on your local instance</string>
</resources>

View File

@ -46,6 +46,12 @@
app:title="@string/anonymous_account_instance"
app:useSimpleSummaryProvider="true" />
<eu.toldi.infinityforlemmy.customviews.CustomFontSwitchPreference
app:defaultValue="false"
app:key="share_link_on_local_instance"
app:title="@string/share_links_on_your_local_instance"
app:summary="@string/share_links_on_your_local_instance_rather_than_the_original_creation_instance" />
<eu.toldi.infinityforlemmy.customviews.CustomFontPreferenceCategory app:title="@string/settings_miscellaneous_dangerous_group_title" />
<eu.toldi.infinityforlemmy.customviews.CustomFontPreference