mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-18 06:37:47 +01:00
Fix crash when opening GPX file, reformat code
This commit is contained in:
parent
c3887ddb86
commit
c20810059d
@ -55,16 +55,12 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_summary_details);
|
setContentView(R.layout.activity_summary_details);
|
||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
|
|
||||||
//if (true) return;
|
mGBDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
||||||
|
|
||||||
GBDevice device = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
|
||||||
mGBDevice = device;
|
|
||||||
|
|
||||||
ActivitySummary summary = (ActivitySummary) intent.getSerializableExtra("summary");
|
ActivitySummary summary = (ActivitySummary) intent.getSerializableExtra("summary");
|
||||||
|
|
||||||
@ -73,13 +69,11 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
show_track_btn.setVisibility(View.GONE);
|
show_track_btn.setVisibility(View.GONE);
|
||||||
|
|
||||||
if (gpxTrack != null) {
|
if (gpxTrack != null) {
|
||||||
ActivityTrack activityTrack = new ActivityTrack();
|
|
||||||
|
|
||||||
show_track_btn.setVisibility(View.VISIBLE);
|
show_track_btn.setVisibility(View.VISIBLE);
|
||||||
show_track_btn.setOnClickListener(new View.OnClickListener() {
|
show_track_btn.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
try {
|
try {
|
||||||
AndroidUtils.viewFile(gpxTrack, Intent.ACTION_VIEW, getApplicationContext());
|
AndroidUtils.viewFile(gpxTrack, Intent.ACTION_VIEW, ActivitySummaryDetail.this);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
GB.toast(getApplicationContext(), "Unable to display GPX track: " + e.getMessage(), Toast.LENGTH_LONG, GB.ERROR, e);
|
GB.toast(getApplicationContext(), "Unable to display GPX track: " + e.getMessage(), Toast.LENGTH_LONG, GB.ERROR, e);
|
||||||
}
|
}
|
||||||
@ -90,17 +84,16 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
LOG.debug("petr summary: " + summary + "," + summary.getSummaryData());
|
LOG.debug("petr summary: " + summary + "," + summary.getSummaryData());
|
||||||
String activitykind = ActivityKind.asString(summary.getActivityKind(), getApplicationContext());
|
String activitykind = ActivityKind.asString(summary.getActivityKind(), getApplicationContext());
|
||||||
|
|
||||||
|
|
||||||
String starttime = DateTimeUtils.formatDateTime(summary.getStartTime());
|
String starttime = DateTimeUtils.formatDateTime(summary.getStartTime());
|
||||||
String endtime = DateTimeUtils.formatDateTime(summary.getEndTime());
|
String endtime = DateTimeUtils.formatDateTime(summary.getEndTime());
|
||||||
Long startTs = summary.getStartTime().getTime() / 1000;
|
long startTs = summary.getStartTime().getTime() / 1000;
|
||||||
Long endTs = summary.getEndTime().getTime() / 1000;
|
long endTs = summary.getEndTime().getTime() / 1000;
|
||||||
Long durationms = (summary.getEndTime().getTime() - summary.getStartTime().getTime());
|
long durationms = (summary.getEndTime().getTime() - summary.getStartTime().getTime());
|
||||||
String durationhms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(durationms),
|
String durationhms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(durationms),
|
||||||
TimeUnit.MILLISECONDS.toMinutes(durationms) % TimeUnit.HOURS.toMinutes(1),
|
TimeUnit.MILLISECONDS.toMinutes(durationms) % TimeUnit.HOURS.toMinutes(1),
|
||||||
TimeUnit.MILLISECONDS.toSeconds(durationms) % TimeUnit.MINUTES.toSeconds(1));
|
TimeUnit.MILLISECONDS.toSeconds(durationms) % TimeUnit.MINUTES.toSeconds(1));
|
||||||
|
|
||||||
int steps = getSteps(startTs.intValue(), endTs.intValue());
|
int steps = getSteps((int) startTs, (int) endTs);
|
||||||
|
|
||||||
ImageView activity_icon = (ImageView) findViewById(R.id.item_image);
|
ImageView activity_icon = (ImageView) findViewById(R.id.item_image);
|
||||||
activity_icon.setImageResource(ActivityKind.getIconId(summary.getActivityKind()));
|
activity_icon.setImageResource(ActivityKind.getIconId(summary.getActivityKind()));
|
||||||
@ -113,7 +106,6 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
TextView activity_duration = (TextView) findViewById(R.id.duration);
|
TextView activity_duration = (TextView) findViewById(R.id.duration);
|
||||||
activity_duration.setText(durationhms);
|
activity_duration.setText(durationhms);
|
||||||
|
|
||||||
|
|
||||||
JSONObject summaryData = null;
|
JSONObject summaryData = null;
|
||||||
String sumData = summary.getSummaryData();
|
String sumData = summary.getSummaryData();
|
||||||
if (sumData != null) {
|
if (sumData != null) {
|
||||||
@ -123,7 +115,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String summaryDatastr = "";
|
StringBuilder summaryDatastr = new StringBuilder();
|
||||||
|
|
||||||
if (summaryData == null) return;
|
if (summaryData == null) return;
|
||||||
|
|
||||||
@ -135,40 +127,31 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
LOG.debug("petr key:" + key);
|
LOG.debug("petr key:" + key);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
LOG.debug("petr" + key + ": " + summaryData.get(key) + "\n");
|
LOG.debug("petr" + key + ": " + summaryData.get(key) + "\n");
|
||||||
DecimalFormat df = new DecimalFormat("#.##");
|
DecimalFormat df = new DecimalFormat("#.##");
|
||||||
JSONObject innerData = (JSONObject) summaryData.get(key);
|
JSONObject innerData = (JSONObject) summaryData.get(key);
|
||||||
Object value = innerData.get("value");
|
Object value = innerData.get("value");
|
||||||
String unit = innerData.getString("unit");
|
String unit = innerData.getString("unit");
|
||||||
summaryDatastr += String.format("%s: %s %s\n", key, df.format(value), unit);
|
summaryDatastr.append(String.format("%s: %s %s\n", key, df.format(value), unit));
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TextView details = (TextView) findViewById(R.id.details);
|
TextView details = (TextView) findViewById(R.id.details);
|
||||||
|
details.setText(summaryDatastr.toString());
|
||||||
details.setText(summaryDatastr);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private int getSteps(int tsStart, int tsEnd) {
|
private int getSteps(int tsStart, int tsEnd) {
|
||||||
|
|
||||||
try (DBHandler handler = GBApplication.acquireDB()) {
|
try (DBHandler handler = GBApplication.acquireDB()) {
|
||||||
DailyTotals dt = new DailyTotals();
|
DailyTotals dt = new DailyTotals();
|
||||||
ActivityAnalysis analysis = new ActivityAnalysis();
|
ActivityAnalysis analysis = new ActivityAnalysis();
|
||||||
ActivityAmounts amountsSteps;
|
ActivityAmounts amountsSteps;
|
||||||
amountsSteps = analysis.calculateActivityAmounts(dt.getSamples(handler, mGBDevice, tsStart, tsEnd));
|
amountsSteps = analysis.calculateActivityAmounts(dt.getSamples(handler, mGBDevice, tsStart, tsEnd));
|
||||||
return (int) dt.getTotalsStepsForActivityAmounts(amountsSteps);
|
return (int) dt.getTotalsStepsForActivityAmounts(amountsSteps);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
GB.toast("Error loading activity steps.", Toast.LENGTH_SHORT, GB.ERROR, e);
|
GB.toast("Error loading activity steps.", Toast.LENGTH_SHORT, GB.ERROR, e);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user