-
Notifications
You must be signed in to change notification settings - Fork 493
Ls login/create #331
Ls login/create #331
Conversation
|
@mapbox/android , would love 👀 , review, and feedback. All networking that isn't browser based in Chrome Custom Tabs, is happening in the background service named Small stuff still remains like adding checks (and alert dialogs) for internet connectivity. Wanted to get the ball rolling on this though... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build is broken 😖
I pointed out some details to discuss before landing.
BTW well done 👍
MapboxAndroidDemo/build.gradle
Outdated
| compile 'com.github.javiersantos:MaterialStyledDialogs:2.1' | ||
| compile 'com.getbase:floatingactionbutton:1.10.1' | ||
| compile 'com.squareup.picasso:picasso:2.5.2' | ||
| // Firebase crash report |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
MapboxAndroidDemo/build.gradle
Outdated
| compile 'com.squareup.retrofit2:retrofit:2.2.0' | ||
| compile 'com.squareup.retrofit2:converter-gson:2.2.0' | ||
| compile 'com.android.support.constraint:constraint-layout:1.0.2' | ||
| compile 'com.android.support:customtabs:25.3.1' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using ${supportLibVersion} here?
Same thing happens with other dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
| compile 'com.google.code.gson:gson:2.8' | ||
| compile 'com.squareup.retrofit2:retrofit:2.2.0' | ||
| compile 'com.squareup.retrofit2:converter-gson:2.2.0' | ||
| // Other dependencies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some Google dependencies intermingled. What about rearranging them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
| android:screenOrientation="portrait"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN"/> | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
| private String username; | ||
|
|
||
| public AccountRetrievalService() { | ||
| super("AccountRetrievalService"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to increase readability, what about replacing magic numbers with constants with a particular meaning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you talking about these numbers that are passed through to the service via the intent?
If so, they're needed as is because they're part of the oAuth flow. Specifically given to me by our API team.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when I say "numbers", I actually meant Strings. You get my point...
| * Service for making call to Mapbox API for account information | ||
| */ | ||
|
|
||
| public interface MapboxAccountRetrofitService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Access can be package-private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. It's now:
interface MapboxAccountRetrofitService {| @@ -0,0 +1,105 @@ | |||
| package com.mapbox.mapboxandroiddemo.model.usermodel; | |||
|
|
|||
| /** | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove file header.
Turning off “created by” stamp when generating files in AS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks. Switched it to:
/**
* TODO: Add a class header comment!
*/| @@ -0,0 +1,47 @@ | |||
| package com.mapbox.mapboxandroiddemo.model.usermodel; | |||
|
|
|||
| /** | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
|
|
||
| public class Plan { | ||
| private String satellite; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why blank line between all variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used http://www.jsonschema2pojo.org/ and that's how they deliver the classes. I've removed the blank lines in all of the usermodel classes.
|
|
||
| public class UserResponse { | ||
|
|
||
| @SerializedName("authorizations") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why @SerializedName? It's normally used for customizing field names (here the names are equal).
Further information on @SerializedName.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeaaa, no reason to have them. I thought I might have to use it but it turned out I didn't. Forgot to change. Removed
|
@Guardiola31337 , all requested changes have been addressed. Except for the okhttp3/retrofit question. |
Guardiola31337
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good @langsmith! Added some remarks.
MapboxAndroidDemo/build.gradle
Outdated
|
|
||
| // Mapbox Android UI | ||
| // Mapbox Android UI | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit new lines and reformat code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| <uses-feature android:name="android.hardware.location.gps"/> | ||
|
|
||
| <application | ||
| android:name=".MapboxApplication" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should clean/remove all unnecessary stuff from this manifest and take advantage of Manifest Merger to add/merge what differs from the root manifest (MapboxAndroidDemo/src/main/AndroidManifest.xml).
| <action android:name="android.intent.action.MAIN"/> | ||
| <category android:name="android.intent.category.LAUNCHER"/> | ||
| </intent-filter> | ||
| <action android:name="android.intent.action.VIEW"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't <intent-filter> needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, not really sure why it's being displayed that way on Github. On this branch, studio shows:
<activity
android:name=".account.LandingActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="authorize"
android:scheme="mapbox-android-dev-preview"/>
</intent-filter>
</activity>This is what we can use moving forward
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@langsmith I'm still seeing previous code without the <intent-filter> 😞
Remember that there are 2 manifests MapboxAndroidDemo/src/gpservices/AndroidManifest.xml and MapboxAndroidDemo/src/main/AndroidManifest.xml. It seems that only the first one was updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. Ok, both manifest files now have:
<activity
android:name=".account.LandingActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="authorize"
android:scheme="mapbox-android-dev-preview"/>
</intent-filter>
</activity>| private String username; | ||
|
|
||
| public AccountRetrievalService() { | ||
| super("AccountRetrievalService"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you talking about these numbers that are passed through to the service via the intent?
Literals in general. Further information: Replace Magic Number with Symbolic Constant.
|
|
||
| JSONObject data = null; | ||
| try { | ||
| data = new JSONObject(json); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Referring to Retrofit's issue in branch ls-switching-last-okhttp3-to-retrofit-for-login.
As you can see in the logcat:
05-22 12:45:17.376 11938-11938/com.mapbox.mapboxandroiddemo.debug D/RetrievalService: onResponse: response received
05-22 12:45:17.376 11938-11938/com.mapbox.mapboxandroiddemo.debug D/RetrievalService: onResponse: json = Response{protocol=http/1.1, code=404, message=Not Found, url=https://api.mapbox.com/oauth/access_token/grant_type=authorization_code&client_id=%7BclientId%7D&client_secret=%7BclientSecret%7D&redirect_uri=%7BredirectUri%7D&code=%7Bcode%7D}
05-22 12:45:17.376 11938-11938/com.mapbox.mapboxandroiddemo.debug D/RetrievalService: onResponse: jsonString = retrofit2.OkHttpCall$NoContentResponseBody@79f9c5f
05-22 12:45:17.376 11938-11938/com.mapbox.mapboxandroiddemo.debug W/System.err: org.json.JSONException: Value Response of type java.lang.String cannot be converted to JSONObject
05-22 12:45:17.376 11938-11938/com.mapbox.mapboxandroiddemo.debug W/System.err: at org.json.JSON.typeMismatch(JSON.java:111)
05-22 12:45:17.376 11938-11938/com.mapbox.mapboxandroiddemo.debug W/System.err: at org.json.JSONObject.<init>(JSONObject.java:160)
05-22 12:45:17.376 11938-11938/com.mapbox.mapboxandroiddemo.debug W/System.err: at org.json.JSONObject.<init>(JSONObject.java:173)
05-22 12:45:17.376 11938-11938/com.mapbox.mapboxandroiddemo.debug W/System.err: at com.mapbox.mapboxandroiddemo.account.AccountRetrievalService$1.onResponse(AccountRetrievalService.java:78)
05-22 12:45:17.376 11938-11938/com.mapbox.mapboxandroiddemo.debug W/System.err: at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)
05-22 12:45:17.376 11938-11938/com.mapbox.mapboxandroiddemo.debug W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
05-22 12:45:17.377 11938-11938/com.mapbox.mapboxandroiddemo.debug W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
05-22 12:45:17.377 11938-11938/com.mapbox.mapboxandroiddemo.debug W/System.err: at android.os.Looper.loop(Looper.java:148)
05-22 12:45:17.377 11938-11938/com.mapbox.mapboxandroiddemo.debug W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417)
05-22 12:45:17.377 11938-11938/com.mapbox.mapboxandroiddemo.debug W/System.err: at java.lang.reflect.Method.invoke(Native Method)
05-22 12:45:17.377 11938-11938/com.mapbox.mapboxandroiddemo.debug W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
05-22 12:45:17.377 11938-11938/com.mapbox.mapboxandroiddemo.debug W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Retrofit was able to communicate with the given server, but the server could not find what was requested (code=404, message=Not Found) and data can't be created (see org.json.JSONException: Value Response of type java.lang.String cannot be converted to JSONObject).
So it seems that isn't a problem with Retrofit but with how the request is created/configured.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I knew that my configuration was off. I guess the question is/was whether it's worth spending the time to fiddle with the configuration until it works or just leave the okhttp3 as is. I think I know your answer 😉
|
|
||
| String json = response.body().string(); | ||
|
|
||
| JSONObject data = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable data initializer null is redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed to:
try {
JSONObject data = new JSONObject(json);| setUpSkipDialog(); | ||
| } | ||
|
|
||
| private void setUpButtons() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rearrange methods order (public, protected, private, etc.).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
| } | ||
|
|
||
| private void openChromeCustomTab(boolean creatingAccount) { | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit new lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
|
||
| if (getIntent() != null && getIntent().getAction().equals(Intent.ACTION_VIEW)) { | ||
| Uri uri = getIntent().getData(); | ||
| if (uri.getQueryParameter("error") != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not extracting uri.getQueryParameter("error") into a variable String error and being able to reuse it when logging (no need to query again)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I believe I've fixed with:
if (uri.getQueryParameter("error") != null) {
Toast.makeText(this, R.string.whoops_error_message_on_app_return, Toast.LENGTH_SHORT).show();
String error = uri.getQueryParameter("error");
Log.d("LandingActivity", "onResume: error = " + error);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@langsmith
Sorry, I meant replacing all 2 occurrences of uri.getQueryParameter("error"), define a new variable to store the value before the if check so it'll be available to reuse it inside and remove unnecessary String error inside the if.
Basically, move String error definition out of the if and reuse it as much as possible:
String error = uri.getQueryParameter("error");
if (error != null) {
Toast.makeText(this, R.string.whoops_error_message_on_app_return, Toast.LENGTH_SHORT).show();
Log.d("LandingActivity", "onResume: error = " + error);
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
| @@ -0,0 +1,44 @@ | |||
| package com.mapbox.mapboxandroiddemo.model.usermodel; | |||
|
|
|||
| /** | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove file headers.
Done. Thanks. Switched it to:
/** * TODO: Add a class header comment! */
You can leave it blank if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, fixed. Template is blank.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@langsmith
👀 There are still classes with file headers: Mapviews, Plan, Services, UserDirections and UserResponse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed from those classes
|
One more thing @langsmith rebase/fix up the commits to represent what would be merged into |
|
Thank you @langsmith @Guardiola31337, this is looking great. In order to unblock #336 I suggest that, if the OkHttp/Retrofit conversation is the one thing left here, that we move that work to a separate PR that allows us to merge this one. Happy to help reviewing that separate PR. |
|
Ok @zugaldia .
I believe I've fixed all of the issues that @Guardiola31337 has mentioned in this PR and in our Slack DMs, besides the two above. |
| @@ -0,0 +1,93 @@ | |||
| package com.mapbox.mapboxandroiddemo.model.usermodel; | |||
|
|
|||
| public class Authorizations { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@langsmith
Access can be package-private.
👀 the same thing happens in other classes inside usermodel package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
|
Made adjustments for your latest round of review @Guardiola31337 |
|
Next steps? @zugaldia , I've made separate tickets in this repo for the okHttp/Retrofit switch and for cleaning up the two manifest files, so that we don't forget about them. I've made changes for all of @Guardiola31337 's requests besides rebasing/fixing up the commits to represent what would be merged into |
Guardiola31337
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done @langsmith ![]()
PR adds oAuth2 flow for non-mandatory account login/creation before viewing examples.