forked from koying/SPMC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CHG: [droid] replace image provider by file provider
- Loading branch information
Showing
6 changed files
with
118 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,10 +124,6 @@ | |
</intent-filter> | ||
</receiver> | ||
|
||
<provider | ||
android:name=".content.XBMCImageContentProvider" | ||
android:authorities="@[email protected]" | ||
android:exported="true" /> | ||
<provider | ||
android:name=".content.XBMCMediaContentProvider" | ||
android:authorities="@[email protected]" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
package @APP_PACKAGE@; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.OutputStreamWriter; | ||
import java.net.ConnectException; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.util.List; | ||
|
@@ -39,7 +35,6 @@ import @[email protected]; | |
import @[email protected]; | ||
import @[email protected]; | ||
import @[email protected]; | ||
import @[email protected]; | ||
|
||
public class XBMCJsonRPC | ||
{ | ||
|
@@ -419,8 +414,8 @@ public class XBMCJsonRPC | |
movie.get("movieid").getAsString(), | ||
movie.get("title").getAsString(), | ||
movie.get("tagline").getAsString(), | ||
XBMCImageContentProvider.GetImageUri(getDownloadUrl(movie.get("thumbnail").getAsString())).toString(), | ||
XBMCImageContentProvider.GetImageUri(getDownloadUrl(movie.get("thumbnail").getAsString())).toString(), | ||
XBMCFileContentProvider.buildUri(getDownloadUrl(movie.get("thumbnail").getAsString())).toString(), | ||
XBMCFileContentProvider.buildUri(getDownloadUrl(movie.get("thumbnail").getAsString())).toString(), | ||
Intent.ACTION_GET_CONTENT, | ||
Uri.parse("videodb://movies/titles/" + movie.get("movieid").getAsString() + "?showinfo=true"), | ||
0, | ||
|
@@ -467,8 +462,8 @@ public class XBMCJsonRPC | |
tvshow.get("tvshowid").getAsString(), | ||
tvshow.get("title").getAsString(), | ||
tvshow.get("plot").getAsString(), | ||
XBMCImageContentProvider.GetImageUri(getDownloadUrl(tvshow.get("thumbnail").getAsString())).toString(), | ||
XBMCImageContentProvider.GetImageUri(getDownloadUrl(tvshow.get("thumbnail").getAsString())).toString(), | ||
XBMCFileContentProvider.buildUri(getDownloadUrl(tvshow.get("thumbnail").getAsString())).toString(), | ||
XBMCFileContentProvider.buildUri(getDownloadUrl(tvshow.get("thumbnail").getAsString())).toString(), | ||
Intent.ACTION_GET_CONTENT, | ||
Uri.parse("videodb://tvshows/titles/" + tvshow.get("tvshowid").getAsString() + "?showinfo=true"), | ||
0, | ||
|
@@ -505,8 +500,8 @@ public class XBMCJsonRPC | |
album.get("albumid").getAsString(), | ||
album.get("title").getAsString(), | ||
album.get("displayartist").getAsString(), | ||
XBMCImageContentProvider.GetImageUri(getDownloadUrl(album.get("thumbnail").getAsString())).toString(), | ||
XBMCImageContentProvider.GetImageUri(getDownloadUrl(album.get("thumbnail").getAsString())).toString(), | ||
XBMCFileContentProvider.buildUri(getDownloadUrl(album.get("thumbnail").getAsString())).toString(), | ||
XBMCFileContentProvider.buildUri(getDownloadUrl(album.get("thumbnail").getAsString())).toString(), | ||
Intent.ACTION_GET_CONTENT, | ||
Uri.parse("musicdb://albums/" + album.get("albumid").getAsString() + "/"), | ||
0, | ||
|
@@ -541,8 +536,8 @@ public class XBMCJsonRPC | |
artist.get("artistid").getAsString(), | ||
artist.get("artist").getAsString(), | ||
artist.get("description").getAsString(), | ||
XBMCImageContentProvider.GetImageUri(getDownloadUrl(artist.get("thumbnail").getAsString())).toString(), | ||
XBMCImageContentProvider.GetImageUri(getDownloadUrl(artist.get("thumbnail").getAsString())).toString(), | ||
XBMCFileContentProvider.buildUri(getDownloadUrl(artist.get("thumbnail").getAsString())).toString(), | ||
XBMCFileContentProvider.buildUri(getDownloadUrl(artist.get("thumbnail").getAsString())).toString(), | ||
Intent.ACTION_GET_CONTENT, | ||
Uri.parse("musicdb://artists/" + artist.get("artistid").getAsString() + "/"), | ||
0, | ||
|
@@ -595,7 +590,7 @@ public class XBMCJsonRPC | |
|
||
final XBMCRecommendationBuilder notificationBuilder = builder | ||
.setBackground( | ||
XBMCImageContentProvider.GetImageUri( | ||
XBMCFileContentProvider.buildUri( | ||
getDownloadUrl(movie.get("fanart").getAsString())).toString()) | ||
.setId(id).setPriority(MAX_RECOMMENDATIONS - count) | ||
.setTitle(movie.get("title").getAsString()) | ||
|
@@ -637,7 +632,7 @@ public class XBMCJsonRPC | |
|
||
final XBMCRecommendationBuilder notificationBuilder = builder | ||
.setBackground( | ||
XBMCImageContentProvider.GetImageUri( | ||
XBMCFileContentProvider.buildUri( | ||
getDownloadUrl(tvshow.get("fanart").getAsString())).toString()) | ||
.setId(id).setPriority(MAX_RECOMMENDATIONS - count) | ||
.setTitle(tvshow.get("title").getAsString()) | ||
|
@@ -680,7 +675,7 @@ public class XBMCJsonRPC | |
|
||
final XBMCRecommendationBuilder notificationBuilder = builder | ||
.setBackground( | ||
XBMCImageContentProvider.GetImageUri( | ||
XBMCFileContentProvider.buildUri( | ||
getDownloadUrl(album.get("fanart").getAsString())).toString()) | ||
.setId(id).setPriority(MAX_RECOMMENDATIONS - count) | ||
.setTitle(album.get("title").getAsString()) | ||
|
@@ -806,14 +801,14 @@ public class XBMCJsonRPC | |
{ | ||
String url = getDownloadUrl(details.get("thumbnail").getAsString()); | ||
if (url != null && url != null && !url.isEmpty()) | ||
med.setCardImageUrl(XBMCImageContentProvider.GetImageUri(url).toString()); | ||
med.setCardImageUrl(XBMCFileContentProvider.buildUri(url).toString()); | ||
} | ||
med.setCardImageAspectRatio("2:3"); | ||
if (details.has("fanart") && !details.get("fanart").getAsString().isEmpty()) | ||
{ | ||
String url = getDownloadUrl(details.get("fanart").getAsString()); | ||
if (url != null && url != null && !url.isEmpty()) | ||
med.setBackgroundImageUrl(XBMCImageContentProvider.GetImageUri(url).toString()); | ||
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(url).toString()); | ||
} | ||
med.setXbmcUrl("videodb://movies/titles/" + details.get("movieid").getAsString() + "?showinfo=true"); | ||
|
||
|
@@ -864,14 +859,14 @@ public class XBMCJsonRPC | |
{ | ||
String url = getDownloadUrl(details.get("thumbnail").getAsString()); | ||
if (url != null && !url.isEmpty()) | ||
med.setCardImageUrl(XBMCImageContentProvider.GetImageUri(url).toString()); | ||
med.setCardImageUrl(XBMCFileContentProvider.buildUri(url).toString()); | ||
} | ||
med.setCardImageAspectRatio("2:3"); | ||
if (details.has("fanart") && !details.get("fanart").getAsString().isEmpty()) | ||
{ | ||
String url = getDownloadUrl(details.get("fanart").getAsString()); | ||
if (url != null && !url.isEmpty()) | ||
med.setBackgroundImageUrl(XBMCImageContentProvider.GetImageUri(url).toString()); | ||
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(url).toString()); | ||
} | ||
med.setXbmcUrl("videodb://tvshows/titles/" + details.get("tvshowid").getAsInt() + "/"); | ||
med.setCategory(Media.MEDIA_TYPE_TVSHOW); | ||
|
@@ -897,14 +892,14 @@ public class XBMCJsonRPC | |
{ | ||
String url = getDownloadUrl(details.get("thumbnail").getAsString()); | ||
if (url != null && !url.isEmpty()) | ||
med.setCardImageUrl(XBMCImageContentProvider.GetImageUri(url).toString()); | ||
med.setCardImageUrl(XBMCFileContentProvider.buildUri(url).toString()); | ||
} | ||
med.setCardImageAspectRatio("16:9"); | ||
if (details.has("fanart") && !details.get("fanart").getAsString().isEmpty()) | ||
{ | ||
String url = getDownloadUrl(details.get("fanart").getAsString()); | ||
if (url != null && !url.isEmpty()) | ||
med.setBackgroundImageUrl(XBMCImageContentProvider.GetImageUri(url).toString()); | ||
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(url).toString()); | ||
} | ||
med.setXbmcUrl("videodb://tvshows/titles/" + details.get("tvshowid").getAsInt() + "/" + details.get("episodeid").getAsInt() + "?showinfo=true"); | ||
/* | ||
|
@@ -938,14 +933,14 @@ public class XBMCJsonRPC | |
{ | ||
String url = getDownloadUrl(details.get("thumbnail").getAsString()); | ||
if (url != null && !url.isEmpty()) | ||
med.setCardImageUrl(XBMCImageContentProvider.GetImageUri(url).toString()); | ||
med.setCardImageUrl(XBMCFileContentProvider.buildUri(url).toString()); | ||
} | ||
med.setCardImageAspectRatio("1:1"); | ||
if (details.has("fanart") && !details.get("fanart").getAsString().isEmpty()) | ||
{ | ||
String url = getDownloadUrl(details.get("fanart").getAsString()); | ||
if (url != null && !url.isEmpty()) | ||
med.setBackgroundImageUrl(XBMCImageContentProvider.GetImageUri(url).toString()); | ||
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(url).toString()); | ||
} | ||
med.setXbmcUrl("musicdb://albums/" + details.get("albumid").getAsString() + "/"); | ||
med.setCategory(Media.MEDIA_TYPE_ALBUM); | ||
|
@@ -971,14 +966,14 @@ public class XBMCJsonRPC | |
{ | ||
String url = getDownloadUrl(details.get("thumbnail").getAsString()); | ||
if (url != null && !url.isEmpty()) | ||
med.setCardImageUrl(XBMCImageContentProvider.GetImageUri(url).toString()); | ||
med.setCardImageUrl(XBMCFileContentProvider.buildUri(url).toString()); | ||
} | ||
med.setCardImageAspectRatio("1:1"); | ||
if (details.has("fanart") && !details.get("fanart").getAsString().isEmpty()) | ||
{ | ||
String url = getDownloadUrl(details.get("fanart").getAsString()); | ||
if (url != null && !url.isEmpty()) | ||
med.setBackgroundImageUrl(XBMCImageContentProvider.GetImageUri(url).toString()); | ||
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(url).toString()); | ||
} | ||
|
||
String extension = ""; | ||
|
@@ -1024,21 +1019,21 @@ public class XBMCJsonRPC | |
{ | ||
String url = getDownloadUrl(details.get("thumbnail").getAsString()); | ||
if (url != null && !url.isEmpty()) | ||
med.setCardImageUrl(XBMCImageContentProvider.GetImageUri(url).toString()); | ||
med.setCardImageUrl(XBMCFileContentProvider.buildUri(url).toString()); | ||
} | ||
med.setCardImageAspectRatio("1:1"); | ||
if (details.has("fanart") && !details.get("fanart").getAsString().isEmpty()) | ||
{ | ||
String url = getDownloadUrl(details.get("fanart").getAsString()); | ||
if (url != null && !url.isEmpty()) | ||
med.setBackgroundImageUrl(XBMCImageContentProvider.GetImageUri(url).toString()); | ||
med.setBackgroundImageUrl(XBMCFileContentProvider.buildUri(url).toString()); | ||
} | ||
|
||
med.setXbmcUrl("videodb://musicvideos/titles/" + details.get("musicvideoid").getAsInt()); | ||
|
||
String url = getDownloadUrl(details.get("file").getAsString()); | ||
if (url != null && !url.isEmpty()) | ||
med.setVideoUrl(url); | ||
med.setVideoUrl(XBMCFileContentProvider.buildUri(url).toString()); | ||
|
||
med.setCategory(Media.MEDIA_TYPE_MUSICVIDEO); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,16 @@ import android.content.ContentValues; | |
import android.database.Cursor; | ||
import android.database.MatrixCursor; | ||
import android.net.Uri; | ||
import android.os.ParcelFileDescriptor; | ||
import android.util.Log; | ||
|
||
import @[email protected]; | ||
import @[email protected]; | ||
import @[email protected]; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.List; | ||
|
||
public class XBMCFileContentProvider extends XBMCContentProvider | ||
|
@@ -18,13 +24,21 @@ public class XBMCFileContentProvider extends XBMCContentProvider | |
|
||
private XBMCJsonRPC mJsonRPC = null; | ||
|
||
public static Uri buildUri(String path) | ||
public static Uri buildUri(String surl) | ||
{ | ||
if (surl == null) | ||
return null; | ||
if (surl.isEmpty()) | ||
return null; | ||
|
||
Uri.Builder builder = new Uri.Builder(); | ||
builder.scheme("content") | ||
.authority(AUTHORITY) | ||
.path(path); | ||
return builder.build(); | ||
.fragment(surl); | ||
|
||
Uri out = builder.build(); | ||
// Log.d(TAG, "GetImageUri: in:" + surl + " out:" + out.toString()); | ||
return out; | ||
} | ||
|
||
@Override | ||
|
@@ -66,8 +80,7 @@ public class XBMCFileContentProvider extends XBMCContentProvider | |
public Cursor query(Uri uri, String[] projection, String selection, | ||
String[] selectionArgs, String sortOrder) | ||
{ | ||
String path = uri.getPath(); | ||
String xbmcURL = "special://profile" + path; | ||
String xbmcURL = uri.getFragment(); | ||
|
||
List<File> files = mJsonRPC.getFiles(xbmcURL); | ||
if (files.isEmpty()) | ||
|
@@ -96,4 +109,77 @@ public class XBMCFileContentProvider extends XBMCContentProvider | |
} | ||
return mc; | ||
} | ||
|
||
@Override | ||
public ParcelFileDescriptor openFile(Uri uri, String mode) | ||
throws FileNotFoundException | ||
{ | ||
// Log.d(TAG, "openFile: " + uri.toString()); | ||
|
||
ParcelFileDescriptor[] pipe = null; | ||
|
||
try | ||
{ | ||
String decodedUrl = uri.getFragment(); | ||
// Log.d(TAG, " decodedUrl: " + decodedUrl); | ||
if (decodedUrl == null) | ||
return null; | ||
|
||
pipe = ParcelFileDescriptor.createPipe(); | ||
|
||
new XBMCFileContentProvider.TransferThread(decodedUrl, | ||
new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1])).start(); | ||
} | ||
catch (IOException e) | ||
{ | ||
Log.e(getClass().getSimpleName(), "Exception opening pipe", e); | ||
throw new FileNotFoundException("Could not open pipe for: " | ||
+ uri.toString()); | ||
} | ||
|
||
return (pipe[0]); | ||
} | ||
|
||
|
||
static class TransferThread extends Thread | ||
{ | ||
String path; | ||
OutputStream out; | ||
|
||
TransferThread(String path, OutputStream out) | ||
{ | ||
this.path = path; | ||
this.out = out; | ||
} | ||
|
||
@Override | ||
public void run() | ||
{ | ||
try | ||
{ | ||
XBMCFile in = new XBMCFile(); | ||
if (!in.Open(path)) | ||
{ | ||
out.flush(); | ||
out.close(); | ||
return; | ||
} | ||
|
||
while (!in.Eof()) | ||
{ | ||
byte[] buf = in.Read(); | ||
out.write(buf, 0, buf.length); | ||
} | ||
|
||
in.Close(); | ||
out.flush(); | ||
out.close(); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.e(getClass().getSimpleName(), "Exception transferring file", e); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.