Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Twitter done

  • Loading branch information...
commit ce95ca390429dfe7dba2fa011ecce78110069f69 1 parent 88bb1b8
Codeskraps authored
View
4 AndroidManifest.xml
@@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.codeskraps.lolo"
- android:versionCode="22"
- android:versionName="2.1.1" >
+ android:versionCode="23"
+ android:versionName="2.2" >
<!-- Remember to update the info code version -->
View
5 README.rdoc
@@ -4,7 +4,7 @@
* <b>Git:</b> https://github.com/091labs/lo-lo
* <b>Author:</b> 091 Labs members
* <b>License:</b> GNU GPL v3
-* <b>Latest Version:</b> 2.0
+* <b>Latest Version:</b> 2.2
* <b>Release Date:</b> 2013
== General Infromation
@@ -31,6 +31,9 @@ Install from Google Play
* http://play.google.com/store/apps/details?id=com.codeskraps.lolo
== ChangeLog
+<b>v2.2</b>
+* New Twitter feed
+
<b>v2.1.1</b>
* Bug Fix
View
BIN  res/drawable-hdpi/navigation_refresh.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-mdpi/navigation_refresh.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable-xhdpi/navigation_refresh.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable/middle_row.9.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  res/drawable/top_tow.9.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
40 res/layout/row_tweet.xml
@@ -10,29 +10,55 @@
android:layout_height="40dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
- android:layout_marginRight="5dp"
- android:layout_marginTop="5dp"
+ android:layout_marginRight="10dp"
+ android:layout_marginTop="10dp"
android:contentDescription="@string/contentDescription" />
<LinearLayout
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="1dp"
+ android:layout_marginRight="10dp"
+ android:layout_marginTop="4dp"
+ android:orientation="horizontal" >
+
+ <TextView
+ android:id="@+id/tws_row_txt_user"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginRight="5dp"
+ android:textIsSelectable="false" />
+
+ <TextView
+ android:id="@+id/tws_row_txt_screen_name"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textIsSelectable="false" />
+ </LinearLayout>
+
<TextView
- android:id="@+id/tws_row_txt_user"
+ android:id="@+id/tws_row_txt_created"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginBottom="5dp"
+ android:layout_marginBottom="1dp"
android:layout_marginRight="10dp"
+ android:layout_marginTop="1dp"
+ android:gravity="right"
android:textIsSelectable="false" />
- <TextView
+ <WebView
android:id="@+id/tws_row_txt_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:layout_marginBottom="6dp"
android:layout_marginRight="10dp"
- android:textIsSelectable="false" />
+ android:background="#dcdcdc"
+ android:textIsSelectable="true" />
</LinearLayout>
</LinearLayout>
View
13 res/layout/tweet.xml
@@ -10,6 +10,15 @@
android:layout_height="1dp"
android:background="#FF0000" />
+ <TextView
+ android:id="@+id/twe_txt_count"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginRight="10dp"
+ android:layout_marginTop="10dp"
+ android:gravity="right"
+ android:textIsSelectable="false" />
+
<EditText
android:id="@+id/twe_etxt_data"
android:layout_width="match_parent"
@@ -17,7 +26,9 @@
android:layout_margin="10dp"
android:gravity="top"
android:hint="@string/twe_enter"
- android:inputType="text" />
+ android:inputType="textMultiLine"
+ android:lines="10"
+ android:singleLine="false" />
<TextView
android:id="@+id/twe_txt_feedback"
View
3  res/layout/tweets.xml
@@ -12,6 +12,7 @@
<ListView
android:id="@+id/tws_lst"
android:layout_width="match_parent"
- android:layout_height="match_parent" />
+ android:layout_height="match_parent"
+ android:divider="@android:color/transparent" />
</LinearLayout>
View
8 res/menu/activity_main.xml
@@ -1,6 +1,11 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
+ android:id="@+id/men_refresh"
+ android:icon="@drawable/navigation_refresh"
+ android:showAsAction="always"
+ android:title="@string/men_refresh"/>
+ <item
android:id="@+id/men_tweet"
android:icon="@drawable/social_send_now"
android:showAsAction="always"
@@ -8,7 +13,8 @@
<item
android:id="@+id/men_settings"
android:icon="@drawable/action_settings"
- android:showAsAction="always"
+ android:orderInCategory="100"
+ android:showAsAction="ifRoom"
android:title="@string/men_setting"/>
</menu>
View
1  res/values/strings.xml
@@ -89,6 +89,7 @@
<!-- Menu -->
<string name="men_setting">Settings</string>
<string name="men_tweet">Tweet</string>
+ <string name="men_refresh">Refresh</string>
<!-- About -->
<string name="about_title">091 Labs lo-lo</string>
View
88 src/com/codeskraps/lolo/home/DataBase.java
@@ -0,0 +1,88 @@
+package com.codeskraps.lolo.home;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+import android.util.Log;
+
+public class DataBase {
+ private static final String TAG = DataBase.class.getSimpleName();
+
+ public static final String DB_TABLE_TWITTER = "twitter";
+ public static final String DB_TABLE_TABS = "tabs";
+
+ public static final String C_TWEET_ID = "tweet_id";
+ public static final String C_TWEET_CREATED = "tweet_created";
+ public static final String C_TWEET_IMAGE = "tweet_image";
+ public static final String C_TWEET_NAME = "tweet_name";
+ public static final String C_TWEET_SCREEN = "tweet_screen";
+ public static final String C_TWEET_TEXT = "tweet_text";
+
+ private Context context;
+ private DbHelper dbHelper;
+
+ public DataBase(Context context) {
+ this.context = context;
+ dbHelper = new DbHelper();
+ }
+
+ public void close() {
+ dbHelper.close();
+ }
+
+ public void insert(String table, TweetItem tweetItem) {
+
+ ContentValues values = new ContentValues();
+ values.put(C_TWEET_ID, tweetItem.getId());
+ values.put(C_TWEET_CREATED, tweetItem.getCreated());
+ values.put(C_TWEET_IMAGE, tweetItem.getImgUser());
+ values.put(C_TWEET_NAME, tweetItem.getTxtUser());
+ values.put(C_TWEET_SCREEN, tweetItem.getTxtScreenName());
+ values.put(C_TWEET_TEXT, tweetItem.getText());
+
+ SQLiteDatabase db = dbHelper.getWritableDatabase();
+ db.insertWithOnConflict(table, null, values, SQLiteDatabase.CONFLICT_IGNORE);
+ db.close();
+ }
+
+ public Cursor query(String table) {
+ SQLiteDatabase db = dbHelper.getReadableDatabase();
+
+ return db.query(table, null, null, null, null, null, C_TWEET_CREATED + " DESC", "500");
+ }
+
+ public void deleteTable(String table) {
+ SQLiteDatabase db = dbHelper.getWritableDatabase();
+ db.delete(table, null, null);
+ db.close();
+ }
+
+ private class DbHelper extends SQLiteOpenHelper {
+ public static final String DB_NAME = "sBrowserDB.db";
+ public static final int DB_VERSION = 2;
+
+ public DbHelper() {
+ super(context, DB_NAME, null, DB_VERSION);
+ }
+
+ @Override
+ public void onCreate(SQLiteDatabase db) {
+ String sql = String
+ .format("create table %s (%s VARCHAR(18) primary key, %s text, %s text, %s text, %s text, %s text)",
+ DB_TABLE_TWITTER, C_TWEET_ID, C_TWEET_CREATED, C_TWEET_IMAGE,
+ C_TWEET_NAME, C_TWEET_SCREEN, C_TWEET_TEXT);
+ db.execSQL(sql);
+ }
+
+ @Override
+ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+ db.execSQL("drop table if exists " + DB_TABLE_TWITTER);
+ Log.d(TAG, "onUpdate dropped tables " + DB_TABLE_TWITTER);
+
+ this.onCreate(db);
+ }
+ }
+
+}
View
27 src/com/codeskraps/lolo/home/LoloApp.java
@@ -3,20 +3,41 @@
import org.acra.ACRA;
import org.acra.annotation.ReportsCrashes;
-import com.codeskraps.lolo.twitter.TwitterService;
-
+import android.app.Activity;
+import android.app.AlarmManager;
import android.app.Application;
+import android.app.PendingIntent;
import android.content.Intent;
+import com.codeskraps.lolo.twitter.TwitterService;
+
@ReportsCrashes(formKey = "dC1lU3BVVGh4ejlQSTJta05pNXBPQVE6MQ")
public class LoloApp extends Application {
+ private DataBase data = null;
+
@Override
public void onCreate() {
// The following line triggers the initialization of ACRA
ACRA.init(this);
super.onCreate();
- startService(new Intent(this, TwitterService.class));
+ data = new DataBase(this);
+
+ Intent intent = new Intent(this, TwitterService.class);
+ PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ AlarmManager am = (AlarmManager) getSystemService(Activity.ALARM_SERVICE);
+ am.setInexactRepeating(AlarmManager.RTC, 0, AlarmManager.INTERVAL_HALF_HOUR, pendingIntent);
+ }
+
+ public DataBase getDataBase() {
+ return data;
+ }
+
+ @Override
+ public void onTerminate() {
+ super.onTerminate();
+ data.close();
}
}
View
78 src/com/codeskraps/lolo/home/TweetItem.java
@@ -0,0 +1,78 @@
+package com.codeskraps.lolo.home;
+
+public class TweetItem {
+
+ private String id;
+ private String created;
+ private String ImgUser;
+ private String text;
+ private String txtUser;
+ private String txtScreenName;
+
+ public TweetItem(String created, String ImgUser, String text, String txtUser,
+ String txtScreenName) {
+ this.created = created;
+ this.ImgUser = ImgUser;
+ this.text = text;
+ this.txtUser = txtUser;
+ this.txtScreenName = txtScreenName;
+ }
+
+ public TweetItem(String id, String created, String ImgUser, String text, String txtUser,
+ String txtScreenName) {
+ this.created = created;
+ this.id = id;
+ this.ImgUser = ImgUser;
+ this.text = text;
+ this.txtUser = txtUser;
+ this.txtScreenName = txtScreenName;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getCreated() {
+ return created;
+ }
+
+ public void setCreated(String created) {
+ this.created = created;
+ }
+
+ public String getImgUser() {
+ return ImgUser;
+ }
+
+ public void setImgUser(String imgUser) {
+ ImgUser = imgUser;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public String getTxtUser() {
+ return txtUser;
+ }
+
+ public void setTxtUser(String txtUser) {
+ this.txtUser = txtUser;
+ }
+
+ public String getTxtScreenName() {
+ return txtScreenName;
+ }
+
+ public void setTxtScreenName(String txtScreenName) {
+ this.txtScreenName = txtScreenName;
+ }
+}
View
1  src/com/codeskraps/lolo/misc/Constants.java
@@ -10,6 +10,7 @@ private Constants() {}
public static final String FORCE_WIDGET_UPDATE = "com.codeskraps.lolo.FORCE_WIDGET_UPDATE";
public static final String BROADCAST_RECEIVER = "com.codeskraps.lolo.BROADCAST_RECEIVER";
public static final String CONFIGURE_ACTION = "android.appwidget.action.APPWIDGET_CONFIGURE";
+ public static final String ACTION_REFRESH = "com.codeskraps.lolo.action.REFRESH";
public static final String ONCLICK = "lstOnClick";
public static final String EURL = "eURL";
View
39 src/com/codeskraps/lolo/twitter/TextCount.java
@@ -0,0 +1,39 @@
+package com.codeskraps.lolo.twitter;
+
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.widget.TextView;
+
+public class TextCount implements TextWatcher {
+
+ private boolean mEditing;
+ private TextView txtCount = null;
+
+ public TextCount(TextView txtCount) {
+ this.txtCount = txtCount;
+ }
+
+ public boolean ismEditing() {
+ return mEditing;
+ }
+
+ public void setmEditing(boolean mEditing) {
+ this.mEditing = mEditing;
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ if (!ismEditing()) {
+ setmEditing(true);
+ txtCount.setText(String.valueOf(s.length()));
+ setmEditing(false);
+ }
+ }
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+}
View
14 src/com/codeskraps/lolo/twitter/TweetActivity.java
@@ -1,5 +1,9 @@
package com.codeskraps.lolo.twitter;
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.Map;
+
import org.scribe.builder.ServiceBuilder;
import org.scribe.builder.api.TwitterApi;
import org.scribe.model.OAuthRequest;
@@ -24,6 +28,8 @@
import com.codeskraps.lolo.R;
import com.codeskraps.lolo.misc.Constants;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
public class TweetActivity extends Activity implements OnClickListener {
private static final String TAG = TweetActivity.class.getSimpleName();
@@ -44,6 +50,9 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.tweet);
etxtTweet = (EditText) findViewById(R.id.twe_etxt_data);
+ TextView txtCount = (TextView) findViewById(R.id.twe_txt_count);
+ txtCount.setText("0");
+ etxtTweet.addTextChangedListener(new TextCount(txtCount));
((Button) findViewById(R.id.twe_btn_submit)).setOnClickListener(this);
}
@@ -94,7 +103,10 @@ protected void onPostExecute(String result) {
TextView txtFeedBack = (TextView) findViewById(R.id.twe_txt_feedback);
String message = null;
if (result != null && result.startsWith("{")) {
- message = "Tweet posted succesfully!";
+ Type collectionType = new TypeToken<Map<String, Object>>() {}.getType();
+ Map<String, Object> json = new Gson().fromJson(result, collectionType);
+ if (json.containsKey("error")) message = (String) json.get("error");
+ else message = "Tweet posted succesfully!";
} else {
message = "Something has gone wrong!";
}
View
172 src/com/codeskraps/lolo/twitter/TweetsFeedActivity.java
@@ -1,24 +1,20 @@
package com.codeskraps.lolo.twitter;
-import java.lang.reflect.Type;
-import java.util.HashMap;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
-import java.util.Map;
-
-import org.scribe.builder.ServiceBuilder;
-import org.scribe.builder.api.TwitterApi;
-import org.scribe.model.OAuthRequest;
-import org.scribe.model.Token;
-import org.scribe.model.Verb;
-import org.scribe.oauth.OAuthService;
+import java.util.Locale;
import android.app.Activity;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
-import android.content.SharedPreferences;
+import android.content.IntentFilter;
+import android.database.Cursor;
+import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
-import android.preference.PreferenceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -26,31 +22,30 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
+import android.webkit.WebView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.codeskraps.lolo.R;
+import com.codeskraps.lolo.home.DataBase;
+import com.codeskraps.lolo.home.LoloApp;
import com.codeskraps.lolo.home.PrefsActivity;
+import com.codeskraps.lolo.home.TweetItem;
import com.codeskraps.lolo.misc.Constants;
import com.codeskraps.lolo.misc.ImageHelper;
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
public class TweetsFeedActivity extends Activity {
private static final String TAG = TweetsFeedActivity.class.getSimpleName();
- private static final String RESOURCE_URL = "https://api.twitter.com/1.1/statuses/home_timeline.json";
- private OAuthService service = null;
private TweetsAdapter adapter = null;
+ private BroadcastReceiver refreshReceiver = new RefreshReciever();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
- service = new ServiceBuilder().provider(TwitterApi.class).apiKey("Z4lEh5rSu0rV3fXt37gw7A")
- .apiSecret("vLLTqO311ZhlVXhl1GaB72DnIwdCOPwzeozNRWy3I").build();
setContentView(R.layout.tweets);
@@ -64,6 +59,24 @@ protected void onCreate(Bundle savedInstanceState) {
protected void onResume() {
super.onResume();
new GetTimeline().execute();
+
+ IntentFilter filter = new IntentFilter(Constants.ACTION_REFRESH);
+ registerReceiver(refreshReceiver, filter);
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+
+ unregisterReceiver(refreshReceiver);
+ }
+
+ private class RefreshReciever extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context arg0, Intent arg1) {
+ new GetTimeline().execute();
+ }
}
@Override
@@ -81,11 +94,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.men_settings:
startActivity(new Intent(this, PrefsActivity.class));
break;
+ case R.id.men_refresh:
+ setProgressBarIndeterminateVisibility(Boolean.TRUE);
+ startService(new Intent(this, TwitterService.class));
+ break;
}
return true;
}
- private class GetTimeline extends AsyncTask<Void, Void, String> {
+ private class GetTimeline extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
@@ -94,62 +111,67 @@ protected void onPreExecute() {
}
@Override
- protected String doInBackground(Void... params) {
+ protected Void doInBackground(Void... params) {
+ Cursor cursor = null;
try {
- SharedPreferences prefs = PreferenceManager
- .getDefaultSharedPreferences(getApplication());
- String token = prefs.getString(Constants.ACCESS_TOKEN, null);
- String secret = prefs.getString(Constants.ACCESS_SECRET, null);
-
- Token accessToken = new Token(token, secret);
+ LoloApp app = (LoloApp) getApplication();
+ cursor = app.getDataBase().query(DataBase.DB_TABLE_TWITTER);
+ startManagingCursor(cursor);
+
+ final int createdColumnIndex = cursor.getColumnIndex(DataBase.C_TWEET_CREATED);
+ final int imgColumnIndex = cursor.getColumnIndex(DataBase.C_TWEET_IMAGE);
+ final int nameColumnIndex = cursor.getColumnIndex(DataBase.C_TWEET_NAME);
+ final int screenColumnIndex = cursor.getColumnIndex(DataBase.C_TWEET_SCREEN);
+ final int textColumnIndex = cursor.getColumnIndex(DataBase.C_TWEET_TEXT);
+
+ Log.d(TAG, ("Got cursor with records: " + cursor.getCount()));
+
+ String created, image, name, screen, text;
+ Log.d(TAG, "tweets:" + cursor.getCount());
+ ArrayList<TweetItem> tweets = new ArrayList<TweetItem>();
+ while (cursor.moveToNext()) {
+ created = cursor.getString(createdColumnIndex);
+ image = cursor.getString(imgColumnIndex);
+ name = cursor.getString(nameColumnIndex);
+ screen = cursor.getString(screenColumnIndex);
+ text = cursor.getString(textColumnIndex);
+ TweetItem tweet = new TweetItem(created, image, text, name, screen);
+ tweets.add(tweet);
+ }
- OAuthRequest request = new OAuthRequest(Verb.GET, RESOURCE_URL);
- service.signRequest(accessToken, request);
- return request.send().getBody();
+ adapter.setTweet(tweets);
- } catch (Exception e) {
- Log.i(TAG, "Handled: GetTimeline - " + e, e);
+ } finally {
+ stopManagingCursor(cursor);
+ cursor.close();
}
return null;
}
@Override
- protected void onPostExecute(String result) {
+ protected void onPostExecute(Void result) {
super.onPostExecute(result);
- new Gson();
-
setProgressBarIndeterminateVisibility(Boolean.FALSE);
-
- if (result != null) {
- try {
- Log.v(TAG, result);
- Type collectionType = new TypeToken<List<Map<String, Object>>>() {}.getType();
- List<Map<String, Object>> tweets = new Gson().fromJson(result, collectionType);
- adapter.setTweets(tweets);
- adapter.notifyDataSetChanged();
- } catch (Exception e) {
- Log.i(TAG, "Handle: onPostExecute - " + e, e);
- Log.i(TAG, "Handle: result:" + result);
- }
- }
+ adapter.notifyDataSetChanged();
}
}
private class TweetsAdapter extends BaseAdapter {
- private List<Map<String, Object>> tweets = null;
+ private List<TweetItem> tweets;
private LayoutInflater mInflater = null;
public TweetsAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}
- public void setTweets(List<Map<String, Object>> tweets) {
+ public void setTweet(ArrayList<TweetItem> tweets) {
this.tweets = tweets;
}
@Override
public int getCount() {
- if (tweets == null || tweets.isEmpty()) return 0;
+ if (tweets == null) return 0;
+ if (tweets.isEmpty()) return 0;
return tweets.size();
}
@@ -173,21 +195,43 @@ public View getView(int position, View convertView, ViewGroup parent) {
vHolder = new ViewHolder();
vHolder.ImgUser = (ImageView) convertView.findViewById(R.id.tws_row_img_user);
- vHolder.text = (TextView) convertView.findViewById(R.id.tws_row_txt_text);
+ vHolder.text = (WebView) convertView.findViewById(R.id.tws_row_txt_text);
vHolder.txtUser = (TextView) convertView.findViewById(R.id.tws_row_txt_user);
+ vHolder.txtScreenName = (TextView) convertView
+ .findViewById(R.id.tws_row_txt_screen_name);
+ vHolder.txtCreated = (TextView) convertView.findViewById(R.id.tws_row_txt_created);
convertView.setTag(vHolder);
convertView.setId(position);
}
+ int back = position == 0 ? R.drawable.top_tow : R.drawable.middle_row;
+
+ convertView.setBackgroundResource(back);
+
try {
- Map<String, Object> tweet = tweets.get(position);
- Map<String, Object> user = (Map<String, Object>) tweet.get("user");
-
- String url = (String) user.get("profile_image_url");
- ImageHelper.loadBitmap(getResources(), url, vHolder.ImgUser);
- vHolder.txtUser.setText((String) user.get("name"));
- vHolder.text.setText((String) tweet.get("text"));
+ TweetItem tweet = tweets.get(position);
+
+ ImageHelper.loadBitmap(getResources(), tweet.getImgUser(), vHolder.ImgUser);
+ vHolder.txtUser.setText(tweet.getTxtUser());
+ vHolder.txtScreenName.setText("@" + tweet.getTxtScreenName());
+ StringBuilder sb = new StringBuilder("<html><body>");
+ sb.append(fixLinks(tweet.getText()));
+ sb.append("</body></html>");
+ vHolder.text.loadDataWithBaseURL(null, sb.toString(), "text/html", "UTF-8", null);
+ vHolder.text.setBackgroundColor(Color.parseColor("#dcdcdc"));
+
+ long created = Long.parseLong(tweet.getCreated());
+ created = (System.currentTimeMillis() - created) / (1000 * 60);
+ if (created > 59) {
+ created = created / 60;
+ if (created > 24) {
+ Date date = new SimpleDateFormat("ddMMM", Locale.ENGLISH).parse(tweet
+ .getCreated());
+ vHolder.txtCreated.setText(date.toString());
+ } else vHolder.txtCreated.setText(String.valueOf(created) + "h");
+ } else vHolder.txtCreated.setText(String.valueOf(created) + "m");
+
} catch (Exception e) {
Log.i(TAG, "Handled: " + e, e);
}
@@ -195,9 +239,19 @@ public View getView(int position, View convertView, ViewGroup parent) {
}
}
+ private String fixLinks(String body) {
+ String regex = "(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";
+ body = body.replaceAll(regex, "<a href=\"$0\">$0</a>");
+ body = body.replace(">http://", ">");
+ Log.d(TAG, body);
+ return body;
+ }
+
public static class ViewHolder {
ImageView ImgUser;
- TextView text;
+ WebView text;
TextView txtUser;
+ TextView txtScreenName;
+ TextView txtCreated;
}
}
View
40 src/com/codeskraps/lolo/twitter/TwitterService.java
@@ -1,7 +1,10 @@
package com.codeskraps.lolo.twitter;
import java.lang.reflect.Type;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import org.scribe.builder.ServiceBuilder;
@@ -18,6 +21,9 @@
import android.preference.PreferenceManager;
import android.util.Log;
+import com.codeskraps.lolo.home.DataBase;
+import com.codeskraps.lolo.home.LoloApp;
+import com.codeskraps.lolo.home.TweetItem;
import com.codeskraps.lolo.misc.Constants;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
@@ -72,15 +78,39 @@ protected void onPostExecute(String result) {
super.onPostExecute(result);
new Gson();
+ DataBase data = ((LoloApp) getApplication()).getDataBase();
+
if (result != null) {
Log.v(TAG, result);
- Type collectionType = new TypeToken<List<Map<String, Object>>>() {}.getType();
- List<Map<String, Object>> tweets = new Gson().fromJson(result, collectionType);
- for (Map m : tweets) {
- String blah = (String) m.get("text");
- Log.d(TAG, blah);
+ try {
+ Type collectionType = new TypeToken<List<Map<String, Object>>>() {}.getType();
+ List<Map<String, Object>> tweets = new Gson().fromJson(result, collectionType);
+ for (Map tweet : tweets) {
+ Map<String, Object> user = (Map<String, Object>) tweet.get("user");
+
+ String create = (String) tweet.get("created_at");
+ Date date = new SimpleDateFormat("EEE MMM dd kk:mm:ss ZZZZZ yyyy",
+ Locale.ENGLISH).parse(create);
+ String created = String.valueOf(date.getTime());
+ String id = (String) tweet.get("id_str");
+ String ImgUser = (String) user.get("profile_image_url");
+ String txtUser = (String) user.get("name");
+ String txtScreenName = (String) user.get("screen_name");
+ String text = (String) tweet.get("text");
+
+ TweetItem item = new TweetItem(id, created, ImgUser, text, txtUser,
+ txtScreenName);
+ data.insert(DataBase.DB_TABLE_TWITTER, item);
+ }
+ } catch (Exception e) {
+ Log.w(TAG, "Handled: parsing json - " + e, e);
+ Log.i(TAG, "Handle: result:" + result);
}
}
+
+ Intent refresh = new Intent();
+ refresh.setAction(Constants.ACTION_REFRESH);
+ sendBroadcast(refresh);
}
}
}
View
20 src/com/codeskraps/lolo/twitter/TwitterSignInActivity.java
@@ -127,17 +127,15 @@ protected void onPostExecute(Boolean result) {
setProgressBarIndeterminateVisibility(Boolean.FALSE);
- if (result)
- new AlertDialog.Builder(TwitterSignInActivity.this)
- .setIcon(R.drawable.alerts_and_states_error)
- .setMessage(R.string.twi_dia_message)
- .setTitle(R.string.twi_dia_title)
- .setPositiveButton(R.string.twi_dia_ok,
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- dialog.dismiss();
- }
- }).create().show();
+ if (result) new AlertDialog.Builder(TwitterSignInActivity.this)
+ .setIcon(R.drawable.alerts_and_states_error)
+ .setMessage(R.string.twi_dia_message).setTitle(R.string.twi_dia_title)
+ .setPositiveButton(R.string.twi_dia_ok, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.dismiss();
+ }
+ }).create().show();
+ else startService(new Intent(getApplication(), TwitterService.class));
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.