Skip to content
Merged
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 app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ android {
encoding 'utf-8'
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}

// Required and used only by groupie
androidExtensions {
experimental = true
Expand Down Expand Up @@ -184,6 +188,7 @@ dependencies {
implementation "androidx.recyclerview:recyclerview:1.1.0"
implementation "androidx.cardview:cardview:1.0.0"
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
implementation 'androidx.core:core-ktx:1.3.1'

implementation "androidx.lifecycle:lifecycle-livedata:${androidxLifecycleVersion}"
implementation "androidx.lifecycle:lifecycle-viewmodel:${androidxLifecycleVersion}"
Expand Down
50 changes: 16 additions & 34 deletions app/src/main/java/org/schabi/newpipe/App.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.schabi.newpipe;

import android.annotation.TargetApi;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
Expand Down Expand Up @@ -33,6 +32,7 @@
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.SocketException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -90,7 +90,7 @@ public void onCreate() {
Localization.init(getApplicationContext());

StateSaver.init(this);
initNotificationChannel();
initNotificationChannels();

ServiceHelper.initServices(this);

Expand Down Expand Up @@ -219,49 +219,31 @@ protected void initACRA() {
}
}

public void initNotificationChannel() {
private void initNotificationChannels() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
return;
}

final String id = getString(R.string.notification_channel_id);
final CharSequence name = getString(R.string.notification_channel_name);
final String description = getString(R.string.notification_channel_description);
String id = getString(R.string.notification_channel_id);
String name = getString(R.string.notification_channel_name);
String description = getString(R.string.notification_channel_description);

// Keep this below DEFAULT to avoid making noise on every notification update
final int importance = NotificationManager.IMPORTANCE_LOW;

final NotificationChannel mChannel = new NotificationChannel(id, name, importance);
mChannel.setDescription(description);
final NotificationChannel mainChannel = new NotificationChannel(id, name, importance);
mainChannel.setDescription(description);

final NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.createNotificationChannel(mChannel);
id = getString(R.string.app_update_notification_channel_id);
name = getString(R.string.app_update_notification_channel_name);
description = getString(R.string.app_update_notification_channel_description);

setUpUpdateNotificationChannel(importance);
}
final NotificationChannel appUpdateChannel = new NotificationChannel(id, name, importance);
appUpdateChannel.setDescription(description);

/**
* Set up notification channel for app update.
*
* @param importance
*/
@TargetApi(Build.VERSION_CODES.O)
private void setUpUpdateNotificationChannel(final int importance) {
final String appUpdateId
= getString(R.string.app_update_notification_channel_id);
final CharSequence appUpdateName
= getString(R.string.app_update_notification_channel_name);
final String appUpdateDescription
= getString(R.string.app_update_notification_channel_description);

final NotificationChannel appUpdateChannel
= new NotificationChannel(appUpdateId, appUpdateName, importance);
appUpdateChannel.setDescription(appUpdateDescription);

final NotificationManager appUpdateNotificationManager
= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
appUpdateNotificationManager.createNotificationChannel(appUpdateChannel);
final NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannels(Arrays.asList(mainChannel,
appUpdateChannel));
}

protected boolean isDisposedRxExceptionsReported() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.app.Application;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
Expand All @@ -11,11 +10,12 @@
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.AsyncTask;
import androidx.preference.PreferenceManager;
import android.util.Log;

import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;

import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
Expand Down Expand Up @@ -213,8 +213,8 @@ private void compareAppVersionAndShowNotification(final String versionName,
}

private boolean isConnected() {
final ConnectivityManager cm =
(ConnectivityManager) APP.getSystemService(Context.CONNECTIVITY_SERVICE);
final ConnectivityManager cm = ContextCompat.getSystemService(APP,
ConnectivityManager.class);
return cm.getActiveNetworkInfo() != null
&& cm.getActiveNetworkInfo().isConnected();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.core.text.HtmlCompat;
import androidx.preference.PreferenceManager;
import android.text.Editable;
import android.text.Html;
import android.text.TextUtils;
Expand All @@ -30,6 +28,9 @@
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.TooltipCompat;
import androidx.core.content.ContextCompat;
import androidx.core.text.HtmlCompat;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;

Expand All @@ -49,9 +50,9 @@
import org.schabi.newpipe.local.history.HistoryRecordManager;
import org.schabi.newpipe.report.ErrorActivity;
import org.schabi.newpipe.report.UserAction;
import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.AnimationUtils;
import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.ExceptionUtils;
import org.schabi.newpipe.util.ExtractorHelper;
import org.schabi.newpipe.util.NavigationHelper;
Expand Down Expand Up @@ -639,8 +640,8 @@ private void showKeyboardSearch() {
}

if (searchEditText.requestFocus()) {
final InputMethodManager imm = (InputMethodManager) activity.getSystemService(
Context.INPUT_METHOD_SERVICE);
final InputMethodManager imm = ContextCompat.getSystemService(activity,
InputMethodManager.class);
imm.showSoftInput(searchEditText, InputMethodManager.SHOW_FORCED);
}
}
Expand All @@ -653,8 +654,8 @@ private void hideKeyboardSearch() {
return;
}

final InputMethodManager imm = (InputMethodManager) activity
.getSystemService(Context.INPUT_METHOD_SERVICE);
final InputMethodManager imm = ContextCompat.getSystemService(activity,
InputMethodManager.class);
imm.hideSoftInputFromWindow(searchEditText.getWindowToken(),
InputMethodManager.RESULT_UNCHANGED_SHOWN);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.schabi.newpipe.local.subscription.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.os.Parcelable
import android.text.Editable
Expand All @@ -12,6 +11,7 @@ import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import androidx.core.content.getSystemService
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
Expand Down Expand Up @@ -459,7 +459,7 @@ class FeedGroupDialog : DialogFragment(), BackPressable {
}

private val inputMethodManager by lazy {
requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
requireActivity().getSystemService<InputMethodManager>()!!
}

private fun showKeyboardSearch() {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/org/schabi/newpipe/player/MainPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import android.view.ViewGroup;
import android.view.WindowManager;

import androidx.core.content.ContextCompat;

import org.schabi.newpipe.R;
import org.schabi.newpipe.util.ThemeHelper;

Expand Down Expand Up @@ -91,7 +93,7 @@ public void onCreate() {
Log.d(TAG, "onCreate() called");
}
assureCorrectAppLanguage(this);
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
windowManager = ContextCompat.getSystemService(this, WindowManager.class);

ThemeHelper.setTheme(this);
createView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.content.ContextCompat;
import androidx.core.view.DisplayCutoutCompat;
import androidx.core.view.ViewCompat;
import androidx.preference.PreferenceManager;
Expand Down Expand Up @@ -105,7 +106,6 @@

import java.util.List;

import static android.content.Context.WINDOW_SERVICE;
import static org.schabi.newpipe.player.MainPlayer.ACTION_CLOSE;
import static org.schabi.newpipe.player.MainPlayer.ACTION_FAST_FORWARD;
import static org.schabi.newpipe.player.MainPlayer.ACTION_FAST_REWIND;
Expand Down Expand Up @@ -269,7 +269,7 @@ public void handleIntent(final Intent intent) {
super("MainPlayer" + TAG, service);
this.service = service;
this.shouldUpdateOnProgress = true;
this.windowManager = (WindowManager) service.getSystemService(WINDOW_SERVICE);
this.windowManager = ContextCompat.getSystemService(service, WindowManager.class);
this.defaultPreferences = PreferenceManager.getDefaultSharedPreferences(service);
this.resolver = new AudioPlaybackResolver(context, dataSource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.analytics.AnalyticsListener;
Expand Down Expand Up @@ -39,7 +40,7 @@ public AudioReactor(@NonNull final Context context,
@NonNull final SimpleExoPlayer player) {
this.player = player;
this.context = context;
this.audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
this.audioManager = ContextCompat.getSystemService(context, AudioManager.class);
player.addAnalyticsListener(this);

if (SHOULD_BUILD_FOCUS_REQUEST) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import android.os.PowerManager;
import android.util.Log;

import static android.content.Context.POWER_SERVICE;
import static android.content.Context.WIFI_SERVICE;
import androidx.core.content.ContextCompat;

public class LockManager {
private final String TAG = "LockManager@" + hashCode();
Expand All @@ -18,10 +17,9 @@ public class LockManager {
private WifiManager.WifiLock wifiLock;

public LockManager(final Context context) {
powerManager = ((PowerManager) context.getApplicationContext()
.getSystemService(POWER_SERVICE));
wifiManager = ((WifiManager) context.getApplicationContext()
.getSystemService(WIFI_SERVICE));
powerManager = ContextCompat.getSystemService(context.getApplicationContext(),
PowerManager.class);
wifiManager = ContextCompat.getSystemService(context, WifiManager.class);
}

public void acquireWifiAndCpu() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;

import com.google.android.exoplayer2.SeekParameters;
Expand Down Expand Up @@ -312,8 +313,8 @@ public static int getTossFlingVelocity(@NonNull final Context context) {

@NonNull
public static CaptionStyleCompat getCaptionStyle(@NonNull final Context context) {
final CaptioningManager captioningManager = (CaptioningManager)
context.getSystemService(Context.CAPTIONING_SERVICE);
final CaptioningManager captioningManager = ContextCompat.getSystemService(context,
CaptioningManager.class);
if (captioningManager == null || !captioningManager.isEnabled()) {
return CaptionStyleCompat.DEFAULT;
}
Expand All @@ -336,8 +337,8 @@ public static CaptionStyleCompat getCaptionStyle(@NonNull final Context context)
* @return caption scaling
*/
public static float getCaptionScale(@NonNull final Context context) {
final CaptioningManager captioningManager
= (CaptioningManager) context.getSystemService(Context.CAPTIONING_SERVICE);
final CaptioningManager captioningManager = ContextCompat.getSystemService(context,
CaptioningManager.class);
if (captioningManager == null || !captioningManager.isEnabled()) {
return 1.0f;
}
Expand Down
10 changes: 4 additions & 6 deletions app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
import android.view.KeyEvent;

import androidx.annotation.NonNull;
import org.schabi.newpipe.App;
import androidx.core.content.ContextCompat;

import static android.content.Context.BATTERY_SERVICE;
import static android.content.Context.UI_MODE_SERVICE;
import org.schabi.newpipe.App;

public final class DeviceUtils {

Expand All @@ -30,15 +29,14 @@ public static boolean isTv(final Context context) {
final PackageManager pm = App.getApp().getPackageManager();

// from doc: https://developer.android.com/training/tv/start/hardware.html#runtime-check
boolean isTv = ((UiModeManager) context.getSystemService(UI_MODE_SERVICE))
boolean isTv = ContextCompat.getSystemService(context, UiModeManager.class)
.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION
|| pm.hasSystemFeature(AMAZON_FEATURE_FIRE_TV)
|| pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION);

// from https://stackoverflow.com/a/58932366
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
final boolean isBatteryAbsent
= ((BatteryManager) context.getSystemService(BATTERY_SERVICE))
final boolean isBatteryAbsent = context.getSystemService(BatteryManager.class)
.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY) == 0;
isTv = isTv || (isBatteryAbsent
&& !pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/org/schabi/newpipe/util/ListHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;

import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;

import androidx.annotation.Nullable;
Expand Down Expand Up @@ -543,7 +545,7 @@ private static String getResolutionLimit(final Context context) {
*/
public static boolean isMeteredNetwork(final Context context) {
final ConnectivityManager manager
= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
= ContextCompat.getSystemService(context, ConnectivityManager.class);
if (manager == null || manager.getActiveNetworkInfo() == null) {
return false;
}
Expand Down
Loading