|
1 | 1 | package org.schabi.newpipe.fragments.list.channel; |
2 | 2 |
|
3 | 3 | import android.os.Bundle; |
| 4 | +import android.util.Log; |
4 | 5 | import android.view.LayoutInflater; |
5 | 6 | import android.view.View; |
6 | 7 | import android.view.ViewGroup; |
|
14 | 15 | import org.schabi.newpipe.extractor.InfoItem; |
15 | 16 | import org.schabi.newpipe.extractor.ListExtractor; |
16 | 17 | import org.schabi.newpipe.extractor.channel.tabs.ChannelTabInfo; |
| 18 | +import org.schabi.newpipe.extractor.exceptions.ParsingException; |
17 | 19 | import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; |
| 20 | +import org.schabi.newpipe.extractor.linkhandler.ReadyChannelTabListLinkHandler; |
18 | 21 | import org.schabi.newpipe.extractor.stream.StreamInfoItem; |
19 | 22 | import org.schabi.newpipe.fragments.list.BaseListInfoFragment; |
20 | 23 | import org.schabi.newpipe.fragments.list.playlist.PlaylistControlViewHolder; |
@@ -114,6 +117,27 @@ public void setTitle(final String title) { |
114 | 117 | public void handleResult(@NonNull final ChannelTabInfo result) { |
115 | 118 | super.handleResult(result); |
116 | 119 |
|
| 120 | + // FIXME this is a really hacky workaround, to avoid storing useless data in the fragment |
| 121 | + // state. The problem is, `ReadyChannelTabListLinkHandler` might contain raw JSON data that |
| 122 | + // uses a lot of memory (e.g. ~800KB for YouTube). While 800KB doesn't seem much, if |
| 123 | + // you combine just a couple of channel tab fragments you easily go over the 1MB |
| 124 | + // save&restore transaction limit, and get `TransactionTooLargeException`s. A proper |
| 125 | + // solution would require rethinking about `ReadyChannelTabListLinkHandler`s. |
| 126 | + if (tabHandler instanceof ReadyChannelTabListLinkHandler) { |
| 127 | + try { |
| 128 | + // once `handleResult` is called, the parsed data was already saved to cache, so |
| 129 | + // we can discard any raw data in ReadyChannelTabListLinkHandler and create a |
| 130 | + // link handler with identical properties, but without any raw data |
| 131 | + tabHandler = result.getService() |
| 132 | + .getChannelTabLHFactory() |
| 133 | + .fromQuery(tabHandler.getId(), tabHandler.getContentFilters(), |
| 134 | + tabHandler.getSortFilter()); |
| 135 | + } catch (final ParsingException e) { |
| 136 | + // silently ignore the error, as the app can continue to function normally |
| 137 | + Log.w(TAG, "Could not recreate channel tab handler", e); |
| 138 | + } |
| 139 | + } |
| 140 | + |
117 | 141 | if (playlistControlBinding != null) { |
118 | 142 | // PlaylistControls should be visible only if there is some item in |
119 | 143 | // infoListAdapter other than header |
|
0 commit comments