aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2023-11-28 05:08:18 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2023-11-28 05:08:18 +0000
commit776f0aa01f7387a6d7a03fb9d965af969800799f (patch)
tree653a3d229d74cbdf0218fe31f2d663f42db32b2e /app/src
parent966bac159702a1fc648d8448f58f5a2138ebb346 (diff)
downloadinfinity-for-reddit-776f0aa01f7387a6d7a03fb9d965af969800799f.tar
infinity-for-reddit-776f0aa01f7387a6d7a03fb9d965af969800799f.tar.gz
infinity-for-reddit-776f0aa01f7387a6d7a03fb9d965af969800799f.tar.bz2
infinity-for-reddit-776f0aa01f7387a6d7a03fb9d965af969800799f.tar.lz
infinity-for-reddit-776f0aa01f7387a6d7a03fb9d965af969800799f.tar.xz
infinity-for-reddit-776f0aa01f7387a6d7a03fb9d965af969800799f.tar.zst
infinity-for-reddit-776f0aa01f7387a6d7a03fb9d965af969800799f.zip
Hide images and gifs in ImageAndGifEntry and EmotePlugin if corresponding data saving settings are enabled.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java30
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java33
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java27
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java31
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java24
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java48
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java33
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmotePlugin.java61
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java4
13 files changed, 248 insertions, 67 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java
index a6af969e..df2d6faa 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java
@@ -60,6 +60,7 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.UploadedImagesB
import ml.docilealligator.infinityforreddit.comment.Comment;
import ml.docilealligator.infinityforreddit.comment.SendComment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
import ml.docilealligator.infinityforreddit.markdown.CustomMarkwonAdapter;
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.databinding.ActivityCommentBinding;
@@ -135,6 +136,8 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
@ColorInt
private int parentSpoilerBackgroundColor;
private ActivityCommentBinding binding;
+ private EmotePlugin emotePlugin;
+ private ImageAndGifEntry imageAndGifEntry;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -215,12 +218,9 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
}
};
EmoteCloseBracketInlineProcessor emoteCloseBracketInlineProcessor = new EmoteCloseBracketInlineProcessor();
- EmotePlugin emotePlugin = EmotePlugin.create(this);
+ emotePlugin = EmotePlugin.create(this);
ImageAndGifPlugin imageAndGifPlugin = new ImageAndGifPlugin();
- Markwon postBodyMarkwon = MarkdownUtils.createFullRedditMarkwon(this,
- miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, parentTextColor,
- parentSpoilerBackgroundColor, null);
- CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(new ImageAndGifEntry(this, mGlide, mediaMetadata -> {
+ imageAndGifEntry = new ImageAndGifEntry(this, mGlide, mediaMetadata -> {
Intent imageIntent = new Intent(this, ViewImageOrGifActivity.class);
if (mediaMetadata.isGIF) {
imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url);
@@ -229,7 +229,11 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
}
imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, intent.getStringExtra(EXTRA_SUBREDDIT_NAME_KEY));
imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName);
- }));
+ });
+ Markwon postBodyMarkwon = MarkdownUtils.createFullRedditMarkwon(this,
+ miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, parentTextColor,
+ parentSpoilerBackgroundColor, null);
+ CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(imageAndGifEntry);
markwonAdapter.setOnLongClickListener(view -> {
Utils.hideKeyboard(CommentActivity.this);
CopyTextBottomSheetFragment.show(getSupportFragmentManager(),
@@ -514,6 +518,20 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
finish();
}
+ @Subscribe
+ public void onChangeNetworkStatusEvent(ChangeNetworkStatusEvent changeNetworkStatusEvent) {
+ String dataSavingMode = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
+ if (dataSavingMode.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
+ if (emotePlugin != null) {
+ emotePlugin.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR);
+ }
+
+ if (imageAndGifEntry != null) {
+ imageAndGifEntry.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR);
+ }
+ }
+ }
+
@Override
public void uploadImage() {
Intent intent = new Intent();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java
index 33363ec3..e3e5a263 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java
@@ -38,6 +38,7 @@ import io.noties.markwon.core.MarkwonTheme;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
import ml.docilealligator.infinityforreddit.markdown.CustomMarkwonAdapter;
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface;
@@ -50,6 +51,7 @@ import ml.docilealligator.infinityforreddit.markdown.ImageAndGifEntry;
import ml.docilealligator.infinityforreddit.markdown.ImageAndGifPlugin;
import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.utils.Utils;
public class FullMarkdownActivity extends BaseActivity {
@@ -72,6 +74,8 @@ public class FullMarkdownActivity extends BaseActivity {
SharedPreferences mSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
+ private EmotePlugin emotePlugin;
+ private ImageAndGifEntry imageAndGifEntry;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -144,13 +148,9 @@ public class FullMarkdownActivity extends BaseActivity {
}
};
EmoteCloseBracketInlineProcessor emoteCloseBracketInlineProcessor = new EmoteCloseBracketInlineProcessor();
- EmotePlugin emotePlugin = EmotePlugin.create(this);
+ emotePlugin = EmotePlugin.create(this);
ImageAndGifPlugin imageAndGifPlugin = new ImageAndGifPlugin();
- Markwon markwon = MarkdownUtils.createFullRedditMarkwon(this,
- miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, markdownColor,
- spoilerBackgroundColor, null);
-
- CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(new ImageAndGifEntry(this,
+ imageAndGifEntry = new ImageAndGifEntry(this,
Glide.with(this), mediaMetadata -> {
Intent intent = new Intent(this, ViewImageOrGifActivity.class);
if (mediaMetadata.isGIF) {
@@ -160,7 +160,12 @@ public class FullMarkdownActivity extends BaseActivity {
}
intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, isNsfw);
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName);
- }));
+ });
+ Markwon markwon = MarkdownUtils.createFullRedditMarkwon(this,
+ miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, markdownColor,
+ spoilerBackgroundColor, null);
+
+ CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(imageAndGifEntry);
LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() {
@Override
public void lockSwipe() {
@@ -235,4 +240,18 @@ public class FullMarkdownActivity extends BaseActivity {
finish();
}
}
+
+ @Subscribe
+ public void onChangeNetworkStatusEvent(ChangeNetworkStatusEvent changeNetworkStatusEvent) {
+ String dataSavingMode = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
+ if (dataSavingMode.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
+ if (emotePlugin != null) {
+ emotePlugin.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR);
+ }
+
+ if (imageAndGifEntry != null) {
+ imageAndGifEntry.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR);
+ }
+ }
+ }
} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java
index 8644704f..aa83aaa5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/RulesActivity.java
@@ -39,8 +39,10 @@ import ml.docilealligator.infinityforreddit.adapters.RulesRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr;
import ml.docilealligator.infinityforreddit.customviews.slidr.widget.SliderPanel;
+import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.utils.Utils;
import retrofit2.Retrofit;
public class RulesActivity extends BaseActivity {
@@ -224,4 +226,12 @@ public class RulesActivity extends BaseActivity {
public void onAccountSwitchEvent(SwitchAccountEvent event) {
finish();
}
+
+ @Subscribe
+ public void onChangeNetworkStatusEvent(ChangeNetworkStatusEvent changeNetworkStatusEvent) {
+ String dataSavingMode = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
+ if (mAdapter != null && dataSavingMode.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
+ mAdapter.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR);
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java
index cd2f9526..a65a49fc 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java
@@ -51,6 +51,7 @@ import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFi
import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface;
import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager;
import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr;
+import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.markdown.EmoteCloseBracketInlineProcessor;
import ml.docilealligator.infinityforreddit.markdown.EmotePlugin;
@@ -103,6 +104,7 @@ public class WikiActivity extends BaseActivity {
private EmoteCloseBracketInlineProcessor emoteCloseBracketInlineProcessor;
private EmotePlugin emotePlugin;
private ImageAndGifPlugin imageAndGifPlugin;
+ private ImageAndGifEntry imageAndGifEntry;
private Markwon markwon;
private MarkwonAdapter markwonAdapter;
private boolean isRefreshing = false;
@@ -188,10 +190,7 @@ public class WikiActivity extends BaseActivity {
emoteCloseBracketInlineProcessor = new EmoteCloseBracketInlineProcessor();
emotePlugin = EmotePlugin.create(this);
imageAndGifPlugin = new ImageAndGifPlugin();
- markwon = MarkdownUtils.createFullRedditMarkwon(this,
- miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener);
-
- markwonAdapter = MarkdownUtils.createCustomTablesAdapter(new ImageAndGifEntry(this,
+ imageAndGifEntry = new ImageAndGifEntry(this,
mGlide, mediaMetadata -> {
Intent intent = new Intent(this, ViewImageOrGifActivity.class);
if (mediaMetadata.isGIF) {
@@ -201,7 +200,11 @@ public class WikiActivity extends BaseActivity {
}
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, mSubredditName);
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName);
- }));
+ });
+ markwon = MarkdownUtils.createFullRedditMarkwon(this,
+ miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener);
+
+ markwonAdapter = MarkdownUtils.createCustomTablesAdapter(imageAndGifEntry);
LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() {
@Override
public void lockSwipe() {
@@ -335,4 +338,18 @@ public class WikiActivity extends BaseActivity {
finish();
}
}
+
+ @Subscribe
+ public void onChangeNetworkStatusEvent(ChangeNetworkStatusEvent changeNetworkStatusEvent) {
+ String dataSavingMode = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
+ if (dataSavingMode.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
+ if (emotePlugin != null) {
+ emotePlugin.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR);
+ }
+
+ if (imageAndGifEntry != null) {
+ imageAndGifEntry.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR);
+ }
+ }
+ }
} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java
index ce979f78..5e52b063 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java
@@ -365,6 +365,11 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
this.canStartActivity = canStartActivity;
}
+ public void setDataSavingMode(boolean dataSavingMode) {
+ mEmotePlugin.setDataSavingMode(dataSavingMode);
+ mImageAndGifEntry.setDataSavingMode(dataSavingMode);
+ }
+
public interface RetryLoadingMoreCallback {
void retryLoadingMore();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java
index 454d5398..672a2be0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java
@@ -1187,6 +1187,11 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
}
}
+ public void setDataSavingMode(boolean dataSavingMode) {
+ mEmotePlugin.setDataSavingMode(dataSavingMode);
+ mImageAndGifEntry.setDataSavingMode(dataSavingMode);
+ }
+
public interface CommentRecyclerViewAdapterCallback {
void retryFetchingComments();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
index 5e5e8760..0f433688 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
@@ -388,7 +388,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
return true;
};
mEmoteCloseBracketInlineProcessor = new EmoteCloseBracketInlineProcessor();
- mEmotePlugin = EmotePlugin.create(activity);
+ mEmotePlugin = EmotePlugin.create(activity, mDataSavingMode, mDisableImagePreview);
mImageAndGifPlugin = new ImageAndGifPlugin();
mPostDetailMarkwon = MarkdownUtils.createFullRedditMarkwon(mActivity,
miscPlugin, mEmoteCloseBracketInlineProcessor, mEmotePlugin, mImageAndGifPlugin, markdownColor,
@@ -980,6 +980,8 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
public void setDataSavingMode(boolean dataSavingMode) {
mDataSavingMode = dataSavingMode;
+ mEmotePlugin.setDataSavingMode(dataSavingMode);
+ mImageAndGifEntry.setDataSavingMode(dataSavingMode);
}
public void onItemSwipe(RecyclerView.ViewHolder viewHolder, int direction, int swipeLeftAction, int swipeRightAction) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java
index 9c6457ec..8d7ce6dc 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java
@@ -46,6 +46,7 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler
private EmoteCloseBracketInlineProcessor emoteCloseBracketInlineProcessor;
private EmotePlugin emotePlugin;
private ImageAndGifPlugin imageAndGifPlugin;
+ private ImageAndGifEntry imageAndGifEntry;
private Markwon markwon;
@Nullable
private final SliderPanel sliderPanel;
@@ -96,6 +97,18 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler
emoteCloseBracketInlineProcessor = new EmoteCloseBracketInlineProcessor();
emotePlugin = EmotePlugin.create(activity);
imageAndGifPlugin = new ImageAndGifPlugin();
+ imageAndGifEntry = new ImageAndGifEntry(activity,
+ Glide.with(activity),
+ mediaMetadata -> {
+ Intent imageIntent = new Intent(activity, ViewImageOrGifActivity.class);
+ if (mediaMetadata.isGIF) {
+ imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url);
+ } else {
+ imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mediaMetadata.original.url);
+ }
+ imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, subredditName);
+ imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName);
+ });
markwon = MarkdownUtils.createFullRedditMarkwon(activity,
miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, mPrimaryTextColor,
spoilerBackgroundColor, onLinkLongClickListener);
@@ -136,6 +149,11 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler
notifyDataSetChanged();
}
+ public void setDataSavingMode(boolean dataSavingMode) {
+ emotePlugin.setDataSavingMode(dataSavingMode);
+ imageAndGifEntry.setDataSavingMode(dataSavingMode);
+ }
+
class RuleViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.short_name_text_view_item_rule)
TextView shortNameTextView;
@@ -152,18 +170,7 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler
if (activity.typeface != null) {
shortNameTextView.setTypeface(activity.typeface);
}
- markwonAdapter = MarkdownUtils.createCustomTablesAdapter(new ImageAndGifEntry(activity,
- Glide.with(activity),
- mediaMetadata -> {
- Intent imageIntent = new Intent(activity, ViewImageOrGifActivity.class);
- if (mediaMetadata.isGIF) {
- imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url);
- } else {
- imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mediaMetadata.original.url);
- }
- imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, subredditName);
- imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName);
- }));
+ markwonAdapter = MarkdownUtils.createCustomTablesAdapter(imageAndGifEntry);
SwipeLockLinearLayoutManager swipeLockLinearLayoutManager = new SwipeLockLinearLayoutManager(activity,
new SwipeLockInterface() {
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java
index fe5f3b66..b41b2908 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/CommentsListingFragment.java
@@ -30,6 +30,9 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+
import java.util.concurrent.Executor;
import javax.inject.Inject;
@@ -49,6 +52,9 @@ import ml.docilealligator.infinityforreddit.adapters.CommentsListingRecyclerView
import ml.docilealligator.infinityforreddit.comment.CommentViewModel;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
+import ml.docilealligator.infinityforreddit.events.ChangeDataSavingModeEvent;
+import ml.docilealligator.infinityforreddit.events.ChangeDisableImagePreviewEvent;
+import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.Utils;
import retrofit2.Retrofit;
@@ -130,6 +136,8 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
ButterKnife.bind(this, rootView);
+ EventBus.getDefault().register(this);
+
applyTheme();
mGlide = Glide.with(mActivity);
@@ -342,6 +350,12 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
}
}
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ EventBus.getDefault().unregister(this);
+ }
+
public void changeSortType(SortType sortType) {
mCommentViewModel.changeSortType(sortType);
this.sortType = sortType;
@@ -412,4 +426,14 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
mAdapter.editComment(commentMarkdown, position);
}
}
+
+ @Subscribe
+ public void onChangeNetworkStatusEvent(ChangeNetworkStatusEvent changeNetworkStatusEvent) {
+ if (mAdapter != null) {
+ String dataSavingMode = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
+ if (dataSavingMode.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
+ mAdapter.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR);
+ }
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java
index 6d171a3a..d84617cf 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java
@@ -20,6 +20,9 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.bumptech.glide.Glide;
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+
import java.util.concurrent.Executor;
import javax.inject.Inject;
@@ -43,6 +46,7 @@ import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditData;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.CopyTextBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
import ml.docilealligator.infinityforreddit.markdown.CustomMarkwonAdapter;
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
import ml.docilealligator.infinityforreddit.markdown.EmoteCloseBracketInlineProcessor;
@@ -53,6 +57,8 @@ import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils;
import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData;
import ml.docilealligator.infinityforreddit.subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.subreddit.SubredditViewModel;
+import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.utils.Utils;
import retrofit2.Retrofit;
public class SidebarFragment extends Fragment {
@@ -82,6 +88,8 @@ public class SidebarFragment extends Fragment {
private LinearLayoutManagerBugFixed linearLayoutManager;
private int markdownColor;
private String sidebarDescription;
+ private EmotePlugin emotePlugin;
+ private ImageAndGifEntry imageAndGifEntry;
public SidebarFragment() {
// Required empty public constructor
@@ -97,6 +105,8 @@ public class SidebarFragment extends Fragment {
ButterKnife.bind(this, rootView);
+ EventBus.getDefault().register(this);
+
mAccessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME);
if (subredditName == null) {
@@ -149,12 +159,9 @@ public class SidebarFragment extends Fragment {
return true;
};
EmoteCloseBracketInlineProcessor emoteCloseBracketInlineProcessor = new EmoteCloseBracketInlineProcessor();
- EmotePlugin emotePlugin = EmotePlugin.create(activity);
+ emotePlugin = EmotePlugin.create(activity);
ImageAndGifPlugin imageAndGifPlugin = new ImageAndGifPlugin();
- Markwon markwon = MarkdownUtils.createFullRedditMarkwon(activity,
- miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, markdownColor,
- spoilerBackgroundColor, onLinkLongClickListener);
- CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(new ImageAndGifEntry(activity,
+ imageAndGifEntry = new ImageAndGifEntry(activity,
Glide.with(this),
mediaMetadata -> {
Intent imageIntent = new Intent(activity, ViewImageOrGifActivity.class);
@@ -165,7 +172,11 @@ public class SidebarFragment extends Fragment {
}
imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, subredditName);
imageIntent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName);
- }));
+ });
+ Markwon markwon = MarkdownUtils.createFullRedditMarkwon(activity,
+ miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, markdownColor,
+ spoilerBackgroundColor, onLinkLongClickListener);
+ CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(imageAndGifEntry);
markwonAdapter.setOnLongClickListener(view -> {
if (sidebarDescription != null && !sidebarDescription.equals("")) {
Bundle bundle = new Bundle();
@@ -218,6 +229,12 @@ public class SidebarFragment extends Fragment {
activity = (ViewSubredditDetailActivity) context;
}
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ EventBus.getDefault().unregister(this);
+ }
+
public void fetchSubredditData() {
swipeRefreshLayout.setRefreshing(true);
FetchSubredditData.fetchSubredditData(mOauthRetrofit, mRetrofit, subredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
@@ -241,4 +258,23 @@ public class SidebarFragment extends Fragment {
linearLayoutManager.scrollToPositionWithOffset(0, 0);
}
}
+
+ public void setDataSavingMode(boolean dataSavingMode) {
+ emotePlugin.setDataSavingMode(dataSavingMode);
+ imageAndGifEntry.setDataSavingMode(dataSavingMode);
+ }
+
+ @Subscribe
+ public void onChangeNetworkStatusEvent(ChangeNetworkStatusEvent changeNetworkStatusEvent) {
+ String dataSavingMode = activity.getDefaultSharedPreferences().getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
+ if (dataSavingMode.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
+ if (emotePlugin != null) {
+ emotePlugin.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR);
+ }
+
+ if (imageAndGifEntry != null) {
+ imageAndGifEntry.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR);
+ }
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
index 91113d84..e9618502 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java
@@ -2005,26 +2005,33 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Subscribe
public void onChangeNetworkStatusEvent(ChangeNetworkStatusEvent changeNetworkStatusEvent) {
- if (mPostAdapter != null) {
- String autoplay = mSharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
- String dataSavingMode = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
- boolean stateChanged = false;
- if (autoplay.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) {
+ String autoplay = mSharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
+ String dataSavingMode = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
+ boolean stateChanged = false;
+ if (autoplay.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) {
+ if (mPostAdapter != null) {
mPostAdapter.setAutoplay(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_WIFI);
- stateChanged = true;
}
- if (dataSavingMode.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
+ stateChanged = true;
+ }
+ if (dataSavingMode.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
+ if (mPostAdapter != null) {
mPostAdapter.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR);
- stateChanged = true;
}
+ if (mCommentsAdapter != null) {
+ mCommentsAdapter.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR);
+ }
+ stateChanged = true;
+ }
- if (stateChanged) {
- if (mCommentsRecyclerView == null) {
- refreshAdapter(mRecyclerView, mConcatAdapter);
- } else {
+ if (stateChanged) {
+ if (mCommentsRecyclerView == null) {
+ refreshAdapter(mRecyclerView, mConcatAdapter);
+ } else {
+ if (mPostAdapter != null) {
refreshAdapter(mRecyclerView, mPostAdapter);
- refreshAdapter(mCommentsRecyclerView, mCommentsAdapter);
}
+ refreshAdapter(mCommentsRecyclerView, mCommentsAdapter);
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmotePlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmotePlugin.java
index 05675498..2cdae1a4 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmotePlugin.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/EmotePlugin.java
@@ -1,6 +1,5 @@
package ml.docilealligator.infinityforreddit.markdown;
-import android.content.Context;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.text.Spanned;
@@ -34,9 +33,14 @@ import io.noties.markwon.image.AsyncDrawableLoader;
import io.noties.markwon.image.AsyncDrawableScheduler;
import io.noties.markwon.image.DrawableUtils;
import io.noties.markwon.image.ImageProps;
+import ml.docilealligator.infinityforreddit.activities.BaseActivity;
+import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.utils.Utils;
public class EmotePlugin extends AbstractMarkwonPlugin {
- private boolean disableImagePreview = true;
+ private final GlideAsyncDrawableLoader glideAsyncDrawableLoader;
+ private boolean dataSavingMode;
+ private boolean disableImagePreview;
public interface GlideStore {
@@ -47,16 +51,12 @@ public class EmotePlugin extends AbstractMarkwonPlugin {
}
@NonNull
- public static EmotePlugin create(@NonNull final Context context) {
+ public static EmotePlugin create(@NonNull final BaseActivity baseActivity) {
// @since 4.5.0 cache RequestManager
// sometimes `cancel` would be called after activity is destroyed,
- // so `Glide.with(context)` will throw an exception
- return create(Glide.with(context));
- }
-
- @NonNull
- public static EmotePlugin create(@NonNull final RequestManager requestManager) {
- return create(new GlideStore() {
+ // so `Glide.with(baseActivity)` will throw an exception
+ RequestManager requestManager = Glide.with(baseActivity);
+ return new EmotePlugin(baseActivity, new GlideStore() {
@NonNull
@Override
public RequestBuilder<Drawable> load(@NonNull AsyncDrawable drawable) {
@@ -71,15 +71,42 @@ public class EmotePlugin extends AbstractMarkwonPlugin {
}
@NonNull
- public static EmotePlugin create(@NonNull GlideStore glideStore) {
- return new EmotePlugin(glideStore);
+ public static EmotePlugin create(@NonNull final BaseActivity baseActivity, boolean dataSavingMode, boolean disableImagePreview) {
+ // @since 4.5.0 cache RequestManager
+ // sometimes `cancel` would be called after activity is destroyed,
+ // so `Glide.with(baseActivity)` will throw an exception
+ RequestManager requestManager = Glide.with(baseActivity);
+ return new EmotePlugin(baseActivity, new GlideStore() {
+ @NonNull
+ @Override
+ public RequestBuilder<Drawable> load(@NonNull AsyncDrawable drawable) {
+ return requestManager.load(drawable.getDestination());
+ }
+
+ @Override
+ public void cancel(@NonNull Target<?> target) {
+ requestManager.clear(target);
+ }
+ }, dataSavingMode, disableImagePreview);
}
- private final GlideAsyncDrawableLoader glideAsyncDrawableLoader;
+ @SuppressWarnings("WeakerAccess")
+ EmotePlugin(@NonNull final BaseActivity baseActivity, @NonNull GlideStore glideStore) {
+ this.glideAsyncDrawableLoader = new GlideAsyncDrawableLoader(glideStore);
+ String dataSavingModeString = baseActivity.getDefaultSharedPreferences().getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
+ if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ALWAYS)) {
+ dataSavingMode = true;
+ } else if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) {
+ dataSavingMode = Utils.getConnectedNetwork(baseActivity) == Utils.NETWORK_TYPE_CELLULAR;
+ }
+ disableImagePreview = baseActivity.getDefaultSharedPreferences().getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false);
+ }
@SuppressWarnings("WeakerAccess")
- EmotePlugin(@NonNull GlideStore glideStore) {
+ EmotePlugin(@NonNull final BaseActivity baseActivity, @NonNull GlideStore glideStore, boolean dataSavingMode, boolean disableImagePreview) {
this.glideAsyncDrawableLoader = new GlideAsyncDrawableLoader(glideStore);
+ this.dataSavingMode = dataSavingMode;
+ this.disableImagePreview = disableImagePreview;
}
@Override
@@ -95,7 +122,7 @@ public class EmotePlugin extends AbstractMarkwonPlugin {
@Override
public void configureVisitor(@NonNull MarkwonVisitor.Builder builder) {
builder.on(Emote.class, (visitor, emote) -> {
- if (disableImagePreview) {
+ if (dataSavingMode && disableImagePreview) {
Link link = new Link(emote.getMediaMetadata().original.url, emote.getTitle());
final int length = visitor.length();
@@ -155,8 +182,8 @@ public class EmotePlugin extends AbstractMarkwonPlugin {
AsyncDrawableScheduler.schedule(textView);
}
- public void setDisableImagePreview(boolean disableImagePreview) {
- this.disableImagePreview = disableImagePreview;
+ public void setDataSavingMode(boolean dataSavingMode) {
+ this.dataSavingMode = dataSavingMode;
}
private static class GlideAsyncDrawableLoader extends AsyncDrawableLoader {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java
index 12e62632..68611cb0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java
@@ -185,6 +185,10 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
holder.binding.captionTextViewMarkdownImageAndGifBlock.setGravity(Gravity.CENTER_HORIZONTAL);
}
+ public void setDataSavingMode(boolean dataSavingMode) {
+ this.dataSavingMode = dataSavingMode;
+ }
+
public class Holder extends MarkwonAdapter.Holder {
MarkdownImageAndGifBlockBinding binding;
RequestListener<Drawable> requestListener;