Android Open Source - Learn-From-Me Letter Dao






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.dao;
/*from  ww  w .  ja va  2 s  .  co  m*/
import com.overnightApps.myapplication.app.core.Comment;
import com.overnightApps.myapplication.app.core.Letter;
import com.overnightApps.myapplication.app.core.User;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;

import java.io.Serializable;
import java.util.List;

/**
 * Created by andre on 3/21/14.
 */
public class LetterDao extends Dao<Letter, ParseObject, ParseQuery<ParseObject>> implements Serializable{
    public static final String RECIPIENT = "Recipient";
    public static final String MESSAGE = "Message";
    public static final String SIGNATURE = "Signature";
    public static final String CREATOR = "creator";
    public static final String ORIGINAL = "original";
    public static final String CLASS_NAME = "Letter";
    public static final String CREATION_TIME = "creationTime";
    public static final String VOTES = "votes";
    public static final String IS_SIGNED_PUBLICLY = "isSignedPublicly";
    public static final String POPULARITY = "popularity";
    private static LetterDao instance;
    private final UserDao userDao;

    private LetterDao(UserDao userDao) {
        this.userDao = userDao;
    }

    public static LetterDao instance() {
        if (instance == null) {
            instance = new LetterDao(UserDao.instance());
        }
        return instance;
    }

    public Letter convertToDomainObject(ParseObject parseLetter) {
        try {
            parseLetter.fetchIfNeeded();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String recipient = parseLetter.getString(RECIPIENT);
        String message = parseLetter.getString(MESSAGE);
        String signature = parseLetter.getString(SIGNATURE);
        User user = userDao.convertToDomainObject((ParseUser) parseLetter.get(CREATOR));
        Long creationTime = parseLetter.getLong(CREATION_TIME);
        List<Comment> comments = new CommentDao(parseLetter).getComments();
        Letter original;
        original = getOriginalLetter(parseLetter);
        int votes = parseLetter.getInt(VOTES);
        boolean isSignedPublicly = parseLetter.getBoolean(IS_SIGNED_PUBLICLY);
        return new Letter(recipient, message, signature, user, creationTime, comments, original,
                isSignedPublicly, votes);
    }

    private Letter getOriginalLetter(ParseObject parseLetter) {
        Letter original;
        if(parseLetter.get(ORIGINAL) == null){
            original = null;
        }else{
            original = convertToDomainObject((ParseObject) parseLetter.get(ORIGINAL));
        }
        return original;
    }

    @Override
    protected ParseObject getNewDataClassInstance() {
        return new ParseObject(CLASS_NAME);
    }

    @Override
    protected void saveDataClassFromDomain(ParseObject parseObject, Letter letter) {
        parseObject.put(RECIPIENT, letter.getRecipient());
        parseObject.put(MESSAGE, letter.getMessage());
        parseObject.put(SIGNATURE, letter.getSignature());
        parseObject.put(CREATOR, userDao.find(letter.getCreator()));
        Letter originalLetter = letter.getOriginal();
        if(originalLetter != null) {
            parseObject.put(ORIGINAL, LetterDao.instance().find(letter.getOriginal()));
        }
        parseObject.put(CREATION_TIME, letter.getCreationTime());
        parseObject.put(VOTES,letter.getVotes());
        parseObject.put(IS_SIGNED_PUBLICLY,letter.isSignedPublicly());
        new CommentDao(parseObject).saveList(letter.getCommentList());
    }

    @Override
    protected ParseQuery getNewUniqueResultQueryInstance(Letter letter) {
        ParseQuery query = getNewQueryInstance();
        query.whereEqualTo(SIGNATURE, letter.getSignature());
        query.whereEqualTo(CREATION_TIME, letter.getCreationTime());
        return query;
    }

    @Override
    protected ParseQuery getNewQueryInstance() {
        return new ParseQuery(CLASS_NAME);
    }
}




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