From 24f5682bf800d1fcd71e65f827e619ea89d1bf0c Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 10 Nov 2021 21:25:32 +0800 Subject: Some UI tweaks. --- .../activities/EditProfileActivity.java | 30 ++++++++++++++++------ .../activities/PostGalleryActivity.java | 17 +++++------- .../activities/PostImageActivity.java | 17 +++++------- .../activities/PostLinkActivity.java | 15 ++++------- .../activities/PostTextActivity.java | 17 +++++------- .../activities/PostVideoActivity.java | 23 ++++++++--------- 6 files changed, 56 insertions(+), 63 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java index f267e9f4..27086981 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java @@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.activities; import android.content.Intent; import android.content.SharedPreferences; +import android.os.Build; import android.os.Bundle; import android.view.Gravity; import android.view.Menu; @@ -17,7 +18,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.ContextCompat; import androidx.lifecycle.ViewModelProvider; @@ -26,6 +26,8 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import com.bumptech.glide.request.RequestOptions; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.appbar.CollapsingToolbarLayout; +import com.google.android.material.appbar.MaterialToolbar; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.r0adkll.slidr.Slidr; import com.r0adkll.slidr.model.SlidrInterface; @@ -50,6 +52,7 @@ import ml.docilealligator.infinityforreddit.services.EditProfileService; import ml.docilealligator.infinityforreddit.user.UserViewModel; import ml.docilealligator.infinityforreddit.utils.EditProfileUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; public class EditProfileActivity extends BaseActivity { @@ -61,14 +64,16 @@ public class EditProfileActivity extends BaseActivity { CoordinatorLayout root; @BindView(R.id.content_view_edit_profile_activity) LinearLayout content; + @BindView(R.id.collapsing_toolbar_layout_edit_profile_activity) + CollapsingToolbarLayout collapsingToolbarLayout; @BindView(R.id.appbar_layout_view_edit_profile_activity) AppBarLayout appBarLayout; @BindView(R.id.toolbar_view_edit_profile_activity) - Toolbar toolbar; + MaterialToolbar toolbar; @BindView(R.id.image_view_banner_edit_profile_activity) - ImageView bannerImageView; + GifImageView bannerImageView; @BindView(R.id.image_view_avatar_edit_profile_activity) - ImageView avatarImageView; + GifImageView avatarImageView; @BindView(R.id.image_view_change_banner_edit_profile_activity) ImageView changeBanner; @BindView(R.id.image_view_change_avatar_edit_profile_activity) @@ -92,20 +97,28 @@ public class EditProfileActivity extends BaseActivity { @Inject CustomThemeWrapper mCustomThemeWrapper; - // private String mAccountName; private String mAccessToken; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { ((Infinity) getApplication()).getAppComponent().inject(this); - setTransparentStatusBarAfterToolbarCollapsed(); + + setImmersiveModeNotApplicable(); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit_profile); + ButterKnife.bind(this); + EventBus.getDefault().register(this); + applyCustomTheme(); - adjustToolbar(toolbar); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } + setSupportActionBar(toolbar); if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) { @@ -328,8 +341,9 @@ public class EditProfileActivity extends BaseActivity { @Override protected void applyCustomTheme() { - applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); + applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, collapsingToolbarLayout, toolbar); root.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); + changeColorTextView(content, mCustomThemeWrapper.getPrimaryTextColor()); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java index 3dcb726e..a3c12c29 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java @@ -35,6 +35,7 @@ import com.bumptech.glide.request.RequestOptions; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.button.MaterialButton; import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.divider.MaterialDivider; import com.google.android.material.snackbar.Snackbar; import com.google.android.material.switchmaterial.SwitchMaterial; import com.google.gson.Gson; @@ -110,27 +111,23 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee @BindView(R.id.rules_button_post_gallery_activity) MaterialButton rulesButton; @BindView(R.id.divider_1_post_gallery_activity) - View divider1; + MaterialDivider divider1; @BindView(R.id.flair_custom_text_view_post_gallery_activity) CustomTextView flairTextView; @BindView(R.id.spoiler_custom_text_view_post_gallery_activity) CustomTextView spoilerTextView; @BindView(R.id.nsfw_custom_text_view_post_gallery_activity) CustomTextView nsfwTextView; - @BindView(R.id.divider_2_post_gallery_activity) - View divider2; @BindView(R.id.receive_post_reply_notifications_linear_layout_post_gallery_activity) LinearLayout receivePostReplyNotificationsLinearLayout; @BindView(R.id.receive_post_reply_notifications_text_view_post_gallery_activity) TextView receivePostReplyNotificationsTextView; @BindView(R.id.receive_post_reply_notifications_switch_material_post_gallery_activity) SwitchMaterial receivePostReplyNotificationsSwitchMaterial; - @BindView(R.id.divider_3_post_gallery_activity) - View divider3; + @BindView(R.id.divider_2_post_gallery_activity) + MaterialDivider divider2; @BindView(R.id.post_title_edit_text_post_gallery_activity) EditText titleEditText; - @BindView(R.id.divider_4_post_gallery_activity) - View divider4; @BindView(R.id.images_recycler_view_post_gallery_activity) RecyclerView imagesRecyclerView; @Inject @@ -415,10 +412,8 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); receivePostReplyNotificationsTextView.setTextColor(primaryTextColor); int dividerColor = mCustomThemeWrapper.getDividerColor(); - divider1.setBackgroundColor(dividerColor); - divider2.setBackgroundColor(dividerColor); - divider3.setBackgroundColor(dividerColor); - divider4.setBackgroundColor(dividerColor); + divider1.setDividerColor(dividerColor); + divider2.setDividerColor(dividerColor); flairBackgroundColor = mCustomThemeWrapper.getFlairBackgroundColor(); flairTextColor = mCustomThemeWrapper.getFlairTextColor(); spoilerBackgroundColor = mCustomThemeWrapper.getSpoilerBackgroundColor(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java index cf6c7664..759f4911 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java @@ -32,6 +32,7 @@ import com.bumptech.glide.request.RequestOptions; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.button.MaterialButton; import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.divider.MaterialDivider; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; import com.google.android.material.switchmaterial.SwitchMaterial; @@ -97,27 +98,23 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF @BindView(R.id.rules_button_post_image_activity) MaterialButton rulesButton; @BindView(R.id.divider_1_post_image_activity) - View divider1; + MaterialDivider divider1; @BindView(R.id.flair_custom_text_view_post_image_activity) CustomTextView flairTextView; @BindView(R.id.spoiler_custom_text_view_post_image_activity) CustomTextView spoilerTextView; @BindView(R.id.nsfw_custom_text_view_post_image_activity) CustomTextView nsfwTextView; - @BindView(R.id.divider_2_post_image_activity) - View divider2; @BindView(R.id.receive_post_reply_notifications_linear_layout_post_image_activity) LinearLayout receivePostReplyNotificationsLinearLayout; @BindView(R.id.receive_post_reply_notifications_text_view_post_image_activity) TextView receivePostReplyNotificationsTextView; @BindView(R.id.receive_post_reply_notifications_switch_material_post_image_activity) SwitchMaterial receivePostReplyNotificationsSwitchMaterial; - @BindView(R.id.divider_3_post_image_activity) - View divider3; + @BindView(R.id.divider_2_post_image_activity) + MaterialDivider divider2; @BindView(R.id.post_title_edit_text_post_image_activity) EditText titleEditText; - @BindView(R.id.divider_4_post_image_activity) - View divider4; @BindView(R.id.select_image_constraint_layout_post_image_activity) ConstraintLayout constraintLayout; @BindView(R.id.capture_fab_post_image_activity) @@ -396,10 +393,8 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); receivePostReplyNotificationsTextView.setTextColor(primaryTextColor); int dividerColor = mCustomThemeWrapper.getDividerColor(); - divider1.setBackgroundColor(dividerColor); - divider2.setBackgroundColor(dividerColor); - divider3.setBackgroundColor(dividerColor); - divider4.setBackgroundColor(dividerColor); + divider1.setDividerColor(dividerColor); + divider2.setDividerColor(dividerColor); flairBackgroundColor = mCustomThemeWrapper.getFlairBackgroundColor(); flairTextColor = mCustomThemeWrapper.getFlairTextColor(); spoilerBackgroundColor = mCustomThemeWrapper.getSpoilerBackgroundColor(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java index eecefa75..a24ece41 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java @@ -26,6 +26,7 @@ import com.bumptech.glide.request.RequestOptions; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.button.MaterialButton; import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.divider.MaterialDivider; import com.google.android.material.snackbar.Snackbar; import com.google.android.material.switchmaterial.SwitchMaterial; import com.libRG.CustomTextView; @@ -91,11 +92,9 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr @BindView(R.id.rules_button_post_link_activity) MaterialButton rulesButton; @BindView(R.id.divider_1_post_link_activity) - View divider1; + MaterialDivider divider1; @BindView(R.id.divider_2_post_link_activity) - View divider2; - @BindView(R.id.divider_4_post_link_activity) - View divider4; + MaterialDivider divider2; @BindView(R.id.flair_custom_text_view_post_link_activity) CustomTextView flairTextView; @BindView(R.id.spoiler_custom_text_view_post_link_activity) @@ -108,8 +107,6 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr TextView receivePostReplyNotificationsTextView; @BindView(R.id.receive_post_reply_notifications_switch_material_post_link_activity) SwitchMaterial receivePostReplyNotificationsSwitchMaterial; - @BindView(R.id.divider_3_post_link_activity) - View divider3; @BindView(R.id.post_title_edit_text_post_link_activity) EditText titleEditText; @BindView(R.id.suggest_title_button_post_link_activity) @@ -370,10 +367,8 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); receivePostReplyNotificationsTextView.setTextColor(primaryTextColor); int dividerColor = mCustomThemeWrapper.getDividerColor(); - divider1.setBackgroundColor(dividerColor); - divider2.setBackgroundColor(dividerColor); - divider3.setBackgroundColor(dividerColor); - divider4.setBackgroundColor(dividerColor); + divider1.setDividerColor(dividerColor); + divider2.setDividerColor(dividerColor); flairBackgroundColor = mCustomThemeWrapper.getFlairBackgroundColor(); flairTextColor = mCustomThemeWrapper.getFlairTextColor(); spoilerBackgroundColor = mCustomThemeWrapper.getSpoilerBackgroundColor(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java index 5336051c..b54e56af 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java @@ -33,6 +33,7 @@ import com.bumptech.glide.request.RequestOptions; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.button.MaterialButton; import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.divider.MaterialDivider; import com.google.android.material.snackbar.Snackbar; import com.google.android.material.switchmaterial.SwitchMaterial; import com.libRG.CustomTextView; @@ -107,27 +108,23 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr @BindView(R.id.rules_button_post_text_activity) MaterialButton rulesButton; @BindView(R.id.divider_1_post_text_activity) - View divider1; + MaterialDivider divider1; @BindView(R.id.flair_custom_text_view_post_text_activity) CustomTextView flairTextView; @BindView(R.id.spoiler_custom_text_view_post_text_activity) CustomTextView spoilerTextView; @BindView(R.id.nsfw_custom_text_view_post_text_activity) CustomTextView nsfwTextView; - @BindView(R.id.divider_2_post_text_activity) - View divider2; @BindView(R.id.receive_post_reply_notifications_linear_layout_post_text_activity) LinearLayout receivePostReplyNotificationsLinearLayout; @BindView(R.id.receive_post_reply_notifications_text_view_post_text_activity) TextView receivePostReplyNotificationsTextView; @BindView(R.id.receive_post_reply_notifications_switch_material_post_text_activity) SwitchMaterial receivePostReplyNotificationsSwitchMaterial; - @BindView(R.id.divider_3_post_text_activity) - View divider3; + @BindView(R.id.divider_2_post_text_activity) + MaterialDivider divider2; @BindView(R.id.post_title_edit_text_post_text_activity) EditText titleEditText; - @BindView(R.id.divider_4_post_text_activity) - View divider4; @BindView(R.id.post_text_content_edit_text_post_text_activity) EditText contentEditText; @BindView(R.id.markdown_bottom_bar_recycler_view_post_text_activity) @@ -394,10 +391,8 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); receivePostReplyNotificationsTextView.setTextColor(primaryTextColor); int dividerColor = mCustomThemeWrapper.getDividerColor(); - divider1.setBackgroundColor(dividerColor); - divider2.setBackgroundColor(dividerColor); - divider3.setBackgroundColor(dividerColor); - divider4.setBackgroundColor(dividerColor); + divider1.setDividerColor(dividerColor); + divider2.setDividerColor(dividerColor); flairBackgroundColor = mCustomThemeWrapper.getFlairBackgroundColor(); flairTextColor = mCustomThemeWrapper.getFlairTextColor(); spoilerBackgroundColor = mCustomThemeWrapper.getSpoilerBackgroundColor(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java index f80b5e94..d1d09ddc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit.activities; +import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; @@ -14,6 +15,7 @@ import android.view.View; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -36,6 +38,7 @@ import com.google.android.exoplayer2.util.Util; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.button.MaterialButton; import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.divider.MaterialDivider; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; import com.google.android.material.switchmaterial.SwitchMaterial; @@ -98,27 +101,23 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF @BindView(R.id.rules_button_post_video_activity) MaterialButton rulesButton; @BindView(R.id.divider_1_post_video_activity) - View divider1; + MaterialDivider divider1; @BindView(R.id.flair_custom_text_view_post_video_activity) CustomTextView flairTextView; @BindView(R.id.spoiler_custom_text_view_post_video_activity) CustomTextView spoilerTextView; @BindView(R.id.nsfw_custom_text_view_post_video_activity) CustomTextView nsfwTextView; - @BindView(R.id.divider_2_post_video_activity) - View divider2; @BindView(R.id.receive_post_reply_notifications_linear_layout_post_video_activity) LinearLayout receivePostReplyNotificationsLinearLayout; @BindView(R.id.receive_post_reply_notifications_text_view_post_video_activity) TextView receivePostReplyNotificationsTextView; @BindView(R.id.receive_post_reply_notifications_switch_material_post_video_activity) SwitchMaterial receivePostReplyNotificationsSwitchMaterial; - @BindView(R.id.divider_3_post_video_activity) - View divider3; + @BindView(R.id.divider_2_post_video_activity) + MaterialDivider divider2; @BindView(R.id.post_title_edit_text_post_video_activity) EditText titleEditText; - @BindView(R.id.divider_4_post_video_activity) - View divider4; @BindView(R.id.select_video_constraint_layout_post_video_activity) ConstraintLayout constraintLayout; @BindView(R.id.capture_fab_post_video_activity) @@ -364,8 +363,10 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF captureFab.setOnClickListener(view -> { Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); - if (takeVideoIntent.resolveActivity(getPackageManager()) != null) { + try { startActivityForResult(takeVideoIntent, CAPTURE_VIDEO_REQUEST_CODE); + } catch (ActivityNotFoundException e) { + Toast.makeText(this, R.string.no_camera_available, Toast.LENGTH_SHORT).show(); } }); @@ -407,10 +408,8 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); receivePostReplyNotificationsTextView.setTextColor(primaryTextColor); int dividerColor = mCustomThemeWrapper.getDividerColor(); - divider1.setBackgroundColor(dividerColor); - divider2.setBackgroundColor(dividerColor); - divider3.setBackgroundColor(dividerColor); - divider4.setBackgroundColor(dividerColor); + divider1.setDividerColor(dividerColor); + divider2.setDividerColor(dividerColor); flairBackgroundColor = mCustomThemeWrapper.getFlairBackgroundColor(); flairTextColor = mCustomThemeWrapper.getFlairTextColor(); spoilerBackgroundColor = mCustomThemeWrapper.getSpoilerBackgroundColor(); -- cgit v1.2.3 From 2e0ef26d0354f817dc9b1ae3b4cfa53de43f2332 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Thu, 11 Nov 2021 01:21:18 +0300 Subject: Fix markdown not rendering in some comments --- .../infinityforreddit/adapters/CommentsRecyclerViewAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main/java') 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 2dad51f9..b9d6bfd0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -180,7 +180,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter![\\S\\s]+?!<"); Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); int start = 0; -- cgit v1.2.3 From 96b9b51b6d4da2060988358f04db6ffce7a0235a Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Thu, 11 Nov 2021 08:00:40 +0000 Subject: Missed this one --- .../infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main/java') 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 e3a1d53a..e298734c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -137,7 +137,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter![\\S\\s]+?!<"); Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); int start = 0; -- cgit v1.2.3 From d6d6ed5407bf8479957290d1e7cf79279dd4c427 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 11 Nov 2021 20:37:28 +0800 Subject: UI changes in EditProfileActivity. --- .../activities/EditProfileActivity.java | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java index 27086981..d9248652 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java @@ -143,22 +143,26 @@ public class EditProfileActivity extends BaseActivity { new ViewModelProvider(this, userViewModelFactory).get(UserViewModel.class); userViewModel.getUserLiveData().observe(this, userData -> { - if (userData == null) return;// + if (userData == null) { + return; + } // BANNER final String userBanner = userData.getBanner(); LayoutParams cBannerLp = (LayoutParams) changeBanner.getLayoutParams(); if (userBanner == null || userBanner.isEmpty()) { changeBanner.setLongClickable(false); - changeBanner.setImageResource(R.drawable.ic_add_day_night_24dp); - changeBanner.setLayoutParams(new LayoutParams(cBannerLp.width, cBannerLp.height, Gravity.CENTER)); + cBannerLp.gravity = Gravity.CENTER; + changeBanner.setLayoutParams(cBannerLp); changeBanner.setOnLongClickListener(v -> false); } else { changeBanner.setLongClickable(true); - changeBanner.setImageResource(R.drawable.ic_outline_add_a_photo_day_night_24dp); - changeBanner.setLayoutParams(new LayoutParams(cBannerLp.width, cBannerLp.height, Gravity.END | Gravity.BOTTOM)); + cBannerLp.gravity = Gravity.END | Gravity.BOTTOM; + changeBanner.setLayoutParams(cBannerLp); glide.load(userBanner).into(bannerImageView); changeBanner.setOnLongClickListener(view -> { - if (mAccessToken == null) return false; + if (mAccessToken == null) { + return false; + } new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) .setTitle(R.string.remove_banner) .setMessage(R.string.are_you_sure) @@ -195,15 +199,13 @@ public class EditProfileActivity extends BaseActivity { LayoutParams cAvatarLp = (LayoutParams) changeAvatar.getLayoutParams(); if (userAvatar.contains("avatar_default_")) { changeAvatar.setLongClickable(false); - changeAvatar.setImageResource(R.drawable.ic_add_day_night_24dp); - changeAvatar.setLayoutParams(new LayoutParams(cAvatarLp.width, cAvatarLp.height, Gravity.CENTER)); changeAvatar.setOnLongClickListener(v -> false); } else { changeAvatar.setLongClickable(true); - changeAvatar.setImageResource(R.drawable.ic_outline_add_a_photo_day_night_24dp); - changeAvatar.setLayoutParams(new LayoutParams(cAvatarLp.width, cAvatarLp.height, Gravity.END | Gravity.BOTTOM)); changeAvatar.setOnLongClickListener(view -> { - if (mAccessToken == null) return false; + if (mAccessToken == null) { + return false; + } new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) .setTitle(R.string.remove_avatar) .setMessage(R.string.are_you_sure) -- cgit v1.2.3 From 2cdf523eff80d4cee7bab64fbdd6c1e34908207d Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Thu, 11 Nov 2021 18:41:24 +0300 Subject: More fixes related to markdown rendering --- .../infinityforreddit/activities/CommentActivity.java | 11 ++++++++--- .../infinityforreddit/activities/FullMarkdownActivity.java | 9 ++++++--- .../activities/ViewSubredditDetailActivity.java | 5 +++++ .../infinityforreddit/activities/ViewUserDetailActivity.java | 5 +++++ .../infinityforreddit/activities/WikiActivity.java | 9 ++++++--- .../adapters/CommentsListingRecyclerViewAdapter.java | 7 +++++-- .../adapters/CommentsRecyclerViewAdapter.java | 7 +++++-- .../adapters/MessageRecyclerViewAdapter.java | 9 ++++++--- .../adapters/PostDetailRecyclerViewAdapter.java | 9 ++++++--- .../adapters/PrivateMessagesDetailRecyclerViewAdapter.java | 7 +++++-- .../infinityforreddit/adapters/RulesRecyclerViewAdapter.java | 7 +++++-- .../infinityforreddit/fragments/SidebarFragment.java | 7 +++++-- 12 files changed, 67 insertions(+), 25 deletions(-) (limited to 'app/src/main/java') 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 1f85f362..db2353dc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -50,7 +50,8 @@ 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.html.HtmlPlugin; +import io.noties.markwon.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.recycler.MarkwonAdapter; import io.noties.markwon.recycler.table.TableEntry; @@ -160,7 +161,9 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA int linkColor = mCustomThemeWrapper.getLinkColor(); Markwon markwon = Markwon.builder(this) - .usePlugin(HtmlPlugin.create()) + .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { @@ -201,7 +204,9 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA contentMarkdownRecyclerView.setVisibility(View.VISIBLE); contentMarkdownRecyclerView.setNestedScrollingEnabled(false); Markwon postBodyMarkwon = Markwon.builder(this) - .usePlugin(HtmlPlugin.create()) + .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { 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 60406d70..7a54b5d1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -47,7 +47,8 @@ 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.html.HtmlPlugin; +import io.noties.markwon.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.recycler.MarkwonAdapter; import io.noties.markwon.recycler.table.TableEntry; @@ -131,7 +132,9 @@ public class FullMarkdownActivity extends BaseActivity { int spoilerBackgroundColor = markdownColor | 0xFF000000; int linkColor = mCustomThemeWrapper.getLinkColor(); Markwon markwon = Markwon.builder(this) - .usePlugin(HtmlPlugin.create()) + .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @NonNull @Override @@ -152,7 +155,7 @@ public class FullMarkdownActivity extends BaseActivity { @Override public void afterSetText(@NonNull TextView textView) { textView.setHighlightColor(Color.TRANSPARENT); - SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText().toString()); + SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText()); Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); int start = 0; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index 2f534fb0..368e2b46 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -71,6 +71,8 @@ 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.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; @@ -380,6 +382,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp Locale locale = getResources().getConfiguration().locale; Markwon markwon = Markwon.builder(this) + .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index d12290ee..7ef81969 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -73,6 +73,8 @@ 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.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; @@ -376,6 +378,9 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele Locale locale = getResources().getConfiguration().locale; Markwon markwon = Markwon.builder(this) + .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { 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 63b147fb..d5c8cb61 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -51,7 +51,8 @@ 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.html.HtmlPlugin; +import io.noties.markwon.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.recycler.MarkwonAdapter; import io.noties.markwon.recycler.table.TableEntry; @@ -156,7 +157,9 @@ public class WikiActivity extends BaseActivity { int spoilerBackgroundColor = markdownColor | 0xFF000000; int linkColor = mCustomThemeWrapper.getLinkColor(); markwon = Markwon.builder(this) - .usePlugin(HtmlPlugin.create()) + .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @NonNull @Override @@ -177,7 +180,7 @@ public class WikiActivity extends BaseActivity { @Override public void afterSetText(@NonNull TextView textView) { textView.setHighlightColor(Color.TRANSPARENT); - SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText().toString()); + SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText()); Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); int start = 0; 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 e298734c..cc0e640d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -42,7 +42,8 @@ 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.html.HtmlPlugin; +import io.noties.markwon.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import me.saket.bettermovementmethod.BetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.NetworkState; @@ -116,7 +117,9 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @NonNull @Override 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 b9d6bfd0..a06b476d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -47,7 +47,8 @@ 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.html.HtmlPlugin; +import io.noties.markwon.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; import me.saket.bettermovementmethod.BetterLinkMovementMethod; @@ -160,7 +161,9 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @NonNull @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java index 440544dc..4c0ae441 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java @@ -34,7 +34,8 @@ 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.html.HtmlPlugin; +import io.noties.markwon.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.R; @@ -99,7 +100,9 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @NonNull @Override @@ -120,7 +123,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter![\\S\\s]+?!<"); Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); int start = 0; 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 e5075417..ccb19b26 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -73,7 +73,8 @@ 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.html.HtmlPlugin; +import io.noties.markwon.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; import io.noties.markwon.recycler.MarkwonAdapter; @@ -226,7 +227,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @NonNull @Override @@ -247,7 +250,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter![\\S\\s]+?!<"); Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); int start = 0; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java index 8fe78d79..e4ca0dd0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java @@ -27,7 +27,8 @@ 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.html.HtmlPlugin; +import io.noties.markwon.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.R; @@ -66,7 +67,9 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt mLocale = locale; mAccountName = accountName; mMarkwon = Markwon.builder(viewPrivateMessagesActivity) - .usePlugin(HtmlPlugin.create()) + .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { 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 454ecdd4..6cf4ee07 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -22,7 +22,8 @@ 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.html.HtmlPlugin; +import io.noties.markwon.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; import me.saket.bettermovementmethod.BetterLinkMovementMethod; @@ -40,7 +41,9 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { 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 ef3d6925..f02db229 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -34,7 +34,8 @@ 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.html.HtmlPlugin; +import io.noties.markwon.inlineparser.HtmlInlineProcessor; +import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; import io.noties.markwon.movement.MovementMethodPlugin; import io.noties.markwon.recycler.MarkwonAdapter; @@ -104,7 +105,9 @@ public class SidebarFragment extends Fragment { markdownColor = mCustomThemeWrapper.getPrimaryTextColor(); Markwon markwon = Markwon.builder(activity) - .usePlugin(HtmlPlugin.create()) + .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + })) .usePlugin(new AbstractMarkwonPlugin() { @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { -- cgit v1.2.3 From 1960bb5ea14c153b688a5f0fedb8c05998af2bd7 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Fri, 12 Nov 2021 01:51:54 +0300 Subject: Add custom superscript processor --- .../activities/CommentActivity.java | 14 +++++++ .../activities/FullMarkdownActivity.java | 12 +++++- .../infinityforreddit/activities/WikiActivity.java | 12 +++++- .../CommentsListingRecyclerViewAdapter.java | 12 +++++- .../adapters/CommentsRecyclerViewAdapter.java | 15 ++++++- .../adapters/MessageRecyclerViewAdapter.java | 11 ++++++ .../adapters/PostDetailRecyclerViewAdapter.java | 12 +++++- .../PrivateMessagesDetailRecyclerViewAdapter.java | 9 +++++ .../adapters/RulesRecyclerViewAdapter.java | 9 +++++ .../CopyTextBottomSheetFragment.java | 4 +- .../fragments/SidebarFragment.java | 9 +++++ .../utils/ProcessRedditSuperscript.java | 46 ++++++++++++++++++++++ .../utils/SuperscriptInlineProcessor.java | 32 +++++++++++++++ .../infinityforreddit/utils/Utils.java | 5 ++- 14 files changed, 195 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/utils/ProcessRedditSuperscript.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/utils/SuperscriptInlineProcessor.java (limited to 'app/src/main/java') 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 db2353dc..2ffa10e7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -50,6 +50,8 @@ 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.html.HtmlPlugin; +import io.noties.markwon.html.tag.SuperScriptHandler; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -68,7 +70,9 @@ import ml.docilealligator.infinityforreddit.comment.SendComment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; +import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; @@ -163,7 +167,12 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA Markwon markwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { @@ -206,7 +215,12 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA Markwon postBodyMarkwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); + })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { 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 7a54b5d1..92bd1ec8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -47,6 +47,8 @@ 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.html.HtmlPlugin; +import io.noties.markwon.html.tag.SuperScriptHandler; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -59,7 +61,9 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; +import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; public class FullMarkdownActivity extends BaseActivity { @@ -134,8 +138,14 @@ public class FullMarkdownActivity extends BaseActivity { Markwon markwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { @@ -151,7 +161,7 @@ public class FullMarkdownActivity extends BaseActivity { } return super.processMarkdown(markdownStringBuilder.toString()); } - + */ @Override public void afterSetText(@NonNull TextView textView) { textView.setHighlightColor(Color.TRANSPARENT); 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 d5c8cb61..644ac4b5 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,8 @@ 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.html.HtmlPlugin; +import io.noties.markwon.html.tag.SuperScriptHandler; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -65,7 +67,9 @@ import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFi import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.utils.JSONUtils; +import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -159,8 +163,14 @@ public class WikiActivity extends BaseActivity { markwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { @@ -176,7 +186,7 @@ public class WikiActivity extends BaseActivity { } return super.processMarkdown(markdownStringBuilder.toString()); } - + */ @Override public void afterSetText(@NonNull TextView textView) { textView.setHighlightColor(Color.TRANSPARENT); 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 cc0e640d..1a3fb7ac 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -42,6 +42,8 @@ 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.html.HtmlPlugin; +import io.noties.markwon.html.tag.SuperScriptHandler; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -61,7 +63,9 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.CommentIndentationView; import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView; import ml.docilealligator.infinityforreddit.utils.APIUtils; +import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; +import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; @@ -119,8 +123,14 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { @@ -136,7 +146,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { @@ -180,7 +193,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { @@ -102,8 +106,14 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { @@ -119,6 +129,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { @@ -246,7 +256,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { @@ -69,7 +73,12 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt mMarkwon = Markwon.builder(viewPrivateMessagesActivity) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { 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 6cf4ee07..4eb9d5d8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -22,6 +22,8 @@ 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.html.HtmlPlugin; +import io.noties.markwon.html.tag.SuperScriptHandler; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -32,6 +34,8 @@ import ml.docilealligator.infinityforreddit.Rule; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; +import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { private Markwon markwon; @@ -43,7 +47,12 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java index d8cf1fe9..4264f36a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java @@ -6,6 +6,7 @@ import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; import android.os.Bundle; +import android.text.Html; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -72,7 +73,8 @@ public class CopyTextBottomSheetFragment extends LandscapeExpandedRoundedBottomS } if (markdownText != null) { - markdownText = markdownText.replaceAll("", "^").replaceAll("", ""); + //markdownText = markdownText.replaceAll("", "^").replaceAll("", ""); + markdownText = markdownText.replaceAll(">", ">"); copyMarkdownTextView.setOnClickListener(view -> { showCopyDialog(markdownText); dismiss(); 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 f02db229..416b3046 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -34,6 +34,8 @@ 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.html.HtmlPlugin; +import io.noties.markwon.html.tag.SuperScriptHandler; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -55,6 +57,8 @@ import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFi import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData; import ml.docilealligator.infinityforreddit.subreddit.SubredditData; import ml.docilealligator.infinityforreddit.subreddit.SubredditViewModel; +import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; +import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; import retrofit2.Retrofit; public class SidebarFragment extends Fragment { @@ -107,7 +111,12 @@ public class SidebarFragment extends Fragment { Markwon markwon = Markwon.builder(activity) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) + .usePlugin(HtmlPlugin.create(plugin -> { + plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); + })) + .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/ProcessRedditSuperscript.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/ProcessRedditSuperscript.java new file mode 100644 index 00000000..0dc539d7 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/ProcessRedditSuperscript.java @@ -0,0 +1,46 @@ +package ml.docilealligator.infinityforreddit.utils; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import io.noties.markwon.AbstractMarkwonPlugin; + +public class ProcessRedditSuperscript extends AbstractMarkwonPlugin { + private static final Pattern re = Pattern.compile("(?:\\^\\((.+?)\\))|(?:\\^(\\S+))"); + + @Override + public String processMarkdown(String markdown) { + StringBuilder builder = new StringBuilder(); + Matcher matcher = re.matcher(markdown); + int start = 0; + + while (matcher.find()) { + try { + String match; + if ((match = matcher.group(1)) != null || (match = matcher.group(2)) != null) { + builder.append(markdown.substring(start, matcher.start())) + .append("") + .append(match) + .append(""); + start = matcher.end(); + } else { + throw new NullPointerException(); + } + } catch(NullPointerException e) { + e.printStackTrace(); + } finally { + continue; + } + } + + if (start < markdown.length()) { + builder.append(markdown.substring(start)); + } + + if(builder.length() > 0) { + return builder.toString(); } + else { + return markdown; + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SuperscriptInlineProcessor.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SuperscriptInlineProcessor.java new file mode 100644 index 00000000..136a69d4 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SuperscriptInlineProcessor.java @@ -0,0 +1,32 @@ +package ml.docilealligator.infinityforreddit.utils; + +import androidx.annotation.Nullable; + +import org.commonmark.node.HtmlInline; +import org.commonmark.node.Node; + +import java.util.regex.Pattern; + +import io.noties.markwon.inlineparser.InlineProcessor; + +public class SuperscriptInlineProcessor extends InlineProcessor { + private static final Pattern HTML_TAG = Pattern.compile("", Pattern.CASE_INSENSITIVE); + + @Override + public char specialCharacter() { + return '<'; + } + + @Nullable + @Override + protected Node parse() { + String m = match(HTML_TAG); + if (m != null) { + HtmlInline node = new HtmlInline(); + node.setLiteral(m); + return node; + } else { + return null; + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java index ad2b7405..16aeb642 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -65,6 +65,8 @@ public class Utils { .replaceAll("((?<=[\\s])|^)/[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com$0)") .replaceAll("((?<=[\\s])|^)[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com/$0)") .replaceAll("\\^{2,}", "^") + .replaceAll("(", "$1>") + .replaceAll(">!", ">!") .replaceAll("(^|^ *|\\n *)#(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)##(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)###(?!($|\\s|#))", "$0 ") @@ -72,7 +74,8 @@ public class Utils { .replaceAll("(^|^ *|\\n *)#####(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)######(?!($|\\s|#))", "$0 ")); - return fixSuperScript(regexed); + //return fixSuperScript(regexed); + return regexed.toString(); } private static String fixSuperScript(StringBuilder regexed) { -- cgit v1.2.3 From f8c15e03af5a28251ee1abc88b1be1b1bbf8ad82 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 12 Nov 2021 09:10:21 +0800 Subject: Contact mods. --- .../infinityforreddit/activities/ViewSubredditDetailActivity.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index 2f534fb0..8cf3dfc6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -1137,12 +1137,17 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp Toast.makeText(this, R.string.no_app, Toast.LENGTH_SHORT).show(); } return true; - } else if (itemId == R.id.action_go_to_wiki_activity ) { + } else if (itemId == R.id.action_go_to_wiki_view_subreddit_detail_activity) { Intent wikiIntent = new Intent(this, WikiActivity.class); wikiIntent.putExtra(WikiActivity.EXTRA_SUBREDDIT_NAME, subredditName); wikiIntent.putExtra(WikiActivity.EXTRA_WIKI_PATH, "index"); startActivity(wikiIntent); return true; + } else if (itemId == R.id.action_contact_mods_view_subreddit_detail_activity) { + Intent intent = new Intent(this, SendPrivateMessageActivity.class); + intent.putExtra(SendPrivateMessageActivity.EXTRA_RECIPIENT_USERNAME, "r/" + subredditName); + startActivity(intent); + return true; } return false; } -- cgit v1.2.3 From 5fae42c210df8def1e32e4e306fd09729fc1f4ec Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Sat, 13 Nov 2021 01:34:28 +0300 Subject: Try to handle unescaped space inside link blocks * Commonmark spec does not parse links with unescaped spaces in the link query * Maybe we can do the parsing ourselves by extending 'InlineProcessor', instead of using slow regex * Reuse `fixSuperScript` --- .../activities/CommentActivity.java | 15 ++++-- .../activities/EditCommentActivity.java | 2 +- .../activities/EditPostActivity.java | 2 +- .../activities/FullMarkdownActivity.java | 19 ++------ .../infinityforreddit/activities/WikiActivity.java | 19 ++------ .../CommentsListingRecyclerViewAdapter.java | 18 +------- .../adapters/CommentsRecyclerViewAdapter.java | 20 +------- .../adapters/MessageRecyclerViewAdapter.java | 17 +------ .../adapters/PostDetailRecyclerViewAdapter.java | 17 +------ .../PrivateMessagesDetailRecyclerViewAdapter.java | 8 +++- .../adapters/RulesRecyclerViewAdapter.java | 9 +++- .../fragments/SidebarFragment.java | 9 +++- .../utils/ProcessRedditSuperscript.java | 46 ------------------- .../infinityforreddit/utils/Utils.java | 53 ++++++++++++++++++++-- 14 files changed, 97 insertions(+), 157 deletions(-) delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/utils/ProcessRedditSuperscript.java (limited to 'app/src/main/java') 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 2ffa10e7..b6e5717a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -70,7 +70,6 @@ import ml.docilealligator.infinityforreddit.comment.SendComment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; -import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -172,8 +171,13 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA .usePlugin(HtmlPlugin.create(plugin -> { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + @NonNull + @Override + public String processMarkdown(@NonNull String markdown) { + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + } + @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { builder.linkResolver((view, link) -> { @@ -220,8 +224,13 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA .usePlugin(HtmlPlugin.create(plugin -> { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + @NonNull + @Override + public String processMarkdown(@NonNull String markdown) { + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + } + @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { textView.setTextColor(markdownColor); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java index 4f4b81ec..cb03370b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java @@ -132,7 +132,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab mFullName = getIntent().getStringExtra(EXTRA_FULLNAME); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - mCommentContent = getIntent().getStringExtra(EXTRA_CONTENT); + mCommentContent = getIntent().getStringExtra(EXTRA_CONTENT).replaceAll(">",">"); contentEditText.setText(mCommentContent); if (savedInstanceState != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java index 0d22d9b3..16e91ebc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java @@ -141,7 +141,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled mFullName = getIntent().getStringExtra(EXTRA_FULLNAME); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); titleTextView.setText(getIntent().getStringExtra(EXTRA_TITLE)); - mPostContent = getIntent().getStringExtra(EXTRA_CONTENT); + mPostContent = getIntent().getStringExtra(EXTRA_CONTENT).replaceAll(">",">");; contentEditText.setText(mPostContent); if (savedInstanceState != null) { 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 92bd1ec8..5ef80ffc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -33,7 +33,6 @@ import org.commonmark.ext.gfm.tables.TableBlock; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; -import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -61,9 +60,9 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; -import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; +import ml.docilealligator.infinityforreddit.utils.Utils; public class FullMarkdownActivity extends BaseActivity { @@ -143,25 +142,13 @@ public class FullMarkdownActivity extends BaseActivity { .usePlugin(HtmlPlugin.create(plugin -> { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { - /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { - StringBuilder markdownStringBuilder = new StringBuilder(markdown); - Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - ArrayList matched = new ArrayList<>(); - while (matcher.find()) { - matched.add(matcher.start()); - } - for (int i = matched.size() - 1; i >= 0; i--) { - markdownStringBuilder.replace(matched.get(i), matched.get(i) + 1, ">"); - } - return super.processMarkdown(markdownStringBuilder.toString()); + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); } - */ + @Override public void afterSetText(@NonNull TextView textView) { textView.setHighlightColor(Color.TRANSPARENT); 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 644ac4b5..657eafe7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -37,7 +37,6 @@ import org.greenrobot.eventbus.Subscribe; import org.json.JSONException; import org.json.JSONObject; -import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -67,9 +66,9 @@ import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFi import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.utils.JSONUtils; -import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; +import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -168,25 +167,13 @@ public class WikiActivity extends BaseActivity { .usePlugin(HtmlPlugin.create(plugin -> { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { - /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { - StringBuilder markdownStringBuilder = new StringBuilder(markdown); - Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - ArrayList matched = new ArrayList<>(); - while (matcher.find()) { - matched.add(matcher.start()); - } - for (int i = matched.size() - 1; i >= 0; i--) { - markdownStringBuilder.replace(matched.get(i), matched.get(i) + 1, ">"); - } - return super.processMarkdown(markdownStringBuilder.toString()); + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); } - */ + @Override public void afterSetText(@NonNull TextView textView) { textView.setHighlightColor(Color.TRANSPARENT); 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 1a3fb7ac..176953ea 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -30,7 +30,6 @@ import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; -import java.util.ArrayList; import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -63,7 +62,6 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.CommentIndentationView; import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView; import ml.docilealligator.infinityforreddit.utils.APIUtils; -import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -128,25 +126,13 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { - /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { - StringBuilder markdownStringBuilder = new StringBuilder(markdown); - Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - ArrayList matched = new ArrayList<>(); - while (matcher.find()) { - matched.add(matcher.start()); - } - for (int i = matched.size() - 1; i >= 0; i--) { - markdownStringBuilder.replace(matched.get(i), matched.get(i) + 1, ">"); - } - return super.processMarkdown(markdownStringBuilder.toString()); + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); } - */ + @Override public void afterSetText(@NonNull TextView textView) { textView.setHighlightColor(Color.TRANSPARENT); 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 8a6cb8b9..d59514cf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -47,10 +47,7 @@ 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.html.HtmlEmptyTagReplacement; import io.noties.markwon.html.HtmlPlugin; -import io.noties.markwon.html.tag.ImageHandler; -import io.noties.markwon.html.tag.LinkHandler; import io.noties.markwon.html.tag.SuperScriptHandler; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; @@ -74,7 +71,6 @@ import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView; import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.utils.APIUtils; -import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -175,25 +171,13 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { - /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { - StringBuilder markdownStringBuilder = new StringBuilder(markdown); - Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - ArrayList matched = new ArrayList<>(); - while (matcher.find()) { - matched.add(matcher.start()); - } - for (int i = matched.size() - 1; i >= 0; i--) { - markdownStringBuilder.replace(matched.get(i), matched.get(i) + 1, ">"); - } - return super.processMarkdown(markdownStringBuilder.toString()); + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); } - */ + @Override public void afterSetText(@NonNull TextView textView) { SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java index 5b6aae99..3f63ec80 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java @@ -48,8 +48,8 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.message.FetchMessage; import ml.docilealligator.infinityforreddit.message.Message; import ml.docilealligator.infinityforreddit.message.ReadMessage; -import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; +import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; public class MessageRecyclerViewAdapter extends PagedListAdapter { @@ -111,25 +111,12 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { - /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { - StringBuilder markdownStringBuilder = new StringBuilder(markdown); - Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - ArrayList matched = new ArrayList<>(); - while (matcher.find()) { - matched.add(matcher.start()); - } - for (int i = matched.size() - 1; i >= 0; i--) { - markdownStringBuilder.replace(matched.get(i), matched.get(i) + 1, ">"); - } - return super.processMarkdown(markdownStringBuilder.toString()); + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); } - */ @Override public void afterSetText(@NonNull TextView textView) { 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 8663da52..85411123 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -112,7 +112,6 @@ import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.post.PostPagingSource; import ml.docilealligator.infinityforreddit.utils.APIUtils; -import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -238,25 +237,13 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { - /* @NonNull @Override public String processMarkdown(@NonNull String markdown) { - StringBuilder markdownStringBuilder = new StringBuilder(markdown); - Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - ArrayList matched = new ArrayList<>(); - while (matcher.find()) { - matched.add(matcher.start()); - } - for (int i = matched.size() - 1; i >= 0; i--) { - markdownStringBuilder.replace(matched.get(i), matched.get(i) + 1, ">"); - } - return super.processMarkdown(markdownStringBuilder.toString()); + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); } - */ + @Override public void afterSetText(@NonNull TextView textView) { textView.setHighlightColor(Color.TRANSPARENT); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java index 99adc221..93f487bf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java @@ -39,7 +39,6 @@ import ml.docilealligator.infinityforreddit.activities.ViewPrivateMessagesActivi import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.message.Message; -import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -78,8 +77,13 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt .usePlugin(HtmlPlugin.create(plugin -> { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + @NonNull + @Override + public String processMarkdown(@NonNull String markdown) { + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + } + @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { builder.linkResolver((view, link) -> { 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 4eb9d5d8..789c0865 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -34,8 +34,8 @@ import ml.docilealligator.infinityforreddit.Rule; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; +import ml.docilealligator.infinityforreddit.utils.Utils; public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { private Markwon markwon; @@ -52,8 +52,13 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + @NonNull + @Override + public String processMarkdown(@NonNull String markdown) { + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + } + @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { builder.linkResolver((view, link) -> { 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 416b3046..6fb68f53 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -57,8 +57,8 @@ import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFi import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData; import ml.docilealligator.infinityforreddit.subreddit.SubredditData; import ml.docilealligator.infinityforreddit.subreddit.SubredditViewModel; -import ml.docilealligator.infinityforreddit.utils.ProcessRedditSuperscript; import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; +import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; public class SidebarFragment extends Fragment { @@ -116,8 +116,13 @@ public class SidebarFragment extends Fragment { .usePlugin(HtmlPlugin.create(plugin -> { plugin.excludeDefaults(true).addHandler(new SuperScriptHandler()); })) - .usePlugin(new ProcessRedditSuperscript()) .usePlugin(new AbstractMarkwonPlugin() { + @NonNull + @Override + public String processMarkdown(@NonNull String markdown) { + return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + } + @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { textView.setTextColor(markdownColor); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/ProcessRedditSuperscript.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/ProcessRedditSuperscript.java deleted file mode 100644 index 0dc539d7..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/ProcessRedditSuperscript.java +++ /dev/null @@ -1,46 +0,0 @@ -package ml.docilealligator.infinityforreddit.utils; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import io.noties.markwon.AbstractMarkwonPlugin; - -public class ProcessRedditSuperscript extends AbstractMarkwonPlugin { - private static final Pattern re = Pattern.compile("(?:\\^\\((.+?)\\))|(?:\\^(\\S+))"); - - @Override - public String processMarkdown(String markdown) { - StringBuilder builder = new StringBuilder(); - Matcher matcher = re.matcher(markdown); - int start = 0; - - while (matcher.find()) { - try { - String match; - if ((match = matcher.group(1)) != null || (match = matcher.group(2)) != null) { - builder.append(markdown.substring(start, matcher.start())) - .append("") - .append(match) - .append(""); - start = matcher.end(); - } else { - throw new NullPointerException(); - } - } catch(NullPointerException e) { - e.printStackTrace(); - } finally { - continue; - } - } - - if (start < markdown.length()) { - builder.append(markdown.substring(start)); - } - - if(builder.length() > 0) { - return builder.toString(); } - else { - return markdown; - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java index 16aeb642..b76b63be 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -61,12 +61,11 @@ public class Utils { private static final long YEAR_MILLIS = 12 * MONTH_MILLIS; public static String modifyMarkdown(String markdown) { - StringBuilder regexed = new StringBuilder(markdown + StringBuilder regexed = new StringBuilder(trimAndEscapeSpaceInLinks(markdown) .replaceAll("((?<=[\\s])|^)/[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com$0)") .replaceAll("((?<=[\\s])|^)[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com/$0)") .replaceAll("\\^{2,}", "^") - .replaceAll("(", "$1>") - .replaceAll(">!", ">!") + .replaceAll(">!", ">!") // If it's in a code black, html entity remains escaped .replaceAll("(^|^ *|\\n *)#(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)##(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)###(?!($|\\s|#))", "$0 ") @@ -78,7 +77,53 @@ public class Utils { return regexed.toString(); } - private static String fixSuperScript(StringBuilder regexed) { + // Also matches links inside code blocks as a side effect + private static String trimAndEscapeSpaceInLinks(String markdown){ + String TEXT = "\\[([^\\[]\\n?[\\S\\h]+?\\n?[\\S\\h]*?)]"; + String LINK = "(\\n?[\\h]*?\\n?https?:\\/\\/[\\S\\h]+?\n?)"; + String TITLE = "(?:\\s\"(\\n?[\\S\\h]+?\\n?[\\S\\h]*?)?\")?"; + Pattern pattern = Pattern.compile(TEXT + "\\(" + LINK + TITLE + "\\n?\\h*?\\)"); + Matcher matcher = pattern.matcher(markdown); + StringBuilder builder = new StringBuilder(); + int start = 0; + while (matcher.find()) try { + String match1; + String match2; + String match3; + if ((match1 = matcher.group(1)) != null && (match2 = matcher.group(2)) != null) { + match1 = match1.trim().replaceAll("\\s+", " "); + match2 = match2.trim().replaceAll(" ", "%20"); + match3 = matcher.group(3); + builder.append(markdown.substring(start, matcher.start())) + .append("[") + .append(match1) + .append("]") + .append("(") + .append(match2); + if (match3 != null) { + builder.append(" \"") + .append(match3) + .append("\""); + } + builder.append(")"); + start = matcher.end(); + } + } catch (NullPointerException e) { + e.printStackTrace(); + } + + if (start < markdown.length()) { + builder.append(markdown.substring(start)); + } + + if(builder.length() > 0) { + return builder.toString(); } + else { + return markdown; + } + } + + public static String fixSuperScript(StringBuilder regexed) { boolean hasBracket = false; int nCarets = 0; for (int i = 0; i < regexed.length(); i++) { -- cgit v1.2.3 From e3976248cc948df3633f4254d29645389ae9221d Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Sat, 13 Nov 2021 15:58:55 +0300 Subject: Disable BangInlineProcessor Don't process ! bangs before links since reddit markdown does not support it. Now links inside spoilers can be rendered correctly. --- .../activities/CommentActivity.java | 3 ++ .../activities/FullMarkdownActivity.java | 2 + .../activities/ViewSubredditDetailActivity.java | 11 +++-- .../activities/ViewUserDetailActivity.java | 11 +++-- .../infinityforreddit/activities/WikiActivity.java | 2 + .../CommentsListingRecyclerViewAdapter.java | 47 +++++++++--------- .../adapters/CommentsRecyclerViewAdapter.java | 57 ++++++++++++---------- .../adapters/MessageRecyclerViewAdapter.java | 2 + .../adapters/PostDetailRecyclerViewAdapter.java | 50 ++++++++++--------- .../PrivateMessagesDetailRecyclerViewAdapter.java | 2 + .../adapters/RulesRecyclerViewAdapter.java | 2 + .../fragments/SidebarFragment.java | 2 + .../infinityforreddit/utils/Utils.java | 2 +- 13 files changed, 111 insertions(+), 82 deletions(-) (limited to 'app/src/main/java') 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 b6e5717a..d095428f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -52,6 +52,7 @@ import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; import io.noties.markwon.html.HtmlPlugin; import io.noties.markwon.html.tag.SuperScriptHandler; +import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -166,6 +167,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA Markwon markwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { @@ -219,6 +221,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA Markwon postBodyMarkwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { 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 5ef80ffc..12545d44 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -48,6 +48,7 @@ import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; import io.noties.markwon.html.HtmlPlugin; import io.noties.markwon.html.tag.SuperScriptHandler; +import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -137,6 +138,7 @@ public class FullMarkdownActivity extends BaseActivity { Markwon markwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index 368e2b46..dcca88b5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.ColorStateList; +import android.graphics.PorterDuff; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -71,6 +72,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.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -384,6 +386,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp Markwon markwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); })) .usePlugin(new AbstractMarkwonPlugin() { @Override @@ -546,10 +549,10 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp descriptionTextView.setTextColor(primaryTextColor); bottomNavigationView.setBackgroundTint(ColorStateList.valueOf(mCustomThemeWrapper.getBottomAppBarBackgroundColor())); int bottomAppBarIconColor = mCustomThemeWrapper.getBottomAppBarIconColor(); - option2BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - option1BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - option3BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - option4BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + option2BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); + option1BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); + option3BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); + option4BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); applyTabLayoutTheme(tabLayout); applyFABTheme(fab); unsubscribedColor = mCustomThemeWrapper.getUnsubscribed(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index 7ef81969..16ec23b9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.content.res.Resources; +import android.graphics.PorterDuff; import android.net.Uri; import android.os.AsyncTask; import android.os.Build; @@ -73,6 +74,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.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -380,6 +382,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele Markwon markwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); })) .usePlugin(new AbstractMarkwonPlugin() { @Override @@ -640,10 +643,10 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele cakedayTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); bottomNavigationView.setBackgroundTint(ColorStateList.valueOf(mCustomThemeWrapper.getBottomAppBarBackgroundColor())); int bottomAppBarIconColor = mCustomThemeWrapper.getBottomAppBarIconColor(); - option2BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - option1BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - option3BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); - option4BottomAppBar.setColorFilter(bottomAppBarIconColor, android.graphics.PorterDuff.Mode.SRC_IN); + option2BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); + option1BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); + option3BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); + option4BottomAppBar.setColorFilter(bottomAppBarIconColor, PorterDuff.Mode.SRC_IN); applyFABTheme(fab); descriptionTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); subscribeUserChip.setTextColor(mCustomThemeWrapper.getChipTextColor()); 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 657eafe7..ca206b8b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -52,6 +52,7 @@ import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; import io.noties.markwon.html.HtmlPlugin; import io.noties.markwon.html.tag.SuperScriptHandler; +import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -162,6 +163,7 @@ public class WikiActivity extends BaseActivity { markwon = Markwon.builder(this) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { 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 176953ea..91827d06 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.graphics.Color; +import android.graphics.PorterDuff; import android.net.Uri; import android.os.Bundle; import android.text.SpannableStringBuilder; @@ -43,6 +44,7 @@ import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; import io.noties.markwon.html.HtmlPlugin; import io.noties.markwon.html.tag.SuperScriptHandler; +import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -121,6 +123,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { @@ -281,12 +284,12 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { @@ -565,20 +568,20 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { @@ -486,13 +489,13 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter authorTextView.performClick()); @@ -1254,20 +1257,20 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { 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 85411123..dec86c7b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -75,6 +75,7 @@ import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; import io.noties.markwon.html.HtmlPlugin; import io.noties.markwon.html.tag.SuperScriptHandler; +import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -232,6 +233,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { @@ -594,16 +596,16 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { if (mPost != null) { @@ -2348,7 +2350,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java index 93f487bf..6480e886 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java @@ -29,6 +29,7 @@ import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; import io.noties.markwon.html.HtmlPlugin; import io.noties.markwon.html.tag.SuperScriptHandler; +import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -72,6 +73,7 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt mMarkwon = Markwon.builder(viewPrivateMessagesActivity) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { 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 789c0865..4a603c94 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -24,6 +24,7 @@ import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; import io.noties.markwon.html.HtmlPlugin; import io.noties.markwon.html.tag.SuperScriptHandler; +import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -47,6 +48,7 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { 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 6fb68f53..ff31ccae 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -36,6 +36,7 @@ import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; import io.noties.markwon.html.HtmlPlugin; import io.noties.markwon.html.tag.SuperScriptHandler; +import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; import io.noties.markwon.linkify.LinkifyPlugin; @@ -111,6 +112,7 @@ public class SidebarFragment extends Fragment { Markwon markwon = Markwon.builder(activity) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); plugin.addInlineProcessor(new SuperscriptInlineProcessor()); })) .usePlugin(HtmlPlugin.create(plugin -> { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java index b76b63be..edc49f95 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -65,7 +65,7 @@ public class Utils { .replaceAll("((?<=[\\s])|^)/[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com$0)") .replaceAll("((?<=[\\s])|^)[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com/$0)") .replaceAll("\\^{2,}", "^") - .replaceAll(">!", ">!") // If it's in a code black, html entity remains escaped + .replaceAll(">!", ">!") // If it's in a code block, html entity remains escaped .replaceAll("(^|^ *|\\n *)#(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)##(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)###(?!($|\\s|#))", "$0 ") -- cgit v1.2.3 From d0f0647bc8deeff87f297b4d60f6ed58a17a0d31 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 13 Nov 2021 22:11:56 +0800 Subject: Version 5.1.0-beta3. --- .../infinityforreddit/utils/EditProfileUtils.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/EditProfileUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/EditProfileUtils.java index 5293bc71..f66fe648 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/EditProfileUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/EditProfileUtils.java @@ -1,28 +1,30 @@ package ml.docilealligator.infinityforreddit.utils; import android.graphics.Bitmap; + import androidx.annotation.NonNull; + import com.google.gson.Gson; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.ByteArrayOutputStream; +import java.util.HashMap; +import java.util.Map; + import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.subreddit.SubredditSettingData; import okhttp3.MediaType; import okhttp3.MultipartBody; import okhttp3.RequestBody; -import org.json.JSONException; -import org.json.JSONObject; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; -import java.io.ByteArrayOutputStream; -import java.util.HashMap; -import java.util.Map; - public final class EditProfileUtils { - - public static void updateProfile(Retrofit oauthRetrofit, String accessToken, String accountName, -- cgit v1.2.3 From 839325efbedb108917b37353c9493fea305d71e2 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Sun, 14 Nov 2021 14:52:07 +0300 Subject: Don't handle unescaped bracket links for now Until there is a better solution that can also handle `[Title]: https://link.com` type links and others. --- .../infinityforreddit/utils/Utils.java | 48 +--------------------- 1 file changed, 1 insertion(+), 47 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java index edc49f95..0b49ba31 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -61,7 +61,7 @@ public class Utils { private static final long YEAR_MILLIS = 12 * MONTH_MILLIS; public static String modifyMarkdown(String markdown) { - StringBuilder regexed = new StringBuilder(trimAndEscapeSpaceInLinks(markdown) + StringBuilder regexed = new StringBuilder(markdown .replaceAll("((?<=[\\s])|^)/[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com$0)") .replaceAll("((?<=[\\s])|^)[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com/$0)") .replaceAll("\\^{2,}", "^") @@ -77,52 +77,6 @@ public class Utils { return regexed.toString(); } - // Also matches links inside code blocks as a side effect - private static String trimAndEscapeSpaceInLinks(String markdown){ - String TEXT = "\\[([^\\[]\\n?[\\S\\h]+?\\n?[\\S\\h]*?)]"; - String LINK = "(\\n?[\\h]*?\\n?https?:\\/\\/[\\S\\h]+?\n?)"; - String TITLE = "(?:\\s\"(\\n?[\\S\\h]+?\\n?[\\S\\h]*?)?\")?"; - Pattern pattern = Pattern.compile(TEXT + "\\(" + LINK + TITLE + "\\n?\\h*?\\)"); - Matcher matcher = pattern.matcher(markdown); - StringBuilder builder = new StringBuilder(); - int start = 0; - while (matcher.find()) try { - String match1; - String match2; - String match3; - if ((match1 = matcher.group(1)) != null && (match2 = matcher.group(2)) != null) { - match1 = match1.trim().replaceAll("\\s+", " "); - match2 = match2.trim().replaceAll(" ", "%20"); - match3 = matcher.group(3); - builder.append(markdown.substring(start, matcher.start())) - .append("[") - .append(match1) - .append("]") - .append("(") - .append(match2); - if (match3 != null) { - builder.append(" \"") - .append(match3) - .append("\""); - } - builder.append(")"); - start = matcher.end(); - } - } catch (NullPointerException e) { - e.printStackTrace(); - } - - if (start < markdown.length()) { - builder.append(markdown.substring(start)); - } - - if(builder.length() > 0) { - return builder.toString(); } - else { - return markdown; - } - } - public static String fixSuperScript(StringBuilder regexed) { boolean hasBracket = false; int nCarets = 0; -- cgit v1.2.3 From ef1bdf2fa5fa4505e609b0862d9c7ed01659da38 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Sun, 14 Nov 2021 16:34:50 +0300 Subject: Optimize spoiler regex Optimize spoiler regex to allow at least one new line. >! match this!< >!match this!< >! match this!< >!don't match this! match this !< >!match this !< --- app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java index 0b49ba31..525dfa2a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -65,7 +65,7 @@ public class Utils { .replaceAll("((?<=[\\s])|^)/[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com$0)") .replaceAll("((?<=[\\s])|^)[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com/$0)") .replaceAll("\\^{2,}", "^") - .replaceAll(">!", ">!") // If it's in a code block, html entity remains escaped + .replaceAll("(?:>!)(\\n?[\\S\\h]+?\\n?[\\S\\h]+\\n?!<)", ">!$1") // html entity remains escaped inside an inline block .replaceAll("(^|^ *|\\n *)#(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)##(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)###(?!($|\\s|#))", "$0 ") -- cgit v1.2.3 From a52342b336ab71dece4d923e1be17d95fc6b0e30 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Sun, 14 Nov 2021 17:21:59 +0300 Subject: Refactor --- .../infinityforreddit/activities/CommentActivity.java | 4 ++-- .../infinityforreddit/activities/FullMarkdownActivity.java | 2 +- .../docilealligator/infinityforreddit/activities/WikiActivity.java | 2 +- .../adapters/CommentsListingRecyclerViewAdapter.java | 2 +- .../infinityforreddit/adapters/CommentsRecyclerViewAdapter.java | 2 +- .../infinityforreddit/adapters/MessageRecyclerViewAdapter.java | 2 +- .../infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java | 2 +- .../adapters/PrivateMessagesDetailRecyclerViewAdapter.java | 2 +- .../infinityforreddit/adapters/RulesRecyclerViewAdapter.java | 2 +- .../docilealligator/infinityforreddit/fragments/SidebarFragment.java | 2 +- .../main/java/ml/docilealligator/infinityforreddit/utils/Utils.java | 5 ++--- 11 files changed, 13 insertions(+), 14 deletions(-) (limited to 'app/src/main/java') 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 d095428f..0d84fd8b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -177,7 +177,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA @NonNull @Override public String processMarkdown(@NonNull String markdown) { - return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + return super.processMarkdown(markdown); } @Override @@ -231,7 +231,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA @NonNull @Override public String processMarkdown(@NonNull String markdown) { - return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + return super.processMarkdown(markdown); } @Override 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 12545d44..5de7106f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -148,7 +148,7 @@ public class FullMarkdownActivity extends BaseActivity { @NonNull @Override public String processMarkdown(@NonNull String markdown) { - return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + return super.processMarkdown(markdown); } @Override 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 ca206b8b..9cd26d46 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -173,7 +173,7 @@ public class WikiActivity extends BaseActivity { @NonNull @Override public String processMarkdown(@NonNull String markdown) { - return super.processMarkdown(Utils.fixSuperScript(new StringBuilder(markdown))); + return super.processMarkdown(markdown); } @Override 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 91827d06..5c85c4b2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -133,7 +133,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter Date: Sun, 14 Nov 2021 21:48:11 +0300 Subject: Revert changes made in refactor We need the original superscript markdown for when we edit posts! --- .../infinityforreddit/activities/CommentActivity.java | 4 ++-- .../infinityforreddit/activities/FullMarkdownActivity.java | 2 +- .../docilealligator/infinityforreddit/activities/WikiActivity.java | 2 +- .../adapters/CommentsListingRecyclerViewAdapter.java | 2 +- .../infinityforreddit/adapters/CommentsRecyclerViewAdapter.java | 2 +- .../infinityforreddit/adapters/MessageRecyclerViewAdapter.java | 2 +- .../infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java | 2 +- .../adapters/PrivateMessagesDetailRecyclerViewAdapter.java | 2 +- .../infinityforreddit/adapters/RulesRecyclerViewAdapter.java | 2 +- .../infinityforreddit/fragments/SidebarFragment.java | 2 +- .../java/ml/docilealligator/infinityforreddit/utils/Utils.java | 7 +++++-- 11 files changed, 16 insertions(+), 13 deletions(-) (limited to 'app/src/main/java') 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 0d84fd8b..ffb9173b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -177,7 +177,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA @NonNull @Override public String processMarkdown(@NonNull String markdown) { - return super.processMarkdown(markdown); + return super.processMarkdown(Utils.fixSuperScript(markdown)); } @Override @@ -231,7 +231,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA @NonNull @Override public String processMarkdown(@NonNull String markdown) { - return super.processMarkdown(markdown); + return super.processMarkdown(Utils.fixSuperScript(markdown)); } @Override 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 5de7106f..32a5f452 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -148,7 +148,7 @@ public class FullMarkdownActivity extends BaseActivity { @NonNull @Override public String processMarkdown(@NonNull String markdown) { - return super.processMarkdown(markdown); + return super.processMarkdown(Utils.fixSuperScript(markdown)); } @Override 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 9cd26d46..1a353a7f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -173,7 +173,7 @@ public class WikiActivity extends BaseActivity { @NonNull @Override public String processMarkdown(@NonNull String markdown) { - return super.processMarkdown(markdown); + return super.processMarkdown(Utils.fixSuperScript(markdown)); } @Override 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 5c85c4b2..616b9c1b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -133,7 +133,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter Date: Mon, 15 Nov 2021 08:42:07 +0000 Subject: Don't leave out single character oops >! match this!< >!match this!< >! match this!< >!don't match this! match this !< >!match this !< >! match this!< >! O!< >! O !< >! X !< >! DON'TMATCH !< >!O!< >! O O!< >!!< --- app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java index 8e5e73c1..15bcefa0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -65,7 +65,7 @@ public class Utils { .replaceAll("((?<=[\\s])|^)/[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com$0)") .replaceAll("((?<=[\\s])|^)[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com/$0)") .replaceAll("\\^{2,}", "^") - .replaceAll("(?:>!)(\\n?[\\S\\h]+?\\n?[\\S\\h]+\\n?!<)", ">!$1") // html entity remains escaped inside an inline block + .replaceAll(">!(\\n?(?:[\\S\\h]+?(?:\\n?[\\S\\h]+?)?)\\n?)!<", ">!$1!<") // html entity remains escaped inside an inline block .replaceAll("(^|^ *|\\n *)#(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)##(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)###(?!($|\\s|#))", "$0 ") -- cgit v1.2.3 From f94bd5039c2c809ac465af54496b8dafca8caada Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 15 Nov 2021 19:06:05 +0800 Subject: Don't start MaterialYouService if Material You is not enabled. --- .../java/ml/docilealligator/infinityforreddit/Infinity.java | 5 ++++- .../broadcastreceivers/WallpaperChangeReceiver.java | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java index e0eb462d..2b990071 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java @@ -43,6 +43,9 @@ public class Infinity extends Application implements LifecycleObserver { private boolean canStartLockScreenActivity = false; private boolean isSecureMode; @Inject + @Named("default") + SharedPreferences mSharedPreferences; + @Inject @Named("security") SharedPreferences mSecuritySharedPreferences; @@ -127,7 +130,7 @@ public class Infinity extends Application implements LifecycleObserver { new NetworkWifiStatusReceiver(() -> EventBus.getDefault().post(new ChangeNetworkStatusEvent(Utils.getConnectedNetwork(getApplicationContext())))); registerReceiver(mNetworkWifiStatusReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); - registerReceiver(new WallpaperChangeReceiver(), new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED)); + registerReceiver(new WallpaperChangeReceiver(mSharedPreferences), new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED)); } @OnLifecycleEvent(Lifecycle.Event.ON_START) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/broadcastreceivers/WallpaperChangeReceiver.java b/app/src/main/java/ml/docilealligator/infinityforreddit/broadcastreceivers/WallpaperChangeReceiver.java index 5a596308..e65b97f8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/broadcastreceivers/WallpaperChangeReceiver.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/broadcastreceivers/WallpaperChangeReceiver.java @@ -3,16 +3,25 @@ package ml.docilealligator.infinityforreddit.broadcastreceivers; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import androidx.core.content.ContextCompat; import ml.docilealligator.infinityforreddit.services.MaterialYouService; +import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; public class WallpaperChangeReceiver extends BroadcastReceiver { + private SharedPreferences sharedPreferences; + + public WallpaperChangeReceiver(SharedPreferences sharedPreferences) { + this.sharedPreferences = sharedPreferences; + } @Override public void onReceive(Context context, Intent intent) { - Intent materialYouIntent = new Intent(context, MaterialYouService.class); - ContextCompat.startForegroundService(context, materialYouIntent); + if (sharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_MATERIAL_YOU, false)) { + Intent materialYouIntent = new Intent(context, MaterialYouService.class); + ContextCompat.startForegroundService(context, materialYouIntent); + } } } -- cgit v1.2.3 From d5770599f56f8ba1b7119de3b193d1daca7bb766 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Tue, 16 Nov 2021 22:53:56 +0300 Subject: Refactor spoiler parsing into its own class Reuse spoiler pattern otherwise we match markdown like: `>!` lots of new lines and text "); + mCommentContent = getIntent().getStringExtra(EXTRA_CONTENT).replaceAll(">!",">!"); contentEditText.setText(mCommentContent); if (savedInstanceState != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java index 16e91ebc..2de2a47b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java @@ -141,7 +141,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled mFullName = getIntent().getStringExtra(EXTRA_FULLNAME); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); titleTextView.setText(getIntent().getStringExtra(EXTRA_TITLE)); - mPostContent = getIntent().getStringExtra(EXTRA_CONTENT).replaceAll(">",">");; + mPostContent = getIntent().getStringExtra(EXTRA_CONTENT).replaceAll(">!",">!");; contentEditText.setText(mPostContent); if (savedInstanceState != null) { 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 32a5f452..acd1713c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -61,8 +61,10 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; +import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; +import ml.docilealligator.infinityforreddit.markdown.SpoilerSpan; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; +import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; public class FullMarkdownActivity extends BaseActivity { @@ -150,51 +152,6 @@ public class FullMarkdownActivity extends BaseActivity { public String processMarkdown(@NonNull String markdown) { return super.processMarkdown(Utils.fixSuperScript(markdown)); } - - @Override - public void afterSetText(@NonNull TextView textView) { - textView.setHighlightColor(Color.TRANSPARENT); - SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText()); - Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - int start = 0; - boolean find = false; - while (matcher.find(start)) { - if (markdownStringBuilder.length() < 4 - || matcher.start() < 0 - || matcher.end() > markdownStringBuilder.length()) { - break; - } - find = true; - markdownStringBuilder.delete(matcher.end() - 2, matcher.end()); - markdownStringBuilder.delete(matcher.start(), matcher.start() + 2); - ClickableSpan clickableSpan = new ClickableSpan() { - private boolean isShowing = false; - @Override - public void updateDrawState(@NonNull TextPaint ds) { - if (isShowing) { - super.updateDrawState(ds); - ds.setColor(markdownColor); - } else { - ds.bgColor = spoilerBackgroundColor; - ds.setColor(markdownColor); - } - ds.setUnderlineText(false); - } - - @Override - public void onClick(@NonNull View view) { - isShowing = !isShowing; - view.invalidate(); - } - }; - markdownStringBuilder.setSpan(clickableSpan, matcher.start(), matcher.end() - 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - start = matcher.end() - 4; - } - if (find) { - textView.setText(markdownStringBuilder); - } - } @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { @@ -217,6 +174,7 @@ public class FullMarkdownActivity extends BaseActivity { builder.linkColor(linkColor); } }) + .usePlugin(SpoilerParserPlugin.create(markdownColor, spoilerBackgroundColor)) .usePlugin(StrikethroughPlugin.create()) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) .usePlugin(TableEntryPlugin.create(this)) 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 1a353a7f..b44f5d4f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -66,9 +66,11 @@ import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; +import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; +import ml.docilealligator.infinityforreddit.markdown.SpoilerSpan; import ml.docilealligator.infinityforreddit.utils.JSONUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; +import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Call; import retrofit2.Callback; @@ -176,51 +178,6 @@ public class WikiActivity extends BaseActivity { return super.processMarkdown(Utils.fixSuperScript(markdown)); } - @Override - public void afterSetText(@NonNull TextView textView) { - textView.setHighlightColor(Color.TRANSPARENT); - SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText()); - Pattern spoilerPattern = Pattern.compile(">![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - int start = 0; - boolean find = false; - while (matcher.find(start)) { - if (markdownStringBuilder.length() < 4 - || matcher.start() < 0 - || matcher.end() > markdownStringBuilder.length()) { - break; - } - find = true; - markdownStringBuilder.delete(matcher.end() - 2, matcher.end()); - markdownStringBuilder.delete(matcher.start(), matcher.start() + 2); - ClickableSpan clickableSpan = new ClickableSpan() { - private boolean isShowing = false; - @Override - public void updateDrawState(@NonNull TextPaint ds) { - if (isShowing) { - super.updateDrawState(ds); - ds.setColor(markdownColor); - } else { - ds.bgColor = spoilerBackgroundColor; - ds.setColor(markdownColor); - } - ds.setUnderlineText(false); - } - - @Override - public void onClick(@NonNull View view) { - isShowing = !isShowing; - view.invalidate(); - } - }; - markdownStringBuilder.setSpan(clickableSpan, matcher.start(), matcher.end() - 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - start = matcher.end() - 4; - } - if (find) { - textView.setText(markdownStringBuilder); - } - } - @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { textView.setTextColor(markdownColor); @@ -241,6 +198,7 @@ public class WikiActivity extends BaseActivity { builder.linkColor(linkColor); } }) + .usePlugin(SpoilerParserPlugin.create(markdownColor, spoilerBackgroundColor)) .usePlugin(StrikethroughPlugin.create()) .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) .usePlugin(TableEntryPlugin.create(this)) 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 616b9c1b..40bce0d6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -63,9 +63,11 @@ import ml.docilealligator.infinityforreddit.comment.Comment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.CommentIndentationView; import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView; +import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; +import ml.docilealligator.infinityforreddit.markdown.SpoilerSpan; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; +import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; @@ -136,56 +138,6 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - int start = 0; - boolean find = false; - while (matcher.find(start)) { - if (markdownStringBuilder.length() < 4 - || matcher.start() < 0 - || matcher.end() > markdownStringBuilder.length()) { - break; - } - find = true; - markdownStringBuilder.delete(matcher.end() - 2, matcher.end()); - markdownStringBuilder.delete(matcher.start(), matcher.start() + 2); - int matcherStart = matcher.start(); - int matcherEnd = matcher.end(); - ClickableSpan clickableSpan = new ClickableSpan() { - private boolean isShowing = false; - @Override - public void updateDrawState(@NonNull TextPaint ds) { - if (isShowing) { - super.updateDrawState(ds); - ds.setColor(mCommentColor); - } else { - ds.bgColor = commentSpoilerBackgroundColor; - ds.setColor(mCommentColor); - } - ds.setUnderlineText(false); - } - - @Override - public void onClick(@NonNull View view) { - if (textView instanceof SpoilerOnClickTextView) { - ((SpoilerOnClickTextView) textView).setSpoilerOnClick(true); - } - isShowing = !isShowing; - view.invalidate(); - } - }; - markdownStringBuilder.setSpan(clickableSpan, matcherStart, matcherEnd - 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - start = matcherEnd - 4; - } - if (find) { - textView.setText(markdownStringBuilder); - } - } - @Override public void configureTheme(@NonNull MarkwonTheme.Builder builder) { builder.linkColor(customThemeWrapper.getLinkColor()); @@ -202,6 +154,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - int start = 0; - boolean find = false; - while (matcher.find(start)) { - if (markdownStringBuilder.length() < 4 - || matcher.start() < 0 - || matcher.end() > markdownStringBuilder.length()) { - break; - } - find = true; - markdownStringBuilder.delete(matcher.end() - 2, matcher.end()); - markdownStringBuilder.delete(matcher.start(), matcher.start() + 2); - ClickableSpan clickableSpan = new ClickableSpan() { - private boolean isShowing = false; - @Override - public void updateDrawState(@NonNull TextPaint ds) { - if (isShowing) { - super.updateDrawState(ds); - } else { - ds.bgColor = commentSpoilerBackgroundColor; - } - ds.setColor(mCommentTextColor); - ds.setUnderlineText(false); - } - - @Override - public void onClick(@NonNull View view) { - if (textView instanceof SpoilerOnClickTextView) { - ((SpoilerOnClickTextView) textView).setSpoilerOnClick(true); - } - isShowing = !isShowing; - view.invalidate(); - } - }; - markdownStringBuilder.setSpan(clickableSpan, matcher.start(), matcher.end() - 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - start = matcher.end() - 4; - } - if (find) { - textView.setText(markdownStringBuilder); - } - } - @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { builder.linkResolver((view, link) -> { @@ -243,6 +197,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter { if (!activity.isDestroyed() && !activity.isFinishing()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java index 095a36f7..7560aab4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MessageRecyclerViewAdapter.java @@ -46,10 +46,12 @@ import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.activities.ViewPrivateMessagesActivity; import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; +import ml.docilealligator.infinityforreddit.markdown.SpoilerSpan; import ml.docilealligator.infinityforreddit.message.FetchMessage; import ml.docilealligator.infinityforreddit.message.Message; import ml.docilealligator.infinityforreddit.message.ReadMessage; -import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; +import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; @@ -120,53 +122,6 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - int start = 0; - boolean find = false; - while (matcher.find(start)) { - if (markdownStringBuilder.length() < 4 - || matcher.start() < 0 - || matcher.end() > markdownStringBuilder.length()) { - break; - } - find = true; - markdownStringBuilder.delete(matcher.end() - 2, matcher.end()); - markdownStringBuilder.delete(matcher.start(), matcher.start() + 2); - int matcherStart = matcher.start(); - int matcherEnd = matcher.end(); - ClickableSpan clickableSpan = new ClickableSpan() { - private boolean isShowing = false; - @Override - public void updateDrawState(@NonNull TextPaint ds) { - if (isShowing) { - super.updateDrawState(ds); - ds.setColor(mSecondaryTextColor); - } else { - ds.bgColor = spoilerBackgroundColor; - ds.setColor(mSecondaryTextColor); - } - ds.setUnderlineText(false); - } - - @Override - public void onClick(@NonNull View view) { - isShowing = !isShowing; - view.invalidate(); - } - }; - markdownStringBuilder.setSpan(clickableSpan, matcherStart, matcherEnd - 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - start = matcherEnd - 4; - } - if (find) { - textView.setText(markdownStringBuilder); - } - } - @Override public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { builder.linkResolver((view, link) -> { @@ -182,6 +137,7 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter![\\S\\s]+?!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - int start = 0; - boolean find = false; - while (matcher.find(start)) { - if (markdownStringBuilder.length() < 4 - || matcher.start() < 0 - || matcher.end() > markdownStringBuilder.length()) { - break; - } - find = true; - markdownStringBuilder.delete(matcher.end() - 2, matcher.end()); - markdownStringBuilder.delete(matcher.start(), matcher.start() + 2); - ClickableSpan clickableSpan = new ClickableSpan() { - private boolean isShowing = false; - @Override - public void updateDrawState(@NonNull TextPaint ds) { - if (isShowing) { - super.updateDrawState(ds); - ds.setColor(markdownColor); - } else { - ds.bgColor = postSpoilerBackgroundColor; - ds.setColor(markdownColor); - } - ds.setUnderlineText(false); - } - - @Override - public void onClick(@NonNull View view) { - isShowing = !isShowing; - view.invalidate(); - } - }; - markdownStringBuilder.setSpan(clickableSpan, matcher.start(), matcher.end() - 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - start = matcher.end() - 4; - } - if (find) { - textView.setText(markdownStringBuilder); - } - } - @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { textView.setTextColor(markdownColor); @@ -323,6 +280,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { if (activity != null && !activity.isDestroyed() && !activity.isFinishing()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java index e357771b..180b74be 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PrivateMessagesDetailRecyclerViewAdapter.java @@ -41,7 +41,7 @@ import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.message.Message; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; +import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapter { 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 294733a1..d82fcf8d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -35,7 +35,7 @@ import ml.docilealligator.infinityforreddit.Rule; import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; +import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; public class RulesRecyclerViewAdapter extends RecyclerView.Adapter { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java index 4264f36a..1e458fc7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java @@ -74,7 +74,7 @@ public class CopyTextBottomSheetFragment extends LandscapeExpandedRoundedBottomS if (markdownText != null) { //markdownText = markdownText.replaceAll("", "^").replaceAll("", ""); - markdownText = markdownText.replaceAll(">", ">"); + markdownText = markdownText.replaceAll(">!", ">!"); copyMarkdownTextView.setOnClickListener(view -> { showCopyDialog(markdownText); dismiss(); 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 3f22a64e..bea0c4ed 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -58,7 +58,7 @@ import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFi import ml.docilealligator.infinityforreddit.subreddit.FetchSubredditData; import ml.docilealligator.infinityforreddit.subreddit.SubredditData; import ml.docilealligator.infinityforreddit.subreddit.SubredditViewModel; -import ml.docilealligator.infinityforreddit.utils.SuperscriptInlineProcessor; +import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java new file mode 100644 index 00000000..47c484c9 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java @@ -0,0 +1,65 @@ +package ml.docilealligator.infinityforreddit.markdown; + +import android.graphics.Color; +import android.text.SpannableStringBuilder; +import android.text.Spanned; +import android.widget.TextView; + +import androidx.annotation.NonNull; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import io.noties.markwon.AbstractMarkwonPlugin; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; + +public class SpoilerParserPlugin extends AbstractMarkwonPlugin { + private final int textColor; + private final int backgroundColor; + + SpoilerParserPlugin(int textColor, int backgroundColor) { + this.textColor = textColor; + this.backgroundColor = backgroundColor; + } + + public static SpoilerParserPlugin create(@NonNull int textColor, @NonNull int backgroundColor) { + return new SpoilerParserPlugin(textColor, backgroundColor); + } + + @Override + public void afterSetText(@NonNull TextView textView) { + textView.setHighlightColor(Color.TRANSPARENT); + SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText()); + Pattern spoilerPattern = Pattern.compile(">!(\\n?(?:.+?(?:\\n?.+?)?)\\n?)!<"); + Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); + int start = 0; + boolean find = false; + while (matcher.find(start)) { + if (markdownStringBuilder.length() < 4 + || matcher.start() < 0 + || matcher.end() > markdownStringBuilder.length()) { + break; + } + find = true; + markdownStringBuilder.delete(matcher.end() - 2, matcher.end()); + markdownStringBuilder.delete(matcher.start(), matcher.start() + 2); + SpoilerSpan spoilerSpan = new SpoilerSpan(textColor, backgroundColor); + markdownStringBuilder.setSpan(spoilerSpan, matcher.start(), matcher.end() - 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + start = matcher.end() - 4; + } + /*Pattern escapedSpoilerOpenerPattern = Pattern.compile(">!"); + Matcher escapedSpoilerOpenerMatcher = escapedSpoilerOpenerPattern.matcher(markdownStringBuilder); + ArrayList matched = new ArrayList<>(); + while (escapedSpoilerOpenerMatcher.find()) { + matched.add(escapedSpoilerOpenerMatcher.start()); + find = true; + } + for (int i = matched.size() - 1; i >= 0; i--) { + markdownStringBuilder.replace(matched.get(i), matched.get(i) + 4, ">"); + }*/ + if (find) { + textView.setText(markdownStringBuilder); + } + } + +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerSpan.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerSpan.java new file mode 100644 index 00000000..5be3797c --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerSpan.java @@ -0,0 +1,63 @@ +package ml.docilealligator.infinityforreddit.markdown; + +import android.text.Layout; +import android.text.Spannable; +import android.text.TextPaint; +import android.text.style.ClickableSpan; +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.transition.AutoTransition; +import androidx.transition.TransitionManager; + +import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView; + +public class SpoilerSpan extends ClickableSpan { + final int textColor; + final int backgroundColor; + private boolean isShowing = false; + + public SpoilerSpan(@NonNull int textColor, @NonNull int backgroundColor) { + this.textColor = textColor; + this.backgroundColor = backgroundColor; + } + + @Override + public void onClick(@NonNull View widget) { + if (!(widget instanceof TextView)) { + return; + } + + final TextView textView = (TextView) widget; + final Spannable spannable = (Spannable) textView.getText(); + + final int end = spannable.getSpanEnd(this); + + if (end < 0) { + return; + } + + final Layout layout = textView.getLayout(); + if (layout == null) { + return; + } + + if (widget instanceof SpoilerOnClickTextView) { + ((SpoilerOnClickTextView) textView).setSpoilerOnClick(true); + } + isShowing = !isShowing; + widget.invalidate(); + } + + @Override + public void updateDrawState(@NonNull TextPaint ds) { + if (isShowing) { + super.updateDrawState(ds); + } else { + ds.bgColor = backgroundColor; + } + ds.setColor(textColor); + ds.setUnderlineText(false); + } +} \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SuperscriptInlineProcessor.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SuperscriptInlineProcessor.java new file mode 100644 index 00000000..27f4d1e4 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SuperscriptInlineProcessor.java @@ -0,0 +1,32 @@ +package ml.docilealligator.infinityforreddit.markdown; + +import androidx.annotation.Nullable; + +import org.commonmark.node.HtmlInline; +import org.commonmark.node.Node; + +import java.util.regex.Pattern; + +import io.noties.markwon.inlineparser.InlineProcessor; + +public class SuperscriptInlineProcessor extends InlineProcessor { + private static final Pattern HTML_TAG = Pattern.compile("", Pattern.CASE_INSENSITIVE); + + @Override + public char specialCharacter() { + return '<'; + } + + @Nullable + @Override + protected Node parse() { + String m = match(HTML_TAG); + if (m != null) { + HtmlInline node = new HtmlInline(); + node.setLiteral(m); + return node; + } else { + return null; + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SuperscriptInlineProcessor.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SuperscriptInlineProcessor.java deleted file mode 100644 index 136a69d4..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SuperscriptInlineProcessor.java +++ /dev/null @@ -1,32 +0,0 @@ -package ml.docilealligator.infinityforreddit.utils; - -import androidx.annotation.Nullable; - -import org.commonmark.node.HtmlInline; -import org.commonmark.node.Node; - -import java.util.regex.Pattern; - -import io.noties.markwon.inlineparser.InlineProcessor; - -public class SuperscriptInlineProcessor extends InlineProcessor { - private static final Pattern HTML_TAG = Pattern.compile("", Pattern.CASE_INSENSITIVE); - - @Override - public char specialCharacter() { - return '<'; - } - - @Nullable - @Override - protected Node parse() { - String m = match(HTML_TAG); - if (m != null) { - HtmlInline node = new HtmlInline(); - node.setLiteral(m); - return node; - } else { - return null; - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java index 15bcefa0..2963a58f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -65,7 +65,7 @@ public class Utils { .replaceAll("((?<=[\\s])|^)/[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com$0)") .replaceAll("((?<=[\\s])|^)[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com/$0)") .replaceAll("\\^{2,}", "^") - .replaceAll(">!(\\n?(?:[\\S\\h]+?(?:\\n?[\\S\\h]+?)?)\\n?)!<", ">!$1!<") // html entity remains escaped inside an inline block + .replaceAll(">!(\\n?(?:.+?(?:\\n?.+?)?)\\n?)!<", ">!$1!<") // html entity remains escaped inside an inline block .replaceAll("(^|^ *|\\n *)#(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)##(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)###(?!($|\\s|#))", "$0 ") -- cgit v1.2.3 From b106e0677a47e203076fd0a4f5bfcc92b08def6d Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Wed, 17 Nov 2021 02:18:31 +0300 Subject: Make scroll button work on single comment mode --- .../fragments/ViewPostDetailFragment.java | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'app/src/main/java') 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 e912418d..5e4d8c3e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -67,6 +67,7 @@ import butterknife.ButterKnife; import im.ene.toro.exoplayer.ExoCreator; import im.ene.toro.media.PlaybackInfo; import im.ene.toro.media.VolumeInfo; +import im.ene.toro.widget.Container; import ml.docilealligator.infinityforreddit.DeleteThing; import ml.docilealligator.infinityforreddit.Flair; import ml.docilealligator.infinityforreddit.FragmentCommunicator; @@ -1736,28 +1737,32 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic } public void scrollToNextParentComment() { - int currentPosition = ((LinearLayoutManagerBugFixed) (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager()).findFirstVisibleItemPosition(); - if (mCommentsAdapter != null) { - int nextParentPosition = mCommentsAdapter.getNextParentCommentPosition(mCommentsRecyclerView == null ? currentPosition - 1 : currentPosition); + RecyclerView chooseYourView = mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView; + if (mCommentsAdapter != null && chooseYourView != null) { + int currentPosition = ((LinearLayoutManagerBugFixed) chooseYourView.getLayoutManager()).findFirstVisibleItemPosition(); + //int nextParentPosition = mCommentsAdapter.getNextParentCommentPosition(mCommentsRecyclerView == null ? currentPosition - 1 : currentPosition); + int nextParentPosition = mCommentsAdapter.getNextParentCommentPosition(mCommentsRecyclerView == null && !isSingleCommentThreadMode ? currentPosition - 1 : currentPosition); if (nextParentPosition < 0) { return; } - mSmoothScroller.setTargetPosition(mCommentsRecyclerView == null ? nextParentPosition + 1 : nextParentPosition); + mSmoothScroller.setTargetPosition(mCommentsRecyclerView == null && !isSingleCommentThreadMode ? nextParentPosition + 1 : nextParentPosition); mIsSmoothScrolling = true; - (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().startSmoothScroll(mSmoothScroller); + chooseYourView.getLayoutManager().startSmoothScroll(mSmoothScroller); } } public void scrollToPreviousParentComment() { - int currentPosition = ((LinearLayoutManagerBugFixed) (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager()).findFirstVisibleItemPosition(); - if (mCommentsAdapter != null) { - int previousParentPosition = mCommentsAdapter.getPreviousParentCommentPosition(mCommentsRecyclerView == null ? currentPosition - 1 : currentPosition); + RecyclerView chooseYourView = mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView; + if (mCommentsAdapter != null && chooseYourView != null) { + int currentPosition = ((LinearLayoutManagerBugFixed) chooseYourView.getLayoutManager()).findFirstVisibleItemPosition(); + //int previousParentPosition = mCommentsAdapter.getPreviousParentCommentPosition(mCommentsRecyclerView == null ? currentPosition - 1 : currentPosition); + int previousParentPosition = mCommentsAdapter.getPreviousParentCommentPosition(mCommentsRecyclerView == null && !isSingleCommentThreadMode ? currentPosition - 1 : currentPosition); if (previousParentPosition < 0) { return; } - mSmoothScroller.setTargetPosition(mCommentsRecyclerView == null ? previousParentPosition + 1 : previousParentPosition); + mSmoothScroller.setTargetPosition(mCommentsRecyclerView == null && !isSingleCommentThreadMode ? previousParentPosition + 1 : previousParentPosition); mIsSmoothScrolling = true; - (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().startSmoothScroll(mSmoothScroller); + chooseYourView.getLayoutManager().startSmoothScroll(mSmoothScroller); } } -- cgit v1.2.3 From fd1b6fa6fef6aecb7e945546c1f14f3aa6923881 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sun, 21 Nov 2021 19:38:49 +0800 Subject: Fix cannot open media in Gallery layout. --- .../adapters/PostRecyclerViewAdapter.java | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index 2c23649e..57ce12b0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -1916,12 +1916,15 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter Date: Sun, 21 Nov 2021 20:59:01 +0800 Subject: Fix dark theme issue when selecting playback speed. Minor bugs fixed. --- .../infinityforreddit/activities/BaseActivity.java | 4 +- .../infinityforreddit/activities/MainActivity.java | 3 -- .../activities/TrendingActivity.java | 8 ++-- .../activities/ViewVideoActivity.java | 48 +++++++++++++++++++++- .../infinityforreddit/activities/WikiActivity.java | 6 ++- 5 files changed, 59 insertions(+), 10 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java index 13f40f63..ad840efa 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/BaseActivity.java @@ -129,10 +129,10 @@ public abstract class BaseActivity extends AppCompatActivity { } } - boolean userDefinedChangeSatusBarIconColorInImmersiveInterface = + boolean userDefinedChangeStatusBarIconColorInImmersiveInterface = customThemeWrapper.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface(); if (immersiveInterface && isImmersiveInterfaceApplicable) { - changeStatusBarIconColor = userDefinedChangeSatusBarIconColorInImmersiveInterface; + changeStatusBarIconColor = userDefinedChangeStatusBarIconColorInImmersiveInterface; } else { changeStatusBarIconColor = false; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index 30d134fe..1b509410 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -270,9 +270,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { drawer.setFitsSystemWindows(false); getWindow().setDecorFitsSystemWindows(false); - /*drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | - View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | - View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);*/ } else { window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java index 7057b1ad..039688fb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/TrendingActivity.java @@ -22,6 +22,7 @@ import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.bumptech.glide.Glide; +import com.bumptech.glide.RequestManager; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; import com.r0adkll.slidr.Slidr; @@ -100,10 +101,10 @@ public class TrendingActivity extends BaseActivity { @Inject Executor mExecutor; private String mAccessToken; - private String mAccountName; private boolean isRefreshing = false; private ArrayList trendingSearches; private TrendingSearchRecyclerViewAdapter adapter; + private RequestManager mGlide; @Override protected void onCreate(Bundle savedInstanceState) { @@ -151,7 +152,8 @@ public class TrendingActivity extends BaseActivity { setToolbarGoToTop(toolbar); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); + + mGlide = Glide.with(this); DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); @@ -277,7 +279,7 @@ public class TrendingActivity extends BaseActivity { private void showErrorView(int stringId) { errorLinearLayout.setVisibility(View.VISIBLE); - Glide.with(this).load(R.drawable.error_image).into(errorImageView); + mGlide.load(R.drawable.error_image).into(errorImageView); errorTextView.setText(stringId); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java index 548e7c53..50e756ed 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java @@ -1,5 +1,10 @@ package ml.docilealligator.infinityforreddit.activities; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; +import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; + import android.Manifest; import android.content.Intent; import android.content.SharedPreferences; @@ -32,6 +37,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; @@ -150,6 +156,8 @@ public class ViewVideoActivity extends AppCompatActivity { TextView titleTextView; @BindView(R.id.download_image_view_exo_playback_control_view) ImageView downloadImageView; + @BindView(R.id.playback_speed_image_view_exo_playback_control_view) + ImageView playbackSpeedImageView; @BindView(R.id.lockable_nested_scroll_view_view_video_activity) LockableNestedScrollView nestedScrollView; @@ -206,7 +214,37 @@ public class ViewVideoActivity extends AppCompatActivity { ((Infinity) getApplication()).getAppComponent().inject(this); - getTheme().applyStyle(R.style.Theme_Normal, true); + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; + int systemThemeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2")); + switch (systemThemeType) { + case 0: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); + getTheme().applyStyle(R.style.Theme_Normal, true); + break; + case 1: + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); + if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { + getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true); + } else { + getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true); + } + break; + case 2: + if (systemDefault) { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); + } else { + AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY); + } + if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) { + getTheme().applyStyle(R.style.Theme_Normal, true); + } else { + if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { + getTheme().applyStyle(R.style.Theme_Normal_AmoledDark, true); + } else { + getTheme().applyStyle(R.style.Theme_Normal_NormalDark, true); + } + } + } getTheme().applyStyle(FontStyle.valueOf(mSharedPreferences .getString(SharedPreferencesUtils.FONT_SIZE_KEY, FontStyle.Normal.name())).getResId(), true); @@ -250,6 +288,14 @@ public class ViewVideoActivity extends AppCompatActivity { isDownloading = true; requestPermissionAndDownload(); }); + + playbackSpeedImageView.setOnClickListener(view -> { + PlaybackSpeedBottomSheetFragment playbackSpeedBottomSheetFragment = new PlaybackSpeedBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putInt(PlaybackSpeedBottomSheetFragment.EXTRA_PLAYBACK_SPEED, playbackSpeed); + playbackSpeedBottomSheetFragment.setArguments(bundle); + playbackSpeedBottomSheetFragment.show(getSupportFragmentManager(), playbackSpeedBottomSheetFragment.getTag()); + }); } else { ActionBar actionBar = getSupportActionBar(); Drawable upArrow = resources.getDrawable(R.drawable.ic_arrow_back_white_24dp); 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 1a353a7f..09fcffe6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -26,6 +26,7 @@ import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.bumptech.glide.Glide; +import com.bumptech.glide.RequestManager; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; import com.r0adkll.slidr.Slidr; @@ -113,6 +114,7 @@ public class WikiActivity extends BaseActivity { private Markwon markwon; private MarkwonAdapter markwonAdapter; private boolean isRefreshing = false; + private RequestManager mGlide; @Override protected void onCreate(Bundle savedInstanceState) { @@ -154,6 +156,8 @@ public class WikiActivity extends BaseActivity { } } + mGlide = Glide.with(this); + swipeRefreshLayout.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true)); swipeRefreshLayout.setOnRefreshListener(this::loadWiki); @@ -328,7 +332,7 @@ public class WikiActivity extends BaseActivity { swipeRefreshLayout.setRefreshing(false); mFetchWikiInfoLinearLayout.setVisibility(View.VISIBLE); mFetchWikiInfoTextView.setText(stringResId); - Glide.with(this).load(R.drawable.error_image).into(mFetchWikiInfoImageView); + mGlide.load(R.drawable.error_image).into(mFetchWikiInfoImageView); } @Override -- cgit v1.2.3 From 50a2db2a398e257e236505cb222c289cb0d5331f Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sun, 21 Nov 2021 22:55:58 +0800 Subject: Implement SaveMemoryCenterInsideDownsampleStrategy to smartly downsample images in PostRecyclerViewAdapter and PostDetailRecyclerViewAdapter. --- .../SaveMemoryCenterInisdeDownsampleStrategy.java | 29 ++++++++++ .../adapters/PostDetailRecyclerViewAdapter.java | 67 +++++----------------- .../adapters/PostRecyclerViewAdapter.java | 67 +++------------------- .../infinityforreddit/fragments/PostFragment.java | 20 +++---- .../fragments/ViewPostDetailFragment.java | 10 +--- 5 files changed, 61 insertions(+), 132 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/SaveMemoryCenterInisdeDownsampleStrategy.java (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SaveMemoryCenterInisdeDownsampleStrategy.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SaveMemoryCenterInisdeDownsampleStrategy.java new file mode 100644 index 00000000..8516c53e --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SaveMemoryCenterInisdeDownsampleStrategy.java @@ -0,0 +1,29 @@ +package ml.docilealligator.infinityforreddit; + +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; + +public class SaveMemoryCenterInisdeDownsampleStrategy extends DownsampleStrategy { + + @Override + public float getScaleFactor(int sourceWidth, int sourceHeight, int requestedWidth, int requestedHeight) { + int originalSourceWidth = sourceWidth; + int originalSourceHeight = sourceHeight; + if (sourceWidth * sourceHeight > 5_000_000) { + int divisor = 2; + do { + sourceWidth /= divisor; + sourceHeight /= divisor; + } while (sourceWidth * sourceHeight > 5_000_000); + } + + float widthPercentage = (float) requestedWidth / (float) sourceWidth; + float heightPercentage = (float) requestedHeight / (float) sourceHeight; + + return Math.min((float) sourceWidth / (float) originalSourceWidth, (float) sourceHeight / (float) originalSourceHeight) * Math.min(1.f, Math.min(widthPercentage, heightPercentage)); + } + + @Override + public SampleSizeRounding getSampleSizeRounding(int sourceWidth, int sourceHeight, int requestedWidth, int requestedHeight) { + return SampleSizeRounding.MEMORY; + } +} 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 0b2c7f94..0eb69416 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -87,6 +87,7 @@ import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import me.saket.bettermovementmethod.BetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks; +import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SaveThing; @@ -140,7 +141,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter preview.getPreviewWidth()) { - mGlide.load(preview.getPreviewUrl()).override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostDetailVideoAutoplayViewHolder) holder).previewImageView); - } else { - mGlide.load(preview.getPreviewUrl()).into(((PostDetailVideoAutoplayViewHolder) holder).previewImageView); - } + mGlide.load(preview.getPreviewUrl()).centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostDetailVideoAutoplayViewHolder) holder).previewImageView); } else { ((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1); } @@ -736,8 +731,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter 10_000_000) { + if (preview.getPreviewWidth() * preview.getPreviewHeight() > 5_000_000) { for (int i = previews.size() - 1; i >= 1; i--) { preview = previews.get(i); - if (mImageViewWidth >= preview.getPreviewWidth()) { - if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 10_000_000) { - return preview; - } - } else { - int height = mImageViewWidth / preview.getPreviewWidth() * preview.getPreviewHeight(); - if (mImageViewWidth * height <= 10_000_000) { - return preview; - } + if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 5_000_000) { + return preview; } } } - if (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000) { - int divisor = 2; - do { - preview.setPreviewWidth(preview.getPreviewWidth() / divisor); - preview.setPreviewHeight(preview.getPreviewHeight() / divisor); - divisor *= 2; - } while (preview.getPreviewWidth() * preview.getPreviewHeight() > 10_000_000); - } - return preview; } @@ -890,7 +867,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter imageRequestBuilder = mGlide.load(url) - .listener(new RequestListener() { + .listener(new RequestListener<>() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { ((PostDetailImageAndGifAutoplayViewHolder) holder).mLoadImageProgressBar.setVisibility(View.GONE); @@ -913,15 +890,11 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter preview.getPreviewWidth()) { - imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView); - } else { - imageRequestBuilder.into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView); - } + imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView); } } else if (holder instanceof PostDetailVideoAndGifPreviewHolder) { RequestBuilder imageRequestBuilder = mGlide.load(preview.getPreviewUrl()) - .listener(new RequestListener() { + .listener(new RequestListener<>() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { ((PostDetailVideoAndGifPreviewHolder) holder).mLoadImageProgressBar.setVisibility(View.GONE); @@ -945,15 +918,11 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter preview.getPreviewWidth()) { - imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView); - } else { - imageRequestBuilder.into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView); - } + imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView); } } else if (holder instanceof PostDetailLinkViewHolder) { RequestBuilder imageRequestBuilder = mGlide.load(preview.getPreviewUrl()) - .listener(new RequestListener() { + .listener(new RequestListener<>() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { ((PostDetailLinkViewHolder) holder).mLoadImageProgressBar.setVisibility(View.GONE); @@ -977,15 +946,11 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter preview.getPreviewWidth()) { - imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostDetailLinkViewHolder) holder).mImageView); - } else { - imageRequestBuilder.into(((PostDetailLinkViewHolder) holder).mImageView); - } + imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostDetailLinkViewHolder) holder).mImageView); } } else if (holder instanceof PostDetailGalleryViewHolder) { RequestBuilder imageRequestBuilder = mGlide.load(preview.getPreviewUrl()) - .listener(new RequestListener() { + .listener(new RequestListener<>() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { ((PostDetailGalleryViewHolder) holder).mLoadImageProgressBar.setVisibility(View.GONE); @@ -1008,11 +973,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter preview.getPreviewWidth()) { - imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostDetailGalleryViewHolder) holder).mImageView); - } else { - imageRequestBuilder.into(((PostDetailGalleryViewHolder) holder).mImageView); - } + imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostDetailGalleryViewHolder) holder).mImageView); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index 57ce12b0..a8cf40d2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -69,6 +69,7 @@ import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks; import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; +import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SaveThing; import ml.docilealligator.infinityforreddit.VoteThing; @@ -126,7 +127,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter preview.getPreviewWidth()) { - mGlide.load(preview.getPreviewUrl()).override(Target.SIZE_ORIGINAL).into(((PostVideoAutoplayViewHolder) holder).previewImageView); - } else { - mGlide.load(preview.getPreviewUrl()).into(((PostVideoAutoplayViewHolder) holder).previewImageView); - } + mGlide.load(preview.getPreviewUrl()).centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostVideoAutoplayViewHolder) holder).previewImageView); } else { ((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1); } @@ -774,8 +769,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter preview.getPreviewWidth()) { - mGlide.load(preview.getPreviewUrl()).override(Target.SIZE_ORIGINAL).into(((PostCard2VideoAutoplayViewHolder) holder).previewImageView); - } else { - mGlide.load(preview.getPreviewUrl()).into(((PostCard2VideoAutoplayViewHolder) holder).previewImageView); - } + mGlide.load(preview.getPreviewUrl()).centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostCard2VideoAutoplayViewHolder) holder).previewImageView); } else { ((PostCard2VideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1); } @@ -909,8 +898,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter 5_000_000) { for (int i = previews.size() - 1; i >= 1; i--) { preview = previews.get(i); - if (mImageViewWidth >= preview.getPreviewWidth()) { - if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 5_000_000) { - return preview; - } - } else { - int height = mImageViewWidth / preview.getPreviewWidth() * preview.getPreviewHeight(); - if (mImageViewWidth * height <= 5_000_000) { - preview.setPreviewWidth(mImageViewWidth); - preview.setPreviewHeight(height); - return preview; - } + if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 5_000_000) { + return preview; } } } - - if (preview.getPreviewWidth() * preview.getPreviewHeight() > 5_000_000) { - int divisor = 2; - do { - preview.setPreviewWidth(preview.getPreviewWidth() / divisor); - preview.setPreviewHeight(preview.getPreviewHeight() / divisor); - divisor *= 2; - } while (preview.getPreviewWidth() * preview.getPreviewHeight() > 5_000_000); - } return preview; } @@ -1494,7 +1453,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter preview.getPreviewWidth()) { - imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostGalleryViewHolder) holder).imageView); - } else { - imageRequestBuilder.into(((PostGalleryViewHolder) holder).imageView); - } + imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostGalleryViewHolder) holder).imageView); } } } else if (holder instanceof PostCard2WithPreviewViewHolder) { @@ -1558,11 +1513,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter preview.getPreviewWidth()) { - imageRequestBuilder.override(preview.getPreviewWidth(), preview.getPreviewHeight()).into(((PostCard2WithPreviewViewHolder) holder).imageView); - } else { - imageRequestBuilder.into(((PostCard2WithPreviewViewHolder) holder).imageView); - } + imageRequestBuilder.centerInside().downsample(new SaveMemoryCenterInisdeDownsampleStrategy()).into(((PostCard2WithPreviewViewHolder) holder).imageView); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index 4a9703f7..257f604e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -17,7 +17,6 @@ import android.os.Build; import android.os.Bundle; import android.os.CountDownTimer; import android.os.Handler; -import android.util.DisplayMetrics; import android.view.HapticFeedbackConstants; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -338,10 +337,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } } - DisplayMetrics displayMetrics = new DisplayMetrics(); - activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); - int windowWidth = displayMetrics.widthPixels; - mGlide = Glide.with(activity); lazyModeRunnable = new LazyModeRunnable() { @@ -452,7 +447,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mCustomThemeWrapper, locale, - windowWidth, accessToken, accountName, postType, postLayout, true, + accessToken, accountName, postType, postLayout, true, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, mExoCreator, new PostRecyclerViewAdapter.Callback() { @Override @@ -529,7 +524,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mCustomThemeWrapper, locale, - windowWidth, accessToken, accountName, postType, postLayout, displaySubredditName, + accessToken, accountName, postType, postLayout, displaySubredditName, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, mExoCreator, new PostRecyclerViewAdapter.Callback() { @Override @@ -600,7 +595,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mCustomThemeWrapper, locale, - windowWidth, accessToken, accountName, postType, postLayout, true, + accessToken, accountName, postType, postLayout, true, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, mExoCreator, new PostRecyclerViewAdapter.Callback() { @Override @@ -665,7 +660,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mCustomThemeWrapper, locale, - windowWidth, accessToken, accountName, postType, postLayout, true, + accessToken, accountName, postType, postLayout, true, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, mExoCreator, new PostRecyclerViewAdapter.Callback() { @Override @@ -726,7 +721,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mCustomThemeWrapper, locale, - windowWidth, accessToken, accountName, postType, postLayout, true, + accessToken, accountName, postType, postLayout, true, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, mExoCreator, new PostRecyclerViewAdapter.Callback() { @Override @@ -786,7 +781,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mCustomThemeWrapper, locale, - windowWidth, accessToken, accountName, postType, postLayout, true, + accessToken, accountName, postType, postLayout, true, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, mExoCreator, new PostRecyclerViewAdapter.Callback() { @Override @@ -840,7 +835,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mCustomThemeWrapper, locale, - windowWidth, accessToken, accountName, postType, postLayout, true, + accessToken, accountName, postType, postLayout, true, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences, mExoCreator, new PostRecyclerViewAdapter.Callback() { @Override @@ -891,7 +886,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator { StaggeredGridLayoutManagerItemOffsetDecoration itemDecoration = new StaggeredGridLayoutManagerItemOffsetDecoration(activity, R.dimen.staggeredLayoutManagerItemOffset, nColumns); mPostRecyclerView.addItemDecoration(itemDecoration); - windowWidth /= 2; } if (recyclerViewPosition > 0) { 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 e912418d..de32b033 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -16,7 +16,6 @@ import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; -import android.util.DisplayMetrics; import android.view.HapticFeedbackConstants; import android.view.LayoutInflater; import android.view.Menu; @@ -224,7 +223,6 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic private boolean mExpandChildren; private boolean mSeparatePostAndComments = false; private boolean mMarkPostsAsRead; - private int mWindowWidth; private ConcatAdapter mConcatAdapter; private PostDetailRecyclerViewAdapter mPostAdapter; private CommentsRecyclerViewAdapter mCommentsAdapter; @@ -290,10 +288,6 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic showToast = true; } - DisplayMetrics displayMetrics = new DisplayMetrics(); - activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); - mWindowWidth = displayMetrics.widthPixels; - mLockFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false); mSwipeUpToHideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false); mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false); @@ -550,7 +544,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic mPostAdapter = new PostDetailRecyclerViewAdapter(activity, this, mExecutor, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit, mRedditDataRoomDatabase, mGlide, - mWindowWidth, mSeparatePostAndComments, mAccessToken, mAccountName, mPost, mLocale, + mSeparatePostAndComments, mAccessToken, mAccountName, mPost, mLocale, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostDetailsSharedPreferences, mExoCreator, post -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition))); mCommentsAdapter = new CommentsRecyclerViewAdapter(activity, @@ -1195,7 +1189,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic mPostAdapter = new PostDetailRecyclerViewAdapter(activity, ViewPostDetailFragment.this, mExecutor, mCustomThemeWrapper, mRetrofit, mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit, - mRedditDataRoomDatabase, mGlide, mWindowWidth, mSeparatePostAndComments, + mRedditDataRoomDatabase, mGlide, mSeparatePostAndComments, mAccessToken, mAccountName, mPost, mLocale, mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostDetailsSharedPreferences, mExoCreator, -- cgit v1.2.3 From 841fec87dc81eb8559beaf605f0ef06cf0ca90c5 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 22 Nov 2021 19:27:45 +0800 Subject: Fix TrackSelectionDialog button color. Do not automatically show control view in autoplaying videos. --- .../infinityforreddit/activities/ViewVideoActivity.java | 16 ++++++++++++---- .../fragments/ViewRPANBroadcastFragment.java | 12 ++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java index 50e756ed..d70aaa68 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java @@ -6,6 +6,7 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; import android.Manifest; +import android.app.AlertDialog; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.ActivityInfo; @@ -85,6 +86,7 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.apis.VReddIt; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PlaybackSpeedBottomSheetFragment; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.font.ContentFontFamily; import ml.docilealligator.infinityforreddit.font.ContentFontStyle; import ml.docilealligator.infinityforreddit.font.FontFamily; @@ -202,6 +204,9 @@ public class ViewVideoActivity extends AppCompatActivity { @Named("default") SharedPreferences mSharedPreferences; + @Inject + CustomThemeWrapper mCustomThemeWrapper; + @Inject Executor mExecutor; @@ -566,10 +571,13 @@ public class ViewVideoActivity extends AppCompatActivity { hdButton.setVisibility(View.VISIBLE); hdButton.setOnClickListener(view -> { - TrackSelectionDialogBuilder build = new TrackSelectionDialogBuilder(ViewVideoActivity.this, getString(R.string.select_video_quality), trackSelector, 0); - build.setShowDisableOption(true); - build.setAllowAdaptiveSelections(false); - build.build().show(); + TrackSelectionDialogBuilder builder = new TrackSelectionDialogBuilder(ViewVideoActivity.this, getString(R.string.select_video_quality), trackSelector, 0); + builder.setShowDisableOption(true); + builder.setAllowAdaptiveSelections(false); + AlertDialog alertDialog = builder.build(); + alertDialog.show(); + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); + alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); }); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java index 66921637..5b7dcb2c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRPANBroadcastFragment.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit.fragments; +import android.app.AlertDialog; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; @@ -207,11 +208,14 @@ public class ViewRPANBroadcastFragment extends Fragment { hdButton.setVisibility(View.VISIBLE); hdButton.setOnClickListener(view -> { - TrackSelectionDialogBuilder build = new TrackSelectionDialogBuilder(mActivity, + TrackSelectionDialogBuilder builder = new TrackSelectionDialogBuilder(mActivity, getString(R.string.select_video_quality), trackSelector, 0); - build.setShowDisableOption(true); - build.setAllowAdaptiveSelections(false); - build.build().show(); + builder.setShowDisableOption(true); + builder.setAllowAdaptiveSelections(false); + AlertDialog alertDialog = builder.build(); + alertDialog.show(); + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); + alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(mCustomThemeWrapper.getPrimaryTextColor()); }); for (int i = 0; i < trackGroups.length; i++) { -- cgit v1.2.3 From 1b39925cf8f050597e8c98266b724d2cb0334223 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 22 Nov 2021 20:35:14 +0800 Subject: Version 5.1.1. Fix anonymous subreddits and multireddits do not show in MainActivity TabLayout. Fix changing tab names not working in anonymous mode. --- .../infinityforreddit/activities/MainActivity.java | 91 +++++++++------------- .../settings/CustomizeMainPageTabsFragment.java | 16 ++-- 2 files changed, 43 insertions(+), 64 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index 1b509410..990fbe83 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -38,7 +38,6 @@ import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; -import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.RecyclerView; import androidx.viewpager2.adapter.FragmentStateAdapter; @@ -852,51 +851,37 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb tabLayout.setTabMode(TabLayout.MODE_FIXED); } new TabLayoutMediator(tabLayout, viewPager2, (tab, position) -> { - if (mAccessToken == null) { - switch (position) { - case 0: - tab.setText(R.string.home); - break; - case 1: - tab.setText(R.string.popular); - break; - case 2: - tab.setText(R.string.all); - break; - } - } else { - switch (position) { - case 0: - tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, getString(R.string.home))); - break; - case 1: - tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.popular))); - break; - case 2: - tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all))); - break; - } - if (position >= tabCount && (mShowFavoriteMultiReddits || mShowMultiReddits || - mShowFavoriteSubscribedSubreddits || mShowSubscribedSubreddits) - && sectionsPagerAdapter != null) { - if (position - tabCount < sectionsPagerAdapter.favoriteMultiReddits.size()) { - tab.setText(sectionsPagerAdapter.favoriteMultiReddits.get(position - tabCount).getName()); - } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() < sectionsPagerAdapter.multiReddits.size()) { - tab.setText(sectionsPagerAdapter.multiReddits.get(position - tabCount - - sectionsPagerAdapter.favoriteMultiReddits.size()).getName()); - } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() - - sectionsPagerAdapter.multiReddits.size() < sectionsPagerAdapter.favoriteSubscribedSubreddits.size()) { - tab.setText(sectionsPagerAdapter.favoriteSubscribedSubreddits.get(position - tabCount - - sectionsPagerAdapter.favoriteMultiReddits.size() - - sectionsPagerAdapter.multiReddits.size()).getName()); - } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() + switch (position) { + case 0: + tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_TITLE, getString(R.string.home))); + break; + case 1: + tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_TITLE, getString(R.string.popular))); + break; + case 2: + tab.setText(mMainActivityTabsSharedPreferences.getString((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_TITLE, getString(R.string.all))); + break; + } + if (position >= tabCount && (mShowFavoriteMultiReddits || mShowMultiReddits || + mShowFavoriteSubscribedSubreddits || mShowSubscribedSubreddits) + && sectionsPagerAdapter != null) { + if (position - tabCount < sectionsPagerAdapter.favoriteMultiReddits.size()) { + tab.setText(sectionsPagerAdapter.favoriteMultiReddits.get(position - tabCount).getName()); + } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() < sectionsPagerAdapter.multiReddits.size()) { + tab.setText(sectionsPagerAdapter.multiReddits.get(position - tabCount + - sectionsPagerAdapter.favoriteMultiReddits.size()).getName()); + } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() + - sectionsPagerAdapter.multiReddits.size() < sectionsPagerAdapter.favoriteSubscribedSubreddits.size()) { + tab.setText(sectionsPagerAdapter.favoriteSubscribedSubreddits.get(position - tabCount + - sectionsPagerAdapter.favoriteMultiReddits.size() + - sectionsPagerAdapter.multiReddits.size()).getName()); + } else if (position - tabCount - sectionsPagerAdapter.favoriteMultiReddits.size() + - sectionsPagerAdapter.multiReddits.size() + - sectionsPagerAdapter.favoriteSubscribedSubreddits.size() < sectionsPagerAdapter.subscribedSubreddits.size()) { + tab.setText(sectionsPagerAdapter.subscribedSubreddits.get(position - tabCount + - sectionsPagerAdapter.favoriteMultiReddits.size() - sectionsPagerAdapter.multiReddits.size() - - sectionsPagerAdapter.favoriteSubscribedSubreddits.size() < sectionsPagerAdapter.subscribedSubreddits.size()) { - tab.setText(sectionsPagerAdapter.subscribedSubreddits.get(position - tabCount - - sectionsPagerAdapter.favoriteMultiReddits.size() - - sectionsPagerAdapter.multiReddits.size() - - sectionsPagerAdapter.favoriteSubscribedSubreddits.size()).getName()); - } + - sectionsPagerAdapter.favoriteSubscribedSubreddits.size()).getName()); } } }).attach(); @@ -922,7 +907,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb loadSubscriptions(); multiRedditViewModel = new ViewModelProvider(this, new MultiRedditViewModel.Factory(getApplication(), - mRedditDataRoomDatabase, mAccountName)) + mRedditDataRoomDatabase, mAccountName == null ? "-" : mAccountName)) .get(MultiRedditViewModel.class); multiRedditViewModel.getAllFavoriteMultiReddits().observe(this, multiReddits -> { @@ -931,17 +916,14 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } }); - multiRedditViewModel.getAllMultiReddits().observe(this, new Observer>() { - @Override - public void onChanged(List multiReddits) { - if (mShowMultiReddits && sectionsPagerAdapter != null) { - sectionsPagerAdapter.setMultiReddits(multiReddits); - } + multiRedditViewModel.getAllMultiReddits().observe(this, multiReddits -> { + if (mShowMultiReddits && sectionsPagerAdapter != null) { + sectionsPagerAdapter.setMultiReddits(multiReddits); } }); subscribedSubredditViewModel = new ViewModelProvider(this, - new SubscribedSubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName)) + new SubscribedSubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName == null ? "-" : mAccountName)) .get(SubscribedSubredditViewModel.class); subscribedSubredditViewModel.getAllSubscribedSubreddits().observe(this, subscribedSubredditData -> { @@ -1693,9 +1675,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb @Override public int getItemCount() { - if (mAccessToken == null) { - return 3; - } return tabCount + favoriteMultiReddits.size() + multiReddits.size() + favoriteSubscribedSubreddits.size() + subscribedSubreddits.size(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java index dddbda85..44f45eef 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CustomizeMainPageTabsFragment.java @@ -492,26 +492,26 @@ public class CustomizeMainPageTabsFragment extends Fragment { tab3AddImageView.setOnClickListener(view -> selectName(2)); - showMultiredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, false)); - showMultiredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, b).apply()); + showMultiredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, false)); + showMultiredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_MULTIREDDITS, b).apply()); showMultiredditsLinearLayout.setOnClickListener(view -> { showMultiredditsSwitchMaterial.performClick(); }); - showFavoriteMultiredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_MULTIREDDITS, false)); - showFavoriteMultiredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_MULTIREDDITS, b).apply()); + showFavoriteMultiredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_MULTIREDDITS, false)); + showFavoriteMultiredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_MULTIREDDITS, b).apply()); showFavoriteMultiredditsLinearLayout.setOnClickListener(view -> { showFavoriteMultiredditsSwitchMaterial.performClick(); }); - showSubscribedSubredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS, false)); - showSubscribedSubredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS, b).apply()); + showSubscribedSubredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS, false)); + showSubscribedSubredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_SUBSCRIBED_SUBREDDITS, b).apply()); showSubscribedSubredditsLinearLayout.setOnClickListener(view -> { showSubscribedSubredditsSwitchMaterial.performClick(); }); - showFavoriteSubscribedSubredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, false)); - showFavoriteSubscribedSubredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, b).apply()); + showFavoriteSubscribedSubredditsSwitchMaterial.setChecked(mainActivityTabsSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, false)); + showFavoriteSubscribedSubredditsSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> mainActivityTabsSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_SHOW_FAVORITE_SUBSCRIBED_SUBREDDITS, b).apply()); showFavoriteSubscribedSubredditsLinearLayout.setOnClickListener(view -> { showFavoriteSubscribedSubredditsSwitchMaterial.performClick(); }); -- cgit v1.2.3 From b0134984ca078e0c7f3c7bebeaafe2146e76dde4 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Thu, 25 Nov 2021 19:04:34 +0300 Subject: Add a non-regex solution for parsing spoilers Add a non-regex solution for parsing spoilers that can also handle code blocks Add a custom BlockQuoteParser to prevent spoilers from being consumed as block quotes without the need for html escaping Make revealed spoiler backgrounds slightly darker --- .../activities/EditCommentActivity.java | 2 +- .../activities/EditPostActivity.java | 2 +- .../adapters/CommentsRecyclerViewAdapter.java | 8 +- .../CopyTextBottomSheetFragment.java | 1 - .../markdown/BlockQuoteWithExceptionParser.java | 85 ++++++++++ .../markdown/SpoilerParserPlugin.java | 185 +++++++++++++++++---- .../infinityforreddit/markdown/SpoilerSpan.java | 1 + .../infinityforreddit/utils/Utils.java | 1 - 8 files changed, 246 insertions(+), 39 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/markdown/BlockQuoteWithExceptionParser.java (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java index 6b358806..4f4b81ec 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java @@ -132,7 +132,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab mFullName = getIntent().getStringExtra(EXTRA_FULLNAME); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - mCommentContent = getIntent().getStringExtra(EXTRA_CONTENT).replaceAll(">!",">!"); + mCommentContent = getIntent().getStringExtra(EXTRA_CONTENT); contentEditText.setText(mCommentContent); if (savedInstanceState != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java index 2de2a47b..0d22d9b3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java @@ -141,7 +141,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled mFullName = getIntent().getStringExtra(EXTRA_FULLNAME); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); titleTextView.setText(getIntent().getStringExtra(EXTRA_TITLE)); - mPostContent = getIntent().getStringExtra(EXTRA_CONTENT).replaceAll(">!",">!");; + mPostContent = getIntent().getStringExtra(EXTRA_CONTENT); contentEditText.setText(mPostContent); if (savedInstanceState != null) { 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 8c17bc2d..6e6d18d5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -9,8 +9,6 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.os.Handler; -import android.text.SpannableStringBuilder; -import android.text.Spanned; import android.text.util.Linkify; import android.view.LayoutInflater; import android.view.View; @@ -36,8 +34,6 @@ import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar; import java.util.ArrayList; import java.util.Locale; import java.util.concurrent.Executor; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import butterknife.BindView; import butterknife.ButterKnife; @@ -48,6 +44,7 @@ import io.noties.markwon.core.MarkwonTheme; import io.noties.markwon.ext.strikethrough.StrikethroughPlugin; import io.noties.markwon.html.HtmlPlugin; import io.noties.markwon.html.tag.SuperScriptHandler; +import io.noties.markwon.inlineparser.BackslashInlineProcessor; import io.noties.markwon.inlineparser.BangInlineProcessor; import io.noties.markwon.inlineparser.HtmlInlineProcessor; import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin; @@ -70,11 +67,10 @@ import ml.docilealligator.infinityforreddit.customviews.CommentIndentationView; import ml.docilealligator.infinityforreddit.customviews.SpoilerOnClickTextView; import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment; import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; -import ml.docilealligator.infinityforreddit.markdown.SpoilerSpan; +import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.post.Post; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.markdown.SuperscriptInlineProcessor; import ml.docilealligator.infinityforreddit.utils.Utils; import retrofit2.Retrofit; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java index 1e458fc7..e30156dc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java @@ -74,7 +74,6 @@ public class CopyTextBottomSheetFragment extends LandscapeExpandedRoundedBottomS if (markdownText != null) { //markdownText = markdownText.replaceAll("", "^").replaceAll("", ""); - markdownText = markdownText.replaceAll(">!", ">!"); copyMarkdownTextView.setOnClickListener(view -> { showCopyDialog(markdownText); dismiss(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/BlockQuoteWithExceptionParser.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/BlockQuoteWithExceptionParser.java new file mode 100644 index 00000000..f500bb93 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/BlockQuoteWithExceptionParser.java @@ -0,0 +1,85 @@ +package ml.docilealligator.infinityforreddit.markdown; + +import org.commonmark.internal.util.Parsing; +import org.commonmark.node.Block; +import org.commonmark.node.BlockQuote; +import org.commonmark.parser.block.AbstractBlockParser; +import org.commonmark.parser.block.AbstractBlockParserFactory; +import org.commonmark.parser.block.BlockContinue; +import org.commonmark.parser.block.BlockStart; +import org.commonmark.parser.block.MatchedBlockParser; +import org.commonmark.parser.block.ParserState; + +// Parse and consume a block quote except when it's a spoiler opening +public class BlockQuoteWithExceptionParser extends AbstractBlockParser { + private final BlockQuote block = new BlockQuote(); + + private static boolean isMarker(ParserState state, int index) { + CharSequence line = state.getLine(); + return state.getIndent() < Parsing.CODE_BLOCK_INDENT && index < line.length() && line.charAt(index) == '>'; + } + + private static boolean isMarkerSpoiler(ParserState state, int index) { + CharSequence line = state.getLine(); + int length = line.length(); + try { + return state.getIndent() < Parsing.CODE_BLOCK_INDENT && index < length && line.charAt(index) == '>' && (index + 1) < length && line.charAt(index + 1) == '!'; + } catch (IndexOutOfBoundsException e) { + e.printStackTrace(); + return false; + } + } + + @Override + public boolean isContainer() { + return true; + } + + @Override + public boolean canContain(Block block) { + return true; + } + + @Override + public BlockQuote getBlock() { + return block; + } + + @Override + public BlockContinue tryContinue(ParserState state) { + int nextNonSpace = state.getNextNonSpaceIndex(); + if (isMarker(state, nextNonSpace)) { + int newColumn = state.getColumn() + state.getIndent() + 1; + // optional following space or tab + if (Parsing.isSpaceOrTab(state.getLine(), nextNonSpace + 1)) { + newColumn++; + } + return BlockContinue.atColumn(newColumn); + } else { + return BlockContinue.none(); + } + } + + public static class Factory extends AbstractBlockParserFactory { + public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockParser) { + int nextNonSpace = state.getNextNonSpaceIndex(); + // Potential for a spoiler opening + // We don't check for spoiler closing, neither does Reddit + if (isMarkerSpoiler(state, nextNonSpace)) { + // It might be a spoiler, don't consume + return BlockStart.none(); + } + // Not a spoiler then + else if (isMarker(state, nextNonSpace)) { + int newColumn = state.getColumn() + state.getIndent() + 1; + // optional following space or tab + if (Parsing.isSpaceOrTab(state.getLine(), nextNonSpace + 1)) { + newColumn++; + } + return BlockStart.of(new BlockQuoteWithExceptionParser()).atColumn(newColumn); + } else { + return BlockStart.none(); + } + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java index 47c484c9..36068b9a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java @@ -7,11 +7,20 @@ import android.widget.TextView; import androidx.annotation.NonNull; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import org.commonmark.node.Block; +import org.commonmark.node.BlockQuote; +import org.commonmark.node.HtmlBlock; +import org.commonmark.node.HtmlInline; +import org.commonmark.parser.Parser; + +import java.util.LinkedHashMap; +import java.util.Set; +import java.util.Stack; import io.noties.markwon.AbstractMarkwonPlugin; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import io.noties.markwon.core.CorePlugin; +import io.noties.markwon.core.spans.CodeBlockSpan; +import io.noties.markwon.core.spans.CodeSpan; public class SpoilerParserPlugin extends AbstractMarkwonPlugin { private final int textColor; @@ -26,40 +35,158 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin { return new SpoilerParserPlugin(textColor, backgroundColor); } + @Override + public void configureParser(@NonNull Parser.Builder builder) { + builder.customBlockParserFactory(new BlockQuoteWithExceptionParser.Factory()); + + Set> blocks = CorePlugin.enabledBlockTypes(); + blocks.remove(HtmlBlock.class); + blocks.remove(HtmlInline.class); + blocks.remove(BlockQuote.class); + + builder.enabledBlockTypes(blocks); + } + @Override public void afterSetText(@NonNull TextView textView) { textView.setHighlightColor(Color.TRANSPARENT); SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText()); - Pattern spoilerPattern = Pattern.compile(">!(\\n?(?:.+?(?:\\n?.+?)?)\\n?)!<"); - Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); - int start = 0; - boolean find = false; - while (matcher.find(start)) { - if (markdownStringBuilder.length() < 4 - || matcher.start() < 0 - || matcher.end() > markdownStringBuilder.length()) { - break; + + LinkedHashMap spoilers = parse(markdownStringBuilder); + int offset = 2; + + for (var entry : spoilers.entrySet()) { + int spoilerStart = entry.getKey() - offset; + int spoilerEnd = entry.getValue() - offset; + + CodeSpan[] codeSpans = markdownStringBuilder.getSpans(spoilerStart, spoilerEnd, CodeSpan.class); + CodeBlockSpan[] codeBlockSpans = markdownStringBuilder.getSpans(spoilerStart, spoilerEnd, CodeBlockSpan.class); + + if (codeSpans.length == 0 && codeBlockSpans.length == 0) { + markdownStringBuilder.delete(spoilerStart, spoilerStart + 2); + markdownStringBuilder.delete(spoilerEnd, spoilerEnd + 2); + SpoilerSpan spoilerSpan = new SpoilerSpan(textColor, backgroundColor); + markdownStringBuilder.setSpan(spoilerSpan, spoilerStart, spoilerEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + offset += 4; + } + s + for (CodeSpan codeSpan : codeSpans) { + int spanBeginning = markdownStringBuilder.getSpanStart(codeSpan); + int spanEnd = markdownStringBuilder.getSpanEnd(codeSpan); + if (spoilerStart < spanBeginning && spanEnd < spoilerEnd) { + markdownStringBuilder.delete(spoilerStart, spoilerStart + 2); + markdownStringBuilder.delete(spoilerEnd, spoilerEnd + 2); + SpoilerSpan spoilerSpan = new SpoilerSpan(textColor, backgroundColor); + markdownStringBuilder.setSpan(spoilerSpan, spoilerStart, spoilerEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + offset += 4; + } else { + break; + } + } + + for (CodeBlockSpan codeBlockSpan : codeBlockSpans) { + int spanBeginning = markdownStringBuilder.getSpanStart(codeBlockSpan); + int spanEnd = markdownStringBuilder.getSpanEnd(codeBlockSpan); + if (spoilerStart < spanBeginning && spanEnd < spoilerEnd) { + markdownStringBuilder.delete(spoilerStart, spoilerStart + 2); + markdownStringBuilder.delete(spoilerEnd, spoilerEnd + 2); + SpoilerSpan spoilerSpan = new SpoilerSpan(textColor, backgroundColor); + markdownStringBuilder.setSpan(spoilerSpan, spoilerStart, spoilerEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + offset += 4; + } else { + break; + } } - find = true; - markdownStringBuilder.delete(matcher.end() - 2, matcher.end()); - markdownStringBuilder.delete(matcher.start(), matcher.start() + 2); - SpoilerSpan spoilerSpan = new SpoilerSpan(textColor, backgroundColor); - markdownStringBuilder.setSpan(spoilerSpan, matcher.start(), matcher.end() - 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - start = matcher.end() - 4; } - /*Pattern escapedSpoilerOpenerPattern = Pattern.compile(">!"); - Matcher escapedSpoilerOpenerMatcher = escapedSpoilerOpenerPattern.matcher(markdownStringBuilder); - ArrayList matched = new ArrayList<>(); - while (escapedSpoilerOpenerMatcher.find()) { - matched.add(escapedSpoilerOpenerMatcher.start()); - find = true; + + textView.setText(markdownStringBuilder); + } + + // Very naive implementation, needs to be improved for efficiency and edge cases + // Don't allow more than one new line after every non-blank line + // Try not to care about recursing spoilers, we just want the outermost spoiler because + // spoiler revealing-hiding breaks with recursing spoilers + // Try not to set a spoiler span if it's inside a CodeSpan + private LinkedHashMap parse(SpannableStringBuilder markdown) { + final int MAX_NEW_LINE = 1; + var openSpoilerStack = new Stack(); + var closedSpoilerMap = new LinkedHashMap(); + int variable_max_depth = calculateBalance(0, markdown) + 1; + int new_lines = 0; + int depth = 0; + for (int i = 0; i < markdown.length(); i++) { + if (markdown.charAt(i) == '\u2000' || markdown.charAt(i) == '\t') { + continue; + } else if (markdown.charAt(i) == '>' && (i + 1) < markdown.length() && markdown.charAt(i + 1) == '!') { + openSpoilerStack.push(i + 1); + depth++; + } else if (openSpoilerStack.size() > 0 + && markdown.charAt(i) == '!' && (i + 1) < markdown.length() + && markdown.charAt(i + 1) == '<') { + var pos = i + 1; + for (int j = 0; j < depth; j++) { + if (!openSpoilerStack.isEmpty()) pos = openSpoilerStack.peek(); + if (pos + 1 <= i) { + if (!openSpoilerStack.isEmpty()) pos = openSpoilerStack.peek(); + break; + } else { + if (!openSpoilerStack.isEmpty()) pos = openSpoilerStack.pop(); + } + } + if (depth <= variable_max_depth && pos + 1 <= i) //Spoiler content cannot be zero or less length + { + openSpoilerStack.clear(); + closedSpoilerMap.put(pos + 1, i); + } + depth--; + } else if (markdown.charAt(i) == '\n') { + new_lines++; + if (openSpoilerStack.size() >= 1 && new_lines > MAX_NEW_LINE) { + openSpoilerStack.clear(); + new_lines = 0; + depth = 0; + variable_max_depth = calculateBalance(i, markdown) + 1; + } + } else { + new_lines = 0; + } + + if (openSpoilerStack.size() >= 32) // No + { + openSpoilerStack.clear(); + closedSpoilerMap.clear(); + continue; + } } - for (int i = matched.size() - 1; i >= 0; i--) { - markdownStringBuilder.replace(matched.get(i), matched.get(i) + 4, ">"); - }*/ - if (find) { - textView.setText(markdownStringBuilder); + return closedSpoilerMap; + } + + private int calculateBalance(int index, SpannableStringBuilder line) { + final int MAX_NEW_LINE = 1; + int new_lines = 0; + int opening = 0; + int closing = 0; + for (int i = index; i < line.length(); i++) { + if (line.charAt(i) == '\u0020' || line.charAt(i) == '\t') { + continue; + } else if (line.charAt(i) == '>' + && (i + 1) < line.length() + && line.charAt(i + 1) == '!') { + opening++; + } else if (line.charAt(i) == '!' && (i + 1) < line.length() + && line.charAt(i + 1) == '<') { + closing++; + } else if (line.charAt(i) == '\n') { + new_lines++; + if (new_lines > MAX_NEW_LINE) { + break; + } + } else { + new_lines = 0; + continue; + } } + return Math.abs(opening - closing); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerSpan.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerSpan.java index 5be3797c..2264449c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerSpan.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerSpan.java @@ -53,6 +53,7 @@ public class SpoilerSpan extends ClickableSpan { @Override public void updateDrawState(@NonNull TextPaint ds) { if (isShowing) { + ds.bgColor = backgroundColor & 0x0D000000; //Slightly darker background color for revealed spoiler super.updateDrawState(ds); } else { ds.bgColor = backgroundColor; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java index 2963a58f..f292088d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -65,7 +65,6 @@ public class Utils { .replaceAll("((?<=[\\s])|^)/[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com$0)") .replaceAll("((?<=[\\s])|^)[rRuU]/[\\w-]+/{0,1}", "[$0](https://www.reddit.com/$0)") .replaceAll("\\^{2,}", "^") - .replaceAll(">!(\\n?(?:.+?(?:\\n?.+?)?)\\n?)!<", ">!$1!<") // html entity remains escaped inside an inline block .replaceAll("(^|^ *|\\n *)#(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)##(?!($|\\s|#))", "$0 ") .replaceAll("(^|^ *|\\n *)###(?!($|\\s|#))", "$0 ") -- cgit v1.2.3 From d1096f1f7648b3e09d4bf3437121c37c96d966e4 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Thu, 25 Nov 2021 19:07:15 +0300 Subject: Fix typo --- .../docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java index 36068b9a..2fd243ac 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java @@ -69,7 +69,7 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin { markdownStringBuilder.setSpan(spoilerSpan, spoilerStart, spoilerEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); offset += 4; } - s + for (CodeSpan codeSpan : codeSpans) { int spanBeginning = markdownStringBuilder.getSpanStart(codeSpan); int spanEnd = markdownStringBuilder.getSpanEnd(codeSpan); -- cgit v1.2.3 From e481980480bc5666edd671a06a71078525824bac Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Thu, 25 Nov 2021 19:22:32 +0300 Subject: Check if spoiler was found before setting markdown --- .../infinityforreddit/markdown/SpoilerParserPlugin.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java index 2fd243ac..a83df76a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java @@ -14,6 +14,7 @@ import org.commonmark.node.HtmlInline; import org.commonmark.parser.Parser; import java.util.LinkedHashMap; +import java.util.Map; import java.util.Set; import java.util.Stack; @@ -55,7 +56,7 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin { LinkedHashMap spoilers = parse(markdownStringBuilder); int offset = 2; - for (var entry : spoilers.entrySet()) { + for (Map.Entry entry : spoilers.entrySet()) { int spoilerStart = entry.getKey() - offset; int spoilerEnd = entry.getValue() - offset; @@ -69,7 +70,7 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin { markdownStringBuilder.setSpan(spoilerSpan, spoilerStart, spoilerEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); offset += 4; } - + for (CodeSpan codeSpan : codeSpans) { int spanBeginning = markdownStringBuilder.getSpanStart(codeSpan); int spanEnd = markdownStringBuilder.getSpanEnd(codeSpan); @@ -98,8 +99,9 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin { } } } - - textView.setText(markdownStringBuilder); + if(offset > 2) { + textView.setText(markdownStringBuilder); + } } // Very naive implementation, needs to be improved for efficiency and edge cases -- cgit v1.2.3 From 8423a1807162268d3f4b47b9ca7f5d4280b255ce Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Thu, 25 Nov 2021 20:59:18 +0300 Subject: Return early if not spoiler --- .../infinityforreddit/markdown/SpoilerParserPlugin.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java index a83df76a..bd926f7c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java @@ -51,15 +51,24 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin { @Override public void afterSetText(@NonNull TextView textView) { textView.setHighlightColor(Color.TRANSPARENT); + + if(textView.getText().length() < 5) { + return; + } + SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText()); LinkedHashMap spoilers = parse(markdownStringBuilder); + if(spoilers.size() == 0) { + return; + } int offset = 2; for (Map.Entry entry : spoilers.entrySet()) { int spoilerStart = entry.getKey() - offset; int spoilerEnd = entry.getValue() - offset; + // Try not to set a spoiler span if it's inside a CodeSpan CodeSpan[] codeSpans = markdownStringBuilder.getSpans(spoilerStart, spoilerEnd, CodeSpan.class); CodeBlockSpan[] codeBlockSpans = markdownStringBuilder.getSpans(spoilerStart, spoilerEnd, CodeBlockSpan.class); @@ -108,7 +117,6 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin { // Don't allow more than one new line after every non-blank line // Try not to care about recursing spoilers, we just want the outermost spoiler because // spoiler revealing-hiding breaks with recursing spoilers - // Try not to set a spoiler span if it's inside a CodeSpan private LinkedHashMap parse(SpannableStringBuilder markdown) { final int MAX_NEW_LINE = 1; var openSpoilerStack = new Stack(); -- cgit v1.2.3 From 209a874f57f37fd7b32daa5df2c8951df0c940f4 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Thu, 25 Nov 2021 21:54:08 +0300 Subject: Minor tweaks --- .../infinityforreddit/markdown/SpoilerParserPlugin.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java index bd926f7c..1cca0cfe 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java @@ -83,7 +83,7 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin { for (CodeSpan codeSpan : codeSpans) { int spanBeginning = markdownStringBuilder.getSpanStart(codeSpan); int spanEnd = markdownStringBuilder.getSpanEnd(codeSpan); - if (spoilerStart < spanBeginning && spanEnd < spoilerEnd) { + if (spoilerStart + 2 <= spanBeginning && spanEnd <= spoilerEnd + 2) { markdownStringBuilder.delete(spoilerStart, spoilerStart + 2); markdownStringBuilder.delete(spoilerEnd, spoilerEnd + 2); SpoilerSpan spoilerSpan = new SpoilerSpan(textColor, backgroundColor); @@ -97,7 +97,7 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin { for (CodeBlockSpan codeBlockSpan : codeBlockSpans) { int spanBeginning = markdownStringBuilder.getSpanStart(codeBlockSpan); int spanEnd = markdownStringBuilder.getSpanEnd(codeBlockSpan); - if (spoilerStart < spanBeginning && spanEnd < spoilerEnd) { + if (spoilerStart + 2 <= spanBeginning && spanEnd <= spoilerEnd + 2) { markdownStringBuilder.delete(spoilerStart, spoilerStart + 2); markdownStringBuilder.delete(spoilerEnd, spoilerEnd + 2); SpoilerSpan spoilerSpan = new SpoilerSpan(textColor, backgroundColor); -- cgit v1.2.3 From 86d9761f09094920f47183bf2e524666513cc281 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Fri, 26 Nov 2021 14:49:12 +0300 Subject: Don't cancel all ImageLoader instances --- .../fragments/ViewRedditGalleryImageOrGifFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java index 05f0ab7a..494d6b44 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java @@ -427,7 +427,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { @Override public void onDestroyView() { super.onDestroyView(); - BigImageViewer.imageLoader().cancelAll(); + imageView.cancel(); SubsamplingScaleImageView subsamplingScaleImageView = imageView.getSSIV(); if (subsamplingScaleImageView != null) { subsamplingScaleImageView.recycle(); -- cgit v1.2.3