1package eu.siacs.conversations.entities;
2
3import androidx.annotation.DrawableRes;
4
5import com.google.common.base.Strings;
6
7import eu.siacs.conversations.R;
8
9public class RtpSessionStatus {
10
11 public final boolean successful;
12 public final long duration;
13
14
15 public RtpSessionStatus(boolean successful, long duration) {
16 this.successful = successful;
17 this.duration = duration;
18 }
19
20 @Override
21 public String toString() {
22 return successful + ":" + duration;
23 }
24
25 public static RtpSessionStatus of(final String body) {
26 final String[] parts = Strings.nullToEmpty(body).split(":", 2);
27 long duration = 0;
28 if (parts.length == 2) {
29 try {
30 duration = Long.parseLong(parts[1]);
31 } catch (NumberFormatException e) {
32 //do nothing
33 }
34 }
35 boolean made;
36 try {
37 made = Boolean.parseBoolean(parts[0]);
38 } catch (Exception e) {
39 made = false;
40 }
41 return new RtpSessionStatus(made, duration);
42 }
43
44 public static @DrawableRes int getDrawable(final boolean received, final boolean successful) {
45 if (received) {
46 if (successful) {
47 return R.drawable.ic_call_received_24dp;
48 } else {
49 return R.drawable.ic_call_missed_24db;
50 }
51 } else {
52 if (successful) {
53 return R.drawable.ic_call_made_24dp;
54 } else {
55 return R.drawable.ic_call_missed_outgoing_24dp;
56 }
57 }
58 }
59}