Android Open Source - Learn-From-Me Receive Recommendations Fragment






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.ui.homeFragments;
//from  w w w. j ava2  s  . com
import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.nhaarman.listviewanimations.swinginadapters.prepared.SwingBottomInAnimationAdapter;
import com.overnightApps.myapplication.app.R;
import com.overnightApps.myapplication.app.core.User;
import com.overnightApps.myapplication.app.dao.exceptions.DataClassNotFoundException;
import com.overnightApps.myapplication.app.dao.LetterDao;
import com.overnightApps.myapplication.app.dao.LetterRecommendationDao;
import com.overnightApps.myapplication.app.dao.UserDao;
import com.overnightApps.myapplication.app.service.FriendshipSession;
import com.overnightApps.myapplication.app.service.UserSession;
import com.overnightApps.myapplication.app.ui.FragmentIds;
import com.overnightApps.myapplication.app.ui.homeFragments.absFragments.MyListFragment;
import com.overnightApps.myapplication.app.ui.homeFragments.asyncTasks.LoadDetailFragmentTask;
import com.overnightApps.myapplication.app.ui.homeFragments.homeActivityInteractionInterfaces.OnLetterDetailFragmentListener;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseQueryAdapter;
import com.parse.ParseUser;

import junit.framework.Assert;

/**
 * Created by andre on 4/2/14.
 */
public class ReceiveRecommendationsFragment extends MyListFragment {
    private static final String USER_SERVICE_ARG = "User Service Arg";
    private UserSession userSession;
    private OnLetterDetailFragmentListener onLetterDetailFragmentListener;
    private ParseQuery<ParseObject> query;
    private ParseLetterRecommendationsQuery adapter;

    public ReceiveRecommendationsFragment() {
    }

    public static ReceiveRecommendationsFragment newInstance(UserSession userSession){
        Bundle arguments = new Bundle();
        arguments.putSerializable(USER_SERVICE_ARG, userSession);
        ReceiveRecommendationsFragment receiveRecommendationsFragment = new ReceiveRecommendationsFragment();
        receiveRecommendationsFragment.setArguments(arguments);
        return receiveRecommendationsFragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Assert.assertNotNull(getArguments());
        userSession = (UserSession) getArguments().getSerializable(USER_SERVICE_ARG);
        Assert.assertNotNull(userSession);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        onLetterDetailFragmentListener = (OnLetterDetailFragmentListener)activity;
    }

    @Override
    public void onDetach() {
        super.onDetach();
        onLetterDetailFragmentListener = null;
    }

    @Override
    public void onResume() {
        super.onResume();
        ParseUser parseUser;
        try {
            parseUser = UserDao.instance().find(userSession.getCurrentUser()); //TODO - move to function in userService
        } catch (DataClassNotFoundException dataClassNotFoundException) {
            Log.e("","error while loading recommendations try again later", dataClassNotFoundException);
            dataClassNotFoundException.printStackTrace();
            return;
        }
        loadUserRecommendations(parseUser);
    }

    private void loadUserRecommendations(ParseUser parseUser) {
        query = new ParseQuery(LetterRecommendationDao.CLASS_NAME);
        query.orderByDescending(LetterRecommendationDao.CREATED_AT_TAG);
        query.whereEqualTo(LetterRecommendationDao.TO, parseUser);
        adapter =
                new ParseLetterRecommendationsQuery(getActivity(),
                        new ParseQueryAdapter.QueryFactory<ParseObject>() {
                            public ParseQuery<ParseObject> create() {
                                return query;
                            }
                        });
        SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(adapter);
        swingBottomInAnimationAdapter.setInitialDelayMillis(300);
        swingBottomInAnimationAdapter.setAbsListView(getListView());
        setListAdapter(swingBottomInAnimationAdapter);
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        LoadDetailFragmentTask loadDetailFragmentTask = new LoadDetailFragmentTask();
        loadDetailFragmentTask.setActivity(getActivity());
        loadDetailFragmentTask.setUserSession(userSession);
        loadDetailFragmentTask.execute(adapter.getItem(0));
    }

    @Override
    public int getFragmentId() {
        return FragmentIds.RECEIVE_RECOMMENDATIONS.getId();
    }

    private class ParseLetterRecommendationsQuery extends ParseQueryAdapter<ParseObject> {
        private ParseLetterRecommendationsQuery(Context context, Class clazz) {
            super(context, clazz);
        }

        private ParseLetterRecommendationsQuery(Context context, String className) {
            super(context, className);
        }

        private ParseLetterRecommendationsQuery(Context context, Class clazz, int itemViewResource) {
            super(context, clazz, itemViewResource);
        }

        private ParseLetterRecommendationsQuery(Context context, String className, int itemViewResource) {
            super(context, className, itemViewResource);
        }

        private ParseLetterRecommendationsQuery(Context context, ParseQueryAdapter.QueryFactory queryFactory) {
            super(context, queryFactory);
        }

        private ParseLetterRecommendationsQuery(Context context, ParseQueryAdapter.QueryFactory queryFactory, int itemViewResource) {
            super(context, queryFactory, itemViewResource);
        }

        public View getItemView(ParseObject recommendation, View v, ViewGroup parent) {
            if (v == null) {
                v = View.inflate(getContext(), R.layout.letter_recommendations, null);
            }
            ParseObject letter = recommendation.getParseObject(LetterRecommendationDao.LETTER);
            try {
                letter = letter.fetchIfNeeded();
            } catch (ParseException e) {
                e.printStackTrace();
            }
            TextView recipient = (TextView) v.findViewById(R.id.tv_recipient);
            recipient.setText("Dear, " + letter.getString(LetterDao.RECIPIENT));
            TextView message = (TextView) v.findViewById(R.id.tv_message);
            message.setText(letter.getString(LetterDao.MESSAGE));
            TextView signature = (TextView) v.findViewById(R.id.tv_signature);
            signature.setText(letter.getString(LetterDao.SIGNATURE));

            //referer
            new LoadFriendShipAsyncTask(v).execute(recommendation);
               return v;
        }
    }

    class LoadFriendShipAsyncTask extends AsyncTask<ParseObject,Void,String>{
        final View listItem;

        LoadFriendShipAsyncTask(View listItem) {
            this.listItem = listItem;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            getActivity().setProgressBarIndeterminateVisibility(true);
        }

        @Override
        protected String doInBackground(ParseObject... params) {
            ParseObject recommendation = params[0];
            String refererSignature = "";
            User referer = UserDao.instance().convertToDomainObject(recommendation.getParseUser(LetterRecommendationDao.FROM));
            FriendshipSession friendshipSession = FriendshipSession.friendshipServiceInstance(
                    userSession.getCurrentUser(), referer);
            if(friendshipSession.isFriendTrusted()){
                refererSignature += "Trusted User";
            }else{
                refererSignature += referer.getFullName();
            }
            return refererSignature;
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            getActivity().setProgressBarIndeterminateVisibility(false);
            TextView tv_referer = (TextView) listItem.findViewById(R.id.tv_referer);
            tv_referer.setText("Referred by: " + s);
        }
    }
}




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