Skip to content

Commit

Permalink
now urls, mentions, hashtags can be handled in twidere.
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Apr 23, 2012
1 parent c2d96a0 commit 9163b8f
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 101 deletions.
18 changes: 16 additions & 2 deletions .gitignore
@@ -1,2 +1,16 @@
/bin
/gen
# built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
gen/

# Local configuration file (sdk path, etc)
local.properties
2 changes: 1 addition & 1 deletion project.properties
Expand Up @@ -16,4 +16,4 @@ android.library.reference.1=../ActionBarSherlock
android.library.reference.2=../viewpagerindicator
android.library.reference.3=../android-preferences
android.library.reference.4=../android-holocompat
android.library.reference.5=../Android-PullToRefresh
android.library.reference.5=../android-pulltorefresh
44 changes: 26 additions & 18 deletions res/layout/view_status.xml
Expand Up @@ -34,15 +34,13 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"/>

<TextView
android:id="@+id/screen_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="screenname"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"/>
</LinearLayout>
Expand Down Expand Up @@ -70,24 +68,34 @@
</FrameLayout>
</RelativeLayout>

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<ScrollView
android:id="@+id/text_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignLeft="@+id/profile"
android:layout_below="@+id/profile"
android:padding="8dip"
android:singleLine="false"
android:text="Text"
android:textAppearance="?android:attr/textAppearanceMedium"/>
android:padding="8dip">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="false"
android:textAppearance="?android:attr/textAppearanceMedium"/>

<TextView
android:id="@+id/source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/text"
android:layout_below="@+id/text"
android:text="@string/sent_from"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<TextView
android:id="@+id/source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="8dip"
android:text="@string/sent_from"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</LinearLayout>
</ScrollView>

</RelativeLayout>
16 changes: 8 additions & 8 deletions src/org/mariotaku/twidere/IUpdateService.aidl
@@ -1,14 +1,14 @@
package org.mariotaku.twidere;

interface IUpdateService {
void getHomeTimeline(in long[] account_ids, in long[] max_ids);
void getMentions(in long[] account_ids, in long[] max_ids);
void getMessages(in long[] account_ids, in long[] max_ids);
void updateStatus(in long[] account_ids, String content, in Location location, in Uri image_uri, long in_reply_to);
void destroyStatus(long account_id, long status_id);
void retweetStatus(in long[] account_ids, long status_id);
void createFavorite(in long[] account_ids, long status_id);
void destroyFavorite(in long[] account_id, long status_id);
int getHomeTimeline(in long[] account_ids, in long[] max_ids);
int getMentions(in long[] account_ids, in long[] max_ids);
int getMessages(in long[] account_ids, in long[] max_ids);
int updateStatus(in long[] account_ids, String content, in Location location, in Uri image_uri, long in_reply_to);
int destroyStatus(long account_id, long status_id);
int retweetStatus(in long[] account_ids, long status_id);
int createFavorite(in long[] account_ids, long status_id);
int destroyFavorite(in long[] account_id, long status_id);
boolean isHomeTimelineRefreshing();
boolean isMentionsRefreshing();
boolean hasActivatedTask();
Expand Down
17 changes: 10 additions & 7 deletions src/org/mariotaku/twidere/fragment/ViewStatusFragment.java
Expand Up @@ -177,11 +177,6 @@ public void onPrepareOptionsMenu(Menu menu) {
if (cur != null) {
cur.close();
}
if (getSherlockActivity() instanceof ViewStatusActivity) {
getSherlockActivity().finish();
} else {
getFragmentManager().beginTransaction().remove(this);
}
}

if (cur != null && cur.getCount() > 0) {
Expand All @@ -197,6 +192,13 @@ public void onPrepareOptionsMenu(Menu menu) {
itemFav.getIcon().clearColorFilter();
itemFav.setTitle(R.string.fav);
}
} else {
if (getSherlockActivity() instanceof ViewStatusActivity) {
getSherlockActivity().finish();
} else {
//Do what? I will make a decision after I have a tablet.
//getFragmentManager().beginTransaction().remove(this);
}
}
if (cur != null) {
cur.close();
Expand Down Expand Up @@ -245,7 +247,8 @@ private void displayStatus() {
String screen_name = cur.getString(cur.getColumnIndexOrThrow(Statuses.SCREEN_NAME));
mScreenName.setText(screen_name != null ? "@" + screen_name : "");
String text = cur.getString(cur.getColumnIndexOrThrow(Statuses.TEXT));
mText.setText(text != null ? text : "");
if (text != null) mText.setText(Html.fromHtml(text));
mText.setMovementMethod(LinkMovementMethod.getInstance());
String source = cur.getString(cur.getColumnIndexOrThrow(Statuses.SOURCE));
mSource.setText(Html.fromHtml(getString(R.string.sent_from, source)));
mSource.setMovementMethod(LinkMovementMethod.getInstance());
Expand Down Expand Up @@ -285,7 +288,7 @@ private boolean isAllFollowing() {
Twitter twitter = CommonUtils.getTwitterInstance(getSherlockActivity(), id);
try {
Relationship result = twitter.showFriendship(id, mTweetUserId);
if (!result.isSourceFollowingTarget()) return false;
if (!result.isSourceFollowingTarget() && id != mTweetUserId) return false;
} catch (TwitterException e) {
e.printStackTrace();
}
Expand Down
71 changes: 37 additions & 34 deletions src/org/mariotaku/twidere/service/UpdateService.java
Expand Up @@ -20,6 +20,7 @@
import twitter4j.MediaEntity;
import twitter4j.Paging;
import twitter4j.ResponseList;
import twitter4j.Status;
import twitter4j.StatusUpdate;
import twitter4j.Twitter;
import twitter4j.TwitterException;
Expand All @@ -39,19 +40,19 @@ public class UpdateService extends RoboService implements Constants {

private int mRefreshHomeTimelineTaskId, mRefreshMentionsTaskId;

public void createFavorite(long[] account_ids, long status_id) {
public int createFavorite(long[] account_ids, long status_id) {
CreateFavoriteTask task = new CreateFavoriteTask(account_ids, status_id);
mAsyncTaskManager.add(task, true);
return mAsyncTaskManager.add(task, true);
}

public void destroyFavorite(long[] account_ids, long status_id) {
public int destroyFavorite(long[] account_ids, long status_id) {
DestroyFavoriteTask task = new DestroyFavoriteTask(account_ids, status_id);
mAsyncTaskManager.add(task, true);
return mAsyncTaskManager.add(task, true);
}

public void destroyStatus(long account_id, long status_id) {
public int destroyStatus(long account_id, long status_id) {
DestroyStatusTask task = new DestroyStatusTask(account_id, status_id);
mAsyncTaskManager.add(task, true);
return mAsyncTaskManager.add(task, true);
}

public boolean hasActivatedTask() {
Expand All @@ -77,32 +78,32 @@ public void onCreate() {
mAsyncTaskManager = ((TwidereApplication) getApplication()).getAsyncTaskManager();
}

public void refreshHomeTimeline(long[] account_ids, long[] max_ids) {
public int refreshHomeTimeline(long[] account_ids, long[] max_ids) {
mAsyncTaskManager.cancel(mRefreshHomeTimelineTaskId);
GetHomeTimelineTask task = new GetHomeTimelineTask(account_ids, max_ids);
mRefreshHomeTimelineTaskId = mAsyncTaskManager.add(task, true);
return mRefreshHomeTimelineTaskId = mAsyncTaskManager.add(task, true);
}

public void refreshMentions(long[] account_ids, long[] max_ids) {
public int refreshMentions(long[] account_ids, long[] max_ids) {
mAsyncTaskManager.cancel(mRefreshMentionsTaskId);
GetMentionsTask task = new GetMentionsTask(account_ids, max_ids);
mRefreshMentionsTaskId = mAsyncTaskManager.add(task, true);
return mRefreshMentionsTaskId = mAsyncTaskManager.add(task, true);
}

public void refreshMessages(long[] account_ids, long[] max_ids) {

public int refreshMessages(long[] account_ids, long[] max_ids) {
return -1;
}

public void retweetStatus(long[] account_ids, long status_id) {
public int retweetStatus(long[] account_ids, long status_id) {
RetweetStatusTask task = new RetweetStatusTask(account_ids, status_id);
mAsyncTaskManager.add(task, true);
return mAsyncTaskManager.add(task, true);
}

public void updateStatus(long[] account_ids, String content, Location location, Uri image_uri,
public int updateStatus(long[] account_ids, String content, Location location, Uri image_uri,
long in_reply_to) {
UpdateStatusTask task = new UpdateStatusTask(account_ids, content, location, image_uri,
in_reply_to);
mAsyncTaskManager.add(task, true);
return mAsyncTaskManager.add(task, true);
}

private class CreateFavoriteTask extends
Expand Down Expand Up @@ -336,6 +337,7 @@ protected void onPostExecute(List<AccountResponce> responces) {

long min_id = -1, max_id = -1;
for (twitter4j.Status status : statuses) {
if (status == null) continue;
ContentValues values = new ContentValues();
User user = status.getUser();
long status_id = status.getId();
Expand All @@ -344,7 +346,7 @@ protected void onPostExecute(List<AccountResponce> responces) {
values.put(Statuses.ACCOUNT_ID, account_id);
values.put(Statuses.USER_ID, user.getId());
values.put(Statuses.STATUS_TIMESTAMP, status.getCreatedAt().getTime());
values.put(Statuses.TEXT, status.getText());
values.put(Statuses.TEXT, CommonUtils.formatStatusString(status));
values.put(Statuses.NAME, user.getName());
values.put(Statuses.SCREEN_NAME, user.getScreenName());
values.put(Statuses.PROFILE_IMAGE_URL, user.getProfileImageURL().toString());
Expand Down Expand Up @@ -460,6 +462,7 @@ protected void onPostExecute(List<AccountResponce> responces) {

long min_id = -1, max_id = -1;
for (twitter4j.Status mention : mentions) {
if (mention == null) continue;
ContentValues values = new ContentValues();
long status_id = mention.getId();
MediaEntity[] medias = mention.getMediaEntities();
Expand All @@ -468,7 +471,7 @@ protected void onPostExecute(List<AccountResponce> responces) {
values.put(Mentions.STATUS_ID, status_id);
values.put(Mentions.USER_ID, user.getId());
values.put(Mentions.STATUS_TIMESTAMP, mention.getCreatedAt().getTime());
values.put(Mentions.TEXT, mention.getText());
values.put(Mentions.TEXT, CommonUtils.formatStatusString(mention));
values.put(Mentions.NAME, user.getName());
values.put(Mentions.SCREEN_NAME, user.getScreenName());
values.put(Mentions.PROFILE_IMAGE_URL, user.getProfileImageURL().toString());
Expand Down Expand Up @@ -658,33 +661,33 @@ public ServiceStub(UpdateService service) {
}

@Override
public void createFavorite(long[] account_ids, long status_id) throws RemoteException {
mService.get().createFavorite(account_ids, status_id);
public int createFavorite(long[] account_ids, long status_id) throws RemoteException {
return mService.get().createFavorite(account_ids, status_id);
}

@Override
public void destroyFavorite(long[] account_ids, long status_id) throws RemoteException {
mService.get().destroyFavorite(account_ids, status_id);
public int destroyFavorite(long[] account_ids, long status_id) throws RemoteException {
return mService.get().destroyFavorite(account_ids, status_id);
}

@Override
public void destroyStatus(long account_id, long status_id) throws RemoteException {
mService.get().destroyStatus(account_id, status_id);
public int destroyStatus(long account_id, long status_id) throws RemoteException {
return mService.get().destroyStatus(account_id, status_id);
}

@Override
public void getHomeTimeline(long[] account_ids, long[] max_ids) throws RemoteException {
mService.get().refreshHomeTimeline(account_ids, max_ids);
public int getHomeTimeline(long[] account_ids, long[] max_ids) throws RemoteException {
return mService.get().refreshHomeTimeline(account_ids, max_ids);
}

@Override
public void getMentions(long[] account_ids, long[] max_ids) throws RemoteException {
mService.get().refreshMentions(account_ids, max_ids);
public int getMentions(long[] account_ids, long[] max_ids) throws RemoteException {
return mService.get().refreshMentions(account_ids, max_ids);
}

@Override
public void getMessages(long[] account_ids, long[] max_ids) throws RemoteException {
mService.get().refreshMessages(account_ids, max_ids);
public int getMessages(long[] account_ids, long[] max_ids) throws RemoteException {
return mService.get().refreshMessages(account_ids, max_ids);
}

@Override
Expand All @@ -703,14 +706,14 @@ public boolean isMentionsRefreshing() throws RemoteException {
}

@Override
public void retweetStatus(long[] account_ids, long status_id) throws RemoteException {
mService.get().retweetStatus(account_ids, status_id);
public int retweetStatus(long[] account_ids, long status_id) throws RemoteException {
return mService.get().retweetStatus(account_ids, status_id);
}

@Override
public void updateStatus(long[] account_ids, String content, Location location,
public int updateStatus(long[] account_ids, String content, Location location,
Uri image_uri, long in_reply_to) throws RemoteException {
mService.get().updateStatus(account_ids, content, location, image_uri, in_reply_to);
return mService.get().updateStatus(account_ids, content, location, image_uri, in_reply_to);

}

Expand Down

0 comments on commit 9163b8f

Please sign in to comment.