From e815a1444d56a2045ccfa88170c0fcbf0363b569 Mon Sep 17 00:00:00 2001 From: Balazs Toldi Date: Fri, 28 Jul 2023 15:07:45 +0200 Subject: [PATCH] Anonymous browsing This commit adds the Anonymous browsing functionality. Unfortunately, the anonymous home page is disabled as of now. --- .../activities/MainActivity.java | 88 ++++++++++++++++++- .../ViewSubredditDetailActivity.java | 4 +- ...gationDrawerRecyclerViewMergedAdapter.java | 2 +- .../RedditSectionRecyclerViewAdapter.java | 11 ++- .../fragments/PostFragment.java | 47 +++++----- .../post/PostPagingSource.java | 26 +++--- .../infinityforlemmy/post/PostViewModel.java | 26 +++--- .../MiscellaneousPreferenceFragment.java | 20 +++++ .../subreddit/CommunitySubscription.java | 4 +- .../infinityforlemmy/utils/APIUtils.java | 2 +- .../utils/SharedPreferencesUtils.java | 2 + app/src/main/res/values/strings.xml | 3 + .../res/xml/miscellaneous_preferences.xml | 10 ++- 13 files changed, 183 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java index 57bac1bf..c6d21faf 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java @@ -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); diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java index a1bf96d1..c6bc4cfe 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java @@ -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() { diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/navigationdrawer/NavigationDrawerRecyclerViewMergedAdapter.java b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/navigationdrawer/NavigationDrawerRecyclerViewMergedAdapter.java index ef83ac71..6a328f48 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/navigationdrawer/NavigationDrawerRecyclerViewMergedAdapter.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/navigationdrawer/NavigationDrawerRecyclerViewMergedAdapter.java @@ -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, diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/navigationdrawer/RedditSectionRecyclerViewAdapter.java b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/navigationdrawer/RedditSectionRecyclerViewAdapter.java index ba6dc19c..eb691361 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/adapters/navigationdrawer/RedditSectionRecyclerViewAdapter.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/adapters/navigationdrawer/RedditSectionRecyclerViewAdapter.java @@ -22,7 +22,8 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter { public static final int TYPE_FRONT_PAGE = 0; @@ -43,7 +43,7 @@ public class PostPagingSource extends ListenableFuturePagingSource readPostList,String option) { + SortType sortType, PostFilter postFilter, List readPostList, String option) { this.executor = executor; this.retrofit = retrofit; this.accessToken = accessToken; @@ -79,7 +79,7 @@ public class PostPagingSource extends ListenableFuturePagingSource(); } - 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 readPostList) { @@ -117,7 +117,7 @@ public class PostPagingSource extends ListenableFuturePagingSource(); } - 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 readPostList) { @@ -136,7 +136,7 @@ public class PostPagingSource extends ListenableFuturePagingSource(); } - 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 readPostList) { @@ -165,17 +165,21 @@ public class PostPagingSource extends ListenableFuturePagingSource> loadFuture(@NonNull LoadParams 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: diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/post/PostViewModel.java b/app/src/main/java/eu/toldi/infinityforlemmy/post/PostViewModel.java index 2e467aa4..a29e80c4 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/post/PostViewModel.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/post/PostViewModel.java @@ -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 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 readPostList,String option) { + SortType sortType, PostFilter postFilter, List 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 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 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 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 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 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 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; diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/settings/MiscellaneousPreferenceFragment.java b/app/src/main/java/eu/toldi/infinityforlemmy/settings/MiscellaneousPreferenceFragment.java index 29923d8c..16d49204 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/settings/MiscellaneousPreferenceFragment.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/settings/MiscellaneousPreferenceFragment.java @@ -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 { diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/subreddit/CommunitySubscription.java b/app/src/main/java/eu/toldi/infinityforlemmy/subreddit/CommunitySubscription.java index fc500419..0e186f27 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/subreddit/CommunitySubscription.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/subreddit/CommunitySubscription.java @@ -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()) { diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/utils/APIUtils.java b/app/src/main/java/eu/toldi/infinityforlemmy/utils/APIUtils.java index 8bd7a184..48bb5e5b 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/utils/APIUtils.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/utils/APIUtils.java @@ -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/"; diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/utils/SharedPreferencesUtils.java b/app/src/main/java/eu/toldi/infinityforlemmy/utils/SharedPreferencesUtils.java index 4e8bcbc0..25feac18 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/utils/SharedPreferencesUtils.java @@ -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"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5fbbe7c2..f88006eb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -116,6 +116,7 @@ No users found No Multireddits found No storage permission to save this file + Anonymous homepage is not implemented yet Error loading comments.\nTap to retry. Retry @@ -1338,4 +1339,6 @@ 3 Months 6 Months 9 Months + Anonymous Account Instance + URL cannot be null or empty diff --git a/app/src/main/res/xml/miscellaneous_preferences.xml b/app/src/main/res/xml/miscellaneous_preferences.xml index e104ff8f..2842c3a0 100644 --- a/app/src/main/res/xml/miscellaneous_preferences.xml +++ b/app/src/main/res/xml/miscellaneous_preferences.xml @@ -40,8 +40,13 @@ app:title="@string/settings_language_title" app:useSimpleSummaryProvider="true" /> - + + + + \ No newline at end of file