Skip to content

Commit

Permalink
Annotate some NonNulls, some lint cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
TacoTheDank committed Mar 18, 2022
1 parent 102204e commit 9cb781b
Show file tree
Hide file tree
Showing 26 changed files with 57 additions and 58 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/org/schabi/newpipe/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private void addDrawerMenuForCurrentService() throws ExtractionException {
drawerLayoutBinding.navigation.getMenu()
.add(R.id.menu_tabs_group, kioskId, 0, KioskTranslator
.getTranslatedKioskName(ks, this))
.setIcon(KioskTranslator.getKioskIcon(ks, this));
.setIcon(KioskTranslator.getKioskIcon(ks));
kioskId++;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.schabi.newpipe.fragments;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
Expand All @@ -10,7 +11,7 @@
*/
public abstract class OnScrollBelowItemsListener extends RecyclerView.OnScrollListener {
@Override
public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) {
public void onScrolled(@NonNull final RecyclerView recyclerView, final int dx, final int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy > 0) {
int pastVisibleItems = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.schabi.newpipe.fragments.detail;

import androidx.annotation.NonNull;

import org.schabi.newpipe.player.playqueue.PlayQueue;

import java.io.Serializable;
Expand Down Expand Up @@ -46,6 +48,7 @@ public PlayQueue getPlayQueue() {
return playQueue;
}

@NonNull
@Override
public String toString() {
return getServiceId() + ":" + getUrl() + " > " + getTitle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ protected void useInitialItemListLoadScrollListener() {
itemsList.clearOnScrollListeners();
itemsList.addOnScrollListener(new DefaultItemListOnScrolledDownListener() {
@Override
public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) {
public void onScrolled(@NonNull final RecyclerView recyclerView,
final int dx, final int dy) {
super.onScrolled(recyclerView, dx, dy);

if (dy != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.schabi.newpipe.R;
Expand Down Expand Up @@ -34,8 +35,10 @@ public void setListener(final OnSuggestionItemSelected listener) {
this.listener = listener;
}

@NonNull
@Override
public SuggestionItemHolder onCreateViewHolder(final ViewGroup parent, final int viewType) {
public SuggestionItemHolder onCreateViewHolder(@NonNull final ViewGroup parent,
final int viewType) {
return new SuggestionItemHolder(LayoutInflater.from(context)
.inflate(R.layout.item_search_suggestion, parent, false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,10 @@ public Builder addStartHereEntries() {
}

/**
* Adds {@link StreamDialogDefaultEntry.MARK_AS_WATCHED} if the watch history is enabled
* Adds {@link StreamDialogDefaultEntry#MARK_AS_WATCHED} if the watch history is enabled
* and the stream is not a livestream.
* @return the current {@link Builder} instance
*/
public Builder addMarkAsWatchedEntryIfNeeded() {
public void addMarkAsWatchedEntryIfNeeded() {
final boolean isWatchHistoryEnabled = PreferenceManager
.getDefaultSharedPreferences(context)
.getBoolean(context.getString(R.string.enable_watch_history_key), false);
Expand All @@ -290,18 +289,15 @@ public Builder addMarkAsWatchedEntryIfNeeded() {
&& infoItem.getStreamType() != StreamType.AUDIO_LIVE_STREAM) {
addEntry(StreamDialogDefaultEntry.MARK_AS_WATCHED);
}
return this;
}

/**
* Adds the {@link StreamDialogDefaultEntry.PLAY_WITH_KODI} entry if it is needed.
* @return the current {@link Builder} instance
* Adds the {@link StreamDialogDefaultEntry#PLAY_WITH_KODI} entry if it is needed.
*/
public Builder addPlayWithKodiEntryIfNeeded() {
public void addPlayWithKodiEntryIfNeeded() {
if (KoreUtils.shouldShowPlayWithKodi(context, infoItem.getServiceId())) {
addEntry(StreamDialogDefaultEntry.PLAY_WITH_KODI);
}
return this;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void readFrom(@NonNull final Queue<Object> savedObjects) {
}

@Override
public void onSaveInstanceState(final Bundle outState) {
public void onSaveInstanceState(@NonNull final Bundle outState) {
super.onSaveInstanceState(outState);
if (getActivity() != null) {
savedState = StateSaver.tryToSave(getActivity().isChangingConfigurations(),
Expand Down
14 changes: 5 additions & 9 deletions app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.xwray.groupie.GroupieAdapter
import com.xwray.groupie.Item
import com.xwray.groupie.OnAsyncUpdateListener
import com.xwray.groupie.OnItemClickListener
import com.xwray.groupie.OnItemLongClickListener
import icepick.State
Expand Down Expand Up @@ -139,7 +138,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
val factory = FeedViewModel.Factory(requireContext(), groupId)
viewModel = ViewModelProvider(this, factory).get(FeedViewModel::class.java)
showPlayedItems = viewModel.getShowPlayedItemsFromPreferences()
viewModel.stateLiveData.observe(viewLifecycleOwner, { it?.let(::handleResult) })
viewModel.stateLiveData.observe(viewLifecycleOwner) { it?.let(::handleResult) }

groupAdapter = GroupieAdapter().apply {
setOnItemClickListener(listenerStreamItem)
Expand Down Expand Up @@ -393,14 +392,11 @@ class FeedFragment : BaseStateFragment<FeedState>() {
// This need to be saved in a variable as the update occurs async
val oldOldestSubscriptionUpdate = oldestSubscriptionUpdate

groupAdapter.updateAsync(
loadedState.items, false,
OnAsyncUpdateListener {
oldOldestSubscriptionUpdate?.run {
highlightNewItemsAfter(oldOldestSubscriptionUpdate)
}
groupAdapter.updateAsync(loadedState.items, false) {
oldOldestSubscriptionUpdate?.run {
highlightNewItemsAfter(oldOldestSubscriptionUpdate)
}
)
}

listState?.run {
feedBinding.itemsList.layoutManager?.onRestoreInstanceState(listState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class FeedViewModel(
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.io())
.map { (event, showPlayedItems, notLoadedCount, oldestUpdate) ->
var streamItems = if (event is SuccessResultEvent || event is IdleEvent)
val streamItems = if (event is SuccessResultEvent || event is IdleEvent)
feedDatabaseManager
.getStreams(groupId, showPlayedItems)
.blockingGet(arrayListOf())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void onBindViewHolder(final VH holder, final int position) {
}

@Override
public void onViewRecycled(final VH holder) {
public void onViewRecycled(@NonNull final VH holder) {
super.onViewRecycled(holder);
holder.itemView.setOnClickListener(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void onCreate(@Nullable final Bundle savedInstanceState) {
}

@Override
public void onSaveInstanceState(final Bundle outState) {
public void onSaveInstanceState(@NonNull final Bundle outState) {
super.onSaveInstanceState(outState);
Icepick.saveInstanceState(this, outState);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.lifecycle.ViewModelProvider
import io.reactivex.rxjava3.core.Completable
import io.reactivex.rxjava3.core.Flowable
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.functions.BiFunction
import io.reactivex.rxjava3.processors.BehaviorProcessor
import io.reactivex.rxjava3.schedulers.Schedulers
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
Expand All @@ -33,9 +32,8 @@ class FeedGroupDialogViewModel(
private var subscriptionsFlowable = Flowable
.combineLatest(
filterSubscriptions.startWithItem(initialQuery),
toggleShowOnlyUngrouped.startWithItem(initialShowOnlyUngrouped),
BiFunction { t1: String, t2: Boolean -> Filter(t1, t2) }
)
toggleShowOnlyUngrouped.startWithItem(initialShowOnlyUngrouped)
) { t1: String, t2: Boolean -> Filter(t1, t2) }
.distinctUntilChanged()
.switchMap { (query, showOnlyUngrouped) ->
subscriptionManager.getSubscriptions(groupId, query, showOnlyUngrouped)
Expand All @@ -56,9 +54,8 @@ class FeedGroupDialogViewModel(

private var subscriptionsDisposable = Flowable
.combineLatest(
subscriptionsFlowable, feedDatabaseManager.subscriptionIdsForGroup(groupId),
BiFunction { t1: List<PickerSubscriptionItem>, t2: List<Long> -> t1 to t2.toSet() }
)
subscriptionsFlowable, feedDatabaseManager.subscriptionIdsForGroup(groupId)
) { t1: List<PickerSubscriptionItem>, t2: List<Long> -> t1 to t2.toSet() }
.subscribeOn(Schedulers.io())
.subscribe(mutableSubscriptionsLiveData::postValue)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,12 @@ class FeedGroupReorderDialog : DialogFragment() {

viewModel = ViewModelProvider(this).get(FeedGroupReorderDialogViewModel::class.java)
viewModel.groupsLiveData.observe(viewLifecycleOwner, Observer(::handleGroups))
viewModel.dialogEventLiveData.observe(
viewLifecycleOwner,
Observer {
when (it) {
ProcessingEvent -> disableInput()
SuccessEvent -> dismiss()
}
viewModel.dialogEventLiveData.observe(viewLifecycleOwner) {
when (it) {
ProcessingEvent -> disableInput()
SuccessEvent -> dismiss()
}
)
}

binding.feedGroupsList.layoutManager = LinearLayoutManager(requireContext())
binding.feedGroupsList.adapter = groupAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
Expand Down Expand Up @@ -601,7 +600,6 @@ private void onMaybeMuteChanged() {

//2) Icon change accordingly to current App Theme
// using rootView.getContext() because getApplicationContext() didn't work
final Context context = queueControlBinding.getRoot().getContext();
item.setIcon(player.isMuted() ? R.drawable.ic_volume_off : R.drawable.ic_volume_up);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public void onAnimationEnd(final Animator animation) {
//////////////////////////////////////////////////////////////////////////*/

@Override
public void onAudioSessionIdChanged(final EventTime eventTime, final int audioSessionId) {
public void onAudioSessionIdChanged(@NonNull final EventTime eventTime,
final int audioSessionId) {
notifyAudioSessionUpdate(true, audioSessionId);
}
private void notifyAudioSessionUpdate(final boolean active, final int audioSessionId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private CacheFactory(@NonNull final Context context,
}
}

@NonNull
@Override
public DataSource createDataSource() {
Log.d(TAG, "initExoPlayerCache: cacheDir = " + cacheDir.getAbsolutePath());
Expand All @@ -86,8 +87,8 @@ public void tryDeleteCacheFiles() {

Log.d(TAG, "tryDeleteCacheFiles: " + filePath + " deleted = " + deleteSuccessful);
}
} catch (final Exception ignored) {
Log.e(TAG, "Failed to delete file.", ignored);
} catch (final Exception e) {
Log.e(TAG, "Failed to delete file.", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ public void setMetadata(@NonNull final String title,
lastTitleHashCode = title.hashCode();
lastArtistHashCode = artist.hashCode();
lastDuration = duration;
if (optAlbumArt.isPresent()) {
lastAlbumArtHashCode = optAlbumArt.get().hashCode();
}
optAlbumArt.ifPresent(bitmap -> lastAlbumArtHashCode = bitmap.hashCode());
}

private boolean checkIfMetadataShouldBeSet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static PlaybackParameterDialog newInstance(final double playbackTempo,
//////////////////////////////////////////////////////////////////////////*/

@Override
public void onAttach(final Context context) {
public void onAttach(@NonNull final Context context) {
super.onAttach(context);
if (context instanceof Callback) {
callback = (Callback) context;
Expand All @@ -150,7 +150,7 @@ public void onCreate(@Nullable final Bundle savedInstanceState) {
}

@Override
public void onSaveInstanceState(final Bundle outState) {
public void onSaveInstanceState(@NonNull final Bundle outState) {
super.onSaveInstanceState(outState);
outState.putDouble(INITIAL_TEMPO_KEY, initialTempo);
outState.putDouble(INITIAL_PITCH_KEY, initialPitch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private void showMessageDialog(@StringRes final int title, @StringRes final int
}

@Override
public boolean onPreferenceTreeClick(final Preference preference) {
public boolean onPreferenceTreeClick(@NonNull final Preference preference) {
if (DEBUG) {
Log.d(TAG, "onPreferenceTreeClick() called with: "
+ "preference = [" + preference + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public boolean onOptionsItemSelected(final MenuItem item) {
}

@Override
public boolean onPreferenceStartFragment(final PreferenceFragmentCompat caller,
public boolean onPreferenceStartFragment(@NonNull final PreferenceFragmentCompat caller,
final Preference preference) {
showSettingsFragment(instantiateFragment(preference.getFragment()));
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public SettingRegistryEntry setSearchable(final boolean searchable) {
return this;
}

@NonNull
public Class<? extends Fragment> getFragmentClass() {
return fragmentClass;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public NotificationActionsPreference(final Context context, final AttributeSet a
////////////////////////////////////////////////////////////////////////////

@Override
public void onBindViewHolder(final PreferenceViewHolder holder) {
public void onBindViewHolder(@NonNull final PreferenceViewHolder holder) {
super.onBindViewHolder(holder);

holder.itemView.setClickable(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import androidx.preference.PreferenceScreen;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;

public class PreferenceSearchConfiguration {
private PreferenceSearchFunction searcher = new PreferenceFuzzySearchFunction();

private final List<String> parserIgnoreElements = Arrays.asList(
private final List<String> parserIgnoreElements = Collections.singletonList(
PreferenceCategory.class.getSimpleName());
private final List<String> parserContainerElements = Arrays.asList(
PreferenceCategory.class.getSimpleName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,27 @@ public PreferenceSearchItem(
this.searchIndexItemResId = searchIndexItemResId;
}

@NonNull
public String getKey() {
return key;
}

@NonNull
public String getTitle() {
return title;
}

@NonNull
public String getSummary() {
return summary;
}

@NonNull
public String getEntries() {
return entries;
}

@NonNull
public String getBreadcrumbs() {
return breadcrumbs;
}
Expand All @@ -94,7 +99,7 @@ public List<String> getAllRelevantSearchFields() {
getBreadcrumbs());
}


@NonNull
@Override
public String toString() {
return "PreferenceItem: " + title + " " + summary + " " + key;
Expand Down
Loading

0 comments on commit 9cb781b

Please sign in to comment.