Add force update option

master
Piotro 2023-06-13 20:41:51 +02:00
rodzic f022840723
commit f6d3b58bcd
10 zmienionych plików z 99 dodań i 37 usunięć

Wyświetl plik

@ -96,6 +96,13 @@ public class MainActivity extends AppCompatActivity {
protected void onResume() {
super.onResume();
dataCollector.onResume();
// DESIGN: Should collectors be paused???? (loosing track)
}
@Override
protected void onPause() {
super.onPause();
dataCollector.onPause();
}
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1;

Wyświetl plik

@ -22,6 +22,11 @@ public class DataCollector implements Runnable {
private SondeHubCollector sh_col;
private LocalServerCollector lc_col;
private Thread rs_col_thread;
private Thread sh_col_thread;
private Thread lc_col_thread;
private Thread elapi_thread;
public GpsMyLocationProvider locationProvider;
public Orientation orientationProvider;
@ -73,7 +78,7 @@ public class DataCollector implements Runnable {
public void run() {
initCollectors();
Thread elapi_thread = new Thread(elapi);
elapi_thread = new Thread(elapi);
elapi_thread.start();
try {
@ -101,6 +106,8 @@ public class DataCollector implements Runnable {
if(lc_col != null)
lc_col.stop();
refresh();
rs_col = new RadiosondyCollector();
sh_col = new SondeHubCollector();
@ -110,21 +117,21 @@ public class DataCollector implements Runnable {
lc_col = new LocalServerCollector(sharedPref.getString("lsip",""));
Thread rs_thread = new Thread(rs_col, "rscol");
Thread sh_thread = new Thread(sh_col, "shcol");
Thread lc_thread = new Thread(lc_col, "lccol");
rs_col_thread = new Thread(rs_col, "rscol");
sh_col_thread = new Thread(sh_col, "shcol");
lc_col_thread = new Thread(lc_col, "lccol");
showSondeSet = true;
if(!sharedPref.getString("rsid", "").equals("")) {
rs_thread.start();
rs_col_thread.start();
showSondeSet = false;
}
if(!sharedPref.getString("shid", "").equals("")) {
sh_thread.start();
sh_col_thread.start();
showSondeSet = false;
}
if(!sharedPref.getString("lcid", "").equals("")) {
lc_thread.start();
lc_col_thread.start();
showSondeSet = false;
}
}
@ -168,7 +175,7 @@ public class DataCollector implements Runnable {
void updatePosition(Sonde sonde, String source) {
if (sonde == null) {
if (mapUpdater != null) {;
mapUpdater.updatePosition(null, "?", false, 0,0);
mapUpdater.updatePosition(null, "?", false, 0,0, 0);
}
return;
}
@ -205,7 +212,7 @@ public class DataCollector implements Runnable {
}
if (mapUpdater != null) {;
mapUpdater.updatePosition(sonde, source, vs_ok, posdist, bearing);
mapUpdater.updatePosition(sonde, source, vs_ok, posdist, bearing, elapi.alt);
}
}
@ -296,8 +303,29 @@ public class DataCollector implements Runnable {
compassUpdater.update(locationProvider.getLastKnownLocation(), trg, alt, orientationProvider.getAzimuth(), age);
}
public void refresh() {
if(rs_col_thread != null)
rs_col_thread.interrupt();
if(sh_col_thread != null)
sh_col_thread.interrupt();
if(lc_col_thread != null)
lc_col_thread.interrupt();
if(elapi_thread != null)
elapi_thread.interrupt();
}
public void onResume() {
locationProvider.startLocationProvider(null);
elapi.pause = false;
if (elapi_thread != null)
elapi_thread.interrupt();
}
public void onPause() {
elapi.pause = true;
if (elapi_thread != null)
elapi_thread.interrupt();
locationProvider.stopLocationProvider();
}
public void onDestroy() {

Wyświetl plik

@ -13,32 +13,35 @@ public class ElevationApi implements Runnable {
public float lon = 0;
public int alt = 0;
public volatile boolean pause = false;
@Override
public void run() {
try {
while (!Thread.currentThread().isInterrupted()) {
while (true) {
try {
URL url = new URL("https://api.open-meteo.com/v1/elevation?latitude=" + lat + "&longitude=" + lon);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
try {
URL url = new URL("https://api.open-meteo.com/v1/elevation?latitude=" + lat + "&longitude=" + lon);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
try {
System.err.println(conn.getResponseCode());
if (conn.getResponseCode() == 200) {
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder resp = new StringBuilder();
for (String line; (line = br.readLine()) != null; resp.append(line));
String data = resp.toString();
JSONObject json = new JSONObject(data);
alt = json.getJSONArray("elevation").getInt(0);
System.out.println("alt"+alt);
}
} finally {
conn.disconnect();
System.err.println(conn.getResponseCode());
if (conn.getResponseCode() == 200) {
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder resp = new StringBuilder();
for (String line; (line = br.readLine()) != null; resp.append(line));
String data = resp.toString();
JSONObject json = new JSONObject(data);
alt = json.getJSONArray("elevation").getInt(0);
System.out.println("alt"+alt);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
conn.disconnect();
}
Thread.sleep(30000);
}
} catch (InterruptedException ignored) {}
} catch (Exception e) {
e.printStackTrace();
}
try {
while (!Thread.currentThread().isInterrupted())
Thread.sleep(30000);
} catch (InterruptedException ignored) {}
}
}
}

Wyświetl plik

@ -44,6 +44,7 @@ public class LocalServerCollector implements Runnable {
try {
Thread.sleep(2000);
} catch (InterruptedException ignored) {}
boolean ignored = Thread.interrupted();
}
}

Wyświetl plik

@ -73,6 +73,7 @@ public class RadiosondyCollector implements Runnable {
try {
Thread.sleep(15000);
} catch (InterruptedException ignored) {}
boolean ignored = Thread.interrupted();
}
}

Wyświetl plik

@ -53,9 +53,9 @@ public class SondeHubCollector implements Runnable {
while (!stop) {
downloadPrediction();
try {
Thread.sleep(30000);
} catch (InterruptedException ignored) {
}
Thread.sleep(30000);
} catch (InterruptedException ignored) {}
boolean ignored = Thread.interrupted();
}
}

Wyświetl plik

@ -84,6 +84,11 @@ public class HomeFragment extends Fragment {
v.findViewById(R.id.predbtn).setOnClickListener((_v) -> {
mapView.getController().animateTo(updater.last_pred);
});
v.findViewById(R.id.refrbtn).setOnClickListener((_v) -> {
try {
((MainActivity)getActivity()).dataCollector.refresh();
} catch (Exception ignored) {}
});
}
@Override

Wyświetl plik

@ -31,7 +31,6 @@ import eu.piotro.sondechaser.data.SondeHubCollector;
public class MapUpdater {
private HomeFragment homeFragment;
private ElevationApi elapi = new ElevationApi();
private Marker sondeMarker;
@ -133,7 +132,7 @@ public class MapUpdater {
homeFragment.mapView.getOverlays().add(localPathLine);
}
public void updatePosition(Sonde sonde, String source, boolean vs_ok, double posdist, double bearing) {
public void updatePosition(Sonde sonde, String source, boolean vs_ok, double posdist, double bearing, int elapi_alt) {
if (sonde == null) {
homeFragment.requireActivity().runOnUiThread(() -> {
((TextView) homeFragment.requireView().findViewById(R.id.textsid)).setText("N/A");
@ -177,7 +176,7 @@ public class MapUpdater {
((TextView) homeFragment.requireView().findViewById(R.id.textsid)).setText(sonde.sid == null ? "N/A" : sonde.sid);
((TextView) homeFragment.requireView().findViewById(R.id.textfreq)).setText(sonde.freq == null ? "N/A" : sonde.freq);
((TextView) homeFragment.requireView().findViewById(R.id.textalt)).setText(sonde.alt + " m");
((TextView) homeFragment.requireView().findViewById(R.id.textaog)).setText(sonde.alt - elapi.alt + " m");
((TextView) homeFragment.requireView().findViewById(R.id.textaog)).setText(sonde.alt - elapi_alt + " m");
((TextView) homeFragment.requireView().findViewById(R.id.textvspeed)).setText(vs_ok ? sonde.vspeed + " m/s" :
((sonde.vspeed >= 0 ? "+?" : "-?") + " (r: "+Math.abs(sonde.vspeed)+")"));
homeFragment.requireView().findViewById(R.id.imagevsarrow).setRotation(180 * ((sonde.vspeed < 0) ? 1 : 0));

Wyświetl plik

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
</vector>

Wyświetl plik

@ -39,6 +39,19 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ImageButton
android:id="@+id/refrbtn"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="5dp"
android:layout_marginBottom="5dp"
android:cropToPadding="false"
android:padding="7dp"
android:scaleType="fitCenter"
android:src="@drawable/baseline_refresh_24"
app:layout_constraintBottom_toTopOf="@+id/predbtn"
app:layout_constraintStart_toStartOf="parent" />
<ImageButton
android:id="@+id/northbtn"
style="@android:style/Widget.DeviceDefault.ImageButton"