Minor bugs fixed.

This commit is contained in:
Docile-Alligator 2022-02-19 12:16:31 +08:00
parent f508132f32
commit d76abc8c3e
3 changed files with 45 additions and 29 deletions

View File

@ -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);
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)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
disable();
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) {}
}
}

View File

@ -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;
}
}
}

View File

@ -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;