smacgregor / SimpleTwitterClient

A simple twitter client leveraging the twitter API
0 stars 0 forks source link

Week 4 Project: Twitter With Fragments #16

Open smacgregor opened 8 years ago

smacgregor commented 8 years ago

My app is complete, please review. /cc @codepathreview @codepath

Another fun project. I appreciated that we got to build off of last week's project. That allowed me to dig a little deeper this week as I didn't had to build everything from the ground up.

Interesting Notes

public void onAttach(Context context) {
    
    super.onAttach(context);
    
    if (context instanceof OnTweetsDialogFragmentListener) {
        
        mOnTweetsDialogFragmentListener = (OnTweetsDialogFragmentListener) context;
    
    } else {
        
        throw new RuntimeException(context.toString()
  + " must implement OnTweetsDialogFragmentListener");
    
    }

}

It made it easy to have the fragment pick up the fragment listener impeleented by the activity.

Open Questions

Similar to last week - For ActiveAndroid - I had to write some pretty squirrely (maybe even smelly?) code to get the many to one relationships working given the GSON generated model classes. In the following example an Entities model contains an array of media associated with a tweet.

    public static class Entities extends Model {

        List<TweetMedia> media;

        public Entities() {
            super();
        }

        public List<TweetMedia> getMedia() {
            //  if we haven't saved the model yet then use media otherwise
           //  use getMany and hit the db
            if (media == null) {
               return getMany(TweetMedia.class, "Entities");
            } else {
                return media;
            }
        }

        public final Long cascadeSave(Tweet tweet) {
            long retVal = save();
            if (media != null && media.size() > 0) {
                for (TweetMedia med : media) {
                    med.setEntities(this);
                    med.cascadeSave();
                }
            }
            return retVal;
        }
    }

When saving a tweet I have a cascading save method which calls Entities.cascadeSave. In order to get the relationships set correctly - I saved the current entities object first. Then to set up the many to one relationship - enumerated over all the tweet media objects - setting the current entities object on each tweet media model then saving the media object in the media table.

From the if I had more time department

codepathreview commented 8 years ago

:+1: nice work. A few notes after checking out the code:

Here's a detailed Project 4 Feedback Guide here which covers the most common issues with this submitted project. Read through the feedback guide point-by-point to determine how you might be able to improve your submission.

This week (Week 5), we are going to cover the last major piece to the Android puzzle and that is using the hardware and SDK components such as the camera, photo gallery, location, maps, etc. After that, Week 6 and week 7 we will be covering a few important intermediate topics such as more about styling and animation as well as testing.

Following the bootcamp, we are going to have a public demo day to celebrate the progress you've all made with our next batch of Android students and multiple companies attending to see the group projects that you all have built. We are going to help however we can over the next few weeks to get the team project apps in shape for that.