Fix broken view pager tabs implementation
- Fragments were being recreated from scratch (losing their state) every time some configuration change occurred (e.g. screen rotation). - Use `FragmentStatePagerAdapter` instead, as it is built to work with them and manage their states.
This commit is contained in:
parent
532d2f305a
commit
991776c25e
2 changed files with 48 additions and 40 deletions
|
|
@ -28,6 +28,8 @@ import org.schabi.newpipe.util.KioskTranslator;
|
|||
import org.schabi.newpipe.util.ServiceHelper;
|
||||
import org.schabi.newpipe.util.ThemeHelper;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class Tab {
|
||||
Tab() {
|
||||
}
|
||||
|
|
@ -47,6 +49,8 @@ public abstract class Tab {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) return true;
|
||||
|
||||
return obj instanceof Tab && obj.getClass().equals(this.getClass())
|
||||
&& ((Tab) obj).getTabId() == this.getTabId();
|
||||
}
|
||||
|
|
@ -340,6 +344,13 @@ public abstract class Tab {
|
|||
kioskId = jsonObject.getString(JSON_KIOSK_ID_KEY, "<no-id>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return super.equals(obj) &&
|
||||
kioskServiceId == ((KioskTab) obj).kioskServiceId
|
||||
&& Objects.equals(kioskId, ((KioskTab) obj).kioskId);
|
||||
}
|
||||
|
||||
public int getKioskServiceId() {
|
||||
return kioskServiceId;
|
||||
}
|
||||
|
|
@ -409,6 +420,14 @@ public abstract class Tab {
|
|||
channelName = jsonObject.getString(JSON_CHANNEL_NAME_KEY, "<no-name>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return super.equals(obj) &&
|
||||
channelServiceId == ((ChannelTab) obj).channelServiceId
|
||||
&& Objects.equals(channelUrl, ((ChannelTab) obj).channelUrl)
|
||||
&& Objects.equals(channelName, ((ChannelTab) obj).channelName);
|
||||
}
|
||||
|
||||
public int getChannelServiceId() {
|
||||
return channelServiceId;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue