Added Comments
This commit is contained in:
parent
9645ebcd65
commit
a676fb9b7f
|
@ -117,6 +117,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//open file manager
|
||||||
private final ActivityResultLauncher<Intent> requestImportFileLauncher =
|
private final ActivityResultLauncher<Intent> requestImportFileLauncher =
|
||||||
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
|
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
|
||||||
this::requestImportFileResult);
|
this::requestImportFileResult);
|
||||||
|
@ -129,6 +130,7 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
||||||
final String mimeType = getActivity().getContentResolver().getType(uri);
|
final String mimeType = getActivity().getContentResolver().getType(uri);
|
||||||
// Check if the selected file is a text file
|
// Check if the selected file is a text file
|
||||||
if (mimeType != null && mimeType.equals("text/plain")) {
|
if (mimeType != null && mimeType.equals("text/plain")) {
|
||||||
|
//get filename. Name of Playlist is the same as filename
|
||||||
String fileName = "";
|
String fileName = "";
|
||||||
final Cursor returnCursor = getActivity().getContentResolver().query(uri, null,
|
final Cursor returnCursor = getActivity().getContentResolver().query(uri, null,
|
||||||
null, null, null);
|
null, null, null);
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class BookmarkImportService {
|
||||||
private int addedByBackgroundThreadCount = 0;
|
private int addedByBackgroundThreadCount = 0;
|
||||||
|
|
||||||
private String filename;
|
private String filename;
|
||||||
List<StreamEntity> streams;
|
List<StreamEntity> streams; //holds the collection of videos to be added
|
||||||
|
|
||||||
public BookmarkImportService(final Uri textFileUri, final LocalPlaylistManager
|
public BookmarkImportService(final Uri textFileUri, final LocalPlaylistManager
|
||||||
localPlaylistManager, final String filename) {
|
localPlaylistManager, final String filename) {
|
||||||
|
@ -44,20 +44,18 @@ public class BookmarkImportService {
|
||||||
this.localPlaylistManager = localPlaylistManager;
|
this.localPlaylistManager = localPlaylistManager;
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void importBookmarks(final Activity activity) {
|
|
||||||
readTextFile(activity);
|
|
||||||
}
|
|
||||||
public void readTextFile(final Activity activity) {
|
public void readTextFile(final Activity activity) {
|
||||||
if (textFileUri != null) {
|
if (textFileUri != null) {
|
||||||
try {
|
try {
|
||||||
final InputStream inputStream =
|
final InputStream inputStream =
|
||||||
activity.getContentResolver().openInputStream(textFileUri);
|
activity.getContentResolver().openInputStream(textFileUri);
|
||||||
if (inputStream != null) {
|
if (inputStream != null) {
|
||||||
|
//FileReader
|
||||||
final BufferedReader reader =
|
final BufferedReader reader =
|
||||||
new BufferedReader(new InputStreamReader(inputStream));
|
new BufferedReader(new InputStreamReader(inputStream));
|
||||||
String line;
|
String line;
|
||||||
streams = new ArrayList<>();
|
streams = new ArrayList<>();
|
||||||
|
//iterate through all lines
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
readerLineCount++;
|
readerLineCount++;
|
||||||
handleUrl(activity, line);
|
handleUrl(activity, line);
|
||||||
|
@ -77,8 +75,11 @@ public class BookmarkImportService {
|
||||||
final StreamingService service;
|
final StreamingService service;
|
||||||
final StreamingService.LinkType linkType;
|
final StreamingService.LinkType linkType;
|
||||||
try {
|
try {
|
||||||
|
//Extract information from the URL
|
||||||
service = NewPipe.getServiceByUrl(url);
|
service = NewPipe.getServiceByUrl(url);
|
||||||
linkType = service.getLinkTypeByUrl(url);
|
linkType = service.getLinkTypeByUrl(url);
|
||||||
|
//the link must belong to a stream(video)
|
||||||
|
// A playlist cannot have another playlist inside it, or be empty
|
||||||
if (linkType == StreamingService.LinkType.STREAM) {
|
if (linkType == StreamingService.LinkType.STREAM) {
|
||||||
final LinkHandlerFactory factory = service.getStreamLHFactory();
|
final LinkHandlerFactory factory = service.getStreamLHFactory();
|
||||||
final String cleanUrl;
|
final String cleanUrl;
|
||||||
|
@ -100,7 +101,6 @@ public class BookmarkImportService {
|
||||||
// Update the streams list.
|
// Update the streams list.
|
||||||
activity.runOnUiThread(() -> {
|
activity.runOnUiThread(() -> {
|
||||||
streams.add(streamEntity);
|
streams.add(streamEntity);
|
||||||
|
|
||||||
if (addedByBackgroundThreadCount == readerLineCount) {
|
if (addedByBackgroundThreadCount == readerLineCount) {
|
||||||
//All background threads done.
|
//All background threads done.
|
||||||
//Add playlist
|
//Add playlist
|
||||||
|
|
Loading…
Reference in New Issue