Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some deprecations #1203

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies {
implementation(libs.androidx.preference)
implementation(libs.androidx.recyclerview)
implementation(libs.androidx.swiperefreshlayout)
implementation(libs.androidx.window)

implementation(libs.google.flexbox)
implementation(libs.google.material)
Expand Down Expand Up @@ -183,3 +184,7 @@ tasks.register("Checkstyle", Checkstyle::class) {
maxWarnings = 0
configFile = rootProject.file("${project.rootDir}/config/checkstyle/checkstyle.xml")
}

tasks.withType<JavaCompile> {
options.compilerArgs.addAll(listOf("-Xlint:deprecation", "-Xlint:unchecked"))
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ androidx-fragment = "1.7.1"
androidx-preference = "1.2.1"
androidx-recyclerview = "1.3.2"
androidx-swiperefreshlayout = "1.1.0"
androidx-window = "1.3.0"

checkstyle = "10.17.0"
commons-lang = "3.14.0"
Expand Down Expand Up @@ -50,6 +51,7 @@ androidx-fragment = { module = "androidx.fragment:fragment", version.ref = "andr
androidx-preference = { module = "androidx.preference:preference", version.ref = "androidx-preference" }
androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version.ref = "androidx-recyclerview" }
androidx-swiperefreshlayout = { module = "androidx.swiperefreshlayout:swiperefreshlayout", version.ref = "androidx-swiperefreshlayout" }
androidx-window = { module = "androidx.window:window", version.ref = "androidx-window" }

commons-lang = { module = "org.apache.commons:commons-lang3", version.ref = "commons-lang" }
commons-text = { module = "org.apache.commons:commons-text", version.ref = "commons-text" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import android.widget.ScrollView;

import androidx.annotation.NonNull;
import androidx.core.content.IntentCompat;
import androidx.core.os.BundleCompat;

import org.quantumbadger.redreader.R;
import org.quantumbadger.redreader.account.RedditAccount;
Expand Down Expand Up @@ -64,15 +66,17 @@ && getIntent().getBooleanExtra("isSelfPost", false)) {
textEdit = (EditText)getLayoutInflater().inflate(R.layout.comment_edit, null);

if(getIntent() != null && getIntent().hasExtra("commentIdAndType")) {
//noinspection deprecation
commentIdAndType = getIntent().getParcelableExtra("commentIdAndType");
commentIdAndType = IntentCompat.getParcelableExtra(getIntent(),
"commentIdAndType",
RedditIdAndType.class);
textEdit.setText(getIntent().getStringExtra("commentText"));

} else if(savedInstanceState != null && savedInstanceState.containsKey(
"commentIdAndType")) {
textEdit.setText(savedInstanceState.getString("commentText"));
//noinspection deprecation
commentIdAndType = savedInstanceState.getParcelable("commentIdAndType");
commentIdAndType = BundleCompat.getParcelable(savedInstanceState,
"commentIdAndType",
RedditIdAndType.class);
}

final ScrollView sv = new ScrollView(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.core.content.IntentCompat;
import androidx.core.os.BundleCompat;

import org.quantumbadger.redreader.R;
import org.quantumbadger.redreader.account.RedditAccount;
Expand Down Expand Up @@ -119,15 +121,16 @@ protected void onCreate(final Bundle savedInstanceState) {
}

if(intent != null && intent.hasExtra(PARENT_ID_AND_TYPE_KEY)) {
//noinspection deprecation
parentIdAndType = Objects.requireNonNull(
intent.getParcelableExtra(PARENT_ID_AND_TYPE_KEY));
IntentCompat.getParcelableExtra(intent,
PARENT_ID_AND_TYPE_KEY,
RedditIdAndType.class));

} else if(savedInstanceState != null
&& savedInstanceState.containsKey(PARENT_ID_AND_TYPE_KEY)) {
//noinspection deprecation
parentIdAndType = Objects.requireNonNull(
savedInstanceState.getParcelable(PARENT_ID_AND_TYPE_KEY));
parentIdAndType = Objects.requireNonNull(BundleCompat.getParcelable(savedInstanceState,
PARENT_ID_AND_TYPE_KEY,
RedditIdAndType.class));

} else {
throw new RuntimeException("No parent ID in CommentReplyActivity");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import androidx.annotation.OptIn;
import androidx.annotation.StringRes;
import androidx.annotation.UiThread;
import androidx.core.content.IntentCompat;
import androidx.media3.common.MediaItem;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.exoplayer.source.MediaSource;
Expand Down Expand Up @@ -180,12 +181,14 @@ protected void onCreate(final Bundle savedInstanceState) {
return;
}

mPost = intent.getParcelableExtra("post");
mPost = IntentCompat.getParcelableExtra(intent, "post", RedditPost.class);

if(intent.hasExtra("albumUrl")) {
LinkHandler.getAlbumInfo(
this,
intent.getParcelableExtra("albumUrl"),
Objects.requireNonNull(IntentCompat.getParcelableExtra(
intent, "albumUrl",
UriString.class)),
new Priority(Constants.Priority.IMAGE_VIEW),
new GetAlbumInfoListener() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected void onCreate(final Bundle savedInstanceState) {

final View backgroundView = new View(this);

backgroundView.setBackgroundDrawable(new GradientDrawable(
backgroundView.setBackground(new GradientDrawable(
GradientDrawable.Orientation.LEFT_RIGHT,
new int[] {0xffd32f2f, 0xffb52626}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.webkit.ConsoleMessage;
import android.webkit.CookieManager;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
Expand All @@ -34,17 +36,23 @@
import org.quantumbadger.redreader.common.TorCommon;
import org.quantumbadger.redreader.reddit.api.RedditOAuth;

import java.util.Objects;

import info.guardianproject.netcipher.webkit.WebkitProxy;

public class OAuthLoginActivity extends ViewsBaseActivity {

private static final String OAUTH_HOST = "rr_oauth_redir";
private static final String REDREADER_SCHEME = "redreader";
private static final String HTTP_SCHEME = "http";

private WebView mWebView;

@Override
protected void onDestroy() {
super.onDestroy();
final CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
cookieManager.removeAllCookies(null);
}

@SuppressLint("SetJavaScriptEnabled")
Expand All @@ -57,20 +65,20 @@ public void onCreate(final Bundle savedInstanceState) {

mWebView = new WebView(this);

if(TorCommon.isTorEnabled()) {
if (TorCommon.isTorEnabled()) {
try {
final boolean result = WebkitProxy.setProxy(
RedReader.class.getCanonicalName(),
getApplicationContext(),
mWebView,
"127.0.0.1",
8118);
if(!result) {
if (!result) {
BugReportActivity.handleGlobalError(
this,
getResources().getString(R.string.error_tor_setting_failed));
}
} catch(final Exception e) {
} catch (final Exception e) {
BugReportActivity.handleGlobalError(this, e);
}
}
Expand All @@ -83,8 +91,9 @@ public void onCreate(final Bundle savedInstanceState) {
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
settings.setDomStorageEnabled(true);
settings.setSaveFormData(false);
settings.setSavePassword(false);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
settings.setSaveFormData(false);
}
settings.setDatabaseEnabled(false);
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
settings.setDisplayZoomControls(false);
Expand All @@ -100,18 +109,19 @@ public boolean onConsoleMessage(final ConsoleMessage consoleMessage) {
@Override
public boolean shouldOverrideUrlLoading(
final WebView view,
final String url) {

if(url.startsWith("http://rr_oauth_redir")
|| url.startsWith("redreader://rr_oauth_redir")) { // TODO constant
final WebResourceRequest request) {

final Uri url = request.getUrl();
if (Objects.equals(url.getHost(), OAUTH_HOST) &&
(Objects.equals(url.getScheme(), REDREADER_SCHEME) ||
Objects.equals(url.getScheme(), HTTP_SCHEME))) {
final Intent intent = new Intent();
intent.putExtra("url", url);
setResult(123, intent);
finish();

} else {
setTitle(Uri.parse(url).getHost());
setTitle(url.getHost());
return false;
}

Expand All @@ -129,7 +139,7 @@ protected void onPause() {

super.onPause();

if(mWebView != null) {
if (mWebView != null) {
mWebView.onPause();
mWebView.pauseTimers();
}
Expand All @@ -139,7 +149,7 @@ protected void onPause() {
protected void onResume() {
super.onResume();

if(mWebView != null) {
if (mWebView != null) {
mWebView.resumeTimers();
mWebView.onResume();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
package org.quantumbadger.redreader.activities;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Point;
import android.graphics.Rect;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.WindowManager;

import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.window.layout.WindowMetricsCalculator;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

Expand Down Expand Up @@ -489,14 +488,14 @@ public static void pruneMenu(
final boolean backButtonShown) {

//Figure out how many buttons can fit
final Point windowSize = new Point();
((WindowManager)activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()
.getSize(windowSize);

final Rect windowBounds = WindowMetricsCalculator.getOrCreate()
.computeCurrentWindowMetrics(activity).getBounds();

final int buttonSize = General.dpToPixels(activity, 48);
final int backButtonSize = General.dpToPixels(activity, 52);

int buttonSlotsRemaining = (windowSize.x - (backButtonShown
int buttonSlotsRemaining = (windowBounds.width() - (backButtonShown
? backButtonSize
: 0)) / buttonSize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import android.view.View;
import android.widget.Toast;

import androidx.core.content.IntentCompat;

import org.quantumbadger.redreader.R;
import org.quantumbadger.redreader.common.General;
import org.quantumbadger.redreader.common.LinkHandler;
Expand Down Expand Up @@ -55,8 +57,8 @@ public void onCreate(final Bundle savedInstanceState) {

final Intent intent = getIntent();

final UriString url = intent.getParcelableExtra("url");
mPost = intent.getParcelableExtra("post");
final UriString url = IntentCompat.getParcelableExtra(intent, "url", UriString.class);
mPost = IntentCompat.getParcelableExtra(intent, "post", RedditPost.class);

if(url == null) {
BugReportActivity.handleGlobalError(this, "No URL");
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/quantumbadger/redreader/common/General.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.quantumbadger.redreader.common

import android.app.Activity
import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
Expand Down Expand Up @@ -704,13 +705,18 @@ object General {

// http://stackoverflow.com/a/3419987/1526861
val intent = activity.intent
activity.overridePendingTransition(0, 0)
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
activity.finish()
activity.overridePendingTransition(0, 0)
activity.overridePendingTransitionWithNoAnimation()
activity.startActivity(intent)
activity.overridePendingTransitionWithNoAnimation()
}

@Suppress("DEPRECATION")
private fun Activity.overridePendingTransitionWithNoAnimation() {
overridePendingTransition(0, 0)
}

@JvmStatic
fun safeDismissDialog(dialog: Dialog) {
runOnUiThread {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ public void close() throws IOException {

if((extractor.getSampleFlags()
& MediaExtractor.SAMPLE_FLAG_SYNC) != 0) {
//noinspection deprecation
flags |= MediaCodec.BUFFER_FLAG_SYNC_FRAME;
flags |= MediaCodec.BUFFER_FLAG_KEY_FRAME;
}

if((extractor.getSampleFlags()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.core.os.BundleCompat;

import org.quantumbadger.redreader.R;
import org.quantumbadger.redreader.activities.BaseActivity;
import org.quantumbadger.redreader.reddit.kthings.RedditComment;
import org.quantumbadger.redreader.reddit.kthings.RedditFieldEdited;

import java.util.Objects;

public final class CommentPropertiesDialog extends PropertiesDialog {

public static CommentPropertiesDialog newInstance(final RedditComment comment) {
Expand All @@ -51,7 +54,10 @@ protected void prepare(
@NonNull final BaseActivity context,
@NonNull final LinearLayout items) {

final RedditComment comment = getArguments().getParcelable("comment");
final RedditComment comment = Objects.requireNonNull(
BundleCompat.getParcelable(requireArguments(),
"comment",
RedditComment.class));

items.addView(propView(context, "ID", comment.getName().getValue(), true));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.core.os.BundleCompat;

import org.quantumbadger.redreader.R;
import org.quantumbadger.redreader.activities.BaseActivity;
import org.quantumbadger.redreader.image.ImageInfo;

import java.util.Objects;

public final class ImageInfoDialog extends PropertiesDialog {

public static ImageInfoDialog newInstance(final ImageInfo info) {
Expand All @@ -50,7 +53,9 @@ protected void prepare(
@NonNull final BaseActivity context,
@NonNull final LinearLayout items) {

final ImageInfo info = getArguments().getParcelable("info");
final ImageInfo info = Objects.requireNonNull(BundleCompat.getParcelable(requireArguments(),
"info",
ImageInfo.class));

boolean first = true;

Expand Down
Loading