Some fixes

This commit is contained in:
Thomas 2020-11-14 09:50:48 +01:00
parent c3e475be6f
commit fbbab1db68
4 changed files with 31 additions and 25 deletions

View File

@ -19,13 +19,10 @@
tools:node="merge"> tools:node="merge">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:scheme="content" /> <data android:scheme="content" />
<data android:host="*" /> <data android:scheme="file" />
<data android:mimeType="*/*" /> <data android:mimeType="*/*" />
<data android:pathPattern=".*\\.tubelab" /> <data android:pathPattern=".*\\.tubelab" />
<data android:pathPattern=".*\\..*\\.tubelab" /> <data android:pathPattern=".*\\..*\\.tubelab" />

View File

@ -19,13 +19,10 @@
tools:node="merge"> tools:node="merge">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:scheme="content" /> <data android:scheme="content" />
<data android:host="*" /> <data android:scheme="file" />
<data android:mimeType="*/*" /> <data android:mimeType="*/*" />
<data android:pathPattern=".*\\.tubelab" /> <data android:pathPattern=".*\\.tubelab" />
<data android:pathPattern=".*\\..*\\.tubelab" /> <data android:pathPattern=".*\\..*\\.tubelab" />

View File

@ -16,14 +16,15 @@ package app.fedilab.fedilabtube.helper;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.provider.OpenableColumns;
import com.google.gson.Gson; import com.google.gson.Gson;
import java.io.BufferedReader; import java.io.FileNotFoundException;
import java.io.File; import java.io.InputStream;
import java.io.FileReader; import java.util.Scanner;
import java.io.IOException;
import app.fedilab.fedilabtube.PlaylistsActivity; import app.fedilab.fedilabtube.PlaylistsActivity;
import app.fedilab.fedilabtube.client.data.VideoPlaylistData; import app.fedilab.fedilabtube.client.data.VideoPlaylistData;
@ -72,23 +73,34 @@ public class PlaylistExportHelper {
public static void manageIntentUrl(Activity activity, Intent intent) { public static void manageIntentUrl(Activity activity, Intent intent) {
if (intent.getData() != null) { if (intent.getData() != null) {
String url = intent.getData().toString(); String url = intent.getData().toString();
if (url.endsWith(".json")) {
File file = new File(url); String filename = url;
StringBuilder text = new StringBuilder();
if (url.startsWith("content://")) {
Cursor cursor = null;
try { try {
BufferedReader br = new BufferedReader(new FileReader(file)); cursor = activity.getContentResolver().query(intent.getData(), null, null, null, null);
String line; if (cursor != null && cursor.moveToFirst()) {
while ((line = br.readLine()) != null) { filename = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
text.append(line);
text.append('\n');
} }
br.close(); } finally {
} catch (IOException e) { assert cursor != null;
cursor.close();
}
}
String text = null;
if (filename.endsWith(".tubelab")) {
try {
InputStream inputStream = activity.getContentResolver().openInputStream(intent.getData());
Scanner s = new Scanner(inputStream).useDelimiter("\\A");
text = s.hasNext() ? s.next() : "";
} catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
if (text.length() > 20) { if (text != null && text.length() > 20) {
String finalText = text;
new Thread(() -> { new Thread(() -> {
VideoPlaylistData.VideoPlaylistExport videoPlaylistExport = PlaylistExportHelper.restorePlaylistFromString(text.toString()); VideoPlaylistData.VideoPlaylistExport videoPlaylistExport = PlaylistExportHelper.restorePlaylistFromString(finalText);
if (videoPlaylistExport != null) { if (videoPlaylistExport != null) {
SQLiteDatabase db = Sqlite.getInstance(activity.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); SQLiteDatabase db = Sqlite.getInstance(activity.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new ManagePlaylistsDAO(activity, db).insertPlaylist(videoPlaylistExport); new ManagePlaylistsDAO(activity, db).insertPlaylist(videoPlaylistExport);

View File

@ -6,7 +6,7 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.1.0' classpath 'com.android.tools.build:gradle:4.1.1'
def nav_version = "2.3.0" def nav_version = "2.3.0"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong