Skip to content

Commit

Permalink
Partially implements task #81.
Browse files Browse the repository at this point in the history
One thing before finishing this task is:
There is still a delay before show the "if load" alert dialog, not sure
what costs this time.
Keep thinking...
----------------------
Another opinion is: we should always try to load automatically, if the
performance is not good, then fix the performance bug. A possible
solution might be using adaptor tech for the gallery. Will investigate
later.
--------------------------
Now, just add a switch flag in AppConfig class.
  • Loading branch information
tomdong committed Mar 22, 2013
1 parent 227ca21 commit 403fac1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
36 changes: 32 additions & 4 deletions src/com/intalker/borrow/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.intalker.borrow.util.StorageUtil;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.view.Menu;
Expand Down Expand Up @@ -68,15 +70,15 @@ public void onCreate(Bundle savedInstanceState) {
StorageUtil.initialize();
AppData.getInstance().initialize();
DensityAdaptor.init(this);
StorageUtil.loadCachedBooks();
if (!AppConfig.disableAutoLoadCache) {
StorageUtil.loadCachedBooks();
}
CloudAPI.CloudToken = "";

setContentView(initializeWithSlidingStyle());
this.mSlidingMenu.invalidate();

//Continue to investigate this Async task later
// InitialCachedDataAsyncTask initCachedDataTask = new InitialCachedDataAsyncTask();
// initCachedDataTask.execute();
//enable later
tryAutoLogin();
}

Expand Down Expand Up @@ -130,6 +132,32 @@ private void doAfterGetUserInfoByToken(int returnCode) {
if (CloudAPI.isSuccessful(this, returnCode)) {
mBookGallery.updateTopPanel(UserInfo.getCurLoggedinUser());
mSocialPanel.getFriendsView().refreshList();

if (AppConfig.disableAutoLoadCache) {
AlertDialog alertDialog = new AlertDialog.Builder(this)
.setTitle("test")
.setMessage("msg")
.setIcon(R.drawable.question)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog,
int which) {
InitialCachedDataAsyncTask initCachedDataTask = new InitialCachedDataAsyncTask();
initCachedDataTask.execute();
}
})
.setNegativeButton("cancel",
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog,
int which) {
}
}).create();
alertDialog.show();
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/com/intalker/borrow/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
public class AppConfig {
public final static boolean isDebugMode = true;
public final static boolean useSQLiteForCache = true;
public final static boolean disableAutoLoadCache = false;
}
8 changes: 8 additions & 0 deletions src/com/intalker/borrow/data/InitialCachedDataAsyncTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.intalker.borrow.cloud.CloudAPI;
import com.intalker.borrow.cloud.CloudUtility;
import com.intalker.borrow.cloud.CloudAPIAsyncTask.ICloudAPITaskListener;
import com.intalker.borrow.ui.control.TransparentProgressDialog;
import com.intalker.borrow.util.DBUtil;
import com.intalker.borrow.util.StorageUtil;

Expand All @@ -12,6 +13,8 @@

public class InitialCachedDataAsyncTask extends AsyncTask<Void, Void, Void> {

private TransparentProgressDialog mProgressDialog = null;

@Override
protected Void doInBackground(Void... params) {
StorageUtil.loadCachedBooks();
Expand All @@ -32,6 +35,7 @@ public void onFinish(int returnCode) {
app.getBookGallery().updateTopPanel(UserInfo.getCurLoggedinUser());
app.getSocialPanel().getFriendsView().refreshList();
}
mProgressDialog.dismiss();
}

});
Expand All @@ -42,6 +46,10 @@ public void onFinish(int returnCode) {
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
mProgressDialog = new TransparentProgressDialog(HomeActivity.getApp(), false);
mProgressDialog.setCancelable(false);
mProgressDialog.setMessage("Loading");
mProgressDialog.show();
}

}
1 change: 0 additions & 1 deletion src/com/intalker/borrow/ui/book/BookGallery.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.intalker.borrow.util.DeviceUtil;
import com.intalker.borrow.util.LayoutUtil;
import com.intalker.borrow.util.ScanUtil;

import android.content.Context;
import android.graphics.Color;
import android.view.MotionEvent;
Expand Down

0 comments on commit 403fac1

Please sign in to comment.