Commit f61b2bc089a66c3a35a347fb8cdfe38be82936d8
1 parent
7d590ef1
Exists in
master
refactoring
Showing
4 changed files
with
65 additions
and
22 deletions
Show diff stats
app/src/main/java/com/monitorabrasil/monitoralegislativo/actions/ActionsCreator.java
... | ... | @@ -4,6 +4,7 @@ import com.monitorabrasil.monitoralegislativo.dispatcher.Dispatcher; |
4 | 4 | import com.parse.LogInCallback; |
5 | 5 | import com.parse.LogOutCallback; |
6 | 6 | import com.parse.ParseUser; |
7 | +import com.parse.SignUpCallback; | |
7 | 8 | |
8 | 9 | /** |
9 | 10 | * Created by 89741803168 on 13/08/2015. |
... | ... | @@ -70,6 +71,31 @@ public class ActionsCreator { |
70 | 71 | } |
71 | 72 | |
72 | 73 | |
74 | + public void cadastrar(String nome, String password, String email) { | |
75 | + ParseUser user = new ParseUser(); | |
76 | + user.setUsername(email); | |
77 | + user.setPassword(password); | |
78 | + user.setEmail(email); | |
79 | + user.put("nome", nome); | |
73 | 80 | |
74 | 81 | |
82 | + user.signUpInBackground(new SignUpCallback() { | |
83 | + @Override | |
84 | + public void done(com.parse.ParseException e) { | |
85 | + if (e == null) { | |
86 | + dispatcher.dispatch( | |
87 | + UserActions.USER_CADASTRO, | |
88 | + UserActions.KEY_TEXT, "sucesso" | |
89 | + ); | |
90 | + } else { | |
91 | + dispatcher.dispatch( | |
92 | + UserActions.USER_CADASTRO, | |
93 | + UserActions.KEY_TEXT, "erro" | |
94 | + ); | |
95 | + } | |
96 | + } | |
97 | + | |
98 | + | |
99 | + }); | |
100 | + } | |
75 | 101 | } | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/actions/UserActions.java
... | ... | @@ -6,7 +6,10 @@ package com.monitorabrasil.monitoralegislativo.actions; |
6 | 6 | public interface UserActions { |
7 | 7 | String USER_LOGAR = "user-logar"; |
8 | 8 | String USER_LOGOUT = "user-logout"; |
9 | + String USER_CADASTRO = "user_cadastro"; | |
9 | 10 | |
10 | 11 | String KEY_TEXT = "key-text"; |
11 | 12 | String KEY_ID = "key-id"; |
13 | + | |
14 | + | |
12 | 15 | } | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/stores/UserStore.java
... | ... | @@ -12,6 +12,11 @@ public class UserStore extends Store{ |
12 | 12 | |
13 | 13 | private static UserStore instance; |
14 | 14 | private String status; |
15 | + private String evento; | |
16 | + | |
17 | + | |
18 | + | |
19 | + | |
15 | 20 | |
16 | 21 | protected UserStore(Dispatcher dispatcher) { |
17 | 22 | super(dispatcher); |
... | ... | @@ -29,14 +34,19 @@ public class UserStore extends Store{ |
29 | 34 | @Subscribe |
30 | 35 | public void onAction(Action action) { |
31 | 36 | status = "erro"; |
37 | + this.evento = action.getType(); | |
38 | + this.status = ((String) action.getData().get(UserActions.KEY_TEXT)); | |
39 | + | |
32 | 40 | switch (action.getType()) { |
33 | 41 | case UserActions.USER_LOGAR: |
34 | - status = ((String) action.getData().get(UserActions.KEY_TEXT)); | |
35 | 42 | emitStoreChange(); |
36 | 43 | break; |
37 | 44 | case UserActions.USER_LOGOUT: |
38 | 45 | emitStoreChange(); |
39 | 46 | break; |
47 | + case UserActions.USER_CADASTRO: | |
48 | + emitStoreChange(); | |
49 | + break; | |
40 | 50 | } |
41 | 51 | } |
42 | 52 | |
... | ... | @@ -44,10 +54,20 @@ public class UserStore extends Store{ |
44 | 54 | StoreChangeEvent changeEvent() { |
45 | 55 | UserStoreChangeEvent mUserStoreChangeEvent = new UserStoreChangeEvent(); |
46 | 56 | mUserStoreChangeEvent.status = this.status; |
57 | + mUserStoreChangeEvent.evento = this.evento; | |
47 | 58 | return mUserStoreChangeEvent; |
48 | 59 | } |
49 | 60 | |
50 | 61 | public class UserStoreChangeEvent implements StoreChangeEvent { |
51 | - String status; | |
62 | + private String status; | |
63 | + private String evento; | |
64 | + | |
65 | + public String getEvento() { | |
66 | + return evento; | |
67 | + } | |
68 | + | |
69 | + public String getStatus() { | |
70 | + return status; | |
71 | + } | |
52 | 72 | } |
53 | 73 | } | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/Login2Activity.java
... | ... | @@ -24,6 +24,7 @@ import android.widget.TextView; |
24 | 24 | |
25 | 25 | import com.monitorabrasil.monitoralegislativo.R; |
26 | 26 | import com.monitorabrasil.monitoralegislativo.actions.ActionsCreator; |
27 | +import com.monitorabrasil.monitoralegislativo.actions.UserActions; | |
27 | 28 | import com.monitorabrasil.monitoralegislativo.application.MyApp; |
28 | 29 | import com.monitorabrasil.monitoralegislativo.dispatcher.Dispatcher; |
29 | 30 | import com.monitorabrasil.monitoralegislativo.stores.UserStore; |
... | ... | @@ -255,6 +256,15 @@ public class Login2Activity extends AppCompatActivity { |
255 | 256 | |
256 | 257 | @Subscribe |
257 | 258 | public void onTodoStoreChange(UserStore.UserStoreChangeEvent event) { |
259 | + switch (event.getEvento()){ | |
260 | + case UserActions.USER_CADASTRO: | |
261 | + if(event.getStatus().equals("erro")){ | |
262 | + showProgress(false, mLoginFormView); | |
263 | + Snackbar.make(mLoginFormView, "Houve um erro ao fazer seu cadastro ", Snackbar.LENGTH_LONG) | |
264 | + .setAction("Action", null).show(); | |
265 | + } | |
266 | + break; | |
267 | + } | |
258 | 268 | updateUI(); |
259 | 269 | } |
260 | 270 | |
... | ... | @@ -362,29 +372,13 @@ public class Login2Activity extends AppCompatActivity { |
362 | 372 | } else { |
363 | 373 | // Show a progress spinner, and kick off a background task to |
364 | 374 | // perform the user login attempt. |
365 | - showProgress(true,null); | |
375 | + showProgress(true, null); | |
376 | + | |
377 | + | |
378 | + actionsCreator.cadastrar(nome, password, email); | |
366 | 379 | |
367 | - ParseUser user = new ParseUser(); | |
368 | - user.setUsername(email); | |
369 | - user.setPassword(password); | |
370 | - user.setEmail(email); | |
371 | - user.put("nome", mNome.getText().toString()); | |
372 | - | |
373 | - | |
374 | - user.signUpInBackground(new SignUpCallback() { | |
375 | - @Override | |
376 | - public void done(com.parse.ParseException e) { | |
377 | - if (e == null) { | |
378 | - montaFormLogout(); | |
379 | - } else { | |
380 | - showProgress(false, mLoginFormView); | |
381 | - Snackbar.make(mLoginFormView, "Houve um erro ao fazer seu cadastro ", Snackbar.LENGTH_LONG) | |
382 | - .setAction("Action", null).show(); | |
383 | - } | |
384 | - } | |
385 | 380 | |
386 | 381 | |
387 | - }); | |
388 | 382 | |
389 | 383 | } |
390 | 384 | } | ... | ... |