Permalink
Browse files

remove HomeActivity

  • Loading branch information...
1 parent 93274b0 commit 7dd80a85452247f749151ae50c6cd6b37ca8771b @kazuyayokoyama committed May 8, 2012
View
@@ -14,7 +14,7 @@
android:theme="@style/Theme.SherlockCustom" >
<activity
- android:name=".ui.HomeActivity"
+ android:name=".ui.BentoListActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden|screenSize">
<intent-filter>
@@ -23,25 +23,23 @@
<category android:name="musubi.intent.category.MENU" />
<category android:name="musubi.intent.category.DEFAULT" />
</intent-filter>
-
+ </activity>
+
+ <activity
+ android:name=".ui.TodoListActivity"
+ android:label="@string/app_name"
+ android:configChanges="orientation|keyboardHidden|screenSize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.musubi.obj/todobento"/>
</intent-filter>
</activity>
- <activity
- android:name=".ui.BentoListActivity"
- android:label="@string/label_bento_list" />
-
- <activity
- android:name=".ui.TodoListActivity"
- android:label="@string/label_todo_list" />
-
<activity
android:name=".ui.TodoDetailActivity"
- android:label="@string/label_todo_detail" />
+ android:label="@string/label_todo_detail">
+ </activity>
</application>
</manifest>
@@ -27,10 +27,23 @@
android:layout_weight="1"
android:drawSelectorOnTop="false" />
- <TextView android:id="@id/android:empty"
+ <!-- Empty -->
+ <LinearLayout android:id="@id/android:empty"
+ android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:layout_marginLeft="10dip"
- android:layout_marginTop="10dip"
- android:text="@string/todo_list_empty" />
+ android:background="#FFFFFF">
+ <TextView android:id="@+id/empty_message"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="10dip"
+ android:layout_marginTop="10dip"
+ android:text="@string/todo_list_empty" />
+ <ProgressBar android:id="@+id/progress"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="20dip"
+ android:layout_gravity="center"
+ android:visibility="gone" />
+ </LinearLayout>
</LinearLayout>
@@ -24,6 +24,7 @@
import mobisocial.bento.todo.ui.BentoListItem;
import mobisocial.bento.todo.ui.TodoListItem;
import mobisocial.bento.todo.util.BitmapHelper;
+import mobisocial.bento.todo.util.UIUtils;
import mobisocial.socialkit.Obj;
import mobisocial.socialkit.musubi.DbFeed;
import mobisocial.socialkit.musubi.DbIdentity;
@@ -84,7 +85,7 @@
public JSONObject json = null;
public int intKey = 0;
};
- private static final Boolean DEBUG = false;
+ private static final Boolean DEBUG = UIUtils.isDebugMode();
private static final String TAG = "TodoDataManager";
private static BentoManager sInstance = null;
private Musubi mMusubi = null;
@@ -115,10 +116,27 @@ public static BentoManager getInstance() {
return sInstance;
}
+
+ public void init(Musubi musubi) {
+ if (DEBUG) Log.d(TAG, "init()");
+
+ // remove previous data
+ if (mCurrentUri != null) {
+ mMusubi.objForUri(mCurrentUri).getSubfeed().unregisterStateObserver(mStateObserver);
+ }
+ mCurrentUri = null;
+ mBentoList = new ArrayList<BentoListItem>();
+ mBento = null;
+ mMemberNameCache = null;
+ }
- public void init(Musubi musubi, int versionCode) {
+ public void setMusubi(Musubi musubi, int versionCode) {
+ if (DEBUG) Log.d(TAG, "setMusubi()");
+
mMusubi = musubi;
mVersionCode = versionCode;
+
+ // start new one
if (mMusubi.getObj() != null && mMusubi.getObj().getSubfeed() != null) {
setBentoObjUri(mMusubi.getObj().getUri());
}
@@ -167,7 +185,11 @@ synchronized public TodoListItem getTodoListItem(String uuid) {
}
synchronized public int getTodoListCount() {
- return mBento.bento.todoList.size();
+ if (mBento != null) {
+ return mBento.bento.todoList.size();
+ } else {
+ return 0;
+ }
}
synchronized public Bitmap getTodoBitmap(String todoUuid,
@@ -553,39 +575,47 @@ public void setBentoObjUri(Uri objUri) {
private final FeedObserver mStateObserver = new FeedObserver() {
@Override
public void onUpdate(DbObj obj) {
-
if (DEBUG) Log.d(TAG, "onUpdate:" + obj.toString());
+
+ // ignore
+ if (obj == null || obj.getJson() == null || !obj.getJson().has(STATE)) {
+ if (DEBUG) Log.d(TAG, "onUpdate: ignore-1");
+ return;
+ }
- mLastInt = (obj.getIntKey() == null) ? 0 : obj.getIntKey();
- if (DEBUG) Log.d(TAG, "onUpdate - mLastInt: " + mLastInt);
-
- JSONObject stateObj = null;
- if (obj != null && obj.getJson() != null && obj.getJson().has(STATE)) {
- stateObj = obj.getJson().optJSONObject(STATE);
- setNewStateObj(stateObj);
-
- try {
- // TODO : just in case
- if (isValidBento(stateObj.getJSONObject(BENTO).optString(BENTO_UUID))) {
- Handler handler = new Handler();
- handler.post(new Runnable(){
- public void run(){
- for (OnStateUpdatedListener listener : mListenerList) {
- listener.onStateUpdated();
- }
- }
- });
-
- return;
+ // notify refresh (always)
+ Handler handler = new Handler();
+ handler.post(new Runnable(){
+ public void run(){
+ for (OnStateUpdatedListener listener : mListenerList) {
+ listener.onStateUpdated();
}
- } catch (JSONException e) {
- Log.e(TAG, "Failed to get JSON", e);
+ }
+ });
+
+ if (mBento == null || mBento.bento == null) {
+ if (DEBUG) Log.d(TAG, "onUpdate: ignore-2");
+ return;
+ }
+
+ JSONObject stateObj = null;
+ stateObj = obj.getJson().optJSONObject(STATE);
+ try {
+ if (!isValidBento(stateObj.getJSONObject(BENTO).optString(BENTO_UUID))) {
+ if (DEBUG) Log.d(TAG, "onUpdate: ignore-3");
return;
}
-
- } else {
+ } catch (JSONException e) {
+ Log.e(TAG, "Failed to get JSON", e);
return;
}
+
+ // set new state
+ setNewStateObj(stateObj);
+
+ mLastInt = (obj.getIntKey() == null) ? 0 : obj.getIntKey();
+ if (DEBUG) Log.d(TAG, "onUpdate - mLastInt: " + mLastInt);
+
}
};
@@ -22,7 +22,10 @@
import mobisocial.bento.todo.io.Bento;
import mobisocial.bento.todo.io.BentoManager;
import mobisocial.bento.todo.io.BentoManager.OnStateUpdatedListener;
+import mobisocial.bento.todo.util.InitialHelper;
import mobisocial.bento.todo.util.UIUtils;
+import mobisocial.bento.todo.util.InitialHelper.OnInitCompleteListener;
+import mobisocial.socialkit.musubi.Musubi;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
@@ -51,6 +54,14 @@
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+
+ // create Musubi Instance
+ InitialHelper initHelper = new InitialHelper(this, mInitCompleteListener);
+ Musubi musubi = initHelper.initMusubiInstance();
+ if (musubi == null) {
+ return;
+ }
+
setContentView(R.layout.activity_bento_list);
final ActionBar actionBar = getSupportActionBar();
@@ -110,6 +121,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}
};
+
+ // InitialHelper > OnInitCompleteListener
+ private OnInitCompleteListener mInitCompleteListener = new OnInitCompleteListener() {
+ @Override
+ public void onInitCompleted() {
+ mBentoListFragment.refreshView();
+ }
+ };
// BentoEventManager > OnStateUpdatedListener
private OnStateUpdatedListener mStateUpdatedListener = new OnStateUpdatedListener() {
@@ -20,6 +20,7 @@
import mobisocial.bento.todo.R;
import mobisocial.bento.todo.io.BentoManager;
+import mobisocial.bento.todo.util.UIUtils;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
@@ -30,7 +31,7 @@
import android.widget.TextView;
public class BentoListItemAdapter extends ArrayAdapter<BentoListItem> {
- private static final Boolean DEBUG = false;
+ private static final Boolean DEBUG = UIUtils.isDebugMode();
private static final String TAG = "BentoListItemAdapter";
private LayoutInflater mInflater;
@@ -16,9 +16,13 @@
package mobisocial.bento.todo.ui;
+import mobisocial.bento.todo.R;
import mobisocial.bento.todo.io.BentoManager;
import mobisocial.bento.todo.io.BentoManager.OnStateUpdatedListener;
import mobisocial.bento.todo.ui.TodoListFragment.OnBentoSelectedListener;
+import mobisocial.bento.todo.util.InitialHelper;
+import mobisocial.bento.todo.util.InitialHelper.OnInitCompleteListener;
+import mobisocial.socialkit.musubi.Musubi;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ActionBar;
@@ -27,8 +31,6 @@
import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;
-import mobisocial.bento.todo.R;
-
public class TodoListActivity extends FragmentActivity implements OnBentoSelectedListener {
public static final String EXTRA_LAUNCHED_FROM_BENTO_LIST = "launched_from_bento_list";
@@ -41,20 +43,37 @@
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_todo_list);
mLaunchedFromBentoList = getIntent().hasExtra(EXTRA_LAUNCHED_FROM_BENTO_LIST);
+ if (!mLaunchedFromBentoList) {
+ // create Musubi Instance
+ InitialHelper initHelper = new InitialHelper(this, mInitCompleteListener);
+ Musubi musubi = initHelper.initMusubiInstance();
+ if (musubi == null) {
+ return;
+ }
+ }
+
+ setContentView(R.layout.activity_todo_list);
+
final ActionBar actionBar = getSupportActionBar();
// set defaults for logo & home up
actionBar.setDisplayHomeAsUpEnabled(true); // bad know-how for enabling home clickable on ICS.
actionBar.setDisplayHomeAsUpEnabled(mLaunchedFromBentoList);
actionBar.setDisplayUseLogoEnabled(false);
- actionBar.setTitle(mManager.getBentoListItem().bento.name.toString());
+ if (mLaunchedFromBentoList) {
+ actionBar.setTitle(mManager.getBentoListItem().bento.name.toString());
+ }
FragmentManager fm = getSupportFragmentManager();
mTodoListFragment = (TodoListFragment) fm.findFragmentById(R.id.fragment_todo_list);
mManager.addListener(mStateUpdatedListener);
+
+ // loading
+ if (!mLaunchedFromBentoList) {
+ mTodoListFragment.setProgressBarVisible(true);
+ }
}
@Override
@@ -90,6 +109,15 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
+ // InitialHelper > OnInitCompleteListener
+ private OnInitCompleteListener mInitCompleteListener = new OnInitCompleteListener() {
+ @Override
+ public void onInitCompleted() {
+ onBentoSelected();
+ mTodoListFragment.setProgressBarVisible(false);
+ }
+ };
+
// TodoListFragment > OnBentoSelectedListener
@Override
public void onBentoSelected() {
Oops, something went wrong.

0 comments on commit 7dd80a8

Please sign in to comment.