Back to project page Learn-From-Me.
The source code is released under:
Apache License
If you think the Android project Learn-From-Me listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.overnightApps.myapplication.app.service; /*from www. j a v a 2s . com*/ import com.overnightApps.myapplication.app.core.User; import com.overnightApps.myapplication.app.dao.UserDao; import com.overnightApps.myapplication.app.dao.exceptions.DataClassNotFoundException; import com.overnightApps.myapplication.app.dao.exceptions.SavedUserIsNotFoundOnBackEndException; import junit.framework.Assert; import java.io.Serializable; /** * Created by andre on 3/25/14. */ public class UserSession implements Serializable { private User currentUser; private final UserDao userDao; private boolean isRestoreCurrentUserFunctionCalled; public static UserSession newInstance(){ return new UserSession(UserDao.instance(),null,false); } public UserSession(UserDao userDao, User currentUser, boolean isRestoreCurrentUserFunctionCalled) { this.userDao = userDao; this.currentUser = currentUser; this.isRestoreCurrentUserFunctionCalled = isRestoreCurrentUserFunctionCalled; } public User getCurrentUser() { Assert.assertTrue(isRestoreCurrentUserFunctionCalled); return currentUser; } public void restoreSavedUser() throws SavedUserIsNotFoundOnBackEndException { try { User user = userDao.getSavedUser(); currentUser = userDao.searchForUserByEmail(user.getEmail()); } catch (DataClassNotFoundException dataClassNotFoundException){ currentUser = null; }finally { isRestoreCurrentUserFunctionCalled = true; } } public boolean isUserLoggedIn(){ return currentUser != null; } public void logCurrentUserOut() { userDao.logUserOut(); } }