Browse files

Collapse/Expand is async

Expand all is limited by depth and list length
  • Loading branch information...
1 parent a33ef29 commit 3aff9ad21be4760f277ab9db4b4a82d2629304c7 Konstantin Vorobyev committed Jan 20, 2012
View
2 project.properties
@@ -9,5 +9,5 @@
# Project target.
target=android-14
-android.library.reference.1=..\\android-actionbar\\actionbar
+android.library.reference.1=../android-actionbar/actionbar
android.library.reference.2=../android-file-dialog/FileExplorer
View
1 src/com/matburt/mobileorg/ng/service/MobileOrgDBHelper.java
@@ -53,7 +53,6 @@ public void migrate(SQLiteDatabase db, int version) {
db.execSQL("create index if not exists data_note_id on data (note_id)");
break;
case 9:
- db.execSQL("drop index if exists data_parent_id_type");
db.execSQL("drop index if exists data_note_id");
break;
}
View
6 src/com/matburt/mobileorg/ng/settings/widget/SelectOutlineActivity.java
@@ -125,4 +125,10 @@ public void loadFinished() {
// TODO Auto-generated method stub
}
+
+ @Override
+ public void reportError(String message) {
+ // TODO Auto-generated method stub
+
+ }
}
View
16 src/com/matburt/mobileorg/ng/ui/FOutlineViewer.java
@@ -70,7 +70,7 @@
@Override
protected void onCreate(Bundle savedState) {
super.onCreate(savedState);
- requestWindowFeature(Window.FEATURE_PROGRESS);
+ requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
Intent serviceIntent = new Intent(this, DataService.class);
startService(serviceIntent);
if (null != savedState) {
@@ -104,6 +104,7 @@ protected void onCreate(Bundle savedState) {
if (null != right) {
right.setDataListener(this);
}
+ loadFinished();
}
@Override
@@ -720,6 +721,7 @@ public boolean onKeyPress(int keyCode, OutlineViewerFragment fragment,
@Override
public void loadStarted() {
+ Log.i(TAG, "Start load");
setProgressBarIndeterminateVisibility(true);
if (null != actionBar) {
actionBar.setProgressBarVisibility(View.VISIBLE);
@@ -728,9 +730,21 @@ public void loadStarted() {
@Override
public void loadFinished() {
+ Log.i(TAG, "Finish load");
setProgressBarIndeterminateVisibility(false);
if (null != actionBar) {
actionBar.setProgressBarVisibility(View.GONE);
}
}
+
+ @Override
+ public void reportError(final String message) {
+ runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ SuperActivity.notifyUser(FOutlineViewer.this, message);
+ }
+ });
+ }
}
View
6 src/com/matburt/mobileorg/ng/ui/OutlineLinkPicker.java
@@ -122,4 +122,10 @@ public void loadFinished() {
// TODO Auto-generated method stub
}
+
+ @Override
+ public void reportError(String message) {
+ // TODO Auto-generated method stub
+
+ }
}
View
4 src/com/matburt/mobileorg/ng/ui/OutlineViewerFragment.java
@@ -45,6 +45,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
adapter = new OutlineViewerAdapter(getActivity(), null);
setListAdapter(adapter);
+ adapter.setListener(dataListener);
getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
@@ -155,6 +156,9 @@ public void onListItemClick(ListView l, View v, int position, long id) {
public void setDataListener(DataListener dataListener) {
this.dataListener = dataListener;
+ if (null != adapter) {
+ adapter.setListener(dataListener);
+ }
}
public void reload() {
View
50 src/com/matburt/mobileorg/ng/ui/adapter/OutlineViewerAdapter.java
@@ -46,6 +46,9 @@
PlainTextFormatter textFormatter = null;
PlainTextFormatter sublistFormatter = null;
+ private static final int MAX_DATA_SIZE = 200;
+ private static final int MAX_EXPAND_ALL_DEPTH = 3;
+
static {
levelColors = new int[] { theme.ccLBlue, theme.c3Yellow, theme.ceLCyan,
theme.c1Red, theme.c2Green, theme.c5Purple, theme.ccLBlue,
@@ -64,6 +67,8 @@
public void loadStarted();
public void loadFinished();
+
+ public void reportError(String message);
}
public OutlineViewerAdapter(Context context,
@@ -94,6 +99,9 @@ public int getCount() {
@Override
public NoteNG getItem(int position) {
+ if (position >= data.size()) {
+ return null;
+ }
return data.get(position);
}
@@ -383,6 +391,9 @@ public View getView(int position, View convertView, ViewGroup parent) {
parent, false);
}
NoteNG note = getItem(position);
+ if (null == note) {
+ return null;
+ }
// boolean isselected = selected == note.id;
boolean isclicked = null != clicked && clicked.id.equals(note.id);
TextView title = (TextView) convertView
@@ -497,7 +508,7 @@ public int reload(List<Integer> selection) {
clicked = n;
selectedPos = j;
start = j + 1;
- end = expandNote(n, j, false) + start;
+ end = expandNote(n, j, false, -1, false) + start;
found = true;
break;
}
@@ -521,7 +532,7 @@ public void setExpanded(int position, int state) {
collapseNote(note, position);
if (NoteNG.EXPAND_COLLAPSED != state) {
expandNote(note, position, NoteNG.EXPAND_MANY == state ? true
- : false);
+ : false, -1, false);
}
}
@@ -543,12 +554,24 @@ public void collapseExpand(final int position, final boolean notify,
@Override
protected Void doInBackground(Void... params) {
if (note.expanded == NoteNG.EXPAND_COLLAPSED) {
- expandNote(note, position, false);
+ if (data.size() >= MAX_DATA_SIZE) {
+ if (null != listener) {
+ listener.reportError("Max number of visible elements reached");
+ }
+ } else {
+ expandNote(note, position, false, -1, true);
+ }
} else {
if (null != clicked && clicked.id.equals(note.id)) {
if (note.expanded == NoteNG.EXPAND_ONE && canExpandAll) {
collapseNote(note, position);
- expandNote(note, position, true);
+ if (data.size() >= MAX_DATA_SIZE) {
+ if (null != listener) {
+ listener.reportError("Max number of visible elements reached");
+ }
+ } else {
+ expandNote(note, position, true, 0, true);
+ }
} else {
collapseNote(note, position);
}
@@ -583,22 +606,35 @@ private void collapseNote(NoteNG note, int position) {
}
}
- public int expandNote(NoteNG note, int position, boolean expandAll) {
+ public int expandNote(NoteNG note, int position, boolean expandAll,
+ int expandLevel, boolean limitSize) {
+ if (expandLevel > MAX_EXPAND_ALL_DEPTH) {
+ // if (null != listener) {
+ // listener.reportError("Max expand level reached");
+ // }
+ return 0;
+ }
note.expanded = expandAll ? NoteNG.EXPAND_MANY : NoteNG.EXPAND_ONE;
List<NoteNG> list = controller.getData(note.id);
if (null == list) {
return 0;
}
int pos = 0;
+ boolean canExpand = true;
for (int i = 0; i < list.size(); i++) {
NoteNG n = list.get(i);
n.parentNote = note;
n.index = i;
n.indent = note.indent + 1;
pos++;
data.add(position + pos, n);
- if (expandAll) {
- pos += expandNote(n, position + pos, expandAll);
+ if (expandAll && canExpand) {
+ if (limitSize && data.size() > MAX_DATA_SIZE) {
+ canExpand = false;
+ } else {
+ pos += expandNote(n, position + pos, expandAll,
+ expandLevel == -1 ? -1 : expandLevel + 1, limitSize);
+ }
}
}
return pos;
View
5 src/com/matburt/mobileorg/ng/widgets/OutlineWidget.java
@@ -97,13 +97,14 @@ private void putOutline(int expand, boolean longFormat, NoteNG note,
OutlineViewerAdapter adapter = new OutlineViewerAdapter(context, null);
adapter.setWide(longFormat);
adapter.setController(note.id, controller, new ArrayList<Integer>());
- adapter.expandNote(adapter.getItem(0), 0, expand == -1 ? true : false);
+ adapter.expandNote(adapter.getItem(0), 0, expand == -1 ? true : false,
+ -1, false);
if (expand == 2) {
int pos = 0;
int size = adapter.getCount();
for (int i = 1; i < size; i++) {
pos += adapter.expandNote(adapter.getItem(i + pos), i + pos,
- false);
+ false, -1, false);
}
}
// Log.i(TAG, "Number of items: " + adapter.getCount());

0 comments on commit 3aff9ad

Please sign in to comment.