smacgregor / simpletwitterclient Goto Github PK
View Code? Open in Web Editor NEWA simple twitter client leveraging the twitter API
A simple twitter client leveraging the twitter API
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.
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.
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.
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.
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?
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.