[API] Implement Idziennik homework attachment downloading. Change attachment events to sticky.

This commit is contained in:
Kuba Szczodrzyński
2020-04-01 21:49:05 +02:00
parent 9303483470
commit 12d8de1def
13 changed files with 209 additions and 23 deletions

View File

@ -19,7 +19,7 @@ import okhttp3.internal.Util;
* <p>Time : 下午2:39.</p>
*/
public class FileCallbackHandler extends AbsCallbackHandler<File> {
final private File file;
private File file;
final private static int BUFFER_SIZE = 4096;
public FileCallbackHandler(Context context){
@ -66,6 +66,14 @@ public class FileCallbackHandler extends AbsCallbackHandler<File> {
if (file == null){
throw new IllegalArgumentException("File == null");
}
if (this.file.isDirectory()) {
String contentDisposition = response.header("content-disposition");
if (contentDisposition != null) {
String filename = contentDisposition.substring(contentDisposition.indexOf("\"")+1, contentDisposition.lastIndexOf("\""));
this.file = new File(file, filename);
file = this.file;
}
}
InputStream instream = response.body().byteStream();
long contentLength = response.body().contentLength();
FileOutputStream buffer = new FileOutputStream(file);