Skip to content

Commit 88b690f

Browse files
use java portal instead of kotlin
1 parent 7201807 commit 88b690f

File tree

2 files changed

+232
-183
lines changed

2 files changed

+232
-183
lines changed
Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
package com.singularity_code.live_location.util.other;
2+
3+
import android.content.Context;
4+
import androidx.core.app.NotificationCompat;
5+
import com.singularity_code.live_location.util.enums.NetworkMethod;
6+
import com.singularity_code.live_location.util.pattern.*;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
import java.util.HashMap;
10+
11+
public class AlienPortal {
12+
13+
public static AlienPortal newInstance() {
14+
return new AlienPortal();
15+
}
16+
17+
// observable
18+
private String _status = "DEAD";
19+
20+
public String getStatus() {
21+
return _status;
22+
}
23+
24+
private String _errorMessage;
25+
26+
public String getErrorMessage() {
27+
return _errorMessage;
28+
}
29+
30+
private String _latitude;
31+
32+
public String getLatitude() {
33+
return _latitude;
34+
}
35+
36+
private String _longitude;
37+
38+
public String getLongitude() {
39+
return _longitude;
40+
}
41+
42+
private String _accuracy;
43+
44+
public String getAccuracy() {
45+
return _accuracy;
46+
}
47+
48+
private String _updatedTime;
49+
50+
public String getUpdatedTime() {
51+
return _updatedTime;
52+
}
53+
54+
// gps config
55+
private long gpsSamplingRate = 10000L;
56+
57+
// notification config
58+
private Context context;
59+
private String channelId;
60+
private String channelName;
61+
private String channelDescription;
62+
private String notificationTitle;
63+
private String notificationMessage;
64+
65+
// network configuration
66+
private String apiOrSocketURL;
67+
private NetworkMethod networkMethod;
68+
private String messageDescriptor;
69+
private HashMap<String, String> headers = new HashMap<>();
70+
71+
private LiveLocationServiceInteractor liveLocationServiceInteractor;
72+
73+
public void setGPSSamplingRate(long samplingRate) {
74+
gpsSamplingRate = samplingRate;
75+
}
76+
77+
public void setContext(Context context) {
78+
this.context = context;
79+
}
80+
81+
public void setChannelId(String id) {
82+
channelId = id;
83+
}
84+
85+
public void setChannelName(String name) {
86+
channelName = name;
87+
}
88+
89+
public void setChannelDescription(String description) {
90+
channelDescription = description;
91+
}
92+
93+
public void setupAPIorSocketURL(String url) {
94+
apiOrSocketURL = url;
95+
}
96+
97+
public void setNotificationTitle(String title) {
98+
notificationTitle = title;
99+
}
100+
101+
public void setNotificationMessage(String message) {
102+
notificationMessage = message;
103+
}
104+
105+
// 0 -> RESTFUL
106+
// 1 -> Web Socket
107+
public void setupNetworkMethod(int methodEnumIndex) {
108+
networkMethod = NetworkMethod.values()[methodEnumIndex];
109+
}
110+
111+
public void addHeader(String key, String value) {
112+
headers.put(key, value);
113+
}
114+
115+
public void clearHeader() {
116+
headers.clear();
117+
}
118+
119+
public void setMessageDescriptor(String descriptor) {
120+
messageDescriptor = descriptor;
121+
}
122+
123+
public void start() {
124+
liveLocationServiceInteractor = new LiveLocationServiceInteractorAbs() {
125+
@Override
126+
public Context getContext() {
127+
return AlienPortal.this.context;
128+
}
129+
130+
@NotNull
131+
@Override
132+
public GPSConfig getGpsConfig() {
133+
return new GPSConfig() {
134+
@Override
135+
public long getSamplingRate() {
136+
return gpsSamplingRate;
137+
}
138+
};
139+
}
140+
141+
@Override
142+
public NotificationConfig getNotificationConfig() {
143+
return new NotificationConfig() {
144+
@Override
145+
public int getForegroundServiceID() {
146+
return 1003;
147+
}
148+
149+
@Override
150+
public String getNotificationChannelID() {
151+
return AlienPortal.this.channelId;
152+
}
153+
154+
@Override
155+
public String getNotificationChannelName() {
156+
return AlienPortal.this.channelName;
157+
}
158+
159+
@Override
160+
public String getNotificationChannelDescription() {
161+
return AlienPortal.this.channelDescription;
162+
}
163+
164+
@Override
165+
public int getNotificationPriority() {
166+
return NotificationCompat.PRIORITY_DEFAULT;
167+
}
168+
169+
@Override
170+
public Integer getIconRes() {
171+
return null;
172+
}
173+
};
174+
}
175+
176+
@Override
177+
public LiveLocationNetworkConfiguration getNetworkConfiguration() {
178+
return new LiveLocationNetworkConfiguration() {
179+
@Override
180+
public String getUrl() {
181+
return AlienPortal.this.apiOrSocketURL;
182+
}
183+
184+
@Override
185+
public NetworkMethod getNetworkMethod() {
186+
return AlienPortal.this.networkMethod;
187+
}
188+
189+
@Override
190+
public HashMap<String, String> getHeaders() {
191+
return AlienPortal.this.headers;
192+
}
193+
194+
@Override
195+
public String getMessageDescriptor() {
196+
return AlienPortal.this.messageDescriptor;
197+
}
198+
};
199+
}
200+
201+
@Override
202+
public void onServiceStatusChanged(LiveLocationServiceInteractor.ServiceStatus serviceStatus) {
203+
AlienPortal.this._status = serviceStatus.name();
204+
}
205+
206+
@Override
207+
public void onError(String message) {
208+
AlienPortal.this._errorMessage = message;
209+
}
210+
211+
@Override
212+
public void onReceiveUpdate(double latitude, double longitude, float accuracy, long updateTime) {
213+
AlienPortal.this._latitude = String.valueOf(latitude);
214+
AlienPortal.this._longitude = String.valueOf(longitude);
215+
AlienPortal.this._accuracy = String.valueOf(accuracy);
216+
AlienPortal.this._updatedTime = String.valueOf(updateTime);
217+
}
218+
};
219+
220+
liveLocationServiceInteractor.startService(
221+
AlienPortal.this.notificationTitle,
222+
AlienPortal.this.notificationMessage
223+
);
224+
}
225+
226+
public void stop() {
227+
if (liveLocationServiceInteractor != null) {
228+
liveLocationServiceInteractor.stopService();
229+
liveLocationServiceInteractor = null;
230+
}
231+
}
232+
}

0 commit comments

Comments
 (0)