Anonymous browsing

This commit adds the Anonymous browsing functionality. Unfortunately, the anonymous home page is disabled as of now.
This commit is contained in:
Balazs Toldi 2023-07-28 15:07:45 +02:00
parent df81866821
commit e815a1444d
No known key found for this signature in database
GPG Key ID: 6C7D440036F99D58
13 changed files with 183 additions and 62 deletions

View File

@ -60,6 +60,8 @@ import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
@ -325,9 +327,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
fragmentManager = getSupportFragmentManager();
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
String instance = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_INSTANCE, null);
String instance = (mAccessToken == null) ? mSharedPreferences.getString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, APIUtils.API_BASE_URI) : mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_INSTANCE, null);
if(instance != null) {
mRetrofit.setBaseURL(instance);
}
@ -348,6 +351,17 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
initializeNotificationAndBindView();
}
@Override
protected void onResume() {
super.onResume();
if (mAccessToken == null) {
String instancePreference = mSharedPreferences.getString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, APIUtils.API_BASE_URI);
if (!mRetrofit.getBaseURL().equalsIgnoreCase(instancePreference)) {
this.recreate();
}
}
}
@Override
public SharedPreferences getDefaultSharedPreferences() {
return mSharedPreferences;
@ -858,6 +872,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
startActivity(logOutIntent);
finish();
});
} else if (stringId == R.string.anonymous_account_instance) {
changeAnonymousAccountInstance();
}
if (intent != null) {
startActivity(intent);
@ -1385,6 +1401,72 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
}
private void changeAnonymousAccountInstance() {
View rootView = getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, coordinatorLayout, false);
TextInputEditText thingEditText = rootView.findViewById(R.id.text_input_edit_text_go_to_thing_edit_text);
thingEditText.requestFocus();
thingEditText.setText(mSharedPreferences.getString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, APIUtils.API_BASE_URI));
Utils.showKeyboard(this, new Handler(), thingEditText);
thingEditText.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE) {
Utils.hideKeyboard(this);
String url = thingEditText.getText().toString();
if (url.isEmpty()) {
thingEditText.setError("Instance URL cannot be empty");
return false;
}
if (!url.startsWith("http://") || !url.startsWith("https://")) {
url = "https://" + url;
}
try {
URL urlObj = new URL(url);
url = urlObj.getProtocol() + "://" + urlObj.getHost() + "/";
mSharedPreferences.edit().putString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, url).apply();
mRetrofit.setBaseURL(url);
sectionsPagerAdapter.getCurrentFragment().refresh();
} catch (MalformedURLException e) {
thingEditText.setError("Invalid URL");
return false;
}
return true;
}
return false;
});
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
.setTitle(R.string.anonymous_account_instance)
.setView(rootView)
.setPositiveButton(R.string.ok, (dialogInterface, i)
-> {
Utils.hideKeyboard(this);
String url = thingEditText.getText().toString();
if (url.isEmpty()) {
thingEditText.setError("Instance URL cannot be empty");
return;
}
if (!url.startsWith("http://") && !url.startsWith("https://")) {
url = "https://" + url;
}
try {
URL urlObj = new URL(url);
url = urlObj.getProtocol() + "://" + urlObj.getHost() + "/";
mSharedPreferences.edit().putString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, url).apply();
mRetrofit.setBaseURL(url);
sectionsPagerAdapter.getCurrentFragment().refresh();
} catch (MalformedURLException e) {
thingEditText.setError("Invalid URL");
}
})
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
Utils.hideKeyboard(this);
})
.setOnDismissListener(dialogInterface -> {
Utils.hideKeyboard(this);
})
.show();
}
private void goToSubreddit() {
View rootView = getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, coordinatorLayout, false);
TextInputEditText thingEditText = rootView.findViewById(R.id.text_input_edit_text_go_to_thing_edit_text);
@ -1648,7 +1730,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL) {
PostFragment fragment = new PostFragment();
Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccessToken == null ? PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE : PostPagingSource.TYPE_FRONT_PAGE);
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_FRONT_PAGE);
bundle.putString(PostFragment.EXTRA_NAME, "all");
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
@ -1712,7 +1794,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
} else {
PostFragment fragment = new PostFragment();
Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccessToken == null ? PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE : PostPagingSource.TYPE_FRONT_PAGE);
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_FRONT_PAGE);
bundle.putString(PostFragment.EXTRA_NAME, "local");
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);

View File

@ -582,7 +582,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
subscriptionReady = false;
if (getResources().getString(R.string.subscribe).contentEquals(subscribeSubredditChip.getText())) {
CommunitySubscription.anonymousSubscribeToSubreddit(mExecutor, new Handler(),
mRetrofit.getRetrofit(), mRedditDataRoomDatabase, communityName,
mRetrofit.getRetrofit(), mRedditDataRoomDatabase, qualifiedName,
new CommunitySubscription.SubredditSubscriptionListener() {
@Override
public void onSubredditSubscriptionSuccess() {
@ -600,7 +600,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
});
} else {
CommunitySubscription.anonymousUnsubscribeToSubreddit(mExecutor, new Handler(),
mRedditDataRoomDatabase, communityName,
mRedditDataRoomDatabase, qualifiedName,
new CommunitySubscription.SubredditSubscriptionListener() {
@Override
public void onSubredditSubscriptionSuccess() {

View File

@ -50,7 +50,7 @@ public class NavigationDrawerRecyclerViewMergedAdapter {
accountSectionRecyclerViewAdapter = new AccountSectionRecyclerViewAdapter(baseActivity, customThemeWrapper,
navigationDrawerSharedPreferences, accountName != null, itemClickListener);
redditSectionRecyclerViewAdapter = new RedditSectionRecyclerViewAdapter(baseActivity, customThemeWrapper,
navigationDrawerSharedPreferences, itemClickListener);
navigationDrawerSharedPreferences, itemClickListener, accountName != null);
postSectionRecyclerViewAdapter = new PostSectionRecyclerViewAdapter(baseActivity, customThemeWrapper,
navigationDrawerSharedPreferences, accountName != null, itemClickListener);
preferenceSectionRecyclerViewAdapter = new PreferenceSectionRecyclerViewAdapter(baseActivity, customThemeWrapper,

View File

@ -22,7 +22,8 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
private static final int VIEW_TYPE_MENU_GROUP_TITLE = 1;
private static final int VIEW_TYPE_MENU_ITEM = 2;
private static final int REDDIT_SECTION_ITEMS = 1;
private static final int REDDIT_SECTION_ITEMS = 2;
private final boolean isLoggedIn;
private BaseActivity baseActivity;
private int primaryTextColor;
@ -33,13 +34,14 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
public RedditSectionRecyclerViewAdapter(BaseActivity baseActivity, CustomThemeWrapper customThemeWrapper,
SharedPreferences navigationDrawerSharedPreferences,
NavigationDrawerRecyclerViewMergedAdapter.ItemClickListener itemClickListener) {
NavigationDrawerRecyclerViewMergedAdapter.ItemClickListener itemClickListener, boolean isLoggedIn) {
this.baseActivity = baseActivity;
primaryTextColor = customThemeWrapper.getPrimaryTextColor();
secondaryTextColor = customThemeWrapper.getSecondaryTextColor();
primaryIconColor = customThemeWrapper.getPrimaryIconColor();
collapseRedditSection = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.COLLAPSE_REDDIT_SECTION, false);
this.itemClickListener = itemClickListener;
this.isLoggedIn = isLoggedIn;
}
@Override
@ -88,6 +90,9 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
stringId = R.string.trending;
drawableId = R.drawable.ic_trending_24dp;
break;
case 2:
stringId = R.string.anonymous_account_instance;
drawableId = R.drawable.ic_account_circle_24dp;
}
((MenuItemViewHolder) holder).menuTextView.setText(stringId);
@ -99,7 +104,7 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
@Override
public int getItemCount() {
return collapseRedditSection ? 1 : REDDIT_SECTION_ITEMS + 1;
return isLoggedIn ? (REDDIT_SECTION_ITEMS + 1) - 1 : collapseRedditSection ? 1 : REDDIT_SECTION_ITEMS + 1;
}
class MenuGroupTitleViewHolder extends RecyclerView.ViewHolder {

View File

@ -398,8 +398,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
};
mSwipeRefreshLayout.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true));
mSwipeRefreshLayout.setOnRefreshListener(this::refresh);
int recyclerViewPosition = 0;
if (savedInstanceState != null) {
@ -437,6 +435,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
postType = getArguments().getInt(EXTRA_POST_TYPE);
mSwipeRefreshLayout.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true) && postType != PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE);
mSwipeRefreshLayout.setOnRefreshListener(this::refresh);
accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0"));
@ -725,6 +726,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
});
} else if (postType == PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE) {
subredditName = getArguments().getString(EXTRA_NAME);
usage = PostFilterUsage.HOME_TYPE;
nameOfUsage = PostFilterUsage.NO_USAGE;
subredditName = getArguments().getString(EXTRA_NAME);
@ -971,11 +973,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
this.postFilter = postFilter;
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
this.concatenatedSubredditNames = concatenatedSubredditNames;
if (concatenatedSubredditNames == null) {
showErrorView(R.string.anonymous_front_page_no_subscriptions);
} else {
initializeAndBindPostViewModelForAnonymous(concatenatedSubredditNames);
}
showErrorView(R.string.anonymous_homepage_not_implemented);
}
});
} else {
@ -1017,11 +1015,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) {
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
this.concatenatedSubredditNames = concatenatedSubredditNames;
if (concatenatedSubredditNames == null) {
showErrorView(R.string.anonymous_front_page_no_subscriptions);
} else {
initializeAndBindPostViewModelForAnonymous(concatenatedSubredditNames);
}
showErrorView(R.string.anonymous_homepage_not_implemented);
}
});
} else {
@ -1209,33 +1203,33 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private void initializeAndBindPostViewModel(String accessToken) {
if (postType == PostPagingSource.TYPE_SEARCH) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
mRetrofit.getRetrofit() , accessToken,
mRetrofit, accessToken,
accountName, mSharedPreferences,
mPostFeedScrolledPositionSharedPreferences, mPostHistorySharedPreferences, subredditName,
query, trendingSource, postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
mRetrofit.getRetrofit() , accessToken,
mRetrofit, accessToken,
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
mPostHistorySharedPreferences, subredditName, postType, sortType, postFilter, readPosts))
.get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
mRetrofit.getRetrofit(), accessToken,
mRetrofit, accessToken,
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
mPostHistorySharedPreferences, multiRedditPath, postType, sortType, postFilter, readPosts))
.get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_USER) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
mRetrofit.getRetrofit(), accessToken,
mRetrofit, accessToken,
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
mPostHistorySharedPreferences, username, postType, sortType, postFilter, where, readPosts))
.get(PostViewModel.class);
} else {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
mRetrofit.getRetrofit(), accessToken,
mRetrofit, accessToken,
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
mPostHistorySharedPreferences, postType, sortType, postFilter, readPosts,subredditName)).get(PostViewModel.class);
mPostHistorySharedPreferences, postType, sortType, postFilter, readPosts, subredditName)).get(PostViewModel.class);
}
bindPostViewModel();
@ -1245,28 +1239,28 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
//For anonymous user
if (postType == PostPagingSource.TYPE_SEARCH) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
mRetrofit.getRetrofit(), null, accountName, mSharedPreferences,
mRetrofit, null, accountName, mSharedPreferences,
mPostFeedScrolledPositionSharedPreferences, null, subredditName, query, trendingSource,
postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mExecutor,
mRetrofit.getRetrofit(), null, accountName, mSharedPreferences,
mRetrofit, null, accountName, mSharedPreferences,
mPostFeedScrolledPositionSharedPreferences, null, subredditName, postType, sortType,
postFilter, readPosts)).get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
mRetrofit.getRetrofit(), null, accountName, mSharedPreferences,
mRetrofit, null, accountName, mSharedPreferences,
mPostFeedScrolledPositionSharedPreferences, null, multiRedditPath,
postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_USER) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
mRetrofit.getRetrofit(), null, accountName, mSharedPreferences,
mRetrofit, null, accountName, mSharedPreferences,
mPostFeedScrolledPositionSharedPreferences, null, username, postType, sortType, postFilter,
where, readPosts)).get(PostViewModel.class);
} else {
//Anonymous Front Page
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
mRetrofit.getRetrofit(), mSharedPreferences, concatenatedSubredditNames, postType, sortType, postFilter,subredditName))
mRetrofit, mSharedPreferences, concatenatedSubredditNames, postType, sortType, postFilter, subredditName))
.get(PostViewModel.class);
}
@ -1357,7 +1351,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
mFetchPostInfoLinearLayout.setOnClickListener(null);
showErrorView(R.string.no_posts);
if (accessToken != null) {
showErrorView(R.string.no_posts);
} else {
showErrorView(R.string.anonymous_homepage_not_implemented);
}
}
public void changeSortType(SortType sortType) {

View File

@ -18,13 +18,13 @@ import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;
import eu.toldi.infinityforlemmy.RetrofitHolder;
import eu.toldi.infinityforlemmy.SortType;
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import retrofit2.HttpException;
import retrofit2.Response;
import retrofit2.Retrofit;
public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post> {
public static final int TYPE_FRONT_PAGE = 0;
@ -43,7 +43,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
public static final String USER_WHERE_GILDED = "gilded";
private Executor executor;
private Retrofit retrofit;
private RetrofitHolder retrofit;
private String accessToken;
private String accountName;
private SharedPreferences sharedPreferences;
@ -61,10 +61,10 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
private int page = 1;
PostPagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences,
SharedPreferences postFeedScrolledPositionSharedPreferences, int postType,
SortType sortType, PostFilter postFilter, List<String> readPostList,String option) {
SortType sortType, PostFilter postFilter, List<String> readPostList, String option) {
this.executor = executor;
this.retrofit = retrofit;
this.accessToken = accessToken;
@ -79,7 +79,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
postLinkedHashSet = new LinkedHashSet<>();
}
PostPagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
String path, int postType, SortType sortType, PostFilter postFilter,
List<String> readPostList) {
@ -117,7 +117,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
postLinkedHashSet = new LinkedHashSet<>();
}
PostPagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
String subredditOrUserName, int postType, SortType sortType, PostFilter postFilter,
String where, List<String> readPostList) {
@ -136,7 +136,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
postLinkedHashSet = new LinkedHashSet<>();
}
PostPagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
String subredditOrUserName, String query, String trendingSource, int postType,
SortType sortType, PostFilter postFilter, List<String> readPostList) {
@ -165,17 +165,21 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
@NonNull
@Override
public ListenableFuture<LoadResult<Integer, Post>> loadFuture(@NonNull LoadParams<Integer> loadParams) {
LemmyAPI api = retrofit.create(LemmyAPI.class);
LemmyAPI api = retrofit.getRetrofit().create(LemmyAPI.class);
switch (postType) {
default:
case TYPE_FRONT_PAGE:
return loadHomePosts(loadParams, api);
case TYPE_SUBREDDIT:
return loadSubredditPosts(loadParams, api);
case TYPE_USER:
return loadUserPosts(loadParams, api);
case TYPE_SEARCH:
return loadSearchPosts(loadParams, api);
case TYPE_SUBREDDIT:
return loadSubredditPosts(loadParams, api);
default:
case TYPE_ANONYMOUS_FRONT_PAGE:
// Return a dummy result
return Futures.immediateFuture(new LoadResult.Page<>(new ArrayList<>(), null, null));
/* case TYPE_MULTI_REDDIT:
return loadMultiRedditPosts(loadParams, api);
default:

View File

@ -21,14 +21,14 @@ import androidx.paging.PagingLiveData;
import java.util.List;
import java.util.concurrent.Executor;
import eu.toldi.infinityforlemmy.RetrofitHolder;
import eu.toldi.infinityforlemmy.SortType;
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
public class PostViewModel extends ViewModel {
private Executor executor;
private Retrofit retrofit;
private RetrofitHolder retrofit;
private String accessToken;
private String accountName;
private SharedPreferences sharedPreferences;
@ -50,10 +50,10 @@ public class PostViewModel extends ViewModel {
private MutableLiveData<PostFilter> postFilterLiveData;
private SortTypeAndPostFilterLiveData sortTypeAndPostFilterLiveData;
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
public PostViewModel(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
@Nullable SharedPreferences postHistorySharedPreferences, int postType,
SortType sortType, PostFilter postFilter, List<String> readPostList,String option) {
SortType sortType, PostFilter postFilter, List<String> readPostList, String option) {
this.executor = executor;
this.retrofit = retrofit;
this.accessToken = accessToken;
@ -92,7 +92,7 @@ public class PostViewModel extends ViewModel {
&& postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
}
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
public PostViewModel(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
@Nullable SharedPreferences postHistorySharedPreferences, String subredditName, int postType,
SortType sortType, PostFilter postFilter, List<String> readPostList) {
@ -134,7 +134,7 @@ public class PostViewModel extends ViewModel {
&& postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
}
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
public PostViewModel(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences,
SharedPreferences postFeedScrolledPositionSharedPreferences,
@Nullable SharedPreferences postHistorySharedPreferences, String username,
@ -179,7 +179,7 @@ public class PostViewModel extends ViewModel {
&& postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
}
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
public PostViewModel(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
@Nullable SharedPreferences postHistorySharedPreferences, String subredditName, String query,
String trendingSource, int postType, SortType sortType, PostFilter postFilter,
@ -277,7 +277,7 @@ public class PostViewModel extends ViewModel {
public static class Factory extends ViewModelProvider.NewInstanceFactory {
private Executor executor;
private Retrofit retrofit;
private RetrofitHolder retrofit;
private String accessToken;
private String accountName;
private SharedPreferences sharedPreferences;
@ -292,7 +292,7 @@ public class PostViewModel extends ViewModel {
private String userWhere;
private List<String> readPostList;
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
SharedPreferences postHistorySharedPreferences, int postType, SortType sortType,
PostFilter postFilter, List<String> readPostList, String option) {
@ -310,7 +310,7 @@ public class PostViewModel extends ViewModel {
this.name = option;
}
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
SharedPreferences postHistorySharedPreferences, String name, int postType, SortType sortType,
PostFilter postFilter, List<String> readPostList) {
@ -329,7 +329,7 @@ public class PostViewModel extends ViewModel {
}
//User posts
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
SharedPreferences postHistorySharedPreferences, String username, int postType,
SortType sortType, PostFilter postFilter, String where, List<String> readPostList) {
@ -348,7 +348,7 @@ public class PostViewModel extends ViewModel {
this.readPostList = readPostList;
}
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
SharedPreferences postHistorySharedPreferences, String name, String query, String trendingSource,
int postType, SortType sortType, PostFilter postFilter, List<String> readPostList) {
@ -369,7 +369,7 @@ public class PostViewModel extends ViewModel {
}
//Anonymous Front Page
public Factory(Executor executor, Retrofit retrofit, SharedPreferences sharedPreferences,
public Factory(Executor executor, RetrofitHolder retrofit, SharedPreferences sharedPreferences,
String concatenatedSubredditNames, int postType, SortType sortType, PostFilter postFilter, String opt) {
this.executor = executor;
this.retrofit = retrofit;

View File

@ -40,6 +40,7 @@ public class MiscellaneousPreferenceFragment extends CustomFontPreferenceFragmen
ListPreference mainPageBackButtonActionListPreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_BACK_BUTTON_ACTION);
SwitchPreference savePostFeedScrolledPositionSwitch = findPreference(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION);
ListPreference languageListPreference = findPreference(SharedPreferencesUtils.LANGUAGE);
EditTextPreference anonymousAccountInstance = findPreference(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE);
EditTextPreference postFeedMaxResolution = findPreference(SharedPreferencesUtils.POST_FEED_MAX_RESOLUTION);
if (mainPageBackButtonActionListPreference != null) {
@ -66,6 +67,25 @@ public class MiscellaneousPreferenceFragment extends CustomFontPreferenceFragmen
});
}
if (anonymousAccountInstance != null) {
anonymousAccountInstance.setOnPreferenceChangeListener((preference, newValue) -> {
String url = (String) newValue;
if (url == null || url.equals("")) {
Toast.makeText(activity, R.string.url_cannot_be_null_or_empty, Toast.LENGTH_SHORT).show();
return false;
}
if (!url.startsWith("http://") && !url.startsWith("https://")) {
Toast.makeText(activity, "The url has to start with https:// or http://", Toast.LENGTH_SHORT).show();
return false;
}
EventBus.getDefault().post(new RecreateActivityEvent());
return true;
});
}
if (postFeedMaxResolution != null) {
postFeedMaxResolution.setOnPreferenceChangeListener((preference, newValue) -> {
try {

View File

@ -29,7 +29,7 @@ public class CommunitySubscription {
RedditDataRoomDatabase redditDataRoomDatabase,
String subredditName,
SubredditSubscriptionListener subredditSubscriptionListener) {
FetchSubredditData.fetchSubredditData(retrofit, subredditName, "", new FetchSubredditData.FetchSubredditDataListener() {
FetchSubredditData.fetchSubredditData(retrofit, subredditName, null, new FetchSubredditData.FetchSubredditDataListener() {
@Override
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
insertSubscription(executor, handler, redditDataRoomDatabase,
@ -111,7 +111,7 @@ public class CommunitySubscription {
SubredditData subredditData, String accountName,
SubredditSubscriptionListener subredditSubscriptionListener) {
executor.execute(() -> {
SubscribedSubredditData subscribedSubredditData = new SubscribedSubredditData(subredditData.getId(), LemmyUtils.actorID2FullName(subredditData.getActorId()), subredditData.getName(),
SubscribedSubredditData subscribedSubredditData = new SubscribedSubredditData(subredditData.getId(), subredditData.getName(), LemmyUtils.actorID2FullName(subredditData.getActorId()),
subredditData.getIconUrl(), accountName);
if (accountName.equals("-")) {
if (!redditDataRoomDatabase.accountDao().isAnonymousAccountInserted()) {

View File

@ -15,7 +15,7 @@ import okhttp3.RequestBody;
public class APIUtils {
public static final String OAUTH_URL = "https://www.reddit.com/api/v1/authorize.compact";
public static final String OAUTH_API_BASE_URI = "https://oauth.reddit.com";
public static final String API_BASE_URI = "https://lemmy.toldi.eu";
public static final String API_BASE_URI = "https://lemmy.world";
public static final String API_UPLOAD_MEDIA_URI = "https://reddit-uploaded-media.s3-accelerate.amazonaws.com";
public static final String API_UPLOAD_VIDEO_URI = "https://reddit-uploaded-video.s3-accelerate.amazonaws.com";
public static final String GFYCAT_API_BASE_URI = "https://api.gfycat.com/v1/gfycats/";

View File

@ -167,6 +167,8 @@ public class SharedPreferencesUtils {
public static final int SWIPE_ACITON_DOWNVOTE = 1;
public static final String LANGUAGE = "language";
public static final String LANGUAGE_DEFAULT_VALUE = "auto";
public static final String ANONYMOUS_ACCOUNT_INSTANCE = "anonymous_account_instance";
public static final String ENABLE_SEARCH_HISTORY = "enable_search_history";
public static final String POST_FILTER = "post_filter";
public static final String ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS = "only_disable_preview_in_video_and_gif_posts";

View File

@ -116,6 +116,7 @@
<string name="no_users">No users found</string>
<string name="no_multi_reddits">No Multireddits found</string>
<string name="no_storage_permission">No storage permission to save this file</string>
<string name="anonymous_homepage_not_implemented">Anonymous homepage is not implemented yet</string>
<string name="load_comments_failed">Error loading comments.\nTap to retry.</string>
<string name="retry">Retry</string>
@ -1338,4 +1339,6 @@
<string name="sort_time_3months">3 Months</string>
<string name="sort_time_6months">6 Months</string>
<string name="sort_time_9months">9 Months</string>
<string name="anonymous_account_instance">Anonymous Account Instance</string>
<string name="url_cannot_be_null_or_empty">URL cannot be null or empty</string>
</resources>

View File

@ -40,8 +40,13 @@
app:title="@string/settings_language_title"
app:useSimpleSummaryProvider="true" />
<eu.toldi.infinityforlemmy.customviews.CustomFontPreferenceCategory
app:title="@string/settings_miscellaneous_dangerous_group_title" />
<eu.toldi.infinityforlemmy.customviews.CustomFontEditTextPreference
app:defaultValue="https://lemmy.world"
app:key="anonymous_account_instance"
app:title="@string/anonymous_account_instance"
app:useSimpleSummaryProvider="true" />
<eu.toldi.infinityforlemmy.customviews.CustomFontPreferenceCategory app:title="@string/settings_miscellaneous_dangerous_group_title" />
<eu.toldi.infinityforlemmy.customviews.CustomFontPreference
app:icon="@drawable/ic_info_preference_24dp"
@ -54,4 +59,5 @@
app:title="@string/settings_post_feed_max_resolution_title"
app:useSimpleSummaryProvider="true" />
</PreferenceScreen>