mirror of https://github.com/TeamNewPipe/NewPipe
Name of the playlist is the name of the file the links are stored in
This commit is contained in:
parent
33f7d49639
commit
9645ebcd65
|
@ -3,9 +3,11 @@ package org.schabi.newpipe.local.bookmark;
|
|||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.text.InputType;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -127,8 +129,17 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
|
|||
final String mimeType = getActivity().getContentResolver().getType(uri);
|
||||
// Check if the selected file is a text file
|
||||
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,
|
||||
localPlaylistManager);
|
||||
localPlaylistManager, fileName);
|
||||
parser.readTextFile(activity);
|
||||
} else {
|
||||
Toast.makeText(getActivity(), "Please select a .txt file!",
|
||||
|
|
|
@ -35,12 +35,14 @@ public class BookmarkImportService {
|
|||
private int readerLineCount = 0;
|
||||
private int addedByBackgroundThreadCount = 0;
|
||||
|
||||
private String filename;
|
||||
List<StreamEntity> streams;
|
||||
|
||||
public BookmarkImportService(final Uri textFileUri,
|
||||
final LocalPlaylistManager localPlaylistManager) {
|
||||
public BookmarkImportService(final Uri textFileUri, final LocalPlaylistManager
|
||||
localPlaylistManager, final String filename) {
|
||||
this.textFileUri = textFileUri;
|
||||
this.localPlaylistManager = localPlaylistManager;
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public void importBookmarks(final Activity activity) {
|
||||
|
@ -103,7 +105,9 @@ public class BookmarkImportService {
|
|||
//All background threads done.
|
||||
//Add playlist
|
||||
final Maybe<List<Long>> playlistIds =
|
||||
localPlaylistManager.createPlaylist("Sample", streams);
|
||||
localPlaylistManager.createPlaylist(
|
||||
filename.substring(0, filename.lastIndexOf('.')),
|
||||
streams);
|
||||
playlistIds.subscribe(list -> {
|
||||
//this is to make the fragment fetch data from the database
|
||||
//I could not find another way to do this.
|
||||
|
|
Loading…
Reference in New Issue