Skip to content

Commit 7029f69

Browse files
Implemented a lot of week 4 required stories
1 parent cc9173c commit 7029f69

23 files changed

+749
-226
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ dependencies {
2525
compile 'com.loopj.android:android-async-http:1.4.6'
2626
compile 'com.jakewharton:butterknife:6.1.0'
2727
compile 'com.makeramen:roundedimageview:1.5.0'
28+
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
2829
}

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
android:name="android.support.PARENT_ACTIVITY"
6161
android:value="com.codepath.apps.mysimpletweets.activities.TimelineActivity" />
6262
</activity>
63+
<activity
64+
android:name=".activities.ProfileActivity"
65+
android:label="@string/title_activity_profile" >
66+
</activity>
6367
</application>
6468

6569
</manifest>

app/src/main/java/com/codepath/apps/mysimpletweets/TwitterClient.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package com.codepath.apps.mysimpletweets;
22

3-
import org.scribe.builder.api.Api;
4-
import org.scribe.builder.api.FlickrApi;
5-
import org.scribe.builder.api.TwitterApi;
6-
73
import android.content.Context;
8-
import android.util.Log;
94

105
import com.codepath.oauth.OAuthBaseClient;
116
import com.loopj.android.http.AsyncHttpResponseHandler;
127
import com.loopj.android.http.RequestParams;
138

9+
import org.scribe.builder.api.Api;
10+
import org.scribe.builder.api.TwitterApi;
11+
1412
/*
1513
*
1614
* This is the object responsible for communicating with a REST API.
@@ -25,6 +23,8 @@
2523
*/
2624
public class TwitterClient extends OAuthBaseClient {
2725

26+
private static int ITEMS_PER_PAGE = 25;
27+
2828
public static final String TWITTER_DATE_FORMAT = "EEE MMM dd HH:mm:ss ZZZZZ yyyy";
2929

3030
public static final Class<? extends Api> REST_API_CLASS = TwitterApi.class;
@@ -40,14 +40,35 @@ public TwitterClient(Context context) {
4040
public void getHomeTimeline(long max_id, AsyncHttpResponseHandler handler) {
4141
String apiUrl = getApiUrl("statuses/home_timeline.json");
4242
RequestParams params = new RequestParams();
43-
params.put("count", 25);
43+
params.put("count", ITEMS_PER_PAGE);
4444
params.put("since_id", 1);
4545
if (max_id > 0) {
4646
params.put("max_id", max_id);
4747
}
4848
getClient().get(apiUrl, params, handler);
4949
}
5050

51+
public void getMentionsTimeline(long max_id, AsyncHttpResponseHandler handler) {
52+
String apiUrl = getApiUrl("statuses/mentions_timeline.json");
53+
RequestParams params = new RequestParams();
54+
params.put("count", ITEMS_PER_PAGE);
55+
if (max_id > 0) {
56+
params.put("max_id", max_id);
57+
}
58+
getClient().get(apiUrl, params, handler);
59+
}
60+
61+
public void getUserTimeline(String screenName, long max_id, AsyncHttpResponseHandler handler) {
62+
String apiUrl = getApiUrl("statuses/user_timeline.json");
63+
RequestParams params = new RequestParams();
64+
params.put("count", ITEMS_PER_PAGE);
65+
params.put("screen_name", screenName);
66+
if (max_id > 0) {
67+
params.put("max_id", max_id);
68+
}
69+
getClient().get(apiUrl, params, handler);
70+
}
71+
5172
public void getCurrentUser(AsyncHttpResponseHandler handler) {
5273
String apiUrl = getApiUrl("account/verify_credentials.json");
5374
getClient().get(apiUrl, null, handler);
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.codepath.apps.mysimpletweets.activities;
2+
3+
import android.os.Bundle;
4+
import android.support.v4.app.FragmentTransaction;
5+
import android.support.v7.app.ActionBarActivity;
6+
import android.util.TypedValue;
7+
import android.view.Menu;
8+
import android.view.MenuItem;
9+
import android.view.ViewGroup;
10+
import android.widget.FrameLayout;
11+
12+
import com.codepath.apps.mysimpletweets.R;
13+
import com.codepath.apps.mysimpletweets.fragments.UserHeaderFragment;
14+
import com.codepath.apps.mysimpletweets.fragments.UserTimelineFragment;
15+
import com.codepath.apps.mysimpletweets.models.User;
16+
17+
import butterknife.ButterKnife;
18+
import butterknife.InjectView;
19+
20+
public class ProfileActivity extends ActionBarActivity {
21+
22+
public static final String EXTRA_USER = "com.codepath.apps.mysimpletweets.user";
23+
24+
@InjectView(R.id.flUserHeaderContainer)
25+
FrameLayout flUserHeaderContainer;
26+
27+
@Override
28+
protected void onCreate(Bundle savedInstanceState) {
29+
super.onCreate(savedInstanceState);
30+
setContentView(R.layout.activity_profile);
31+
ButterKnife.inject(this);
32+
33+
ViewGroup.LayoutParams params = flUserHeaderContainer.getLayoutParams();
34+
int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 75, getResources().getDisplayMetrics());
35+
params.height = height;
36+
37+
User user = getIntent().getParcelableExtra(EXTRA_USER);
38+
if (savedInstanceState == null) {
39+
UserHeaderFragment userHeaderFragment = UserHeaderFragment.newInstance(user);
40+
UserTimelineFragment userTimelineFragment = UserTimelineFragment.newInstance(user);
41+
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
42+
ft.replace(R.id.flUserHeaderContainer, userHeaderFragment);
43+
ft.replace(R.id.flContainer, userTimelineFragment);
44+
ft.commit();
45+
}
46+
}
47+
48+
49+
@Override
50+
public boolean onCreateOptionsMenu(Menu menu) {
51+
// Inflate the menu; this adds items to the action bar if it is present.
52+
getMenuInflater().inflate(R.menu.menu_profile, menu);
53+
return true;
54+
}
55+
56+
@Override
57+
public boolean onOptionsItemSelected(MenuItem item) {
58+
// Handle action bar item clicks here. The action bar will
59+
// automatically handle clicks on the Home/Up button, so long
60+
// as you specify a parent activity in AndroidManifest.xml.
61+
int id = item.getItemId();
62+
63+
//noinspection SimplifiableIfStatement
64+
if (id == R.id.action_settings) {
65+
return true;
66+
}
67+
68+
return super.onOptionsItemSelected(item);
69+
}
70+
}

0 commit comments

Comments
 (0)