bengoblue05 / udacityalumni Goto Github PK
View Code? Open in Web Editor NEWUdacity Alumni Android App
Udacity Alumni Android App
See ToDo in ArticleDetailActivity
Open the app, select an article from the home screen and press the "Share" button on the toolbar.
I expect the share menu to appear so I can share a link to the article on the current page.
Nothing happens; a long press shows a Toast
message.
Tap on the list item to go to detail view
Come back to list view.
Tap on bookmark.
The list item should be bookmarked
The list item gets bookmarked and the detail view is also shown
Problem probably in onLoadFinished() of MainActivity (https://github.com/BenGoBlue05/UdacityAlumni/blob/master/app/src/main/java/com/google/developer/udacityalumni/activity/MainActivity.java)
This should not be there in onLoadFinished():
startActivity(new Intent(this, ArticleDetailActivity.class)
.putExtra(getString(R.string.article_list_key), ids)
.putExtra(getString(R.string.article_bookmarks_key), isBookmarked)
.putExtra(getString(R.string.tag_key), tags));
1)In the LoginActivity.java when i make the following changes-
a) Remove this line - findViewById(R.id.sign_in_button).setOnClickListener(this);
b)And use @OnClick annotation on sign_in_button because we are using butterknife library why doesn't the button respond to the click?
Button click should be noticed
Button does not respond. There is no crash as such. It is just a doubt
I changed the LoginActivity.java file to this -
package com.google.developer.udacityalumni.activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.developer.udacityalumni.R;
import com.google.developer.udacityalumni.model.User;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GoogleAuthProvider;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import butterknife.OnClick;
/**
* A login screen that offers login via email/password.
*/
public class LoginActivity extends BaseActivity implements GoogleApiClient.OnConnectionFailedListener {
private static final String LOG_TAG = LoginActivity.class.getSimpleName();
private static final int RC_SIGN_IN = 9001;
private GoogleApiClient mGoogleApiClient;
private FirebaseAuth mAuth;
private DatabaseReference mDatabase;
private FirebaseAuth.AuthStateListener mAuthListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
mAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance().getReference();
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) bindUserValues(user);
}
};
}
private void bindUserValues(@NonNull FirebaseUser user) {
DatabaseReference ref = mDatabase.child("users").child(user.getUid());
String displayName = user.getDisplayName();
String email = user.getEmail();
String photoUrl = user.getPhotoUrl() != null ? user.getPhotoUrl().toString() : null;
User usr = new User(displayName, email, photoUrl);
ref.setValue(usr);
}
@OnClick(R.id.sign_in_button)
public void signInButtonClicked(){
Log.i("TAG", "signInButtonClicked: ");
signIn();
}
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
} else {
Log.e(LOG_TAG, "Google Sign In failed.");
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.d(LOG_TAG, "firebaseAuthWithGoogle:" + acct.getId());
showProgressDialog();
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.i(LOG_TAG, "signIn:onComplete:" + task.isSuccessful());
hideProgressDialog();
if (!task.isSuccessful()) {
Log.i(LOG_TAG, "signInWithCredential", task.getException());
Toast.makeText(LoginActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
startActivity(new Intent(LoginActivity.this, MainActivity.class));
}
});
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
// An unresolvable error has occurred and Google APIs (including Sign-In) will not
// be available.
Log.d(LOG_TAG, "onConnectionFailed:" + connectionResult);
Toast.makeText(this, "Google Play Services error.", Toast.LENGTH_SHORT).show();
}
@Override
public void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
@Override
public void onStop() {
super.onStop();
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
}
}
when article have empty tags list, It causes App Crash
365/com.google.developer.udacityalumni E/AndroidRuntime: FATAL EXCEPTION: IntentService[AlumIntentService]
Process: com.google.developer.udacityalumni, PID: 1239
java.lang.IllegalArgumentException: n <= 0: 0
at java.util.Random.nextInt(Random.java:182)
at com.google.developer.udacityalumni.service.AlumIntentService.addArticles(AlumIntentService.java:54)
at com.google.developer.udacityalumni.service.AlumIntentService.onHandleIntent(AlumIntentService.java:108)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
check last article item in json response
AlumIntentService
should check for empty tag list in json response before using it.
Right now in AlumIntentService
we are casting the JSONObject
and JSONArray
.
Json String Casting can be done many ways, but Gson is the best one for now.
it will be easy for any buddy to just call a method of from Utils to serialize the Json String to Java Object.
It would be nice if the project has a DI setup in place. Not only it will help in development and following best practices but can also be a starting point for developers and students new to the term.
Should be minSDKVersion be as high as 21? I believe it should be 16 or 17 so that the app runs on more than 95% of the devices. @BenGoBlue05
What are steps we can follow to reproduce this issue?
What did you expected to happen?
What did happened instead?
e.g. the stack trace of a crash
Provide a code sample or test case that highlights the issue.
If relevant, include your model definitions.
For larger code samples, links to external gists / repositories are preferred.
Open the application. Shortly after loading the home page, the application will crash with the following LogCat message:
java.lang.IllegalArgumentException: n <= 0: 0
at java.util.Random.nextInt(Random.java:182)
at com.google.developer.udacityalumni.service.AlumIntentService.addArticles(AlumIntentService.java:55)
at com.google.developer.udacityalumni.service.AlumIntentService.onHandleIntent(AlumIntentService.java:109)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.os.HandlerThread.run(HandlerThread.java:61)
The problem appears to be caused on this line in AlumIntentService
:
JSONArray tags = article.getJSONArray(KEY_TAGS);
int ind = new Random().nextInt(tags.length());
If tags
has a length of zero, then the application crashes as the nextInt()
method in Random
cannot accept zero as an argument.
Checking the JSON file at http://udacity-alumni-api.herokuapp.com/api/v1/articles
shows what's likely causing the problem (note the empty tags array):
{
"id": 11,
"title": "my title",
"featured": false,
"spotlighted": true,
"content": "yo this is my story\n",
"feature_image": "",
"status": "draft",
"slug": "my-title",
"user": {
"id": 15,
"email": "[email protected]",
"created_at": "2017-01-25T09:33:40.858Z",
"updated_at": "2017-01-25T09:43:34.337Z",
"name": "noah hall",
"avatar": null,
"role": "user",
"bio": "",
"public": true
},
"created_at": "2017-01-25T10:41:15.683Z",
"updated_at": "2017-01-25T10:41:15.709Z",
"tags": [
]
}
Open the side navigation menu and select either My Classroom, Catlog or Success Stores to open the Chrome Custom Tabs browser. The browser will animate in by sliding from the right side of the screen to the left. Then exit by pressing back, and a different animation is used that is part-translation and part-fade.
It would be better to match the exit animation so it is a true reversal of the entry animation.
What are steps we can follow to reproduce this issue?
What did you expected to happen?
What did happened instead?
e.g. the stack trace of a crash
Provide a code sample or test case that highlights the issue.
If relevant, include your model definitions.
For larger code samples, links to external gists / repositories are preferred.
We can follow any if them, I can take responsibility for this.
I am suggesting the MVP architecture then It will become easy to write the unit test and Integration test and without any architecture, It's very hard to write the test cases.
What do you think @BenGoBlue05 @PPartisan @chashmeetsingh
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.