Resource Download Android 10 Compatibility

This commit is contained in:
Sebastian Seedorf
2019-10-28 22:20:44 +01:00
parent 22b42ff3f4
commit 98d04cb810
6 changed files with 69 additions and 11 deletions

View File

@@ -2,6 +2,7 @@ package de.sebse.fuplanner.fragments.moddetails;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@@ -102,8 +103,20 @@ public class ModDetailAnnounceFragment extends Fragment implements Download.OnDo
return;
mListener.getKVV(kvv -> {
kvv.modules().list().find(mItemPos, (Modules.Module module) -> {
String folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
folderName += "/Announcement";
String folderName;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (module.semester != null) {
folderName = module.semester.toString();
} else {
folderName = "PROJ";
}
folderName += "-" + module.title.replaceAll("[:*<>|/\"\\\\]", "-");
folderName += "/Announcements";
} else {
folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
folderName += "/Announcement";
}
getDownload().openDownloadDialog(title, url, folderName);
}, log::e);
});

View File

@@ -2,6 +2,7 @@ package de.sebse.fuplanner.fragments.moddetails;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@@ -102,8 +103,20 @@ public class ModDetailAssignmentFragment extends Fragment implements Download.On
return;
mListener.getKVV(kvv -> {
kvv.modules().list().find(mItemPos, (Modules.Module module) -> {
String folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
folderName += "/Announcement";
String folderName;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (module.semester != null) {
folderName = module.semester.toString();
} else {
folderName = "PROJ";
}
folderName += "-" + module.title.replaceAll("[:*<>|/\"\\\\]", "-");
folderName += "/Assignments";
} else {
folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
folderName += "/Assignment";
}
getDownload().openDownloadDialog(title, url, folderName);
}, log::e);
});

View File

@@ -2,6 +2,7 @@ package de.sebse.fuplanner.fragments.moddetails;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@@ -92,7 +93,18 @@ public class ModDetailResourceFragment extends Fragment implements Download.OnDo
} else if (node.getContent() instanceof Resource.File && ModDetailResourceFragment.this.mListener != null) { // if leaf is file
ModDetailResourceFragment.this.mListener.getKVV(kvv -> {
kvv.modules().resources().recv(mItemPos, (Modules.Module module) -> {
String folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
String folderName;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (module.semester != null) {
folderName = module.semester.toString();
} else {
folderName = "PROJ";
}
folderName += "-" + module.title.replaceAll("[:*<>|/\"\\\\]", "-");
folderName += "/Resources";
} else {
folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
}
Resource.File file = (Resource.File) node.getContent();
getDownload().openDownloadDialog(file, folderName);
}, log::e);

View File

@@ -1,6 +1,7 @@
package de.sebse.fuplanner.services.kvv;
import android.content.Context;
import android.os.Build;
import android.os.Environment;
import androidx.core.content.ContextCompat;
@@ -369,10 +370,15 @@ public class ModulesResources extends PartModules<ArrayList<Resource>> {
}
private String saveFileInDownloads(String filename, byte[] data, String moduleName) {
// Saves file in folder: DOWNLOADS/moduleName
File folder = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS), moduleName);
//ContextCompat.checkSelfPermission(getContext(), )
log.d("FILE", folder.toString());
File folder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
folder = new File(getContext().getExternalFilesDir(
Environment.DIRECTORY_DOWNLOADS), moduleName);
} else {
folder = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS), moduleName);
}
if (!folder.mkdirs()) {
log.w( "Directory not created");
}

View File

@@ -2,6 +2,7 @@ package de.sebse.fuplanner.services.kvv.types;
import java.io.Serializable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import de.sebse.fuplanner.tools.Regex;
@@ -52,4 +53,10 @@ public class Semester implements Serializable {
}
return false;
}
@NonNull
@Override
public String toString() {
return (type == SEM_SS ? "SS" : "WS") + year;
}
}

View File

@@ -7,6 +7,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import java.io.File;
@@ -47,8 +48,14 @@ public class Download {
if (context == null)
return;
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
File f = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS)+"/"+folderName+"/"+file.getTitle());
File f;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
f = new File(context.getExternalFilesDir(
Environment.DIRECTORY_DOWNLOADS) + "/" + folderName + "/" + file.getTitle());
} else {
f = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS) + "/" + folderName + "/" + file.getTitle());
}
Resources resources = context.getResources();
String message = "";
if (file.getAuthor() != null && !file.getAuthor().isEmpty())