Skip to content

Commit 06e8e00

Browse files
committed
TimeAsXAxisLabelFormatter -> kt
1 parent 83fc6a0 commit 06e8e00

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
1-
package info.nightscout.core.graph.data;
1+
package info.nightscout.core.graph.data
22

3-
import com.jjoe64.graphview.DefaultLabelFormatter;
4-
5-
import java.text.DateFormat;
6-
import java.text.SimpleDateFormat;
7-
import java.util.Locale;
3+
import com.jjoe64.graphview.DefaultLabelFormatter
4+
import java.text.DateFormat
5+
import java.text.SimpleDateFormat
6+
import java.util.Locale
87

98
/**
109
* Created by mike on 09.06.2016.
1110
*/
12-
public class TimeAsXAxisLabelFormatter extends DefaultLabelFormatter {
13-
14-
protected final String mFormat;
15-
16-
public TimeAsXAxisLabelFormatter(String format) {
17-
mFormat = format;
18-
}
11+
class TimeAsXAxisLabelFormatter(private val format: String) : DefaultLabelFormatter() {
1912

20-
@Override
21-
public String formatLabel(double value, boolean isValueX) {
13+
override fun formatLabel(value: Double, isValueX: Boolean): String =
2214
if (isValueX) {
2315
// format as date
24-
DateFormat dateFormat = new SimpleDateFormat(mFormat, Locale.getDefault());
25-
return dateFormat.format((long) value);
16+
val dateFormat: DateFormat = SimpleDateFormat(format, Locale.getDefault())
17+
dateFormat.format(value.toLong())
2618
} else {
2719
try {
2820
// unknown reason for crashing on this
@@ -33,11 +25,9 @@ public String formatLabel(double value, boolean isValueX) {
3325
// com.jjoe64.graphview.GridLabelRenderer.drawVerticalSteps (GridLabelRenderer.java:1057)
3426
// com.jjoe64.graphview.GridLabelRenderer.draw (GridLabelRenderer.java:866)
3527
// com.jjoe64.graphview.GraphView.onDraw (GraphView.java:296)
36-
//noinspection ConstantConditions
37-
return super.formatLabel(value, isValueX);
38-
} catch (Exception ignored) {
39-
return "";
28+
super.formatLabel(value, false)
29+
} catch (ignored: Exception) {
30+
""
4031
}
4132
}
42-
}
4333
}

0 commit comments

Comments
 (0)