Commit bcd1eca166594f98228d1e15b040ff0bb84d626e

Authored by transpine
1 parent 226d8cd7

- add sync dialog

app/src/main/java/net/devfac/userstory/ActivityLogin.java
1 1 package net.devfac.userstory;
2 2  
3   -import android.app.AlertDialog;
  3 +import android.app.ProgressDialog;
4 4 import android.content.Intent;
5 5 import android.net.Uri;
6 6 import android.os.Bundle;
... ... @@ -10,7 +10,6 @@ import android.view.Menu;
10 10 import android.view.MenuInflater;
11 11 import android.view.MenuItem;
12 12 import android.view.View;
13   -import android.widget.Button;
14 13 import android.widget.EditText;
15 14 import android.widget.ImageButton;
16 15 import android.widget.TextView;
... ... @@ -23,8 +22,6 @@ import net.devfac.userstory.FSM.state.StateLoginRequested;
23 22 import net.devfac.userstory.Utils.Logger;
24 23 import net.devfac.userstory.Utils.PreferenceUtil;
25 24  
26   -import org.w3c.dom.Text;
27   -
28 25 /**
29 26 * Created by Onether on 15. 11. 10..
30 27 */
... ... @@ -35,7 +32,7 @@ public class ActivityLogin extends AppCompatActivity implements View.OnClickList
35 32 private ImageButton mImgBtnLogin;
36 33 private TextView mTextHomepageLink;
37 34  
38   - private AlertDialog mAlertDialog;
  35 + private ProgressDialog mProgressDialog;
39 36  
40 37 @Override
41 38 protected void onCreate(Bundle savedInstanceState) {
... ... @@ -65,8 +62,6 @@ public class ActivityLogin extends AppCompatActivity implements View.OnClickList
65 62 mTextHomepageLink.setOnClickListener(this);
66 63  
67 64 StateContext.getInstance(this).setStateEventListener(this);
68   -
69   - mAlertDialog = new AlertDialog.Builder(this).create();
70 65 }
71 66  
72 67 @Override
... ... @@ -121,16 +116,27 @@ public class ActivityLogin extends AppCompatActivity implements View.OnClickList
121 116 public void onEntry(Class stateClass, Object input) {
122 117 if( stateClass.equals(StateLoginRequested.class)){
123 118 // Toast.makeText(this, "로그인 중입니다...", Toast.LENGTH_LONG).show();
124   - mAlertDialog.setTitle("로그인 중입니다...");
125   - mAlertDialog.setMessage("잠시만 기다려 주세요.");
126   - mAlertDialog.show();
  119 + runOnUiThread(new Runnable() {
  120 + @Override
  121 + public void run() {
  122 + mProgressDialog = ProgressDialog.show(ActivityLogin.this, "로그인 중입니다", "잠시만 기다려주세요..");
  123 + }
  124 + });
127 125 }
128 126 }
129 127  
130 128 @Override
131 129 public void onExit(Class stateClass, Object output, StateContext.STATE_RESULT stateResult) {
132 130 if( stateClass.equals(StateLoginRequested.class)){
133   - mAlertDialog.dismiss();
  131 + runOnUiThread(new Runnable() {
  132 + @Override
  133 + public void run() {
  134 + if( mProgressDialog != null){
  135 + mProgressDialog.dismiss();
  136 + }
  137 + }
  138 + });
  139 +
134 140 switch( stateResult ){
135 141 case LOGIN_FAIL:
136 142 PreferenceUtil.getInstance(this).putIsLoggedInState(false);
... ...
app/src/main/java/net/devfac/userstory/FragmentBookShelf.java
1 1 package net.devfac.userstory;
2 2  
  3 +import android.app.ProgressDialog;
3 4 import android.os.Bundle;
4 5 import android.support.v4.app.Fragment;
5 6 import android.support.v7.widget.LinearLayoutManager;
... ... @@ -28,14 +29,10 @@ public class FragmentBookShelf extends Fragment implements StateEventListener {
28 29 private BookShelfCursorAdapter mBookShelfCursorAdapter;
29 30 private ListView mBookshelf;
30 31 private WebView wv;
31   -
32   - public final static String ITEMS_COUNT_KEY = "PartThreeFragment$ItemsCount";
  32 + private ProgressDialog mProgressDialog;
33 33  
34 34 public static FragmentBookShelf getInstance(int itemCount){
35 35 FragmentBookShelf fragmentBookShelf = new FragmentBookShelf();
36   - Bundle bundle = new Bundle();
37   - bundle.putInt(ITEMS_COUNT_KEY, itemCount);
38   - fragmentBookShelf.setArguments(bundle);
39 36 return fragmentBookShelf;
40 37 }
41 38  
... ... @@ -62,45 +59,35 @@ public class FragmentBookShelf extends Fragment implements StateEventListener {
62 59  
63 60 private void setupRecyclerView(RecyclerView recyclerView) {
64 61 recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
65   -// RecyclerAdapterBookShelfItem recyclerAdapter = new RecyclerAdapterBookShelfItem(createItemList());
66 62 RecyclerAdapterBookShelfItem recyclerAdapter = new RecyclerAdapterBookShelfItem(getActivity(), mBookShelfCursorAdapter);
67 63 recyclerView.setAdapter(recyclerAdapter);
68 64 }
69 65  
70   - private List<String> createItemList() {
71   - List<String> itemList = new ArrayList<>();
72   -
73   - int itemsCount = 50;
74   - for (int i = 0; i < itemsCount; i++) {
75   - itemList.add("Item " + i);
76   - }
77   - return itemList;
78   - }
79   -
80   - @Override
81   - public void onResume() {
82   - //TODO: error display when userid is none
83   - StateContext.getInstance(getActivity()).processEvent(Action.REQ_SYNC, null);
84   -
85   - super.onResume();
86   - }
87   -
88 66 @Override
89 67 public void onEntry(Class stateClass, Object input) {
90 68 if( stateClass.equals(StateSync.class)){
91   - Toast.makeText(getActivity(), "SYNC STARTED", Toast.LENGTH_LONG).show();
  69 +// Toast.makeText(getActivity(), "SYNC STARTED", Toast.LENGTH_LONG).show();
  70 + getActivity().runOnUiThread(new Runnable() {
  71 + @Override
  72 + public void run() {
  73 + mProgressDialog = ProgressDialog.show(getActivity(), "SYNC", "SYNC START");
  74 + }
  75 + });
92 76 }
93   -
94 77 }
95 78  
96 79 @Override
97 80 public void onExit(Class stateClass, Object output, StateContext.STATE_RESULT stateResult) {
98 81 if( stateClass.equals(StateSync.class)){
99   - Toast.makeText(getActivity(), "SYNC END", Toast.LENGTH_LONG).show();
  82 +// Toast.makeText(getActivity(), "SYNC END", Toast.LENGTH_LONG).show();
100 83 getActivity().runOnUiThread(new Runnable() {
101 84 @Override
102 85 public void run() {
103 86 mBookShelfCursorAdapter.changeCursor(StateContext.getInstance(getActivity()).getDbOpenHelper().getCursor());
  87 +
  88 + if( mProgressDialog != null){
  89 + mProgressDialog.dismiss();
  90 + }
104 91 }
105 92 });
106 93 }
... ...
app/src/main/java/net/devfac/userstory/MainActivity.java
1 1 package net.devfac.userstory;
2 2  
  3 +import android.app.ProgressDialog;
3 4 import android.content.Context;
4 5 import android.content.Intent;
5 6 import android.content.res.TypedArray;
... ... @@ -47,6 +48,8 @@ public class MainActivity extends AppCompatActivity
47 48 private AppBarLayout mAppBarMain;
48 49 private CoordinatorLayout mCoordinateMain;
49 50  
  51 + private ProgressDialog mProgressDialog;
  52 +
50 53 FloatingActionButton mFab;
51 54  
52 55 @Override
... ... @@ -101,6 +104,7 @@ public class MainActivity extends AppCompatActivity
101 104 @Override
102 105 public void onPageSelected(int position) {
103 106 if (mViewPagerAdapter.getPosition(Constants.FRAGMENT_TITLE_BOOK_SHELF) == position) {
  107 + StateContext.getInstance(MainActivity.this).processEvent(Action.REQ_SYNC, null);
104 108 } else if (mViewPagerAdapter.getPosition(Constants.FRAGMENT_TITLE_ADD_BOOK) == position) {
105 109 //Expand toolbar
106 110 CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mAppBarMain.getLayoutParams();
... ... @@ -315,15 +319,38 @@ public class MainActivity extends AppCompatActivity
315 319 @Override
316 320 public void onEntry(Class stateClass, Object input) {
317 321 if( stateClass.equals(StateLoginRequested.class)){
318   - Toast.makeText(this, "로그인 중입니다...", Toast.LENGTH_LONG).show();
  322 +// Toast.makeText(this, "로그인 중입니다...", Toast.LENGTH_LONG).show();
  323 + runOnUiThread(new Runnable() {
  324 + @Override
  325 + public void run() {
  326 + mProgressDialog = ProgressDialog.show(MainActivity.this, "로그인중입니다", "잠시만 기다려 주세요...");
  327 + }
  328 + });
  329 +
319 330 }
320 331 else if( stateClass.equals(StateLogoutRequested.class)){
321   - Toast.makeText(this, "로그아웃 중입니다...", Toast.LENGTH_LONG).show();
  332 +// Toast.makeText(this, "로그아웃 중입니다...", Toast.LENGTH_LONG).show();
  333 + runOnUiThread(new Runnable() {
  334 + @Override
  335 + public void run() {
  336 + mProgressDialog = ProgressDialog.show(MainActivity.this, "로그아웃중입니다", "잠시만 기다려 주세요...");
  337 + }
  338 + });
  339 +
322 340 }
323 341 }
324 342  
325 343 @Override
326 344 public void onExit(Class stateClass, Object output, StateContext.STATE_RESULT stateResult) {
  345 + runOnUiThread(new Runnable() {
  346 + @Override
  347 + public void run() {
  348 + if( mProgressDialog != null){
  349 + mProgressDialog.dismiss();
  350 + }
  351 + }
  352 + });
  353 +
327 354 if( stateClass.equals(StateLoginRequested.class)){
328 355 switch(stateResult){
329 356 case LOGIN_SUCCESS:
... ...