aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java50
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java6
3 files changed, 46 insertions, 30 deletions
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 0586b8ed..6a6b378c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewVideoActivity.java
@@ -363,29 +363,33 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
resumePosition = intent.getLongExtra(EXTRA_PROGRESS_SECONDS, -1);
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.VIDEO_PLAYER_AUTOMATIC_LANDSCAPE_ORIENTATION, false)) {
originalOrientation = resources.getConfiguration().orientation;
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
-
- if (android.provider.Settings.System.getInt(getContentResolver(),
- Settings.System.ACCELEROMETER_ROTATION, 0) == 1) {
- OrientationEventListener orientationEventListener = new OrientationEventListener(this) {
- @Override
- public void onOrientationChanged(int orientation) {
- int epsilon = 10;
- int leftLandscape = 90;
- int rightLandscape = 270;
- if(epsilonCheck(orientation, leftLandscape, epsilon) ||
- epsilonCheck(orientation, rightLandscape, epsilon)) {
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
- disable();
+ try {
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
+
+ if (android.provider.Settings.System.getInt(getContentResolver(),
+ Settings.System.ACCELEROMETER_ROTATION, 0) == 1) {
+ OrientationEventListener orientationEventListener = new OrientationEventListener(this) {
+ @Override
+ public void onOrientationChanged(int orientation) {
+ int epsilon = 10;
+ int leftLandscape = 90;
+ int rightLandscape = 270;
+ if(epsilonCheck(orientation, leftLandscape, epsilon) ||
+ epsilonCheck(orientation, rightLandscape, epsilon)) {
+ try {
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
+ disable();
+ } catch (Exception ignore) {}
+ }
}
- }
- private boolean epsilonCheck(int a, int b, int epsilon) {
- return a > b - epsilon && a < b + epsilon;
- }
- };
- orientationEventListener.enable();
- }
+ private boolean epsilonCheck(int a, int b, int epsilon) {
+ return a > b - epsilon && a < b + epsilon;
+ }
+ };
+ orientationEventListener.enable();
+ }
+ } catch (Exception ignore) {}
}
}
@@ -896,7 +900,9 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
wasPlaying = player.getPlayWhenReady();
player.setPlayWhenReady(false);
if (originalOrientation != null) {
- setRequestedOrientation(originalOrientation);
+ try {
+ setRequestedOrientation(originalOrientation);
+ } catch (Exception ignore) {}
}
}
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 08ef7769..a3680bd1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CopyTextBottomSheetFragment.java
@@ -12,6 +12,7 @@ import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@@ -20,6 +21,7 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
+import ml.docilealligator.infinityforreddit.activities.ViewRedditGalleryActivity;
import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
import ml.docilealligator.infinityforreddit.utils.Utils;
@@ -39,7 +41,8 @@ public class CopyTextBottomSheetFragment extends LandscapeExpandedRoundedBottomS
@BindView(R.id.copy_all_markdown_text_view_copy_text_bottom_sheet_fragment)
TextView copyAllMarkdownTextView;
- private BaseActivity activity;
+ private BaseActivity baseActivity;
+ private ViewRedditGalleryActivity viewRedditGalleryActivity;
private String markdownText;
public CopyTextBottomSheetFragment() {
@@ -73,7 +76,6 @@ public class CopyTextBottomSheetFragment extends LandscapeExpandedRoundedBottomS
}
if (markdownText != null) {
- //markdownText = markdownText.replaceAll("<sup>", "^").replaceAll("</sup>", "");
copyMarkdownTextView.setOnClickListener(view -> {
showCopyDialog(markdownText);
dismiss();
@@ -88,14 +90,17 @@ public class CopyTextBottomSheetFragment extends LandscapeExpandedRoundedBottomS
copyAllMarkdownTextView.setVisibility(View.GONE);
}
- if (activity.typeface != null) {
- Utils.setFontToAllTextViews(rootView, activity.typeface);
+ if (baseActivity != null && baseActivity.typeface != null) {
+ Utils.setFontToAllTextViews(rootView, baseActivity.typeface);
+ } else if (viewRedditGalleryActivity != null && viewRedditGalleryActivity.typeface != null) {
+ Utils.setFontToAllTextViews(rootView, viewRedditGalleryActivity.typeface);
}
return rootView;
}
private void showCopyDialog(String text) {
+ AppCompatActivity activity = baseActivity == null ? viewRedditGalleryActivity : baseActivity;
LayoutInflater inflater = activity.getLayoutInflater();
View layout = inflater.inflate(R.layout.copy_text_material_dialog, null);
TextView textView = layout.findViewById(R.id.text_view_copy_text_material_dialog);
@@ -109,6 +114,7 @@ public class CopyTextBottomSheetFragment extends LandscapeExpandedRoundedBottomS
}
private void copyText(String text) {
+ AppCompatActivity activity = baseActivity == null ? viewRedditGalleryActivity : baseActivity;
ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard != null) {
ClipData clip = ClipData.newPlainText("simple text", text);
@@ -122,6 +128,10 @@ public class CopyTextBottomSheetFragment extends LandscapeExpandedRoundedBottomS
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
- activity = (BaseActivity) context;
+ if (context instanceof BaseActivity) {
+ baseActivity = (BaseActivity) context;
+ } else {
+ viewRedditGalleryActivity = (ViewRedditGalleryActivity) context;
+ }
}
}
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 5200c535..90e439b0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SpoilerParserPlugin.java
@@ -96,8 +96,8 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin {
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);
+ markdownStringBuilder.delete(spoilerStart, spoilerStart + 2);
SpoilerSpan spoilerSpan = new SpoilerSpan(textColor, backgroundColor);
markdownStringBuilder.setSpan(spoilerSpan, spoilerStart, spoilerEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
offset += 4;
@@ -108,8 +108,8 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin {
int spanBeginning = markdownStringBuilder.getSpanStart(codeSpan);
int spanEnd = markdownStringBuilder.getSpanEnd(codeSpan);
if (spoilerStart + 2 <= spanBeginning && spanEnd <= spoilerEnd + 2) {
- markdownStringBuilder.delete(spoilerStart, spoilerStart + 2);
markdownStringBuilder.delete(spoilerEnd, spoilerEnd + 2);
+ markdownStringBuilder.delete(spoilerStart, spoilerStart + 2);
SpoilerSpan spoilerSpan = new SpoilerSpan(textColor, backgroundColor);
markdownStringBuilder.setSpan(spoilerSpan, spoilerStart, spoilerEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
offset += 4;
@@ -122,8 +122,8 @@ public class SpoilerParserPlugin extends AbstractMarkwonPlugin {
int spanBeginning = markdownStringBuilder.getSpanStart(codeBlockSpan);
int spanEnd = markdownStringBuilder.getSpanEnd(codeBlockSpan);
if (spoilerStart + 2 <= spanBeginning && spanEnd <= spoilerEnd + 2) {
- markdownStringBuilder.delete(spoilerStart, spoilerStart + 2);
markdownStringBuilder.delete(spoilerEnd, spoilerEnd + 2);
+ markdownStringBuilder.delete(spoilerStart, spoilerStart + 2);
SpoilerSpan spoilerSpan = new SpoilerSpan(textColor, backgroundColor);
markdownStringBuilder.setSpan(spoilerSpan, spoilerStart, spoilerEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
offset += 4;