Commit a7b9eec0 authored by Loris's avatar Loris
Browse files

u

parent 24c79cd7
package de.tonifetzer.sensorrecorder;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
......@@ -43,12 +44,14 @@ public class MainActivity extends AppCompatActivity {
private PhoneSensors phoneSensors;
private final Logger dataLogger = new Logger(this);
private final Sender sender = new Sender();
private final Sender sender = new Sender(this);
private String appUser;
private String appPosition;
private String TAG = MainActivity.class.getCanonicalName();
ProgressDialog progressDialog;
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -56,6 +59,9 @@ public class MainActivity extends AppCompatActivity {
sender.start();
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Uploading...");
//this is super ugly. normally we would use fragments to switch ui
mainView = getLayoutInflater().inflate(R.layout.activity_main, null);
setContentView(mainView);
......@@ -76,6 +82,7 @@ public class MainActivity extends AppCompatActivity {
txtViewFilename = findViewById(R.id.textViewFilename);
//set the listener
phoneSensors.setListener(new MySensor.SensorListener(){
@Override public void onData(final String csv) {}
......@@ -176,7 +183,7 @@ public class MainActivity extends AppCompatActivity {
public void fileSend() throws Exception {
for (File f : dataLogger.getFolder().getFolder().listFiles()) {
Log.d("FileSend", "startRecording: " + f);
sender.upload(f);
sender.upload(f, progressDialog);
}
}
}
......@@ -12,10 +12,8 @@ import retrofit2.http.Part;
public
interface ApiConfig {
@Multipart
@POST
@POST("/")
Call uploadFile(@Part MultipartBody.Part file, @Part RequestBody name);
@Multipart
@POST("retrofit_example/upload_multiple_files.php")
Call < ServerResponse > uploadMulFile(@Part List<MultipartBody.Part> files);
}
package de.tonifetzer.sensorrecorder.sender;
import android.app.ProgressDialog;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;
......@@ -14,44 +15,46 @@ import de.tonifetzer.sensorrecorder.sender.ApiConfig;
import de.tonifetzer.sensorrecorder.sender.AppConfig;
import de.tonifetzer.sensorrecorder.sender.ServerResponse;
import de.tonifetzer.sensorrecorder.sensors.Logger;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.Response;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public final class Sender {
private Context context;
private Logger dataLogger;
public void start() {
this.context = MainActivity.getAppContext();
dataLogger = new Logger(context);
}
public Sender() {
public Sender(Context context) {
this.context = context;
}
// Uploading Image/Video
public void upload(File file) {
//progressDialog.show();
public void upload(File file, ProgressDialog progressDialog) {
progressDialog.show();
// Map is used to multipart the file using okhttp3.RequestBody
// Parsing any Media type file
MultipartBody.Part fileToUpload;
RequestBody requestBody = RequestBody.create(MediaType.parse("*/*"), file);
fileToUpload = MultipartBody.Part.createFormData("file1", file.getName(), requestBody);
MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("file",
file.getName(), requestBody);
RequestBody fileName = RequestBody.create(MediaType.parse("text/plain"), file.getName());
ApiConfig getResponse = AppConfig.getRetrofit().create(ApiConfig.class);
retrofit2.Call<ServerResponse> call = getResponse.uploadFile(fileToUpload, requestBody);
call.enqueue(new retrofit2.Callback<ServerResponse> () {
Call<ServerResponse> call = getResponse.uploadFile(fileToUpload, fileName);
call.enqueue(new Callback<ServerResponse>() {
@Override
public void onResponse(retrofit2.Call<ServerResponse> call, retrofit2.Response<ServerResponse> response) {
public void onResponse(Call<ServerResponse> call, Response<ServerResponse> response) {
ServerResponse serverResponse = response.body();
if (serverResponse != null) {
if (serverResponse.getSuccess()) {
......@@ -63,11 +66,12 @@ public final class Sender {
assert serverResponse != null;
Log.v("Response", serverResponse.toString());
}
//progressDialog.dismiss();
progressDialog.dismiss();
}
@Override
public void onFailure(retrofit2.Call<ServerResponse> call, Throwable t) {
public void onFailure(Call<ServerResponse> call, Throwable t) {
}
});
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment