Skip to content
This repository was archived by the owner on Jun 30, 2023. It is now read-only.

Commit b88abe3

Browse files
nyoungshipchainajhodges
authored andcommitted
Gradle and Kotlin
Included Kotlin into Gradle Updated Gradle Dependencies Changed Constants to Kotlin (will still need to be refactored later) Changed public members of Route class to private that could be
1 parent f20b207 commit b88abe3

File tree

13 files changed

+121
-111
lines changed

13 files changed

+121
-111
lines changed

app/build.gradle

+10-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ buildscript {
1313
}
1414
apply plugin: 'com.android.application'
1515
apply plugin: 'io.fabric'
16+
apply plugin: 'kotlin-android'
17+
apply plugin: 'kotlin-android-extensions'
18+
apply plugin: 'kotlin-kapt'
1619

1720
repositories {
1821
jcenter()
@@ -54,11 +57,13 @@ android {
5457
}
5558

5659
dependencies {
60+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
61+
5762
api fileTree(dir: 'libs', include: ['*.jar'])
58-
api 'com.android.support:appcompat-v7:26.0.0'
59-
api 'com.google.android.gms:play-services-base:11.0.4'
60-
api 'com.google.android.gms:play-services-maps:11.0.4'
61-
api 'com.google.android.gms:play-services-location:11.0.4'
63+
api 'com.android.support:appcompat-v7:26.1.0'
64+
api 'com.google.android.gms:play-services-base:16.0.1'
65+
api 'com.google.android.gms:play-services-maps:16.0.0'
66+
api 'com.google.android.gms:play-services-location:16.0.0'
6267

6368
api 'com.joanzapata.iconify:android-iconify:2.0.8'
6469
api 'com.joanzapata.iconify:android-iconify-material:2.0.8'
@@ -68,7 +73,7 @@ dependencies {
6873
transitive = true
6974
}
7075
api 'net.danlew:android.joda:2.9.5.1' // for joda
71-
api 'com.android.support:design:26.0.0'
76+
api 'com.android.support:design:26.1.0'
7277
api 'com.yqritc:recyclerview-flexibledivider:1.2.6'
7378
api('com.github.afollestad.material-dialogs:core:0.8.5.3@aar') {
7479
transitive = true

app/src/main/java/com/codeforgvl/trolleytrackerclient/Constants.java

-71
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.codeforgvl.trolleytrackerclient
2+
3+
import android.content.Context
4+
import android.support.v4.content.ContextCompat
5+
6+
class Constants {
7+
companion object {
8+
const val LOG_TAG = "TROLLEYTRACKER"
9+
const val ROUTE_UPDATE_INTERVAL = 15
10+
const val SLEEP_INTERVAL = 5000
11+
const val LOCATION_PERMISSION_REQUEST_ID = 1
12+
13+
val HOST =
14+
if (BuildConfig.DEBUG) "yeahthattrolley.azurewebsites.net" else "api.yeahthattrolley.com"
15+
val API_PATH = "/api/v1/"
16+
// var ALL_TROLLEYS_ENDPOINT =
17+
// var RUNNING_TROLLEYS_ENDPOINT =
18+
// var ACTIVE_ROUTES_ENDPOINT =
19+
// var ROUTE_SCHEDULE_ENDPOINT =
20+
21+
private val ROUTE_DETAILS_ENDPOINT = "http://" + HOST + API_PATH + "Routes/"
22+
23+
fun getRouteDetailsEndpoint(routeId: Int): String {
24+
return ROUTE_DETAILS_ENDPOINT + routeId
25+
}
26+
27+
fun getAllTrolleysEndpoint(): String {
28+
return """http://$HOST${API_PATH}Trolleys""" // Complete trolley record - all trolleys
29+
}
30+
31+
fun getRunningTrolleysEndpoint(): String {
32+
return """http://$HOST${API_PATH}Trolleys/Running"""
33+
}
34+
35+
fun getActiveRoutesEndpoint(): String {
36+
return """http://$HOST${API_PATH}Routes/Active"""
37+
}
38+
39+
fun getRouteScheduleEndpoint(): String {
40+
return """http://$HOST${API_PATH}RouteSchedules"""
41+
}
42+
43+
fun getRouteColorForRouteNumber(context: Context, ndx: Int): Int {
44+
45+
val routeNo = ndx % 5 + 1
46+
return when (routeNo) {
47+
1 -> ContextCompat.getColor(context, R.color.route1)
48+
2 -> ContextCompat.getColor(context, R.color.route2)
49+
3 -> ContextCompat.getColor(context, R.color.route3)
50+
4 -> ContextCompat.getColor(context, R.color.route4)
51+
else -> ContextCompat.getColor(context, R.color.route5)
52+
}
53+
}
54+
55+
fun getStopColorForRouteNumber(context: Context, ndx: Int): Int {
56+
val routeNo = ndx % 5 + 1
57+
return when (routeNo) {
58+
1 -> ContextCompat.getColor(context, R.color.stop1)
59+
2 -> ContextCompat.getColor(context, R.color.stop2)
60+
3 -> ContextCompat.getColor(context, R.color.stop3)
61+
4 -> ContextCompat.getColor(context, R.color.stop4)
62+
else -> ContextCompat.getColor(context, R.color.stop5)
63+
}
64+
}
65+
}
66+
67+
enum class DayOfWeek {
68+
Monday,
69+
Tuesday,
70+
Wednesday,
71+
Thursday,
72+
Friday,
73+
Saturday,
74+
Sunday
75+
}
76+
}

app/src/main/java/com/codeforgvl/trolleytrackerclient/activities/MainActivity.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,18 @@
3333
import icepick.State;
3434

3535
public class MainActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback, TrackerFragment.MapFragmentListener, FragmentManager.OnBackStackChangedListener {
36-
public final static int MAP_FRAGMENT_ID = 1;
37-
public final static int SCHEDULE_FRAGMENT_ID = 2;
38-
public final static int PREVIEW_FRAGMENT_ID = 3;
39-
public final static int FEEDBACK_ID = 4;
36+
37+
private final static int MAP_FRAGMENT_ID = 1;
38+
private final static int SCHEDULE_FRAGMENT_ID = 2;
39+
private final static int PREVIEW_FRAGMENT_ID = 3;
40+
private final static int FEEDBACK_ID = 4;
41+
private final static String SCHEDULE_FRAGMENT_TAG = "SCHEDULE_FRAGMENT";
42+
private final static String PREVIEW_FRAGMENT_TAG = "PREVIEW_FRAGMENT";
4043
public final static String MAP_FRAGMENT_TAG = "MAP_FRAGMENT";
41-
public final static String SCHEDULE_FRAGMENT_TAG = "SCHEDULE_FRAGMENT";
42-
public final static String PREVIEW_FRAGMENT_TAG = "PREVIEW_FRAGMENT";
4344

44-
TrackerFragment trackerFragment;
45-
ScheduleFragment scheduleFragment;
46-
RoutePreviewFragment previewFragment;
45+
private TrackerFragment trackerFragment;
46+
private ScheduleFragment scheduleFragment;
47+
private RoutePreviewFragment previewFragment;
4748
@State
4849
String activeFragment;
4950

app/src/main/java/com/codeforgvl/trolleytrackerclient/data/TrolleyAPI.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private static String httpGETRequest(String urlString){
5252

5353
// Location only for the trolleys that are running
5454
public static Trolley[] getRunningTrolleys(){
55-
String json = httpGETRequest(Constants.RUNNING_TROLLEYS_ENDPOINT);
55+
String json = httpGETRequest(Constants.Companion.getRunningTrolleysEndpoint());
5656
Trolley[] ret = null;
5757
try{
5858
ret = new Gson().fromJson(json, Trolley[].class);
@@ -65,7 +65,7 @@ public static Trolley[] getRunningTrolleys(){
6565

6666
// Get full record for all trolleys
6767
public static Trolley[] getAllTrolleys(){
68-
String json = httpGETRequest(Constants.ALL_TROLLEYS_ENDPOINT);
68+
String json = httpGETRequest(Constants.Companion.getAllTrolleysEndpoint());
6969
Trolley[] ret = null;
7070
try{
7171
ret = new Gson().fromJson(json, Trolley[].class);
@@ -76,7 +76,7 @@ public static Trolley[] getAllTrolleys(){
7676
}
7777

7878
public static Route[] getActiveRoutes(){
79-
String json = httpGETRequest(Constants.ACTIVE_ROUTES_ENDPOINT);
79+
String json = httpGETRequest(Constants.Companion.getActiveRoutesEndpoint());
8080
Route[] ret = null;
8181
try{
8282
ret = new Gson().fromJson(json, Route[].class);
@@ -87,7 +87,7 @@ public static Route[] getActiveRoutes(){
8787
}
8888

8989
public static RouteSchedule[] getRouteSchedule(){
90-
String json = httpGETRequest(Constants.ROUTE_SCHEDULE_ENDPOINT);
90+
String json = httpGETRequest(Constants.Companion.getRouteScheduleEndpoint());
9191
RouteSchedule[] ret = null;
9292
try{
9393
ret = new Gson().fromJson(json, RouteSchedule[].class);
@@ -98,7 +98,7 @@ public static RouteSchedule[] getRouteSchedule(){
9898
}
9999

100100
public static Route getRouteDetails(int routeId){
101-
String json = httpGETRequest(Constants.GetRouteDetailsEndpoint(routeId));
101+
String json = httpGETRequest(Constants.Companion.getRouteDetailsEndpoint(routeId));
102102
Route ret = null;
103103
try{
104104
ret = new Gson().fromJson(json, Route.class);

app/src/main/java/com/codeforgvl/trolleytrackerclient/fragments/ScheduleFragment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
141141
listView.addOnItemTouchListener(new RecyclerItemClickListener(getContext(), new ScheduleItemClickListener()));
142142
}
143143

144-
SwipeRefreshLayout swipeRefresh = (SwipeRefreshLayout)view.findViewById(R.id.scheduleRefreshLayout);
144+
SwipeRefreshLayout swipeRefresh = view.findViewById(R.id.scheduleRefreshLayout);
145145
if(swipeRefresh != null){
146146
swipeRefresh.setOnRefreshListener(this);
147147
}

app/src/main/java/com/codeforgvl/trolleytrackerclient/fragments/TrackerFragment.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
9191

9292
((FloatingActionButton) view.findViewById(R.id.myFAB)).setImageDrawable(new IconDrawable(getContext(), MaterialIcons.md_directions_walk).colorRes(R.color.white));
9393

94-
drawer = (SlidingUpPanelLayout)view.findViewById(R.id.sliding_layout);
94+
drawer = view.findViewById(R.id.sliding_layout);
9595
drawer.setPanelSlideListener(new DrawerListener());
9696

97-
fab = (FloatingActionButton)view.findViewById(R.id.myFAB);
97+
fab = view.findViewById(R.id.myFAB);
9898
fab.setOnClickListener(new View.OnClickListener() {
9999
@Override
100100
public void onClick(View v) {

app/src/main/java/com/codeforgvl/trolleytrackerclient/helpers/RecyclerItemClickListener.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListen
1515
private OnItemClickListener mListener;
1616

1717
public interface OnItemClickListener {
18-
public void onItemClick(View view, int position);
18+
void onItemClick(View view, int position);
1919
}
2020

2121
GestureDetector mGestureDetector;

app/src/main/java/com/codeforgvl/trolleytrackerclient/helpers/RouteManager.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import static com.codeforgvl.trolleytrackerclient.Constants.ROUTE_UPDATE_INTERVAL;
3030

31+
3132
/**
3233
* Created by ahodges on 12/18/2015.
3334
*/
@@ -36,7 +37,7 @@ public class RouteManager {
3637
private HashMap<Integer, Polyline> routePolylines = new HashMap<>();
3738
private HashMap<Integer, Marker> stopMarkers = new HashMap<>();
3839

39-
Route[] lastRouteUpdate;
40+
private Route[] lastRouteUpdate;
4041
//long lastUpdatedAt;
4142

4243
public RouteManager(IMapFragment activity){
@@ -46,9 +47,7 @@ public RouteManager(IMapFragment activity){
4647
public void processBundle(Bundle b){
4748
if(b == null){
4849
return;
49-
}
50-
51-
if (b != null){
50+
} else if (b != null) {
5251
Icepick.restoreInstanceState(trackerFragment, b);
5352
if(!updateRoutesIfNeeded()){
5453
updateRoutes(lastRouteUpdate);
@@ -82,7 +81,7 @@ public boolean updateRoutesIfNeeded(){
8281
}
8382
}
8483

85-
public void updateRoutes(Route[] routes){
84+
private void updateRoutes(Route[] routes){
8685
if(trackerFragment.getMap() == null || !trackerFragment.fragmentIsAdded())
8786
return;
8887

@@ -112,7 +111,7 @@ public void updateRoutes(Route[] routes){
112111
.title(s.Name)
113112
.snippet(s.Description)
114113
.anchor(0.5f, 0.5f)
115-
.icon(IconFactory.getStopIcon(trackerFragment.getContext(), Constants.getStopColorForRouteNumber(trackerFragment.getContext(), i)))
114+
.icon(IconFactory.getStopIcon(trackerFragment.getContext(), Constants.Companion.getStopColorForRouteNumber(trackerFragment.getContext(), i)))
116115
.position(new LatLng(s.Lat, s.Lon))));
117116
}
118117
}

app/src/main/java/com/codeforgvl/trolleytrackerclient/helpers/TrolleyManager.java

-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
import android.graphics.Color;
44
import android.os.AsyncTask;
55
import android.os.Bundle;
6-
import android.os.Parcelable;
76
import android.util.Log;
87

98
import com.codeforgvl.trolleytrackerclient.Constants;
10-
import com.codeforgvl.trolleytrackerclient.R;
119
import com.codeforgvl.trolleytrackerclient.data.TrolleyAPI;
1210
import com.codeforgvl.trolleytrackerclient.data.TrolleyData;
1311
import com.codeforgvl.trolleytrackerclient.fragments.TrackerFragment;
1412
import com.codeforgvl.trolleytrackerclient.models.json.Trolley;
15-
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
1613
import com.google.android.gms.maps.model.LatLng;
1714
import com.google.android.gms.maps.model.Marker;
1815
import com.google.android.gms.maps.model.MarkerOptions;

app/src/main/java/com/codeforgvl/trolleytrackerclient/models/json/LatLon.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void writeToParcel(Parcel dest, int flags) {
2121
dest.writeDouble(Lon);
2222
}
2323

24-
public LatLon(Parcel in){
24+
public LatLon(Parcel in) {
2525
Lat = in.readDouble();
2626
Lon = in.readDouble();
2727
}

app/src/main/java/com/codeforgvl/trolleytrackerclient/models/json/Route.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
package com.codeforgvl.trolleytrackerclient.models.json;
22

3-
import android.content.Context;
43
import android.os.Parcel;
54
import android.os.Parcelable;
65

7-
import com.codeforgvl.trolleytrackerclient.Constants;
8-
96
/**
107
* Created by Adam Hodges on 8/23/2015.
118
*/
129
public class Route implements Parcelable {
1310
public static final String ROUTE_KEY = "ROUTE_KEY";
1411
public static final String LAST_UPDATED_KEY = "ROUTE_LAST_UPDATED_KEY";
15-
public String ShortName;
1612
public String Description;
1713
public int ID;
18-
public boolean FlagStopsOnly;
19-
public String LongName;
20-
public String RouteColorRGB = "#acb71d";
14+
15+
private String ShortName;
16+
private boolean FlagStopsOnly;
17+
private String LongName;
18+
private String RouteColorRGB = "#acb71d";
2119

2220
public RouteStop[] Stops;
2321
public LatLon[] RouteShape;

0 commit comments

Comments
 (0)