Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="guava-15.0" level="project" />
<orderEntry type="library" exported="" name="play-services-6.5.87" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.2" level="project" />
<orderEntry type="library" exported="" name="dagger-1.2.2" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
<orderEntry type="library" exported="" name="library-1.3" level="project" />
<orderEntry type="library" exported="" name="eventbus-2.4.0" level="project" />
<orderEntry type="library" exported="" name="httpclientandroidlib-1.1.2" level="project" />
Expand All @@ -96,11 +96,11 @@
<orderEntry type="library" exported="" name="dagger-compiler-1.2.2" level="project" />
<orderEntry type="library" exported="" name="library-1.0.8" level="project" />
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.2" level="project" />
<orderEntry type="library" exported="" name="YouTubeAndroidPlayerApi" level="project" />
<orderEntry type="library" exported="" name="javax.inject-1" level="project" />
<orderEntry type="library" exported="" name="achartengine-1.1.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-21.0.2" level="project" />
<orderEntry type="library" exported="" name="bolts-android-1.1.2" level="project" />
<orderEntry type="library" exported="" name="javawriter-2.5.0" level="project" />
</component>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</meta-data>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBvatkHkBtQ8lk6xtRnd4ZXTX8CgxfsZQQ" >
android:value="AIzaSyBpDIEEPbFGUr7cvXI5_nq04J6i5fou9rY" >
</meta-data>

<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import com.eswaraj.app.eswaraj.events.GetCategoriesDataEvent;
import com.eswaraj.app.eswaraj.events.GetCategoriesImagesEvent;
import com.eswaraj.app.eswaraj.events.GetUserEvent;
import com.eswaraj.app.eswaraj.events.LoginResultEvent;
import com.eswaraj.app.eswaraj.fragments.SplashFragment;
import com.eswaraj.app.eswaraj.interfaces.FacebookLoginInterface;
import com.eswaraj.app.eswaraj.interfaces.LaunchNextActivityInterface;
import com.eswaraj.app.eswaraj.models.UserSession;
import com.eswaraj.app.eswaraj.util.LocationUtil;
import com.eswaraj.app.eswaraj.middleware.MiddlewareServiceImpl;
import com.eswaraj.app.eswaraj.util.InternetServicesCheckUtil;
Expand All @@ -25,7 +27,7 @@

import de.greenrobot.event.EventBus;

public class SplashActivity extends BaseActivity implements FacebookLoginInterface, LaunchNextActivityInterface {
public class SplashActivity extends BaseActivity implements LaunchNextActivityInterface {

private SplashFragment splashFragment;
@Inject
Expand All @@ -40,33 +42,21 @@ public class SplashActivity extends BaseActivity implements FacebookLoginInterfa
EventBus eventBus;

//Logged-in user
UserDto userDto;
@Inject
UserSession userSession;

//Internet and Location service availability
Boolean hasNeededServices;

//Maintain async task return state
Boolean loginDone;
Boolean serverDataDownloadDone;
Boolean redirectDone;
Boolean userLocationKnown;

//Facebook Session
Session session;


@Override
protected void onStart() {
super.onStart();
eventBus.registerSticky(this);

//Start location service
locationUtil.startLocationService();
//Start data download from server, if needed
middlewareService.loadCategoriesData(this, true);
//Check if Internet connection and Location services are present. If not, don't proceed.
hasNeededServices = checkLocationAndInternet();
splashFragment.notifyServiceAvailability(hasNeededServices);
}

@Override
Expand All @@ -81,26 +71,24 @@ protected void onStop() {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
eventBus.register(this);

splashFragment = SplashFragment.newInstance("", "");
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().add(R.id.SplashFragmentContainer, splashFragment).commit();
}
splashFragment = (SplashFragment)getSupportFragmentManager().findFragmentById(R.id.splash_fragment);

locationUtil.setup(this);

//Set up initial state
loginDone = false;
serverDataDownloadDone = false;
redirectDone = false;
userLocationKnown = false;

}
//Start location service
locationUtil.startLocationService();
//Start data download from server, if needed
middlewareService.loadCategoriesData(this, true);
//Check if Internet connection and Location services are present. If not, don't proceed.
hasNeededServices = checkLocationAndInternet();
splashFragment.notifyServiceAvailability(hasNeededServices);

@Override
public void onFacebookLoginDone(Session session) {
this.session = session;
middlewareService.loadUserData(this, session);
}

@Override
Expand Down Expand Up @@ -135,47 +123,33 @@ public void onEventMainThread(GetCategoriesDataEvent event) {
}
}

public void onEventMainThread(GetUserEvent event) {
if(event.getSuccess()) {
Log.d("SplashActivity", "GetUserEvent:Success");
userDto = event.getUserDto();
loginDone = true;
if(userDto.getPerson().getPersonAddress() != null) {
if(userDto.getPerson().getPersonAddress().getLongitude() != null) {
userLocationKnown = true;
}
}
if(serverDataDownloadDone) {
appReady();
}
}
else {
Toast.makeText(this, "Could not fetch user details from server. Error = " + event.getError(), Toast.LENGTH_LONG).show();
//Show retry button which will re-trigger the request.
}
}



//Event When Login is Completed either fail or Success
public void onEventMainThread(LoginResultEvent event) {
takeUserToNextScreen();
}
public void onEventMainThread(GetCategoriesImagesEvent event) {
if(event.getSuccess()) {
Log.d("SplashActivity", "GetCategoriesImagesEvent:Success");
serverDataDownloadDone = true;
if (loginDone) {
if (splashFragment.getLoginDone()) {
appReady();
}
}
else {
Toast.makeText(this, "Could not fetch all categories images from server. Error = " + event.getError(), Toast.LENGTH_LONG).show();
//Show retry button which will re-trigger the request.
serverDataDownloadDone = true;
if (loginDone) {
if (splashFragment.getLoginDone()) {
appReady();
}
}
}

private void appReady() {
splashFragment.setShowInstruction(!userLocationKnown);
splashFragment.setShowInstruction(!userSession.isUserLocationKnown());
splashFragment.notifyAppReady();
}

Expand All @@ -190,15 +164,14 @@ public void takeUserToNextScreen() {
} else {
redirectDone = true;
Intent i = null;
if(userLocationKnown) {
if(userSession.isUserLocationKnown()) {
i = new Intent(this, SelectAmenityActivity.class);
}
else {
i = new Intent(this, MarkLocationActivity.class);
}
startActivity(i);
locationUtil.stopLocationService();
eventBus.unregister(this);
finish(); //User cant press back to return to this activity
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.eswaraj.app.eswaraj.events;

/**
* Created by Ravi on 24/12/2014.
*/
public class LoginResultEvent {
private boolean success;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,32 @@
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.eswaraj.app.eswaraj.R;
import com.eswaraj.app.eswaraj.base.BaseFragment;
import com.eswaraj.app.eswaraj.events.GetUserEvent;
import com.eswaraj.app.eswaraj.events.LoginResultEvent;
import com.eswaraj.app.eswaraj.interfaces.FacebookLoginInterface;
import com.eswaraj.app.eswaraj.interfaces.LaunchNextActivityInterface;
import com.eswaraj.app.eswaraj.middleware.MiddlewareServiceImpl;
import com.eswaraj.app.eswaraj.models.UserSession;
import com.eswaraj.app.eswaraj.util.FacebookLoginUtil;
import com.eswaraj.web.dto.UserDto;
import com.facebook.Session;
import com.facebook.widget.LoginButton;
import com.pnikosis.materialishprogress.ProgressWheel;

import javax.inject.Inject;

import de.greenrobot.event.EventBus;


public class SplashFragment extends BaseFragment implements FacebookLoginInterface {

Expand All @@ -30,17 +39,24 @@ public class SplashFragment extends BaseFragment implements FacebookLoginInterfa
TextView welcomeText;
ProgressWheel progressWheel;

boolean loginDone = false;

//Facebook Session
Session session;

@Inject
FacebookLoginUtil facebookLoginUtil;
UserSession userSession;

private Boolean showInstruction;
@Inject
EventBus eventBus;

public static SplashFragment newInstance(String param1, String param2) {
SplashFragment fragment = new SplashFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
@Inject
MiddlewareServiceImpl middlewareService;

@Inject
FacebookLoginUtil facebookLoginUtil;

private boolean showInstruction = false;

public SplashFragment() {
// Required empty public constructor
Expand All @@ -50,6 +66,7 @@ public SplashFragment() {
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);


//References to UI elements
buttonLogin = (LoginButton) getView().findViewById(R.id.buttonLogin);
buttonQuit = (Button) getView().findViewById(R.id.buttonQuit);
Expand Down Expand Up @@ -94,7 +111,7 @@ public void notifyServiceAvailability(Boolean hasNeededServices) {
}
}

public void setShowInstruction(Boolean show) {
public void setShowInstruction(boolean show) {
showInstruction = show;
}

Expand All @@ -107,21 +124,20 @@ public void notifyAppReady() {
welcomeText.setText("The app is setup.\n\nOn the next screen you will be asked to mark your home location on a map.\n\nThis is a one-time activity and will help us serve you data about your constituency.");
buttonGotIt.setVisibility(View.VISIBLE);
}
else {
((LaunchNextActivityInterface) getActivity()).takeUserToNextScreen();
}
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
facebookLoginUtil.onCreate(this, savedInstanceState);
eventBus.register(this);
}

@Override
public void onDestroy() {
super.onDestroy();
facebookLoginUtil.onDestroy();
eventBus.unregister(this);
}

@Override
Expand Down Expand Up @@ -155,7 +171,8 @@ public void onFacebookLoginDone(Session session) {
buttonLogin.setVisibility(View.INVISIBLE);
progressWheel.setVisibility(View.VISIBLE);
progressWheel.spin();
((FacebookLoginInterface)getActivity()).onFacebookLoginDone(session);
this.session = session;
middlewareService.loadUserData(this.getActivity(), session);
}


Expand All @@ -164,4 +181,29 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebookLoginUtil.onActivityResult(requestCode, resultCode, data);
}

public boolean getLoginDone() {
return loginDone;
}

public void setLoginDone(boolean loginDone) {
this.loginDone = loginDone;
}

public void onEventMainThread(GetUserEvent event) {
if(event.getSuccess()) {
Log.d("SplashActivity", "GetUserEvent:Success");
UserDto userDto = event.getUserDto();
userSession.setUser(userDto);
notifyAppReady();
}
else {
Toast.makeText(this.getActivity(), "Could not fetch user details from server. Error = " + event.getError(), Toast.LENGTH_LONG).show();
//Show retry button which will re-trigger the request.
}
LoginResultEvent loginResultEvent = new LoginResultEvent();
eventBus.post(loginResultEvent);
}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.eswaraj.app.eswaraj.helpers;

import android.app.Activity;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/com/eswaraj/app/eswaraj/models/UserSession.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.eswaraj.app.eswaraj.models;

import com.eswaraj.web.dto.UserDto;

/**
* Created by Ravi on 24/12/2014.
*/
public class UserSession {
private UserDto user;

public boolean isUserLocationKnown(){
if(user.getPerson().getPersonAddress() != null) {
if(user.getPerson().getPersonAddress().getLongitude() != null) {
return true;
}
}
return false;
}
public UserDto getUser() {
return user;
}

public void setUser(UserDto user) {
this.user = user;
}

}
Loading