more work on responsiveness and cleanups
This commit is contained in:
parent
f7907f73bf
commit
22224f7e41
7 changed files with 117 additions and 56 deletions
|
@ -33,8 +33,7 @@ public class PassVisualizer {
|
|||
findById(container, R.id.navigateTo).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final String lang = activity.getResources().getConfiguration().locale.getLanguage();
|
||||
NavigateToLocationsDialog.perform(activity, App.getPassStore().getPassbookForId(pass.getId(), lang), false);
|
||||
NavigateToLocationsDialog.perform(activity, App.getPassStore().getPassbookForId(pass.getId()), false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.google.common.base.Optional;
|
|||
import org.ligi.axt.AXT;
|
||||
import org.ligi.passandroid.App;
|
||||
import org.ligi.passandroid.helper.DirectoryFileFilter;
|
||||
import org.ligi.tracedroid.logging.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
@ -40,6 +41,12 @@ public class AndroidFileSystemPassStore implements PassStore {
|
|||
return new File(getPathForID(id) + "/base_cache.obj");
|
||||
}
|
||||
|
||||
public void preCachePassesList() {
|
||||
for (String key : getPassIDArray()) {
|
||||
getPassbookForId(key);
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshPassesList() {
|
||||
path = App.getPassesDir(context);
|
||||
|
||||
|
@ -69,12 +76,15 @@ public class AndroidFileSystemPassStore implements PassStore {
|
|||
|
||||
|
||||
private Pass getCachedPassOrLoad(String id) {
|
||||
Log.i("PassGet " + id);
|
||||
final File cachedFile = getCacheFile(id);
|
||||
try {
|
||||
return AXT.at(cachedFile).loadToObject();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Log.i("PassGet cache miss" + cachedFile.exists() );
|
||||
final String language = context.getResources().getConfiguration().locale.getLanguage();
|
||||
final Pass pass = AppleStylePassReader.read(getPathForID(id), language);
|
||||
AXT.at(cachedFile).writeObject(pass);
|
||||
|
@ -102,10 +112,14 @@ public class AndroidFileSystemPassStore implements PassStore {
|
|||
return passList.get(pos);
|
||||
}
|
||||
|
||||
public Pass getPassbookForId(final String id, final String language) {
|
||||
final String mPath = path + "/" + id;
|
||||
// TODO read from cache
|
||||
return AppleStylePassReader.read(mPath, language);
|
||||
public Pass getPassbookForId(final String id) {
|
||||
for (Pass pass : passList) {
|
||||
if (pass.getId().equals(id)) {
|
||||
return pass;
|
||||
}
|
||||
}
|
||||
|
||||
return getCachedPassOrLoad(id);
|
||||
}
|
||||
|
||||
public void sort(final SortOrder order) {
|
||||
|
|
|
@ -37,6 +37,8 @@ public interface PassStore {
|
|||
}
|
||||
}
|
||||
|
||||
public void preCachePassesList();
|
||||
|
||||
public void deleteCache();
|
||||
|
||||
public void refreshPassesList();
|
||||
|
@ -47,7 +49,7 @@ public interface PassStore {
|
|||
|
||||
public Pass getPassbookAt(int pos);
|
||||
|
||||
public Pass getPassbookForId(String id,String language);
|
||||
public Pass getPassbookForId(String id);
|
||||
|
||||
public void sort(SortOrder order);
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public class PassImportActivity extends ActionBarActivity {
|
|||
final String id = AXT.at(path.split("/")).last();
|
||||
|
||||
final PassStore store = App.getPassStore();
|
||||
store.setCurrentPass(store.getPassbookForId(id, getResources().getConfiguration().locale.getLanguage()));
|
||||
store.setCurrentPass(store.getPassbookForId(id));
|
||||
|
||||
AXT.at(PassImportActivity.this).startCommonIntent().activityFromClass(PassViewActivity.class);
|
||||
finish();
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.ligi.passandroid.events.SortOrderChangeEvent;
|
|||
import org.ligi.passandroid.events.TypeFocusEvent;
|
||||
import org.ligi.passandroid.model.InputStreamWithSource;
|
||||
import org.ligi.passandroid.model.Pass;
|
||||
import org.ligi.passandroid.model.PassStore;
|
||||
import org.ligi.passandroid.model.PastLocationsStore;
|
||||
import org.ligi.tracedroid.TraceDroid;
|
||||
import org.ligi.tracedroid.logging.Log;
|
||||
|
@ -58,12 +59,6 @@ public class PassListActivity extends ActionBarActivity {
|
|||
|
||||
private PassAdapter passAdapter;
|
||||
|
||||
private final static int UISTATE_INIT = 0;
|
||||
private final static int UISTATE_SCAN = 1;
|
||||
private final static int UISTATE_LIST = 2;
|
||||
|
||||
private int uiState = UISTATE_INIT;
|
||||
|
||||
private ScanForPassesTask scanTask = null;
|
||||
private ActionBarDrawerToggle drawerToggle;
|
||||
|
||||
|
@ -104,13 +99,33 @@ public class PassListActivity extends ActionBarActivity {
|
|||
}
|
||||
|
||||
public void refreshPasses() {
|
||||
App.getPassStore().refreshPassesList();
|
||||
App.getPassStore().sort(App.getSettings().getSortOrder());
|
||||
final PassStore passStore = App.getPassStore();
|
||||
passStore.preCachePassesList();
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
passStore.refreshPassesList();
|
||||
passStore.sort(App.getSettings().getSortOrder());
|
||||
|
||||
passAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
final PassListUIState uiState;
|
||||
|
||||
public PassListActivity() {
|
||||
super();
|
||||
uiState = new PassListUIState(this) {
|
||||
@Override
|
||||
public void set(int state) {
|
||||
Log.i("setting ui state " + state);
|
||||
super.set(state);
|
||||
updateUIRegardingToUIState();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -144,6 +159,7 @@ public class PassListActivity extends ActionBarActivity {
|
|||
App.getBus().post(new NavigationOpenedEvent());
|
||||
}
|
||||
};
|
||||
|
||||
drawer.setDrawerListener(drawerToggle);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
@ -206,14 +222,15 @@ public class PassListActivity extends ActionBarActivity {
|
|||
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
if (uiState.get() ==PassListUIState.UISTATE_LIST) {
|
||||
Tracker.get().trackEvent(TrackerInterface.EVENT_CATEGORY_UI_ACTION, "refresh", "from_swipe", null);
|
||||
scanForPasses();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void scanForPasses() {
|
||||
App.getPassStore().deleteCache();
|
||||
new ScanForPassesTask().execute();
|
||||
}
|
||||
|
||||
|
@ -229,18 +246,13 @@ public class PassListActivity extends ActionBarActivity {
|
|||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (uiState!=UISTATE_LIST) {
|
||||
Toast.makeText(this,R.string.please_wait,Toast.LENGTH_LONG).show();
|
||||
if (uiState.get() != PassListUIState.UISTATE_LIST) {
|
||||
Toast.makeText(this, R.string.please_wait, Toast.LENGTH_LONG).show();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (drawerToggle.onOptionsItemSelected(item)) {
|
||||
if (navigationFragment==null) {
|
||||
navigationFragment = new NavigationFragment();
|
||||
getSupportFragmentManager().beginTransaction().add(R.id.left_drawer, navigationFragment).commit();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -289,53 +301,45 @@ public class PassListActivity extends ActionBarActivity {
|
|||
listView.setAdapter(passAdapter);
|
||||
|
||||
if (App.getPassStore().isEmpty()) {
|
||||
uiState = UISTATE_SCAN;
|
||||
uiState.set(PassListUIState.UISTATE_SCAN);
|
||||
scanTask = new ScanForPassesTask();
|
||||
scanTask.execute();
|
||||
} else {
|
||||
uiState = UISTATE_LIST;
|
||||
uiState.set(PassListUIState.UISTATE_LIST);
|
||||
}
|
||||
|
||||
updateUIRegardingToUIState();
|
||||
|
||||
Tracker.get().trackEvent("ui_event", "resume", "passes", (long) App.getPassStore().passCount());
|
||||
|
||||
refreshPasses();
|
||||
|
||||
if (navigationFragment == null) {
|
||||
navigationFragment = new NavigationFragment();
|
||||
getSupportFragmentManager().beginTransaction().add(R.id.left_drawer, navigationFragment).commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
menu.clear();
|
||||
if (uiState == UISTATE_LIST) {
|
||||
if (uiState.get() == PassListUIState.UISTATE_LIST) {
|
||||
getMenuInflater().inflate(R.menu.activity_pass_list_view, menu);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void updateUIRegardingToUIState() {
|
||||
Log.i("", "changeuistate" + uiState);
|
||||
|
||||
listSwipeRefreshLayout.setRefreshing(uiState!=UISTATE_LIST);
|
||||
emptySwipeRefreshLayout.setRefreshing(uiState!=UISTATE_LIST);
|
||||
listSwipeRefreshLayout.setRefreshing(uiState.get() != PassListUIState.UISTATE_LIST);
|
||||
emptySwipeRefreshLayout.setRefreshing(uiState.get() != PassListUIState.UISTATE_LIST);
|
||||
|
||||
supportInvalidateOptionsMenu();
|
||||
|
||||
emptyView.setText(Html.fromHtml(getHtmlForEmptyView()));
|
||||
emptyView.setText(Html.fromHtml(uiState.getHtmlResForEmptyView()));
|
||||
emptyView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
|
||||
public String getHtmlForEmptyView() {
|
||||
switch (uiState) {
|
||||
case UISTATE_INIT:
|
||||
return getString(R.string.please_wait);
|
||||
|
||||
case UISTATE_SCAN:
|
||||
return getString(R.string.scan_empty_text) + getString(R.string.no_passes_appendix);
|
||||
|
||||
default:
|
||||
return getString(R.string.no_passes_empty_text) + getString(R.string.no_passes_appendix);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
|
@ -358,7 +362,7 @@ public class PassListActivity extends ActionBarActivity {
|
|||
if (scanTask != null) {
|
||||
scanTask.cancel(true);
|
||||
}
|
||||
uiState=UISTATE_LIST;
|
||||
uiState.set(PassListUIState.UISTATE_LIST);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
|
@ -445,20 +449,18 @@ public class PassListActivity extends ActionBarActivity {
|
|||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
uiState=UISTATE_LIST;
|
||||
uiState.set(PassListUIState.UISTATE_SCAN);
|
||||
|
||||
Tracker.get().trackEvent("ui_event", "scan", "started", null);
|
||||
|
||||
updateUIRegardingToUIState();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
super.onPostExecute(aVoid);
|
||||
uiState=UISTATE_LIST;
|
||||
uiState.set(PassListUIState.UISTATE_LIST);
|
||||
|
||||
// TODO bring back Tracker.get().trackTiming("timing", System.currentTimeMillis() - start_time, "scan", "scan_time");
|
||||
updateUIRegardingToUIState();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
42
src/main/java/org/ligi/passandroid/ui/PassListUIState.java
Normal file
42
src/main/java/org/ligi/passandroid/ui/PassListUIState.java
Normal file
|
@ -0,0 +1,42 @@
|
|||
package org.ligi.passandroid.ui;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.ligi.passandroid.R;
|
||||
|
||||
public class PassListUIState {
|
||||
|
||||
public final static int UISTATE_INIT = 0;
|
||||
public final static int UISTATE_SCAN = 1;
|
||||
public final static int UISTATE_LIST = 2;
|
||||
|
||||
private int state = UISTATE_INIT;
|
||||
|
||||
private final Context ctx;
|
||||
|
||||
public PassListUIState(Context ctx) {
|
||||
this.ctx = ctx;
|
||||
}
|
||||
|
||||
public void set(int state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public int get() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public String getHtmlResForEmptyView() {
|
||||
switch (state) {
|
||||
case PassListUIState.UISTATE_INIT:
|
||||
return ctx.getString(R.string.please_wait);
|
||||
|
||||
case PassListUIState.UISTATE_SCAN:
|
||||
return ctx.getString(R.string.scan_empty_text) + ctx.getString(R.string.no_passes_appendix);
|
||||
|
||||
default:
|
||||
return ctx.getString(R.string.no_passes_empty_text) + ctx.getString(R.string.no_passes_appendix);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -91,11 +91,13 @@ public class UnzipPassController {
|
|||
new File(spec.targetPath).mkdirs();
|
||||
final File rename_file = new File(rename_str);
|
||||
|
||||
if (rename_file.exists()) {
|
||||
AXT.at(rename_file).deleteRecursive();
|
||||
if (!rename_file.exists()) {
|
||||
new File(path + "/").renameTo(rename_file);
|
||||
} else {
|
||||
spec.failCallback.fail("Pass with same ID exists");
|
||||
return;
|
||||
}
|
||||
|
||||
new File(path + "/").renameTo(rename_file);
|
||||
path = rename_str;
|
||||
} catch (JSONException e) {
|
||||
spec.failCallback.fail("Problem with pass.json: " + e);
|
||||
|
|
Loading…
Reference in a new issue