Skip to content

Commit 78b7a3d

Browse files
committed
mvp
1 parent 5c34097 commit 78b7a3d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1269
-0
lines changed

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 28
5+
defaultConfig {
6+
applicationId "track.club.couriermobile"
7+
minSdkVersion 19
8+
targetSdkVersion 28
9+
versionCode 1
10+
versionName "1.0"
11+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12+
}
13+
buildTypes {
14+
release {
15+
minifyEnabled false
16+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17+
}
18+
}
19+
compileOptions {
20+
targetCompatibility JavaVersion.VERSION_1_8
21+
sourceCompatibility JavaVersion.VERSION_1_8
22+
23+
24+
}
25+
}
26+
27+
dependencies {
28+
implementation fileTree(dir: 'libs', include: ['*.jar'])
29+
implementation 'com.android.support:mediarouter-v7:28.0.0'
30+
implementation 'com.android.support:support-v4:28.0.0'
31+
implementation 'com.android.support:appcompat-v7:28.0.0'
32+
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
33+
implementation 'com.google.code.gson:gson:2.8.5'
34+
35+
36+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
37+
implementation 'com.google.android.gms:play-services:12.0.1'
38+
testImplementation 'junit:junit:4.12'
39+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
40+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
41+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package track.club.couriermobile;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("track.club.couriermobile", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="track.club.couriermobile">
4+
5+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
6+
7+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
8+
<application
9+
android:allowBackup="true"
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="@string/app_name"
12+
android:roundIcon="@mipmap/ic_launcher_round"
13+
android:supportsRtl="true"
14+
android:theme="@style/AppTheme">
15+
<activity android:name=".MainActivity">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN"/>
18+
19+
<category android:name="android.intent.category.LAUNCHER"/>
20+
</intent-filter>
21+
</activity>
22+
23+
<service
24+
android:name=".ForegroundStub"
25+
android:enabled="true"
26+
android:exported="true">
27+
</service>
28+
</application>
29+
30+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package track.club.couriermobile;
2+
3+
public class Courier {
4+
private String id;
5+
private String name;
6+
private String phone;
7+
private Location location;
8+
9+
public Courier(String name, String phone) {
10+
this.name = name;
11+
this.phone = phone;
12+
}
13+
14+
public Courier(String id) {
15+
this.id = id;
16+
}
17+
18+
public String getName() {
19+
return name;
20+
}
21+
22+
public void setName(String name) {
23+
this.name = name;
24+
}
25+
26+
public String getPhone() {
27+
return phone;
28+
}
29+
30+
public void setPhone(String phone) {
31+
this.phone = phone;
32+
}
33+
34+
public Location getLocation() {
35+
return location;
36+
}
37+
38+
public void setLocation(Location location) {
39+
this.location = location;
40+
}
41+
42+
public String getId() {
43+
return id;
44+
}
45+
46+
public void setId(String id) {
47+
this.id = id;
48+
}
49+
50+
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package track.club.couriermobile;
2+
3+
import android.support.v4.util.Consumer;
4+
import android.util.Log;
5+
import com.google.gson.FieldNamingPolicy;
6+
import com.google.gson.Gson;
7+
import com.google.gson.GsonBuilder;
8+
import okhttp3.*;
9+
10+
public class CourierAPI {
11+
private final OkHttpClient client;
12+
private final Gson gson = new GsonBuilder()
13+
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
14+
.create();
15+
private final RESTAcceptor<Courier> restAcceptor;
16+
private static final MediaType JSON
17+
= MediaType.parse("application/json; charset=utf-8");
18+
19+
20+
public CourierAPI(OkHttpClient client) {
21+
this.client = client;
22+
this.restAcceptor = new RESTAcceptor<>(gson);
23+
}
24+
25+
public void Create(Courier courier, final Consumer<Courier> consumer) {
26+
RequestBody body = RequestBody.create(JSON, gson.toJson(courier));
27+
Request request = new Request.Builder()
28+
.post(body)
29+
.url("https://track-delivery.club/api/v1/couriers")
30+
.build();
31+
client.newCall(request).enqueue(restAcceptor.onResponse(consumer, Courier.class));
32+
}
33+
34+
public void Update(Courier courier, final Consumer<Courier> consumer) {
35+
Gson gson = new Gson();
36+
String json = gson.toJson(courier);
37+
RequestBody body = RequestBody.create(JSON, json);
38+
Request request = new Request.Builder()
39+
.put(body)
40+
.url("https://track-delivery.club/api/v1/couriers/" + courier.getId())
41+
.build();
42+
Log.i("update req", json);
43+
client.newCall(request).enqueue(restAcceptor.onResponse(consumer, Courier.class));
44+
}
45+
46+
public void Delete(Courier courier) {
47+
HttpUrl respURL = new HttpUrl.Builder()
48+
.scheme("https")
49+
.host("track-delivery.club")
50+
.addPathSegment("api/v1/couriers/")
51+
.addPathSegment(courier.getId())
52+
.build();
53+
54+
Request request = new Request.Builder()
55+
.delete()
56+
.url(respURL)
57+
.build();
58+
client.newCall(request).enqueue(restAcceptor.onEmptyResponse());
59+
}
60+
61+
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package track.club.couriermobile;
2+
3+
import android.app.*;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.os.IBinder;
7+
import android.support.v4.app.NotificationCompat;
8+
import android.support.v4.content.ContextCompat;
9+
10+
public class ForegroundStub extends Service {
11+
public ForegroundStub() {
12+
}
13+
14+
@Override
15+
public IBinder onBind(Intent intent) {
16+
throw new UnsupportedOperationException("Not yet implemented");
17+
}
18+
19+
@Override
20+
public int onStartCommand(Intent intent, int flags, int startId) {
21+
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
22+
NotificationCompat.Builder builder = null;
23+
Intent notificationIntent = new Intent(this, MainActivity.class);
24+
25+
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
26+
27+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
28+
int importance = NotificationManager.IMPORTANCE_DEFAULT;
29+
NotificationChannel notificationChannel = new NotificationChannel("ID", "Name", importance);
30+
notificationManager.createNotificationChannel(notificationChannel);
31+
builder = new NotificationCompat.Builder(getApplicationContext(), notificationChannel.getId());
32+
} else {
33+
builder = new NotificationCompat.Builder(getApplicationContext());
34+
}
35+
Notification notification = builder
36+
.setSmallIcon(R.drawable.ic_launcher_foreground)
37+
.setColor(ContextCompat.getColor(this, R.color.colorAccent))
38+
.setContentTitle(getString(R.string.app_name))
39+
.setTicker(getString(R.string.app_name))
40+
.setContentText("FOREGROUND")
41+
.setDefaults(Notification.DEFAULT_ALL)
42+
.setAutoCancel(true)
43+
.setOngoing(true)
44+
.setContentIntent(pendingIntent)
45+
.build();
46+
startForeground(1, notification);
47+
return START_STICKY;
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package track.club.couriermobile;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
5+
public class GPSPoint {
6+
@SerializedName("lat")
7+
private double latitude;
8+
@SerializedName("lon")
9+
private double longitude;
10+
11+
public GPSPoint(double latitude, double longitude) {
12+
this.latitude = latitude;
13+
this.longitude = longitude;
14+
}
15+
16+
public double getLatitude() {
17+
return latitude;
18+
}
19+
20+
public void setLatitude(double latitude) {
21+
this.latitude = latitude;
22+
}
23+
24+
public double getLongitude() {
25+
return longitude;
26+
}
27+
28+
public void setLongitude(double longitude) {
29+
this.longitude = longitude;
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package track.club.couriermobile;
2+
3+
public class Location {
4+
private GPSPoint point;
5+
private String address;
6+
7+
public Location(GPSPoint point) {
8+
this.point = point;
9+
}
10+
11+
public Location(String address) {
12+
this.address = address;
13+
}
14+
15+
public GPSPoint getPoint() {
16+
return point;
17+
}
18+
19+
public void setPoint(GPSPoint point) {
20+
this.point = point;
21+
}
22+
23+
public String getAddress() {
24+
return address;
25+
}
26+
27+
public void setAddress(String address) {
28+
this.address = address;
29+
}
30+
}

0 commit comments

Comments
 (0)