Giter Site home page Giter Site logo

simpletwitterclient's People

Contributors

smacgregor avatar smacgregorz avatar

Watchers

 avatar

simpletwitterclient's Issues

Week 4 Project: Twitter With Fragments

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

  • I got a progress bar to work inside of a RecyclerView by adding another heterogeneous view for the progress bar. When I wanted to show progress I append a null tweet to the datasource for the adapter. The progress bar view is used when rendering a null tweet. That was fun to figure out.
  • Thank you Nate for SmartFragmentStatePageAdapter which came in handy!
  • I thought this part of the life cycle feature of fragments was slick:
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

  • Move JSON parsing and object creation onto a background thread to improve scrolling performance. This would be particularly valuable when saving timeline tweets to the database in a transaction.
  • When in offline mode - adjust the db queries to filter against just mentions and user timelines. Currently just searching through all saved tweets.
  • Data binding would have come in handy for this project but I didn't have time.

Week 3 Project: A Twitter Client that Allows You To Interact With Your Timeline

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

Another fun project. I was butting my head for a while trying to get the relationships set up correctly using ActiveAndroid. It was particularly challenging because of the model class hierarchies GSON is generating on my behalf. I almost got ActiveAndroid working well when offline - so close but not in time for the 10pm deadline. The work can be found here and I plan on wrapping that up tomorrow.

Interesting Notes

  1. Created a separate TwitterManager to remove code smells from the activities. The TwitterManager is responsible for interacting with the Twitter client for network requests and for parsing the responses into Java objects which are then passed back to the activity.
  2. I created a set of listener interfaces to be implemented by the activity when making requests on the TwitterManager.
    public interface OnTimelineTweetsReceivedListener {
        void onTweetsReceived(List<Tweet> tweets);
        void onTweetsFailed(int statusCode, Throwable throwable);
    }

    public interface OnCurrentUserReceivedListener {
        void onUserReceived(User user);
        void onUserFailed(int statusCode, Throwable throwable);
    }

    public interface OnNewPostReceivedListener {
        void onPostCreated(Tweet tweet);
        void onPostFailed(int statusCode, Throwable throwable);
    }

    public interface OnTweetUpdatedListener {
        void onTweetUpdated(Tweet tweet);
        void onTweetUpdateFailed(int statusCode, Throwable throwable);
    }

This got a little verbose on the activity side as every method call but I liked how it allowed the activity to deal with Tweet and User objects and not worry about whether those objects are coming from the server or from the database. Does that pattern look ok to you?

Open Questions

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 entitites object on each tweet media model then saving the media object in the media table.

From the if I had more time department

  • Finish my ActiveAndroid integration - so close!!
  • Move JSON parsing and object creation onto a background thread to improve scrolling performance. This would be particularly valuable when saving timeline tweets to the database in a transaction.
  • Progress spinners inside the RecyclerView when loading more results
  • Progress spinner when fetching the initial set of results
  • Add highlight / press states to all buttons (reply, retweet, mark as favorite)
  • Linkify twitter usernames and hash tags

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.