Skip to content

Commit 66beedc

Browse files
author
Yevhen Babiichuk (DustDFG)
committed
Utilize var syntax for some local variables in some java files
1 parent 1fb2b4a commit 66beedc

78 files changed

Lines changed: 203 additions & 255 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/main/java/org/schabi/newpipe/App.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import android.app.Application;
44
import android.content.Context;
5-
import android.content.SharedPreferences;
65
import android.util.Log;
76

87
import androidx.annotation.NonNull;
@@ -121,7 +120,7 @@ public void onCreate() {
121120
ServiceHelper.initServices(this);
122121

123122
// Initialize image loader
124-
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
123+
final var prefs = PreferenceManager.getDefaultSharedPreferences(this);
125124
PicassoHelper.init(this);
126125
ImageStrategy.setPreferredImageQuality(PreferredImageQuality.fromPreferenceKey(this,
127126
prefs.getString(getString(R.string.image_quality_key),
@@ -147,8 +146,7 @@ protected Downloader getDownloader() {
147146
}
148147

149148
protected void setCookiesToDownloader(final DownloaderImpl downloader) {
150-
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(
151-
getApplicationContext());
149+
final var prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
152150
final String key = getApplicationContext().getString(R.string.recaptcha_cookies_key);
153151
downloader.setCookie(ReCaptchaActivity.RECAPTCHA_COOKIES_KEY, prefs.getString(key, null));
154152
downloader.updateYoutubeRestrictedModeCookies(getApplicationContext());
@@ -178,7 +176,7 @@ public void accept(@NonNull final Throwable throwable) {
178176
errors = List.of(actualThrowable);
179177
}
180178

181-
for (final Throwable error : errors) {
179+
for (final var error : errors) {
182180
if (isThrowableIgnored(error)) {
183181
return;
184182
}

app/src/main/java/org/schabi/newpipe/ExitActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
public class ExitActivity extends Activity {
2929

3030
public static void exitAndRemoveFromRecentApps(final Activity activity) {
31-
final Intent intent = new Intent(activity, ExitActivity.class);
31+
final var intent = new Intent(activity, ExitActivity.class);
3232

3333
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
3434
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS

app/src/main/java/org/schabi/newpipe/MainActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,14 +451,14 @@ private void showServices() {
451451
}
452452

453453
private void enhancePeertubeMenu(final MenuItem menuItem) {
454-
final PeertubeInstance currentInstance = PeertubeHelper.getCurrentInstance();
454+
final var currentInstance = PeertubeHelper.getCurrentInstance();
455455
menuItem.setTitle(currentInstance.getName());
456456
final Spinner spinner = InstanceSpinnerLayoutBinding.inflate(LayoutInflater.from(this))
457457
.getRoot();
458458
final List<PeertubeInstance> instances = PeertubeHelper.getInstanceList(this);
459459
final List<String> items = new ArrayList<>();
460460
int defaultSelect = 0;
461-
for (final PeertubeInstance instance : instances) {
461+
for (final var instance : instances) {
462462
items.add(instance.getName());
463463
if (instance.getUrl().equals(currentInstance.getUrl())) {
464464
defaultSelect = items.size() - 1;
@@ -895,7 +895,7 @@ public void onReceive(final Context context, final Intent intent) {
895895
}
896896
}
897897
};
898-
final IntentFilter intentFilter = new IntentFilter();
898+
final var intentFilter = new IntentFilter();
899899
intentFilter.addAction(VideoDetailFragment.ACTION_PLAYER_STARTED);
900900
ContextCompat.registerReceiver(this, broadcastReceiver, intentFilter,
901901
ContextCompat.RECEIVER_EXPORTED);

app/src/main/java/org/schabi/newpipe/PanicResponderActivity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import android.annotation.SuppressLint;
44
import android.app.Activity;
5-
import android.content.Intent;
65
import android.os.Bundle;
76

87
/*
@@ -30,7 +29,7 @@ public class PanicResponderActivity extends Activity {
3029
@Override
3130
protected void onCreate(final Bundle savedInstanceState) {
3231
super.onCreate(savedInstanceState);
33-
final Intent intent = getIntent();
32+
final var intent = getIntent();
3433
if (intent != null && PANIC_TRIGGER_ACTION.equals(intent.getAction())) {
3534
// TODO: Explicitly clear the search results
3635
// once they are restored when the app restarts

app/src/main/java/org/schabi/newpipe/QueueItemMenuUtil.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ public static void openPopupMenu(final PlayQueue playQueue,
3030
final boolean hideDetails,
3131
final FragmentManager fragmentManager,
3232
final Context context) {
33-
final ContextThemeWrapper themeWrapper =
34-
new ContextThemeWrapper(context, R.style.DarkPopupMenu);
35-
36-
final PopupMenu popupMenu = new PopupMenu(themeWrapper, view);
33+
final var themeWrapper = new ContextThemeWrapper(context, R.style.DarkPopupMenu);
34+
final var popupMenu = new PopupMenu(themeWrapper, view);
3735
popupMenu.inflate(R.menu.menu_play_queue_item);
3836

3937
if (hideDetails) {

app/src/main/java/org/schabi/newpipe/RouterActivity.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import android.content.Context;
99
import android.content.DialogInterface;
1010
import android.content.Intent;
11-
import android.content.SharedPreferences;
1211
import android.content.pm.PackageManager;
1312
import android.os.Build;
1413
import android.os.Bundle;
@@ -263,7 +262,7 @@ private static void handleError(final Context context, final ErrorInfo errorInfo
263262
if (errorInfo.getRecaptchaUrl() != null) {
264263
Toast.makeText(context, R.string.recaptcha_request_toast, Toast.LENGTH_LONG).show();
265264
// Starting ReCaptcha Challenge Activity
266-
final Intent intent = new Intent(context, ReCaptchaActivity.class);
265+
final var intent = new Intent(context, ReCaptchaActivity.class);
267266
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
268267
intent.putExtra(ReCaptchaActivity.RECAPTCHA_URL_EXTRA, errorInfo.getRecaptchaUrl());
269268
context.startActivity(intent);
@@ -281,7 +280,7 @@ private static void handleError(final Context context, final ErrorInfo errorInfo
281280
}
282281

283282
protected void showUnsupportedUrlDialog(final String url) {
284-
final Context context = getThemeWrapperContext();
283+
final var context = getThemeWrapperContext();
285284
new AlertDialog.Builder(context)
286285
.setTitle(R.string.unsupported_url)
287286
.setMessage(R.string.unsupported_url_dialog_message)
@@ -296,10 +295,9 @@ protected void showUnsupportedUrlDialog(final String url) {
296295
}
297296

298297
protected void onSuccess() {
299-
final SharedPreferences preferences = PreferenceManager
300-
.getDefaultSharedPreferences(this);
298+
final var preferences = PreferenceManager.getDefaultSharedPreferences(this);
301299

302-
final ChoiceAvailabilityChecker choiceChecker = new ChoiceAvailabilityChecker(
300+
final var choiceChecker = new ChoiceAvailabilityChecker(
303301
getChoicesForService(currentService, currentLinkType),
304302
preferences.getString(getString(R.string.preferred_open_action_key),
305303
getString(R.string.preferred_open_action_default)));
@@ -411,7 +409,7 @@ public boolean isAvailableAndSelected(@StringRes final int wantedKey) {
411409
}
412410

413411
private void showDialog(final List<AdapterChoiceItem> choices) {
414-
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
412+
final var preferences = PreferenceManager.getDefaultSharedPreferences(this);
415413

416414
final Context themeWrapperContext = getThemeWrapperContext();
417415
final LayoutInflater layoutInflater = LayoutInflater.from(themeWrapperContext);
@@ -564,8 +562,7 @@ private List<AdapterChoiceItem> getChoicesForService(final StreamingService serv
564562
} else {
565563
// LinkType.NONE is never present because it's filtered out before
566564
// channels and playlist can be played as they contain a list of videos
567-
final SharedPreferences preferences = PreferenceManager
568-
.getDefaultSharedPreferences(this);
565+
final var preferences = PreferenceManager.getDefaultSharedPreferences(this);
569566
final boolean isExtVideoEnabled = preferences.getBoolean(
570567
getString(R.string.use_external_video_player_key), false);
571568
final boolean isExtAudioEnabled = preferences.getBoolean(
@@ -602,7 +599,7 @@ private void setDialogButtonsState(final AlertDialog dialog, final boolean state
602599
private void handleText() {
603600
final String searchString = getIntent().getStringExtra(Intent.EXTRA_TEXT);
604601
final int serviceId = getIntent().getIntExtra(Constants.KEY_SERVICE_ID, 0);
605-
final Intent intent = new Intent(getThemeWrapperContext(), MainActivity.class);
602+
final var intent = new Intent(getThemeWrapperContext(), MainActivity.class);
606603
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
607604
startActivity(intent);
608605
NavigationHelper.openSearch(getThemeWrapperContext(), serviceId, searchString);
@@ -657,8 +654,8 @@ private void handleChoice(final String selectedChoiceKey) {
657654
return;
658655
}
659656

660-
final Intent intent = new Intent(this, FetcherService.class);
661-
final Choice choice = new Choice(currentService.getServiceId(), currentLinkType,
657+
final var intent = new Intent(this, FetcherService.class);
658+
final var choice = new Choice(currentService.getServiceId(), currentLinkType,
662659
currentUrl, selectedChoiceKey);
663660
intent.putExtra(FetcherService.KEY_CHOICE, choice);
664661
startService(intent);
@@ -772,7 +769,7 @@ public void onResume(@NonNull final LifecycleOwner owner) {
772769
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q
773770
&& !context.isChangingConfigurations()) {
774771
// try to bring the activity back to front if minimised
775-
final Intent i = new Intent(context, RouterActivity.class);
772+
final var i = new Intent(context, RouterActivity.class);
776773
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
777774
startActivity(i);
778775
}
@@ -946,7 +943,7 @@ protected void onHandleIntent(@Nullable final Intent intent) {
946943
if (!(serializable instanceof Choice)) {
947944
return;
948945
}
949-
final Choice playerChoice = (Choice) serializable;
946+
final var playerChoice = (Choice) serializable;
950947
handleChoice(playerChoice);
951948
}
952949

@@ -992,8 +989,7 @@ public Consumer<Info> getResultHandler(final Choice choice) {
992989
final String backgroundPlayerKey = getString(R.string.background_player_key);
993990
final String popupPlayerKey = getString(R.string.popup_player_key);
994991

995-
final SharedPreferences preferences = PreferenceManager
996-
.getDefaultSharedPreferences(this);
992+
final var preferences = PreferenceManager.getDefaultSharedPreferences(this);
997993
final boolean isExtVideoEnabled = preferences.getBoolean(
998994
getString(R.string.use_external_video_player_key), false);
999995
final boolean isExtAudioEnabled = preferences.getBoolean(

app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.content.Intent;
44
import android.os.Bundle;
55
import android.view.Menu;
6-
import android.view.MenuInflater;
76
import android.view.MenuItem;
87
import android.view.ViewTreeObserver;
98

@@ -27,7 +26,7 @@ public class DownloadActivity extends AppCompatActivity {
2726
@Override
2827
protected void onCreate(final Bundle savedInstanceState) {
2928
// Service
30-
final Intent i = new Intent();
29+
final var i = new Intent();
3130
i.setClass(this, DownloadManagerService.class);
3231
startService(i);
3332

@@ -74,7 +73,7 @@ private void updateFragments() {
7473
@Override
7574
public boolean onCreateOptionsMenu(final Menu menu) {
7675
super.onCreateOptionsMenu(menu);
77-
final MenuInflater inflater = getMenuInflater();
76+
final var inflater = getMenuInflater();
7877

7978
inflater.inflate(R.menu.download_menu, menu);
8079

app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public void onCreate(@Nullable final Bundle savedInstanceState) {
219219
this.subtitleStreamsAdapter = new StreamItemAdapter<>(wrappedSubtitleStreams);
220220
updateSecondaryStreams();
221221

222-
final Intent intent = new Intent(context, DownloadManagerService.class);
222+
final var intent = new Intent(context, DownloadManagerService.class);
223223
context.startService(intent);
224224

225225
context.bindService(intent, new ServiceConnection() {
@@ -248,16 +248,16 @@ public void onServiceDisconnected(final ComponentName name) {
248248
* Update the displayed video streams based on the selected audio track.
249249
*/
250250
private void updateSecondaryStreams() {
251-
final StreamInfoWrapper<AudioStream> audioStreams = getWrappedAudioStreams();
251+
final var audioStreams = getWrappedAudioStreams();
252252
final var secondaryStreams = new SparseArrayCompat<SecondaryStreamHelper<AudioStream>>(4);
253-
final List<VideoStream> videoStreams = wrappedVideoStreams.getStreamsList();
253+
final var videoStreams = wrappedVideoStreams.getStreamsList();
254254
wrappedVideoStreams.resetInfo();
255255

256256
for (int i = 0; i < videoStreams.size(); i++) {
257257
if (!videoStreams.get(i).isVideoOnly()) {
258258
continue;
259259
}
260-
final AudioStream audioStream = SecondaryStreamHelper.getAudioStreamFor(
260+
final var audioStream = SecondaryStreamHelper.getAudioStreamFor(
261261
context, audioStreams.getStreamsList(), videoStreams.get(i));
262262

263263
if (audioStream != null) {
@@ -717,7 +717,7 @@ private int getSubtitleIndexBy(@NonNull final List<SubtitlesStream> streams) {
717717

718718
int candidate = 0;
719719
for (int i = 0; i < streams.size(); i++) {
720-
final Locale streamLocale = streams.get(i).getLocale();
720+
final var streamLocale = streams.get(i).getLocale();
721721

722722
final boolean languageEquals = streamLocale.getLanguage() != null
723723
&& preferredLocalization.getLanguageCode() != null
@@ -860,8 +860,7 @@ private void prepareSelectedDownload() {
860860
Toast.makeText(context, getString(R.
861861
string.error_insufficient_storage), Toast.LENGTH_LONG).show();
862862
// move the user to storage setting tab
863-
final Intent storageSettingsIntent = new Intent(Settings.
864-
ACTION_INTERNAL_STORAGE_SETTINGS);
863+
final var storageSettingsIntent = new Intent(Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
865864
if (storageSettingsIntent.resolveActivity(context.getPackageManager())
866865
!= null) {
867866
startActivity(storageSettingsIntent);

app/src/main/java/org/schabi/newpipe/error/ErrorActivity.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import android.view.MenuInflater;
1111
import android.view.MenuItem;
1212

13-
import androidx.appcompat.app.ActionBar;
1413
import androidx.appcompat.app.AlertDialog;
1514
import androidx.appcompat.app.AppCompatActivity;
1615
import androidx.core.content.IntentCompat;
@@ -85,11 +84,11 @@ protected void onCreate(final Bundle savedInstanceState) {
8584
activityErrorBinding = ActivityErrorBinding.inflate(getLayoutInflater());
8685
setContentView(activityErrorBinding.getRoot());
8786

88-
final Intent intent = getIntent();
87+
final var intent = getIntent();
8988

9089
setSupportActionBar(activityErrorBinding.toolbarLayout.toolbar);
9190

92-
final ActionBar actionBar = getSupportActionBar();
91+
final var actionBar = getSupportActionBar();
9392
if (actionBar != null) {
9493
actionBar.setDisplayHomeAsUpEnabled(true);
9594
actionBar.setTitle(R.string.error_report_title);
@@ -157,7 +156,7 @@ private void openPrivacyPolicyDialog(final Context context, final String action)
157156
context.getString(R.string.privacy_policy_url)))
158157
.setPositiveButton(R.string.accept, (dialog, which) -> {
159158
if (action.equals("EMAIL")) { // send on email
160-
final Intent i = new Intent(Intent.ACTION_SENDTO)
159+
final var i = new Intent(Intent.ACTION_SENDTO)
161160
.setData(Uri.parse("mailto:")) // only email apps should handle this
162161
.putExtra(Intent.EXTRA_EMAIL, new String[]{ERROR_EMAIL_ADDRESS})
163162
.putExtra(Intent.EXTRA_SUBJECT, ERROR_EMAIL_SUBJECT

app/src/main/java/org/schabi/newpipe/error/ReCaptchaActivity.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import android.annotation.SuppressLint;
44
import android.content.Intent;
5-
import android.content.SharedPreferences;
65
import android.os.Bundle;
76
import android.util.Log;
87
import android.view.Menu;
@@ -148,7 +147,7 @@ private void saveCookiesAndFinish() {
148147

149148
if (!foundCookies.isEmpty()) {
150149
// save cookies to preferences
151-
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(
150+
final var prefs = PreferenceManager.getDefaultSharedPreferences(
152151
getApplicationContext());
153152
final String key = getApplicationContext().getString(R.string.recaptcha_cookies_key);
154153
prefs.edit().putString(key, foundCookies).apply();
@@ -161,7 +160,7 @@ private void saveCookiesAndFinish() {
161160
// Navigate to blank page (unloads youtube to prevent background playback)
162161
recaptchaBinding.reCaptchaWebView.loadUrl("about:blank");
163162

164-
final Intent intent = new Intent(this, org.schabi.newpipe.MainActivity.class);
163+
final var intent = new Intent(this, org.schabi.newpipe.MainActivity.class);
165164
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
166165
NavUtils.navigateUpTo(this, intent);
167166
}

0 commit comments

Comments
 (0)