Browse Source

added flavors

tags/v1.0.0
Robin Thoni 7 years ago
parent
commit
95e1dd97fc

+ 3
- 0
.gitignore View File

@@ -6,3 +6,6 @@
6 6
 /build
7 7
 /captures
8 8
 *.apk
9
+
10
+app/src/dev/res/values/config.xml
11
+app/src/devlocal/res/values/config.xml

+ 13
- 0
app/build.gradle View File

@@ -18,6 +18,19 @@ android {
18 18
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 19
         }
20 20
     }
21
+
22
+    productFlavors {
23
+        main {
24
+        }
25
+        dev {
26
+            applicationId "com.rthoni.stssaguenay.dev"
27
+            versionName "1.0-dev"
28
+        }
29
+        devlocal {
30
+            applicationId "com.rthoni.stssaguenay.devlocal"
31
+            versionName "1.0-devlocal"
32
+        }
33
+    }
21 34
 }
22 35
 
23 36
 dependencies {

+ 42
- 0
app/src/dev/google-services.json View File

@@ -0,0 +1,42 @@
1
+{
2
+  "project_info": {
3
+    "project_number": "171393394108",
4
+    "firebase_url": "https://admob-app-id-3084832113.firebaseio.com",
5
+    "project_id": "admob-app-id-3084832113",
6
+    "storage_bucket": "admob-app-id-3084832113.appspot.com"
7
+  },
8
+  "client": [
9
+    {
10
+      "client_info": {
11
+        "mobilesdk_app_id": "1:171393394108:android:6fd8956541c81e90",
12
+        "android_client_info": {
13
+          "package_name": "com.rthoni.stssaguenay.dev"
14
+        }
15
+      },
16
+      "oauth_client": [
17
+        {
18
+          "client_id": "171393394108-eovbvhuab49spjk18c382f1ueqij1lvv.apps.googleusercontent.com",
19
+          "client_type": 3
20
+        }
21
+      ],
22
+      "api_key": [
23
+        {
24
+          "current_key": "AIzaSyDfBkaeX5670C6Y-AYZgl5wRNV-pr8mldw"
25
+        }
26
+      ],
27
+      "services": {
28
+        "analytics_service": {
29
+          "status": 1
30
+        },
31
+        "appinvite_service": {
32
+          "status": 1,
33
+          "other_platform_oauth_client": []
34
+        },
35
+        "ads_service": {
36
+          "status": 2
37
+        }
38
+      }
39
+    }
40
+  ],
41
+  "configuration_version": "1"
42
+}

+ 42
- 0
app/src/devlocal/google-services.json View File

@@ -0,0 +1,42 @@
1
+{
2
+  "project_info": {
3
+    "project_number": "171393394108",
4
+    "firebase_url": "https://admob-app-id-3084832113.firebaseio.com",
5
+    "project_id": "admob-app-id-3084832113",
6
+    "storage_bucket": "admob-app-id-3084832113.appspot.com"
7
+  },
8
+  "client": [
9
+    {
10
+      "client_info": {
11
+        "mobilesdk_app_id": "1:171393394108:android:6fd8956541c81e90",
12
+        "android_client_info": {
13
+          "package_name": "com.rthoni.stssaguenay.devlocal"
14
+        }
15
+      },
16
+      "oauth_client": [
17
+        {
18
+          "client_id": "171393394108-eovbvhuab49spjk18c382f1ueqij1lvv.apps.googleusercontent.com",
19
+          "client_type": 3
20
+        }
21
+      ],
22
+      "api_key": [
23
+        {
24
+          "current_key": "AIzaSyDfBkaeX5670C6Y-AYZgl5wRNV-pr8mldw"
25
+        }
26
+      ],
27
+      "services": {
28
+        "analytics_service": {
29
+          "status": 1
30
+        },
31
+        "appinvite_service": {
32
+          "status": 1,
33
+          "other_platform_oauth_client": []
34
+        },
35
+        "ads_service": {
36
+          "status": 2
37
+        }
38
+      }
39
+    }
40
+  ],
41
+  "configuration_version": "1"
42
+}

app/google-services.json → app/src/main/google-services.json View File


+ 11
- 2
app/src/main/java/com/rthoni/stssaguenay/business/STSBusiness.java View File

@@ -3,6 +3,7 @@ package com.rthoni.stssaguenay.business;
3 3
 import android.content.Context;
4 4
 
5 5
 import com.luticate.utils.dbo.LuDataAccessConfigDbo;
6
+import com.rthoni.stssaguenay.R;
6 7
 import com.rthoni.stssaguenay.dataaccess.STSDataAccess;
7 8
 import com.rthoni.stssaguenay.dbo.UserFavouriteStopsDbo;
8 9
 import com.rthoni.stssaguenay.dbo.UserDbo;
@@ -22,11 +23,19 @@ public class STSBusiness {
22 23
 
23 24
     private static LuDataAccessConfigDbo _config = null;
24 25
 
25
-    public static LuDataAccessConfigDbo getConfig()
26
+    public static LuDataAccessConfigDbo getConfig(Context ctx)
26 27
     {
27 28
         if (_config == null) {
28 29
             _config = new LuDataAccessConfigDbo();
29
-            _config.setBaseUrl("http://gigi-eth:8089/");
30
+            try {
31
+                String str = ctx.getString(R.string.luticate_config);
32
+                _config.fromJson(new JSONObject(str));
33
+            } catch (JSONException e) {
34
+                e.printStackTrace();
35
+                _config = null;
36
+                return null;
37
+            }
38
+//            _config.setBaseUrl("http://gigi-eth:8089/");
30 39
         }
31 40
         return _config;
32 41
     }

+ 46
- 4
app/src/main/java/com/rthoni/stssaguenay/ui/activities/MainActivity.java View File

@@ -6,7 +6,9 @@ import android.content.Intent;
6 6
 import android.os.Bundle;
7 7
 import android.support.design.widget.FloatingActionButton;
8 8
 import android.support.design.widget.NavigationView;
9
+import android.support.v4.app.FragmentManager;
9 10
 import android.support.v4.widget.DrawerLayout;
11
+import android.support.v7.app.ActionBar;
10 12
 import android.support.v7.app.ActionBarDrawerToggle;
11 13
 import android.support.v7.app.AlertDialog;
12 14
 import android.support.v7.app.AppCompatActivity;
@@ -37,10 +39,12 @@ import com.luticate.utils.dbo.LuVoidDbo;
37 39
 import com.rthoni.stssaguenay.R;
38 40
 import com.rthoni.stssaguenay.business.STSBusiness;
39 41
 import com.rthoni.stssaguenay.business.UsersSettingsBusiness;
42
+import com.rthoni.stssaguenay.dbo.StopsDbo;
40 43
 import com.rthoni.stssaguenay.dbo.UserFavouriteStopsDbo;
41 44
 import com.rthoni.stssaguenay.dbo.UserDbo;
42 45
 import com.rthoni.stssaguenay.dbo.UsersSettingsDbo;
43 46
 import com.rthoni.stssaguenay.ui.fragments.HomeFragment;
47
+import com.rthoni.stssaguenay.ui.fragments.StopViewerFragment;
44 48
 
45 49
 import org.json.JSONException;
46 50
 import org.json.JSONObject;
@@ -72,6 +76,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
72 76
 
73 77
     private CallbackManager _callbackManager;
74 78
 
79
+    private ActionBar _actionBar;
80
+
81
+    private FragmentManager _fragmentManager;
82
+
75 83
     @Override
76 84
     protected void onCreate(Bundle savedInstanceState) {
77 85
         super.onCreate(savedInstanceState);
@@ -149,10 +157,32 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
149 157
             }
150 158
         });
151 159
 
160
+
161
+        _fragmentManager = getSupportFragmentManager();
162
+        _fragmentManager.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
163
+            @Override
164
+            public void onBackStackChanged() {
165
+                if (_fragmentManager.getBackStackEntryCount() == 0) {
166
+                    goToHome();
167
+                }
168
+            }
169
+        });
170
+
171
+        _actionBar = getSupportActionBar();
172
+
152 173
         updateLoginState();
153 174
         goToHome();
154 175
     }
155 176
 
177
+    @Override
178
+    public boolean onSupportNavigateUp() {
179
+        if (_fragmentManager.getBackStackEntryCount() == 0) {
180
+            return super.onSupportNavigateUp();
181
+        }
182
+        _fragmentManager.popBackStack();
183
+        return true;
184
+    }
185
+
156 186
     @Override
157 187
     protected void onResume() {
158 188
         if (_goToHome) {
@@ -166,13 +196,25 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
166 196
     {
167 197
         _fab.show();
168 198
         HomeFragment f = new HomeFragment();
199
+        f.setOnFavouriteStopClicked(new LuPromise.LuConsumer<UserFavouriteStopsDbo>() {
200
+            @Override
201
+            public void execute(UserFavouriteStopsDbo data) {
202
+                goToStop(data.getStop());
203
+            }
204
+        });
169 205
         getSupportFragmentManager().beginTransaction().replace(R.id.container, f).commit();
170 206
     }
171 207
 
172
-    public void goToStop()
208
+    public void goToStop(StopsDbo stopsDbo)
173 209
     {
174 210
         _fab.hide();
175
-
211
+        StopViewerFragment f = new StopViewerFragment();
212
+        f.setStopsDbo(stopsDbo);
213
+        getSupportFragmentManager()
214
+                .beginTransaction()
215
+                .replace(R.id.container, f)
216
+                .addToBackStack("StopViewerFragment")
217
+                .commit();
176 218
     }
177 219
 
178 220
     public void goToAddStop()
@@ -282,7 +324,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
282 324
         progressDialog.setMessage(getString(R.string.settings_restoring));
283 325
 
284 326
         UserDbo user = STSBusiness.getLoggedUser(MainActivity.this);
285
-        UsersSettingsBusiness.get(STSBusiness.getConfig(), user.getId())
327
+        UsersSettingsBusiness.get(STSBusiness.getConfig(this), user.getId())
286 328
                 .then(new LuPromise.LuConsumer<String>() {
287 329
                     @Override
288 330
                     public void execute(final String data) {
@@ -329,7 +371,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
329 371
                 progressDialog.show();
330 372
                 progressDialog.setTitle(R.string.loading);
331 373
                 progressDialog.setMessage(getString(R.string.settings_backing_up));
332
-                UsersSettingsBusiness.put(STSBusiness.getConfig(), data, user.getId())
374
+                UsersSettingsBusiness.put(STSBusiness.getConfig(MainActivity.this), data, user.getId())
333 375
                         .then(new LuPromise.LuConsumer<LuVoidDbo>() {
334 376
                             @Override
335 377
                             public void execute(LuVoidDbo data) {

+ 12
- 2
app/src/main/java/com/rthoni/stssaguenay/ui/fragments/HomeFragment.java View File

@@ -18,6 +18,7 @@ import com.luticate.utils.business.LuPromise;
18 18
 import com.rthoni.stssaguenay.R;
19 19
 import com.rthoni.stssaguenay.business.STSBusiness;
20 20
 import com.rthoni.stssaguenay.business.SchedulesBusiness;
21
+import com.rthoni.stssaguenay.dbo.StopsDbo;
21 22
 import com.rthoni.stssaguenay.dbo.UserFavouriteStopsDbo;
22 23
 import com.rthoni.stssaguenay.dbo.SchedulesDbo;
23 24
 
@@ -43,7 +44,9 @@ public class HomeFragment extends Fragment {
43 44
     @BindView(R.id.swipeContainer)
44 45
     SwipeRefreshLayout _swipeRefreshLayout;
45 46
 
46
-    FavouriteStopsAdapter _adapter;
47
+    private FavouriteStopsAdapter _adapter;
48
+
49
+    private LuPromise.LuConsumer<UserFavouriteStopsDbo> _onFavouriteStopClicked;
47 50
 
48 51
     public static class ViewHolder extends RecyclerView.ViewHolder {
49 52
         public View _parentView;
@@ -172,6 +175,9 @@ public class HomeFragment extends Fragment {
172 175
 
173 176
     public void onFavouriteClicked(UserFavouriteStopsDbo favouriteStopDbo)
174 177
     {
178
+        if (_onFavouriteStopClicked != null) {
179
+            _onFavouriteStopClicked.execute(favouriteStopDbo);
180
+        }
175 181
     }
176 182
 
177 183
     public void onFavouriteLongClicked(final UserFavouriteStopsDbo favouriteStopDbo)
@@ -205,7 +211,7 @@ public class HomeFragment extends Fragment {
205 211
         DateTimeZone dtz = DateTimeZone.forOffsetMillis(TimeZone.getDefault().getRawOffset() + TimeZone.getDefault().getDSTSavings());
206 212
         LocalDateTime date = LocalDateTime.now(dtz).plusMinutes(-30);
207 213
 
208
-        SchedulesBusiness.getMultiple(STSBusiness.getConfig(), _adapter.getFavourites(), date, 10)
214
+        SchedulesBusiness.getMultiple(STSBusiness.getConfig(getContext()), _adapter.getFavourites(), date, 10)
209 215
                 .then(new LuPromise.LuConsumer<List<SchedulesDbo>>() {
210 216
                     @Override
211 217
                     public void execute(List<SchedulesDbo> data) {
@@ -220,4 +226,8 @@ public class HomeFragment extends Fragment {
220 226
                     }
221 227
                 });
222 228
     }
229
+
230
+    public void setOnFavouriteStopClicked(LuPromise.LuConsumer<UserFavouriteStopsDbo> onFavouriteStopClicked) {
231
+        _onFavouriteStopClicked = onFavouriteStopClicked;
232
+    }
223 233
 }

+ 1
- 1
app/src/main/java/com/rthoni/stssaguenay/ui/fragments/StopPickerFragment.java View File

@@ -177,7 +177,7 @@ public class StopPickerFragment extends Fragment {
177 177
         progressDialog.setTitle(R.string.loading);
178 178
         progressDialog.setMessage(getString(R.string.loading_stops));
179 179
 
180
-        StopsBusiness.getAll(STSBusiness.getConfig())
180
+        StopsBusiness.getAll(STSBusiness.getConfig(getContext()))
181 181
                 .then(new LuPromise.LuConsumer<List<StopsDbo>>() {
182 182
                     @Override
183 183
                     public void execute(List<StopsDbo> data) {

+ 1
- 1
app/src/main/java/com/rthoni/stssaguenay/ui/fragments/StopRoutesPickerFragment.java View File

@@ -156,7 +156,7 @@ public class StopRoutesPickerFragment extends Fragment {
156 156
         progressDialog.setTitle(R.string.loading);
157 157
         progressDialog.setMessage(getString(R.string.loading_routes));
158 158
 
159
-        RoutesBusiness.getAll(STSBusiness.getConfig())
159
+        RoutesBusiness.getAll(STSBusiness.getConfig(getContext()))
160 160
                 .then(new LuPromise.LuConsumer<List<RoutesDbo>>() {
161 161
                     @Override
162 162
                     public void execute(List<RoutesDbo> data) {

+ 42
- 0
app/src/main/java/com/rthoni/stssaguenay/ui/fragments/StopViewerFragment.java View File

@@ -0,0 +1,42 @@
1
+package com.rthoni.stssaguenay.ui.fragments;
2
+
3
+import android.os.Bundle;
4
+import android.support.annotation.Nullable;
5
+import android.support.v4.app.Fragment;
6
+import android.view.LayoutInflater;
7
+import android.view.View;
8
+import android.view.ViewGroup;
9
+import android.widget.TextView;
10
+
11
+import com.rthoni.stssaguenay.R;
12
+import com.rthoni.stssaguenay.dbo.StopsDbo;
13
+
14
+import butterknife.BindView;
15
+import butterknife.ButterKnife;
16
+
17
+/**
18
+ * Created by robin on 10/6/16.
19
+ */
20
+
21
+public class StopViewerFragment extends Fragment {
22
+
23
+    @BindView(R.id.textView)
24
+    TextView _textStop;
25
+
26
+    private StopsDbo _stopsDbo;
27
+
28
+    @Nullable
29
+    @Override
30
+    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
31
+        View v = inflater.inflate(R.layout.fragment_stop_viewer, container, false);
32
+        ButterKnife.bind(this, v);
33
+
34
+        _textStop.setText(_stopsDbo.getFullName());
35
+
36
+        return v;
37
+    }
38
+
39
+    public void setStopsDbo(StopsDbo stopsDbo) {
40
+        _stopsDbo = stopsDbo;
41
+    }
42
+}

+ 15
- 0
app/src/main/res/layout/fragment_stop_viewer.xml View File

@@ -0,0 +1,15 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+              xmlns:tools="http://schemas.android.com/tools"
4
+              android:orientation="vertical"
5
+              android:layout_width="match_parent"
6
+              android:layout_height="match_parent">
7
+
8
+    <TextView
9
+        android:layout_width="match_parent"
10
+        android:layout_height="wrap_content"
11
+        android:id="@+id/textView"
12
+        android:textAppearance="?android:attr/textAppearanceMedium"
13
+        tools:text="268 - Émile-Girardin / Roitelets"
14
+        android:gravity="center_horizontal"/>
15
+</LinearLayout>

+ 1
- 0
app/src/main/res/values/strings.xml View File

@@ -3,6 +3,7 @@
3 3
     <string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>
4 4
     <string name="ad_init">ca-app-pub-2016581167110949~3084832113</string>
5 5
     <string name="facebook_app_id">1463583156990249</string>
6
+    <string name="luticate_config">{\"baseURL\": \"https://sts.rthoni.com/api/v1/\"}</string>
6 7
 
7 8
 
8 9
     <string name="navigation_drawer_open">Open navigation drawer</string>

+ 49
- 2
luticateutils/src/main/java/com/luticate/utils/dbo/LuDataAccessConfigDbo.java View File

@@ -1,5 +1,10 @@
1 1
 package com.luticate.utils.dbo;
2 2
 
3
+import android.util.Base64;
4
+
5
+import org.json.JSONException;
6
+import org.json.JSONObject;
7
+
3 8
 import java.util.HashMap;
4 9
 import java.util.Map;
5 10
 
@@ -7,9 +12,13 @@ import java.util.Map;
7 12
  *
8 13
  * Created by robin on 11/28/15.
9 14
  */
10
-public class LuDataAccessConfigDbo {
15
+public class LuDataAccessConfigDbo extends LuDbo {
16
+
17
+    protected String _baseUrl;
18
+
19
+    protected String _httpUsername;
11 20
 
12
-    private String _baseUrl;
21
+    protected String _httpPassword;
13 22
 
14 23
     public String getBaseUrl() {
15 24
         return _baseUrl;
@@ -19,9 +28,47 @@ public class LuDataAccessConfigDbo {
19 28
         _baseUrl = baseUrl;
20 29
     }
21 30
 
31
+    public String getHttpUsername() {
32
+        return _httpUsername;
33
+    }
34
+
35
+    public void setHttpUsername(String httpUsername) {
36
+        _httpUsername = httpUsername;
37
+    }
38
+
39
+    public String getHttpPassword() {
40
+        return _httpPassword;
41
+    }
42
+
43
+    public void setHttpPassword(String httpPassword) {
44
+        _httpPassword = httpPassword;
45
+    }
46
+
22 47
     public Map<String, String> getHeaders()
23 48
     {
24 49
         Map<String, String> map = new HashMap<>();
50
+        if (_httpUsername != null) {
51
+            map.put("Authorization", "Basic " + Base64.encodeToString(
52
+                    String.format("%s:%s", _httpUsername, _httpPassword).getBytes(), Base64.DEFAULT));
53
+        }
25 54
         return map;
26 55
     }
56
+
57
+    @Override
58
+    public void fromJson(JSONObject json) throws JSONException {
59
+        _baseUrl = json.getString("baseURL");
60
+        if (!json.isNull("httpUsername")) {
61
+            _httpUsername = json.getString("httpUsername");
62
+            _httpPassword = json.getString("httpPassword");
63
+        }
64
+        else {
65
+            _httpUsername = null;
66
+            _httpPassword = null;
67
+        }
68
+    }
69
+
70
+    @Override
71
+    public HashMap<String, Object> toArray() {
72
+        return null;
73
+    }
27 74
 }

Loading…
Cancel
Save