Delete TransferService revert to native DL/UP

This commit is contained in:
lionel
2021-01-12 11:26:36 +01:00
parent 5388ef79eb
commit bb63f3b623
6 changed files with 62 additions and 156 deletions

View File

@ -1,75 +0,0 @@
package com.localtransfer;
import android.app.IntentService;
import android.content.Intent;
import android.net.Uri;
import android.widget.Button;
import android.widget.LinearLayout;
import java.io.IOException;
public class TransferService extends IntentService {
public static final String ACTION_UPLOAD = "com.localtransfer.action.FOO";
public static final String ACTION_DOWNLOAD = "com.localtransfer.action.BAZ";
public static final String EXTRA_URI = "com.localtransfer.extra.URI";
public static final String EXTRA = "com.localtransfer.extra.EXTRA";
public TransferService() {
super("TransferService");
}
@Override
protected void onHandleIntent(Intent intent) {
if (intent != null) {
final String action = intent.getAction();
switch (action) {
case ACTION_UPLOAD:
handleUpload(intent);
break;
case ACTION_DOWNLOAD:
handleDownload(intent);
break;
}
}
}
private void handleUpload(Intent intent) {
final Uri uri = intent.getParcelableExtra(EXTRA_URI);
Transfer tr = new Transfer();
try {
tr.uploadFile(uri);
} catch (IOException e) {
final String ExceptionName = e.getClass().getSimpleName();
final String ExceptionMess = e.getMessage();
if(ExceptionName != null && ExceptionMess != null) {
Transfer.error(ExceptionName + ": " + ExceptionMess, null, null);
}
}
}
private void handleDownload(Intent intent) {
Extra ex = (Extra) intent.getExtras().getParcelable(EXTRA);
final LinearLayout layout = Transfer.activity.findViewById(ex.id);
Button button = null;
if(layout != null)
button = layout.findViewById(R.id.file_download);
Transfer tr = new Transfer();
try {
tr.downloadFile(Uri.parse(ex.uri), ex.name, ex.size, ex.href, button);
} catch (IOException e) {
final String ExceptionName = e.getClass().getSimpleName();
final String ExceptionMess = e.getMessage();
if(ExceptionName != null && ExceptionMess != null) {
Transfer.error(ExceptionName + ": " + ExceptionMess, null, null);
}
}
}
}