diff --git a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java index 34ecfda8d..9c4428b5b 100644 --- a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java @@ -41,7 +41,6 @@ import org.schabi.newpipe.local.playlist.LocalPlaylistManager; import org.schabi.newpipe.local.playlist.RemotePlaylistManager; import org.schabi.newpipe.streams.io.NoFileManagerSafeGuard; import org.schabi.newpipe.streams.io.StoredFileHelper; -import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.OnClickGesture; @@ -58,8 +57,6 @@ import io.reactivex.rxjava3.disposables.Disposable; public final class BookmarkFragment extends BaseLocalListFragment, Void> { @State protected Parcelable itemsListState; - @State - int currentServiceId = Constants.NO_SERVICE_ID; private Subscription databaseSubscription; private CompositeDisposable disposables = new CompositeDisposable(); @@ -131,7 +128,8 @@ public final class BookmarkFragment extends BaseLocalListFragment streamInfoSingle; + private StreamInfo streamInfo; + List streams; + public BookmarkImportService(final Uri textFileUri, + final RemotePlaylistManager remotePlaylistManager, + final LocalPlaylistManager localPlaylistManager) { this.textFileUri = textFileUri; + this.remotePlaylistManager = remotePlaylistManager; + this.localPlaylistManager = localPlaylistManager; } public void importBookmarks(final Activity activity) { + readTextFile(activity); + } + public void readTextFile(final Activity activity) { + int count = 0; if (textFileUri != null) { - try { - final InputStream inputStream = - activity.getContentResolver().openInputStream(textFileUri); - if (inputStream != null) { - final BufferedReader reader = - new BufferedReader(new InputStreamReader(inputStream)); - String line; + try { + final InputStream inputStream = + activity.getContentResolver().openInputStream(textFileUri); + if (inputStream != null) { + final BufferedReader reader = + new BufferedReader(new InputStreamReader(inputStream)); + String line; - while ((line = reader.readLine()) != null) { - Toast.makeText(activity, line, Toast.LENGTH_SHORT).show(); + while ((line = reader.readLine()) != null) { + if (count == 0) { + //cannot create an empty playlist + createNewPlayListWithOneEntry(); + count++; + getStreamEntity(line); + } else { + addEntries(); + } + } + reader.close(); + inputStream.close(); } - - reader.close(); - inputStream.close(); + } catch (final IOException e) { + throw new RuntimeException(e); } - } catch (final IOException e) { - throw new RuntimeException(e); - } } } + public void createNewPlayListWithOneEntry() { + System.out.println("LOL"); + } + public void addEntries() { + System.out.println("LOL"); + } + public void getStreamEntity(final String url) { + try { + streamingService = NewPipe.getServiceByUrl(url); + streamInfoSingle = + ExtractorHelper.getStreamInfo(streamingService.getServiceId(), + url, true); + convertToStreamEntity(streamInfoSingle); + } catch (final ExtractionException e) { + throw new RuntimeException(e); + } + } + public void convertToStreamEntity(final Single singleStreamInfo) { + streamInfo = singleStreamInfo.blockingGet(); + final StreamEntity streamEntity = new StreamEntity( + Long.parseLong(streamInfo.getId()), + streamInfo.getServiceId(), + streamInfo.getUrl(), + streamInfo.getName(), + streamInfo.getStreamType(), + streamInfo.getDuration(), + streamInfo.getUploaderName(), + streamInfo.getUploaderUrl(), + ImageStrategy.imageListToDbUrl(streamInfo.getThumbnails()), + streamInfo.getViewCount(), + streamInfo.getTextualUploadDate(), + streamInfo.getUploadDate() != null + ? streamInfo.getUploadDate().offsetDateTime() : null, + streamInfo.getUploadDate() != null + ? streamInfo.getUploadDate().isApproximation() : null + ); + streams.add(streamEntity); + } }