Android Open Source - Learn-From-Me Send Recommendation 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;
//w w  w. j ava 2  s . c  o m
import android.content.Context;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
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.Letter;
import com.overnightApps.myapplication.app.core.User;
import com.overnightApps.myapplication.app.dao.UserDao;
import com.overnightApps.myapplication.app.service.RecommendationCreator;
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.util.BitmapUtil;
import com.overnightApps.myapplication.app.util.Logger;
import com.parse.GetDataCallback;
import com.parse.ParseException;
import com.parse.ParseFile;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseQueryAdapter;
import com.parse.ParseUser;

import junit.framework.Assert;

import java.util.ArrayList;

/**
 * A fragment representing a list of Items.
 * <p />
 * <p />
 */
public class SendRecommendationFragment extends MyListFragment {
    private static final String LETTER_ARG = "LetterARg";
    private static final String USER_SERVICE_ARG = "userServiceArg";

    private ParseFriendQueryAdapter adapter;
    private Letter letterBeingRecommended;
    private UserSession userSession;

    public static SendRecommendationFragment newInstance(UserSession userSession, Letter letter) {
        SendRecommendationFragment fragment = new SendRecommendationFragment();
        Bundle args = new Bundle();
        args.putSerializable(LETTER_ARG,letter);
        args.putSerializable(USER_SERVICE_ARG, userSession);
        fragment.setArguments(args);
        return fragment;
    }

    public SendRecommendationFragment() {
    }

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

    @Override
    public void onStart() {
        super.onStart();
        adapter =
                new ParseFriendQueryAdapter(getActivity(), new ParseQueryAdapter.QueryFactory<ParseObject>() {
                    public ParseQuery<ParseObject> create() {
                        ParseQuery query = new ParseQuery("Friendship");
                        query.whereEqualTo("user", ParseUser.getCurrentUser());
                        return query;
                    }
                });
        SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(adapter);
        swingBottomInAnimationAdapter.setInitialDelayMillis(300);
        swingBottomInAnimationAdapter.setAbsListView(getListView());

        setListAdapter(swingBottomInAnimationAdapter);
    }

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

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        User user = UserDao.instance().convertToDomainObject(adapter.getItem(position).getParseUser("friend"));
        ArrayList<User> userArrayList = new ArrayList<>();
        userArrayList.add(user);
        Logger.p(getActivity(), "Recommendation Sent");
        removeThisFragmentFromStack();
        new SendRecommendationToFriendsTask().execute(userArrayList);
    }

    class SendRecommendationToFriendsTask extends AsyncTask<ArrayList<User>,Void,Void>{
        @Override
        protected Void doInBackground(ArrayList<User>... params) {
            RecommendationCreator recommendationCreator = RecommendationCreator.newInstance();
            recommendationCreator.sendToList(userSession.getCurrentUser(), params[0], letterBeingRecommended);
            return null;
        }
    }

    public class ParseFriendQueryAdapter extends ParseQueryAdapter<ParseObject> {
        public ParseFriendQueryAdapter(Context context, Class<? extends ParseObject> clazz) {
            super(context, clazz);
        }

        public ParseFriendQueryAdapter(Context context, String className) {
            super(context, className);
        }

        public ParseFriendQueryAdapter(Context context, Class<? extends ParseObject> clazz, int itemViewResource) {
            super(context, clazz, itemViewResource);
        }

        public ParseFriendQueryAdapter(Context context, String className, int itemViewResource) {
            super(context, className, itemViewResource);
        }

        public ParseFriendQueryAdapter(Context context, QueryFactory<ParseObject> queryFactory) {
            super(context, queryFactory);
        }

        public ParseFriendQueryAdapter(Context context, QueryFactory<ParseObject> queryFactory, int itemViewResource) {
            super(context, queryFactory, itemViewResource);
        }

        public View getItemView(final ParseObject object, View view, ViewGroup parent) {
            if (view == null) {
                view = view.inflate(getContext(), R.layout.row_friend, null);
            }

            TextView tv_friendName = (TextView) view.findViewById(R.id.tv_friendName);
            ParseUser friend = null;
            friend = object.getParseUser("friend");

            try {
                friend = friend.fetchIfNeeded();
            } catch (ParseException e) {
                Log.e("tag", "error", e);
                e.printStackTrace();
            }

            String friendName = friend.getString("fullName");
            tv_friendName.setText(friendName);

            final ImageView iv_friendProfilePicture = (ImageView) view.findViewById(R.id.iv_friendProfilePicture);
            ParseFile profilePicture = (ParseFile) friend.get("profilePicture");
            profilePicture.getDataInBackground(new GetDataCallback() {
                public void done(byte[] data, ParseException e) {
                    if (e == null) {
                        Bitmap bitmap = BitmapUtil.byteArrayToBitmap(data);
                        iv_friendProfilePicture.setImageBitmap(bitmap);
                    } else {
                        Integer.parseInt("Throw exception");
                    }
                }
            });
            return view;
        }
    }
}




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