-
Notifications
You must be signed in to change notification settings - Fork 530
/
TwitterActivity.java
93 lines (76 loc) · 2.95 KB
/
TwitterActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.joanzapata.android.twitter;
import android.os.Bundle;
import android.text.util.Linkify;
import android.util.Log;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.googlecode.androidannotations.annotations.*;
import com.joanzapata.android.BaseAdapterHelper;
import com.joanzapata.android.QuickAdapter;
import com.joanzapata.android.twitter.component.ExtendedListView;
import twitter4j.Status;
import java.text.DateFormat;
import java.util.List;
import static com.actionbarsherlock.view.Window.FEATURE_INDETERMINATE_PROGRESS;
import static com.joanzapata.android.twitter.R.id.*;
import static java.text.DateFormat.*;
@EActivity(R.layout.activity_main)
public class TwitterActivity extends SherlockActivity implements ExtendedListView.OnEndOfListListener<Status> {
public static final String TAG = TwitterActivity.class.getSimpleName();
private static final DateFormat dateFormat = getDateInstance(SHORT);
@ViewById
protected ExtendedListView listView;
@Bean
protected TwitterService twitter;
@NonConfigurationInstance
protected QuickAdapter adapter;
private String followingAccount = "JoanZap";
@AfterViews
void afterViews() {
setTitle("@" + followingAccount);
listView.setOnEndOfListListener(this);
if (adapter == null)
adapter = new QuickAdapter<Status>(this, R.layout.tweet) {
@Override
protected void convert(BaseAdapterHelper helper, Status status) {
boolean isRetweet = status.isRetweet();
if (isRetweet) status = status.getRetweetedStatus();
helper.setText(tweetText, status.getText())
.setVisible(tweetRT, isRetweet)
.setText(tweetName, status.getUser().getName())
.setText(tweetDate, dateFormat.format(status.getCreatedAt()))
.setImageUrl(tweetAvatar, status.getUser().getProfileImageURL())
.linkify(tweetText);
}
};
listView.setAdapter(adapter);
}
@Override
@Background
public void onEndOfList(Status status) {
showProgressDialog(true);
installTweets(twitter.getTweetsBefore(followingAccount, status));
}
@UiThread
protected void installTweets(List<Status> tweets) {
// Problem with connection, retry
if (tweets == null) {
adapter.notifyDataSetChanged();
return;
}
// No more tweets
if (tweets.isEmpty()) {
listView.setOnEndOfListListener(null);
}
showProgressDialog(false);
adapter.addAll(tweets);
}
@UiThread
protected void showProgressDialog(boolean visibility) {
adapter.showIndeterminateProgress(visibility);
}
// @Override
// public boolean onCreateOptionsMenu(Menu menu) {
// return true;
// }
}