fix/get-all-stations-hangout
Mateusz Lubecki 2021-10-16 22:41:14 +02:00
rodzic 1907b88bbd
commit aa992cb23a
6 zmienionych plików z 147 dodań i 3 usunięć

Wyświetl plik

@ -55,5 +55,8 @@ dependencies {
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
implementation 'com.jakewharton.threetenabp:threetenabp:1.2.1'
implementation 'org.greenrobot:eventbus:3.0.0'
implementation 'org.apache.poi:poi:3.12'
// implementation 'org.apache.poi:poi-ooxml:3.12'
implementation 'com.fasterxml:aalto-xml:1.0.0'
}

Wyświetl plik

@ -1,9 +1,12 @@
package cc.pogoda.mobile.pogodacc.activity;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.FileUtils;
import android.text.Editable;
import android.view.View;
import android.widget.ArrayAdapter;
@ -90,9 +93,35 @@ public class ExportDataActivity extends AppCompatActivity {
}
public int getOutputFormat() {
String selected = outputFormat.getSelectedItem().toString();
switch (selected) {
case "CSV" : return 1;
case "MS Excel XLSX": return 2;
}
return -1;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
String s;
if (requestCode == 123 && resultCode == RESULT_OK) {
Uri uri = data.getData();
s = uri.getPath();
FileUtils.
System.out.println(s);
}
super.onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Wyświetl plik

@ -1,9 +1,12 @@
package cc.pogoda.mobile.pogodacc.activity.handler;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import cc.pogoda.mobile.pogodacc.activity.ExportDataActivity;
import cc.pogoda.mobile.pogodacc.dao.StationDataDao;
import cc.pogoda.mobile.pogodacc.file.ExcelExport;
import cc.pogoda.mobile.pogodacc.type.WeatherStation;
import cc.pogoda.mobile.pogodacc.type.web.ListOfStationData;
@ -15,6 +18,17 @@ public class ExportDataActStartButtonClickEvent implements View.OnClickListener{
activity = act;
}
public void openDirectory(Uri uriToLoad) {
// Choose a directory using the system's file picker.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
// Optionally, specify a URI for the directory that should be opened in
// the system file picker when it loads.
//intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, uriToLoad);
activity.startActivityForResult(intent, 123);
}
@Override
public void onClick(View view) {
@ -30,6 +44,16 @@ public class ExportDataActStartButtonClickEvent implements View.OnClickListener{
ListOfStationData stationData = stationDataDao.getLastStationData(toExport.getSystemName(), timestampStart, timestampStop);
int format = activity.getOutputFormat();
openDirectory(null);
if (format == 2) {
ExcelExport.exportToExcel(stationData, toExport, activity.getApplicationContext());
}
}
}

Wyświetl plik

@ -8,7 +8,6 @@ import cc.pogoda.mobile.pogodacc.web.TrendConsumer;
import retrofit2.Response;
public class TrendDao {
RestClientConfig restClient;
Response<Trend> trend;
@ -16,6 +15,8 @@ public class TrendDao {
class Worker implements Runnable {
RestClientConfig restClient;
@Override
public void run() {
@ -27,7 +28,7 @@ public class TrendDao {
trend = trendConsumer.getTrendForStation(station).execute();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
@ -47,6 +48,9 @@ public class TrendDao {
} catch (InterruptedException e) {
e.printStackTrace();
}
catch (NullPointerException e) {
e.printStackTrace();
}
return out;
}

Wyświetl plik

@ -0,0 +1,75 @@
package cc.pogoda.mobile.pogodacc.file;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.DocumentsContract;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import cc.pogoda.mobile.pogodacc.type.WeatherStation;
import cc.pogoda.mobile.pogodacc.type.web.ListOfStationData;
public class ExcelExport {
public static boolean exportToExcel(ListOfStationData data, WeatherStation station, Context context) {
Cell cell;
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet(station.getSystemName());
Row header = sheet.createRow(3);
cell = header.createCell(0);
cell.setCellValue("UNIX Epoch Timestamp");
cell = header.createCell(1);
cell.setCellValue("Date / Time");
cell = header.createCell(2);
cell.setCellValue("Temperature");
cell = header.createCell(3);
cell.setCellValue("QNH pressure");
cell = header.createCell(4);
cell.setCellValue("Humidity");
cell = header.createCell(5);
cell.setCellValue("Wind Direction");
cell = header.createCell(6);
cell.setCellValue("Wind Average Speed");
cell = header.createCell(7);
cell.setCellValue("Wind Gusts");
File file = new File(context.getExternalFilesDir(null), "test.xls");
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(file);
workbook.write(fileOutputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return true;
}
}

Wyświetl plik

@ -3,6 +3,8 @@ package cc.pogoda.mobile.pogodacc.web;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.concurrent.TimeUnit;
import cc.pogoda.mobile.pogodacc.type.CustomLocalDateTime;
import cc.pogoda.mobile.pogodacc.web.deserializer.CustomLocalDateTimeDeserializer;
import okhttp3.OkHttpClient;
@ -16,7 +18,14 @@ public class RestClientConfig {
Gson gson = new GsonBuilder().registerTypeAdapter(CustomLocalDateTime.class, new CustomLocalDateTimeDeserializer()).setLenient().create();
OkHttpClient client = new OkHttpClient();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.readTimeout(20, TimeUnit.SECONDS);
builder.writeTimeout(20, TimeUnit.SECONDS);
builder.connectTimeout(20, TimeUnit.SECONDS);
builder.callTimeout(20, TimeUnit.SECONDS);
OkHttpClient client = builder.build();//new OkHttpClient(builder);
out = new Retrofit.Builder().baseUrl("http://pogoda.cc:8080/").addConverterFactory(GsonConverterFactory.create(gson)).client(client).build();