Commit ef2ddd882bd01d15f49bc3c8b74d872e8a9f0c92
1 parent
97f3d354
- fix initial sync update view display error
Showing
2 changed files
with
21 additions
and
14 deletions
app/src/main/java/net/devfac/userstory/FSM/StateContext.java
... | ... | @@ -367,21 +367,25 @@ public class StateContext { |
367 | 367 | } |
368 | 368 | |
369 | 369 | boolean is_contained = false; |
370 | + mDbEntries = mDbOpenHelper.getAllEntries(); | |
371 | + | |
372 | + if( mDbEntries != null ){ | |
373 | + for( BookShelfInfo dbBookInfo : mDbEntries ){ | |
374 | + for( BookShelfInfo newBookInfo : mBookShelfInfoArray){ | |
375 | + if( dbBookInfo.getResisteredId().equals(newBookInfo.getResisteredId())){ | |
376 | + is_contained = true; | |
377 | + break; | |
378 | + } | |
379 | + } | |
370 | 380 | |
371 | - for( BookShelfInfo dbBookInfo : mDbEntries ){ | |
372 | - for( BookShelfInfo newBookInfo : mBookShelfInfoArray){ | |
373 | - if( dbBookInfo.getResisteredId().equals(newBookInfo.getResisteredId())){ | |
374 | - is_contained = true; | |
375 | - break; | |
381 | + if( !is_contained ){ | |
382 | + mDbOpenHelper.delete(dbBookInfo.getResisteredId()); | |
376 | 383 | } |
377 | - } | |
378 | 384 | |
379 | - if( !is_contained ){ | |
380 | - mDbOpenHelper.delete(dbBookInfo.getResisteredId()); | |
385 | + is_contained = false; | |
381 | 386 | } |
382 | - | |
383 | - is_contained = false; | |
384 | 387 | } |
388 | + | |
385 | 389 | mStateResult = STATE_RESULT.SYNC_SUCCESS; |
386 | 390 | processEvent(Action.RES_SYNC, null); |
387 | 391 | } | ... | ... |
app/src/main/java/net/devfac/userstory/FragmentBookShelf.java
... | ... | @@ -30,6 +30,8 @@ public class FragmentBookShelf extends Fragment implements StateEventListener { |
30 | 30 | private ListView mBookshelf; |
31 | 31 | private WebView wv; |
32 | 32 | private ProgressDialog mProgressDialog; |
33 | + private RecyclerView mRecyclerView; | |
34 | + private RecyclerAdapterBookShelfItem mRecyclerAdapter; | |
33 | 35 | |
34 | 36 | public static FragmentBookShelf getInstance(int itemCount){ |
35 | 37 | FragmentBookShelf fragmentBookShelf = new FragmentBookShelf(); |
... | ... | @@ -42,13 +44,13 @@ public class FragmentBookShelf extends Fragment implements StateEventListener { |
42 | 44 | |
43 | 45 | View rootView = inflater.inflate(R.layout.recycler_book_shelf, container, false); |
44 | 46 | |
45 | - RecyclerView recyclerView = (RecyclerView)rootView.findViewById(R.id.recycler_book_shelf); | |
47 | + mRecyclerView = (RecyclerView)rootView.findViewById(R.id.recycler_book_shelf); | |
46 | 48 | |
47 | 49 | mBookShelfCursorAdapter = new BookShelfCursorAdapter( |
48 | 50 | getActivity(), |
49 | 51 | StateContext.getInstance(getActivity()).getDbOpenHelper().getCursor(), true); |
50 | 52 | |
51 | - setupRecyclerView(recyclerView); | |
53 | + setupRecyclerView(mRecyclerView); | |
52 | 54 | |
53 | 55 | StateContext.getInstance(getActivity()).setStateEventListener(this); |
54 | 56 | |
... | ... | @@ -57,8 +59,8 @@ public class FragmentBookShelf extends Fragment implements StateEventListener { |
57 | 59 | |
58 | 60 | private void setupRecyclerView(RecyclerView recyclerView) { |
59 | 61 | recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); |
60 | - RecyclerAdapterBookShelfItem recyclerAdapter = new RecyclerAdapterBookShelfItem(getActivity(), mBookShelfCursorAdapter); | |
61 | - recyclerView.setAdapter(recyclerAdapter); | |
62 | + mRecyclerAdapter = new RecyclerAdapterBookShelfItem(getActivity(), mBookShelfCursorAdapter); | |
63 | + recyclerView.setAdapter(mRecyclerAdapter); | |
62 | 64 | } |
63 | 65 | |
64 | 66 | @Override |
... | ... | @@ -82,6 +84,7 @@ public class FragmentBookShelf extends Fragment implements StateEventListener { |
82 | 84 | @Override |
83 | 85 | public void run() { |
84 | 86 | mBookShelfCursorAdapter.changeCursor(StateContext.getInstance(getActivity()).getDbOpenHelper().getCursor()); |
87 | + mRecyclerAdapter.notifyDataSetChanged(); | |
85 | 88 | |
86 | 89 | if( mProgressDialog != null){ |
87 | 90 | mProgressDialog.dismiss(); | ... | ... |