Browse Source

Downloads fixes

pull/24/head
Ezerous 8 years ago
parent
commit
e7488c1524
  1. 12
      app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java
  2. 8
      app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java
  3. 9
      app/src/main/res/drawable/ic_file_download.xml

12
app/src/main/java/gr/thmmy/mthmmy/receiver/Receiver.java

@ -29,8 +29,7 @@ import static gr.thmmy.mthmmy.services.DownloadService.STARTED;
public class Receiver extends BroadcastReceiver { public class Receiver extends BroadcastReceiver {
public Receiver() { public Receiver() {}
}
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
@ -48,11 +47,11 @@ public class Receiver extends BroadcastReceiver {
builder.setContentTitle(title) builder.setContentTitle(title)
.setContentText(text) .setContentText(text)
.setTicker(ticker) .setTicker(ticker)
.setAutoCancel(true) .setAutoCancel(true);
.setSmallIcon(R.drawable.ic_file_download);
if (state.equals(STARTED)) if (state.equals(STARTED))
builder.setOngoing(true); builder.setOngoing(true)
.setSmallIcon(android.R.drawable.stat_sys_download);
else if (state.equals(COMPLETED)) { else if (state.equals(COMPLETED)) {
String fileName = extras.getString(EXTRA_FILE_NAME, "NONE"); String fileName = extras.getString(EXTRA_FILE_NAME, "NONE");
@ -68,7 +67,8 @@ public class Receiver extends BroadcastReceiver {
Intent chooser = Intent.createChooser(chooserIntent, "Open With..."); Intent chooser = Intent.createChooser(chooserIntent, "Open With...");
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, chooser, PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, chooser, PendingIntent.FLAG_CANCEL_CURRENT);
builder.setContentIntent(pendingIntent); builder.setContentIntent(pendingIntent)
.setSmallIcon(android.R.drawable.stat_sys_download_done);
} else } else
Timber.w("File doesn't exist."); Timber.w("File doesn't exist.");

8
app/src/main/java/gr/thmmy/mthmmy/services/DownloadService.java

@ -106,9 +106,9 @@ public class DownloadService extends IntentService {
Request request = new Request.Builder().url(downloadLink).build(); Request request = new Request.Builder().url(downloadLink).build();
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
String contentType = response.headers("Content-Type").toString(); //check if link provides a binary file String contentDisposition = response.headers("Content-Disposition").toString(); //check if link provides an attachment
if (contentType.equals("[application/octet-stream]")) { if (contentDisposition.contains("attachment")){
fileName = response.headers("Content-Disposition").toString().split("\"")[1]; fileName = contentDisposition.split("\"")[1];
File dirPath = new File(SAVE_DIR); File dirPath = new File(SAVE_DIR);
if (!dirPath.isDirectory()) { if (!dirPath.isDirectory()) {
@ -150,7 +150,7 @@ public class DownloadService extends IntentService {
Timber.i("Download OK!"); Timber.i("Download OK!");
sendNotification(downloadId, COMPLETED, fileName); sendNotification(downloadId, COMPLETED, fileName);
} else } else
Timber.e("Response not a binary file!"); Timber.e("No attachment in response!");
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Timber.i("Download failed..."); Timber.i("Download failed...");
Timber.e(e, "FileNotFound"); Timber.e(e, "FileNotFound");

9
app/src/main/res/drawable/ic_file_download.xml

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#ffffff"
android:pathData="M19,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z"/>
</vector>
Loading…
Cancel
Save