Skip to content

Commit

Permalink
Version 4.0.3. Only save scrolled position for Best posts in HOME. Se…
Browse files Browse the repository at this point in the history
…t Save Scrolled Position in HOME to false by default. Apply link color in CommentActivity.
  • Loading branch information
Docile-Alligator committed Aug 4, 2020
1 parent d10a3bd commit 74a4206
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "ml.docilealligator.infinityforreddit"
minSdkVersion 21
targetSdkVersion 29
versionCode 38
versionName "4.0.2"
versionCode 39
versionName "4.0.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon;
import io.noties.markwon.MarkwonConfiguration;
import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
import io.noties.markwon.linkify.LinkifyPlugin;
import io.noties.markwon.recycler.MarkwonAdapter;
Expand All @@ -49,14 +50,14 @@
import io.noties.markwon.simple.ext.SimpleExtPlugin;
import io.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.BottomSheetFragment.CopyTextBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Comment.Comment;
import ml.docilealligator.infinityforreddit.Comment.SendComment;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.BottomSheetFragment.CopyTextBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.Comment.SendComment;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.Utils.Utils;
import retrofit2.Retrofit;
Expand Down Expand Up @@ -146,6 +147,8 @@ protected void onCreate(Bundle savedInstanceState) {
String parentTextMarkdown = intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_MARKDOWN_KEY);
String parentText = intent.getStringExtra(EXTRA_COMMENT_PARENT_TEXT_KEY);
CopyTextBottomSheetFragment copyTextBottomSheetFragment = new CopyTextBottomSheetFragment();

int linkColor = mCustomThemeWrapper.getLinkColor();
Markwon markwon = Markwon.builder(this)
.usePlugin(new AbstractMarkwonPlugin() {
@Override
Expand All @@ -161,6 +164,11 @@ public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder
startActivity(intent);
});
}

@Override
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
builder.linkColor(linkColor);
}
})
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
.usePlugin(SimpleExtPlugin.create(plugin ->
Expand Down Expand Up @@ -220,6 +228,11 @@ public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder
startActivity(intent);
}).urlProcessor(new UrlProcessorRelativeToAbsolute("https://www.reddit.com"));
}

@Override
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
builder.linkColor(linkColor);
}
})
.usePlugin(StrikethroughPlugin.create())
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
boolean nsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_KEY, false);
int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0"));
savePostFeedScrolledPosition = mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION, true);
savePostFeedScrolledPosition = mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION, false);
Locale locale = getResources().getConfiguration().locale;

if (postType == PostDataSource.TYPE_SEARCH) {
Expand Down Expand Up @@ -717,7 +717,7 @@ public void onStop() {
}

private void saveCache() {
if (savePostFeedScrolledPosition && postType == PostDataSource.TYPE_FRONT_PAGE && mAdapter != null) {
if (savePostFeedScrolledPosition && postType == PostDataSource.TYPE_FRONT_PAGE && sortType != null && sortType.getType() == SortType.Type.BEST && mAdapter != null) {
Post currentPost = mAdapter.getItemByPosition(maxPosition);
if (currentPost != null) {
String accountNameForCache = accountName == null ? SharedPreferencesUtils.FRONT_PAGE_SCROLLED_POSITION_ANONYMOUS : accountName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public void loadInitial(@NonNull LoadInitialParams<String> params, @NonNull fina
initialLoadStateLiveData.postValue(NetworkState.LOADING);
switch (postType) {
case TYPE_FRONT_PAGE:
boolean savePostFeedScrolledPosition = sharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION, true);
boolean savePostFeedScrolledPosition = sortType != null && sortType.getType() == SortType.Type.BEST && sharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION, false);
String accountNameForCache = accountName == null ? SharedPreferencesUtils.FRONT_PAGE_SCROLLED_POSITION_ANONYMOUS : accountName;
if (savePostFeedScrolledPosition) {
loadBestPostsInitial(callback, postFeedScrolledPositionSharedPreferences.getString(accountNameForCache + SharedPreferencesUtils.FRONT_PAGE_SCROLLED_POSITION_FRONT_PAGE_BASE, null));
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
<string name="settings_interface_title">Interface</string>
<string name="settings_gestures_and_buttons_title">Gestures &amp; Buttons</string>
<string name="settings_save_front_page_scrolled_position_title">Save Scrolled Position in HOME</string>
<string name="settings_save_front_page_scrolled_position_summary">Browse new posts after refreshing in HOME (Front Page)</string>
<string name="settings_save_front_page_scrolled_position_summary">Browse new posts after refreshing in HOME (Front Page, sort type: Best)</string>
<string name="settings_open_link_in_app_title">Open Link In App</string>
<string name="settigns_video_title">Video</string>
<string name="settings_video_autoplay_title">Video Autoplay</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/main_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
app:useSimpleSummaryProvider="true" />

<SwitchPreference
app:defaultValue="true"
app:defaultValue="false"
app:key="save_front_page_scrolled_position"
app:title="@string/settings_save_front_page_scrolled_position_title"
app:summary="@string/settings_save_front_page_scrolled_position_summary" />
Expand Down

0 comments on commit 74a4206

Please sign in to comment.