Android Open Source - Learn-From-Me Friendship Session






From Project

Back to project page Learn-From-Me.

License

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.

Java Source Code

package com.overnightApps.myapplication.app.service;
/*from www . ja v  a2  s  . c om*/
import com.overnightApps.myapplication.app.core.FriendShipRequest;
import com.overnightApps.myapplication.app.core.Friendship;
import com.overnightApps.myapplication.app.core.User;
import com.overnightApps.myapplication.app.dao.FriendshipDao;
import com.overnightApps.myapplication.app.dao.FriendshipRequestDao;

/**
 * Created by andre on 3/25/14.
 */
public class FriendshipSession {
    private final FriendshipRequestDao friendshipRequestDao;
    private final FriendshipDao friendshipDao;
    private final User currentUser;
    private final User friend;

    public FriendshipSession(FriendshipRequestDao friendshipRequestDao, FriendshipDao friendshipDao, User currentUser, User friend) {
        this.friendshipRequestDao = friendshipRequestDao;
        this.friendshipDao = friendshipDao;
        this.currentUser = currentUser;
        this.friend = friend;
    }

    public static FriendshipSession friendshipServiceInstance(User current, User friend) {
        return new FriendshipSession(FriendshipRequestDao.instance(), FriendshipDao.instance(), current, friend);
    }

    public FriendShipState getFriendshipState() {
        FriendShipRequest friendShipRequest = friendshipRequestDao.get(currentUser, friend);
        if (isFriendshipRequestFound(friendShipRequest)) {
            return FriendShipState.NONE;
        }
        if (!friendShipRequest.isResponded()) {
            if (isCurrentUserRequestSender(friendShipRequest)) {
                return FriendShipState.WAITING_FOR_RESPONSE;
            } else {
                return FriendShipState.RECEIVED_REQUEST;
            }
        } else {
            if (!friendShipRequest.isAccepted()) {
                return FriendShipState.DENIED;
            } else if (isFriendTrusted(friend)) {
                return FriendShipState.TRUSTED_FRIEND;
            } else {
                return FriendShipState.UNTRUSTED_FRIEND;
            }
        }
    }

    public void sendFriendRequest() {
        friendshipRequestDao.save(new FriendShipRequest(friend,currentUser, false, false));
    }

    public void acceptFriendRequest() {
        FriendShipRequest friendShipRequest = friendshipRequestDao.get(currentUser, friend);
        friendShipRequest.acceptFriendRequest();
        friendshipRequestDao.save(friendShipRequest);
        Friendship newFriendShip1 = new Friendship(currentUser,friend,false);
        friendshipDao.save(newFriendShip1);
        Friendship newFriendShip2 = new Friendship(friend,currentUser,false);
        friendshipDao.save(newFriendShip2);
    }

    public void denyFriendRequest() {
        FriendShipRequest friendShipRequest = friendshipRequestDao.get(currentUser, friend);
        friendShipRequest.denyFriendRequest();
        friendshipRequestDao.save(friendShipRequest);
    }

    public void trustUser() {
        Friendship friendship = friendshipDao.getFriendship(currentUser, friend);
        friendship.trustUser();
        friendshipDao.save(friendship);
    }

    public void unTrustUser() {
        Friendship friendship = friendshipDao.getFriendship(currentUser, friend);
        friendship.unTrustUser();
        friendshipDao.save(friendship);
    }

    private boolean isFriendTrusted(User friend) {
        return friendshipDao.getFriendship(currentUser, friend).isTrusted();
    }

    private boolean isFriendshipRequestFound(FriendShipRequest friendShipRequest) {
        return friendShipRequest == null;
    }

    private boolean isCurrentUserRequestSender(FriendShipRequest friendShipRequest) {
        return friendShipRequest.getFrom().equals(currentUser);
    }

    public boolean isFriendTrusted() {
        Friendship friendship = friendshipDao.getFriendship(currentUser,friend);
        return friendship != null && friendship.isTrusted();
    }

    public enum FriendShipState {
        TRUSTED_FRIEND("Un-trust User"), UNTRUSTED_FRIEND("Trust User"),
        WAITING_FOR_RESPONSE("Waiting For Response"), RECEIVED_REQUEST("Accept Friend Request"),
        NONE("Add as a Friend"), DENIED("You Denied Friend Request");
        final String getMessageForUser;

        FriendShipState(String getMessageForUser) {
            this.getMessageForUser = getMessageForUser;
        }

        public String getMessageForUser() {
            return getMessageForUser;
        }
    }
}




Java Source Code List

com.overnightApps.myapplication.app.CustomApplication.java
com.overnightApps.myapplication.app.core.Comment.java
com.overnightApps.myapplication.app.core.FriendShipRequest.java
com.overnightApps.myapplication.app.core.Friendship.java
com.overnightApps.myapplication.app.core.LetterRecommendation.java
com.overnightApps.myapplication.app.core.LetterVote.java
com.overnightApps.myapplication.app.core.Letter.java
com.overnightApps.myapplication.app.core.User.java
com.overnightApps.myapplication.app.core.helper.LetterWithUserVote.java
com.overnightApps.myapplication.app.core.helper.SignUpForm.java
com.overnightApps.myapplication.app.dao.CommentDao.java
com.overnightApps.myapplication.app.dao.Dao.java
com.overnightApps.myapplication.app.dao.FriendshipDao.java
com.overnightApps.myapplication.app.dao.FriendshipRequestDao.java
com.overnightApps.myapplication.app.dao.LetterDao.java
com.overnightApps.myapplication.app.dao.LetterRecommendationDao.java
com.overnightApps.myapplication.app.dao.LetterVoteDao.java
com.overnightApps.myapplication.app.dao.UserDao.java
com.overnightApps.myapplication.app.dao.exceptions.DataClassNotFoundException.java
com.overnightApps.myapplication.app.dao.exceptions.SavedUserIsNotFoundOnBackEndException.java
com.overnightApps.myapplication.app.dao.exceptions.UnableToSignUpException.java
com.overnightApps.myapplication.app.service.FriendshipSession.java
com.overnightApps.myapplication.app.service.LetterSender.java
com.overnightApps.myapplication.app.service.LetterVoter.java
com.overnightApps.myapplication.app.service.PrivateLetterSender.java
com.overnightApps.myapplication.app.service.PublicLetterSender.java
com.overnightApps.myapplication.app.service.RecommendationCreator.java
com.overnightApps.myapplication.app.service.SignUpFormVerifier.java
com.overnightApps.myapplication.app.service.SignUpSubmissionBuilder.java
com.overnightApps.myapplication.app.service.SignUpSubmission.java
com.overnightApps.myapplication.app.service.UserLogIn.java
com.overnightApps.myapplication.app.service.UserSession.java
com.overnightApps.myapplication.app.ui.FragmentIds.java
com.overnightApps.myapplication.app.ui.HomeActivity.java
com.overnightApps.myapplication.app.ui.homeFragments.CommentsFragment.java
com.overnightApps.myapplication.app.ui.homeFragments.CreateLetterFragment.java
com.overnightApps.myapplication.app.ui.homeFragments.FriendRequestsFragment.java
com.overnightApps.myapplication.app.ui.homeFragments.FriendsFragment.java
com.overnightApps.myapplication.app.ui.homeFragments.LearnFragment.java
com.overnightApps.myapplication.app.ui.homeFragments.LogInDialogFragment.java
com.overnightApps.myapplication.app.ui.homeFragments.ReceiveRecommendationsFragment.java
com.overnightApps.myapplication.app.ui.homeFragments.SendRecommendationFragment.java
com.overnightApps.myapplication.app.ui.homeFragments.SettingsFragment.java
com.overnightApps.myapplication.app.ui.homeFragments.UserLogInStateDependentFragments.LetterDetailFragmentUserNotLoggedIn.java
com.overnightApps.myapplication.app.ui.homeFragments.UserLogInStateDependentFragments.LetterDetailFragment_UserLoggedIn.java
com.overnightApps.myapplication.app.ui.homeFragments.UserLogInStateDependentFragments.LetterDetailFragment.java
com.overnightApps.myapplication.app.ui.homeFragments.UserLogInStateDependentFragments.UserFragment_UserLoggedIn.java
com.overnightApps.myapplication.app.ui.homeFragments.UserLogInStateDependentFragments.UserFragment_UserLoggedOut.java
com.overnightApps.myapplication.app.ui.homeFragments.UserLogInStateDependentFragments.UserFragment.java
com.overnightApps.myapplication.app.ui.homeFragments.absFragments.FilterListFragment.java
com.overnightApps.myapplication.app.ui.homeFragments.absFragments.HomeFragment.java
com.overnightApps.myapplication.app.ui.homeFragments.absFragments.MyListFragment.java
com.overnightApps.myapplication.app.ui.homeFragments.asyncTasks.LoadDetailFragmentTask.java
com.overnightApps.myapplication.app.ui.homeFragments.homeActivityInteractionInterfaces.OnActiveFragmentListener.java
com.overnightApps.myapplication.app.ui.homeFragments.homeActivityInteractionInterfaces.OnCreateLetterFragmentListener.java
com.overnightApps.myapplication.app.ui.homeFragments.homeActivityInteractionInterfaces.OnLetterDetailActionListener.java
com.overnightApps.myapplication.app.ui.homeFragments.homeActivityInteractionInterfaces.OnLetterDetailFragmentListener.java
com.overnightApps.myapplication.app.ui.homeFragments.homeActivityInteractionInterfaces.OnLoginFragmentListener.java
com.overnightApps.myapplication.app.ui.homeFragments.homeActivityInteractionInterfaces.OnSignUpActivityListener.java
com.overnightApps.myapplication.app.ui.homeFragments.homeActivityInteractionInterfaces.OnUserFragmentListener.java
com.overnightApps.myapplication.app.ui.homeFragments.homeActivityInteractionInterfaces.OnUserLogInListener.java
com.overnightApps.myapplication.app.ui.homeFragments.homeActivityInteractionInterfaces.OnUserLogOutListener.java
com.overnightApps.myapplication.app.ui.optionsMenus.MenuItem.java
com.overnightApps.myapplication.app.ui.optionsMenus.MenuOptionsBuilder.java
com.overnightApps.myapplication.app.ui.optionsMenus.MenuOptions.java
com.overnightApps.myapplication.app.ui.optionsMenus.menuOptionFactories.FriendMenuOptionsFactory.java
com.overnightApps.myapplication.app.ui.optionsMenus.menuOptionFactories.HomeMenuOptionsFactory.java
com.overnightApps.myapplication.app.ui.optionsMenus.menuOptionFactories.LetterMenuOptionsFactory.java
com.overnightApps.myapplication.app.ui.optionsMenus.menuOptionFactories.MenuOptionsFactory.java
com.overnightApps.myapplication.app.ui.optionsMenus.menuOptionFactories.RecommendationMenuOptionsFactory.java
com.overnightApps.myapplication.app.ui.signUp.NoSwipingViewPager.java
com.overnightApps.myapplication.app.ui.signUp.OnSignUpListener.java
com.overnightApps.myapplication.app.ui.signUp.OnUserSelectSignUpMethodListener.java
com.overnightApps.myapplication.app.ui.signUp.SelectSignUpMethodFragment.java
com.overnightApps.myapplication.app.ui.signUp.SignUpActivity.java
com.overnightApps.myapplication.app.ui.signUp.UploadProfilePictureFragment.java
com.overnightApps.myapplication.app.ui.signUp.UserSignUpFormFragment.java
com.overnightApps.myapplication.app.ui.slidingMenu.OptionsFragment.java
com.overnightApps.myapplication.app.util.AUtil.java
com.overnightApps.myapplication.app.util.BitmapUtil.java
com.overnightApps.myapplication.app.util.Logger.java
com.overnightApps.myapplication.app.util.MyAssert.java