Permalink
Browse files

Added Details, support for Fragments

  • Loading branch information...
1 parent 12e81b0 commit 0e1e19f52147a101db53a4f24ed26637ef390c0d Marko Gargenta committed Mar 8, 2012
@@ -36,6 +36,11 @@
android:name=".AboutActivity"
android:label="@string/yamba_about" >
</activity>
+ <activity
+ android:name=".DetailsActivity"
+ android:label="@string/yamba_details"
+ android:exported="false">
+ </activity>
<service android:name=".UpdateService" >
<intent-filter>
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="horizontal" >
+
+ <fragment
+ android:id="@+id/timeline"
+ android:layout_width="0px"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ class="com.marakana.android.yamba.TimelineFragment" />
+
+ <FrameLayout
+ android:id="@+id/details"
+ android:layout_width="0px"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ android:background="?android:attr/detailsElementBackground" />
+
+</LinearLayout>
@@ -9,6 +9,8 @@
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
+ android:focusable="false"
+ android:focusableInTouchMode="false"
android:text="Slashdot"
android:textAppearance="?android:attr/textAppearanceLarge" />
@@ -19,17 +21,21 @@
android:layout_alignParentLeft="true"
android:layout_below="@+id/text_user"
android:autoLink="all"
+ android:focusable="false"
+ android:focusableInTouchMode="false"
android:text="Today, Android officially takes over the world as number one mobile OS http://android.com/"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/text_createdAt"
- android:textColor="@android:color/holo_blue_light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/text_user"
android:layout_alignBottom="@+id/text_user"
android:layout_alignParentRight="true"
- android:text="10 minutes ago" />
+ android:focusable="false"
+ android:focusableInTouchMode="false"
+ android:text="10 minutes ago"
+ android:textColor="@android:color/holo_blue_light" />
</RelativeLayout>
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+
+ <fragment
+ android:id="@+id/timeline"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ class="com.marakana.android.yamba.TimelineFragment" />
+
+</FrameLayout>
@@ -22,4 +22,6 @@
<string name="refresh">Refresh</string>
<string name="update_successful">Successfully posted</string>
<string name="update_failed">Failed to post</string>
+ <string name="yamba_details">Yamba Details</string>
+ <string name="details">details</string>
</resources>
@@ -0,0 +1,28 @@
+package com.marakana.android.yamba;
+
+import android.app.Activity;
+import android.content.res.Configuration;
+import android.os.Bundle;
+
+public class DetailsActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
+ // If the screen is now in landscape mode, we can show the
+ // dialog in-line with the list so we don't need this activity.
+ finish();
+ return;
+ }
+
+ if (savedInstanceState == null) {
+ // During initial setup, plug in the details fragment.
+ DetailsFragment details = new DetailsFragment();
+ details.setArguments(getIntent().getExtras());
+ getFragmentManager().beginTransaction()
+ .add(android.R.id.content, details).commit();
+ }
+ }
+
+}
@@ -0,0 +1,74 @@
+package com.marakana.android.yamba;
+
+import android.app.Fragment;
+import android.content.ContentUris;
+import android.database.Cursor;
+import android.os.Bundle;
+import android.text.format.DateUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+public class DetailsFragment extends Fragment {
+ private static final String TAG = DetailsFragment.class.getSimpleName();
+
+ /**
+ * Create a new instance of DetailsFragment, initialized to show the text at
+ * 'index'.
+ */
+ public static DetailsFragment newInstance(long index) {
+ DetailsFragment detailsFragment = new DetailsFragment();
+
+ // Supply index input as an argument.
+ Bundle args = new Bundle();
+ args.putLong("id", index);
+ detailsFragment.setArguments(args);
+
+ return detailsFragment;
+ }
+
+ public long getStatusId() {
+ return getArguments().getLong("id", 0);
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ Log.d(TAG, "onCreateView container: " + container);
+
+ if (container == null) {
+ // We have different layouts, and in one of them this
+ // fragment's containing frame doesn't exist. The fragment
+ // may still be created from its saved state, but there is
+ // no reason to try to create its view hierarchy because it
+ // won't be displayed. Note this is not needed -- we could
+ // just run the code below, where we would create and return
+ // the view hierarchy; it would just never be used.
+
+ return null;
+ }
+
+ Cursor cursor = getActivity().getContentResolver().query(
+ ContentUris.withAppendedId(StatusProvider.CONTENT_URI,
+ getStatusId()), null, null, null, null);
+ if (cursor==null || cursor.getCount()<1) return null;
+
+ cursor.moveToFirst();
+ Log.d(TAG, "onCreateView with cursor size: " + cursor.getCount());
+ View view = inflater.inflate(R.layout.row, null);
+ ((TextView) view.findViewById(R.id.text_user)).setText(cursor
+ .getString(cursor.getColumnIndex(StatusData.C_USER)));
+
+ ((TextView) view.findViewById(R.id.text_text)).setText(cursor
+ .getString(cursor.getColumnIndex(StatusData.C_TEXT)));
+
+ long timestamp = cursor.getLong(cursor.getColumnIndex(StatusData.C_CREATED_AT));
+ CharSequence relativeTime = DateUtils
+ .getRelativeTimeSpanString(timestamp);
+ ((TextView) view.findViewById(R.id.text_createdAt)).setText(relativeTime);
+
+ return view;
+ }
+}
@@ -1,5 +1,8 @@
package com.marakana.android.yamba;
+import java.util.Date;
+
+import winterwell.jtwitter.Twitter;
import winterwell.jtwitter.Twitter.Status;
import android.content.ContentValues;
import android.content.Context;
@@ -22,7 +25,7 @@
static final String C_TEXT = "yamba_text";
static final String SORT_BY = C_CREATED_AT + " DESC";
-
+
private DbHelper dbHelper;
/** Constructor */
@@ -39,7 +42,7 @@ public static ContentValues statusToValues(Status status) {
values.put(C_TEXT, status.text);
return values;
}
-
+
/** Inserts the status into the database. */
public long insert(Status status) {
SQLiteDatabase db = dbHelper.getWritableDatabase();
@@ -87,7 +90,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
onCreate(db);
}
}
-
+
/** Getter. */
public DbHelper getDbHelper() {
return dbHelper;
@@ -143,11 +143,13 @@ public Cursor query(Uri uri, String[] projection, String selection,
case ALL_STATUS:
cursor = db.query(StatusData.TABLE, projection, selection,
selectionArgs, null, null, sortOrder);
+ Log.d(TAG, "query for ALL_STATUS uri: "+uri);
break;
case SINGLE_STATUS:
cursor = db.query(StatusData.TABLE, projection, StatusData.C_ID
+ "=" + ContentUris.parseId(uri), null, null, null, null);
+ Log.d(TAG, "query for SINGLE_STATUS id: "+ContentUris.parseId(uri));
break;
default:
@@ -1,62 +1,23 @@
package com.marakana.android.yamba;
-import android.app.ListActivity;
-import android.content.BroadcastReceiver;
-import android.content.Context;
+import android.app.Activity;
import android.content.Intent;
-import android.content.IntentFilter;
-import android.database.Cursor;
import android.os.Bundle;
-import android.text.format.DateUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
-import android.view.View;
-import android.widget.SimpleCursorAdapter;
-import android.widget.SimpleCursorAdapter.ViewBinder;
-import android.widget.TextView;
-public class TimelineActivity extends ListActivity {
+public class TimelineActivity extends Activity {
private static final String TAG = TimelineActivity.class.getSimpleName();
- private String[] FROM = { StatusData.C_USER, StatusData.C_TEXT,
- StatusData.C_CREATED_AT };
- private int[] TO = { R.id.text_user, R.id.text_text, R.id.text_createdAt };
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
- private SimpleCursorAdapter adapter;
- private Cursor cursor;
+ setContentView(R.layout.timeline);
+ Log.d(TAG, "onCreated");
+ }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Get the timeline
- cursor = getContentResolver().query(StatusProvider.CONTENT_URI, null,
- null, null, StatusData.SORT_BY);
-
- // Setup the adapter
- adapter = new SimpleCursorAdapter(this, R.layout.row, cursor, FROM, TO);
- adapter.setViewBinder(VIEW_BINDER);
- setListAdapter(adapter);
- }
-
- /** Custom ViewBinder to convert timestamp to relative time. */
- static final ViewBinder VIEW_BINDER = new ViewBinder() {
- @Override
- public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
- // Ignore custom binding for user and text values
- if (view.getId() != R.id.text_createdAt)
- return false;
-
- // Custom binding for timestamp to relative time
- long timestamp = cursor.getLong(columnIndex);
- CharSequence relativeTime = DateUtils
- .getRelativeTimeSpanString(timestamp);
- ((TextView) view).setText(relativeTime);
- return true;
- }
-
- };
// ----- Menu Callbacks -----
@@ -87,34 +48,5 @@ public boolean onOptionsItemSelected(MenuItem item) {
return false;
}
- // --- Timeline Receiver related code
- TimelineReceiver receiver = new TimelineReceiver();
- IntentFilter filter = new IntentFilter(YambaApp.NEW_STATUS_BROADCAST);
- @Override
- protected void onResume() {
- super.onResume();
- registerReceiver(receiver, filter);
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- unregisterReceiver(receiver);
- }
-
- /**
- * Called when there are new statuses in the database so we can update the
- * list.
- */
- class TimelineReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- // Update list from new timeline
- cursor = getContentResolver().query(StatusProvider.CONTENT_URI,
- null, null, null, StatusData.SORT_BY);
- adapter.changeCursor(cursor);
- Log.d(TAG, "TimelineReceiver refreshing the list");
- }
- }
}
Oops, something went wrong.

0 comments on commit 0e1e19f

Please sign in to comment.