1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 08:30:44 +00:00

Replaced the equals method

This commit is contained in:
Jared Fantaye 2023-01-21 14:56:55 +01:00
parent 52e39c3402
commit 5b3f8a3d30
4 changed files with 20 additions and 21 deletions

View File

@ -864,7 +864,8 @@ public final class VideoDetailFragment
if (playQueue == null) { if (playQueue == null) {
playQueue = new SinglePlayQueue(result); playQueue = new SinglePlayQueue(result);
} }
if (stack.isEmpty() || !stack.peek().getPlayQueue().equals(playQueue)) { if (stack.isEmpty() || !stack.peek().getPlayQueue()
.equalStreams(playQueue)) {
stack.push(new StackItem(serviceId, url, title, playQueue)); stack.push(new StackItem(serviceId, url, title, playQueue));
} }
} }
@ -1780,7 +1781,7 @@ public final class VideoDetailFragment
// deleted/added items inside Channel/Playlist queue and makes possible to have // deleted/added items inside Channel/Playlist queue and makes possible to have
// a history of played items // a history of played items
@Nullable final StackItem stackPeek = stack.peek(); @Nullable final StackItem stackPeek = stack.peek();
if (stackPeek != null && !stackPeek.getPlayQueue().equals(queue)) { if (stackPeek != null && !stackPeek.getPlayQueue().equalStreams(queue)) {
@Nullable final PlayQueueItem playQueueItem = queue.getItem(); @Nullable final PlayQueueItem playQueueItem = queue.getItem();
if (playQueueItem != null) { if (playQueueItem != null) {
stack.push(new StackItem(playQueueItem.getServiceId(), playQueueItem.getUrl(), stack.push(new StackItem(playQueueItem.getServiceId(), playQueueItem.getUrl(),
@ -1846,7 +1847,7 @@ public final class VideoDetailFragment
// They are not equal when user watches something in popup while browsing in fragment and // They are not equal when user watches something in popup while browsing in fragment and
// then changes screen orientation. In that case the fragment will set itself as // then changes screen orientation. In that case the fragment will set itself as
// a service listener and will receive initial call to onMetadataUpdate() // a service listener and will receive initial call to onMetadataUpdate()
if (!queue.equals(playQueue)) { if (!queue.equalStreams(playQueue)) {
return; return;
} }
@ -2113,7 +2114,7 @@ public final class VideoDetailFragment
final Iterator<StackItem> iterator = stack.descendingIterator(); final Iterator<StackItem> iterator = stack.descendingIterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
final StackItem next = iterator.next(); final StackItem next = iterator.next();
if (next.getPlayQueue().equals(queue)) { if (next.getPlayQueue().equalStreams(queue)) {
item = next; item = next;
break; break;
} }
@ -2128,7 +2129,7 @@ public final class VideoDetailFragment
if (isClearingQueueConfirmationRequired(activity) if (isClearingQueueConfirmationRequired(activity)
&& playerIsNotStopped() && playerIsNotStopped()
&& activeQueue != null && activeQueue != null
&& !activeQueue.equals(playQueue)) { && !activeQueue.equalStreams(playQueue)) {
showClearingQueueConfirmation(onAllow); showClearingQueueConfirmation(onAllow);
} else { } else {
onAllow.run(); onAllow.run();

View File

@ -348,7 +348,7 @@ public final class Player implements PlaybackListener, Listener {
final boolean playbackSkipSilence = getPrefs().getBoolean(getContext().getString( final boolean playbackSkipSilence = getPrefs().getBoolean(getContext().getString(
R.string.playback_skip_silence_key), getPlaybackSkipSilence()); R.string.playback_skip_silence_key), getPlaybackSkipSilence());
final boolean samePlayQueue = playQueue != null && playQueue.equals(newQueue); final boolean samePlayQueue = playQueue != null && playQueue.equalStreamsAndIndex(newQueue);
final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode()); final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode());
final boolean playWhenReady = intent.getBooleanExtra(PLAY_WHEN_READY, true); final boolean playWhenReady = intent.getBooleanExtra(PLAY_WHEN_READY, true);
final boolean isMuted = intent.getBooleanExtra(IS_MUTED, isMuted()); final boolean isMuted = intent.getBooleanExtra(IS_MUTED, isMuted());

View File

@ -518,18 +518,13 @@ public abstract class PlayQueue implements Serializable {
* This method also gives a chance to track history of items in a queue in * This method also gives a chance to track history of items in a queue in
* VideoDetailFragment without duplicating items from two identical queues * VideoDetailFragment without duplicating items from two identical queues
*/ */
@Override public boolean equalStreams(@Nullable final PlayQueue other) {
public boolean equals(@Nullable final Object obj) { if (other == null) {
if (!(obj instanceof PlayQueue)) {
return false; return false;
} }
final PlayQueue other = (PlayQueue) obj;
if (size() != other.size()) { if (size() != other.size()) {
return false; return false;
} }
if (other.getIndex() != getIndex()) {
return false;
}
for (int i = 0; i < size(); i++) { for (int i = 0; i < size(); i++) {
final PlayQueueItem stream = streams.get(i); final PlayQueueItem stream = streams.get(i);
final PlayQueueItem otherStream = other.streams.get(i); final PlayQueueItem otherStream = other.streams.get(i);
@ -542,9 +537,11 @@ public abstract class PlayQueue implements Serializable {
return true; return true;
} }
@Override public boolean equalStreamsAndIndex(@Nullable final PlayQueue other) {
public int hashCode() { if (equalStreams(other)) {
return streams.hashCode(); return other.getIndex() == getIndex();
}
return false;
} }
public boolean isDisposed() { public boolean isDisposed() {

View File

@ -13,7 +13,6 @@ import java.util.Objects;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -169,7 +168,8 @@ public class PlayQueueTest {
final List<PlayQueueItem> streams = Collections.nCopies(5, item1); final List<PlayQueueItem> streams = Collections.nCopies(5, item1);
final PlayQueue queue1 = makePlayQueue(0, streams); final PlayQueue queue1 = makePlayQueue(0, streams);
final PlayQueue queue2 = makePlayQueue(0, streams); final PlayQueue queue2 = makePlayQueue(0, streams);
assertEquals(queue1, queue2); assertTrue(queue1.equalStreams(queue2));
assertTrue(queue1.equalStreamsAndIndex(queue2));
} }
@Test @Test
@ -177,7 +177,8 @@ public class PlayQueueTest {
final List<PlayQueueItem> streams = Collections.nCopies(5, item1); final List<PlayQueueItem> streams = Collections.nCopies(5, item1);
final PlayQueue queue1 = makePlayQueue(1, streams); final PlayQueue queue1 = makePlayQueue(1, streams);
final PlayQueue queue2 = makePlayQueue(4, streams); final PlayQueue queue2 = makePlayQueue(4, streams);
assertNotEquals(queue1, queue2); assertTrue(queue1.equalStreams(queue2));
assertFalse(queue1.equalStreamsAndIndex(queue2));
} }
@Test @Test
@ -186,7 +187,7 @@ public class PlayQueueTest {
final List<PlayQueueItem> streams2 = Collections.nCopies(5, item2); final List<PlayQueueItem> streams2 = Collections.nCopies(5, item2);
final PlayQueue queue1 = makePlayQueue(0, streams1); final PlayQueue queue1 = makePlayQueue(0, streams1);
final PlayQueue queue2 = makePlayQueue(0, streams2); final PlayQueue queue2 = makePlayQueue(0, streams2);
assertNotEquals(queue1, queue2); assertFalse(queue1.equalStreams(queue2));
} }
@Test @Test
@ -195,7 +196,7 @@ public class PlayQueueTest {
final List<PlayQueueItem> streams2 = Collections.nCopies(6, item2); final List<PlayQueueItem> streams2 = Collections.nCopies(6, item2);
final PlayQueue queue1 = makePlayQueue(0, streams1); final PlayQueue queue1 = makePlayQueue(0, streams1);
final PlayQueue queue2 = makePlayQueue(0, streams2); final PlayQueue queue2 = makePlayQueue(0, streams2);
assertNotEquals(queue1, queue2); assertFalse(queue1.equalStreams(queue2));
} }
} }
} }