Commit 8071edb3bd024589708c0d1dc4c3712ceb8f253a
Committed by
geraldo morais
1 parent
eb442e62
Exists in
master
Refactoring de políticos e projetos
Showing
15 changed files
with
548 additions
and
238 deletions
Show diff stats
app/src/main/java/com/monitorabrasil/participacidadao/actions/ActionsCreator.java
1 | package com.monitorabrasil.participacidadao.actions; | 1 | package com.monitorabrasil.participacidadao.actions; |
2 | 2 | ||
3 | +import com.crashlytics.android.answers.Answers; | ||
4 | +import com.crashlytics.android.answers.ContentViewEvent; | ||
3 | import com.monitorabrasil.participacidadao.dispatcher.Dispatcher; | 5 | import com.monitorabrasil.participacidadao.dispatcher.Dispatcher; |
6 | +import com.parse.FindCallback; | ||
4 | import com.parse.LogInCallback; | 7 | import com.parse.LogInCallback; |
5 | import com.parse.LogOutCallback; | 8 | import com.parse.LogOutCallback; |
6 | import com.parse.ParseFile; | 9 | import com.parse.ParseFile; |
10 | +import com.parse.ParseObject; | ||
11 | +import com.parse.ParseQuery; | ||
7 | import com.parse.ParseUser; | 12 | import com.parse.ParseUser; |
8 | import com.parse.ProgressCallback; | 13 | import com.parse.ProgressCallback; |
9 | import com.parse.SignUpCallback; | 14 | import com.parse.SignUpCallback; |
10 | 15 | ||
16 | +import java.util.List; | ||
17 | + | ||
11 | /** | 18 | /** |
12 | * Created by 89741803168 on 13/08/2015. | 19 | * Created by 89741803168 on 13/08/2015. |
13 | */ | 20 | */ |
@@ -26,15 +33,82 @@ public class ActionsCreator { | @@ -26,15 +33,82 @@ public class ActionsCreator { | ||
26 | return instance; | 33 | return instance; |
27 | } | 34 | } |
28 | 35 | ||
36 | + /***** | ||
37 | + * | ||
38 | + */ | ||
39 | + | ||
40 | + public void getAllProjetos(String idPolitico, String tipoProjeto) { | ||
41 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("Projeto"); | ||
42 | + query.addDescendingOrder("createdAt"); | ||
43 | + | ||
44 | + if(idPolitico!= null){ | ||
45 | + query.whereEqualTo("politico", idPolitico); | ||
46 | + } | ||
47 | + | ||
48 | + if(tipoProjeto != null){ | ||
49 | + query.whereEqualTo("classificacao", tipoProjeto); | ||
50 | + Answers.getInstance().logContentView(new ContentViewEvent() | ||
51 | + .putContentName("ListaProjetosFragment") | ||
52 | + .putContentType("Fragment") | ||
53 | + .putCustomAttribute("tipoProjeto", tipoProjeto)); | ||
54 | + } | ||
55 | + query.findInBackground(new FindCallback<ParseObject>() { | ||
56 | + @Override | ||
57 | + public void done(List<ParseObject> list, com.parse.ParseException e) { | ||
58 | + if (e == null) { | ||
59 | + dispatcher.dispatch( | ||
60 | + ProjetoActions.PROJETO_GET_ALL, | ||
61 | + ProjetoActions.KEY_TEXT, list | ||
62 | + ); | ||
63 | + } else { | ||
64 | + dispatcher.dispatch( | ||
65 | + ProjetoActions.PROJETO_GET_ALL, | ||
66 | + ProjetoActions.KEY_TEXT, "erro" | ||
67 | + ); | ||
68 | + } | ||
69 | + } | ||
70 | + | ||
71 | + | ||
72 | + }); | ||
73 | + } | ||
74 | + | ||
75 | + /* | ||
76 | + # ACTIONS DE POLITICOS | ||
77 | + **/ | ||
78 | + | ||
79 | + public void getAllPoliticos(){ | ||
80 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("Politico"); | ||
81 | + query.addAscendingOrder("nome"); | ||
82 | + query.findInBackground(new FindCallback<ParseObject>() { | ||
83 | + @Override | ||
84 | + public void done(List<ParseObject> list, com.parse.ParseException e) { | ||
85 | + if (e == null) { | ||
86 | + dispatcher.dispatch( | ||
87 | + PoliticoActions.POLITICO_GET_ALL, | ||
88 | + PoliticoActions.KEY_TEXT, list | ||
89 | + ); | ||
90 | + } else { | ||
91 | + dispatcher.dispatch( | ||
92 | + PoliticoActions.POLITICO_GET_ALL, | ||
93 | + PoliticoActions.KEY_TEXT, "erro" | ||
94 | + ); | ||
95 | + } | ||
96 | + } | ||
97 | + | ||
98 | + | ||
99 | + }); | ||
100 | + } | ||
101 | + | ||
102 | + /* | ||
103 | + # ACTIONS DE USUARIOS | ||
104 | + **/ | ||
105 | + | ||
29 | /** | 106 | /** |
30 | * Actions do usuario - logar | 107 | * Actions do usuario - logar |
31 | * @param inputUsuario | 108 | * @param inputUsuario |
32 | * @param inputSenha | 109 | * @param inputSenha |
33 | */ | 110 | */ |
34 | - | ||
35 | public void logar(String inputUsuario, String inputSenha){ | 111 | public void logar(String inputUsuario, String inputSenha){ |
36 | - | ||
37 | - | ||
38 | ParseUser.logInInBackground(inputUsuario, inputSenha, new LogInCallback() { | 112 | ParseUser.logInInBackground(inputUsuario, inputSenha, new LogInCallback() { |
39 | 113 | ||
40 | @Override | 114 | @Override |
@@ -72,7 +146,13 @@ public class ActionsCreator { | @@ -72,7 +146,13 @@ public class ActionsCreator { | ||
72 | }); | 146 | }); |
73 | } | 147 | } |
74 | 148 | ||
75 | - | 149 | + /** |
150 | + * Actions do usuario - cadastrar | ||
151 | + * @param nome | ||
152 | + * @param password | ||
153 | + * @param email | ||
154 | + * @param mParseFile | ||
155 | + */ | ||
76 | public void cadastrar(final String nome, final String password, final String email, final ParseFile mParseFile) { | 156 | public void cadastrar(final String nome, final String password, final String email, final ParseFile mParseFile) { |
77 | mParseFile.saveInBackground(new ProgressCallback() { | 157 | mParseFile.saveInBackground(new ProgressCallback() { |
78 | @Override | 158 | @Override |
@@ -107,4 +187,6 @@ public class ActionsCreator { | @@ -107,4 +187,6 @@ public class ActionsCreator { | ||
107 | 187 | ||
108 | 188 | ||
109 | } | 189 | } |
190 | + | ||
191 | + | ||
110 | } | 192 | } |
app/src/main/java/com/monitorabrasil/participacidadao/actions/PoliticoActions.java
0 → 100644
@@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
1 | +package com.monitorabrasil.participacidadao.actions; | ||
2 | + | ||
3 | +/** | ||
4 | + * Created by Geraldo on 13/08/2015. | ||
5 | + */ | ||
6 | +public interface PoliticoActions { | ||
7 | + String POLITICO_AVALIAR = "politico_avaliar"; | ||
8 | + String POLITICO_COMENTAR = "politico_comentar"; | ||
9 | + String POLITICO_GET_INFOS = "politico_get_infos"; | ||
10 | + String POLITICO_GET_GAST0S = "politico_get_gastos"; | ||
11 | + String POLITICO_GET_PROJETOS = "politico_get_projetos"; | ||
12 | + String POLITICO_GET_ALL = "politico_get_all"; | ||
13 | + | ||
14 | + String KEY_TEXT = "key-text"; | ||
15 | + String KEY_ID = "key-id"; | ||
16 | + | ||
17 | + | ||
18 | +} |
app/src/main/java/com/monitorabrasil/participacidadao/actions/ProjetoActions.java
0 → 100644
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +package com.monitorabrasil.participacidadao.actions; | ||
2 | + | ||
3 | +/** | ||
4 | + * Created by Geraldo on 13/08/2015. | ||
5 | + */ | ||
6 | +public interface ProjetoActions { | ||
7 | + String PROJETO_COMENTAR = "projeto_comentar"; | ||
8 | + String PROJETO_GET_ALL = "projeto_get_all"; | ||
9 | + | ||
10 | + String KEY_TEXT = "key-text"; | ||
11 | + String KEY_ID = "key-id"; | ||
12 | + | ||
13 | + | ||
14 | +} |
app/src/main/java/com/monitorabrasil/participacidadao/stores/PoliticoStore.java
0 → 100644
@@ -0,0 +1,75 @@ | @@ -0,0 +1,75 @@ | ||
1 | +package com.monitorabrasil.participacidadao.stores; | ||
2 | + | ||
3 | +import com.monitorabrasil.participacidadao.actions.Action; | ||
4 | +import com.monitorabrasil.participacidadao.actions.PoliticoActions; | ||
5 | +import com.monitorabrasil.participacidadao.dispatcher.Dispatcher; | ||
6 | +import com.parse.ParseObject; | ||
7 | +import com.squareup.otto.Subscribe; | ||
8 | + | ||
9 | +import java.util.ArrayList; | ||
10 | +import java.util.List; | ||
11 | + | ||
12 | +/** | ||
13 | + * Created by Geraldo on 13/08/2015. | ||
14 | + */ | ||
15 | +public class PoliticoStore extends Store{ | ||
16 | + | ||
17 | + private static PoliticoStore instance; | ||
18 | + private String status; | ||
19 | + private String evento; | ||
20 | + private List<ParseObject> politicos; | ||
21 | + | ||
22 | + protected PoliticoStore(Dispatcher dispatcher) { | ||
23 | + super(dispatcher); | ||
24 | + politicos = new ArrayList<>(); | ||
25 | + } | ||
26 | + | ||
27 | + public static PoliticoStore get(Dispatcher dispatcher) { | ||
28 | + if (instance == null) { | ||
29 | + instance = new PoliticoStore(dispatcher); | ||
30 | + } | ||
31 | + return instance; | ||
32 | + } | ||
33 | + | ||
34 | + public List<ParseObject> getPoliticos(){ | ||
35 | + return politicos; | ||
36 | + } | ||
37 | + | ||
38 | + | ||
39 | + @Override | ||
40 | + @Subscribe | ||
41 | + public void onAction(Action action) { | ||
42 | + status = "erro"; | ||
43 | + this.evento = action.getType(); | ||
44 | + | ||
45 | + switch (action.getType()) { | ||
46 | + case PoliticoActions.POLITICO_GET_ALL: | ||
47 | + politicos = ((List<ParseObject>) action.getData().get(PoliticoActions.KEY_TEXT)); | ||
48 | + emitStoreChange(); | ||
49 | + break; | ||
50 | + | ||
51 | + } | ||
52 | + } | ||
53 | + | ||
54 | + @Override | ||
55 | + StoreChangeEvent changeEvent() { | ||
56 | + UserStoreChangeEvent mUserStoreChangeEvent = new UserStoreChangeEvent(); | ||
57 | + mUserStoreChangeEvent.status = this.status; | ||
58 | + mUserStoreChangeEvent.evento = this.evento; | ||
59 | + return mUserStoreChangeEvent; | ||
60 | + } | ||
61 | + | ||
62 | + | ||
63 | + public class UserStoreChangeEvent implements StoreChangeEvent { | ||
64 | + private String status; | ||
65 | + private String evento; | ||
66 | + | ||
67 | + public String getEvento() { | ||
68 | + return evento; | ||
69 | + } | ||
70 | + | ||
71 | + public String getStatus() { | ||
72 | + return status; | ||
73 | + } | ||
74 | + } | ||
75 | +} |
app/src/main/java/com/monitorabrasil/participacidadao/stores/ProjetoStore.java
0 → 100644
@@ -0,0 +1,75 @@ | @@ -0,0 +1,75 @@ | ||
1 | +package com.monitorabrasil.participacidadao.stores; | ||
2 | + | ||
3 | +import com.monitorabrasil.participacidadao.actions.Action; | ||
4 | +import com.monitorabrasil.participacidadao.actions.PoliticoActions; | ||
5 | +import com.monitorabrasil.participacidadao.dispatcher.Dispatcher; | ||
6 | +import com.parse.ParseObject; | ||
7 | +import com.squareup.otto.Subscribe; | ||
8 | + | ||
9 | +import java.util.ArrayList; | ||
10 | +import java.util.List; | ||
11 | + | ||
12 | +/** | ||
13 | + * Created by Geraldo on 13/08/2015. | ||
14 | + */ | ||
15 | +public class ProjetoStore extends Store{ | ||
16 | + | ||
17 | + private static ProjetoStore instance; | ||
18 | + private String status; | ||
19 | + private String evento; | ||
20 | + private List<ParseObject> projetos; | ||
21 | + | ||
22 | + protected ProjetoStore(Dispatcher dispatcher) { | ||
23 | + super(dispatcher); | ||
24 | + projetos = new ArrayList<>(); | ||
25 | + } | ||
26 | + | ||
27 | + public static ProjetoStore get(Dispatcher dispatcher) { | ||
28 | + if (instance == null) { | ||
29 | + instance = new ProjetoStore(dispatcher); | ||
30 | + } | ||
31 | + return instance; | ||
32 | + } | ||
33 | + | ||
34 | + public List<ParseObject> getProjetos(){ | ||
35 | + return projetos; | ||
36 | + } | ||
37 | + | ||
38 | + | ||
39 | + @Override | ||
40 | + @Subscribe | ||
41 | + public void onAction(Action action) { | ||
42 | + status = "erro"; | ||
43 | + this.evento = action.getType(); | ||
44 | + | ||
45 | + switch (action.getType()) { | ||
46 | + case PoliticoActions.POLITICO_GET_ALL: | ||
47 | + projetos = ((List<ParseObject>) action.getData().get(PoliticoActions.KEY_TEXT)); | ||
48 | + emitStoreChange(); | ||
49 | + break; | ||
50 | + | ||
51 | + } | ||
52 | + } | ||
53 | + | ||
54 | + @Override | ||
55 | + StoreChangeEvent changeEvent() { | ||
56 | + UserStoreChangeEvent mUserStoreChangeEvent = new UserStoreChangeEvent(); | ||
57 | + mUserStoreChangeEvent.status = this.status; | ||
58 | + mUserStoreChangeEvent.evento = this.evento; | ||
59 | + return mUserStoreChangeEvent; | ||
60 | + } | ||
61 | + | ||
62 | + | ||
63 | + public class UserStoreChangeEvent implements StoreChangeEvent { | ||
64 | + private String status; | ||
65 | + private String evento; | ||
66 | + | ||
67 | + public String getEvento() { | ||
68 | + return evento; | ||
69 | + } | ||
70 | + | ||
71 | + public String getStatus() { | ||
72 | + return status; | ||
73 | + } | ||
74 | + } | ||
75 | +} |
app/src/main/java/com/monitorabrasil/participacidadao/stores/UserStore.java
@@ -14,8 +14,13 @@ public class UserStore extends Store{ | @@ -14,8 +14,13 @@ public class UserStore extends Store{ | ||
14 | private String status; | 14 | private String status; |
15 | private String evento; | 15 | private String evento; |
16 | 16 | ||
17 | + public String getStatus(){ | ||
18 | + return status; | ||
19 | + } | ||
17 | 20 | ||
18 | - | 21 | + public String getEvento(){ |
22 | + return evento; | ||
23 | + } | ||
19 | 24 | ||
20 | 25 | ||
21 | protected UserStore(Dispatcher dispatcher) { | 26 | protected UserStore(Dispatcher dispatcher) { |
@@ -53,21 +58,10 @@ public class UserStore extends Store{ | @@ -53,21 +58,10 @@ public class UserStore extends Store{ | ||
53 | @Override | 58 | @Override |
54 | StoreChangeEvent changeEvent() { | 59 | StoreChangeEvent changeEvent() { |
55 | UserStoreChangeEvent mUserStoreChangeEvent = new UserStoreChangeEvent(); | 60 | UserStoreChangeEvent mUserStoreChangeEvent = new UserStoreChangeEvent(); |
56 | - mUserStoreChangeEvent.status = this.status; | ||
57 | - mUserStoreChangeEvent.evento = this.evento; | ||
58 | return mUserStoreChangeEvent; | 61 | return mUserStoreChangeEvent; |
59 | } | 62 | } |
60 | 63 | ||
61 | public class UserStoreChangeEvent implements StoreChangeEvent { | 64 | public class UserStoreChangeEvent implements StoreChangeEvent { |
62 | - private String status; | ||
63 | - private String evento; | ||
64 | 65 | ||
65 | - public String getEvento() { | ||
66 | - return evento; | ||
67 | - } | ||
68 | - | ||
69 | - public String getStatus() { | ||
70 | - return status; | ||
71 | - } | ||
72 | } | 66 | } |
73 | } | 67 | } |
app/src/main/java/com/monitorabrasil/participacidadao/view/LoginActivity.java
@@ -358,16 +358,16 @@ public class LoginActivity extends AppCompatActivity { | @@ -358,16 +358,16 @@ public class LoginActivity extends AppCompatActivity { | ||
358 | */ | 358 | */ |
359 | @Subscribe | 359 | @Subscribe |
360 | public void onTodoStoreChange(UserStore.UserStoreChangeEvent event) { | 360 | public void onTodoStoreChange(UserStore.UserStoreChangeEvent event) { |
361 | - switch (event.getEvento()) { | 361 | + switch (userStore.getEvento()) { |
362 | case UserActions.USER_CADASTRO: | 362 | case UserActions.USER_CADASTRO: |
363 | - if(event.getStatus().equals("erro")){ | 363 | + if(userStore.getStatus().equals("erro")){ |
364 | showProgress(false); | 364 | showProgress(false); |
365 | - Snackbar.make(form, "Houve um erro ao fazer seu cadastro ", Snackbar.LENGTH_LONG) | 365 | + Snackbar.make(form, "Houve um erro ao fazer seu cadastro", Snackbar.LENGTH_LONG) |
366 | .setAction("Action", null).show(); | 366 | .setAction("Action", null).show(); |
367 | } | 367 | } |
368 | break; | 368 | break; |
369 | case UserActions.USER_LOGAR: | 369 | case UserActions.USER_LOGAR: |
370 | - if(event.getStatus().equals("erro")){ | 370 | + if(userStore.getStatus().equals("erro")){ |
371 | showProgress(false); | 371 | showProgress(false); |
372 | Snackbar.make(form, "Houve um erro ao fazer o login", Snackbar.LENGTH_LONG) | 372 | Snackbar.make(form, "Houve um erro ao fazer o login", Snackbar.LENGTH_LONG) |
373 | .setAction("Action", null).show(); | 373 | .setAction("Action", null).show(); |
app/src/main/java/com/monitorabrasil/participacidadao/view/PoliticosActivity.java
@@ -23,9 +23,9 @@ public class PoliticosActivity extends AppCompatActivity { | @@ -23,9 +23,9 @@ public class PoliticosActivity extends AppCompatActivity { | ||
23 | .putContentName("PoliticosActivity") | 23 | .putContentName("PoliticosActivity") |
24 | .putContentType("Activity")); | 24 | .putContentType("Activity")); |
25 | 25 | ||
26 | - ListaPoliticoFragment frag = (ListaPoliticoFragment) getSupportFragmentManager().findFragmentByTag("listaPoliticoFrag"); | 26 | + ListaPoliticoFragment frag = (ListaPoliticoFragment) getSupportFragmentManager().findFragmentByTag("listaPoliticoFrag"); |
27 | if(frag == null) { | 27 | if(frag == null) { |
28 | - frag = new ListaPoliticoFragment(); | 28 | + frag = ListaPoliticoFragment.newInstance(); |
29 | FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); | 29 | FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); |
30 | ft.replace(R.id.rl_fragment_container, frag, "listaPoliticoFrag"); | 30 | ft.replace(R.id.rl_fragment_container, frag, "listaPoliticoFrag"); |
31 | ft.commit(); | 31 | ft.commit(); |
@@ -34,7 +34,7 @@ public class PoliticosActivity extends AppCompatActivity { | @@ -34,7 +34,7 @@ public class PoliticosActivity extends AppCompatActivity { | ||
34 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | 34 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); |
35 | setSupportActionBar(toolbar); | 35 | setSupportActionBar(toolbar); |
36 | 36 | ||
37 | - // toolbar.setNavigationIcon(R.drawable.ic_good); | 37 | + // toolbar.setNavigationIcon(R.drawable.ic_good); |
38 | toolbar.setTitle("Vereadores"); | 38 | toolbar.setTitle("Vereadores"); |
39 | toolbar.setSubtitle("Ouro Branco - MG"); | 39 | toolbar.setSubtitle("Ouro Branco - MG"); |
40 | 40 | ||
@@ -42,7 +42,7 @@ public class PoliticosActivity extends AppCompatActivity { | @@ -42,7 +42,7 @@ public class PoliticosActivity extends AppCompatActivity { | ||
42 | toolbar.setSubtitleTextColor(getResources().getColor(R.color.md_white_1000)); | 42 | toolbar.setSubtitleTextColor(getResources().getColor(R.color.md_white_1000)); |
43 | setSupportActionBar(toolbar); | 43 | setSupportActionBar(toolbar); |
44 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); | 44 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
45 | - // toolbar.setLogo(R.drawable.ic_launcher); | 45 | + // toolbar.setLogo(R.drawable.ic_launcher); |
46 | } | 46 | } |
47 | 47 | ||
48 | 48 |
app/src/main/java/com/monitorabrasil/participacidadao/view/adapters/PoliticoAdapter.java
0 → 100644
@@ -0,0 +1,94 @@ | @@ -0,0 +1,94 @@ | ||
1 | +package com.monitorabrasil.participacidadao.view.adapters; | ||
2 | + | ||
3 | +import android.support.v7.widget.RecyclerView; | ||
4 | +import android.view.LayoutInflater; | ||
5 | +import android.view.View; | ||
6 | +import android.view.ViewGroup; | ||
7 | +import android.widget.ImageView; | ||
8 | +import android.widget.RatingBar; | ||
9 | +import android.widget.TextView; | ||
10 | + | ||
11 | +import com.monitorabrasil.participacidadao.R; | ||
12 | +import com.monitorabrasil.participacidadao.actions.ActionsCreator; | ||
13 | +import com.monitorabrasil.participacidadao.application.MyApp; | ||
14 | +import com.monitorabrasil.participacidadao.view.interfaces.RecyclerViewOnClickListenerHack; | ||
15 | +import com.parse.ParseObject; | ||
16 | + | ||
17 | +import java.util.ArrayList; | ||
18 | +import java.util.List; | ||
19 | + | ||
20 | +/** | ||
21 | + * Created by geraugu on 6/7/15. | ||
22 | + */ | ||
23 | +public class PoliticoAdapter extends RecyclerView.Adapter<PoliticoAdapter.ViewHolder> { | ||
24 | + | ||
25 | + private static ActionsCreator actionsCreator; | ||
26 | + private List<ParseObject> politicos; | ||
27 | + private RecyclerViewOnClickListenerHack mRecyclerViewOnClickListenerHack; | ||
28 | + | ||
29 | + public PoliticoAdapter(ActionsCreator actionsCreator) { | ||
30 | + politicos = new ArrayList<>(); | ||
31 | + PoliticoAdapter.actionsCreator = actionsCreator; | ||
32 | + } | ||
33 | + | ||
34 | + @Override | ||
35 | + public PoliticoAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { | ||
36 | + // create a new view | ||
37 | + View v = LayoutInflater.from(viewGroup.getContext()) | ||
38 | + .inflate(R.layout.item_politico, viewGroup, false); | ||
39 | + // set the view's size, margins, paddings and layout parameter | ||
40 | + ViewHolder vh = new ViewHolder(v); | ||
41 | + return vh; | ||
42 | + } | ||
43 | + public void setRecyclerViewOnClickListenerHack(RecyclerViewOnClickListenerHack r){ | ||
44 | + mRecyclerViewOnClickListenerHack = r; | ||
45 | + } | ||
46 | + | ||
47 | + @Override | ||
48 | + public void onBindViewHolder(PoliticoAdapter.ViewHolder viewHolder, int i) { | ||
49 | + ParseObject vereador = politicos.get(i); | ||
50 | + vereador.pinInBackground(); | ||
51 | + viewHolder.mTextView.setText(vereador.get("nome").toString()); | ||
52 | + viewHolder.txtPartido.setText(vereador.get("partido").toString()); | ||
53 | + viewHolder.rb.setRating((float)vereador.getDouble("avaliacao")); | ||
54 | + MyApp.getInstance().getmImagemLoader().displayImage(MyApp.URL_FOTO + vereador.get("cpf") + ".jpg", viewHolder.foto); | ||
55 | + | ||
56 | + } | ||
57 | + | ||
58 | + @Override | ||
59 | + public int getItemCount() { | ||
60 | + return politicos.size(); | ||
61 | + } | ||
62 | + | ||
63 | + public void setItems(List<ParseObject> politicos) { | ||
64 | + this.politicos = politicos; | ||
65 | + notifyDataSetChanged(); | ||
66 | + } | ||
67 | + | ||
68 | + // Provide a reference to the views for each data item | ||
69 | + // Complex data items may need more than one view per item, and | ||
70 | + // you provide access to all the views for a data item in a view holder | ||
71 | + public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ | ||
72 | + // each data item is just a string in this case | ||
73 | + public TextView mTextView; | ||
74 | + public TextView txtPartido; | ||
75 | + public ImageView foto; | ||
76 | + public RatingBar rb; | ||
77 | + public ViewHolder(View v) { | ||
78 | + super(v); | ||
79 | + mTextView = (TextView) v.findViewById(R.id.txtNome); | ||
80 | + txtPartido = (TextView) v.findViewById(R.id.txtPartido); | ||
81 | + foto = (ImageView)v.findViewById(R.id.foto); | ||
82 | + rb = (RatingBar)v.findViewById(R.id.ratingBar); | ||
83 | + | ||
84 | + itemView.setOnClickListener(this); | ||
85 | + } | ||
86 | + | ||
87 | + @Override | ||
88 | + public void onClick(View v) { | ||
89 | + if(mRecyclerViewOnClickListenerHack != null){ | ||
90 | + mRecyclerViewOnClickListenerHack.onClickListener(v, getPosition()); | ||
91 | + } | ||
92 | + } | ||
93 | + } | ||
94 | +} |
app/src/main/java/com/monitorabrasil/participacidadao/view/adapters/ProjetoAdapter.java
@@ -16,6 +16,7 @@ import android.widget.Button; | @@ -16,6 +16,7 @@ import android.widget.Button; | ||
16 | import android.widget.TextView; | 16 | import android.widget.TextView; |
17 | 17 | ||
18 | import com.google.gson.Gson; | 18 | import com.google.gson.Gson; |
19 | +import com.monitorabrasil.participacidadao.actions.ActionsCreator; | ||
19 | import com.monitorabrasil.participacidadao.view.ComentarioActivity; | 20 | import com.monitorabrasil.participacidadao.view.ComentarioActivity; |
20 | import com.monitorabrasil.participacidadao.R; | 21 | import com.monitorabrasil.participacidadao.R; |
21 | import com.monitorabrasil.participacidadao.application.MyApp; | 22 | import com.monitorabrasil.participacidadao.application.MyApp; |
@@ -27,6 +28,7 @@ import com.parse.ParseQuery; | @@ -27,6 +28,7 @@ import com.parse.ParseQuery; | ||
27 | import com.parse.ParseUser; | 28 | import com.parse.ParseUser; |
28 | import com.parse.SaveCallback; | 29 | import com.parse.SaveCallback; |
29 | 30 | ||
31 | +import java.util.ArrayList; | ||
30 | import java.util.List; | 32 | import java.util.List; |
31 | 33 | ||
32 | /** | 34 | /** |
@@ -34,52 +36,20 @@ import java.util.List; | @@ -34,52 +36,20 @@ import java.util.List; | ||
34 | */ | 36 | */ |
35 | public class ProjetoAdapter extends RecyclerView.Adapter<ProjetoAdapter.ViewHolder> { | 37 | public class ProjetoAdapter extends RecyclerView.Adapter<ProjetoAdapter.ViewHolder> { |
36 | 38 | ||
37 | - private List<ParseObject> mDataset; | 39 | + private static ActionsCreator actionsCreator; |
40 | + private List<ParseObject> projetos; | ||
38 | private RecyclerViewOnClickListenerHack mRecyclerViewOnClickListenerHack; | 41 | private RecyclerViewOnClickListenerHack mRecyclerViewOnClickListenerHack; |
39 | private FragmentActivity mActivity; | 42 | private FragmentActivity mActivity; |
40 | 43 | ||
41 | - public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ | ||
42 | - // each data item is just a string in this case | ||
43 | - public ParseObject projetoVotado; | ||
44 | - public TextView classificacao; | ||
45 | - public TextView data; | ||
46 | - public TextView autor; | ||
47 | - public TextView descricao; | ||
48 | - public TextView numApoio; | ||
49 | - public TextView numNaoApoio; | ||
50 | - public TextView numero; | ||
51 | - public Button btnConcordo; | ||
52 | - public Button btnDiscordo; | ||
53 | - public Button btnComentar; | ||
54 | - public String voto; | ||
55 | - public ParseObject projeto; | ||
56 | - | ||
57 | - public ViewHolder(View v) { | ||
58 | - super(v); | ||
59 | - classificacao = (TextView) v.findViewById(R.id.classificacao); | ||
60 | - data = (TextView) v.findViewById(R.id.data); | ||
61 | - autor = (TextView) v.findViewById(R.id.autor); | ||
62 | - numApoio = (TextView) v.findViewById(R.id.txtNumApoio); | ||
63 | - numNaoApoio = (TextView) v.findViewById(R.id.txtNumNaoApoio); | ||
64 | - descricao = (TextView) v.findViewById(R.id.descricao); | ||
65 | - btnConcordo = (Button) v.findViewById(R.id.btnConcordo); | ||
66 | - btnDiscordo = (Button) v.findViewById(R.id.btnDiscordo); | ||
67 | - btnComentar = (Button) v.findViewById(R.id.btnComentar); | ||
68 | - numero = (TextView) v.findViewById(R.id.numero); | 44 | + public ProjetoAdapter(ActionsCreator actionsCreator) { |
45 | + projetos = new ArrayList<>(); | ||
46 | + ProjetoAdapter.actionsCreator = actionsCreator; | ||
47 | + } | ||
69 | 48 | ||
70 | - itemView.setOnClickListener(this); | ||
71 | - } | ||
72 | 49 | ||
73 | - @Override | ||
74 | - public void onClick(View v) { | ||
75 | - if(mRecyclerViewOnClickListenerHack != null){ | ||
76 | - mRecyclerViewOnClickListenerHack.onClickListener(v, getPosition()); | ||
77 | - } | ||
78 | - } | ||
79 | - } | ||
80 | 50 | ||
81 | public ProjetoAdapter(List<ParseObject> myDataset, FragmentActivity activity) { | 51 | public ProjetoAdapter(List<ParseObject> myDataset, FragmentActivity activity) { |
82 | - mDataset = myDataset; | 52 | + projetos = myDataset; |
83 | mActivity = activity; | 53 | mActivity = activity; |
84 | } | 54 | } |
85 | 55 | ||
@@ -106,7 +76,7 @@ public class ProjetoAdapter extends RecyclerView.Adapter<ProjetoAdapter.ViewHold | @@ -106,7 +76,7 @@ public class ProjetoAdapter extends RecyclerView.Adapter<ProjetoAdapter.ViewHold | ||
106 | viewHolder.btnDiscordo.setEnabled(true); | 76 | viewHolder.btnDiscordo.setEnabled(true); |
107 | viewHolder.btnConcordo.setEnabled(true); | 77 | viewHolder.btnConcordo.setEnabled(true); |
108 | viewHolder.voto = "sem_voto"; | 78 | viewHolder.voto = "sem_voto"; |
109 | - final ParseObject projeto = mDataset.get(i); | 79 | + final ParseObject projeto = projetos.get(i); |
110 | viewHolder.projeto = projeto; | 80 | viewHolder.projeto = projeto; |
111 | //verifica se ja votou | 81 | //verifica se ja votou |
112 | ParseQuery<ParseObject> query = ParseQuery.getQuery("Voto"); | 82 | ParseQuery<ParseObject> query = ParseQuery.getQuery("Voto"); |
@@ -286,6 +256,51 @@ public class ProjetoAdapter extends RecyclerView.Adapter<ProjetoAdapter.ViewHold | @@ -286,6 +256,51 @@ public class ProjetoAdapter extends RecyclerView.Adapter<ProjetoAdapter.ViewHold | ||
286 | 256 | ||
287 | @Override | 257 | @Override |
288 | public int getItemCount() { | 258 | public int getItemCount() { |
289 | - return mDataset.size(); | 259 | + return projetos.size(); |
260 | + } | ||
261 | + | ||
262 | + public void setItems(List<ParseObject> projetos) { | ||
263 | + this.projetos = projetos; | ||
264 | + notifyDataSetChanged(); | ||
265 | + } | ||
266 | + | ||
267 | + public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ | ||
268 | + // each data item is just a string in this case | ||
269 | + public ParseObject projetoVotado; | ||
270 | + public TextView classificacao; | ||
271 | + public TextView data; | ||
272 | + public TextView autor; | ||
273 | + public TextView descricao; | ||
274 | + public TextView numApoio; | ||
275 | + public TextView numNaoApoio; | ||
276 | + public TextView numero; | ||
277 | + public Button btnConcordo; | ||
278 | + public Button btnDiscordo; | ||
279 | + public Button btnComentar; | ||
280 | + public String voto; | ||
281 | + public ParseObject projeto; | ||
282 | + | ||
283 | + public ViewHolder(View v) { | ||
284 | + super(v); | ||
285 | + classificacao = (TextView) v.findViewById(R.id.classificacao); | ||
286 | + data = (TextView) v.findViewById(R.id.data); | ||
287 | + autor = (TextView) v.findViewById(R.id.autor); | ||
288 | + numApoio = (TextView) v.findViewById(R.id.txtNumApoio); | ||
289 | + numNaoApoio = (TextView) v.findViewById(R.id.txtNumNaoApoio); | ||
290 | + descricao = (TextView) v.findViewById(R.id.descricao); | ||
291 | + btnConcordo = (Button) v.findViewById(R.id.btnConcordo); | ||
292 | + btnDiscordo = (Button) v.findViewById(R.id.btnDiscordo); | ||
293 | + btnComentar = (Button) v.findViewById(R.id.btnComentar); | ||
294 | + numero = (TextView) v.findViewById(R.id.numero); | ||
295 | + | ||
296 | + itemView.setOnClickListener(this); | ||
297 | + } | ||
298 | + | ||
299 | + @Override | ||
300 | + public void onClick(View v) { | ||
301 | + if(mRecyclerViewOnClickListenerHack != null){ | ||
302 | + mRecyclerViewOnClickListenerHack.onClickListener(v, getPosition()); | ||
303 | + } | ||
304 | + } | ||
290 | } | 305 | } |
291 | } | 306 | } |
app/src/main/java/com/monitorabrasil/participacidadao/view/adapters/VereadorAdapter.java
@@ -1,85 +0,0 @@ | @@ -1,85 +0,0 @@ | ||
1 | -package com.monitorabrasil.participacidadao.view.adapters; | ||
2 | - | ||
3 | -import android.support.v7.widget.RecyclerView; | ||
4 | -import android.view.LayoutInflater; | ||
5 | -import android.view.View; | ||
6 | -import android.view.ViewGroup; | ||
7 | -import android.widget.ImageView; | ||
8 | -import android.widget.RatingBar; | ||
9 | -import android.widget.TextView; | ||
10 | - | ||
11 | -import com.monitorabrasil.participacidadao.R; | ||
12 | -import com.monitorabrasil.participacidadao.application.MyApp; | ||
13 | -import com.monitorabrasil.participacidadao.view.interfaces.RecyclerViewOnClickListenerHack; | ||
14 | -import com.parse.ParseObject; | ||
15 | - | ||
16 | -import java.util.List; | ||
17 | - | ||
18 | -/** | ||
19 | - * Created by geraugu on 6/7/15. | ||
20 | - */ | ||
21 | -public class VereadorAdapter extends RecyclerView.Adapter<VereadorAdapter.ViewHolder> { | ||
22 | - | ||
23 | - private List<ParseObject> mDataset; | ||
24 | - private RecyclerViewOnClickListenerHack mRecyclerViewOnClickListenerHack; | ||
25 | - | ||
26 | - // Provide a reference to the views for each data item | ||
27 | - // Complex data items may need more than one view per item, and | ||
28 | - // you provide access to all the views for a data item in a view holder | ||
29 | - public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ | ||
30 | - // each data item is just a string in this case | ||
31 | - public TextView mTextView; | ||
32 | - public TextView txtPartido; | ||
33 | - public ImageView foto; | ||
34 | - public RatingBar rb; | ||
35 | - public ViewHolder(View v) { | ||
36 | - super(v); | ||
37 | - mTextView = (TextView) v.findViewById(R.id.txtNome); | ||
38 | - txtPartido = (TextView) v.findViewById(R.id.txtPartido); | ||
39 | - foto = (ImageView)v.findViewById(R.id.foto); | ||
40 | - rb = (RatingBar)v.findViewById(R.id.ratingBar); | ||
41 | - | ||
42 | - itemView.setOnClickListener(this); | ||
43 | - } | ||
44 | - | ||
45 | - @Override | ||
46 | - public void onClick(View v) { | ||
47 | - if(mRecyclerViewOnClickListenerHack != null){ | ||
48 | - mRecyclerViewOnClickListenerHack.onClickListener(v, getPosition()); | ||
49 | - } | ||
50 | - } | ||
51 | - } | ||
52 | - | ||
53 | - public VereadorAdapter(List<ParseObject> myDataset) { | ||
54 | - mDataset = myDataset; | ||
55 | - } | ||
56 | - | ||
57 | - @Override | ||
58 | - public VereadorAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { | ||
59 | - // create a new view | ||
60 | - View v = LayoutInflater.from(viewGroup.getContext()) | ||
61 | - .inflate(R.layout.item_politico, viewGroup, false); | ||
62 | - // set the view's size, margins, paddings and layout parameter | ||
63 | - ViewHolder vh = new ViewHolder(v); | ||
64 | - return vh; | ||
65 | - } | ||
66 | - public void setRecyclerViewOnClickListenerHack(RecyclerViewOnClickListenerHack r){ | ||
67 | - mRecyclerViewOnClickListenerHack = r; | ||
68 | - } | ||
69 | - | ||
70 | - @Override | ||
71 | - public void onBindViewHolder(VereadorAdapter.ViewHolder viewHolder, int i) { | ||
72 | - ParseObject vereador = mDataset.get(i); | ||
73 | - vereador.pinInBackground(); | ||
74 | - viewHolder.mTextView.setText(vereador.get("nome").toString()); | ||
75 | - viewHolder.txtPartido.setText(vereador.get("partido").toString()); | ||
76 | - viewHolder.rb.setRating((float)vereador.getDouble("avaliacao")); | ||
77 | - MyApp.getInstance().getmImagemLoader().displayImage(MyApp.URL_FOTO + vereador.get("cpf") + ".jpg", viewHolder.foto); | ||
78 | - | ||
79 | - } | ||
80 | - | ||
81 | - @Override | ||
82 | - public int getItemCount() { | ||
83 | - return mDataset.size(); | ||
84 | - } | ||
85 | -} |
app/src/main/java/com/monitorabrasil/participacidadao/view/fragments/HomeFragment.java
@@ -25,7 +25,7 @@ import com.github.mikephil.charting.data.BarEntry; | @@ -25,7 +25,7 @@ import com.github.mikephil.charting.data.BarEntry; | ||
25 | import com.github.mikephil.charting.utils.ValueFormatter; | 25 | import com.github.mikephil.charting.utils.ValueFormatter; |
26 | import com.monitorabrasil.participacidadao.view.PoliticoFichaActivity; | 26 | import com.monitorabrasil.participacidadao.view.PoliticoFichaActivity; |
27 | import com.monitorabrasil.participacidadao.R; | 27 | import com.monitorabrasil.participacidadao.R; |
28 | -import com.monitorabrasil.participacidadao.view.adapters.VereadorAdapter; | 28 | +import com.monitorabrasil.participacidadao.view.adapters.PoliticoAdapter; |
29 | import com.monitorabrasil.participacidadao.application.MyApp; | 29 | import com.monitorabrasil.participacidadao.application.MyApp; |
30 | import com.monitorabrasil.participacidadao.model.Grafico; | 30 | import com.monitorabrasil.participacidadao.model.Grafico; |
31 | import com.monitorabrasil.participacidadao.view.interfaces.RecyclerViewOnClickListenerHack; | 31 | import com.monitorabrasil.participacidadao.view.interfaces.RecyclerViewOnClickListenerHack; |
@@ -53,7 +53,7 @@ public class HomeFragment extends Fragment implements RecyclerViewOnClickListene | @@ -53,7 +53,7 @@ public class HomeFragment extends Fragment implements RecyclerViewOnClickListene | ||
53 | 53 | ||
54 | private OnFragmentInteractionListener mListener; | 54 | private OnFragmentInteractionListener mListener; |
55 | private RecyclerView mRecyclerView; | 55 | private RecyclerView mRecyclerView; |
56 | - private VereadorAdapter mAdapter; | 56 | + private PoliticoAdapter mAdapter; |
57 | private List<ParseObject> ob; | 57 | private List<ParseObject> ob; |
58 | private HashMap<String,Float> valorTotal = new HashMap<String,Float>(); | 58 | private HashMap<String,Float> valorTotal = new HashMap<String,Float>(); |
59 | ArrayList<String> xVals = new ArrayList<String>(); | 59 | ArrayList<String> xVals = new ArrayList<String>(); |
@@ -310,7 +310,7 @@ public class HomeFragment extends Fragment implements RecyclerViewOnClickListene | @@ -310,7 +310,7 @@ public class HomeFragment extends Fragment implements RecyclerViewOnClickListene | ||
310 | } | 310 | } |
311 | 311 | ||
312 | public void carregaList(List<ParseObject> list){ | 312 | public void carregaList(List<ParseObject> list){ |
313 | - mAdapter = new VereadorAdapter(list); | 313 | + mAdapter = new PoliticoAdapter(list); |
314 | mAdapter.setRecyclerViewOnClickListenerHack(this); | 314 | mAdapter.setRecyclerViewOnClickListenerHack(this); |
315 | mRecyclerView.setAdapter(mAdapter); | 315 | mRecyclerView.setAdapter(mAdapter); |
316 | //pb.setVisibility(View.INVISIBLE); | 316 | //pb.setVisibility(View.INVISIBLE); |
app/src/main/java/com/monitorabrasil/participacidadao/view/fragments/ListaPoliticoFragment.java
@@ -5,21 +5,21 @@ import android.os.Bundle; | @@ -5,21 +5,21 @@ import android.os.Bundle; | ||
5 | import android.support.v4.app.Fragment; | 5 | import android.support.v4.app.Fragment; |
6 | import android.support.v7.widget.LinearLayoutManager; | 6 | import android.support.v7.widget.LinearLayoutManager; |
7 | import android.support.v7.widget.RecyclerView; | 7 | import android.support.v7.widget.RecyclerView; |
8 | -import android.util.Log; | ||
9 | import android.view.LayoutInflater; | 8 | import android.view.LayoutInflater; |
10 | import android.view.View; | 9 | import android.view.View; |
11 | import android.view.ViewGroup; | 10 | import android.view.ViewGroup; |
12 | import android.widget.ProgressBar; | 11 | import android.widget.ProgressBar; |
13 | 12 | ||
14 | -import com.monitorabrasil.participacidadao.view.PoliticoFichaActivity; | ||
15 | import com.monitorabrasil.participacidadao.R; | 13 | import com.monitorabrasil.participacidadao.R; |
16 | -import com.monitorabrasil.participacidadao.view.adapters.VereadorAdapter; | 14 | +import com.monitorabrasil.participacidadao.actions.ActionsCreator; |
15 | +import com.monitorabrasil.participacidadao.actions.PoliticoActions; | ||
16 | +import com.monitorabrasil.participacidadao.dispatcher.Dispatcher; | ||
17 | +import com.monitorabrasil.participacidadao.stores.PoliticoStore; | ||
18 | +import com.monitorabrasil.participacidadao.view.PoliticoFichaActivity; | ||
19 | +import com.monitorabrasil.participacidadao.view.adapters.PoliticoAdapter; | ||
17 | import com.monitorabrasil.participacidadao.view.interfaces.RecyclerViewOnClickListenerHack; | 20 | import com.monitorabrasil.participacidadao.view.interfaces.RecyclerViewOnClickListenerHack; |
18 | -import com.parse.FindCallback; | ||
19 | -import com.parse.ParseObject; | ||
20 | -import com.parse.ParseQuery; | ||
21 | - | ||
22 | -import java.util.List; | 21 | +import com.squareup.otto.Bus; |
22 | +import com.squareup.otto.Subscribe; | ||
23 | 23 | ||
24 | /** | 24 | /** |
25 | * Created by geraugu on 6/10/15. | 25 | * Created by geraugu on 6/10/15. |
@@ -27,23 +27,47 @@ import java.util.List; | @@ -27,23 +27,47 @@ import java.util.List; | ||
27 | public class ListaPoliticoFragment extends Fragment implements RecyclerViewOnClickListenerHack { | 27 | public class ListaPoliticoFragment extends Fragment implements RecyclerViewOnClickListenerHack { |
28 | 28 | ||
29 | private RecyclerView mRecyclerView; | 29 | private RecyclerView mRecyclerView; |
30 | - private VereadorAdapter mAdapter; | ||
31 | - private List<ParseObject> ob; | 30 | + private PoliticoAdapter mAdapter; |
32 | private ProgressBar pb; | 31 | private ProgressBar pb; |
33 | 32 | ||
33 | + private Dispatcher dispatcher; | ||
34 | + private ActionsCreator actionsCreator; | ||
35 | + private PoliticoStore politicoStore; | ||
36 | + | ||
37 | + public static ListaPoliticoFragment newInstance() { | ||
38 | + ListaPoliticoFragment fragment = new ListaPoliticoFragment(); | ||
39 | + return fragment; | ||
40 | + } | ||
41 | + | ||
42 | + public ListaPoliticoFragment(){} | ||
43 | + | ||
34 | @Override | 44 | @Override |
35 | public View onCreateView(LayoutInflater inflater, | 45 | public View onCreateView(LayoutInflater inflater, |
36 | ViewGroup container, | 46 | ViewGroup container, |
37 | Bundle savedInstanceState) { | 47 | Bundle savedInstanceState) { |
38 | View view = inflater.inflate(R.layout.fragment_list_politico, container, false); | 48 | View view = inflater.inflate(R.layout.fragment_list_politico, container, false); |
49 | + initDependencies(); | ||
50 | + setupView(view); | ||
51 | + pb.setVisibility(View.VISIBLE); | ||
52 | + actionsCreator.getAllPoliticos(); | ||
53 | + return view; | ||
39 | 54 | ||
40 | - pb = (ProgressBar) view.findViewById(R.id.progressBar); | 55 | + } |
56 | + | ||
57 | + private void initDependencies() { | ||
58 | + dispatcher = Dispatcher.get(new Bus()); | ||
59 | + actionsCreator = ActionsCreator.get(dispatcher); | ||
60 | + politicoStore = PoliticoStore.get(dispatcher); | ||
61 | + } | ||
41 | 62 | ||
42 | 63 | ||
64 | + private void setupView(View view) { | ||
65 | + | ||
66 | + pb = (ProgressBar) view.findViewById(R.id.progressBar); | ||
67 | + | ||
43 | //tableview | 68 | //tableview |
44 | mRecyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view); | 69 | mRecyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view); |
45 | 70 | ||
46 | - | ||
47 | // use this setting to improve performance if you know that changes | 71 | // use this setting to improve performance if you know that changes |
48 | // in content do not change the layout size of the RecyclerView | 72 | // in content do not change the layout size of the RecyclerView |
49 | mRecyclerView.setHasFixedSize(true); | 73 | mRecyclerView.setHasFixedSize(true); |
@@ -51,41 +75,33 @@ public class ListaPoliticoFragment extends Fragment implements RecyclerViewOnCli | @@ -51,41 +75,33 @@ public class ListaPoliticoFragment extends Fragment implements RecyclerViewOnCli | ||
51 | LinearLayoutManager llm = new LinearLayoutManager(getActivity()); | 75 | LinearLayoutManager llm = new LinearLayoutManager(getActivity()); |
52 | llm.setOrientation(LinearLayoutManager.VERTICAL); | 76 | llm.setOrientation(LinearLayoutManager.VERTICAL); |
53 | mRecyclerView.setLayoutManager(llm); | 77 | mRecyclerView.setLayoutManager(llm); |
54 | - | ||
55 | - buscaVereadores(); | ||
56 | - | ||
57 | - return view; | 78 | + mAdapter = new PoliticoAdapter(actionsCreator); |
79 | + mRecyclerView.setAdapter(mAdapter); | ||
80 | + mAdapter.setRecyclerViewOnClickListenerHack(this); | ||
58 | 81 | ||
59 | } | 82 | } |
60 | 83 | ||
61 | - //busca objetos | ||
62 | - public void buscaVereadores(){ | ||
63 | - ParseQuery<ParseObject> query = ParseQuery.getQuery("Politico"); | ||
64 | - query.addAscendingOrder("nome"); | ||
65 | - //query.whereEqualTo("playerName", "Dan Stemkoski"); | ||
66 | - query.findInBackground(new FindCallback<ParseObject>() { | ||
67 | - @Override | ||
68 | - public void done(List<ParseObject> list, com.parse.ParseException e) { | ||
69 | - if (e == null) { | ||
70 | - ob = list; | ||
71 | - carregaList(list); | ||
72 | - } else { | ||
73 | - Log.d("score", "Error: " + e.getMessage()); | ||
74 | - } | ||
75 | - } | ||
76 | - | ||
77 | 84 | ||
78 | - }); | ||
79 | - } | ||
80 | - | ||
81 | - public void carregaList(List<ParseObject> list){ | ||
82 | - mAdapter = new VereadorAdapter(list); | ||
83 | - mAdapter.setRecyclerViewOnClickListenerHack(this); | ||
84 | - mRecyclerView.setAdapter(mAdapter); | 85 | + private void updateUI() { |
86 | + mAdapter.setItems(politicoStore.getPoliticos()); | ||
85 | pb.setVisibility(View.INVISIBLE); | 87 | pb.setVisibility(View.INVISIBLE); |
86 | } | 88 | } |
87 | 89 | ||
90 | + /** | ||
91 | + * Atualiza a UI depois de uma action | ||
92 | + * @param event | ||
93 | + */ | ||
94 | + @Subscribe | ||
95 | + public void onTodoStoreChange(PoliticoStore.UserStoreChangeEvent event) { | ||
96 | + switch (event.getEvento()) { | ||
97 | + case PoliticoActions.POLITICO_GET_ALL: | ||
98 | + if(event.getStatus().equals("erro")){ | ||
88 | 99 | ||
100 | + } | ||
101 | + break; | ||
102 | + } | ||
103 | + updateUI(); | ||
104 | + } | ||
89 | 105 | ||
90 | @Override | 106 | @Override |
91 | public void onClickListener(View view, int position) { | 107 | public void onClickListener(View view, int position) { |
@@ -105,7 +121,21 @@ public class ListaPoliticoFragment extends Fragment implements RecyclerViewOnCli | @@ -105,7 +121,21 @@ public class ListaPoliticoFragment extends Fragment implements RecyclerViewOnCli | ||
105 | // ft.addToBackStack(null); | 121 | // ft.addToBackStack(null); |
106 | // ft.commit(); | 122 | // ft.commit(); |
107 | Intent intent = new Intent(getActivity(),PoliticoFichaActivity.class); | 123 | Intent intent = new Intent(getActivity(),PoliticoFichaActivity.class); |
108 | - intent.putExtra("politico", ob.get(position).getObjectId()); | 124 | + intent.putExtra("politico", politicoStore.getPoliticos().get(position).getObjectId()); |
109 | startActivity(intent); | 125 | startActivity(intent); |
110 | } | 126 | } |
127 | + | ||
128 | + @Override | ||
129 | + public void onResume() { | ||
130 | + super.onResume(); | ||
131 | + dispatcher.register(this); | ||
132 | + dispatcher.register(politicoStore); | ||
133 | + } | ||
134 | + | ||
135 | + @Override | ||
136 | + public void onPause() { | ||
137 | + super.onPause(); | ||
138 | + dispatcher.unregister(this); | ||
139 | + dispatcher.unregister(politicoStore); | ||
140 | + } | ||
111 | } | 141 | } |
app/src/main/java/com/monitorabrasil/participacidadao/view/fragments/ListaProjetosFragment.java
@@ -5,20 +5,22 @@ import android.os.Bundle; | @@ -5,20 +5,22 @@ import android.os.Bundle; | ||
5 | import android.support.v4.app.Fragment; | 5 | import android.support.v4.app.Fragment; |
6 | import android.support.v7.widget.LinearLayoutManager; | 6 | import android.support.v7.widget.LinearLayoutManager; |
7 | import android.support.v7.widget.RecyclerView; | 7 | import android.support.v7.widget.RecyclerView; |
8 | -import android.util.Log; | ||
9 | import android.view.LayoutInflater; | 8 | import android.view.LayoutInflater; |
10 | import android.view.View; | 9 | import android.view.View; |
11 | import android.view.ViewGroup; | 10 | import android.view.ViewGroup; |
12 | import android.widget.ProgressBar; | 11 | import android.widget.ProgressBar; |
13 | 12 | ||
14 | -import com.crashlytics.android.answers.Answers; | ||
15 | -import com.crashlytics.android.answers.ContentViewEvent; | ||
16 | import com.monitorabrasil.participacidadao.R; | 13 | import com.monitorabrasil.participacidadao.R; |
14 | +import com.monitorabrasil.participacidadao.actions.ActionsCreator; | ||
15 | +import com.monitorabrasil.participacidadao.dispatcher.Dispatcher; | ||
16 | +import com.monitorabrasil.participacidadao.stores.PoliticoStore; | ||
17 | +import com.monitorabrasil.participacidadao.stores.ProjetoStore; | ||
17 | import com.monitorabrasil.participacidadao.view.adapters.ProjetoAdapter; | 18 | import com.monitorabrasil.participacidadao.view.adapters.ProjetoAdapter; |
18 | import com.monitorabrasil.participacidadao.view.interfaces.RecyclerViewOnClickListenerHack; | 19 | import com.monitorabrasil.participacidadao.view.interfaces.RecyclerViewOnClickListenerHack; |
19 | -import com.parse.FindCallback; | ||
20 | import com.parse.ParseObject; | 20 | import com.parse.ParseObject; |
21 | import com.parse.ParseQuery; | 21 | import com.parse.ParseQuery; |
22 | +import com.squareup.otto.Bus; | ||
23 | +import com.squareup.otto.Subscribe; | ||
22 | 24 | ||
23 | import java.util.List; | 25 | import java.util.List; |
24 | 26 | ||
@@ -36,6 +38,10 @@ public class ListaProjetosFragment extends Fragment implements RecyclerViewOnCli | @@ -36,6 +38,10 @@ public class ListaProjetosFragment extends Fragment implements RecyclerViewOnCli | ||
36 | private String tipoProjeto; | 38 | private String tipoProjeto; |
37 | private String idPolitico; | 39 | private String idPolitico; |
38 | 40 | ||
41 | + private Dispatcher dispatcher; | ||
42 | + private ActionsCreator actionsCreator; | ||
43 | + private ProjetoStore projetoStore; | ||
44 | + | ||
39 | 45 | ||
40 | public static ListaProjetosFragment newInstance(String tipoProjeto, String idPolitico) { | 46 | public static ListaProjetosFragment newInstance(String tipoProjeto, String idPolitico) { |
41 | ListaProjetosFragment fragment = new ListaProjetosFragment(); | 47 | ListaProjetosFragment fragment = new ListaProjetosFragment(); |
@@ -66,6 +72,25 @@ public class ListaProjetosFragment extends Fragment implements RecyclerViewOnCli | @@ -66,6 +72,25 @@ public class ListaProjetosFragment extends Fragment implements RecyclerViewOnCli | ||
66 | View view = inflater.inflate(R.layout.fragment_lista_projetos, container, false); | 72 | View view = inflater.inflate(R.layout.fragment_lista_projetos, container, false); |
67 | // View view = inflater.inflate(R.layout.fragment_escolha_tipo_projeto, container, false); | 73 | // View view = inflater.inflate(R.layout.fragment_escolha_tipo_projeto, container, false); |
68 | 74 | ||
75 | + initDependencies(); | ||
76 | + setupView(view); | ||
77 | + | ||
78 | + actionsCreator.getAllProjetos(idPolitico, tipoProjeto); | ||
79 | + | ||
80 | + return view; | ||
81 | + } | ||
82 | + | ||
83 | + private void initDependencies() { | ||
84 | + dispatcher = Dispatcher.get(new Bus()); | ||
85 | + actionsCreator = ActionsCreator.get(dispatcher); | ||
86 | + projetoStore = ProjetoStore.get(dispatcher); | ||
87 | + } | ||
88 | + | ||
89 | + | ||
90 | + private void setupView(View view) { | ||
91 | + pb.setVisibility(View.VISIBLE); | ||
92 | + | ||
93 | + | ||
69 | pb = (ProgressBar) view.findViewById(R.id.progressBar); | 94 | pb = (ProgressBar) view.findViewById(R.id.progressBar); |
70 | 95 | ||
71 | 96 | ||
@@ -79,43 +104,14 @@ public class ListaProjetosFragment extends Fragment implements RecyclerViewOnCli | @@ -79,43 +104,14 @@ public class ListaProjetosFragment extends Fragment implements RecyclerViewOnCli | ||
79 | LinearLayoutManager llm = new LinearLayoutManager(getActivity()); | 104 | LinearLayoutManager llm = new LinearLayoutManager(getActivity()); |
80 | llm.setOrientation(LinearLayoutManager.VERTICAL); | 105 | llm.setOrientation(LinearLayoutManager.VERTICAL); |
81 | mRecyclerView.setLayoutManager(llm); | 106 | mRecyclerView.setLayoutManager(llm); |
82 | - | ||
83 | - buscaProjetos(); | ||
84 | - return view; | 107 | + mAdapter = new ProjetoAdapter(actionsCreator); |
108 | + mRecyclerView.setAdapter(mAdapter); | ||
109 | + mAdapter.setRecyclerViewOnClickListenerHack(this); | ||
85 | } | 110 | } |
86 | 111 | ||
87 | - public void buscaProjetos(){ | ||
88 | - ParseQuery<ParseObject> query = ParseQuery.getQuery("Projeto"); | ||
89 | - query.addDescendingOrder("createdAt"); | ||
90 | - | ||
91 | - if(idPolitico!= null){ | ||
92 | - | ||
93 | - query.whereEqualTo("politico", buscaPolitico(idPolitico)); | ||
94 | - | ||
95 | - } | ||
96 | - | ||
97 | - if(tipoProjeto != null){ | ||
98 | - query.whereEqualTo("classificacao", tipoProjeto); | ||
99 | - Answers.getInstance().logContentView(new ContentViewEvent() | ||
100 | - .putContentName("ListaProjetosFragment") | ||
101 | - .putContentType("Fragment") | ||
102 | - .putCustomAttribute("tipoProjeto", tipoProjeto)); | ||
103 | - } | ||
104 | - | ||
105 | - | ||
106 | - query.findInBackground(new FindCallback<ParseObject>() { | ||
107 | - @Override | ||
108 | - public void done(List<ParseObject> list, com.parse.ParseException e) { | ||
109 | - if (e == null) { | ||
110 | - ob = list; | ||
111 | - carregaList(list); | ||
112 | - } else { | ||
113 | - Log.d("score", "Error: " + e.getMessage()); | ||
114 | - } | ||
115 | - } | ||
116 | - | ||
117 | - | ||
118 | - }); | 112 | + private void updateUI() { |
113 | + mAdapter.setItems(projetoStore.getProjetos()); | ||
114 | + pb.setVisibility(View.INVISIBLE); | ||
119 | } | 115 | } |
120 | 116 | ||
121 | private ParseObject buscaPolitico(String id) { | 117 | private ParseObject buscaPolitico(String id) { |
@@ -130,11 +126,13 @@ public class ListaProjetosFragment extends Fragment implements RecyclerViewOnCli | @@ -130,11 +126,13 @@ public class ListaProjetosFragment extends Fragment implements RecyclerViewOnCli | ||
130 | return null; | 126 | return null; |
131 | } | 127 | } |
132 | 128 | ||
133 | - public void carregaList(List<ParseObject> list){ | ||
134 | - mAdapter = new ProjetoAdapter(list,getActivity()); | ||
135 | - mAdapter.setRecyclerViewOnClickListenerHack(this); | ||
136 | - mRecyclerView.setAdapter(mAdapter); | ||
137 | - pb.setVisibility(View.INVISIBLE); | 129 | + /** |
130 | + * Atualiza a UI depois de uma action | ||
131 | + * @param event | ||
132 | + */ | ||
133 | + @Subscribe | ||
134 | + public void onTodoStoreChange(PoliticoStore.UserStoreChangeEvent event) { | ||
135 | + updateUI(); | ||
138 | } | 136 | } |
139 | 137 | ||
140 | @Override | 138 | @Override |
app/src/main/res/layout/activity_login.xml
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | android:background="@color/grey" | 6 | android:background="@color/grey" |
7 | android:orientation="vertical" | 7 | android:orientation="vertical" |
8 | tools:context="com.monitorabrasil.participacidadao.view.LoginActivity" | 8 | tools:context="com.monitorabrasil.participacidadao.view.LoginActivity" |
9 | - android:paddingTop="8dp"> | 9 | + android:paddingTop="0dp"> |
10 | 10 | ||
11 | <android.support.v7.widget.Toolbar | 11 | <android.support.v7.widget.Toolbar |
12 | android:id="@+id/toolbar" | 12 | android:id="@+id/toolbar" |