App Crashes

This commit is contained in:
Mannith Narayan 2023-10-29 01:58:21 +11:00
parent b7d34ea25d
commit 758d84a87f
2 changed files with 89 additions and 22 deletions

View File

@ -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<List<PlaylistLocalItem>, 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<List<PlaylistL
// Check if the selected file is a text file
if (mimeType != null && mimeType.equals("text/plain")) {
final BookmarkImportService parser = new BookmarkImportService(uri);
final BookmarkImportService parser = new BookmarkImportService(uri,
remotePlaylistManager, localPlaylistManager);
parser.importBookmarks(activity);
System.out.println(parser);
} else {

View File

@ -2,41 +2,110 @@ package org.schabi.newpipe.local.bookmark;
import android.app.Activity;
import android.net.Uri;
import android.widget.Toast;
import org.schabi.newpipe.database.stream.model.StreamEntity;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.local.playlist.LocalPlaylistManager;
import org.schabi.newpipe.local.playlist.RemotePlaylistManager;
import org.schabi.newpipe.util.ExtractorHelper;
import org.schabi.newpipe.util.image.ImageStrategy;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import io.reactivex.rxjava3.core.Single;
public class BookmarkImportService {
private Uri textFileUri;
public BookmarkImportService(final Uri textFileUri) {
private RemotePlaylistManager remotePlaylistManager;
private LocalPlaylistManager localPlaylistManager;
private StreamingService streamingService;
private Single<StreamInfo> streamInfoSingle;
private StreamInfo streamInfo;
List<StreamEntity> 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<StreamInfo> 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);
}
}