Resource Download Android 10 Compatibility
This commit is contained in:
@@ -2,6 +2,7 @@ package de.sebse.fuplanner.fragments.moddetails;
|
|||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -102,8 +103,20 @@ public class ModDetailAnnounceFragment extends Fragment implements Download.OnDo
|
|||||||
return;
|
return;
|
||||||
mListener.getKVV(kvv -> {
|
mListener.getKVV(kvv -> {
|
||||||
kvv.modules().list().find(mItemPos, (Modules.Module module) -> {
|
kvv.modules().list().find(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 += "/Announcements";
|
||||||
|
} else {
|
||||||
|
folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
||||||
folderName += "/Announcement";
|
folderName += "/Announcement";
|
||||||
|
}
|
||||||
|
|
||||||
getDownload().openDownloadDialog(title, url, folderName);
|
getDownload().openDownloadDialog(title, url, folderName);
|
||||||
}, log::e);
|
}, log::e);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package de.sebse.fuplanner.fragments.moddetails;
|
|||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -102,8 +103,20 @@ public class ModDetailAssignmentFragment extends Fragment implements Download.On
|
|||||||
return;
|
return;
|
||||||
mListener.getKVV(kvv -> {
|
mListener.getKVV(kvv -> {
|
||||||
kvv.modules().list().find(mItemPos, (Modules.Module module) -> {
|
kvv.modules().list().find(mItemPos, (Modules.Module module) -> {
|
||||||
String folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
String folderName;
|
||||||
folderName += "/Announcement";
|
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);
|
getDownload().openDownloadDialog(title, url, folderName);
|
||||||
}, log::e);
|
}, log::e);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package de.sebse.fuplanner.fragments.moddetails;
|
|||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
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
|
} else if (node.getContent() instanceof Resource.File && ModDetailResourceFragment.this.mListener != null) { // if leaf is file
|
||||||
ModDetailResourceFragment.this.mListener.getKVV(kvv -> {
|
ModDetailResourceFragment.this.mListener.getKVV(kvv -> {
|
||||||
kvv.modules().resources().recv(mItemPos, (Modules.Module module) -> {
|
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();
|
Resource.File file = (Resource.File) node.getContent();
|
||||||
getDownload().openDownloadDialog(file, folderName);
|
getDownload().openDownloadDialog(file, folderName);
|
||||||
}, log::e);
|
}, log::e);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package de.sebse.fuplanner.services.kvv;
|
package de.sebse.fuplanner.services.kvv;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
|
||||||
import androidx.core.content.ContextCompat;
|
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) {
|
private String saveFileInDownloads(String filename, byte[] data, String moduleName) {
|
||||||
// Saves file in folder: DOWNLOADS/moduleName
|
// Saves file in folder: DOWNLOADS/moduleName
|
||||||
File folder = new File(Environment.getExternalStoragePublicDirectory(
|
File folder;
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
folder = new File(getContext().getExternalFilesDir(
|
||||||
Environment.DIRECTORY_DOWNLOADS), moduleName);
|
Environment.DIRECTORY_DOWNLOADS), moduleName);
|
||||||
//ContextCompat.checkSelfPermission(getContext(), )
|
} else {
|
||||||
log.d("FILE", folder.toString());
|
folder = new File(Environment.getExternalStoragePublicDirectory(
|
||||||
|
Environment.DIRECTORY_DOWNLOADS), moduleName);
|
||||||
|
}
|
||||||
if (!folder.mkdirs()) {
|
if (!folder.mkdirs()) {
|
||||||
log.w( "Directory not created");
|
log.w( "Directory not created");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package de.sebse.fuplanner.services.kvv.types;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import de.sebse.fuplanner.tools.Regex;
|
import de.sebse.fuplanner.tools.Regex;
|
||||||
|
|
||||||
@@ -52,4 +53,10 @@ public class Semester implements Serializable {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return (type == SEM_SS ? "SS" : "WS") + year;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.content.Intent;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -47,8 +48,14 @@ public class Download {
|
|||||||
if (context == null)
|
if (context == null)
|
||||||
return;
|
return;
|
||||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
|
||||||
File f = new File(Environment.getExternalStoragePublicDirectory(
|
File f;
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
f = new File(context.getExternalFilesDir(
|
||||||
Environment.DIRECTORY_DOWNLOADS) + "/" + folderName + "/" + file.getTitle());
|
Environment.DIRECTORY_DOWNLOADS) + "/" + folderName + "/" + file.getTitle());
|
||||||
|
} else {
|
||||||
|
f = new File(Environment.getExternalStoragePublicDirectory(
|
||||||
|
Environment.DIRECTORY_DOWNLOADS) + "/" + folderName + "/" + file.getTitle());
|
||||||
|
}
|
||||||
Resources resources = context.getResources();
|
Resources resources = context.getResources();
|
||||||
String message = "";
|
String message = "";
|
||||||
if (file.getAuthor() != null && !file.getAuthor().isEmpty())
|
if (file.getAuthor() != null && !file.getAuthor().isEmpty())
|
||||||
|
|||||||
Reference in New Issue
Block a user