1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-10-26 12:57:39 +00:00

Name of the playlist is the name of the file the links are stored in

This commit is contained in:
Mannith Narayan
2023-10-29 07:50:21 +11:00
parent 33f7d49639
commit 9645ebcd65
2 changed files with 19 additions and 4 deletions

View File

@@ -3,9 +3,11 @@ package org.schabi.newpipe.local.bookmark;
import android.app.Activity; import android.app.Activity;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable; import android.os.Parcelable;
import android.provider.OpenableColumns;
import android.text.InputType; import android.text.InputType;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@@ -127,8 +129,17 @@ 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")) {
String fileName = "";
final Cursor returnCursor = getActivity().getContentResolver().query(uri, null,
null, null, null);
if (returnCursor != null) {
final int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
returnCursor.moveToFirst();
fileName = returnCursor.getString(nameIndex);
returnCursor.close();
}
final BookmarkImportService parser = new BookmarkImportService(uri, final BookmarkImportService parser = new BookmarkImportService(uri,
localPlaylistManager); localPlaylistManager, fileName);
parser.readTextFile(activity); parser.readTextFile(activity);
} else { } else {
Toast.makeText(getActivity(), "Please select a .txt file!", Toast.makeText(getActivity(), "Please select a .txt file!",

View File

@@ -35,12 +35,14 @@ public class BookmarkImportService {
private int readerLineCount = 0; private int readerLineCount = 0;
private int addedByBackgroundThreadCount = 0; private int addedByBackgroundThreadCount = 0;
private String filename;
List<StreamEntity> streams; List<StreamEntity> streams;
public BookmarkImportService(final Uri textFileUri, public BookmarkImportService(final Uri textFileUri, final LocalPlaylistManager
final LocalPlaylistManager localPlaylistManager) { localPlaylistManager, final String filename) {
this.textFileUri = textFileUri; this.textFileUri = textFileUri;
this.localPlaylistManager = localPlaylistManager; this.localPlaylistManager = localPlaylistManager;
this.filename = filename;
} }
public void importBookmarks(final Activity activity) { public void importBookmarks(final Activity activity) {
@@ -103,7 +105,9 @@ public class BookmarkImportService {
//All background threads done. //All background threads done.
//Add playlist //Add playlist
final Maybe<List<Long>> playlistIds = final Maybe<List<Long>> playlistIds =
localPlaylistManager.createPlaylist("Sample", streams); localPlaylistManager.createPlaylist(
filename.substring(0, filename.lastIndexOf('.')),
streams);
playlistIds.subscribe(list -> { playlistIds.subscribe(list -> {
//this is to make the fragment fetch data from the database //this is to make the fragment fetch data from the database
//I could not find another way to do this. //I could not find another way to do this.