Commit edd522d61757451745233c4b9b0368266794457f
1 parent
ebaf4f5a
Exists in
master
fazendo refactoring - arquitetura flux
Showing
70 changed files
with
4909 additions
and
4014 deletions
Show diff stats
app/app.iml
| ... | ... | @@ -71,12 +71,12 @@ |
| 71 | 71 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" /> |
| 72 | 72 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" /> |
| 73 | 73 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" /> |
| 74 | - <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/jars" /> | |
| 75 | - <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/cardview-v7/22.2.0/jars" /> | |
| 76 | - <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/22.2.0/jars" /> | |
| 74 | + <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.1/jars" /> | |
| 75 | + <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/cardview-v7/22.2.1/jars" /> | |
| 76 | + <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/22.2.1/jars" /> | |
| 77 | 77 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/mediarouter-v7/22.0.0/jars" /> |
| 78 | - <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/22.2.0/jars" /> | |
| 79 | - <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.0/jars" /> | |
| 78 | + <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/22.2.1/jars" /> | |
| 79 | + <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.1/jars" /> | |
| 80 | 80 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.crashlytics.sdk.android/answers/1.3.0/jars" /> |
| 81 | 81 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.crashlytics.sdk.android/beta/1.1.3/jars" /> |
| 82 | 82 | <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.crashlytics.sdk.android/crashlytics-core/2.3.3/jars" /> |
| ... | ... | @@ -126,26 +126,27 @@ |
| 126 | 126 | <orderEntry type="library" exported="" name="gson-2.3.1" level="project" /> |
| 127 | 127 | <orderEntry type="library" exported="" name="play-services-cast-7.5.0" level="project" /> |
| 128 | 128 | <orderEntry type="library" exported="" name="mediarouter-v7-22.0.0" level="project" /> |
| 129 | - <orderEntry type="library" exported="" name="recyclerview-v7-22.2.0" level="project" /> | |
| 130 | 129 | <orderEntry type="library" exported="" name="play-services-drive-7.5.0" level="project" /> |
| 131 | - <orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" /> | |
| 130 | + <orderEntry type="library" exported="" name="recyclerview-v7-22.2.1" level="project" /> | |
| 131 | + <orderEntry type="library" exported="" name="support-annotations-22.2.1" level="project" /> | |
| 132 | 132 | <orderEntry type="library" exported="" name="play-services-analytics-7.5.0" level="project" /> |
| 133 | 133 | <orderEntry type="library" exported="" name="play-services-panorama-7.5.0" level="project" /> |
| 134 | 134 | <orderEntry type="library" exported="" name="materialdrawer-3.0.6" level="project" /> |
| 135 | - <orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" /> | |
| 136 | 135 | <orderEntry type="library" exported="" name="play-services-appindexing-7.5.0" level="project" /> |
| 136 | + <orderEntry type="library" exported="" name="appcompat-v7-22.2.1" level="project" /> | |
| 137 | 137 | <orderEntry type="library" exported="" name="play-services-location-7.5.0" level="project" /> |
| 138 | 138 | <orderEntry type="library" exported="" name="Parse-1.9.2" level="project" /> |
| 139 | 139 | <orderEntry type="library" exported="" name="play-services-ads-7.5.0" level="project" /> |
| 140 | 140 | <orderEntry type="library" exported="" name="play-services-safetynet-7.5.0" level="project" /> |
| 141 | 141 | <orderEntry type="library" exported="" name="play-services-base-7.5.0" level="project" /> |
| 142 | 142 | <orderEntry type="library" exported="" name="play-services-7.5.0" level="project" /> |
| 143 | + <orderEntry type="library" exported="" name="otto-1.3.8" level="project" /> | |
| 144 | + <orderEntry type="library" exported="" name="bolts-android-1.2.1" level="project" /> | |
| 143 | 145 | <orderEntry type="library" exported="" name="play-services-gcm-7.5.0" level="project" /> |
| 144 | - <orderEntry type="library" exported="" name="bolts-android-1.2.0" level="project" /> | |
| 145 | 146 | <orderEntry type="library" exported="" name="play-services-appinvite-7.5.0" level="project" /> |
| 147 | + <orderEntry type="library" exported="" name="support-v4-22.2.1" level="project" /> | |
| 146 | 148 | <orderEntry type="library" exported="" name="iconics-1.0.2" level="project" /> |
| 147 | 149 | <orderEntry type="library" exported="" name="beta-1.1.3" level="project" /> |
| 148 | - <orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" /> | |
| 149 | 150 | <orderEntry type="library" exported="" name="fabric-1.3.5" level="project" /> |
| 150 | 151 | <orderEntry type="library" exported="" name="universal-image-loader-1.9.3" level="project" /> |
| 151 | 152 | <orderEntry type="library" exported="" name="crashlytics-core-2.3.3" level="project" /> |
| ... | ... | @@ -156,11 +157,11 @@ |
| 156 | 157 | <orderEntry type="library" exported="" name="play-services-wearable-7.5.0" level="project" /> |
| 157 | 158 | <orderEntry type="library" exported="" name="play-services-appstate-7.5.0" level="project" /> |
| 158 | 159 | <orderEntry type="library" exported="" name="play-services-games-7.5.0" level="project" /> |
| 160 | + <orderEntry type="library" exported="" name="MPAndroidChart-v2.1.3" level="project" /> | |
| 159 | 161 | <orderEntry type="library" exported="" name="play-services-identity-7.5.0" level="project" /> |
| 160 | - <orderEntry type="library" exported="" name="MPAndroidChart-v2.1.0" level="project" /> | |
| 161 | - <orderEntry type="library" exported="" name="design-22.2.0" level="project" /> | |
| 162 | + <orderEntry type="library" exported="" name="design-22.2.1" level="project" /> | |
| 163 | + <orderEntry type="library" exported="" name="cardview-v7-22.2.1" level="project" /> | |
| 162 | 164 | <orderEntry type="library" exported="" name="play-services-maps-7.5.0" level="project" /> |
| 163 | 165 | <orderEntry type="library" exported="" name="answers-1.3.0" level="project" /> |
| 164 | - <orderEntry type="library" exported="" name="cardview-v7-22.2.0" level="project" /> | |
| 165 | 166 | </component> |
| 166 | 167 | </module> |
| 167 | 168 | \ No newline at end of file | ... | ... |
app/build.gradle
| ... | ... | @@ -50,9 +50,10 @@ dependencies { |
| 50 | 50 | compile 'com.android.support:recyclerview-v7:22.2.1' |
| 51 | 51 | compile 'com.android.support:cardview-v7:22.2.1' |
| 52 | 52 | compile 'com.android.support:design:22.2.1' |
| 53 | - compile 'com.parse.bolts:bolts-android:1.+' | |
| 53 | + compile 'com.parse.bolts:bolts-android:1.2.1' | |
| 54 | 54 | compile 'com.google.code.gson:gson:2.3.1' |
| 55 | 55 | compile 'com.github.PhilJay:MPAndroidChart:v2.1.3' |
| 56 | 56 | compile 'com.google.android.gms:play-services:7.5.0' |
| 57 | 57 | compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3' |
| 58 | + compile 'com.squareup:otto:1.3.8' | |
| 58 | 59 | } | ... | ... |
app/src/main/AndroidManifest.xml
| ... | ... | @@ -18,7 +18,7 @@ |
| 18 | 18 | android:label="@string/app_name" |
| 19 | 19 | android:theme="@style/Theme.MyTheme" > |
| 20 | 20 | <activity |
| 21 | - android:name=".MainActivity" | |
| 21 | + android:name=".view.MainActivity" | |
| 22 | 22 | android:label="@string/app_name" > |
| 23 | 23 | <intent-filter> |
| 24 | 24 | <action android:name="android.intent.action.MAIN" /> |
| ... | ... | @@ -27,13 +27,13 @@ |
| 27 | 27 | </intent-filter> |
| 28 | 28 | </activity> |
| 29 | 29 | <activity |
| 30 | - android:name=".PoliticosActivity" | |
| 30 | + android:name=".view.PoliticosActivity" | |
| 31 | 31 | android:label="@string/title_activity_politicos" |
| 32 | - android:parentActivityName=".MainActivity" | |
| 32 | + android:parentActivityName=".view.MainActivity" | |
| 33 | 33 | android:theme="@style/Theme.MyTheme" > |
| 34 | 34 | <meta-data |
| 35 | 35 | android:name="android.support.PARENT_ACTIVITY" |
| 36 | - android:value="com.monitorabrasil.monitoralegislativo.MainActivity" /> | |
| 36 | + android:value=".view.MainActivity" /> | |
| 37 | 37 | </activity> |
| 38 | 38 | |
| 39 | 39 | <meta-data |
| ... | ... | @@ -41,49 +41,57 @@ |
| 41 | 41 | android:value="fb370c047719aaf76293ffecd977d8476584bbee" /> |
| 42 | 42 | |
| 43 | 43 | <activity |
| 44 | - android:name=".CamaraActivity" | |
| 44 | + android:name=".view.CamaraActivity" | |
| 45 | 45 | android:label="@string/title_activity_camara" |
| 46 | - android:parentActivityName=".MainActivity" > | |
| 46 | + android:parentActivityName=".view.MainActivity" > | |
| 47 | 47 | <meta-data |
| 48 | 48 | android:name="android.support.PARENT_ACTIVITY" |
| 49 | - android:value="com.monitorabrasil.monitoralegislativo.MainActivity" /> | |
| 49 | + android:value=".view.MainActivity" /> | |
| 50 | 50 | </activity> |
| 51 | 51 | <activity |
| 52 | - android:name=".ProjetosActivity" | |
| 52 | + android:name=".view.ProjetosActivity" | |
| 53 | 53 | android:label="@string/title_activity_projetos" |
| 54 | - android:parentActivityName=".MainActivity" > | |
| 54 | + android:parentActivityName=".view.MainActivity" > | |
| 55 | 55 | <meta-data |
| 56 | 56 | android:name="android.support.PARENT_ACTIVITY" |
| 57 | - android:value="com.monitorabrasil.monitoralegislativo.MainActivity" /> | |
| 57 | + android:value=".view.MainActivity" /> | |
| 58 | 58 | </activity> |
| 59 | 59 | <activity |
| 60 | - android:name=".LoginActivity" | |
| 60 | + android:name=".view.LoginActivity" | |
| 61 | 61 | android:label="@string/title_activity_login" |
| 62 | - android:parentActivityName=".MainActivity" | |
| 62 | + android:parentActivityName=".view.MainActivity" | |
| 63 | 63 | android:windowSoftInputMode="adjustResize|stateVisible" > |
| 64 | 64 | <meta-data |
| 65 | 65 | android:name="android.support.PARENT_ACTIVITY" |
| 66 | - android:value="com.monitorabrasil.monitoralegislativo.MainActivity" /> | |
| 66 | + android:value=".view.MainActivity" /> | |
| 67 | 67 | </activity> |
| 68 | 68 | <activity |
| 69 | - android:name=".PoliticoFichaActivity" | |
| 69 | + android:name=".view.PoliticoFichaActivity" | |
| 70 | 70 | android:label="@string/title_activity_politico_ficha" |
| 71 | - android:parentActivityName=".PoliticosActivity" > | |
| 71 | + android:parentActivityName=".view.PoliticosActivity" > | |
| 72 | 72 | <meta-data |
| 73 | 73 | android:name="android.support.PARENT_ACTIVITY" |
| 74 | - android:value="com.monitorabrasil.monitoralegislativo.PoliticosActivity" /> | |
| 74 | + android:value=".view.PoliticosActivity" /> | |
| 75 | 75 | </activity> |
| 76 | 76 | <activity |
| 77 | - android:name=".ComentarioActivity" | |
| 77 | + android:name=".view.ComentarioActivity" | |
| 78 | 78 | android:label="@string/title_activity_comentario" > |
| 79 | 79 | </activity> |
| 80 | 80 | <activity |
| 81 | - android:name=".SobreActivity" | |
| 81 | + android:name=".view.SobreActivity" | |
| 82 | 82 | android:label="@string/title_activity_sobre" |
| 83 | - android:parentActivityName=".MainActivity" > | |
| 83 | + android:parentActivityName=".view.MainActivity" > | |
| 84 | 84 | <meta-data |
| 85 | 85 | android:name="android.support.PARENT_ACTIVITY" |
| 86 | - android:value="com.monitorabrasil.monitoralegislativo.MainActivity" /> | |
| 86 | + android:value=".view.MainActivity" /> | |
| 87 | + </activity> | |
| 88 | + <activity | |
| 89 | + android:name=".view.Login2Activity" | |
| 90 | + android:label="@string/title_activity_login2" | |
| 91 | + android:parentActivityName=".view.MainActivity" > | |
| 92 | + <meta-data | |
| 93 | + android:name="android.support.PARENT_ACTIVITY" | |
| 94 | + android:value="com.monitorabrasil.monitoralegislativo.view.MainActivity" /> | |
| 87 | 95 | </activity> |
| 88 | 96 | </application> |
| 89 | 97 | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/CamaraActivity.java
| ... | ... | @@ -1,64 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo; | |
| 2 | - | |
| 3 | -import android.os.Bundle; | |
| 4 | -import android.support.v4.app.FragmentTransaction; | |
| 5 | -import android.support.v7.app.AppCompatActivity; | |
| 6 | -import android.support.v7.widget.Toolbar; | |
| 7 | -import android.view.Menu; | |
| 8 | -import android.view.MenuItem; | |
| 9 | - | |
| 10 | -import com.crashlytics.android.answers.Answers; | |
| 11 | -import com.crashlytics.android.answers.ContentViewEvent; | |
| 12 | -import com.monitorabrasil.monitoralegislativo.fragments.GastosCamaraFragment; | |
| 13 | - | |
| 14 | -public class CamaraActivity extends AppCompatActivity { | |
| 15 | - | |
| 16 | - @Override | |
| 17 | - protected void onCreate(Bundle savedInstanceState) { | |
| 18 | - super.onCreate(savedInstanceState); | |
| 19 | - setContentView(R.layout.activity_camara); | |
| 20 | - | |
| 21 | - Answers.getInstance().logContentView(new ContentViewEvent() | |
| 22 | - .putContentName("CamaraActivity") | |
| 23 | - .putContentType("Activity")); | |
| 24 | - | |
| 25 | - GastosCamaraFragment frag = (GastosCamaraFragment) getSupportFragmentManager().findFragmentByTag("gastosCamaraFrag"); | |
| 26 | - if(frag == null) { | |
| 27 | - frag = new GastosCamaraFragment(); | |
| 28 | - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); | |
| 29 | - ft.replace(R.id.rl_fragment_container, frag, "gastosCamaraFrag"); | |
| 30 | - ft.commit(); | |
| 31 | - } | |
| 32 | - | |
| 33 | - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
| 34 | - setSupportActionBar(toolbar); | |
| 35 | - // toolbar.setNavigationIcon(R.drawable.ic_good); | |
| 36 | - toolbar.setTitle("Despesas da Câmara"); | |
| 37 | - toolbar.setSubtitle("Ouro Branco - MG"); | |
| 38 | - | |
| 39 | - toolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 40 | - toolbar.setSubtitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 41 | - setSupportActionBar(toolbar); | |
| 42 | - getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 43 | - } | |
| 44 | - | |
| 45 | - @Override | |
| 46 | - public boolean onCreateOptionsMenu(Menu menu) { | |
| 47 | - // Inflate the menu; this adds items to the action bar if it is present. | |
| 48 | - getMenuInflater().inflate(R.menu.menu_camara, menu); | |
| 49 | - return true; | |
| 50 | - } | |
| 51 | - | |
| 52 | - @Override | |
| 53 | - public boolean onOptionsItemSelected(MenuItem item) { | |
| 54 | - // Handle action bar item clicks here. The action bar will | |
| 55 | - // automatically handle clicks on the Home/Up button, so long | |
| 56 | - // as you specify a parent activity in AndroidManifest.xml. | |
| 57 | - int id = item.getItemId(); | |
| 58 | - | |
| 59 | - //noinspection SimplifiableIfStatement | |
| 60 | - | |
| 61 | - | |
| 62 | - return super.onOptionsItemSelected(item); | |
| 63 | - } | |
| 64 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/ComentarioActivity.java
| ... | ... | @@ -1,229 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo; | |
| 2 | - | |
| 3 | -import android.os.Build; | |
| 4 | -import android.os.Bundle; | |
| 5 | -import android.support.design.widget.Snackbar; | |
| 6 | -import android.support.v7.app.AppCompatActivity; | |
| 7 | -import android.support.v7.widget.LinearLayoutManager; | |
| 8 | -import android.support.v7.widget.RecyclerView; | |
| 9 | -import android.support.v7.widget.Toolbar; | |
| 10 | -import android.transition.Transition; | |
| 11 | -import android.transition.TransitionInflater; | |
| 12 | -import android.util.Log; | |
| 13 | -import android.view.Menu; | |
| 14 | -import android.view.MenuItem; | |
| 15 | -import android.view.View; | |
| 16 | -import android.widget.Button; | |
| 17 | -import android.widget.EditText; | |
| 18 | -import android.widget.ProgressBar; | |
| 19 | - | |
| 20 | -import com.monitorabrasil.monitoralegislativo.adapters.ComentarioAdapter; | |
| 21 | -import com.parse.FindCallback; | |
| 22 | -import com.parse.GetCallback; | |
| 23 | -import com.parse.ParseException; | |
| 24 | -import com.parse.ParseObject; | |
| 25 | -import com.parse.ParseQuery; | |
| 26 | -import com.parse.ParseUser; | |
| 27 | -import com.parse.SaveCallback; | |
| 28 | - | |
| 29 | -import java.util.List; | |
| 30 | - | |
| 31 | -public class ComentarioActivity extends AppCompatActivity { | |
| 32 | - | |
| 33 | - private ParseObject projeto; | |
| 34 | - private ParseObject politico; | |
| 35 | - private Toolbar mToolbar; | |
| 36 | - private RecyclerView mRecyclerView; | |
| 37 | - private ComentarioAdapter mAdapter; | |
| 38 | - private List<ParseObject> ob; | |
| 39 | - private ProgressBar pb; | |
| 40 | - | |
| 41 | - @Override | |
| 42 | - protected void onCreate(Bundle savedInstanceState) { | |
| 43 | - super.onCreate(savedInstanceState); | |
| 44 | - setContentView(R.layout.activity_comentario); | |
| 45 | - | |
| 46 | - | |
| 47 | - | |
| 48 | - // TOOLBAR | |
| 49 | - mToolbar = (Toolbar) findViewById(R.id.tb_main); | |
| 50 | - | |
| 51 | - //mToolbar.setSubtitle("just a subtitle"); | |
| 52 | - //mToolbar.setLogo(R.drawable.ic_launcher); | |
| 53 | - setSupportActionBar(mToolbar); | |
| 54 | - mToolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 55 | - | |
| 56 | - pb = (ProgressBar) findViewById(R.id.progressBar); | |
| 57 | - | |
| 58 | - | |
| 59 | - //tableview | |
| 60 | - mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view); | |
| 61 | - | |
| 62 | - | |
| 63 | - //verifica se eh comentario de projeto ou politico | |
| 64 | - if (getIntent().getStringExtra("projeto")!= null){ | |
| 65 | - ParseQuery<ParseObject> query = ParseQuery.getQuery("Projeto"); | |
| 66 | - query.getInBackground(getIntent().getStringExtra("projeto"), new GetCallback<ParseObject>() { | |
| 67 | - public void done(ParseObject object, ParseException e) { | |
| 68 | - if (e == null) { | |
| 69 | - projeto = object; | |
| 70 | - mToolbar.setTitle(projeto.get("classificacao").toString()); | |
| 71 | - setTitle(projeto.get("classificacao").toString()); | |
| 72 | - buscaComentarios("Comentario"); | |
| 73 | - } else { | |
| 74 | - // something went wrong | |
| 75 | - } | |
| 76 | - } | |
| 77 | - }); | |
| 78 | - }else{ | |
| 79 | - //busca comentario de politico | |
| 80 | - buscaPolitico(getIntent().getStringExtra("politico")); | |
| 81 | - } | |
| 82 | - | |
| 83 | - | |
| 84 | - | |
| 85 | - | |
| 86 | - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ | |
| 87 | - //fazer a animacao | |
| 88 | - TransitionInflater inflater = TransitionInflater.from(this); | |
| 89 | - Transition transition = inflater.inflateTransition(R.transition.transitions); | |
| 90 | - | |
| 91 | - getWindow().setSharedElementEnterTransition(transition); | |
| 92 | - } | |
| 93 | - | |
| 94 | - //botao para enviar mensagem | |
| 95 | - Button btnEnviar = (Button)findViewById(R.id.btnEnviar); | |
| 96 | - btnEnviar.setOnClickListener(new View.OnClickListener() { | |
| 97 | - @Override | |
| 98 | - public void onClick(View v) { | |
| 99 | - enviarMensagem(v); | |
| 100 | - } | |
| 101 | - }); | |
| 102 | - | |
| 103 | - | |
| 104 | - | |
| 105 | - // use this setting to improve performance if you know that changes | |
| 106 | - // in content do not change the layout size of the RecyclerView | |
| 107 | - mRecyclerView.setHasFixedSize(true); | |
| 108 | - | |
| 109 | - LinearLayoutManager llm = new LinearLayoutManager(this); | |
| 110 | - llm.setOrientation(LinearLayoutManager.VERTICAL); | |
| 111 | - llm.setReverseLayout(true); | |
| 112 | - mRecyclerView.setLayoutManager(llm); | |
| 113 | - | |
| 114 | - } | |
| 115 | - | |
| 116 | - private ParseObject buscaPolitico(String id) { | |
| 117 | - | |
| 118 | - ParseQuery<ParseObject> query = ParseQuery.getQuery("Politico"); | |
| 119 | - query.fromLocalDatastore(); | |
| 120 | - try { | |
| 121 | - politico = query.get(id); | |
| 122 | - mToolbar.setTitle(politico.get("nome").toString()); | |
| 123 | - buscaComentarios("ComentarioPolitico"); | |
| 124 | - } catch (com.parse.ParseException e) { | |
| 125 | - e.printStackTrace(); | |
| 126 | - } | |
| 127 | - return null; | |
| 128 | - } | |
| 129 | - | |
| 130 | - public void buscaComentarios(String tipo){ | |
| 131 | - pb.setVisibility(View.VISIBLE); | |
| 132 | - ParseQuery<ParseObject> query = ParseQuery.getQuery(tipo); | |
| 133 | - if(tipo.equals("Comentario")){ | |
| 134 | - query.whereEqualTo("projeto",projeto); | |
| 135 | - }else{ | |
| 136 | - query.whereEqualTo("politico",politico); | |
| 137 | - } | |
| 138 | - | |
| 139 | - query.addAscendingOrder("createdAt"); | |
| 140 | - //query.whereEqualTo("playerName", "Dan Stemkoski"); | |
| 141 | - query.findInBackground(new FindCallback<ParseObject>() { | |
| 142 | - @Override | |
| 143 | - public void done(List<ParseObject> list, com.parse.ParseException e) { | |
| 144 | - if (e == null) { | |
| 145 | - ob = list; | |
| 146 | - carregaList(list); | |
| 147 | - } else { | |
| 148 | - Log.d("score", "Error: " + e.getMessage()); | |
| 149 | - } | |
| 150 | - } | |
| 151 | - | |
| 152 | - | |
| 153 | - }); | |
| 154 | - } | |
| 155 | - public void carregaList(List<ParseObject> list){ | |
| 156 | - mAdapter = new ComentarioAdapter(list); | |
| 157 | - // mAdapter.setRecyclerViewOnClickListenerHack(this); | |
| 158 | - mRecyclerView.setAdapter(mAdapter); | |
| 159 | - pb.setVisibility(View.INVISIBLE); | |
| 160 | - } | |
| 161 | - | |
| 162 | - | |
| 163 | - private void enviarMensagem(final View v) { | |
| 164 | - final EditText txtMensagem = (EditText)findViewById(R.id.mensagem); | |
| 165 | - String mensagem = txtMensagem.getText().toString(); | |
| 166 | - ParseUser user = ParseUser.getCurrentUser(); | |
| 167 | - final String tipo; | |
| 168 | - if(user!= null){ | |
| 169 | - ParseObject comentario; | |
| 170 | - if(politico != null){ | |
| 171 | - tipo = "ComentarioPolitico"; | |
| 172 | - comentario = new ParseObject("ComentarioPolitico"); | |
| 173 | - comentario.put("politico",politico); | |
| 174 | - }else{ | |
| 175 | - tipo ="Comentario"; | |
| 176 | - comentario = new ParseObject("Comentario"); | |
| 177 | - comentario.put("projeto",projeto); | |
| 178 | - } | |
| 179 | - comentario.put("mensagem",mensagem); | |
| 180 | - comentario.put("user", user); | |
| 181 | - comentario.put("nome", user.getString("nome")); | |
| 182 | - | |
| 183 | - comentario.saveInBackground(new SaveCallback() { | |
| 184 | - @Override | |
| 185 | - public void done(ParseException e) { | |
| 186 | - Snackbar.make(v, "Comentário enviado", Snackbar.LENGTH_LONG) | |
| 187 | - .setAction("Action", null).show(); | |
| 188 | - | |
| 189 | - //recarregar lista | |
| 190 | - buscaComentarios(tipo); | |
| 191 | - } | |
| 192 | - }); | |
| 193 | - if(politico != null){ | |
| 194 | - politico.increment("nr_comentarios"); | |
| 195 | - politico.saveInBackground(); | |
| 196 | - }else{ | |
| 197 | - projeto.increment("nr_comentarios"); | |
| 198 | - projeto.saveInBackground(); | |
| 199 | - } | |
| 200 | - | |
| 201 | - | |
| 202 | - }else{ | |
| 203 | - Snackbar.make(v, "Para comentar é necessário estar logado", Snackbar.LENGTH_LONG) | |
| 204 | - .setAction("Action", null).show(); | |
| 205 | - return; | |
| 206 | - } | |
| 207 | - | |
| 208 | - txtMensagem.setText(""); | |
| 209 | - } | |
| 210 | - | |
| 211 | - @Override | |
| 212 | - public boolean onCreateOptionsMenu(Menu menu) { | |
| 213 | - // Inflate the menu; this adds items to the action bar if it is present. | |
| 214 | - getMenuInflater().inflate(R.menu.menu_comentario, menu); | |
| 215 | - return true; | |
| 216 | - } | |
| 217 | - | |
| 218 | - @Override | |
| 219 | - public boolean onOptionsItemSelected(MenuItem item) { | |
| 220 | - // Handle action bar item clicks here. The action bar will | |
| 221 | - // automatically handle clicks on the Home/Up button, so long | |
| 222 | - // as you specify a parent activity in AndroidManifest.xml. | |
| 223 | - int id = item.getItemId(); | |
| 224 | - | |
| 225 | - //noinspection SimplifiableIfStatement | |
| 226 | - | |
| 227 | - return super.onOptionsItemSelected(item); | |
| 228 | - } | |
| 229 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/LoginActivity.java
| ... | ... | @@ -1,456 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo; | |
| 2 | - | |
| 3 | -import android.app.Activity; | |
| 4 | -import android.content.Intent; | |
| 5 | -import android.graphics.Bitmap; | |
| 6 | -import android.graphics.BitmapFactory; | |
| 7 | -import android.net.Uri; | |
| 8 | -import android.os.Bundle; | |
| 9 | -import android.support.design.widget.Snackbar; | |
| 10 | -import android.support.v7.app.AppCompatActivity; | |
| 11 | -import android.support.v7.widget.Toolbar; | |
| 12 | -import android.text.TextUtils; | |
| 13 | -import android.view.KeyEvent; | |
| 14 | -import android.view.View; | |
| 15 | -import android.view.View.OnClickListener; | |
| 16 | -import android.view.inputmethod.EditorInfo; | |
| 17 | -import android.widget.ArrayAdapter; | |
| 18 | -import android.widget.AutoCompleteTextView; | |
| 19 | -import android.widget.Button; | |
| 20 | -import android.widget.EditText; | |
| 21 | -import android.widget.ImageButton; | |
| 22 | -import android.widget.ImageView; | |
| 23 | -import android.widget.TextView; | |
| 24 | - | |
| 25 | -import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 26 | -import com.nostra13.universalimageloader.core.assist.FailReason; | |
| 27 | -import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; | |
| 28 | -import com.parse.LogInCallback; | |
| 29 | -import com.parse.LogOutCallback; | |
| 30 | -import com.parse.ParseTwitterUtils; | |
| 31 | -import com.parse.ParseUser; | |
| 32 | -import com.parse.SignUpCallback; | |
| 33 | - | |
| 34 | -import java.io.FileNotFoundException; | |
| 35 | -import java.io.InputStream; | |
| 36 | -import java.util.List; | |
| 37 | - | |
| 38 | -/** | |
| 39 | - * A login screen that offers login via email/password. | |
| 40 | - */ | |
| 41 | -public class LoginActivity extends AppCompatActivity { | |
| 42 | - | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * Keep track of the login task to ensure we can cancel it if requested. | |
| 46 | - */ | |
| 47 | - | |
| 48 | - | |
| 49 | - // UI references. | |
| 50 | - private AutoCompleteTextView mEmailView; | |
| 51 | - private EditText mPasswordView; | |
| 52 | - private EditText mNome; | |
| 53 | - private View mProgressView; | |
| 54 | - private View mLoginFormView; | |
| 55 | - private View mLogoutFormView; | |
| 56 | - private Button btnFazerCadastro; | |
| 57 | - private Button btnLogar; | |
| 58 | - private Button btnLogout; | |
| 59 | - private Button btnLoginTwitter; | |
| 60 | - private TextView lblNome; | |
| 61 | - private TextView lblEmail; | |
| 62 | - private ImageView foto; | |
| 63 | - private ParseUser currentUser; | |
| 64 | - private ImageButton btnFoto; | |
| 65 | - | |
| 66 | - private final int PICK_IMAGE=2; | |
| 67 | - | |
| 68 | - @Override | |
| 69 | - protected void onCreate(Bundle savedInstanceState) { | |
| 70 | - super.onCreate(savedInstanceState); | |
| 71 | - setContentView(R.layout.activity_login); | |
| 72 | - setupActionBar(); | |
| 73 | - mLoginFormView = findViewById(R.id.login_form); | |
| 74 | - mLogoutFormView = findViewById(R.id.logout_form); | |
| 75 | - mProgressView = findViewById(R.id.login_progress); | |
| 76 | - btnFoto = (ImageButton) findViewById(R.id.btnFoto); | |
| 77 | - currentUser = ParseUser.getCurrentUser(); | |
| 78 | - | |
| 79 | - | |
| 80 | - | |
| 81 | - | |
| 82 | - if (currentUser != null) { | |
| 83 | - montaFormLogout(); | |
| 84 | - | |
| 85 | - }else{ | |
| 86 | - mLogoutFormView.setVisibility(View.GONE); | |
| 87 | - mLoginFormView.setVisibility(View.VISIBLE); | |
| 88 | - | |
| 89 | - } | |
| 90 | - | |
| 91 | - // Set up the login form. | |
| 92 | - btnFoto.setOnClickListener(new OnClickListener() { | |
| 93 | - @Override | |
| 94 | - public void onClick(View v) { | |
| 95 | - Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT); | |
| 96 | - getIntent.setType("image/*"); | |
| 97 | - | |
| 98 | - Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); | |
| 99 | - pickIntent.setType("image/*"); | |
| 100 | - | |
| 101 | - Intent chooserIntent = Intent.createChooser(getIntent, "Selecione uma foto"); | |
| 102 | - chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent}); | |
| 103 | - | |
| 104 | - startActivityForResult(chooserIntent, PICK_IMAGE); | |
| 105 | - } | |
| 106 | - }); | |
| 107 | - | |
| 108 | - mNome = (EditText)findViewById(R.id.txtNome); | |
| 109 | - mNome.setVisibility(View.GONE); | |
| 110 | - | |
| 111 | - btnLogar = (Button)findViewById(R.id.email_sign_in_button); | |
| 112 | - btnLogout = (Button)findViewById(R.id.btnLogout); | |
| 113 | - | |
| 114 | - btnLogout.setOnClickListener(new OnClickListener() { | |
| 115 | - | |
| 116 | - @Override | |
| 117 | - public void onClick(View v) { | |
| 118 | - showProgress(true,null); | |
| 119 | - ParseUser.logOutInBackground(new LogOutCallback() { | |
| 120 | - @Override | |
| 121 | - public void done(com.parse.ParseException e) { | |
| 122 | - showProgress(false, mLoginFormView); | |
| 123 | - } | |
| 124 | - }); | |
| 125 | - } | |
| 126 | - }); | |
| 127 | - | |
| 128 | - btnFazerCadastro = (Button)findViewById(R.id.fazer_cadastro); | |
| 129 | - btnFazerCadastro.setOnClickListener(new OnClickListener() { | |
| 130 | - @Override | |
| 131 | - public void onClick(View v) { | |
| 132 | - if(btnFazerCadastro.getText().toString().equals("Fazer Cadastro")){ | |
| 133 | - mNome.setVisibility(View.VISIBLE); | |
| 134 | - btnLogar.setVisibility(View.GONE); | |
| 135 | - btnLoginTwitter.setVisibility(View.GONE); | |
| 136 | - btnFazerCadastro.setText("Cadastrar"); | |
| 137 | - View view = mNome; | |
| 138 | - view.requestFocus(); | |
| 139 | - }else{ | |
| 140 | - realizarCadastro(); | |
| 141 | - } | |
| 142 | - | |
| 143 | - } | |
| 144 | - }); | |
| 145 | - | |
| 146 | - btnLoginTwitter = (Button)findViewById(R.id.login_twitter); | |
| 147 | - btnLoginTwitter.setOnClickListener(new OnClickListener() { | |
| 148 | - @Override | |
| 149 | - public void onClick(View v) { | |
| 150 | - ParseTwitterUtils.logIn(v.getContext(), new LogInCallback() { | |
| 151 | - @Override | |
| 152 | - public void done(ParseUser parseUser, com.parse.ParseException e) { | |
| 153 | - if (parseUser == null) { | |
| 154 | - Snackbar.make(mLoginFormView, "Login cancelado ", Snackbar.LENGTH_LONG) | |
| 155 | - .setAction("Action", null).show(); | |
| 156 | - } else if (parseUser.isNew()) { | |
| 157 | - parseUser.put("nome",ParseTwitterUtils.getTwitter().getScreenName()); | |
| 158 | - parseUser.saveInBackground(); | |
| 159 | - montaFormLogout(); | |
| 160 | - } else { | |
| 161 | - montaFormLogout(); | |
| 162 | - } | |
| 163 | - } | |
| 164 | - }); | |
| 165 | - } | |
| 166 | - }); | |
| 167 | - | |
| 168 | - mEmailView = (AutoCompleteTextView) findViewById(R.id.email); | |
| 169 | - | |
| 170 | - | |
| 171 | - mPasswordView = (EditText) findViewById(R.id.password); | |
| 172 | - mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() { | |
| 173 | - @Override | |
| 174 | - public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { | |
| 175 | - if (id == R.id.login || id == EditorInfo.IME_NULL) { | |
| 176 | - attemptLogin(); | |
| 177 | - return true; | |
| 178 | - } | |
| 179 | - return false; | |
| 180 | - } | |
| 181 | - }); | |
| 182 | - | |
| 183 | - Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button); | |
| 184 | - mEmailSignInButton.setOnClickListener(new OnClickListener() { | |
| 185 | - @Override | |
| 186 | - public void onClick(View view) { | |
| 187 | - attemptLogin(); | |
| 188 | - } | |
| 189 | - }); | |
| 190 | - | |
| 191 | - | |
| 192 | - | |
| 193 | - } | |
| 194 | - | |
| 195 | - @Override | |
| 196 | - public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
| 197 | - super.onActivityResult(requestCode, resultCode, data); | |
| 198 | - if (requestCode == PICK_IMAGE && resultCode == Activity.RESULT_OK) { | |
| 199 | - if (data == null) { | |
| 200 | - //Display an error | |
| 201 | - return; | |
| 202 | - } | |
| 203 | - try { | |
| 204 | - Uri selectedImage = data.getData(); | |
| 205 | - InputStream imageStream = getContentResolver().openInputStream(selectedImage); | |
| 206 | - Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream); | |
| 207 | - btnFoto.setImageBitmap(yourSelectedImage); | |
| 208 | - } catch (FileNotFoundException e) { | |
| 209 | - e.printStackTrace(); | |
| 210 | - } | |
| 211 | - //Now you can do whatever you want with your inpustream, save it as file, upload to a server, decode a bitmap... | |
| 212 | - } | |
| 213 | - } | |
| 214 | - | |
| 215 | - private void showProgress(boolean b,View v) { | |
| 216 | - if(b){ | |
| 217 | - mProgressView.setVisibility(View.VISIBLE); | |
| 218 | - mLogoutFormView.setVisibility(View.GONE); | |
| 219 | - mLoginFormView.setVisibility(View.GONE); | |
| 220 | - }else{ | |
| 221 | - mProgressView.setVisibility(View.GONE); | |
| 222 | - v.setVisibility(View.VISIBLE); | |
| 223 | - } | |
| 224 | - } | |
| 225 | - | |
| 226 | - private void montaFormLogout() { | |
| 227 | - lblNome = (TextView)findViewById(R.id.lblNome); | |
| 228 | - lblEmail = (TextView)findViewById(R.id.lblEmail); | |
| 229 | - foto = (ImageView)findViewById(R.id.foto); | |
| 230 | - | |
| 231 | - mLoginFormView.setVisibility(View.GONE); | |
| 232 | - showProgress(false,mLogoutFormView); | |
| 233 | - | |
| 234 | - if(ParseTwitterUtils.getTwitter().getUserId() !=null){ | |
| 235 | - String screenName = ParseTwitterUtils.getTwitter().getScreenName(); | |
| 236 | - lblNome.setText(screenName); | |
| 237 | - lblEmail.setText(""); | |
| 238 | - MyApp.getInstance().getmImagemLoader().loadImage("https://twitter.com/" + screenName + "/profile_image?size=bigger", new ImageLoadingListener() { | |
| 239 | - | |
| 240 | - | |
| 241 | - @Override | |
| 242 | - public void onLoadingStarted(String imageUri, View view) { | |
| 243 | - | |
| 244 | - } | |
| 245 | - | |
| 246 | - @Override | |
| 247 | - public void onLoadingFailed(String imageUri, View view, FailReason failReason) { | |
| 248 | - | |
| 249 | - } | |
| 250 | - | |
| 251 | - @Override | |
| 252 | - public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { | |
| 253 | - foto.setImageBitmap(loadedImage); | |
| 254 | - } | |
| 255 | - | |
| 256 | - @Override | |
| 257 | - public void onLoadingCancelled(String imageUri, View view) { | |
| 258 | - | |
| 259 | - } | |
| 260 | - | |
| 261 | - | |
| 262 | - }); | |
| 263 | - }else{ | |
| 264 | - lblNome.setText(currentUser.get("nome").toString()); | |
| 265 | - lblEmail.setText(currentUser.getEmail()); | |
| 266 | - } | |
| 267 | - } | |
| 268 | - | |
| 269 | - | |
| 270 | - private void realizarCadastro() { | |
| 271 | - | |
| 272 | - // Reset errors. | |
| 273 | - mEmailView.setError(null); | |
| 274 | - mPasswordView.setError(null); | |
| 275 | - mNome.setError(null); | |
| 276 | - | |
| 277 | - // Store values at the time of the login attempt. | |
| 278 | - String email = mEmailView.getText().toString(); | |
| 279 | - String password = mPasswordView.getText().toString(); | |
| 280 | - String nome =mNome.getText().toString(); | |
| 281 | - | |
| 282 | - boolean cancel = false; | |
| 283 | - View focusView = null; | |
| 284 | - | |
| 285 | - if (TextUtils.isEmpty(nome)) { | |
| 286 | - mNome.setError(getString(R.string.error_field_required)); | |
| 287 | - focusView = mNome; | |
| 288 | - cancel = true; | |
| 289 | - } | |
| 290 | - | |
| 291 | - // Check for a valid password, if the user entered one. | |
| 292 | - if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) { | |
| 293 | - mPasswordView.setError(getString(R.string.error_invalid_password)); | |
| 294 | - focusView = mPasswordView; | |
| 295 | - cancel = true; | |
| 296 | - } | |
| 297 | - | |
| 298 | - // Check for a valid email address. | |
| 299 | - if (TextUtils.isEmpty(email)) { | |
| 300 | - mEmailView.setError(getString(R.string.error_field_required)); | |
| 301 | - focusView = mEmailView; | |
| 302 | - cancel = true; | |
| 303 | - } else if (!isEmailValid(email)) { | |
| 304 | - mEmailView.setError(getString(R.string.error_invalid_email)); | |
| 305 | - focusView = mEmailView; | |
| 306 | - cancel = true; | |
| 307 | - } | |
| 308 | - | |
| 309 | - if (cancel) { | |
| 310 | - // There was an error; don't attempt login and focus the first | |
| 311 | - // form field with an error. | |
| 312 | - focusView.requestFocus(); | |
| 313 | - } else { | |
| 314 | - // Show a progress spinner, and kick off a background task to | |
| 315 | - // perform the user login attempt. | |
| 316 | - showProgress(true,null); | |
| 317 | - | |
| 318 | - ParseUser user = new ParseUser(); | |
| 319 | - user.setUsername(email); | |
| 320 | - user.setPassword(password); | |
| 321 | - user.setEmail(email); | |
| 322 | - user.put("nome",mNome.getText().toString()); | |
| 323 | - | |
| 324 | - | |
| 325 | - user.signUpInBackground(new SignUpCallback() { | |
| 326 | - @Override | |
| 327 | - public void done(com.parse.ParseException e) { | |
| 328 | - if (e == null) { | |
| 329 | - montaFormLogout(); | |
| 330 | - } else { | |
| 331 | - showProgress(false,mLoginFormView); | |
| 332 | - Snackbar.make(mLoginFormView, "Houve um erro ao fazer seu cadastro ", Snackbar.LENGTH_LONG) | |
| 333 | - .setAction("Action", null).show(); | |
| 334 | - } | |
| 335 | - } | |
| 336 | - | |
| 337 | - | |
| 338 | - }); | |
| 339 | - | |
| 340 | - } | |
| 341 | - } | |
| 342 | - | |
| 343 | - | |
| 344 | - | |
| 345 | - /** | |
| 346 | - * Set up the {@link android.app.ActionBar}, if the API is available. | |
| 347 | - */ | |
| 348 | -// @TargetApi(Build.VERSION_CODES.HONEYCOMB) | |
| 349 | - private void setupActionBar() { | |
| 350 | - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
| 351 | - | |
| 352 | - // toolbar.setNavigationIcon(R.drawable.ic_good); | |
| 353 | - toolbar.setTitle("Login"); | |
| 354 | - | |
| 355 | - toolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 356 | - toolbar.setSubtitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 357 | - setSupportActionBar(toolbar); | |
| 358 | - getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 359 | - } | |
| 360 | - | |
| 361 | - /** | |
| 362 | - * Attempts to sign in or register the account specified by the login form. | |
| 363 | - * If there are form errors (invalid email, missing fields, etc.), the | |
| 364 | - * errors are presented and no actual login attempt is made. | |
| 365 | - */ | |
| 366 | - public void attemptLogin() { | |
| 367 | - | |
| 368 | - | |
| 369 | - // Reset errors. | |
| 370 | - mEmailView.setError(null); | |
| 371 | - mPasswordView.setError(null); | |
| 372 | - | |
| 373 | - // Store values at the time of the login attempt. | |
| 374 | - String email = mEmailView.getText().toString(); | |
| 375 | - String password = mPasswordView.getText().toString(); | |
| 376 | - | |
| 377 | - boolean cancel = false; | |
| 378 | - View focusView = null; | |
| 379 | - | |
| 380 | - // Check for a valid password, if the user entered one. | |
| 381 | - if (TextUtils.isEmpty(password) && !isPasswordValid(password)) { | |
| 382 | - mPasswordView.setError(getString(R.string.error_invalid_password)); | |
| 383 | - focusView = mPasswordView; | |
| 384 | - cancel = true; | |
| 385 | - } | |
| 386 | - | |
| 387 | - // Check for a valid email address. | |
| 388 | - if (TextUtils.isEmpty(email)) { | |
| 389 | - mEmailView.setError(getString(R.string.error_field_required)); | |
| 390 | - focusView = mEmailView; | |
| 391 | - cancel = true; | |
| 392 | - } else if (!isEmailValid(email)) { | |
| 393 | - mEmailView.setError(getString(R.string.error_invalid_email)); | |
| 394 | - focusView = mEmailView; | |
| 395 | - cancel = true; | |
| 396 | - } | |
| 397 | - | |
| 398 | - if (cancel) { | |
| 399 | - // There was an error; don't attempt login and focus the first | |
| 400 | - // form field with an error. | |
| 401 | - focusView.requestFocus(); | |
| 402 | - } else { | |
| 403 | - // Show a progress spinner, and kick off a background task to | |
| 404 | - // perform the user login attempt. | |
| 405 | - showProgress(true,null); | |
| 406 | - | |
| 407 | - //fazer o login aqui | |
| 408 | - fazerLogin(email, password); | |
| 409 | - | |
| 410 | - } | |
| 411 | - } | |
| 412 | - | |
| 413 | - private void fazerLogin(String email, String password) { | |
| 414 | - ParseUser.logInInBackground(email, password, new LogInCallback() { | |
| 415 | - | |
| 416 | - @Override | |
| 417 | - public void done(ParseUser parseUser, com.parse.ParseException e) { | |
| 418 | - if (parseUser != null) { | |
| 419 | - finish(); | |
| 420 | - } else { | |
| 421 | - mPasswordView.setError(getString(R.string.error_incorrect_password)); | |
| 422 | - mPasswordView.requestFocus(); | |
| 423 | - showProgress(false,mLoginFormView); | |
| 424 | - } | |
| 425 | - } | |
| 426 | - | |
| 427 | - | |
| 428 | - }); | |
| 429 | - } | |
| 430 | - | |
| 431 | - private boolean isEmailValid(String email) { | |
| 432 | - //TODO: Replace this with your own logic | |
| 433 | - return email.contains("@"); | |
| 434 | - } | |
| 435 | - | |
| 436 | - private boolean isPasswordValid(String password) { | |
| 437 | - //TODO: Replace this with your own logic | |
| 438 | - return password.length() > 4; | |
| 439 | - } | |
| 440 | - | |
| 441 | - | |
| 442 | - | |
| 443 | - | |
| 444 | - | |
| 445 | - private void addEmailsToAutoComplete(List<String> emailAddressCollection) { | |
| 446 | - //Create adapter to tell the AutoCompleteTextView what to show in its dropdown list. | |
| 447 | - ArrayAdapter<String> adapter = | |
| 448 | - new ArrayAdapter<String>(LoginActivity.this, | |
| 449 | - android.R.layout.simple_dropdown_item_1line, emailAddressCollection); | |
| 450 | - | |
| 451 | - mEmailView.setAdapter(adapter); | |
| 452 | - } | |
| 453 | - | |
| 454 | - | |
| 455 | -} | |
| 456 | - |
app/src/main/java/com/monitorabrasil/monitoralegislativo/MainActivity.java
| ... | ... | @@ -1,270 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo; | |
| 2 | - | |
| 3 | -import android.content.Intent; | |
| 4 | -import android.graphics.Bitmap; | |
| 5 | -import android.net.Uri; | |
| 6 | -import android.support.design.widget.Snackbar; | |
| 7 | -import android.support.v4.app.FragmentTransaction; | |
| 8 | -import android.support.v7.app.ActionBarActivity; | |
| 9 | -import android.os.Bundle; | |
| 10 | -import android.support.v7.app.AppCompatActivity; | |
| 11 | -import android.support.v7.widget.LinearLayoutManager; | |
| 12 | -import android.support.v7.widget.RecyclerView; | |
| 13 | -import android.support.v7.widget.Toolbar; | |
| 14 | -import android.util.Log; | |
| 15 | -import android.view.Gravity; | |
| 16 | -import android.view.Menu; | |
| 17 | -import android.view.MenuItem; | |
| 18 | -import android.view.View; | |
| 19 | -import android.widget.AdapterView; | |
| 20 | -import android.widget.Toast; | |
| 21 | - | |
| 22 | -import com.mikepenz.materialdrawer.Drawer; | |
| 23 | -import com.mikepenz.materialdrawer.DrawerBuilder; | |
| 24 | -import com.mikepenz.materialdrawer.accountswitcher.AccountHeader; | |
| 25 | -import com.mikepenz.materialdrawer.accountswitcher.AccountHeaderBuilder; | |
| 26 | -import com.mikepenz.materialdrawer.model.DividerDrawerItem; | |
| 27 | -import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; | |
| 28 | -import com.mikepenz.materialdrawer.model.ProfileDrawerItem; | |
| 29 | -import com.mikepenz.materialdrawer.model.SecondaryDrawerItem; | |
| 30 | -import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; | |
| 31 | -import com.mikepenz.materialdrawer.model.interfaces.IProfile; | |
| 32 | -import com.monitorabrasil.monitoralegislativo.adapters.VereadorAdapter; | |
| 33 | -import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 34 | -import com.monitorabrasil.monitoralegislativo.fragments.HomeFragment; | |
| 35 | -import com.monitorabrasil.monitoralegislativo.fragments.ListaPoliticoFragment; | |
| 36 | -import com.monitorabrasil.monitoralegislativo.interfaces.RecyclerViewOnClickListenerHack; | |
| 37 | -import com.nostra13.universalimageloader.core.assist.FailReason; | |
| 38 | -import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; | |
| 39 | -import com.parse.FindCallback; | |
| 40 | -import com.parse.Parse; | |
| 41 | -import com.parse.ParseObject; | |
| 42 | -import com.parse.ParseQuery; | |
| 43 | -import com.parse.ParseTwitterUtils; | |
| 44 | -import com.parse.ParseUser; | |
| 45 | -import com.parse.twitter.Twitter; | |
| 46 | - | |
| 47 | -import org.apache.http.HttpResponse; | |
| 48 | -import org.apache.http.client.ClientProtocolException; | |
| 49 | -import org.apache.http.client.HttpClient; | |
| 50 | -import org.apache.http.client.methods.HttpGet; | |
| 51 | -import org.apache.http.impl.client.DefaultHttpClient; | |
| 52 | - | |
| 53 | -import java.io.IOException; | |
| 54 | -import java.net.URI; | |
| 55 | -import java.net.URISyntaxException; | |
| 56 | -import java.net.URL; | |
| 57 | -import java.util.List; | |
| 58 | - | |
| 59 | - | |
| 60 | -public class MainActivity extends AppCompatActivity implements HomeFragment.OnFragmentInteractionListener { | |
| 61 | - | |
| 62 | - | |
| 63 | - | |
| 64 | - private Toolbar mToolbar; | |
| 65 | - private AccountHeader headerNavigationLeft; | |
| 66 | - private Drawer navigationDrawerLeft; | |
| 67 | - | |
| 68 | - | |
| 69 | - | |
| 70 | - @Override | |
| 71 | - protected void onCreate(Bundle savedInstanceState) { | |
| 72 | - super.onCreate(savedInstanceState); | |
| 73 | - setContentView(R.layout.activity_main); | |
| 74 | - | |
| 75 | - //FRAGMENT | |
| 76 | - HomeFragment homeFragment = (HomeFragment) getSupportFragmentManager().findFragmentByTag("homeFrag"); | |
| 77 | - if(homeFragment == null) { | |
| 78 | - homeFragment = homeFragment.newInstance(); | |
| 79 | - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); | |
| 80 | - ft.replace(R.id.rl_fragment_container, homeFragment, "homeFrag"); | |
| 81 | - ft.commit(); | |
| 82 | - } | |
| 83 | - | |
| 84 | - // TOOLBAR | |
| 85 | - mToolbar = (Toolbar) findViewById(R.id.tb_main); | |
| 86 | - mToolbar.setTitle(getString(R.string.app_name)); | |
| 87 | - mToolbar.setSubtitle("Ouro Branco - MG"); | |
| 88 | - //mToolbar.setLogo(R.drawable.ic_launcher); | |
| 89 | - setSupportActionBar(mToolbar); | |
| 90 | - mToolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 91 | - mToolbar.setSubtitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 92 | - | |
| 93 | - /*getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 94 | - getSupportActionBar().setHomeButtonEnabled(false);*/ | |
| 95 | - | |
| 96 | - | |
| 97 | - headerNavigationLeft = new AccountHeaderBuilder() | |
| 98 | - .withActivity(this) | |
| 99 | - .withHeaderBackground(R.drawable.rsz_ourobranco) | |
| 100 | - .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() { | |
| 101 | - @Override | |
| 102 | - public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) { | |
| 103 | - startActivity(new Intent(getApplicationContext(), LoginActivity.class)); | |
| 104 | - | |
| 105 | - return false; | |
| 106 | - } | |
| 107 | - }) | |
| 108 | - .build(); | |
| 109 | - | |
| 110 | - ParseUser currentUser = ParseUser.getCurrentUser(); | |
| 111 | - if (currentUser != null) { | |
| 112 | - | |
| 113 | - if(ParseTwitterUtils.getTwitter()!=null){ | |
| 114 | - String screenName = ParseTwitterUtils.getTwitter().getScreenName(); | |
| 115 | - MyApp.getInstance().getmImagemLoader().loadImage("https://twitter.com/" + screenName + "/profile_image?size=bigger", new ImageLoadingListener() { | |
| 116 | - @Override | |
| 117 | - public void onLoadingStarted(String imageUri, View view) { | |
| 118 | - | |
| 119 | - } | |
| 120 | - | |
| 121 | - @Override | |
| 122 | - public void onLoadingFailed(String imageUri, View view, FailReason failReason) { | |
| 123 | - | |
| 124 | - } | |
| 125 | - | |
| 126 | - @Override | |
| 127 | - public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { | |
| 128 | - headerNavigationLeft.addProfiles( | |
| 129 | - new ProfileDrawerItem().withName(ParseTwitterUtils.getTwitter().getScreenName()). | |
| 130 | - withEmail(ParseUser.getCurrentUser().getEmail()). | |
| 131 | - withIcon(loadedImage) | |
| 132 | - | |
| 133 | - ); | |
| 134 | - } | |
| 135 | - | |
| 136 | - @Override | |
| 137 | - public void onLoadingCancelled(String imageUri, View view) { | |
| 138 | - | |
| 139 | - } | |
| 140 | - }); | |
| 141 | - | |
| 142 | - | |
| 143 | - | |
| 144 | - Uri uri = Uri.parse("https://twitter.com/" + screenName + "/profile_image?size=bigger"); | |
| 145 | - | |
| 146 | -// MyApp.getInstance().getmImagemLoader().lo.loadImageSync("https://twitter.com/" + screenName + "/profile_image?size=bigger"); | |
| 147 | -// headerNavigationLeft.getProfiles().get(0).setIcon(uri); | |
| 148 | - | |
| 149 | -// Uri uri = Uri.parse("https://twitter.com/"+screenName+"/profile_image?size=bigger"); | |
| 150 | - | |
| 151 | - | |
| 152 | - | |
| 153 | - }else{ | |
| 154 | - headerNavigationLeft.addProfiles( | |
| 155 | - new ProfileDrawerItem().withName(currentUser.get("nome").toString()). | |
| 156 | - withEmail(currentUser.getEmail()) | |
| 157 | - .withIcon(getResources().getDrawable(R.drawable.person_1)) | |
| 158 | - ); | |
| 159 | - } | |
| 160 | - | |
| 161 | - | |
| 162 | - | |
| 163 | - } else { | |
| 164 | - headerNavigationLeft.addProfiles( | |
| 165 | - new ProfileDrawerItem().withName("Faça seu cadastro")); | |
| 166 | - } | |
| 167 | - | |
| 168 | - navigationDrawerLeft = new DrawerBuilder() | |
| 169 | - .withActivity(this) | |
| 170 | - .withToolbar(mToolbar) | |
| 171 | - .withDisplayBelowToolbar(false) | |
| 172 | - .withActionBarDrawerToggleAnimated(true) | |
| 173 | - .withDrawerGravity(Gravity.START) | |
| 174 | - .withSavedInstance(savedInstanceState) | |
| 175 | - .withActionBarDrawerToggle(true) | |
| 176 | - .withAccountHeader(headerNavigationLeft) | |
| 177 | - .addDrawerItems( | |
| 178 | - new PrimaryDrawerItem().withName("Home"), | |
| 179 | - new DividerDrawerItem(), | |
| 180 | - new PrimaryDrawerItem().withName("Vereadores"), | |
| 181 | - new SecondaryDrawerItem().withName("Indicações"), | |
| 182 | - new SecondaryDrawerItem().withName("Câmara"), | |
| 183 | - new SecondaryDrawerItem().withName("Sobre") | |
| 184 | - ) | |
| 185 | - .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { | |
| 186 | - @Override | |
| 187 | - public boolean onItemClick(AdapterView<?> parent, View view, int position, long id, IDrawerItem drawerItem) { | |
| 188 | - switch (position){ | |
| 189 | - case 0: | |
| 190 | - HomeFragment homeFragment = (HomeFragment) getSupportFragmentManager().findFragmentByTag("homeFrag"); | |
| 191 | - if(homeFragment == null) { | |
| 192 | - homeFragment = homeFragment.newInstance(); | |
| 193 | - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); | |
| 194 | - ft.replace(R.id.rl_fragment_container, homeFragment, "homeFrag"); | |
| 195 | - ft.commit(); | |
| 196 | - } | |
| 197 | - break; | |
| 198 | - | |
| 199 | - | |
| 200 | - case 2: | |
| 201 | - startActivity(new Intent(getApplicationContext(), PoliticosActivity.class)); | |
| 202 | - break; | |
| 203 | - | |
| 204 | - case 3: | |
| 205 | - startActivity(new Intent(getApplicationContext(),ProjetosActivity.class)); | |
| 206 | - break; | |
| 207 | - | |
| 208 | - case 4: | |
| 209 | - startActivity(new Intent(getApplicationContext(), CamaraActivity.class)); | |
| 210 | - break; | |
| 211 | - case 5: | |
| 212 | - startActivity(new Intent(getApplicationContext(), SobreActivity.class)); | |
| 213 | - break; | |
| 214 | - | |
| 215 | - } | |
| 216 | - navigationDrawerLeft.closeDrawer(); | |
| 217 | - | |
| 218 | - return true; | |
| 219 | - } | |
| 220 | - }) | |
| 221 | - .build(); | |
| 222 | - | |
| 223 | - | |
| 224 | - } | |
| 225 | - | |
| 226 | - | |
| 227 | - | |
| 228 | - | |
| 229 | - @Override | |
| 230 | - public boolean onCreateOptionsMenu(Menu menu) { | |
| 231 | - // Inflate the menu; this adds items to the action bar if it is present. | |
| 232 | - getMenuInflater().inflate(R.menu.menu_main, menu); | |
| 233 | - return true; | |
| 234 | - } | |
| 235 | - | |
| 236 | - @Override | |
| 237 | - public boolean onOptionsItemSelected(MenuItem item) { | |
| 238 | - // Handle action bar item clicks here. The action bar will | |
| 239 | - // automatically handle clicks on the Home/Up button, so long | |
| 240 | - // as you specify a parent activity in AndroidManifest.xml. | |
| 241 | - int id = item.getItemId(); | |
| 242 | - | |
| 243 | - //noinspection SimplifiableIfStatement | |
| 244 | - if (id == R.id.action_sobre) { | |
| 245 | - startActivity(new Intent(getApplicationContext(),SobreActivity.class)); | |
| 246 | - return true; | |
| 247 | - } | |
| 248 | - | |
| 249 | - return super.onOptionsItemSelected(item); | |
| 250 | - } | |
| 251 | - | |
| 252 | - @Override | |
| 253 | - public void onBackPressed() { | |
| 254 | - if(navigationDrawerLeft.isDrawerOpen()){ | |
| 255 | - navigationDrawerLeft.closeDrawer(); | |
| 256 | - } | |
| 257 | - /*else if(fab.isOpened()){ | |
| 258 | - fab.close(true); | |
| 259 | - }*/ | |
| 260 | - else{ | |
| 261 | - super.onBackPressed(); | |
| 262 | - } | |
| 263 | - } | |
| 264 | - | |
| 265 | - | |
| 266 | - @Override | |
| 267 | - public void onFragmentInteraction(Uri uri) { | |
| 268 | - | |
| 269 | - } | |
| 270 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/PoliticoFichaActivity.java
| ... | ... | @@ -1,214 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo; | |
| 2 | - | |
| 3 | -import android.content.Intent; | |
| 4 | -import android.content.res.Configuration; | |
| 5 | -import android.os.Bundle; | |
| 6 | -import android.support.design.widget.CollapsingToolbarLayout; | |
| 7 | -import android.support.design.widget.CoordinatorLayout; | |
| 8 | -import android.support.design.widget.FloatingActionButton; | |
| 9 | -import android.support.design.widget.TabLayout; | |
| 10 | -import android.support.v4.app.Fragment; | |
| 11 | -import android.support.v4.app.FragmentManager; | |
| 12 | -import android.support.v4.app.FragmentStatePagerAdapter; | |
| 13 | -import android.support.v4.view.ViewPager; | |
| 14 | -import android.support.v7.app.AppCompatActivity; | |
| 15 | -import android.support.v7.widget.Toolbar; | |
| 16 | -import android.view.Menu; | |
| 17 | -import android.view.MenuItem; | |
| 18 | -import android.view.View; | |
| 19 | - | |
| 20 | -import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 21 | -import com.monitorabrasil.monitoralegislativo.fragments.GastosFragment; | |
| 22 | -import com.monitorabrasil.monitoralegislativo.fragments.ListaProjetosFragment; | |
| 23 | -import com.monitorabrasil.monitoralegislativo.fragments.PoliticoFichaFragment; | |
| 24 | -import com.parse.ParseObject; | |
| 25 | -import com.parse.ParseQuery; | |
| 26 | - | |
| 27 | -import java.util.ArrayList; | |
| 28 | -import java.util.List; | |
| 29 | - | |
| 30 | -public class PoliticoFichaActivity extends AppCompatActivity { | |
| 31 | - | |
| 32 | - Toolbar toolbar; | |
| 33 | - CollapsingToolbarLayout collapsingToolbarLayout; | |
| 34 | - TabLayout tabLayout; | |
| 35 | - String idPolitico; | |
| 36 | - | |
| 37 | - | |
| 38 | - | |
| 39 | -// ActionBarDrawerToggle drawerToggle; | |
| 40 | - | |
| 41 | - CoordinatorLayout rootLayout; | |
| 42 | - | |
| 43 | - @Override | |
| 44 | - protected void onCreate(Bundle savedInstanceState) { | |
| 45 | - super.onCreate(savedInstanceState); | |
| 46 | - setContentView(R.layout.activity_politico_ficha); | |
| 47 | - | |
| 48 | - | |
| 49 | - initInstances(); | |
| 50 | - initToolbar(); | |
| 51 | - | |
| 52 | - Bundle bundle = getIntent().getExtras(); | |
| 53 | - idPolitico = bundle.getString("politico"); | |
| 54 | - buscaPolitico(idPolitico) ; | |
| 55 | - | |
| 56 | - // buscaGrafico(); | |
| 57 | - //montaFicha(); | |
| 58 | - | |
| 59 | - ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); | |
| 60 | - if (viewPager != null) { | |
| 61 | - setupViewPager(viewPager); | |
| 62 | - } | |
| 63 | - | |
| 64 | - setSupportActionBar(toolbar); | |
| 65 | - getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 66 | - | |
| 67 | - FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); | |
| 68 | - fab.setOnClickListener(new View.OnClickListener() { | |
| 69 | - @Override | |
| 70 | - public void onClick(View view) { | |
| 71 | - Intent mIntent = new Intent(MyApp.getInstance().getApplicationContext(), ComentarioActivity.class); | |
| 72 | - mIntent.putExtra("politico", idPolitico); | |
| 73 | - | |
| 74 | - mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
| 75 | - | |
| 76 | - MyApp.getInstance().startActivity(mIntent); | |
| 77 | - | |
| 78 | - } | |
| 79 | - }); | |
| 80 | - | |
| 81 | - | |
| 82 | - | |
| 83 | - | |
| 84 | - } | |
| 85 | - | |
| 86 | - private void setupViewPager(ViewPager viewPager) { | |
| 87 | - Adapter adapter = new Adapter(getSupportFragmentManager()); | |
| 88 | - PoliticoFichaFragment ficha = new PoliticoFichaFragment(); | |
| 89 | - ficha.setArguments(getIntent().getExtras()); | |
| 90 | - adapter.addFragment(ficha, "Ficha"); | |
| 91 | - GastosFragment gastos = new GastosFragment(); | |
| 92 | - gastos.setArguments(getIntent().getExtras()); | |
| 93 | - adapter.addFragment(gastos, "Gastos"); | |
| 94 | - | |
| 95 | - //projetos | |
| 96 | - ListaProjetosFragment listaProjetosFragment = ListaProjetosFragment.newInstance(null,idPolitico); | |
| 97 | - // listaProjetosFragment.setArguments(getIntent().getExtras()); | |
| 98 | - adapter.addFragment(listaProjetosFragment, "Projetos"); | |
| 99 | - | |
| 100 | - viewPager.setAdapter(adapter); | |
| 101 | - viewPager.getAdapter().notifyDataSetChanged(); | |
| 102 | - | |
| 103 | - tabLayout = (TabLayout) findViewById(R.id.tabLayout); | |
| 104 | - tabLayout.setupWithViewPager(viewPager); | |
| 105 | - } | |
| 106 | - | |
| 107 | - | |
| 108 | - | |
| 109 | - private ParseObject buscaPolitico(String id) { | |
| 110 | - | |
| 111 | - ParseQuery<ParseObject> query = ParseQuery.getQuery("Politico"); | |
| 112 | - query.fromLocalDatastore(); | |
| 113 | - try { | |
| 114 | - ParseObject politico = query.get(id); | |
| 115 | - setTitle(politico.get("nome").toString()); | |
| 116 | -// collapsingToolbarLayout.setTitle(politico.get("nome").toString()); | |
| 117 | - } catch (com.parse.ParseException e) { | |
| 118 | - e.printStackTrace(); | |
| 119 | - } | |
| 120 | - return null; | |
| 121 | - } | |
| 122 | - | |
| 123 | - private void initToolbar() { | |
| 124 | - toolbar = (Toolbar) findViewById(R.id.toolbar); | |
| 125 | - setSupportActionBar(toolbar); | |
| 126 | - } | |
| 127 | - | |
| 128 | - private void initInstances() { | |
| 129 | -// drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout); | |
| 130 | -// drawerToggle = new ActionBarDrawerToggle(PoliticoFichaActivity.this, drawerLayout, R.string.hello_world, R.string.hello_world); | |
| 131 | -// drawerLayout.setDrawerListener(drawerToggle); | |
| 132 | - | |
| 133 | -// getSupportActionBar().setHomeButtonEnabled(true); | |
| 134 | -// getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 135 | - | |
| 136 | - rootLayout = (CoordinatorLayout) findViewById(R.id.main_content); | |
| 137 | - | |
| 138 | - | |
| 139 | - | |
| 140 | - | |
| 141 | - //collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); | |
| 142 | - | |
| 143 | - | |
| 144 | - | |
| 145 | - | |
| 146 | - | |
| 147 | - } | |
| 148 | - | |
| 149 | - @Override | |
| 150 | - public void onPostCreate(Bundle savedInstanceState) { | |
| 151 | - super.onPostCreate(savedInstanceState); | |
| 152 | -// drawerToggle.syncState(); | |
| 153 | - } | |
| 154 | - | |
| 155 | - @Override | |
| 156 | - public void onConfigurationChanged(Configuration newConfig) { | |
| 157 | - super.onConfigurationChanged(newConfig); | |
| 158 | -// drawerToggle.onConfigurationChanged(newConfig); | |
| 159 | - } | |
| 160 | - | |
| 161 | - @Override | |
| 162 | - public boolean onCreateOptionsMenu(Menu menu) { | |
| 163 | - // Inflate the menu; this adds items to the action bar if it is present. | |
| 164 | - getMenuInflater().inflate(R.menu.menu_main, menu); | |
| 165 | - return true; | |
| 166 | - } | |
| 167 | - | |
| 168 | - @Override | |
| 169 | - public boolean onOptionsItemSelected(MenuItem item) { | |
| 170 | -// if (drawerToggle.onOptionsItemSelected(item)) | |
| 171 | -// return true; | |
| 172 | - | |
| 173 | - // Handle action bar item clicks here. The action bar will | |
| 174 | - // automatically handle clicks on the Home/Up button, so long | |
| 175 | - // as you specify a parent activity in AndroidManifest.xml. | |
| 176 | - int id = item.getItemId(); | |
| 177 | - | |
| 178 | - //noinspection SimplifiableIfStatement | |
| 179 | - | |
| 180 | - | |
| 181 | - return super.onOptionsItemSelected(item); | |
| 182 | - } | |
| 183 | - | |
| 184 | - static class Adapter extends FragmentStatePagerAdapter { | |
| 185 | - private final List<Fragment> mFragments = new ArrayList<>(); | |
| 186 | - private final List<String> mFragmentTitles = new ArrayList<>(); | |
| 187 | - | |
| 188 | - public Adapter(FragmentManager fm) { | |
| 189 | - super(fm); | |
| 190 | - } | |
| 191 | - | |
| 192 | - public void addFragment(Fragment fragment, String title) { | |
| 193 | - mFragments.add(fragment); | |
| 194 | - mFragmentTitles.add(title); | |
| 195 | - } | |
| 196 | - | |
| 197 | - @Override | |
| 198 | - public Fragment getItem(int position) { | |
| 199 | - | |
| 200 | - return mFragments.get(position); | |
| 201 | - } | |
| 202 | - | |
| 203 | - | |
| 204 | - @Override | |
| 205 | - public int getCount() { | |
| 206 | - return mFragments.size(); | |
| 207 | - } | |
| 208 | - | |
| 209 | - @Override | |
| 210 | - public CharSequence getPageTitle(int position) { | |
| 211 | - return mFragmentTitles.get(position); | |
| 212 | - } | |
| 213 | - } | |
| 214 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/PoliticosActivity.java
| ... | ... | @@ -1,69 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo; | |
| 2 | - | |
| 3 | -import android.support.v4.app.FragmentTransaction; | |
| 4 | -import android.support.v7.app.ActionBarActivity; | |
| 5 | -import android.os.Bundle; | |
| 6 | -import android.support.v7.app.AppCompatActivity; | |
| 7 | -import android.support.v7.widget.Toolbar; | |
| 8 | -import android.view.Menu; | |
| 9 | -import android.view.MenuItem; | |
| 10 | - | |
| 11 | -import com.crashlytics.android.answers.Answers; | |
| 12 | -import com.crashlytics.android.answers.ContentViewEvent; | |
| 13 | -import com.monitorabrasil.monitoralegislativo.R; | |
| 14 | -import com.monitorabrasil.monitoralegislativo.fragments.ListaPoliticoFragment; | |
| 15 | - | |
| 16 | -public class PoliticosActivity extends AppCompatActivity { | |
| 17 | - | |
| 18 | - @Override | |
| 19 | - protected void onCreate(Bundle savedInstanceState) { | |
| 20 | - super.onCreate(savedInstanceState); | |
| 21 | - setContentView(R.layout.activity_politicos); | |
| 22 | - | |
| 23 | - Answers.getInstance().logContentView(new ContentViewEvent() | |
| 24 | - .putContentName("PoliticosActivity") | |
| 25 | - .putContentType("Activity")); | |
| 26 | - | |
| 27 | - ListaPoliticoFragment frag = (ListaPoliticoFragment) getSupportFragmentManager().findFragmentByTag("listaPoliticoFrag"); | |
| 28 | - if(frag == null) { | |
| 29 | - frag = new ListaPoliticoFragment(); | |
| 30 | - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); | |
| 31 | - ft.replace(R.id.rl_fragment_container, frag, "listaPoliticoFrag"); | |
| 32 | - ft.commit(); | |
| 33 | - } | |
| 34 | - | |
| 35 | - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
| 36 | - setSupportActionBar(toolbar); | |
| 37 | - | |
| 38 | - // toolbar.setNavigationIcon(R.drawable.ic_good); | |
| 39 | - toolbar.setTitle("Vereadores"); | |
| 40 | - toolbar.setSubtitle("Ouro Branco - MG"); | |
| 41 | - | |
| 42 | - toolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 43 | - toolbar.setSubtitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 44 | - setSupportActionBar(toolbar); | |
| 45 | - getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 46 | - // toolbar.setLogo(R.drawable.ic_launcher); | |
| 47 | - } | |
| 48 | - | |
| 49 | - | |
| 50 | - @Override | |
| 51 | - public boolean onCreateOptionsMenu(Menu menu) { | |
| 52 | - // Inflate the menu; this adds items to the action bar if it is present. | |
| 53 | -// getMenuInflater().inflate(R.menu.menu_politicos, menu); | |
| 54 | - return true; | |
| 55 | - } | |
| 56 | - | |
| 57 | - @Override | |
| 58 | - public boolean onOptionsItemSelected(MenuItem item) { | |
| 59 | - // Handle action bar item clicks here. The action bar will | |
| 60 | - // automatically handle clicks on the Home/Up button, so long | |
| 61 | - // as you specify a parent activity in AndroidManifest.xml. | |
| 62 | - int id = item.getItemId(); | |
| 63 | - | |
| 64 | - //noinspection SimplifiableIfStatement | |
| 65 | - | |
| 66 | - | |
| 67 | - return super.onOptionsItemSelected(item); | |
| 68 | - } | |
| 69 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/ProjetosActivity.java
| ... | ... | @@ -1,99 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo; | |
| 2 | - | |
| 3 | -import android.os.Bundle; | |
| 4 | -import android.support.v4.app.FragmentTransaction; | |
| 5 | -import android.support.v7.app.AppCompatActivity; | |
| 6 | -import android.support.v7.widget.Toolbar; | |
| 7 | -import android.view.Menu; | |
| 8 | -import android.view.MenuItem; | |
| 9 | - | |
| 10 | -import com.crashlytics.android.answers.Answers; | |
| 11 | -import com.crashlytics.android.answers.ContentViewEvent; | |
| 12 | -import com.monitorabrasil.monitoralegislativo.fragments.EscolhaTipoProjeto; | |
| 13 | - | |
| 14 | -public class ProjetosActivity extends AppCompatActivity { | |
| 15 | - | |
| 16 | - @Override | |
| 17 | - protected void onCreate(Bundle savedInstanceState) { | |
| 18 | - super.onCreate(savedInstanceState); | |
| 19 | - setContentView(R.layout.activity_projetos); | |
| 20 | - | |
| 21 | - | |
| 22 | - Answers.getInstance().logContentView(new ContentViewEvent() | |
| 23 | - .putContentName("ProjetosActivity") | |
| 24 | - .putContentType("Activity")); | |
| 25 | - | |
| 26 | - EscolhaTipoProjeto frag = (EscolhaTipoProjeto) getSupportFragmentManager().findFragmentByTag("listaTipoProjFrag"); | |
| 27 | - if(frag == null) { | |
| 28 | - frag = new EscolhaTipoProjeto(); | |
| 29 | - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); | |
| 30 | - ft.replace(R.id.rl_fragment_container, frag, "listaTipoProjFrag"); | |
| 31 | - ft.commit(); | |
| 32 | - } | |
| 33 | - | |
| 34 | - /*ListaProjetosFragment frag = (ListaProjetosFragment) getSupportFragmentManager().findFragmentByTag("listaProjFrag"); | |
| 35 | - if(frag == null) { | |
| 36 | - frag = new ListaProjetosFragment(); | |
| 37 | - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); | |
| 38 | - ft.replace(R.id.rl_fragment_container, frag, "listaProjFrag"); | |
| 39 | - ft.commit(); | |
| 40 | - }*/ | |
| 41 | - | |
| 42 | - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
| 43 | - setSupportActionBar(toolbar); | |
| 44 | - | |
| 45 | - // toolbar.setNavigationIcon(R.drawable.ic_good); | |
| 46 | - toolbar.setTitle("Indicações"); | |
| 47 | - toolbar.setSubtitle("Ouro Branco - MG"); | |
| 48 | - | |
| 49 | - toolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 50 | - toolbar.setSubtitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 51 | - setSupportActionBar(toolbar); | |
| 52 | - getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 53 | - } | |
| 54 | - | |
| 55 | - @Override | |
| 56 | - public boolean onCreateOptionsMenu(Menu menu) { | |
| 57 | - // Inflate the menu; this adds items to the action bar if it is present. | |
| 58 | - getMenuInflater().inflate(R.menu.menu_projetos, menu); | |
| 59 | - /* MenuItem searchItem = menu.findItem(R.id.ic_procura); | |
| 60 | - | |
| 61 | - SearchView searchView = (SearchView) searchItem.getActionView(); | |
| 62 | - | |
| 63 | - SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); | |
| 64 | - searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); | |
| 65 | - searchView.setIconifiedByDefault(true); | |
| 66 | - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { | |
| 67 | - | |
| 68 | - @Override | |
| 69 | - public boolean onQueryTextSubmit(String query) { | |
| 70 | - if (!query.isEmpty()) { | |
| 71 | - //realizar a busca | |
| 72 | - System.out.println(query); | |
| 73 | - } | |
| 74 | - | |
| 75 | - return false; | |
| 76 | - } | |
| 77 | - | |
| 78 | - @Override | |
| 79 | - public boolean onQueryTextChange(String newText) { | |
| 80 | - | |
| 81 | - return false; | |
| 82 | - } | |
| 83 | - });*/ | |
| 84 | - return true; | |
| 85 | - } | |
| 86 | - | |
| 87 | - @Override | |
| 88 | - public boolean onOptionsItemSelected(MenuItem item) { | |
| 89 | - // Handle action bar item clicks here. The action bar will | |
| 90 | - // automatically handle clicks on the Home/Up button, so long | |
| 91 | - // as you specify a parent activity in AndroidManifest.xml. | |
| 92 | - int id = item.getItemId(); | |
| 93 | - | |
| 94 | - //noinspection SimplifiableIfStatement | |
| 95 | - | |
| 96 | - | |
| 97 | - return super.onOptionsItemSelected(item); | |
| 98 | - } | |
| 99 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/SobreActivity.java
| ... | ... | @@ -1,71 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo; | |
| 2 | - | |
| 3 | -import android.content.pm.PackageManager; | |
| 4 | -import android.support.v7.app.ActionBarActivity; | |
| 5 | -import android.os.Bundle; | |
| 6 | -import android.support.v7.app.AppCompatActivity; | |
| 7 | -import android.support.v7.widget.Toolbar; | |
| 8 | -import android.text.Html; | |
| 9 | -import android.text.method.LinkMovementMethod; | |
| 10 | -import android.view.Menu; | |
| 11 | -import android.view.MenuItem; | |
| 12 | -import android.widget.TextView; | |
| 13 | - | |
| 14 | -import com.crashlytics.android.answers.Answers; | |
| 15 | -import com.crashlytics.android.answers.ContentViewEvent; | |
| 16 | -import com.monitorabrasil.monitoralegislativo.R; | |
| 17 | - | |
| 18 | -import org.w3c.dom.Text; | |
| 19 | - | |
| 20 | -public class SobreActivity extends AppCompatActivity { | |
| 21 | - | |
| 22 | - Toolbar toolbar; | |
| 23 | - | |
| 24 | - @Override | |
| 25 | - protected void onCreate(Bundle savedInstanceState) { | |
| 26 | - super.onCreate(savedInstanceState); | |
| 27 | - setContentView(R.layout.activity_sobre); | |
| 28 | - initToolbar(); | |
| 29 | - toolbar.setTitle("Sobre"); | |
| 30 | - setSupportActionBar(toolbar); | |
| 31 | - getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 32 | - | |
| 33 | - | |
| 34 | - | |
| 35 | - TextView versao = (TextView)findViewById(R.id.versao); | |
| 36 | - try { | |
| 37 | - versao.setText("Versão: "+getPackageManager().getPackageInfo(getPackageName(), 0).versionName); | |
| 38 | - } catch (PackageManager.NameNotFoundException e) { | |
| 39 | - e.printStackTrace(); | |
| 40 | - } | |
| 41 | - | |
| 42 | - Answers.getInstance().logContentView(new ContentViewEvent() | |
| 43 | - .putContentName("SobreActivity") | |
| 44 | - .putContentType("Activity")); | |
| 45 | - } | |
| 46 | - | |
| 47 | - private void initToolbar() { | |
| 48 | - toolbar = (Toolbar) findViewById(R.id.toolbar); | |
| 49 | - setSupportActionBar(toolbar); | |
| 50 | - } | |
| 51 | - | |
| 52 | - @Override | |
| 53 | - public boolean onCreateOptionsMenu(Menu menu) { | |
| 54 | - // Inflate the menu; this adds items to the action bar if it is present. | |
| 55 | - getMenuInflater().inflate(R.menu.menu_sobre, menu); | |
| 56 | - return true; | |
| 57 | - } | |
| 58 | - | |
| 59 | - @Override | |
| 60 | - public boolean onOptionsItemSelected(MenuItem item) { | |
| 61 | - // Handle action bar item clicks here. The action bar will | |
| 62 | - // automatically handle clicks on the Home/Up button, so long | |
| 63 | - // as you specify a parent activity in AndroidManifest.xml. | |
| 64 | - int id = item.getItemId(); | |
| 65 | - | |
| 66 | - //noinspection SimplifiableIfStatement | |
| 67 | - | |
| 68 | - | |
| 69 | - return super.onOptionsItemSelected(item); | |
| 70 | - } | |
| 71 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/actions/Action.java
0 → 100644
| ... | ... | @@ -0,0 +1,62 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.actions; | |
| 2 | + | |
| 3 | +import java.util.HashMap; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * Created by Geraldo on 13/08/2015. | |
| 7 | + */ | |
| 8 | +public class Action { | |
| 9 | + private final String type; | |
| 10 | + private final HashMap<String, Object> data; | |
| 11 | + | |
| 12 | + Action(String type, HashMap<String, Object> data) { | |
| 13 | + this.type = type; | |
| 14 | + this.data = data; | |
| 15 | + } | |
| 16 | + | |
| 17 | + public static Builder type(String type) { | |
| 18 | + return new Builder().with(type); | |
| 19 | + } | |
| 20 | + | |
| 21 | + public String getType() { | |
| 22 | + return type; | |
| 23 | + } | |
| 24 | + | |
| 25 | + public HashMap getData() { | |
| 26 | + return data; | |
| 27 | + } | |
| 28 | + | |
| 29 | + public static class Builder { | |
| 30 | + | |
| 31 | + private String type; | |
| 32 | + private HashMap<String, Object> data; | |
| 33 | + | |
| 34 | + Builder with(String type) { | |
| 35 | + if (type == null) { | |
| 36 | + throw new IllegalArgumentException("Type may not be null."); | |
| 37 | + } | |
| 38 | + this.type = type; | |
| 39 | + this.data = new HashMap<>(); | |
| 40 | + return this; | |
| 41 | + } | |
| 42 | + | |
| 43 | + public Builder bundle(String key, Object value) { | |
| 44 | + if (key == null) { | |
| 45 | + throw new IllegalArgumentException("Key may not be null."); | |
| 46 | + } | |
| 47 | + | |
| 48 | + if (value == null) { | |
| 49 | + throw new IllegalArgumentException("Value may not be null."); | |
| 50 | + } | |
| 51 | + data.put(key, value); | |
| 52 | + return this; | |
| 53 | + } | |
| 54 | + | |
| 55 | + public Action build() { | |
| 56 | + if (type == null || type.isEmpty()) { | |
| 57 | + throw new IllegalArgumentException("At least one key is required."); | |
| 58 | + } | |
| 59 | + return new Action(type, data); | |
| 60 | + } | |
| 61 | + } | |
| 62 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/actions/ActionsCreator.java
0 → 100644
| ... | ... | @@ -0,0 +1,75 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.actions; | |
| 2 | + | |
| 3 | +import com.monitorabrasil.monitoralegislativo.dispatcher.Dispatcher; | |
| 4 | +import com.parse.LogInCallback; | |
| 5 | +import com.parse.LogOutCallback; | |
| 6 | +import com.parse.ParseUser; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * Created by 89741803168 on 13/08/2015. | |
| 10 | + */ | |
| 11 | +public class ActionsCreator { | |
| 12 | + private static ActionsCreator instance; | |
| 13 | + final Dispatcher dispatcher; | |
| 14 | + | |
| 15 | + ActionsCreator(Dispatcher dispatcher) { | |
| 16 | + this.dispatcher = dispatcher; | |
| 17 | + } | |
| 18 | + | |
| 19 | + public static ActionsCreator get(Dispatcher dispatcher) { | |
| 20 | + if (instance == null) { | |
| 21 | + instance = new ActionsCreator(dispatcher); | |
| 22 | + } | |
| 23 | + return instance; | |
| 24 | + } | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * Actions do usuario - logar | |
| 28 | + * @param inputUsuario | |
| 29 | + * @param inputSenha | |
| 30 | + */ | |
| 31 | + | |
| 32 | + public void logar(String inputUsuario, String inputSenha){ | |
| 33 | + | |
| 34 | + | |
| 35 | + ParseUser.logInInBackground(inputUsuario, inputSenha, new LogInCallback() { | |
| 36 | + | |
| 37 | + @Override | |
| 38 | + public void done(ParseUser parseUser, com.parse.ParseException e) { | |
| 39 | + if (parseUser != null) { | |
| 40 | + dispatcher.dispatch( | |
| 41 | + UserActions.USER_LOGAR, | |
| 42 | + UserActions.KEY_TEXT, "sucesso" | |
| 43 | + ); | |
| 44 | + } else { | |
| 45 | + dispatcher.dispatch( | |
| 46 | + UserActions.USER_LOGAR, | |
| 47 | + UserActions.KEY_TEXT, "erro" | |
| 48 | + ); | |
| 49 | + } | |
| 50 | + } | |
| 51 | + | |
| 52 | + | |
| 53 | + }); | |
| 54 | + | |
| 55 | + } | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * Actions do usuario - logout | |
| 59 | + */ | |
| 60 | + public void logout(){ | |
| 61 | + ParseUser.logOutInBackground(new LogOutCallback() { | |
| 62 | + @Override | |
| 63 | + public void done(com.parse.ParseException e) { | |
| 64 | + dispatcher.dispatch( | |
| 65 | + UserActions.USER_LOGOUT, | |
| 66 | + UserActions.KEY_TEXT, "sucesso" | |
| 67 | + ); | |
| 68 | + } | |
| 69 | + }); | |
| 70 | + } | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/actions/UserActions.java
0 → 100644
| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.actions; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Created by Geraldo on 13/08/2015. | |
| 5 | + */ | |
| 6 | +public interface UserActions { | |
| 7 | + String USER_LOGAR = "user-logar"; | |
| 8 | + String USER_LOGOUT = "user-logout"; | |
| 9 | + | |
| 10 | + String KEY_TEXT = "key-text"; | |
| 11 | + String KEY_ID = "key-id"; | |
| 12 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/adapters/ComentarioAdapter.java
| ... | ... | @@ -1,75 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo.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.TextView; | |
| 8 | - | |
| 9 | -import com.monitorabrasil.monitoralegislativo.R; | |
| 10 | -import com.monitorabrasil.monitoralegislativo.interfaces.RecyclerViewOnClickListenerHack; | |
| 11 | -import com.parse.ParseObject; | |
| 12 | - | |
| 13 | -import java.util.List; | |
| 14 | - | |
| 15 | -/** | |
| 16 | - * Created by geral_000 on 05/07/2015. | |
| 17 | - */ | |
| 18 | -public class ComentarioAdapter extends RecyclerView.Adapter<ComentarioAdapter.ViewHolder> { | |
| 19 | - | |
| 20 | - private List<ParseObject> mDataset; | |
| 21 | - private RecyclerViewOnClickListenerHack mRecyclerViewOnClickListenerHack; | |
| 22 | - | |
| 23 | - // Provide a reference to the views for each data item | |
| 24 | - // Complex data items may need more than one view per item, and | |
| 25 | - // you provide access to all the views for a data item in a view holder | |
| 26 | - public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ | |
| 27 | - // each data item is just a string in this case | |
| 28 | - public TextView txtUser; | |
| 29 | - public TextView txtComentario; | |
| 30 | - public ViewHolder(View v) { | |
| 31 | - super(v); | |
| 32 | - txtUser = (TextView) v.findViewById(R.id.txtUser); | |
| 33 | - txtComentario = (TextView) v.findViewById(R.id.txtComentario); | |
| 34 | - | |
| 35 | - itemView.setOnClickListener(this); | |
| 36 | - } | |
| 37 | - | |
| 38 | - @Override | |
| 39 | - public void onClick(View v) { | |
| 40 | - if(mRecyclerViewOnClickListenerHack != null){ | |
| 41 | - mRecyclerViewOnClickListenerHack.onClickListener(v, getPosition()); | |
| 42 | - } | |
| 43 | - } | |
| 44 | - } | |
| 45 | - | |
| 46 | - public ComentarioAdapter(List<ParseObject> myDataset) { | |
| 47 | - mDataset = myDataset; | |
| 48 | - } | |
| 49 | - | |
| 50 | - @Override | |
| 51 | - public ComentarioAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { | |
| 52 | - // create a new view | |
| 53 | - View v = LayoutInflater.from(viewGroup.getContext()) | |
| 54 | - .inflate(R.layout.item_comentario, viewGroup, false); | |
| 55 | - // set the view's size, margins, paddings and layout parameter | |
| 56 | - ViewHolder vh = new ViewHolder(v); | |
| 57 | - return vh; | |
| 58 | - } | |
| 59 | - public void setRecyclerViewOnClickListenerHack(RecyclerViewOnClickListenerHack r){ | |
| 60 | - mRecyclerViewOnClickListenerHack = r; | |
| 61 | - } | |
| 62 | - | |
| 63 | - @Override | |
| 64 | - public void onBindViewHolder(ComentarioAdapter.ViewHolder viewHolder, int i) { | |
| 65 | - ParseObject comentario = mDataset.get(i); | |
| 66 | - // vereador.pinInBackground(); | |
| 67 | - viewHolder.txtUser.setText(comentario.get("nome").toString()); | |
| 68 | - viewHolder.txtComentario.setText(comentario.get("mensagem").toString()); | |
| 69 | - } | |
| 70 | - | |
| 71 | - @Override | |
| 72 | - public int getItemCount() { | |
| 73 | - return mDataset.size(); | |
| 74 | - } | |
| 75 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/adapters/GastoAdapter.java
| ... | ... | @@ -1,206 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo.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.ProgressBar; | |
| 8 | -import android.widget.TextView; | |
| 9 | - | |
| 10 | -import com.crashlytics.android.Crashlytics; | |
| 11 | -import com.github.mikephil.charting.animation.Easing; | |
| 12 | -import com.github.mikephil.charting.charts.BarChart; | |
| 13 | -import com.github.mikephil.charting.components.Legend; | |
| 14 | -import com.github.mikephil.charting.components.XAxis; | |
| 15 | -import com.github.mikephil.charting.components.YAxis; | |
| 16 | -import com.github.mikephil.charting.data.BarData; | |
| 17 | -import com.github.mikephil.charting.data.BarDataSet; | |
| 18 | -import com.github.mikephil.charting.data.BarEntry; | |
| 19 | -import com.github.mikephil.charting.utils.ValueFormatter; | |
| 20 | -import com.monitorabrasil.monitoralegislativo.R; | |
| 21 | -import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 22 | -import com.monitorabrasil.monitoralegislativo.classes.Grafico; | |
| 23 | -import com.monitorabrasil.monitoralegislativo.interfaces.RecyclerViewOnClickListenerHack; | |
| 24 | -import com.monitorabrasil.monitoralegislativo.util.MyValueFormatter; | |
| 25 | - | |
| 26 | -import org.w3c.dom.Text; | |
| 27 | - | |
| 28 | -import java.util.ArrayList; | |
| 29 | -import java.util.List; | |
| 30 | - | |
| 31 | -/** | |
| 32 | - * Created by geral_000 on 26/06/2015. | |
| 33 | - */ | |
| 34 | -public class GastoAdapter extends RecyclerView.Adapter<GastoAdapter.ViewHolder> { | |
| 35 | - | |
| 36 | - private List<Grafico> mDataset; | |
| 37 | - private RecyclerViewOnClickListenerHack mRecyclerViewOnClickListenerHack; | |
| 38 | - | |
| 39 | - // Provide a reference to the views for each data item | |
| 40 | - // Complex data items may need more than one view per item, and | |
| 41 | - // you provide access to all the views for a data item in a view holder | |
| 42 | - public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ | |
| 43 | - // each data item is just a string in this case | |
| 44 | - | |
| 45 | - public BarChart chart; | |
| 46 | - public TextView titulo; | |
| 47 | - public ViewHolder(View v) { | |
| 48 | - super(v); | |
| 49 | - | |
| 50 | - chart = (BarChart) v.findViewById(R.id.chart1); | |
| 51 | - titulo = (TextView) v.findViewById(R.id.titulo); | |
| 52 | - | |
| 53 | - itemView.setOnClickListener(this); | |
| 54 | - } | |
| 55 | - | |
| 56 | - @Override | |
| 57 | - public void onClick(View v) { | |
| 58 | - if(mRecyclerViewOnClickListenerHack != null){ | |
| 59 | - mRecyclerViewOnClickListenerHack.onClickListener(v, getPosition()); | |
| 60 | - } | |
| 61 | - } | |
| 62 | - } | |
| 63 | - | |
| 64 | - public GastoAdapter(List<Grafico> myDataset) { | |
| 65 | - mDataset = myDataset; | |
| 66 | - } | |
| 67 | - | |
| 68 | - @Override | |
| 69 | - public GastoAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { | |
| 70 | - // create a new view | |
| 71 | - View v = LayoutInflater.from(viewGroup.getContext()) | |
| 72 | - .inflate(R.layout.item_grafico, viewGroup, false); | |
| 73 | - // set the view's size, margins, paddings and layout parameter | |
| 74 | - ViewHolder vh = new ViewHolder(v); | |
| 75 | - return vh; | |
| 76 | - } | |
| 77 | - public void setRecyclerViewOnClickListenerHack(RecyclerViewOnClickListenerHack r){ | |
| 78 | - mRecyclerViewOnClickListenerHack = r; | |
| 79 | - } | |
| 80 | - | |
| 81 | - @Override | |
| 82 | - public void onBindViewHolder(GastoAdapter.ViewHolder viewHolder, int i) { | |
| 83 | - | |
| 84 | - //construir grafico | |
| 85 | - buildGraph(viewHolder.chart); | |
| 86 | - //setdata | |
| 87 | - Grafico grafico = mDataset.get(i); | |
| 88 | - setData(grafico,viewHolder.chart); | |
| 89 | - | |
| 90 | - viewHolder.chart.animateX(2500, Easing.EasingOption.EaseInOutQuart); | |
| 91 | - viewHolder.chart.notifyDataSetChanged(); | |
| 92 | - | |
| 93 | - viewHolder.titulo.setText(grafico.getTitulo()); | |
| 94 | - //ParseObject vereador = mDataset.get(i); | |
| 95 | - //vereador.pinInBackground(); | |
| 96 | - //viewHolder.pb.setText(vereador.get("nome").toString()); | |
| 97 | - | |
| 98 | - } | |
| 99 | - | |
| 100 | - @Override | |
| 101 | - public int getItemCount() { | |
| 102 | - return mDataset.size(); | |
| 103 | - } | |
| 104 | - | |
| 105 | - private void buildGraph(BarChart mChart) { | |
| 106 | - | |
| 107 | -// mChart.set | |
| 108 | - | |
| 109 | - mChart.setDrawBarShadow(false); | |
| 110 | - mChart.setDrawValueAboveBar(true); | |
| 111 | - | |
| 112 | - mChart.setDescription(""); | |
| 113 | - | |
| 114 | - // if more than 60 entries are displayed in the chart, no values will be | |
| 115 | - // drawn | |
| 116 | - mChart.setMaxVisibleValueCount(60); | |
| 117 | - | |
| 118 | - // scaling can now only be done on x- and y-axis separately | |
| 119 | - mChart.setPinchZoom(false); | |
| 120 | - | |
| 121 | - // draw shadows for each bar that show the maximum value | |
| 122 | - // mChart.setDrawBarShadow(true); | |
| 123 | - | |
| 124 | - // mChart.setDrawXLabels(false); | |
| 125 | - | |
| 126 | - mChart.setDrawGridBackground(false); | |
| 127 | - // mChart.setDrawYLabels(false); | |
| 128 | - | |
| 129 | -// mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); | |
| 130 | - | |
| 131 | - XAxis xAxis = mChart.getXAxis(); | |
| 132 | - xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); | |
| 133 | -// xAxis.setTypeface(mTf); | |
| 134 | - xAxis.setDrawGridLines(false); | |
| 135 | - xAxis.setSpaceBetweenLabels(2); | |
| 136 | - | |
| 137 | - ValueFormatter custom = new MyValueFormatter(); | |
| 138 | - | |
| 139 | - YAxis leftAxis = mChart.getAxisLeft(); | |
| 140 | -// leftAxis.setTypeface(mTf); | |
| 141 | - leftAxis.setLabelCount(8); | |
| 142 | - leftAxis.setValueFormatter(custom); | |
| 143 | - leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART); | |
| 144 | - leftAxis.setSpaceTop(15f); | |
| 145 | - | |
| 146 | - mChart.getAxisRight().setEnabled(false); | |
| 147 | - YAxis rightAxis = mChart.getAxisRight(); | |
| 148 | - rightAxis.setDrawGridLines(false); | |
| 149 | -// rightAxis.setTypeface(mTf); | |
| 150 | - rightAxis.setLabelCount(8); | |
| 151 | - rightAxis.setValueFormatter(custom); | |
| 152 | - rightAxis.setSpaceTop(15f); | |
| 153 | - | |
| 154 | - Legend l = mChart.getLegend(); | |
| 155 | - l.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT); | |
| 156 | - l.setForm(Legend.LegendForm.SQUARE); | |
| 157 | - l.setFormSize(9f); | |
| 158 | - l.setTextSize(11f); | |
| 159 | - l.setXEntrySpace(4f); | |
| 160 | - // l.setExtra(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc", | |
| 161 | - // "def", "ghj", "ikl", "mno" }); | |
| 162 | - // l.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc", | |
| 163 | - // "def", "ghj", "ikl", "mno" }); | |
| 164 | - | |
| 165 | - | |
| 166 | - | |
| 167 | - // setting data | |
| 168 | -// mSeekBarY.setProgress(50); | |
| 169 | -// mSeekBarX.setProgress(12); | |
| 170 | -// | |
| 171 | -// mSeekBarY.setOnSeekBarChangeListener(this); | |
| 172 | -// mSeekBarX.setOnSeekBarChangeListener(this); | |
| 173 | - | |
| 174 | - // mChart.setDrawLegend(false); | |
| 175 | - | |
| 176 | - } | |
| 177 | - | |
| 178 | - private void setData(Grafico grafico, BarChart mChart) { | |
| 179 | - | |
| 180 | - | |
| 181 | - | |
| 182 | - BarDataSet set1 = new BarDataSet(grafico.getyAxis(), "Gastos Totais"); | |
| 183 | - set1.setBarSpacePercent(35f); | |
| 184 | - | |
| 185 | - ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>(); | |
| 186 | - dataSets.add(set1); | |
| 187 | - try{ | |
| 188 | - set1.setColor(MyApp.getInstance().getResources().getColor(grafico.getCor())); | |
| 189 | - | |
| 190 | - BarData data = new BarData(grafico.getxVals(), dataSets); | |
| 191 | - // data.setValueFormatter(new MyValueFormatter()); | |
| 192 | - data.setValueTextSize(10f); | |
| 193 | -// data.setValueTypeface(mTf); | |
| 194 | - mChart.setVisibility(View.VISIBLE); | |
| 195 | - mChart.setData(data); | |
| 196 | - | |
| 197 | - | |
| 198 | - | |
| 199 | - }catch (Exception e){ | |
| 200 | - Crashlytics.log("GastosCamaraFragment " + e.toString()); | |
| 201 | - } | |
| 202 | - | |
| 203 | - } | |
| 204 | - | |
| 205 | - | |
| 206 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/adapters/ProjetoAdapter.java
| ... | ... | @@ -1,293 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo.adapters; | |
| 2 | - | |
| 3 | -import android.content.Intent; | |
| 4 | -import android.graphics.drawable.Drawable; | |
| 5 | -import android.os.Build; | |
| 6 | -import android.os.Bundle; | |
| 7 | -import android.support.design.widget.Snackbar; | |
| 8 | -import android.support.v4.app.ActivityOptionsCompat; | |
| 9 | -import android.support.v4.app.FragmentActivity; | |
| 10 | -import android.support.v4.content.ContextCompat; | |
| 11 | -import android.support.v4.util.Pair; | |
| 12 | -import android.support.v7.widget.RecyclerView; | |
| 13 | -import android.view.LayoutInflater; | |
| 14 | -import android.view.View; | |
| 15 | -import android.view.ViewGroup; | |
| 16 | -import android.widget.Button; | |
| 17 | -import android.widget.TextView; | |
| 18 | - | |
| 19 | -import com.google.gson.Gson; | |
| 20 | -import com.monitorabrasil.monitoralegislativo.ComentarioActivity; | |
| 21 | -import com.monitorabrasil.monitoralegislativo.R; | |
| 22 | -import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 23 | -import com.monitorabrasil.monitoralegislativo.interfaces.RecyclerViewOnClickListenerHack; | |
| 24 | -import com.parse.FindCallback; | |
| 25 | -import com.parse.GetCallback; | |
| 26 | -import com.parse.ParseException; | |
| 27 | -import com.parse.ParseObject; | |
| 28 | -import com.parse.ParseQuery; | |
| 29 | -import com.parse.ParseUser; | |
| 30 | -import com.parse.SaveCallback; | |
| 31 | - | |
| 32 | -import java.util.List; | |
| 33 | - | |
| 34 | -/** | |
| 35 | - * Created by geral_000 on 25/06/2015. | |
| 36 | - */ | |
| 37 | -public class ProjetoAdapter extends RecyclerView.Adapter<ProjetoAdapter.ViewHolder> { | |
| 38 | - | |
| 39 | - private List<ParseObject> mDataset; | |
| 40 | - private RecyclerViewOnClickListenerHack mRecyclerViewOnClickListenerHack; | |
| 41 | - private FragmentActivity mActivity; | |
| 42 | - | |
| 43 | - public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ | |
| 44 | - // each data item is just a string in this case | |
| 45 | - public ParseObject projetoVotado; | |
| 46 | - public TextView classificacao; | |
| 47 | - public TextView data; | |
| 48 | - public TextView autor; | |
| 49 | - public TextView descricao; | |
| 50 | - public TextView numApoio; | |
| 51 | - public TextView numNaoApoio; | |
| 52 | - public TextView numero; | |
| 53 | - public Button btnConcordo; | |
| 54 | - public Button btnDiscordo; | |
| 55 | - public Button btnComentar; | |
| 56 | - public String voto; | |
| 57 | - public ParseObject projeto; | |
| 58 | - | |
| 59 | - public ViewHolder(View v) { | |
| 60 | - super(v); | |
| 61 | - classificacao = (TextView) v.findViewById(R.id.classificacao); | |
| 62 | - data = (TextView) v.findViewById(R.id.data); | |
| 63 | - autor = (TextView) v.findViewById(R.id.autor); | |
| 64 | - numApoio = (TextView) v.findViewById(R.id.txtNumApoio); | |
| 65 | - numNaoApoio = (TextView) v.findViewById(R.id.txtNumNaoApoio); | |
| 66 | - descricao = (TextView) v.findViewById(R.id.descricao); | |
| 67 | - btnConcordo = (Button) v.findViewById(R.id.btnConcordo); | |
| 68 | - btnDiscordo = (Button) v.findViewById(R.id.btnDiscordo); | |
| 69 | - btnComentar = (Button) v.findViewById(R.id.btnComentar); | |
| 70 | - numero = (TextView) v.findViewById(R.id.numero); | |
| 71 | - | |
| 72 | - itemView.setOnClickListener(this); | |
| 73 | - } | |
| 74 | - | |
| 75 | - @Override | |
| 76 | - public void onClick(View v) { | |
| 77 | - if(mRecyclerViewOnClickListenerHack != null){ | |
| 78 | - mRecyclerViewOnClickListenerHack.onClickListener(v, getPosition()); | |
| 79 | - } | |
| 80 | - } | |
| 81 | - } | |
| 82 | - | |
| 83 | - public ProjetoAdapter(List<ParseObject> myDataset, FragmentActivity activity) { | |
| 84 | - mDataset = myDataset; | |
| 85 | - mActivity = activity; | |
| 86 | - } | |
| 87 | - | |
| 88 | - @Override | |
| 89 | - public ProjetoAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { | |
| 90 | - // create a new view | |
| 91 | - View v = LayoutInflater.from(viewGroup.getContext()) | |
| 92 | - .inflate(R.layout.item_projeto, viewGroup, false); | |
| 93 | - // set the view's size, margins, paddings and layout parameter | |
| 94 | - ViewHolder vh = new ViewHolder(v); | |
| 95 | - return vh; | |
| 96 | - } | |
| 97 | - | |
| 98 | - @Override | |
| 99 | - public void onBindViewHolder(final ViewHolder viewHolder, int i) { | |
| 100 | - Drawable apoio = ContextCompat.getDrawable(MyApp.getInstance().getApplicationContext(), R.mipmap.ic_action_like_gray); | |
| 101 | - Drawable napoio = ContextCompat.getDrawable(MyApp.getInstance().getApplicationContext(), R.mipmap.ic_action_unlike_gray); | |
| 102 | - final Drawable napoioVermelho = ContextCompat.getDrawable(MyApp.getInstance().getApplicationContext(), R.mipmap.ic_action_unlike_red); | |
| 103 | - final Drawable apoioVerde = ContextCompat.getDrawable(MyApp.getInstance().getApplicationContext(), R.mipmap.ic_action_like_green); | |
| 104 | - | |
| 105 | - viewHolder.btnConcordo.setBackground(apoio); | |
| 106 | - viewHolder.btnDiscordo.setBackground(napoio); | |
| 107 | - | |
| 108 | - viewHolder.btnDiscordo.setEnabled(true); | |
| 109 | - viewHolder.btnConcordo.setEnabled(true); | |
| 110 | - viewHolder.voto = "sem_voto"; | |
| 111 | - final ParseObject projeto = mDataset.get(i); | |
| 112 | - viewHolder.projeto = projeto; | |
| 113 | - //verifica se ja votou | |
| 114 | - ParseQuery<ParseObject> query = ParseQuery.getQuery("Voto"); | |
| 115 | - query.fromLocalDatastore(); | |
| 116 | - query.whereEqualTo("projeto", projeto); | |
| 117 | - query.findInBackground(new FindCallback<ParseObject>() { | |
| 118 | - @Override | |
| 119 | - public void done(List<ParseObject> list, ParseException e) { | |
| 120 | - if (list.size() > 0) { | |
| 121 | - String voto = list.get(0).get("voto").toString(); | |
| 122 | - viewHolder.projetoVotado = list.get(0); | |
| 123 | - if (voto.equals("s")) { | |
| 124 | - viewHolder.btnConcordo.setBackground(apoioVerde); | |
| 125 | - viewHolder.btnConcordo.setEnabled(false); | |
| 126 | - viewHolder.voto = "apoioado"; | |
| 127 | - ; | |
| 128 | - } else { | |
| 129 | - viewHolder.btnDiscordo.setBackground(napoioVermelho); | |
| 130 | - viewHolder.btnDiscordo.setEnabled(false); | |
| 131 | - viewHolder.voto = "nao_apoioado"; | |
| 132 | - } | |
| 133 | - } | |
| 134 | - } | |
| 135 | - }); | |
| 136 | - | |
| 137 | - viewHolder.numero.setText("ID: "+projeto.getString("numero")); | |
| 138 | - viewHolder.classificacao.setText(projeto.get("classificacao").toString()); | |
| 139 | - viewHolder.data.setText(projeto.get("data").toString()); | |
| 140 | - viewHolder.descricao.setText(projeto.get("descricao").toString()); | |
| 141 | - int numComentario = 0; | |
| 142 | - if(projeto.get("nr_comentarios") != null){ | |
| 143 | - numComentario = Integer.valueOf( projeto.get("nr_comentarios").toString()); | |
| 144 | - } | |
| 145 | - viewHolder.btnComentar.setText(String.valueOf(numComentario)); | |
| 146 | - int num=0; | |
| 147 | - if(projeto.get("apoio") != null){ | |
| 148 | - num = Integer.valueOf( projeto.get("apoio").toString()); | |
| 149 | - } | |
| 150 | - | |
| 151 | - viewHolder.numApoio.setText(String.valueOf(num)); | |
| 152 | - num=0; | |
| 153 | - if(projeto.get("nao_apoio") != null){ | |
| 154 | - num = Integer.valueOf( projeto.get("nao_apoio").toString()); | |
| 155 | - } | |
| 156 | - viewHolder.numNaoApoio.setText(String.valueOf(num)); | |
| 157 | - ParseObject autor = (ParseObject) projeto.get("politico"); | |
| 158 | - try { | |
| 159 | - autor.fetchFromLocalDatastore(); | |
| 160 | - viewHolder.autor.setText(autor.get("nome").toString()); | |
| 161 | - } catch (ParseException e) { | |
| 162 | - e.printStackTrace(); | |
| 163 | - } | |
| 164 | - | |
| 165 | - viewHolder.btnConcordo.setOnClickListener(new View.OnClickListener() { | |
| 166 | - @Override | |
| 167 | - public void onClick(final View v) { | |
| 168 | - registraVoto(v, projeto, "s", viewHolder); | |
| 169 | - | |
| 170 | - } | |
| 171 | - }); | |
| 172 | - | |
| 173 | - viewHolder.btnDiscordo.setOnClickListener(new View.OnClickListener() { | |
| 174 | - @Override | |
| 175 | - public void onClick(View v) { | |
| 176 | - registraVoto(v, projeto, "n", viewHolder); | |
| 177 | - } | |
| 178 | - }); | |
| 179 | - | |
| 180 | - viewHolder.btnComentar.setOnClickListener(new View.OnClickListener() { | |
| 181 | - @Override | |
| 182 | - public void onClick(View v) { | |
| 183 | - Intent mIntent =new Intent(MyApp.getInstance().getApplicationContext(), ComentarioActivity.class); | |
| 184 | - Gson gson = new Gson(); | |
| 185 | - mIntent.putExtra("projeto",viewHolder.projeto.getObjectId()); | |
| 186 | - | |
| 187 | - mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
| 188 | - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ | |
| 189 | - View titulo = viewHolder.descricao; | |
| 190 | - ActivityOptionsCompat options = ActivityOptionsCompat. | |
| 191 | - makeSceneTransitionAnimation(mActivity, | |
| 192 | - Pair.create(titulo, "element1")); | |
| 193 | - mActivity.startActivity(mIntent, options.toBundle()); | |
| 194 | - }else{ | |
| 195 | - MyApp.getInstance().startActivity(mIntent); | |
| 196 | - } | |
| 197 | - | |
| 198 | - | |
| 199 | - } | |
| 200 | - }); | |
| 201 | - } | |
| 202 | - | |
| 203 | - private void registraVoto(final View v, ParseObject projeto, final String tipoVoto, final ViewHolder viewHolder2) { | |
| 204 | - | |
| 205 | - //verificar se esta logado | |
| 206 | - if(ParseUser.getCurrentUser() == null){ | |
| 207 | - Snackbar.make(v, "Para votar é necessário estar logado", Snackbar.LENGTH_LONG) | |
| 208 | - .setAction("Action", null).show(); | |
| 209 | - return; | |
| 210 | - } | |
| 211 | - | |
| 212 | - Drawable apoio = ContextCompat.getDrawable(MyApp.getInstance().getApplicationContext(), R.mipmap.ic_action_like_gray); | |
| 213 | - Drawable napoio = ContextCompat.getDrawable(MyApp.getInstance().getApplicationContext(), R.mipmap.ic_action_unlike_gray); | |
| 214 | - final Drawable napoioVermelho = ContextCompat.getDrawable(MyApp.getInstance().getApplicationContext(), R.mipmap.ic_action_unlike_red); | |
| 215 | - final Drawable apoioVerde = ContextCompat.getDrawable(MyApp.getInstance().getApplicationContext(), R.mipmap.ic_action_like_green); | |
| 216 | - | |
| 217 | - //verificar se ja votou nesse projeto | |
| 218 | - boolean votado; | |
| 219 | - if(viewHolder2.voto.equals("sem_voto")){ | |
| 220 | - | |
| 221 | - votado = false; | |
| 222 | - }else{ | |
| 223 | - votado=true; | |
| 224 | - | |
| 225 | - } | |
| 226 | - if(votado){ | |
| 227 | - | |
| 228 | - if(null!= viewHolder2.projetoVotado){ | |
| 229 | - viewHolder2.projetoVotado.unpinInBackground(); | |
| 230 | - viewHolder2.projetoVotado.deleteInBackground(); | |
| 231 | - } | |
| 232 | - | |
| 233 | - | |
| 234 | - | |
| 235 | - } | |
| 236 | - | |
| 237 | - ParseObject voto = new ParseObject("Voto"); | |
| 238 | - voto.put("projeto", projeto); | |
| 239 | - voto.put("user", ParseUser.getCurrentUser()); | |
| 240 | - voto.put("voto", tipoVoto); | |
| 241 | - Button btnVoto = (Button) v; | |
| 242 | - if(tipoVoto.equals("s")){ | |
| 243 | - if(votado){ | |
| 244 | - viewHolder2.numNaoApoio.setText(String.valueOf(Integer.valueOf(viewHolder2.numNaoApoio.getText().toString()) - 1)); | |
| 245 | - projeto.increment("nao_apoio", -1); | |
| 246 | - } | |
| 247 | - viewHolder2.numApoio.setText(String.valueOf(Integer.valueOf(viewHolder2.numApoio.getText().toString()) + 1)); | |
| 248 | - projeto.increment("apoio"); | |
| 249 | - btnVoto.setBackground(apoioVerde); | |
| 250 | - viewHolder2.btnDiscordo.setBackground(napoio); | |
| 251 | - viewHolder2.voto = "apoiado"; | |
| 252 | - viewHolder2.btnConcordo.setEnabled(false); | |
| 253 | - viewHolder2.btnDiscordo.setEnabled(true); | |
| 254 | - | |
| 255 | - }else{ | |
| 256 | - if(votado){ | |
| 257 | - viewHolder2.numApoio.setText(String.valueOf(Integer.valueOf(viewHolder2.numApoio.getText().toString()) - 1)); | |
| 258 | - projeto.increment("apoio", -1); | |
| 259 | - } | |
| 260 | - projeto.increment("nao_apoio"); | |
| 261 | - viewHolder2.numNaoApoio.setText(String.valueOf(Integer.valueOf(viewHolder2.numNaoApoio.getText().toString()) + 1)); | |
| 262 | - btnVoto.setBackground(napoioVermelho); | |
| 263 | - viewHolder2.btnConcordo.setBackground(apoio); | |
| 264 | - viewHolder2.voto = "nao_apoiado"; | |
| 265 | - viewHolder2.btnDiscordo.setEnabled(false); | |
| 266 | - viewHolder2.btnConcordo.setEnabled(true); | |
| 267 | - | |
| 268 | - } | |
| 269 | - projeto.saveInBackground(); | |
| 270 | - | |
| 271 | - try { | |
| 272 | - voto.pin(); | |
| 273 | - voto.saveInBackground(new SaveCallback() { | |
| 274 | - @Override | |
| 275 | - public void done(ParseException e) { | |
| 276 | - Snackbar.make(v, "Voto registrado", Snackbar.LENGTH_SHORT) | |
| 277 | - .setAction("Action", null).show(); | |
| 278 | - } | |
| 279 | - }); | |
| 280 | - } catch (ParseException e) { | |
| 281 | - e.printStackTrace(); | |
| 282 | - } | |
| 283 | - } | |
| 284 | - | |
| 285 | - public void setRecyclerViewOnClickListenerHack(RecyclerViewOnClickListenerHack r){ | |
| 286 | - mRecyclerViewOnClickListenerHack = r; | |
| 287 | - } | |
| 288 | - | |
| 289 | - @Override | |
| 290 | - public int getItemCount() { | |
| 291 | - return mDataset.size(); | |
| 292 | - } | |
| 293 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/adapters/TipoProjetoAdapter.java
| ... | ... | @@ -1,92 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo.adapters; | |
| 2 | - | |
| 3 | -import android.support.v4.app.FragmentActivity; | |
| 4 | -import android.support.v7.widget.RecyclerView; | |
| 5 | -import android.view.LayoutInflater; | |
| 6 | -import android.view.View; | |
| 7 | -import android.view.ViewGroup; | |
| 8 | -import android.widget.TextView; | |
| 9 | - | |
| 10 | -import com.monitorabrasil.monitoralegislativo.R; | |
| 11 | -import com.monitorabrasil.monitoralegislativo.interfaces.RecyclerViewOnClickListenerHack; | |
| 12 | -import com.parse.ParseObject; | |
| 13 | - | |
| 14 | -import java.util.List; | |
| 15 | - | |
| 16 | -/** | |
| 17 | - * Created by geral_000 on 23/07/2015. | |
| 18 | - */ | |
| 19 | -public class TipoProjetoAdapter extends RecyclerView.Adapter<TipoProjetoAdapter.ViewHolder> { | |
| 20 | - | |
| 21 | - private List<ParseObject> mDataset; | |
| 22 | - private RecyclerViewOnClickListenerHack mRecyclerViewOnClickListenerHack; | |
| 23 | - private FragmentActivity mActivity; | |
| 24 | - int[] cores = new int[]{R.color.cor1, R.color.cor2,R.color.cor3, R.color.cor4,R.color.cor5, R.color.cor6, | |
| 25 | - R.color.cor7, R.color.cor8,R.color.cor9, R.color.cor10}; | |
| 26 | - | |
| 27 | - public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ | |
| 28 | - // each data item is just a string in this case | |
| 29 | - | |
| 30 | - public TextView txtTipoProjeto; | |
| 31 | - public ParseObject tipoProjeto; | |
| 32 | - | |
| 33 | - public ViewHolder(View v) { | |
| 34 | - super(v); | |
| 35 | - txtTipoProjeto = (TextView) v.findViewById(R.id.txtTipoProjeto); | |
| 36 | - itemView.setOnClickListener(this); | |
| 37 | - } | |
| 38 | - | |
| 39 | - @Override | |
| 40 | - public void onClick(View v) { | |
| 41 | - if(mRecyclerViewOnClickListenerHack != null){ | |
| 42 | - mRecyclerViewOnClickListenerHack.onClickListener(v, getPosition()); | |
| 43 | - } | |
| 44 | - } | |
| 45 | - } | |
| 46 | - | |
| 47 | - public TipoProjetoAdapter(List<ParseObject> myDataset, FragmentActivity activity) { | |
| 48 | - mDataset = myDataset; | |
| 49 | - mActivity = activity; | |
| 50 | - } | |
| 51 | - | |
| 52 | - @Override | |
| 53 | - public TipoProjetoAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { | |
| 54 | - // create a new view | |
| 55 | - View v = LayoutInflater.from(viewGroup.getContext()) | |
| 56 | - .inflate(R.layout.item_tipo_projeto, viewGroup, false); | |
| 57 | - // set the view's size, margins, paddings and layout parameter | |
| 58 | - ViewHolder vh = new ViewHolder(v); | |
| 59 | - return vh; | |
| 60 | - } | |
| 61 | - | |
| 62 | - @Override | |
| 63 | - public void onBindViewHolder(final ViewHolder viewHolder, int i) { | |
| 64 | - | |
| 65 | - final ParseObject tipoProjeto = mDataset.get(i); | |
| 66 | - viewHolder.tipoProjeto = tipoProjeto; | |
| 67 | - | |
| 68 | - viewHolder.txtTipoProjeto.setText(tipoProjeto.getString("nome")); | |
| 69 | - int posCor=i; | |
| 70 | - if(i > 19) | |
| 71 | - posCor = i-20; | |
| 72 | - else | |
| 73 | - if(i > 9) | |
| 74 | - posCor = i-10; | |
| 75 | - | |
| 76 | - viewHolder.txtTipoProjeto.setBackgroundResource(cores[posCor]); | |
| 77 | - } | |
| 78 | - | |
| 79 | - | |
| 80 | - public void setRecyclerViewOnClickListenerHack(RecyclerViewOnClickListenerHack r){ | |
| 81 | - mRecyclerViewOnClickListenerHack = r; | |
| 82 | - } | |
| 83 | - | |
| 84 | - @Override | |
| 85 | - public int getItemCount() { | |
| 86 | - return mDataset.size(); | |
| 87 | - } | |
| 88 | - | |
| 89 | - public String getItem(int i){ | |
| 90 | - return mDataset.get(i).getString("nome"); | |
| 91 | - } | |
| 92 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/adapters/VereadorAdapter.java
| ... | ... | @@ -1,85 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo.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.monitoralegislativo.R; | |
| 12 | -import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 13 | -import com.monitorabrasil.monitoralegislativo.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/monitoralegislativo/classes/Grafico.java
| ... | ... | @@ -1,54 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo.classes; | |
| 2 | - | |
| 3 | -import com.github.mikephil.charting.data.BarEntry; | |
| 4 | - | |
| 5 | -import java.util.ArrayList; | |
| 6 | - | |
| 7 | -/** | |
| 8 | - * Created by geral_000 on 27/06/2015. | |
| 9 | - */ | |
| 10 | -public class Grafico { | |
| 11 | - private String titulo; | |
| 12 | - private ArrayList<BarEntry> yAxis; | |
| 13 | - private ArrayList<String> xVals; | |
| 14 | - private int cor; | |
| 15 | - | |
| 16 | - public Grafico(String titulo, ArrayList<BarEntry> yAxis, ArrayList<String> xVals,int cor) { | |
| 17 | - this.titulo = titulo; | |
| 18 | - this.yAxis = yAxis; | |
| 19 | - this.xVals = xVals; | |
| 20 | - this.cor = cor; | |
| 21 | - } | |
| 22 | - | |
| 23 | - public String getTitulo() { | |
| 24 | - return titulo; | |
| 25 | - } | |
| 26 | - | |
| 27 | - public void setTitulo(String titulo) { | |
| 28 | - this.titulo = titulo; | |
| 29 | - } | |
| 30 | - | |
| 31 | - public ArrayList<BarEntry> getyAxis() { | |
| 32 | - return yAxis; | |
| 33 | - } | |
| 34 | - | |
| 35 | - public void setyAxis(ArrayList<BarEntry> yAxis) { | |
| 36 | - this.yAxis = yAxis; | |
| 37 | - } | |
| 38 | - | |
| 39 | - public ArrayList<String> getxVals() { | |
| 40 | - return xVals; | |
| 41 | - } | |
| 42 | - | |
| 43 | - public void setxVals(ArrayList<String> xVals) { | |
| 44 | - this.xVals = xVals; | |
| 45 | - } | |
| 46 | - | |
| 47 | - public int getCor() { | |
| 48 | - return cor; | |
| 49 | - } | |
| 50 | - | |
| 51 | - public void setCor(int cor) { | |
| 52 | - this.cor = cor; | |
| 53 | - } | |
| 54 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/dialogs/DialogAvaliacao.java
| ... | ... | @@ -1,166 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo.dialogs; | |
| 2 | - | |
| 3 | -import android.annotation.SuppressLint; | |
| 4 | -import android.app.Dialog; | |
| 5 | -import android.app.DialogFragment; | |
| 6 | -import android.content.Context; | |
| 7 | -import android.content.DialogInterface; | |
| 8 | -import android.os.AsyncTask; | |
| 9 | -import android.os.Bundle; | |
| 10 | -import android.support.design.widget.Snackbar; | |
| 11 | -import android.view.LayoutInflater; | |
| 12 | -import android.view.View; | |
| 13 | -import android.view.View.OnClickListener; | |
| 14 | -import android.view.ViewGroup; | |
| 15 | -import android.widget.Button; | |
| 16 | -import android.widget.RatingBar; | |
| 17 | -import android.widget.Toast; | |
| 18 | - | |
| 19 | - | |
| 20 | -import com.monitorabrasil.monitoralegislativo.R; | |
| 21 | -import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 22 | -import com.parse.ParseException; | |
| 23 | -import com.parse.ParseObject; | |
| 24 | -import com.parse.ParseQuery; | |
| 25 | -import com.parse.ParseUser; | |
| 26 | -import com.parse.SaveCallback; | |
| 27 | - | |
| 28 | -@SuppressLint("ValidFragment") | |
| 29 | -public class DialogAvaliacao extends DialogFragment { | |
| 30 | - | |
| 31 | - int idUser; | |
| 32 | - int idPolitico; | |
| 33 | - private String titulo; | |
| 34 | - private ParseObject mPolitico; | |
| 35 | - private ParseObject mAvaliacao; | |
| 36 | - | |
| 37 | - private DialogInterface.OnDismissListener onDismissListener; | |
| 38 | - | |
| 39 | - private boolean jaVotou; | |
| 40 | - | |
| 41 | - | |
| 42 | - | |
| 43 | - public DialogAvaliacao(ParseObject politico, String titulo) { | |
| 44 | - this.titulo=titulo; | |
| 45 | - this.mPolitico = politico; | |
| 46 | - } | |
| 47 | - | |
| 48 | - @Override | |
| 49 | - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
| 50 | - final View view = inflater.inflate(R.layout.dialog_avaliacao, container, false); | |
| 51 | - | |
| 52 | - final RatingBar rb = (RatingBar) view.findViewById(R.id.ratingBar1); | |
| 53 | - | |
| 54 | - jaVotou = false; | |
| 55 | - | |
| 56 | - // setar avaliacao feita | |
| 57 | - ParseQuery<ParseObject> query = ParseQuery.getQuery("Avaliacao"); | |
| 58 | - query.fromLocalDatastore(); | |
| 59 | - try { | |
| 60 | - query.whereEqualTo("politico", mPolitico); | |
| 61 | - mAvaliacao = query.getFirst(); | |
| 62 | - if(mAvaliacao != null){ | |
| 63 | - jaVotou = true; | |
| 64 | - rb.setRating((float)mAvaliacao.getDouble("avaliacao")); | |
| 65 | - } | |
| 66 | - } catch (Exception e) { | |
| 67 | - e.printStackTrace(); | |
| 68 | - } | |
| 69 | - | |
| 70 | - //rb.setRating(new UserDAO(getActivity()).buscaAvaliacaoSalva(idPolitico)); | |
| 71 | - | |
| 72 | - Button btnCancelar = (Button) view.findViewById(R.id.cancel); | |
| 73 | - btnCancelar.setOnClickListener(new OnClickListener() { | |
| 74 | - | |
| 75 | - @Override | |
| 76 | - public void onClick(View v) { | |
| 77 | - getDialog().dismiss(); | |
| 78 | - | |
| 79 | - } | |
| 80 | - }); | |
| 81 | - | |
| 82 | - Button btnOk = (Button) view.findViewById(R.id.ok); | |
| 83 | - btnOk.setOnClickListener(new OnClickListener() { | |
| 84 | - | |
| 85 | - @Override | |
| 86 | - public void onClick(final View v) { | |
| 87 | - if(ParseUser.getCurrentUser()!= null){ | |
| 88 | - double ultimaAvaliacao=0; | |
| 89 | - //salva a avaliacao | |
| 90 | - if(!jaVotou){ | |
| 91 | - mAvaliacao = new ParseObject("Avaliacao"); | |
| 92 | - mAvaliacao.put("politico",mPolitico); | |
| 93 | - mAvaliacao.put("user", ParseUser.getCurrentUser()); | |
| 94 | - }else{ | |
| 95 | - //guardar a ultima valor da avaliacao anterior | |
| 96 | - ultimaAvaliacao = mAvaliacao.getDouble("avaliacao"); | |
| 97 | - } | |
| 98 | - | |
| 99 | - mAvaliacao.put("avaliacao", rb.getRating()); | |
| 100 | - mAvaliacao.saveInBackground(new SaveCallback() { | |
| 101 | - @Override | |
| 102 | - public void done(ParseException e) { | |
| 103 | - | |
| 104 | - } | |
| 105 | - }); | |
| 106 | - mAvaliacao.pinInBackground(); | |
| 107 | - try { | |
| 108 | - mPolitico.fetchFromLocalDatastore(); | |
| 109 | - } catch (ParseException e) { | |
| 110 | - e.printStackTrace(); | |
| 111 | - } | |
| 112 | - int nrAvalicao = mPolitico.getInt("qtd_avaliacao"); | |
| 113 | - double media = mPolitico.getDouble("avaliacao"); | |
| 114 | - double total = nrAvalicao*media; | |
| 115 | - if(jaVotou){ | |
| 116 | - total = total - ultimaAvaliacao; | |
| 117 | - }else{ | |
| 118 | - nrAvalicao++; | |
| 119 | - mPolitico.increment("qtd_avaliacao"); | |
| 120 | - } | |
| 121 | - | |
| 122 | - mPolitico.put("avaliacao", (rb.getRating() + total) / nrAvalicao); | |
| 123 | - | |
| 124 | - mPolitico.saveInBackground(); | |
| 125 | - mPolitico.pinInBackground(); | |
| 126 | - } | |
| 127 | - | |
| 128 | - getDialog().dismiss(); | |
| 129 | - } | |
| 130 | - }); | |
| 131 | - return view; | |
| 132 | - } | |
| 133 | - | |
| 134 | - @Override | |
| 135 | - public Dialog onCreateDialog(Bundle savedInstanceState) { | |
| 136 | - | |
| 137 | - Dialog dialog = super.onCreateDialog(savedInstanceState); | |
| 138 | - // dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); | |
| 139 | - dialog.setTitle(titulo); | |
| 140 | - | |
| 141 | - // WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); | |
| 142 | - // lp.copyFrom(dialog.getWindow().getAttributes()); | |
| 143 | - // lp.width = WindowManager.LayoutParams.MATCH_PARENT-20; | |
| 144 | - // dialog.show(); | |
| 145 | - // dialog.getWindow().setAttributes(lp); | |
| 146 | - | |
| 147 | - return dialog; | |
| 148 | - } | |
| 149 | - | |
| 150 | - | |
| 151 | - | |
| 152 | - public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) { | |
| 153 | - this.onDismissListener = onDismissListener; | |
| 154 | - } | |
| 155 | - | |
| 156 | - @Override | |
| 157 | - public void onDismiss(DialogInterface dialog) { | |
| 158 | - super.onDismiss(dialog); | |
| 159 | - if (onDismissListener != null) { | |
| 160 | - onDismissListener.onDismiss(dialog); | |
| 161 | - } | |
| 162 | - } | |
| 163 | - | |
| 164 | - | |
| 165 | - | |
| 166 | -} | |
| 167 | 0 | \ No newline at end of file |
app/src/main/java/com/monitorabrasil/monitoralegislativo/dispatcher/Dispatcher.java
0 → 100644
| ... | ... | @@ -0,0 +1,64 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.dispatcher; | |
| 2 | + | |
| 3 | +import com.monitorabrasil.monitoralegislativo.actions.Action; | |
| 4 | +import com.monitorabrasil.monitoralegislativo.stores.Store; | |
| 5 | +import com.squareup.otto.Bus; | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | +public class Dispatcher { | |
| 11 | + private final Bus bus; | |
| 12 | + private static Dispatcher instance; | |
| 13 | + | |
| 14 | + public static Dispatcher get(Bus bus) { | |
| 15 | + if (instance == null) { | |
| 16 | + instance = new Dispatcher(bus); | |
| 17 | + } | |
| 18 | + return instance; | |
| 19 | + } | |
| 20 | + | |
| 21 | + Dispatcher(Bus bus) { | |
| 22 | + this.bus = bus; | |
| 23 | + } | |
| 24 | + | |
| 25 | + public void register(final Object cls) { | |
| 26 | + bus.register(cls); | |
| 27 | + | |
| 28 | + } | |
| 29 | + | |
| 30 | + public void unregister(final Object cls) { | |
| 31 | + bus.unregister(cls); | |
| 32 | + } | |
| 33 | + | |
| 34 | + public void emitChange(Store.StoreChangeEvent o) { | |
| 35 | + post(o); | |
| 36 | + } | |
| 37 | + | |
| 38 | + public void dispatch(String type, Object... data) { | |
| 39 | + if (isEmpty(type)) { | |
| 40 | + throw new IllegalArgumentException("Type must not be empty"); | |
| 41 | + } | |
| 42 | + | |
| 43 | + if (data.length % 2 != 0) { | |
| 44 | + throw new IllegalArgumentException("Data must be a valid list of key,value pairs"); | |
| 45 | + } | |
| 46 | + | |
| 47 | + Action.Builder actionBuilder = Action.type(type); | |
| 48 | + int i = 0; | |
| 49 | + while (i < data.length) { | |
| 50 | + String key = (String) data[i++]; | |
| 51 | + Object value = data[i++]; | |
| 52 | + actionBuilder.bundle(key, value); | |
| 53 | + } | |
| 54 | + post(actionBuilder.build()); | |
| 55 | + } | |
| 56 | + | |
| 57 | + private boolean isEmpty(String type) { | |
| 58 | + return type == null || type.isEmpty(); | |
| 59 | + } | |
| 60 | + | |
| 61 | + private void post(final Object event) { | |
| 62 | + bus.post(event); | |
| 63 | + } | |
| 64 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/fragments/EscolhaTipoProjeto.java
| ... | ... | @@ -1,164 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo.fragments; | |
| 2 | - | |
| 3 | -import android.net.Uri; | |
| 4 | -import android.os.Bundle; | |
| 5 | -import android.support.v4.app.Fragment; | |
| 6 | -import android.support.v4.app.FragmentTransaction; | |
| 7 | -import android.support.v7.widget.GridLayoutManager; | |
| 8 | -import android.support.v7.widget.RecyclerView; | |
| 9 | -import android.util.Log; | |
| 10 | -import android.view.LayoutInflater; | |
| 11 | -import android.view.View; | |
| 12 | -import android.view.ViewGroup; | |
| 13 | - | |
| 14 | -import com.monitorabrasil.monitoralegislativo.R; | |
| 15 | -import com.monitorabrasil.monitoralegislativo.adapters.TipoProjetoAdapter; | |
| 16 | -import com.monitorabrasil.monitoralegislativo.interfaces.RecyclerViewOnClickListenerHack; | |
| 17 | -import com.parse.FindCallback; | |
| 18 | -import com.parse.ParseObject; | |
| 19 | -import com.parse.ParseQuery; | |
| 20 | - | |
| 21 | -import java.util.List; | |
| 22 | - | |
| 23 | -/** | |
| 24 | - * A simple {@link Fragment} subclass. | |
| 25 | - * Activities that contain this fragment must implement the | |
| 26 | - * {@link EscolhaTipoProjeto.OnFragmentInteractionListener} interface | |
| 27 | - * to handle interaction events. | |
| 28 | - * Use the {@link EscolhaTipoProjeto#newInstance} factory method to | |
| 29 | - * create an instance of this fragment. | |
| 30 | - */ | |
| 31 | -public class EscolhaTipoProjeto extends Fragment implements RecyclerViewOnClickListenerHack { | |
| 32 | - // TODO: Rename parameter arguments, choose names that match | |
| 33 | - // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER | |
| 34 | - private static final String ARG_PARAM1 = "param1"; | |
| 35 | - private static final String ARG_PARAM2 = "param2"; | |
| 36 | - private RecyclerView mRecyclerView; | |
| 37 | - private TipoProjetoAdapter mAdapter; | |
| 38 | - | |
| 39 | - // TODO: Rename and change types of parameters | |
| 40 | - private String mParam1; | |
| 41 | - private String mParam2; | |
| 42 | - | |
| 43 | - private OnFragmentInteractionListener mListener; | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * Use this factory method to create a new instance of | |
| 47 | - * this fragment using the provided parameters. | |
| 48 | - * | |
| 49 | - * @param param1 Parameter 1. | |
| 50 | - * @param param2 Parameter 2. | |
| 51 | - * @return A new instance of fragment EscolhaTipoProjeto. | |
| 52 | - */ | |
| 53 | - // TODO: Rename and change types and number of parameters | |
| 54 | - public static EscolhaTipoProjeto newInstance(String param1, String param2) { | |
| 55 | - EscolhaTipoProjeto fragment = new EscolhaTipoProjeto(); | |
| 56 | - Bundle args = new Bundle(); | |
| 57 | - args.putString(ARG_PARAM1, param1); | |
| 58 | - args.putString(ARG_PARAM2, param2); | |
| 59 | - fragment.setArguments(args); | |
| 60 | - return fragment; | |
| 61 | - } | |
| 62 | - | |
| 63 | - public EscolhaTipoProjeto() { | |
| 64 | - // Required empty public constructor | |
| 65 | - } | |
| 66 | - | |
| 67 | - @Override | |
| 68 | - public void onCreate(Bundle savedInstanceState) { | |
| 69 | - super.onCreate(savedInstanceState); | |
| 70 | - if (getArguments() != null) { | |
| 71 | - mParam1 = getArguments().getString(ARG_PARAM1); | |
| 72 | - mParam2 = getArguments().getString(ARG_PARAM2); | |
| 73 | - } | |
| 74 | - } | |
| 75 | - | |
| 76 | - @Override | |
| 77 | - public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
| 78 | - Bundle savedInstanceState) { | |
| 79 | - View view = inflater.inflate(R.layout.fragment_escolha_tipo_projeto, container, false); | |
| 80 | - | |
| 81 | - //tableview | |
| 82 | - mRecyclerView = (RecyclerView) view.findViewById(R.id.rv_escolha_tipo); | |
| 83 | - | |
| 84 | - // use this setting to improve performance if you know that changes | |
| 85 | - // in content do not change the layout size of the RecyclerView | |
| 86 | - mRecyclerView.setHasFixedSize(true); | |
| 87 | - | |
| 88 | - GridLayoutManager llm = new GridLayoutManager(getActivity(),2,GridLayoutManager.VERTICAL, false); | |
| 89 | - mRecyclerView.setLayoutManager(llm); | |
| 90 | - | |
| 91 | - //busca os tipos de projetos | |
| 92 | - buscaTiposProjetos(); | |
| 93 | - | |
| 94 | - return view; | |
| 95 | - } | |
| 96 | - | |
| 97 | - private void buscaTiposProjetos() { | |
| 98 | - ParseQuery<ParseObject> query = ParseQuery.getQuery("TipoProjeto"); | |
| 99 | - query.addAscendingOrder("nome"); | |
| 100 | - query.findInBackground(new FindCallback<ParseObject>() { | |
| 101 | - @Override | |
| 102 | - public void done(List<ParseObject> list, com.parse.ParseException e) { | |
| 103 | - if (e == null) { | |
| 104 | - carregaList(list); | |
| 105 | - } else { | |
| 106 | - Log.d("score", "Error: " + e.getMessage()); | |
| 107 | - } | |
| 108 | - } | |
| 109 | - | |
| 110 | - | |
| 111 | - }); | |
| 112 | - } | |
| 113 | - | |
| 114 | - private void carregaList(List<ParseObject> list) { | |
| 115 | - mAdapter = new TipoProjetoAdapter(list,getActivity()); | |
| 116 | - mAdapter.setRecyclerViewOnClickListenerHack(this); | |
| 117 | - mRecyclerView.setAdapter(mAdapter); | |
| 118 | - //pb.setVisibility(View.INVISIBLE); | |
| 119 | - } | |
| 120 | - | |
| 121 | - @Override | |
| 122 | - public void onClickListener(View view, int position) { | |
| 123 | - ListaProjetosFragment frag = (ListaProjetosFragment) getActivity().getSupportFragmentManager().findFragmentByTag("listaProjFrag"); | |
| 124 | - if(frag == null) { | |
| 125 | - frag = ListaProjetosFragment.newInstance(mAdapter.getItem(position),null); | |
| 126 | - FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); | |
| 127 | - ft.replace(R.id.rl_fragment_container, frag, "listaProjFrag"); | |
| 128 | - ft.addToBackStack(null); | |
| 129 | - ft.commit(); | |
| 130 | - } | |
| 131 | - | |
| 132 | - } | |
| 133 | - | |
| 134 | - // TODO: Rename method, update argument and hook method into UI event | |
| 135 | - public void onButtonPressed(Uri uri) { | |
| 136 | - if (mListener != null) { | |
| 137 | - mListener.onFragmentInteraction(uri); | |
| 138 | - } | |
| 139 | - } | |
| 140 | - | |
| 141 | - | |
| 142 | - | |
| 143 | - @Override | |
| 144 | - public void onDetach() { | |
| 145 | - super.onDetach(); | |
| 146 | - mListener = null; | |
| 147 | - } | |
| 148 | - | |
| 149 | - /** | |
| 150 | - * This interface must be implemented by activities that contain this | |
| 151 | - * fragment to allow an interaction in this fragment to be communicated | |
| 152 | - * to the activity and potentially other fragments contained in that | |
| 153 | - * activity. | |
| 154 | - * <p/> | |
| 155 | - * See the Android Training lesson <a href= | |
| 156 | - * "http://developer.android.com/training/basics/fragments/communicating.html" | |
| 157 | - * >Communicating with Other Fragments</a> for more information. | |
| 158 | - */ | |
| 159 | - public interface OnFragmentInteractionListener { | |
| 160 | - // TODO: Update argument type and name | |
| 161 | - public void onFragmentInteraction(Uri uri); | |
| 162 | - } | |
| 163 | - | |
| 164 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/fragments/GastosCamaraFragment.java
| ... | ... | @@ -1,321 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo.fragments; | |
| 2 | - | |
| 3 | -import android.app.Activity; | |
| 4 | -import android.net.Uri; | |
| 5 | -import android.os.Bundle; | |
| 6 | -import android.support.v4.app.Fragment; | |
| 7 | -import android.support.v7.widget.LinearLayoutManager; | |
| 8 | -import android.support.v7.widget.RecyclerView; | |
| 9 | -import android.view.LayoutInflater; | |
| 10 | -import android.view.View; | |
| 11 | -import android.view.ViewGroup; | |
| 12 | -import android.widget.ProgressBar; | |
| 13 | - | |
| 14 | -import com.crashlytics.android.Crashlytics; | |
| 15 | -import com.github.mikephil.charting.animation.Easing; | |
| 16 | -import com.github.mikephil.charting.charts.BarChart; | |
| 17 | -import com.github.mikephil.charting.components.Legend; | |
| 18 | -import com.github.mikephil.charting.components.XAxis; | |
| 19 | -import com.github.mikephil.charting.components.YAxis; | |
| 20 | -import com.github.mikephil.charting.data.BarData; | |
| 21 | -import com.github.mikephil.charting.data.BarDataSet; | |
| 22 | -import com.github.mikephil.charting.data.BarEntry; | |
| 23 | -import com.github.mikephil.charting.utils.ValueFormatter; | |
| 24 | -import com.monitorabrasil.monitoralegislativo.R; | |
| 25 | -import com.monitorabrasil.monitoralegislativo.adapters.GastoAdapter; | |
| 26 | -import com.monitorabrasil.monitoralegislativo.classes.Grafico; | |
| 27 | -import com.monitorabrasil.monitoralegislativo.util.MyValueFormatter; | |
| 28 | -import com.parse.FindCallback; | |
| 29 | -import com.parse.ParseException; | |
| 30 | -import com.parse.ParseObject; | |
| 31 | -import com.parse.ParseQuery; | |
| 32 | - | |
| 33 | -import java.util.ArrayList; | |
| 34 | -import java.util.HashMap; | |
| 35 | -import java.util.Iterator; | |
| 36 | -import java.util.List; | |
| 37 | -import java.util.Set; | |
| 38 | - | |
| 39 | -/** | |
| 40 | - * A simple {@link Fragment} subclass. | |
| 41 | - * Activities that contain this fragment must implement the | |
| 42 | - * {@link GastosCamaraFragment.OnFragmentInteractionListener} interface | |
| 43 | - * to handle interaction events. | |
| 44 | - * Use the {@link GastosCamaraFragment#newInstance} factory method to | |
| 45 | - * create an instance of this fragment. | |
| 46 | - */ | |
| 47 | -public class GastosCamaraFragment extends Fragment { | |
| 48 | - | |
| 49 | - | |
| 50 | - protected BarChart mChart; | |
| 51 | - private View mView; | |
| 52 | - private HashMap<String,HashMap<String,Float>> dataset = new HashMap<String,HashMap<String,Float>>(); | |
| 53 | - private HashMap<String,Float> valorTotal = new HashMap<String,Float>(); | |
| 54 | - ArrayList<String> xVals = new ArrayList<String>(); | |
| 55 | - ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>(); | |
| 56 | - private RecyclerView mRecyclerView; | |
| 57 | - private GastoAdapter mAdapter; | |
| 58 | - List<Grafico> myDataset=new ArrayList<Grafico>(); | |
| 59 | - List<String> tipos = new ArrayList<String>(); | |
| 60 | - int[] cores = new int[]{R.color.cor1, R.color.cor2,R.color.cor3, R.color.cor4,R.color.cor5, R.color.cor6, | |
| 61 | - R.color.cor7, R.color.cor8,R.color.cor9, R.color.cor10}; | |
| 62 | - | |
| 63 | - private ProgressBar pb; | |
| 64 | - | |
| 65 | - | |
| 66 | - | |
| 67 | - private OnFragmentInteractionListener mListener; | |
| 68 | - | |
| 69 | - /** | |
| 70 | - * Use this factory method to create a new instance of | |
| 71 | - * this fragment using the provided parameters. | |
| 72 | - * | |
| 73 | - * @param param1 Parameter 1. | |
| 74 | - * @param param2 Parameter 2. | |
| 75 | - * @return A new instance of fragment GastosCamaraFragment. | |
| 76 | - */ | |
| 77 | - // TODO: Rename and change types and number of parameters | |
| 78 | - public static GastosCamaraFragment newInstance(String param1, String param2) { | |
| 79 | - GastosCamaraFragment fragment = new GastosCamaraFragment(); | |
| 80 | - Bundle args = new Bundle(); | |
| 81 | -// args.putString(ARG_PARAM1, param1); | |
| 82 | -// args.putString(ARG_PARAM2, param2); | |
| 83 | - fragment.setArguments(args); | |
| 84 | - return fragment; | |
| 85 | - } | |
| 86 | - | |
| 87 | - public GastosCamaraFragment() { | |
| 88 | - // Required empty public constructor | |
| 89 | - } | |
| 90 | - | |
| 91 | - @Override | |
| 92 | - public void onCreate(Bundle savedInstanceState) { | |
| 93 | - super.onCreate(savedInstanceState); | |
| 94 | - if (getArguments() != null) { | |
| 95 | -// mParam1 = getArguments().getString(ARG_PARAM1); | |
| 96 | -// mParam2 = getArguments().getString(ARG_PARAM2); | |
| 97 | - } | |
| 98 | - } | |
| 99 | - | |
| 100 | - | |
| 101 | - | |
| 102 | - @Override | |
| 103 | - public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
| 104 | - Bundle savedInstanceState) { | |
| 105 | - // Inflate the layout for this fragment | |
| 106 | - View view =inflater.inflate(R.layout.fragment_lista_projetos, container, false); | |
| 107 | - pb = (ProgressBar) view.findViewById(R.id.progressBar); | |
| 108 | -// pb.setVisibility(View.VISIBLE); | |
| 109 | - mView=view; | |
| 110 | -// mChart = (BarChart) view.findViewById(R.id.chart1); | |
| 111 | -// mChart.setVisibility(View.GONE); | |
| 112 | -// buildGraph(); | |
| 113 | - | |
| 114 | - //tableview | |
| 115 | - mRecyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view); | |
| 116 | - | |
| 117 | - // use this setting to improve performance if you know that changes | |
| 118 | - // in content do not change the layout size of the RecyclerView | |
| 119 | - mRecyclerView.setHasFixedSize(true); | |
| 120 | - | |
| 121 | - LinearLayoutManager llm = new LinearLayoutManager(getActivity()); | |
| 122 | - llm.setOrientation(LinearLayoutManager.VERTICAL); | |
| 123 | - mRecyclerView.setLayoutManager(llm); | |
| 124 | - buscaGastos(); | |
| 125 | - return view; | |
| 126 | - } | |
| 127 | - | |
| 128 | - private ParseObject buscaGastos() { | |
| 129 | - | |
| 130 | - ParseQuery<ParseObject> query = ParseQuery.getQuery("DespesaCamara"); | |
| 131 | - query.setLimit(200); | |
| 132 | - //query.whereEqualTo("politico",politico); | |
| 133 | - | |
| 134 | - query.addAscendingOrder("mes_numero"); | |
| 135 | - query.findInBackground(new FindCallback<ParseObject>() { | |
| 136 | - public void done(List<ParseObject> gastos, ParseException e) { | |
| 137 | - | |
| 138 | - Iterator<ParseObject> gastoIt = gastos.iterator(); | |
| 139 | - | |
| 140 | - while (gastoIt.hasNext()) { | |
| 141 | - | |
| 142 | - ParseObject g = gastoIt.next(); | |
| 143 | - String mes = g.getString("mes"); | |
| 144 | - Float novoValor = Float.valueOf(g.getString("valor")); | |
| 145 | - | |
| 146 | - String tipo = g.getString("tipo"); | |
| 147 | - if(!tipos.contains(tipo)){ | |
| 148 | - tipos.add(tipo); | |
| 149 | - } | |
| 150 | - //verifica tipo | |
| 151 | - HashMap<String,Float> data = dataset.get(tipo); | |
| 152 | - if(data != null){ | |
| 153 | - //verifica se tem o valor por mes | |
| 154 | - Float valorMesTipo = data.get(mes); | |
| 155 | - if(valorMesTipo != null){ | |
| 156 | - valorMesTipo = valorMesTipo +novoValor; | |
| 157 | - data.remove(mes); | |
| 158 | - data.put(mes, valorMesTipo); | |
| 159 | - }else{ | |
| 160 | - data.put(mes,novoValor); | |
| 161 | - } | |
| 162 | - | |
| 163 | - | |
| 164 | - }else{ | |
| 165 | - data = new HashMap<String, Float>(); | |
| 166 | - data.put(mes,novoValor); | |
| 167 | - dataset.put(tipo,data); | |
| 168 | - } | |
| 169 | - | |
| 170 | - | |
| 171 | - Float valor = valorTotal.get(mes); | |
| 172 | - if (valor != null) { | |
| 173 | - valor = valor + novoValor; | |
| 174 | - valorTotal.remove(mes); | |
| 175 | - valorTotal.put(mes, valor); | |
| 176 | - } else { | |
| 177 | - valorTotal.put(mes, novoValor); | |
| 178 | - } | |
| 179 | - if (!xVals.contains(mes)) { | |
| 180 | - xVals.add(mes); | |
| 181 | - } | |
| 182 | - | |
| 183 | - // | |
| 184 | - | |
| 185 | - | |
| 186 | - } | |
| 187 | - for (int j = 0; j < xVals.size(); j++) { | |
| 188 | - Float val = valorTotal.get(xVals.get(j)); | |
| 189 | - yVals1.add(new BarEntry(val, j)); | |
| 190 | - } | |
| 191 | - Grafico grafico = new Grafico("Todos", yVals1, xVals, R.color.cor10); | |
| 192 | - myDataset.add(grafico); | |
| 193 | - | |
| 194 | - //adicionar os outros graficos | |
| 195 | - for(int i=0; i < tipos.size();i++ ){ | |
| 196 | - HashMap<String,Float> temp = dataset.get(tipos.get(i)); | |
| 197 | - ArrayList<String> x = new ArrayList<String>(); | |
| 198 | - for ( int k=0; k < temp.size(); k++ ) { | |
| 199 | - x.add(k,""); | |
| 200 | - } | |
| 201 | - ArrayList<BarEntry> y = new ArrayList<BarEntry>(); | |
| 202 | - for ( String mes : temp.keySet() ) { | |
| 203 | - if(!x.contains(mes)){ | |
| 204 | - int pos = buscaPosicao(mes); | |
| 205 | - x.remove(pos); | |
| 206 | - x.add(pos, mes); | |
| 207 | - } | |
| 208 | - Float val = temp.get(mes); | |
| 209 | - y.add(new BarEntry(val, x.indexOf(mes))); | |
| 210 | - } | |
| 211 | - | |
| 212 | - | |
| 213 | - | |
| 214 | - myDataset.add(new Grafico(tipos.get(i),y,x,cores[i])); | |
| 215 | - } | |
| 216 | - | |
| 217 | - carregaList(); | |
| 218 | - pb.setVisibility(View.INVISIBLE); | |
| 219 | - | |
| 220 | - // setData(); | |
| 221 | - | |
| 222 | - } | |
| 223 | - }); | |
| 224 | - | |
| 225 | - | |
| 226 | - return null; | |
| 227 | - } | |
| 228 | - | |
| 229 | - private int buscaPosicao(String mes) { | |
| 230 | - int ret=0; | |
| 231 | - switch (mes){ | |
| 232 | - case "JAN": | |
| 233 | - ret=0; | |
| 234 | - break; | |
| 235 | - case "FEV": | |
| 236 | - ret=1; | |
| 237 | - break; | |
| 238 | - case "MAR": | |
| 239 | - ret=2; | |
| 240 | - break; | |
| 241 | - case "ABR": | |
| 242 | - ret=3; | |
| 243 | - break; | |
| 244 | - case "MAI": | |
| 245 | - ret=4; | |
| 246 | - break; | |
| 247 | - case "JUN": | |
| 248 | - ret=5; | |
| 249 | - break; | |
| 250 | - case "JUL": | |
| 251 | - ret=6; | |
| 252 | - break; | |
| 253 | - case "AGO": | |
| 254 | - ret=7; | |
| 255 | - break; | |
| 256 | - case "SET": | |
| 257 | - ret=8; | |
| 258 | - break; | |
| 259 | - case "OUT": | |
| 260 | - ret=9; | |
| 261 | - break; | |
| 262 | - case "NOV": | |
| 263 | - ret=10; | |
| 264 | - break; | |
| 265 | - case "DEZ": | |
| 266 | - ret=11; | |
| 267 | - break; | |
| 268 | - | |
| 269 | - } | |
| 270 | - return ret; | |
| 271 | - } | |
| 272 | - | |
| 273 | - public void carregaList(){ | |
| 274 | - mAdapter = new GastoAdapter(myDataset); | |
| 275 | -// mAdapter.setRecyclerViewOnClickListenerHack(this); | |
| 276 | - mRecyclerView.setAdapter(mAdapter); | |
| 277 | -// pb.setVisibility(View.INVISIBLE); | |
| 278 | - } | |
| 279 | - | |
| 280 | - | |
| 281 | - | |
| 282 | - // TODO: Rename method, update argument and hook method into UI event | |
| 283 | - public void onButtonPressed(Uri uri) { | |
| 284 | - if (mListener != null) { | |
| 285 | - mListener.onFragmentInteraction(uri); | |
| 286 | - } | |
| 287 | - } | |
| 288 | - | |
| 289 | - @Override | |
| 290 | - public void onAttach(Activity activity) { | |
| 291 | - super.onAttach(activity); | |
| 292 | -// try { | |
| 293 | -// mListener = (OnFragmentInteractionListener) activity; | |
| 294 | -// } catch (ClassCastException e) { | |
| 295 | -// throw new ClassCastException(activity.toString() | |
| 296 | -// + " must implement OnFragmentInteractionListener"); | |
| 297 | -// } | |
| 298 | - } | |
| 299 | - | |
| 300 | - @Override | |
| 301 | - public void onDetach() { | |
| 302 | - super.onDetach(); | |
| 303 | - mListener = null; | |
| 304 | - } | |
| 305 | - | |
| 306 | - /** | |
| 307 | - * This interface must be implemented by activities that contain this | |
| 308 | - * fragment to allow an interaction in this fragment to be communicated | |
| 309 | - * to the activity and potentially other fragments contained in that | |
| 310 | - * activity. | |
| 311 | - * <p/> | |
| 312 | - * See the Android Training lesson <a href= | |
| 313 | - * "http://developer.android.com/training/basics/fragments/communicating.html" | |
| 314 | - * >Communicating with Other Fragments</a> for more information. | |
| 315 | - */ | |
| 316 | - public interface OnFragmentInteractionListener { | |
| 317 | - // TODO: Update argument type and name | |
| 318 | - public void onFragmentInteraction(Uri uri); | |
| 319 | - } | |
| 320 | - | |
| 321 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/fragments/GastosFragment.java
| ... | ... | @@ -1,215 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo.fragments; | |
| 2 | - | |
| 3 | -import android.graphics.Color; | |
| 4 | -import android.os.Bundle; | |
| 5 | -import android.support.v4.app.Fragment; | |
| 6 | -import android.util.Log; | |
| 7 | -import android.view.LayoutInflater; | |
| 8 | -import android.view.View; | |
| 9 | -import android.view.ViewGroup; | |
| 10 | - | |
| 11 | -import com.github.mikephil.charting.animation.Easing; | |
| 12 | -import com.github.mikephil.charting.charts.LineChart; | |
| 13 | -import com.github.mikephil.charting.components.Legend; | |
| 14 | -import com.github.mikephil.charting.components.LimitLine; | |
| 15 | -import com.github.mikephil.charting.components.YAxis; | |
| 16 | -import com.github.mikephil.charting.data.Entry; | |
| 17 | -import com.github.mikephil.charting.data.LineData; | |
| 18 | -import com.github.mikephil.charting.data.LineDataSet; | |
| 19 | -import com.monitorabrasil.monitoralegislativo.R; | |
| 20 | -import com.monitorabrasil.monitoralegislativo.classes.Grafico; | |
| 21 | -import com.parse.FindCallback; | |
| 22 | -import com.parse.ParseException; | |
| 23 | -import com.parse.ParseObject; | |
| 24 | -import com.parse.ParseQuery; | |
| 25 | -import com.parse.ParseUser; | |
| 26 | - | |
| 27 | -import java.lang.reflect.Array; | |
| 28 | -import java.util.ArrayList; | |
| 29 | -import java.util.Iterator; | |
| 30 | -import java.util.List; | |
| 31 | - | |
| 32 | -/** | |
| 33 | - * Created by geral_000 on 20/06/2015. | |
| 34 | - */ | |
| 35 | -public class GastosFragment extends Fragment { | |
| 36 | - | |
| 37 | - private LineChart mChart; | |
| 38 | - private ParseObject politico; | |
| 39 | - float maximo = 0f, minimo = 0f; | |
| 40 | - View mView; | |
| 41 | - ArrayList<String> xVals = new ArrayList<String>(); | |
| 42 | - ArrayList<Entry> yVals = new ArrayList<Entry>(); | |
| 43 | - private ArrayList<Grafico> graficos =new ArrayList<Grafico>(); | |
| 44 | - | |
| 45 | - public View onCreateView(LayoutInflater inflater, | |
| 46 | - ViewGroup container, | |
| 47 | - Bundle savedInstanceState) { | |
| 48 | - View view = inflater.inflate(R.layout.fragment_politico_gastos, container, false); | |
| 49 | - | |
| 50 | - Bundle bundle = getArguments(); | |
| 51 | - politico = buscaGastos(bundle.getString("politico")) ; | |
| 52 | - | |
| 53 | - mView=view; | |
| 54 | - | |
| 55 | - return view; | |
| 56 | - } | |
| 57 | - | |
| 58 | - private void buildGraph(){ | |
| 59 | - mChart = (LineChart)mView.findViewById(R.id.chart1); | |
| 60 | - | |
| 61 | - mChart.setDrawGridBackground(false); | |
| 62 | - | |
| 63 | - | |
| 64 | - mChart.setDescription(""); | |
| 65 | - mChart.setNoDataTextDescription("You need to provide data for the chart."); | |
| 66 | - | |
| 67 | - // enable value highlighting | |
| 68 | - mChart.setHighlightEnabled(true); | |
| 69 | - | |
| 70 | - // enable touch gestures | |
| 71 | - mChart.setTouchEnabled(true); | |
| 72 | - | |
| 73 | - // enable scaling and dragging | |
| 74 | - mChart.setDragEnabled(true); | |
| 75 | - mChart.setScaleEnabled(true); | |
| 76 | - // mChart.setScaleXEnabled(true); | |
| 77 | - // mChart.setScaleYEnabled(true); | |
| 78 | - | |
| 79 | - // if disabled, scaling can be done on x- and y-axis separately | |
| 80 | - mChart.setPinchZoom(true); | |
| 81 | - | |
| 82 | - // enable/disable highlight indicators (the lines that indicate the | |
| 83 | - // highlighted Entry) | |
| 84 | - mChart.setHighlightEnabled(false); | |
| 85 | - | |
| 86 | - LimitLine ll1 = new LimitLine(130f, "Upper Limit"); | |
| 87 | - ll1.setLineWidth(4f); | |
| 88 | - ll1.enableDashedLine(10f, 10f, 0f); | |
| 89 | - ll1.setLabelPosition(LimitLine.LimitLabelPosition.POS_RIGHT); | |
| 90 | - ll1.setTextSize(10f); | |
| 91 | - | |
| 92 | - LimitLine ll2 = new LimitLine(-30f, "Lower Limit"); | |
| 93 | - ll2.setLineWidth(4f); | |
| 94 | - ll2.enableDashedLine(10f, 10f, 0f); | |
| 95 | - ll2.setLabelPosition(LimitLine.LimitLabelPosition.POS_RIGHT); | |
| 96 | - ll2.setTextSize(10f); | |
| 97 | - | |
| 98 | - YAxis leftAxis = mChart.getAxisLeft(); | |
| 99 | - leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines | |
| 100 | - //leftAxis.addLimitLine(ll1); | |
| 101 | - //leftAxis.addLimitLine(ll2); | |
| 102 | - leftAxis.setAxisMaxValue(maximo + 200); | |
| 103 | - minimo = minimo-200; | |
| 104 | - if(minimo < 0f){ | |
| 105 | - minimo=0f; | |
| 106 | - } | |
| 107 | - leftAxis.setAxisMinValue(minimo); | |
| 108 | - leftAxis.setStartAtZero(false); | |
| 109 | - //leftAxis.setYOffset(20f); | |
| 110 | - leftAxis.enableGridDashedLine(10f, 10f, 0f); | |
| 111 | - | |
| 112 | - // limit lines are drawn behind data (and not on top) | |
| 113 | - leftAxis.setDrawLimitLinesBehindData(true); | |
| 114 | - | |
| 115 | - mChart.getAxisRight().setEnabled(false); | |
| 116 | - | |
| 117 | - // add data | |
| 118 | - setData(); | |
| 119 | - | |
| 120 | -// mChart.setVisibleXRange(20); | |
| 121 | -// mChart.setVisibleYRange(20f, AxisDependency.LEFT); | |
| 122 | -// mChart.centerViewTo(20, 50, AxisDependency.LEFT); | |
| 123 | - | |
| 124 | - mChart.animateX(2500, Easing.EasingOption.EaseInOutQuart); | |
| 125 | -// mChart.invalidate(); | |
| 126 | - | |
| 127 | - // get the legend (only possible after setting data) | |
| 128 | - Legend l = mChart.getLegend(); | |
| 129 | - | |
| 130 | - // modify the legend ... | |
| 131 | - // l.setPosition(LegendPosition.LEFT_OF_CHART); | |
| 132 | - l.setForm(Legend.LegendForm.LINE); | |
| 133 | - } | |
| 134 | - | |
| 135 | - private ParseObject buscaGastos(String id) { | |
| 136 | - | |
| 137 | - ParseObject politico = buscaPolitico(id); | |
| 138 | - xVals =new ArrayList<String>(); | |
| 139 | - yVals = new ArrayList<Entry>(); | |
| 140 | - maximo = 0f; | |
| 141 | - minimo = 0f; | |
| 142 | - | |
| 143 | - ParseQuery<ParseObject> query = ParseQuery.getQuery("Verba"); | |
| 144 | - query.whereEqualTo("politico",politico); | |
| 145 | - query.orderByAscending("createdAt"); | |
| 146 | - query.findInBackground(new FindCallback<ParseObject>() { | |
| 147 | - public void done(List<ParseObject> gastos, ParseException e) { | |
| 148 | - Iterator<ParseObject> gastoIt = gastos.iterator(); | |
| 149 | - int i=0; | |
| 150 | - while (gastoIt.hasNext()) { | |
| 151 | - ParseObject g = gastoIt.next(); | |
| 152 | - float possivelMaximo = Float.valueOf(g.getString("valor")); | |
| 153 | - if(possivelMaximo > maximo ){ | |
| 154 | - maximo = possivelMaximo; | |
| 155 | - } | |
| 156 | - if(minimo > possivelMaximo || i==0){ | |
| 157 | - minimo=possivelMaximo; | |
| 158 | - } | |
| 159 | - xVals.add(g.getString("mes").substring(0,3)+" "+g.getString("ano")); | |
| 160 | - yVals.add(new Entry(possivelMaximo, i)); | |
| 161 | - i++; | |
| 162 | - } | |
| 163 | - buildGraph(); | |
| 164 | - } | |
| 165 | - }); | |
| 166 | - | |
| 167 | - return null; | |
| 168 | - } | |
| 169 | - | |
| 170 | - private ParseObject buscaPolitico(String id) { | |
| 171 | - | |
| 172 | - ParseQuery<ParseObject> query = ParseQuery.getQuery("Politico"); | |
| 173 | - query.fromLocalDatastore(); | |
| 174 | - try { | |
| 175 | - return query.get(id); | |
| 176 | - } catch (com.parse.ParseException e) { | |
| 177 | - e.printStackTrace(); | |
| 178 | - } | |
| 179 | - return null; | |
| 180 | - } | |
| 181 | - | |
| 182 | - private void setData() { | |
| 183 | - | |
| 184 | - | |
| 185 | - | |
| 186 | - // create a dataset and give it a type | |
| 187 | - LineDataSet set1 = new LineDataSet(yVals, "Verba idenizatoria"); | |
| 188 | - set1.setFillAlpha(110); | |
| 189 | - set1.setFillColor(Color.RED); | |
| 190 | - | |
| 191 | - // set the line to be drawn like this "- - - - - -" | |
| 192 | - set1.enableDashedLine(10f, 5f, 0f); | |
| 193 | - set1.setColor(Color.BLACK); | |
| 194 | - set1.setCircleColor(Color.BLACK); | |
| 195 | - set1.setLineWidth(1f); | |
| 196 | - set1.setCircleSize(3f); | |
| 197 | - set1.setDrawCircleHole(false); | |
| 198 | - set1.setValueTextSize(9f); | |
| 199 | - set1.setFillAlpha(65); | |
| 200 | - set1.setFillColor(Color.BLACK); | |
| 201 | -// set1.setDrawFilled(true); | |
| 202 | - // set1.setShader(new LinearGradient(0, 0, 0, mChart.getHeight(), | |
| 203 | - // Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR)); | |
| 204 | - | |
| 205 | - ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>(); | |
| 206 | - dataSets.add(set1); // add the datasets | |
| 207 | - | |
| 208 | - // create a data object with the datasets | |
| 209 | - LineData data = new LineData(xVals, dataSets); | |
| 210 | - | |
| 211 | - // set data | |
| 212 | - mChart.setData(data); | |
| 213 | - } | |
| 214 | -} | |
| 215 | - |
app/src/main/java/com/monitorabrasil/monitoralegislativo/fragments/HomeFragment.java
| ... | ... | @@ -1,361 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo.fragments; | |
| 2 | - | |
| 3 | -import android.app.Activity; | |
| 4 | -import android.content.Intent; | |
| 5 | -import android.net.Uri; | |
| 6 | -import android.os.Bundle; | |
| 7 | -import android.support.design.widget.FloatingActionButton; | |
| 8 | -import android.support.v4.app.Fragment; | |
| 9 | -import android.support.v7.widget.LinearLayoutManager; | |
| 10 | -import android.support.v7.widget.RecyclerView; | |
| 11 | -import android.util.Log; | |
| 12 | -import android.view.LayoutInflater; | |
| 13 | -import android.view.View; | |
| 14 | -import android.view.ViewGroup; | |
| 15 | - | |
| 16 | -import com.crashlytics.android.Crashlytics; | |
| 17 | -import com.github.mikephil.charting.animation.Easing; | |
| 18 | -import com.github.mikephil.charting.charts.BarChart; | |
| 19 | -import com.github.mikephil.charting.components.Legend; | |
| 20 | -import com.github.mikephil.charting.components.XAxis; | |
| 21 | -import com.github.mikephil.charting.components.YAxis; | |
| 22 | -import com.github.mikephil.charting.data.BarData; | |
| 23 | -import com.github.mikephil.charting.data.BarDataSet; | |
| 24 | -import com.github.mikephil.charting.data.BarEntry; | |
| 25 | -import com.github.mikephil.charting.data.Entry; | |
| 26 | -import com.github.mikephil.charting.utils.ValueFormatter; | |
| 27 | -import com.monitorabrasil.monitoralegislativo.ComentarioActivity; | |
| 28 | -import com.monitorabrasil.monitoralegislativo.PoliticoFichaActivity; | |
| 29 | -import com.monitorabrasil.monitoralegislativo.R; | |
| 30 | -import com.monitorabrasil.monitoralegislativo.adapters.VereadorAdapter; | |
| 31 | -import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 32 | -import com.monitorabrasil.monitoralegislativo.classes.Grafico; | |
| 33 | -import com.monitorabrasil.monitoralegislativo.interfaces.RecyclerViewOnClickListenerHack; | |
| 34 | -import com.monitorabrasil.monitoralegislativo.util.MyValueFormatter; | |
| 35 | -import com.parse.FindCallback; | |
| 36 | -import com.parse.ParseException; | |
| 37 | -import com.parse.ParseObject; | |
| 38 | -import com.parse.ParseQuery; | |
| 39 | - | |
| 40 | -import java.util.ArrayList; | |
| 41 | -import java.util.HashMap; | |
| 42 | -import java.util.Iterator; | |
| 43 | -import java.util.List; | |
| 44 | - | |
| 45 | -/** | |
| 46 | - * A simple {@link Fragment} subclass. | |
| 47 | - * Activities that contain this fragment must implement the | |
| 48 | - * {@link HomeFragment.OnFragmentInteractionListener} interface | |
| 49 | - * to handle interaction events. | |
| 50 | - * Use the {@link HomeFragment#newInstance} factory method to | |
| 51 | - * create an instance of this fragment. | |
| 52 | - */ | |
| 53 | -public class HomeFragment extends Fragment implements RecyclerViewOnClickListenerHack { | |
| 54 | - | |
| 55 | - | |
| 56 | - private OnFragmentInteractionListener mListener; | |
| 57 | - private RecyclerView mRecyclerView; | |
| 58 | - private VereadorAdapter mAdapter; | |
| 59 | - private List<ParseObject> ob; | |
| 60 | - private HashMap<String,Float> valorTotal = new HashMap<String,Float>(); | |
| 61 | - ArrayList<String> xVals = new ArrayList<String>(); | |
| 62 | - ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>(); | |
| 63 | - | |
| 64 | - public BarChart mChart; | |
| 65 | - | |
| 66 | - /** | |
| 67 | - * Use this factory method to create a new instance of | |
| 68 | - * this fragment using the provided parameters. | |
| 69 | - * @return A new instance of fragment HomeFragment. | |
| 70 | - */ | |
| 71 | - // TODO: Rename and change types and number of parameters | |
| 72 | - public static HomeFragment newInstance() { | |
| 73 | - HomeFragment fragment = new HomeFragment(); | |
| 74 | - Bundle args = new Bundle(); | |
| 75 | - | |
| 76 | - fragment.setArguments(args); | |
| 77 | - return fragment; | |
| 78 | - } | |
| 79 | - | |
| 80 | - public HomeFragment() { | |
| 81 | - // Required empty public constructor | |
| 82 | - } | |
| 83 | - | |
| 84 | - @Override | |
| 85 | - public void onCreate(Bundle savedInstanceState) { | |
| 86 | - super.onCreate(savedInstanceState); | |
| 87 | - | |
| 88 | - } | |
| 89 | - | |
| 90 | - @Override | |
| 91 | - public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
| 92 | - Bundle savedInstanceState) { | |
| 93 | - // Inflate the layout for this fragment | |
| 94 | - View view = inflater.inflate(R.layout.fragment_home, container, false); | |
| 95 | - //tableview | |
| 96 | - mRecyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view); | |
| 97 | - | |
| 98 | - | |
| 99 | - // use this setting to improve performance if you know that changes | |
| 100 | - // in content do not change the layout size of the RecyclerView | |
| 101 | - mRecyclerView.setHasFixedSize(true); | |
| 102 | - | |
| 103 | - LinearLayoutManager llm = new LinearLayoutManager(getActivity()); | |
| 104 | - llm.setOrientation(LinearLayoutManager.VERTICAL); | |
| 105 | - mRecyclerView.setLayoutManager(llm); | |
| 106 | - | |
| 107 | - //buscar os vereadores | |
| 108 | - buscaVereadores(); | |
| 109 | - | |
| 110 | - //buscar o grafico de gastos | |
| 111 | - mChart = (BarChart)view.findViewById(R.id.chart1); | |
| 112 | - | |
| 113 | - buscaGastos(); | |
| 114 | - | |
| 115 | - FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab); | |
| 116 | - fab.setOnClickListener(new View.OnClickListener() { | |
| 117 | - @Override | |
| 118 | - public void onClick(View view) { | |
| 119 | - Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); | |
| 120 | - sharingIntent.setType("text/plain"); | |
| 121 | - String shareBody = "Recomendo o app Participa Cidadão https://play.google.com/store/apps/details?id=com.monitorabrasil.monitoramunicipio"; | |
| 122 | - sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Participa Cidadão"); | |
| 123 | - sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody); | |
| 124 | - startActivity(Intent.createChooser(sharingIntent, "Compartilhar via")); | |
| 125 | - | |
| 126 | - } | |
| 127 | - }); | |
| 128 | - | |
| 129 | - | |
| 130 | - return view; | |
| 131 | - } | |
| 132 | - | |
| 133 | - private ParseObject buscaGastos() { | |
| 134 | - | |
| 135 | - ParseQuery<ParseObject> query = ParseQuery.getQuery("DespesaCamara"); | |
| 136 | - query.setLimit(200); | |
| 137 | - //query.whereEqualTo("politico",politico); | |
| 138 | - | |
| 139 | - query.addAscendingOrder("mes_numero"); | |
| 140 | - query.findInBackground(new FindCallback<ParseObject>() { | |
| 141 | - public void done(List<ParseObject> gastos, ParseException e) { | |
| 142 | - if(null != gastos){ | |
| 143 | - Iterator<ParseObject> gastoIt = gastos.iterator(); | |
| 144 | - | |
| 145 | - while (gastoIt.hasNext()) { | |
| 146 | - | |
| 147 | - ParseObject g = gastoIt.next(); | |
| 148 | - String mes = g.getString("mes"); | |
| 149 | - Float novoValor = Float.valueOf(g.getString("valor")); | |
| 150 | - Float valor = valorTotal.get(mes); | |
| 151 | - if (valor != null) { | |
| 152 | - valor = valor + novoValor; | |
| 153 | - valorTotal.remove(mes); | |
| 154 | - valorTotal.put(mes, valor); | |
| 155 | - } else { | |
| 156 | - valorTotal.put(mes, novoValor); | |
| 157 | - } | |
| 158 | - if (!xVals.contains(mes)) { | |
| 159 | - xVals.add(mes); | |
| 160 | - } | |
| 161 | - | |
| 162 | - } | |
| 163 | - for (int j = 0; j < xVals.size(); j++) { | |
| 164 | - Float val = valorTotal.get(xVals.get(j)); | |
| 165 | - yVals1.add(new BarEntry(val, j)); | |
| 166 | - } | |
| 167 | - Grafico grafico = new Grafico("Todos", yVals1, xVals, R.color.cor10); | |
| 168 | - buildGraph(grafico); | |
| 169 | - } | |
| 170 | - | |
| 171 | - | |
| 172 | - } | |
| 173 | - }); | |
| 174 | - | |
| 175 | - | |
| 176 | - return null; | |
| 177 | - } | |
| 178 | - | |
| 179 | - private void buildGraph(Grafico grafico) { | |
| 180 | - | |
| 181 | -// mChart.set | |
| 182 | - | |
| 183 | - mChart.setDrawBarShadow(false); | |
| 184 | - mChart.setDrawValueAboveBar(true); | |
| 185 | - | |
| 186 | - mChart.setDescription(""); | |
| 187 | - | |
| 188 | - // if more than 60 entries are displayed in the chart, no values will be | |
| 189 | - // drawn | |
| 190 | - mChart.setMaxVisibleValueCount(60); | |
| 191 | - | |
| 192 | - // scaling can now only be done on x- and y-axis separately | |
| 193 | - mChart.setPinchZoom(false); | |
| 194 | - | |
| 195 | - // draw shadows for each bar that show the maximum value | |
| 196 | - // mChart.setDrawBarShadow(true); | |
| 197 | - | |
| 198 | - // mChart.setDrawXLabels(false); | |
| 199 | - | |
| 200 | - mChart.setDrawGridBackground(false); | |
| 201 | - // mChart.setDrawYLabels(false); | |
| 202 | - | |
| 203 | -// mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); | |
| 204 | - | |
| 205 | - XAxis xAxis = mChart.getXAxis(); | |
| 206 | - xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); | |
| 207 | -// xAxis.setTypeface(mTf); | |
| 208 | - xAxis.setDrawGridLines(false); | |
| 209 | - xAxis.setSpaceBetweenLabels(2); | |
| 210 | - | |
| 211 | - ValueFormatter custom = new MyValueFormatter(); | |
| 212 | - | |
| 213 | - YAxis leftAxis = mChart.getAxisLeft(); | |
| 214 | -// leftAxis.setTypeface(mTf); | |
| 215 | - leftAxis.setLabelCount(8); | |
| 216 | - leftAxis.setValueFormatter(custom); | |
| 217 | - leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART); | |
| 218 | - leftAxis.setSpaceTop(15f); | |
| 219 | - | |
| 220 | - mChart.getAxisRight().setEnabled(false); | |
| 221 | - YAxis rightAxis = mChart.getAxisRight(); | |
| 222 | - rightAxis.setDrawGridLines(false); | |
| 223 | -// rightAxis.setTypeface(mTf); | |
| 224 | - rightAxis.setLabelCount(8); | |
| 225 | - rightAxis.setValueFormatter(custom); | |
| 226 | - rightAxis.setSpaceTop(15f); | |
| 227 | - | |
| 228 | - Legend l = mChart.getLegend(); | |
| 229 | - l.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT); | |
| 230 | - l.setForm(Legend.LegendForm.SQUARE); | |
| 231 | - l.setFormSize(9f); | |
| 232 | - l.setTextSize(11f); | |
| 233 | - l.setXEntrySpace(4f); | |
| 234 | - // l.setExtra(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc", | |
| 235 | - // "def", "ghj", "ikl", "mno" }); | |
| 236 | - // l.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc", | |
| 237 | - // "def", "ghj", "ikl", "mno" }); | |
| 238 | - | |
| 239 | - | |
| 240 | - | |
| 241 | - // setting data | |
| 242 | -// mSeekBarY.setProgress(50); | |
| 243 | -// mSeekBarX.setProgress(12); | |
| 244 | -// | |
| 245 | -// mSeekBarY.setOnSeekBarChangeListener(this); | |
| 246 | -// mSeekBarX.setOnSeekBarChangeListener(this); | |
| 247 | - | |
| 248 | - // mChart.setDrawLegend(false); | |
| 249 | - | |
| 250 | - | |
| 251 | - //setdata | |
| 252 | - | |
| 253 | - setData(grafico); | |
| 254 | - | |
| 255 | - mChart.animateX(2500, Easing.EasingOption.EaseInOutQuart); | |
| 256 | - mChart.notifyDataSetChanged(); | |
| 257 | - | |
| 258 | - } | |
| 259 | - | |
| 260 | - private void setData(Grafico grafico) { | |
| 261 | - | |
| 262 | - | |
| 263 | - | |
| 264 | - BarDataSet set1 = new BarDataSet(grafico.getyAxis(), "Gastos Totais"); | |
| 265 | - set1.setBarSpacePercent(35f); | |
| 266 | - | |
| 267 | - ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>(); | |
| 268 | - dataSets.add(set1); | |
| 269 | - try{ | |
| 270 | - set1.setColor(MyApp.getInstance().getResources().getColor(grafico.getCor())); | |
| 271 | - | |
| 272 | - BarData data = new BarData(grafico.getxVals(), dataSets); | |
| 273 | - // data.setValueFormatter(new MyValueFormatter()); | |
| 274 | - data.setValueTextSize(10f); | |
| 275 | -// data.setValueTypeface(mTf); | |
| 276 | - mChart.setVisibility(View.VISIBLE); | |
| 277 | - mChart.setData(data); | |
| 278 | - | |
| 279 | - | |
| 280 | - | |
| 281 | - }catch (Exception e){ | |
| 282 | - Crashlytics.log("GastosCamaraFragment " + e.toString()); | |
| 283 | - } | |
| 284 | - | |
| 285 | - } | |
| 286 | - | |
| 287 | - // TODO: Rename method, update argument and hook method into UI event | |
| 288 | - public void onButtonPressed(Uri uri) { | |
| 289 | - if (mListener != null) { | |
| 290 | - mListener.onFragmentInteraction(uri); | |
| 291 | - } | |
| 292 | - } | |
| 293 | - | |
| 294 | - //busca objetos | |
| 295 | - public void buscaVereadores(){ | |
| 296 | - ParseQuery<ParseObject> query = ParseQuery.getQuery("Politico"); | |
| 297 | - query.addDescendingOrder("avaliacao"); | |
| 298 | - //query.whereEqualTo("playerName", "Dan Stemkoski"); | |
| 299 | - query.findInBackground(new FindCallback<ParseObject>() { | |
| 300 | - @Override | |
| 301 | - public void done(List<ParseObject> list, com.parse.ParseException e) { | |
| 302 | - if (e == null) { | |
| 303 | - ob = list; | |
| 304 | - carregaList(list); | |
| 305 | - } else { | |
| 306 | - Log.d("score", "Error: " + e.getMessage()); | |
| 307 | - } | |
| 308 | - } | |
| 309 | - | |
| 310 | - | |
| 311 | - }); | |
| 312 | - } | |
| 313 | - | |
| 314 | - public void carregaList(List<ParseObject> list){ | |
| 315 | - mAdapter = new VereadorAdapter(list); | |
| 316 | - mAdapter.setRecyclerViewOnClickListenerHack(this); | |
| 317 | - mRecyclerView.setAdapter(mAdapter); | |
| 318 | - //pb.setVisibility(View.INVISIBLE); | |
| 319 | - } | |
| 320 | - | |
| 321 | - @Override | |
| 322 | - public void onClickListener(View view, int position) { | |
| 323 | - Intent intent = new Intent(getActivity(),PoliticoFichaActivity.class); | |
| 324 | - intent.putExtra("politico", ob.get(position).getObjectId()); | |
| 325 | - startActivity(intent); | |
| 326 | - | |
| 327 | - } | |
| 328 | - | |
| 329 | - @Override | |
| 330 | - public void onAttach(Activity activity) { | |
| 331 | - super.onAttach(activity); | |
| 332 | - try { | |
| 333 | - mListener = (OnFragmentInteractionListener) activity; | |
| 334 | - } catch (ClassCastException e) { | |
| 335 | - throw new ClassCastException(activity.toString() | |
| 336 | - + " must implement OnFragmentInteractionListener"); | |
| 337 | - } | |
| 338 | - } | |
| 339 | - | |
| 340 | - @Override | |
| 341 | - public void onDetach() { | |
| 342 | - super.onDetach(); | |
| 343 | - mListener = null; | |
| 344 | - } | |
| 345 | - | |
| 346 | - /** | |
| 347 | - * This interface must be implemented by activities that contain this | |
| 348 | - * fragment to allow an interaction in this fragment to be communicated | |
| 349 | - * to the activity and potentially other fragments contained in that | |
| 350 | - * activity. | |
| 351 | - * <p/> | |
| 352 | - * See the Android Training lesson <a href= | |
| 353 | - * "http://developer.android.com/training/basics/fragments/communicating.html" | |
| 354 | - * >Communicating with Other Fragments</a> for more information. | |
| 355 | - */ | |
| 356 | - public interface OnFragmentInteractionListener { | |
| 357 | - // TODO: Update argument type and name | |
| 358 | - public void onFragmentInteraction(Uri uri); | |
| 359 | - } | |
| 360 | - | |
| 361 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/fragments/ListaPoliticoFragment.java
| ... | ... | @@ -1,115 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo.fragments; | |
| 2 | - | |
| 3 | -import android.content.Intent; | |
| 4 | -import android.os.Bundle; | |
| 5 | -import android.support.v4.app.Fragment; | |
| 6 | -import android.support.v4.app.FragmentTransaction; | |
| 7 | -import android.support.v7.widget.LinearLayoutManager; | |
| 8 | -import android.support.v7.widget.RecyclerView; | |
| 9 | -import android.util.Log; | |
| 10 | -import android.view.LayoutInflater; | |
| 11 | -import android.view.View; | |
| 12 | -import android.view.ViewGroup; | |
| 13 | -import android.widget.ProgressBar; | |
| 14 | -import android.widget.Toast; | |
| 15 | - | |
| 16 | -import com.google.gson.Gson; | |
| 17 | -import com.monitorabrasil.monitoralegislativo.PoliticoFichaActivity; | |
| 18 | -import com.monitorabrasil.monitoralegislativo.R; | |
| 19 | -import com.monitorabrasil.monitoralegislativo.adapters.VereadorAdapter; | |
| 20 | -import com.monitorabrasil.monitoralegislativo.interfaces.RecyclerViewOnClickListenerHack; | |
| 21 | -import com.parse.FindCallback; | |
| 22 | -import com.parse.ParseException; | |
| 23 | -import com.parse.ParseObject; | |
| 24 | -import com.parse.ParseQuery; | |
| 25 | - | |
| 26 | -import java.util.List; | |
| 27 | - | |
| 28 | -/** | |
| 29 | - * Created by geraugu on 6/10/15. | |
| 30 | - */ | |
| 31 | -public class ListaPoliticoFragment extends Fragment implements RecyclerViewOnClickListenerHack { | |
| 32 | - | |
| 33 | - private RecyclerView mRecyclerView; | |
| 34 | - private VereadorAdapter mAdapter; | |
| 35 | - private List<ParseObject> ob; | |
| 36 | - private ProgressBar pb; | |
| 37 | - | |
| 38 | - @Override | |
| 39 | - public View onCreateView(LayoutInflater inflater, | |
| 40 | - ViewGroup container, | |
| 41 | - Bundle savedInstanceState) { | |
| 42 | - View view = inflater.inflate(R.layout.fragment_list_politico, container, false); | |
| 43 | - | |
| 44 | - pb = (ProgressBar) view.findViewById(R.id.progressBar); | |
| 45 | - | |
| 46 | - | |
| 47 | - //tableview | |
| 48 | - mRecyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view); | |
| 49 | - | |
| 50 | - | |
| 51 | - // use this setting to improve performance if you know that changes | |
| 52 | - // in content do not change the layout size of the RecyclerView | |
| 53 | - mRecyclerView.setHasFixedSize(true); | |
| 54 | - | |
| 55 | - LinearLayoutManager llm = new LinearLayoutManager(getActivity()); | |
| 56 | - llm.setOrientation(LinearLayoutManager.VERTICAL); | |
| 57 | - mRecyclerView.setLayoutManager(llm); | |
| 58 | - | |
| 59 | - buscaVereadores(); | |
| 60 | - | |
| 61 | - return view; | |
| 62 | - | |
| 63 | - } | |
| 64 | - | |
| 65 | - //busca objetos | |
| 66 | - public void buscaVereadores(){ | |
| 67 | - ParseQuery<ParseObject> query = ParseQuery.getQuery("Politico"); | |
| 68 | - query.addAscendingOrder("nome"); | |
| 69 | - //query.whereEqualTo("playerName", "Dan Stemkoski"); | |
| 70 | - query.findInBackground(new FindCallback<ParseObject>() { | |
| 71 | - @Override | |
| 72 | - public void done(List<ParseObject> list, com.parse.ParseException e) { | |
| 73 | - if (e == null) { | |
| 74 | - ob = list; | |
| 75 | - carregaList(list); | |
| 76 | - } else { | |
| 77 | - Log.d("score", "Error: " + e.getMessage()); | |
| 78 | - } | |
| 79 | - } | |
| 80 | - | |
| 81 | - | |
| 82 | - }); | |
| 83 | - } | |
| 84 | - | |
| 85 | - public void carregaList(List<ParseObject> list){ | |
| 86 | - mAdapter = new VereadorAdapter(list); | |
| 87 | - mAdapter.setRecyclerViewOnClickListenerHack(this); | |
| 88 | - mRecyclerView.setAdapter(mAdapter); | |
| 89 | - pb.setVisibility(View.INVISIBLE); | |
| 90 | - } | |
| 91 | - | |
| 92 | - | |
| 93 | - | |
| 94 | - @Override | |
| 95 | - public void onClickListener(View view, int position) { | |
| 96 | - | |
| 97 | - | |
| 98 | -// PoliticoFragment frag = new PoliticoFragment(); | |
| 99 | -// Bundle bundle = new Bundle(); | |
| 100 | -// try { | |
| 101 | -// ob.get(position).pin(); | |
| 102 | -// } catch (ParseException e) { | |
| 103 | -// e.printStackTrace(); | |
| 104 | -// } | |
| 105 | -// bundle.putString("politico", ob.get(position).getObjectId()); | |
| 106 | -// frag.setArguments(bundle); | |
| 107 | -// FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); | |
| 108 | -// ft.replace(R.id.rl_fragment_container, frag, "politicoFrag"); | |
| 109 | -// ft.addToBackStack(null); | |
| 110 | -// ft.commit(); | |
| 111 | - Intent intent = new Intent(getActivity(),PoliticoFichaActivity.class); | |
| 112 | - intent.putExtra("politico", ob.get(position).getObjectId()); | |
| 113 | - startActivity(intent); | |
| 114 | - } | |
| 115 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/fragments/ListaProjetosFragment.java
| ... | ... | @@ -1,162 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo.fragments; | |
| 2 | - | |
| 3 | - | |
| 4 | -import android.os.Bundle; | |
| 5 | -import android.support.v4.app.Fragment; | |
| 6 | -import android.support.v4.app.FragmentTransaction; | |
| 7 | -import android.support.v7.widget.LinearLayoutManager; | |
| 8 | -import android.support.v7.widget.RecyclerView; | |
| 9 | -import android.util.Log; | |
| 10 | -import android.view.LayoutInflater; | |
| 11 | -import android.view.View; | |
| 12 | -import android.view.ViewGroup; | |
| 13 | -import android.widget.ProgressBar; | |
| 14 | - | |
| 15 | -import com.crashlytics.android.answers.Answers; | |
| 16 | -import com.crashlytics.android.answers.ContentViewEvent; | |
| 17 | -import com.monitorabrasil.monitoralegislativo.R; | |
| 18 | -import com.monitorabrasil.monitoralegislativo.adapters.ProjetoAdapter; | |
| 19 | -import com.monitorabrasil.monitoralegislativo.adapters.VereadorAdapter; | |
| 20 | -import com.monitorabrasil.monitoralegislativo.interfaces.RecyclerViewOnClickListenerHack; | |
| 21 | -import com.parse.FindCallback; | |
| 22 | -import com.parse.ParseException; | |
| 23 | -import com.parse.ParseObject; | |
| 24 | -import com.parse.ParseQuery; | |
| 25 | - | |
| 26 | -import java.util.List; | |
| 27 | - | |
| 28 | -/** | |
| 29 | - * A simple {@link Fragment} subclass. | |
| 30 | - */ | |
| 31 | -public class ListaProjetosFragment extends Fragment implements RecyclerViewOnClickListenerHack { | |
| 32 | - | |
| 33 | - private RecyclerView mRecyclerView; | |
| 34 | - private ProjetoAdapter mAdapter; | |
| 35 | - private List<ParseObject> ob; | |
| 36 | - private ProgressBar pb; | |
| 37 | - private static final String TIPO_PROJETO = "tipoProjeto"; | |
| 38 | - private static final String ID_POLITICO = "idPolitico"; | |
| 39 | - private String tipoProjeto; | |
| 40 | - private String idPolitico; | |
| 41 | - | |
| 42 | - | |
| 43 | - public static ListaProjetosFragment newInstance(String tipoProjeto, String idPolitico) { | |
| 44 | - ListaProjetosFragment fragment = new ListaProjetosFragment(); | |
| 45 | - Bundle args = new Bundle(); | |
| 46 | - args.putString(TIPO_PROJETO, tipoProjeto); | |
| 47 | - args.putString(ID_POLITICO, idPolitico); | |
| 48 | - fragment.setArguments(args); | |
| 49 | - return fragment; | |
| 50 | - } | |
| 51 | - public ListaProjetosFragment(){ | |
| 52 | - | |
| 53 | - } | |
| 54 | - | |
| 55 | - @Override | |
| 56 | - public void onCreate(Bundle savedInstanceState) { | |
| 57 | - super.onCreate(savedInstanceState); | |
| 58 | - if (getArguments() != null) { | |
| 59 | - tipoProjeto = getArguments().getString(TIPO_PROJETO); | |
| 60 | - idPolitico = getArguments().getString(ID_POLITICO); | |
| 61 | - } | |
| 62 | - } | |
| 63 | - | |
| 64 | - | |
| 65 | - @Override | |
| 66 | - public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
| 67 | - Bundle savedInstanceState) { | |
| 68 | - // Inflate the layout for this fragment | |
| 69 | - View view = inflater.inflate(R.layout.fragment_lista_projetos, container, false); | |
| 70 | - // View view = inflater.inflate(R.layout.fragment_escolha_tipo_projeto, container, false); | |
| 71 | - | |
| 72 | - pb = (ProgressBar) view.findViewById(R.id.progressBar); | |
| 73 | - | |
| 74 | - | |
| 75 | - //tableview | |
| 76 | - mRecyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view); | |
| 77 | - | |
| 78 | - // use this setting to improve performance if you know that changes | |
| 79 | - // in content do not change the layout size of the RecyclerView | |
| 80 | - mRecyclerView.setHasFixedSize(true); | |
| 81 | - | |
| 82 | - LinearLayoutManager llm = new LinearLayoutManager(getActivity()); | |
| 83 | - llm.setOrientation(LinearLayoutManager.VERTICAL); | |
| 84 | - mRecyclerView.setLayoutManager(llm); | |
| 85 | - | |
| 86 | - buscaProjetos(); | |
| 87 | - return view; | |
| 88 | - } | |
| 89 | - | |
| 90 | - public void buscaProjetos(){ | |
| 91 | - ParseQuery<ParseObject> query = ParseQuery.getQuery("Projeto"); | |
| 92 | - query.addDescendingOrder("createdAt"); | |
| 93 | - | |
| 94 | - if(idPolitico!= null){ | |
| 95 | - | |
| 96 | - query.whereEqualTo("politico", buscaPolitico(idPolitico)); | |
| 97 | - | |
| 98 | - } | |
| 99 | - | |
| 100 | - if(tipoProjeto != null){ | |
| 101 | - query.whereEqualTo("classificacao", tipoProjeto); | |
| 102 | - Answers.getInstance().logContentView(new ContentViewEvent() | |
| 103 | - .putContentName("ListaProjetosFragment") | |
| 104 | - .putContentType("Fragment") | |
| 105 | - .putCustomAttribute("tipoProjeto", tipoProjeto)); | |
| 106 | - } | |
| 107 | - | |
| 108 | - | |
| 109 | - query.findInBackground(new FindCallback<ParseObject>() { | |
| 110 | - @Override | |
| 111 | - public void done(List<ParseObject> list, com.parse.ParseException e) { | |
| 112 | - if (e == null) { | |
| 113 | - ob = list; | |
| 114 | - carregaList(list); | |
| 115 | - } else { | |
| 116 | - Log.d("score", "Error: " + e.getMessage()); | |
| 117 | - } | |
| 118 | - } | |
| 119 | - | |
| 120 | - | |
| 121 | - }); | |
| 122 | - } | |
| 123 | - | |
| 124 | - private ParseObject buscaPolitico(String id) { | |
| 125 | - | |
| 126 | - ParseQuery<ParseObject> query = ParseQuery.getQuery("Politico"); | |
| 127 | - query.fromLocalDatastore(); | |
| 128 | - try { | |
| 129 | - return query.get(id); | |
| 130 | - } catch (com.parse.ParseException e) { | |
| 131 | - e.printStackTrace(); | |
| 132 | - } | |
| 133 | - return null; | |
| 134 | - } | |
| 135 | - | |
| 136 | - public void carregaList(List<ParseObject> list){ | |
| 137 | - mAdapter = new ProjetoAdapter(list,getActivity()); | |
| 138 | - mAdapter.setRecyclerViewOnClickListenerHack(this); | |
| 139 | - mRecyclerView.setAdapter(mAdapter); | |
| 140 | - pb.setVisibility(View.INVISIBLE); | |
| 141 | - } | |
| 142 | - | |
| 143 | - @Override | |
| 144 | - public void onClickListener(View view, int position) { | |
| 145 | - | |
| 146 | - | |
| 147 | -// PoliticoFragment frag = new PoliticoFragment(); | |
| 148 | -// Bundle bundle = new Bundle(); | |
| 149 | -// try { | |
| 150 | -// ob.get(position).pin(); | |
| 151 | -// } catch (ParseException e) { | |
| 152 | -// e.printStackTrace(); | |
| 153 | -// } | |
| 154 | -// bundle.putString("politico", ob.get(position).getObjectId()); | |
| 155 | -// frag.setArguments(bundle); | |
| 156 | -// FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); | |
| 157 | -// ft.replace(R.id.rl_fragment_container, frag, "politicoFrag"); | |
| 158 | -// ft.addToBackStack(null); | |
| 159 | -// ft.commit(); | |
| 160 | - } | |
| 161 | - | |
| 162 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/fragments/PoliticoFichaFragment.java
| ... | ... | @@ -1,156 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo.fragments; | |
| 2 | - | |
| 3 | -import android.content.DialogInterface; | |
| 4 | -import android.graphics.PorterDuff; | |
| 5 | -import android.graphics.drawable.LayerDrawable; | |
| 6 | -import android.os.Build; | |
| 7 | -import android.os.Bundle; | |
| 8 | -import android.support.design.widget.Snackbar; | |
| 9 | -import android.support.v4.app.Fragment; | |
| 10 | -import android.util.Log; | |
| 11 | -import android.view.LayoutInflater; | |
| 12 | -import android.view.View; | |
| 13 | -import android.view.ViewGroup; | |
| 14 | -import android.widget.Button; | |
| 15 | -import android.widget.ImageView; | |
| 16 | -import android.widget.RatingBar; | |
| 17 | -import android.widget.TextView; | |
| 18 | - | |
| 19 | -import com.crashlytics.android.answers.Answers; | |
| 20 | -import com.crashlytics.android.answers.ContentViewEvent; | |
| 21 | -import com.monitorabrasil.monitoralegislativo.R; | |
| 22 | -import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 23 | -import com.monitorabrasil.monitoralegislativo.dialogs.DialogAvaliacao; | |
| 24 | -import com.parse.Parse; | |
| 25 | -import com.parse.ParseException; | |
| 26 | -import com.parse.ParseObject; | |
| 27 | -import com.parse.ParseQuery; | |
| 28 | -import com.parse.ParseUser; | |
| 29 | - | |
| 30 | -import java.text.NumberFormat; | |
| 31 | - | |
| 32 | -/** | |
| 33 | - * Created by geral_000 on 20/06/2015. | |
| 34 | - */ | |
| 35 | -public class PoliticoFichaFragment extends Fragment { | |
| 36 | - | |
| 37 | - | |
| 38 | - private ParseObject politico; | |
| 39 | - private View mView; | |
| 40 | - private RatingBar mRatingBar; | |
| 41 | - private Button btnAvaliar; | |
| 42 | - | |
| 43 | - | |
| 44 | - public View onCreateView(LayoutInflater inflater, | |
| 45 | - ViewGroup container, | |
| 46 | - Bundle savedInstanceState) { | |
| 47 | - View view = inflater.inflate(R.layout.fragment_politico_detalhe, container, false); | |
| 48 | - | |
| 49 | - | |
| 50 | - | |
| 51 | - mView=view; | |
| 52 | - mRatingBar = (RatingBar)view.findViewById(R.id.ratingBar); | |
| 53 | - | |
| 54 | - | |
| 55 | - | |
| 56 | - | |
| 57 | - | |
| 58 | - Bundle bundle = getArguments(); | |
| 59 | - politico = buscaPolitico(bundle.getString("politico")) ; | |
| 60 | - | |
| 61 | - Answers.getInstance().logContentView(new ContentViewEvent() | |
| 62 | - .putContentName("PoliticoFichaFragment") | |
| 63 | - .putContentType("Fragment") | |
| 64 | - .putCustomAttribute("vereador",politico.getString("nome"))); | |
| 65 | - | |
| 66 | - | |
| 67 | - mRatingBar.setRating((float) politico.getDouble("avaliacao")); | |
| 68 | - | |
| 69 | - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ | |
| 70 | - LayerDrawable stars = (LayerDrawable) mRatingBar.getProgressDrawable(); | |
| 71 | - stars.getDrawable(2).setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.SRC_ATOP); | |
| 72 | - stars.getDrawable(1).setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.SRC_ATOP); | |
| 73 | - stars.getDrawable(0).setColorFilter(getResources().getColor(R.color.coloLink), PorterDuff.Mode.SRC_ATOP); | |
| 74 | - } | |
| 75 | - | |
| 76 | - | |
| 77 | - //btnAvaliar | |
| 78 | - btnAvaliar = (Button) view.findViewById(R.id.btnAvalie); | |
| 79 | - btnAvaliar.setOnClickListener(new View.OnClickListener() { | |
| 80 | - @Override | |
| 81 | - public void onClick(final View v) { | |
| 82 | - if(ParseUser.getCurrentUser() != null){ | |
| 83 | - DialogAvaliacao avaliacao =new DialogAvaliacao(politico, "Avalie"); | |
| 84 | - avaliacao.setOnDismissListener(new DialogInterface.OnDismissListener() { | |
| 85 | - @Override | |
| 86 | - public void onDismiss(DialogInterface dialog) { | |
| 87 | - //atualizar a avaliacao | |
| 88 | - try { | |
| 89 | - politico.fetchFromLocalDatastore(); | |
| 90 | - mRatingBar.setRating((float) politico.getDouble("avaliacao")); | |
| 91 | - Snackbar.make(v, "Avaliação salva.", Snackbar.LENGTH_LONG) | |
| 92 | - .setAction("Action", null).show(); | |
| 93 | - } catch (ParseException e) { | |
| 94 | - e.printStackTrace(); | |
| 95 | - } | |
| 96 | - | |
| 97 | - } | |
| 98 | - }); | |
| 99 | - avaliacao.show(getActivity().getFragmentManager(), "dialogAvaliar"); | |
| 100 | - }else{ | |
| 101 | - Snackbar.make(v, "É necessário logar para avaliar.", Snackbar.LENGTH_LONG) | |
| 102 | - .setAction("Action", null).show(); | |
| 103 | - } | |
| 104 | - | |
| 105 | - } | |
| 106 | - }); | |
| 107 | - | |
| 108 | - //foto | |
| 109 | - ImageView foto = (ImageView)view.findViewById(R.id.foto); | |
| 110 | - MyApp.getInstance().getmImagemLoader().displayImage(MyApp.URL_FOTO+politico.get("cpf")+".jpg",foto); | |
| 111 | - | |
| 112 | - //nome | |
| 113 | - TextView txtNome = (TextView) view.findViewById(R.id.txtNome); | |
| 114 | - txtNome.setText(politico.get("nome").toString()); | |
| 115 | - | |
| 116 | - //telefone | |
| 117 | - TextView telefone = (TextView) view.findViewById(R.id.txtTelefone); | |
| 118 | - telefone.setText(politico.get("telefone").toString()); | |
| 119 | - //telefone | |
| 120 | - TextView txtPartido = (TextView) view.findViewById(R.id.txtPartido); | |
| 121 | - txtPartido.setText(politico.get("partido").toString()); | |
| 122 | ||
| 123 | - TextView email = (TextView) view.findViewById(R.id.email); | |
| 124 | - email.setText(politico.get("email").toString()); | |
| 125 | ||
| 126 | - TextView facebook = (TextView) view.findViewById(R.id.facebook); | |
| 127 | - facebook.setText(politico.get("facebook").toString()); | |
| 128 | - //gastos | |
| 129 | - TextView gastos = (TextView) view.findViewById(R.id.gastos); | |
| 130 | - gastos.setText(politico.get("gasto_campanha").toString().replace(",","").replace(".",",")); | |
| 131 | - //bens declarados | |
| 132 | - TextView bens = (TextView) view.findViewById(R.id.bens); | |
| 133 | - bens.setText(politico.get("bens_declarados").toString().replace(",", "").replace(".",",")); | |
| 134 | - | |
| 135 | - return view; | |
| 136 | - } | |
| 137 | - | |
| 138 | - @Override | |
| 139 | - public void onResume() { | |
| 140 | - Log.e("DEBUG", "onResume of HomeFragment"); | |
| 141 | - super.onResume(); | |
| 142 | - } | |
| 143 | - | |
| 144 | - | |
| 145 | - private ParseObject buscaPolitico(String id) { | |
| 146 | - | |
| 147 | - ParseQuery<ParseObject> query = ParseQuery.getQuery("Politico"); | |
| 148 | - query.fromLocalDatastore(); | |
| 149 | - try { | |
| 150 | - return query.get(id); | |
| 151 | - } catch (com.parse.ParseException e) { | |
| 152 | - e.printStackTrace(); | |
| 153 | - } | |
| 154 | - return null; | |
| 155 | - } | |
| 156 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/interfaces/RecyclerViewOnClickListenerHack.java
app/src/main/java/com/monitorabrasil/monitoralegislativo/model/Grafico.java
0 → 100644
| ... | ... | @@ -0,0 +1,54 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.model; | |
| 2 | + | |
| 3 | +import com.github.mikephil.charting.data.BarEntry; | |
| 4 | + | |
| 5 | +import java.util.ArrayList; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * Created by geral_000 on 27/06/2015. | |
| 9 | + */ | |
| 10 | +public class Grafico { | |
| 11 | + private String titulo; | |
| 12 | + private ArrayList<BarEntry> yAxis; | |
| 13 | + private ArrayList<String> xVals; | |
| 14 | + private int cor; | |
| 15 | + | |
| 16 | + public Grafico(String titulo, ArrayList<BarEntry> yAxis, ArrayList<String> xVals,int cor) { | |
| 17 | + this.titulo = titulo; | |
| 18 | + this.yAxis = yAxis; | |
| 19 | + this.xVals = xVals; | |
| 20 | + this.cor = cor; | |
| 21 | + } | |
| 22 | + | |
| 23 | + public String getTitulo() { | |
| 24 | + return titulo; | |
| 25 | + } | |
| 26 | + | |
| 27 | + public void setTitulo(String titulo) { | |
| 28 | + this.titulo = titulo; | |
| 29 | + } | |
| 30 | + | |
| 31 | + public ArrayList<BarEntry> getyAxis() { | |
| 32 | + return yAxis; | |
| 33 | + } | |
| 34 | + | |
| 35 | + public void setyAxis(ArrayList<BarEntry> yAxis) { | |
| 36 | + this.yAxis = yAxis; | |
| 37 | + } | |
| 38 | + | |
| 39 | + public ArrayList<String> getxVals() { | |
| 40 | + return xVals; | |
| 41 | + } | |
| 42 | + | |
| 43 | + public void setxVals(ArrayList<String> xVals) { | |
| 44 | + this.xVals = xVals; | |
| 45 | + } | |
| 46 | + | |
| 47 | + public int getCor() { | |
| 48 | + return cor; | |
| 49 | + } | |
| 50 | + | |
| 51 | + public void setCor(int cor) { | |
| 52 | + this.cor = cor; | |
| 53 | + } | |
| 54 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/model/util/MyValueFormatter.java
0 → 100644
| ... | ... | @@ -0,0 +1,24 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.model.util; | |
| 2 | + | |
| 3 | +import com.github.mikephil.charting.utils.ValueFormatter; | |
| 4 | + | |
| 5 | +import java.text.DecimalFormat; | |
| 6 | +import java.text.NumberFormat; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * Created by geral_000 on 21/06/2015. | |
| 10 | + */ | |
| 11 | +public class MyValueFormatter implements ValueFormatter { | |
| 12 | + | |
| 13 | + private DecimalFormat mFormat; | |
| 14 | + | |
| 15 | + public MyValueFormatter() { | |
| 16 | + mFormat = new DecimalFormat("###,###,###,##0.0"); | |
| 17 | + } | |
| 18 | + | |
| 19 | + @Override | |
| 20 | + public String getFormattedValue(float value) { | |
| 21 | + return "R$" + NumberFormat.getCurrencyInstance().format(value) ; | |
| 22 | + } | |
| 23 | + | |
| 24 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/stores/Store.java
0 → 100644
| ... | ... | @@ -0,0 +1,26 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.stores; | |
| 2 | + | |
| 3 | + | |
| 4 | +import com.monitorabrasil.monitoralegislativo.actions.Action; | |
| 5 | +import com.monitorabrasil.monitoralegislativo.dispatcher.Dispatcher; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * Created by lgvalle on 02/08/15. | |
| 9 | + */ | |
| 10 | +public abstract class Store { | |
| 11 | + | |
| 12 | + final Dispatcher dispatcher; | |
| 13 | + | |
| 14 | + protected Store(Dispatcher dispatcher) { | |
| 15 | + this.dispatcher = dispatcher; | |
| 16 | + } | |
| 17 | + | |
| 18 | + void emitStoreChange() { | |
| 19 | + dispatcher.emitChange(changeEvent()); | |
| 20 | + } | |
| 21 | + | |
| 22 | + abstract StoreChangeEvent changeEvent(); | |
| 23 | + public abstract void onAction(Action action); | |
| 24 | + | |
| 25 | + public interface StoreChangeEvent {} | |
| 26 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/stores/UserStore.java
0 → 100644
| ... | ... | @@ -0,0 +1,53 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.stores; | |
| 2 | + | |
| 3 | +import com.monitorabrasil.monitoralegislativo.actions.Action; | |
| 4 | +import com.monitorabrasil.monitoralegislativo.actions.UserActions; | |
| 5 | +import com.monitorabrasil.monitoralegislativo.dispatcher.Dispatcher; | |
| 6 | +import com.squareup.otto.Subscribe; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * Created by 89741803168 on 13/08/2015. | |
| 10 | + */ | |
| 11 | +public class UserStore extends Store{ | |
| 12 | + | |
| 13 | + private static UserStore instance; | |
| 14 | + private String status; | |
| 15 | + | |
| 16 | + protected UserStore(Dispatcher dispatcher) { | |
| 17 | + super(dispatcher); | |
| 18 | + } | |
| 19 | + | |
| 20 | + public static UserStore get(Dispatcher dispatcher) { | |
| 21 | + if (instance == null) { | |
| 22 | + instance = new UserStore(dispatcher); | |
| 23 | + } | |
| 24 | + return instance; | |
| 25 | + } | |
| 26 | + | |
| 27 | + | |
| 28 | + @Override | |
| 29 | + @Subscribe | |
| 30 | + public void onAction(Action action) { | |
| 31 | + status = "erro"; | |
| 32 | + switch (action.getType()) { | |
| 33 | + case UserActions.USER_LOGAR: | |
| 34 | + status = ((String) action.getData().get(UserActions.KEY_TEXT)); | |
| 35 | + emitStoreChange(); | |
| 36 | + break; | |
| 37 | + case UserActions.USER_LOGOUT: | |
| 38 | + emitStoreChange(); | |
| 39 | + break; | |
| 40 | + } | |
| 41 | + } | |
| 42 | + | |
| 43 | + @Override | |
| 44 | + StoreChangeEvent changeEvent() { | |
| 45 | + UserStoreChangeEvent mUserStoreChangeEvent = new UserStoreChangeEvent(); | |
| 46 | + mUserStoreChangeEvent.status = this.status; | |
| 47 | + return mUserStoreChangeEvent; | |
| 48 | + } | |
| 49 | + | |
| 50 | + public class UserStoreChangeEvent implements StoreChangeEvent { | |
| 51 | + String status; | |
| 52 | + } | |
| 53 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/util/MyValueFormatter.java
| ... | ... | @@ -1,24 +0,0 @@ |
| 1 | -package com.monitorabrasil.monitoralegislativo.util; | |
| 2 | - | |
| 3 | -import com.github.mikephil.charting.utils.ValueFormatter; | |
| 4 | - | |
| 5 | -import java.text.DecimalFormat; | |
| 6 | -import java.text.NumberFormat; | |
| 7 | - | |
| 8 | -/** | |
| 9 | - * Created by geral_000 on 21/06/2015. | |
| 10 | - */ | |
| 11 | -public class MyValueFormatter implements ValueFormatter { | |
| 12 | - | |
| 13 | - private DecimalFormat mFormat; | |
| 14 | - | |
| 15 | - public MyValueFormatter() { | |
| 16 | - mFormat = new DecimalFormat("###,###,###,##0.0"); | |
| 17 | - } | |
| 18 | - | |
| 19 | - @Override | |
| 20 | - public String getFormattedValue(float value) { | |
| 21 | - return "R$" + NumberFormat.getCurrencyInstance().format(value) ; | |
| 22 | - } | |
| 23 | - | |
| 24 | -} |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/CamaraActivity.java
0 → 100644
| ... | ... | @@ -0,0 +1,65 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view; | |
| 2 | + | |
| 3 | +import android.os.Bundle; | |
| 4 | +import android.support.v4.app.FragmentTransaction; | |
| 5 | +import android.support.v7.app.AppCompatActivity; | |
| 6 | +import android.support.v7.widget.Toolbar; | |
| 7 | +import android.view.Menu; | |
| 8 | +import android.view.MenuItem; | |
| 9 | + | |
| 10 | +import com.crashlytics.android.answers.Answers; | |
| 11 | +import com.crashlytics.android.answers.ContentViewEvent; | |
| 12 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 13 | +import com.monitorabrasil.monitoralegislativo.view.fragments.GastosCamaraFragment; | |
| 14 | + | |
| 15 | +public class CamaraActivity extends AppCompatActivity { | |
| 16 | + | |
| 17 | + @Override | |
| 18 | + protected void onCreate(Bundle savedInstanceState) { | |
| 19 | + super.onCreate(savedInstanceState); | |
| 20 | + setContentView(R.layout.activity_camara); | |
| 21 | + | |
| 22 | + Answers.getInstance().logContentView(new ContentViewEvent() | |
| 23 | + .putContentName("CamaraActivity") | |
| 24 | + .putContentType("Activity")); | |
| 25 | + | |
| 26 | + GastosCamaraFragment frag = (GastosCamaraFragment) getSupportFragmentManager().findFragmentByTag("gastosCamaraFrag"); | |
| 27 | + if(frag == null) { | |
| 28 | + frag = new GastosCamaraFragment(); | |
| 29 | + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); | |
| 30 | + ft.replace(R.id.rl_fragment_container, frag, "gastosCamaraFrag"); | |
| 31 | + ft.commit(); | |
| 32 | + } | |
| 33 | + | |
| 34 | + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
| 35 | + setSupportActionBar(toolbar); | |
| 36 | + // toolbar.setNavigationIcon(R.drawable.ic_good); | |
| 37 | + toolbar.setTitle("Despesas da Câmara"); | |
| 38 | + toolbar.setSubtitle("Ouro Branco - MG"); | |
| 39 | + | |
| 40 | + toolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 41 | + toolbar.setSubtitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 42 | + setSupportActionBar(toolbar); | |
| 43 | + getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 44 | + } | |
| 45 | + | |
| 46 | + @Override | |
| 47 | + public boolean onCreateOptionsMenu(Menu menu) { | |
| 48 | + // Inflate the menu; this adds items to the action bar if it is present. | |
| 49 | + getMenuInflater().inflate(R.menu.menu_camara, menu); | |
| 50 | + return true; | |
| 51 | + } | |
| 52 | + | |
| 53 | + @Override | |
| 54 | + public boolean onOptionsItemSelected(MenuItem item) { | |
| 55 | + // Handle action bar item clicks here. The action bar will | |
| 56 | + // automatically handle clicks on the Home/Up button, so long | |
| 57 | + // as you specify a parent activity in AndroidManifest.xml. | |
| 58 | + int id = item.getItemId(); | |
| 59 | + | |
| 60 | + //noinspection SimplifiableIfStatement | |
| 61 | + | |
| 62 | + | |
| 63 | + return super.onOptionsItemSelected(item); | |
| 64 | + } | |
| 65 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/ComentarioActivity.java
0 → 100644
| ... | ... | @@ -0,0 +1,230 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view; | |
| 2 | + | |
| 3 | +import android.os.Build; | |
| 4 | +import android.os.Bundle; | |
| 5 | +import android.support.design.widget.Snackbar; | |
| 6 | +import android.support.v7.app.AppCompatActivity; | |
| 7 | +import android.support.v7.widget.LinearLayoutManager; | |
| 8 | +import android.support.v7.widget.RecyclerView; | |
| 9 | +import android.support.v7.widget.Toolbar; | |
| 10 | +import android.transition.Transition; | |
| 11 | +import android.transition.TransitionInflater; | |
| 12 | +import android.util.Log; | |
| 13 | +import android.view.Menu; | |
| 14 | +import android.view.MenuItem; | |
| 15 | +import android.view.View; | |
| 16 | +import android.widget.Button; | |
| 17 | +import android.widget.EditText; | |
| 18 | +import android.widget.ProgressBar; | |
| 19 | + | |
| 20 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 21 | +import com.monitorabrasil.monitoralegislativo.view.adapters.ComentarioAdapter; | |
| 22 | +import com.parse.FindCallback; | |
| 23 | +import com.parse.GetCallback; | |
| 24 | +import com.parse.ParseException; | |
| 25 | +import com.parse.ParseObject; | |
| 26 | +import com.parse.ParseQuery; | |
| 27 | +import com.parse.ParseUser; | |
| 28 | +import com.parse.SaveCallback; | |
| 29 | + | |
| 30 | +import java.util.List; | |
| 31 | + | |
| 32 | +public class ComentarioActivity extends AppCompatActivity { | |
| 33 | + | |
| 34 | + private ParseObject projeto; | |
| 35 | + private ParseObject politico; | |
| 36 | + private Toolbar mToolbar; | |
| 37 | + private RecyclerView mRecyclerView; | |
| 38 | + private ComentarioAdapter mAdapter; | |
| 39 | + private List<ParseObject> ob; | |
| 40 | + private ProgressBar pb; | |
| 41 | + | |
| 42 | + @Override | |
| 43 | + protected void onCreate(Bundle savedInstanceState) { | |
| 44 | + super.onCreate(savedInstanceState); | |
| 45 | + setContentView(R.layout.activity_comentario); | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + // TOOLBAR | |
| 50 | + mToolbar = (Toolbar) findViewById(R.id.tb_main); | |
| 51 | + | |
| 52 | + //mToolbar.setSubtitle("just a subtitle"); | |
| 53 | + //mToolbar.setLogo(R.drawable.ic_launcher); | |
| 54 | + setSupportActionBar(mToolbar); | |
| 55 | + mToolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 56 | + | |
| 57 | + pb = (ProgressBar) findViewById(R.id.progressBar); | |
| 58 | + | |
| 59 | + | |
| 60 | + //tableview | |
| 61 | + mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view); | |
| 62 | + | |
| 63 | + | |
| 64 | + //verifica se eh comentario de projeto ou politico | |
| 65 | + if (getIntent().getStringExtra("projeto")!= null){ | |
| 66 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("Projeto"); | |
| 67 | + query.getInBackground(getIntent().getStringExtra("projeto"), new GetCallback<ParseObject>() { | |
| 68 | + public void done(ParseObject object, ParseException e) { | |
| 69 | + if (e == null) { | |
| 70 | + projeto = object; | |
| 71 | + mToolbar.setTitle(projeto.get("classificacao").toString()); | |
| 72 | + setTitle(projeto.get("classificacao").toString()); | |
| 73 | + buscaComentarios("Comentario"); | |
| 74 | + } else { | |
| 75 | + // something went wrong | |
| 76 | + } | |
| 77 | + } | |
| 78 | + }); | |
| 79 | + }else{ | |
| 80 | + //busca comentario de politico | |
| 81 | + buscaPolitico(getIntent().getStringExtra("politico")); | |
| 82 | + } | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ | |
| 88 | + //fazer a animacao | |
| 89 | + TransitionInflater inflater = TransitionInflater.from(this); | |
| 90 | + Transition transition = inflater.inflateTransition(R.transition.transitions); | |
| 91 | + | |
| 92 | + getWindow().setSharedElementEnterTransition(transition); | |
| 93 | + } | |
| 94 | + | |
| 95 | + //botao para enviar mensagem | |
| 96 | + Button btnEnviar = (Button)findViewById(R.id.btnEnviar); | |
| 97 | + btnEnviar.setOnClickListener(new View.OnClickListener() { | |
| 98 | + @Override | |
| 99 | + public void onClick(View v) { | |
| 100 | + enviarMensagem(v); | |
| 101 | + } | |
| 102 | + }); | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + // use this setting to improve performance if you know that changes | |
| 107 | + // in content do not change the layout size of the RecyclerView | |
| 108 | + mRecyclerView.setHasFixedSize(true); | |
| 109 | + | |
| 110 | + LinearLayoutManager llm = new LinearLayoutManager(this); | |
| 111 | + llm.setOrientation(LinearLayoutManager.VERTICAL); | |
| 112 | + llm.setReverseLayout(true); | |
| 113 | + mRecyclerView.setLayoutManager(llm); | |
| 114 | + | |
| 115 | + } | |
| 116 | + | |
| 117 | + private ParseObject buscaPolitico(String id) { | |
| 118 | + | |
| 119 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("Politico"); | |
| 120 | + query.fromLocalDatastore(); | |
| 121 | + try { | |
| 122 | + politico = query.get(id); | |
| 123 | + mToolbar.setTitle(politico.get("nome").toString()); | |
| 124 | + buscaComentarios("ComentarioPolitico"); | |
| 125 | + } catch (com.parse.ParseException e) { | |
| 126 | + e.printStackTrace(); | |
| 127 | + } | |
| 128 | + return null; | |
| 129 | + } | |
| 130 | + | |
| 131 | + public void buscaComentarios(String tipo){ | |
| 132 | + pb.setVisibility(View.VISIBLE); | |
| 133 | + ParseQuery<ParseObject> query = ParseQuery.getQuery(tipo); | |
| 134 | + if(tipo.equals("Comentario")){ | |
| 135 | + query.whereEqualTo("projeto",projeto); | |
| 136 | + }else{ | |
| 137 | + query.whereEqualTo("politico",politico); | |
| 138 | + } | |
| 139 | + | |
| 140 | + query.addAscendingOrder("createdAt"); | |
| 141 | + //query.whereEqualTo("playerName", "Dan Stemkoski"); | |
| 142 | + query.findInBackground(new FindCallback<ParseObject>() { | |
| 143 | + @Override | |
| 144 | + public void done(List<ParseObject> list, com.parse.ParseException e) { | |
| 145 | + if (e == null) { | |
| 146 | + ob = list; | |
| 147 | + carregaList(list); | |
| 148 | + } else { | |
| 149 | + Log.d("score", "Error: " + e.getMessage()); | |
| 150 | + } | |
| 151 | + } | |
| 152 | + | |
| 153 | + | |
| 154 | + }); | |
| 155 | + } | |
| 156 | + public void carregaList(List<ParseObject> list){ | |
| 157 | + mAdapter = new ComentarioAdapter(list); | |
| 158 | + // mAdapter.setRecyclerViewOnClickListenerHack(this); | |
| 159 | + mRecyclerView.setAdapter(mAdapter); | |
| 160 | + pb.setVisibility(View.INVISIBLE); | |
| 161 | + } | |
| 162 | + | |
| 163 | + | |
| 164 | + private void enviarMensagem(final View v) { | |
| 165 | + final EditText txtMensagem = (EditText)findViewById(R.id.mensagem); | |
| 166 | + String mensagem = txtMensagem.getText().toString(); | |
| 167 | + ParseUser user = ParseUser.getCurrentUser(); | |
| 168 | + final String tipo; | |
| 169 | + if(user!= null){ | |
| 170 | + ParseObject comentario; | |
| 171 | + if(politico != null){ | |
| 172 | + tipo = "ComentarioPolitico"; | |
| 173 | + comentario = new ParseObject("ComentarioPolitico"); | |
| 174 | + comentario.put("politico",politico); | |
| 175 | + }else{ | |
| 176 | + tipo ="Comentario"; | |
| 177 | + comentario = new ParseObject("Comentario"); | |
| 178 | + comentario.put("projeto",projeto); | |
| 179 | + } | |
| 180 | + comentario.put("mensagem",mensagem); | |
| 181 | + comentario.put("user", user); | |
| 182 | + comentario.put("nome", user.getString("nome")); | |
| 183 | + | |
| 184 | + comentario.saveInBackground(new SaveCallback() { | |
| 185 | + @Override | |
| 186 | + public void done(ParseException e) { | |
| 187 | + Snackbar.make(v, "Comentário enviado", Snackbar.LENGTH_LONG) | |
| 188 | + .setAction("Action", null).show(); | |
| 189 | + | |
| 190 | + //recarregar lista | |
| 191 | + buscaComentarios(tipo); | |
| 192 | + } | |
| 193 | + }); | |
| 194 | + if(politico != null){ | |
| 195 | + politico.increment("nr_comentarios"); | |
| 196 | + politico.saveInBackground(); | |
| 197 | + }else{ | |
| 198 | + projeto.increment("nr_comentarios"); | |
| 199 | + projeto.saveInBackground(); | |
| 200 | + } | |
| 201 | + | |
| 202 | + | |
| 203 | + }else{ | |
| 204 | + Snackbar.make(v, "Para comentar é necessário estar logado", Snackbar.LENGTH_LONG) | |
| 205 | + .setAction("Action", null).show(); | |
| 206 | + return; | |
| 207 | + } | |
| 208 | + | |
| 209 | + txtMensagem.setText(""); | |
| 210 | + } | |
| 211 | + | |
| 212 | + @Override | |
| 213 | + public boolean onCreateOptionsMenu(Menu menu) { | |
| 214 | + // Inflate the menu; this adds items to the action bar if it is present. | |
| 215 | + getMenuInflater().inflate(R.menu.menu_comentario, menu); | |
| 216 | + return true; | |
| 217 | + } | |
| 218 | + | |
| 219 | + @Override | |
| 220 | + public boolean onOptionsItemSelected(MenuItem item) { | |
| 221 | + // Handle action bar item clicks here. The action bar will | |
| 222 | + // automatically handle clicks on the Home/Up button, so long | |
| 223 | + // as you specify a parent activity in AndroidManifest.xml. | |
| 224 | + int id = item.getItemId(); | |
| 225 | + | |
| 226 | + //noinspection SimplifiableIfStatement | |
| 227 | + | |
| 228 | + return super.onOptionsItemSelected(item); | |
| 229 | + } | |
| 230 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/Login2Activity.java
0 → 100644
| ... | ... | @@ -0,0 +1,509 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.content.Intent; | |
| 5 | +import android.graphics.Bitmap; | |
| 6 | +import android.graphics.BitmapFactory; | |
| 7 | +import android.net.Uri; | |
| 8 | +import android.os.Bundle; | |
| 9 | +import android.support.design.widget.Snackbar; | |
| 10 | +import android.support.v7.app.AppCompatActivity; | |
| 11 | +import android.support.v7.widget.Toolbar; | |
| 12 | +import android.text.TextUtils; | |
| 13 | +import android.view.KeyEvent; | |
| 14 | +import android.view.View; | |
| 15 | +import android.view.View.OnClickListener; | |
| 16 | +import android.view.inputmethod.EditorInfo; | |
| 17 | +import android.widget.ArrayAdapter; | |
| 18 | +import android.widget.AutoCompleteTextView; | |
| 19 | +import android.widget.Button; | |
| 20 | +import android.widget.EditText; | |
| 21 | +import android.widget.ImageButton; | |
| 22 | +import android.widget.ImageView; | |
| 23 | +import android.widget.TextView; | |
| 24 | + | |
| 25 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 26 | +import com.monitorabrasil.monitoralegislativo.actions.ActionsCreator; | |
| 27 | +import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 28 | +import com.monitorabrasil.monitoralegislativo.dispatcher.Dispatcher; | |
| 29 | +import com.monitorabrasil.monitoralegislativo.stores.UserStore; | |
| 30 | +import com.nostra13.universalimageloader.core.assist.FailReason; | |
| 31 | +import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; | |
| 32 | +import com.parse.LogInCallback; | |
| 33 | +import com.parse.LogOutCallback; | |
| 34 | +import com.parse.ParseTwitterUtils; | |
| 35 | +import com.parse.ParseUser; | |
| 36 | +import com.parse.SignUpCallback; | |
| 37 | +import com.squareup.otto.Bus; | |
| 38 | +import com.squareup.otto.Subscribe; | |
| 39 | + | |
| 40 | +import java.io.FileNotFoundException; | |
| 41 | +import java.io.InputStream; | |
| 42 | +import java.util.List; | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | +/** | |
| 47 | + * A login screen that offers login via email/password. | |
| 48 | + */ | |
| 49 | +public class Login2Activity extends AppCompatActivity { | |
| 50 | + | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Keep track of the login task to ensure we can cancel it if requested. | |
| 54 | + */ | |
| 55 | + | |
| 56 | + | |
| 57 | + // UI references. | |
| 58 | + private AutoCompleteTextView mEmailView; | |
| 59 | + private EditText mPasswordView; | |
| 60 | + private EditText mNome; | |
| 61 | + private View mProgressView; | |
| 62 | + private View mLoginFormView; | |
| 63 | + private View mLogoutFormView; | |
| 64 | + private Button btnFazerCadastro; | |
| 65 | + private Button btnLogar; | |
| 66 | + private Button btnLogout; | |
| 67 | + private Button btnLoginTwitter; | |
| 68 | + private TextView lblNome; | |
| 69 | + private TextView lblEmail; | |
| 70 | + private ImageView foto; | |
| 71 | + private ParseUser currentUser; | |
| 72 | + private ImageButton btnFoto; | |
| 73 | + | |
| 74 | + private Dispatcher dispatcher; | |
| 75 | + private ActionsCreator actionsCreator; | |
| 76 | + private UserStore userStore; | |
| 77 | + | |
| 78 | + | |
| 79 | + private final int PICK_IMAGE=2; | |
| 80 | + | |
| 81 | + @Override | |
| 82 | + protected void onCreate(Bundle savedInstanceState) { | |
| 83 | + super.onCreate(savedInstanceState); | |
| 84 | + setContentView(R.layout.activity_login); | |
| 85 | + initDependencies(); | |
| 86 | + setupView(); | |
| 87 | + } | |
| 88 | + | |
| 89 | + private void initDependencies() { | |
| 90 | + dispatcher = Dispatcher.get(new Bus()); | |
| 91 | + actionsCreator = ActionsCreator.get(dispatcher); | |
| 92 | + userStore = UserStore.get(dispatcher); | |
| 93 | + } | |
| 94 | + | |
| 95 | + private void setupView() { | |
| 96 | + setupActionBar(); | |
| 97 | + mLoginFormView = findViewById(R.id.login_form); | |
| 98 | + mLogoutFormView = findViewById(R.id.logout_form); | |
| 99 | + mProgressView = findViewById(R.id.login_progress); | |
| 100 | + | |
| 101 | + btnFoto = (ImageButton) findViewById(R.id.btnFoto); | |
| 102 | + btnLogar = (Button) findViewById(R.id.email_sign_in_button); | |
| 103 | + btnLogout = (Button) findViewById(R.id.btnLogout); | |
| 104 | + | |
| 105 | + currentUser = ParseUser.getCurrentUser(); | |
| 106 | + | |
| 107 | + if (currentUser != null) { | |
| 108 | + montaFormLogout(); | |
| 109 | + | |
| 110 | + } else { | |
| 111 | + montaFormLogin(); | |
| 112 | + | |
| 113 | + } | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + btnLogar.setOnClickListener(new OnClickListener() { | |
| 118 | + @Override | |
| 119 | + public void onClick(View view) { | |
| 120 | + showProgress(true, null); | |
| 121 | + logar(); | |
| 122 | + } | |
| 123 | + }); | |
| 124 | + | |
| 125 | + btnLogout.setOnClickListener(new OnClickListener() { | |
| 126 | + | |
| 127 | + @Override | |
| 128 | + public void onClick(View v) { | |
| 129 | + showProgress(true, null); | |
| 130 | + logout(); | |
| 131 | + | |
| 132 | + | |
| 133 | + } | |
| 134 | + }); | |
| 135 | + | |
| 136 | + btnFoto.setOnClickListener(new OnClickListener() { | |
| 137 | + @Override | |
| 138 | + public void onClick(View v) { | |
| 139 | + Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT); | |
| 140 | + getIntent.setType("image/*"); | |
| 141 | + | |
| 142 | + Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); | |
| 143 | + pickIntent.setType("image/*"); | |
| 144 | + | |
| 145 | + Intent chooserIntent = Intent.createChooser(getIntent, "Selecione uma foto"); | |
| 146 | + chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent}); | |
| 147 | + | |
| 148 | + startActivityForResult(chooserIntent, PICK_IMAGE); | |
| 149 | + } | |
| 150 | + }); | |
| 151 | + | |
| 152 | + mNome = (EditText) findViewById(R.id.txtNome); | |
| 153 | + mNome.setVisibility(View.GONE); | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + btnFazerCadastro = (Button) findViewById(R.id.fazer_cadastro); | |
| 160 | + btnFazerCadastro.setOnClickListener(new OnClickListener() { | |
| 161 | + @Override | |
| 162 | + public void onClick(View v) { | |
| 163 | + if (btnFazerCadastro.getText().toString().equals("Fazer Cadastro")) { | |
| 164 | + mNome.setVisibility(View.VISIBLE); | |
| 165 | + btnLogar.setVisibility(View.GONE); | |
| 166 | + btnLoginTwitter.setVisibility(View.GONE); | |
| 167 | + btnFazerCadastro.setText("Cadastrar"); | |
| 168 | + View view = mNome; | |
| 169 | + view.requestFocus(); | |
| 170 | + } else { | |
| 171 | + realizarCadastro(); | |
| 172 | + } | |
| 173 | + | |
| 174 | + } | |
| 175 | + }); | |
| 176 | + | |
| 177 | + btnLoginTwitter = (Button) findViewById(R.id.login_twitter); | |
| 178 | + btnLoginTwitter.setOnClickListener(new OnClickListener() { | |
| 179 | + @Override | |
| 180 | + public void onClick(View v) { | |
| 181 | + ParseTwitterUtils.logIn(v.getContext(), new LogInCallback() { | |
| 182 | + @Override | |
| 183 | + public void done(ParseUser parseUser, com.parse.ParseException e) { | |
| 184 | + if (parseUser == null) { | |
| 185 | + Snackbar.make(mLoginFormView, "Login cancelado ", Snackbar.LENGTH_LONG) | |
| 186 | + .setAction("Action", null).show(); | |
| 187 | + } else if (parseUser.isNew()) { | |
| 188 | + parseUser.put("nome", ParseTwitterUtils.getTwitter().getScreenName()); | |
| 189 | + parseUser.saveInBackground(); | |
| 190 | + montaFormLogout(); | |
| 191 | + } else { | |
| 192 | + montaFormLogout(); | |
| 193 | + } | |
| 194 | + } | |
| 195 | + }); | |
| 196 | + } | |
| 197 | + }); | |
| 198 | + | |
| 199 | + mEmailView = (AutoCompleteTextView) findViewById(R.id.email); | |
| 200 | + | |
| 201 | + | |
| 202 | + mPasswordView = (EditText) findViewById(R.id.password); | |
| 203 | + mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() { | |
| 204 | + @Override | |
| 205 | + public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { | |
| 206 | + if (id == R.id.login || id == EditorInfo.IME_NULL) { | |
| 207 | + attemptLogin(); | |
| 208 | + return true; | |
| 209 | + } | |
| 210 | + return false; | |
| 211 | + } | |
| 212 | + }); | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + } | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + private void verificaLogin() { | |
| 221 | + if(ParseUser.getCurrentUser()!=null){ | |
| 222 | + montaFormLogout(); | |
| 223 | + }else{ | |
| 224 | + montaFormLogin(); | |
| 225 | + } | |
| 226 | + } | |
| 227 | + | |
| 228 | + private void logout() { | |
| 229 | + | |
| 230 | + actionsCreator.logout(); | |
| 231 | + } | |
| 232 | + | |
| 233 | + private void montaFormLogin() { | |
| 234 | + mLogoutFormView.setVisibility(View.GONE); | |
| 235 | + mLoginFormView.setVisibility(View.VISIBLE); | |
| 236 | + } | |
| 237 | + | |
| 238 | + private void logar() { | |
| 239 | + if(validaCampos()){ | |
| 240 | + actionsCreator.logar(getInputUsuario(), getInputSenha()); | |
| 241 | + } | |
| 242 | + } | |
| 243 | + | |
| 244 | + private String getInputUsuario() { | |
| 245 | + return mEmailView.getText().toString(); | |
| 246 | + } | |
| 247 | + | |
| 248 | + private String getInputSenha() { | |
| 249 | + return mPasswordView.getText().toString(); | |
| 250 | + } | |
| 251 | + | |
| 252 | + private boolean validaCampos() { | |
| 253 | + return true; | |
| 254 | + } | |
| 255 | + | |
| 256 | + @Subscribe | |
| 257 | + public void onTodoStoreChange(UserStore.UserStoreChangeEvent event) { | |
| 258 | + updateUI(); | |
| 259 | + } | |
| 260 | + | |
| 261 | + @Override | |
| 262 | + protected void onResume() { | |
| 263 | + super.onResume(); | |
| 264 | + dispatcher.register(this); | |
| 265 | + dispatcher.register(userStore); | |
| 266 | + } | |
| 267 | + | |
| 268 | + @Override | |
| 269 | + protected void onPause() { | |
| 270 | + super.onPause(); | |
| 271 | + dispatcher.unregister(this); | |
| 272 | + dispatcher.unregister(userStore); | |
| 273 | + } | |
| 274 | + | |
| 275 | + | |
| 276 | + @Override | |
| 277 | + public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
| 278 | + super.onActivityResult(requestCode, resultCode, data); | |
| 279 | + if (requestCode == PICK_IMAGE && resultCode == Activity.RESULT_OK) { | |
| 280 | + if (data == null) { | |
| 281 | + //Display an error | |
| 282 | + return; | |
| 283 | + } | |
| 284 | + try { | |
| 285 | + Uri selectedImage = data.getData(); | |
| 286 | + InputStream imageStream = getContentResolver().openInputStream(selectedImage); | |
| 287 | + Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream); | |
| 288 | + btnFoto.setImageBitmap(yourSelectedImage); | |
| 289 | + } catch (FileNotFoundException e) { | |
| 290 | + e.printStackTrace(); | |
| 291 | + } | |
| 292 | + //Now you can do whatever you want with your inpustream, save it as file, upload to a server, decode a bitmap... | |
| 293 | + } | |
| 294 | + } | |
| 295 | + | |
| 296 | + private void showProgress(boolean b,View v) { | |
| 297 | + if(b){ | |
| 298 | + mProgressView.setVisibility(View.VISIBLE); | |
| 299 | + mLogoutFormView.setVisibility(View.GONE); | |
| 300 | + mLoginFormView.setVisibility(View.GONE); | |
| 301 | + }else{ | |
| 302 | + mProgressView.setVisibility(View.GONE); | |
| 303 | + v.setVisibility(View.VISIBLE); | |
| 304 | + } | |
| 305 | + } | |
| 306 | + | |
| 307 | + private void montaFormLogout() { | |
| 308 | + lblNome = (TextView)findViewById(R.id.lblNome); | |
| 309 | + lblEmail = (TextView)findViewById(R.id.lblEmail); | |
| 310 | + foto = (ImageView)findViewById(R.id.foto); | |
| 311 | + | |
| 312 | + mLoginFormView.setVisibility(View.GONE); | |
| 313 | + showProgress(false,mLogoutFormView); | |
| 314 | + | |
| 315 | + | |
| 316 | + } | |
| 317 | + | |
| 318 | + | |
| 319 | + private void realizarCadastro() { | |
| 320 | + | |
| 321 | + // Reset errors. | |
| 322 | + mEmailView.setError(null); | |
| 323 | + mPasswordView.setError(null); | |
| 324 | + mNome.setError(null); | |
| 325 | + | |
| 326 | + // Store values at the time of the login attempt. | |
| 327 | + String email = mEmailView.getText().toString(); | |
| 328 | + String password = mPasswordView.getText().toString(); | |
| 329 | + String nome =mNome.getText().toString(); | |
| 330 | + | |
| 331 | + boolean cancel = false; | |
| 332 | + View focusView = null; | |
| 333 | + | |
| 334 | + if (TextUtils.isEmpty(nome)) { | |
| 335 | + mNome.setError(getString(R.string.error_field_required)); | |
| 336 | + focusView = mNome; | |
| 337 | + cancel = true; | |
| 338 | + } | |
| 339 | + | |
| 340 | + // Check for a valid password, if the user entered one. | |
| 341 | + if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) { | |
| 342 | + mPasswordView.setError(getString(R.string.error_invalid_password)); | |
| 343 | + focusView = mPasswordView; | |
| 344 | + cancel = true; | |
| 345 | + } | |
| 346 | + | |
| 347 | + // Check for a valid email address. | |
| 348 | + if (TextUtils.isEmpty(email)) { | |
| 349 | + mEmailView.setError(getString(R.string.error_field_required)); | |
| 350 | + focusView = mEmailView; | |
| 351 | + cancel = true; | |
| 352 | + } else if (!isEmailValid(email)) { | |
| 353 | + mEmailView.setError(getString(R.string.error_invalid_email)); | |
| 354 | + focusView = mEmailView; | |
| 355 | + cancel = true; | |
| 356 | + } | |
| 357 | + | |
| 358 | + if (cancel) { | |
| 359 | + // There was an error; don't attempt login and focus the first | |
| 360 | + // form field with an error. | |
| 361 | + focusView.requestFocus(); | |
| 362 | + } else { | |
| 363 | + // Show a progress spinner, and kick off a background task to | |
| 364 | + // perform the user login attempt. | |
| 365 | + showProgress(true,null); | |
| 366 | + | |
| 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 | + | |
| 386 | + | |
| 387 | + }); | |
| 388 | + | |
| 389 | + } | |
| 390 | + } | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + /** | |
| 395 | + * Set up the {@link android.app.ActionBar}, if the API is available. | |
| 396 | + */ | |
| 397 | +// @TargetApi(Build.VERSION_CODES.HONEYCOMB) | |
| 398 | + private void setupActionBar() { | |
| 399 | + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
| 400 | + | |
| 401 | + // toolbar.setNavigationIcon(R.drawable.ic_good); | |
| 402 | + toolbar.setTitle("Login"); | |
| 403 | + | |
| 404 | + toolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 405 | + toolbar.setSubtitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 406 | + setSupportActionBar(toolbar); | |
| 407 | + getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 408 | + } | |
| 409 | + | |
| 410 | + /** | |
| 411 | + * Attempts to sign in or register the account specified by the login form. | |
| 412 | + * If there are form errors (invalid email, missing fields, etc.), the | |
| 413 | + * errors are presented and no actual login attempt is made. | |
| 414 | + */ | |
| 415 | + public void attemptLogin() { | |
| 416 | + | |
| 417 | + | |
| 418 | + // Reset errors. | |
| 419 | + mEmailView.setError(null); | |
| 420 | + mPasswordView.setError(null); | |
| 421 | + | |
| 422 | + // Store values at the time of the login attempt. | |
| 423 | + String email = mEmailView.getText().toString(); | |
| 424 | + String password = mPasswordView.getText().toString(); | |
| 425 | + | |
| 426 | + boolean cancel = false; | |
| 427 | + View focusView = null; | |
| 428 | + | |
| 429 | + // Check for a valid password, if the user entered one. | |
| 430 | + if (TextUtils.isEmpty(password) && !isPasswordValid(password)) { | |
| 431 | + mPasswordView.setError(getString(R.string.error_invalid_password)); | |
| 432 | + focusView = mPasswordView; | |
| 433 | + cancel = true; | |
| 434 | + } | |
| 435 | + | |
| 436 | + // Check for a valid email address. | |
| 437 | + if (TextUtils.isEmpty(email)) { | |
| 438 | + mEmailView.setError(getString(R.string.error_field_required)); | |
| 439 | + focusView = mEmailView; | |
| 440 | + cancel = true; | |
| 441 | + } else if (!isEmailValid(email)) { | |
| 442 | + mEmailView.setError(getString(R.string.error_invalid_email)); | |
| 443 | + focusView = mEmailView; | |
| 444 | + cancel = true; | |
| 445 | + } | |
| 446 | + | |
| 447 | + if (cancel) { | |
| 448 | + // There was an error; don't attempt login and focus the first | |
| 449 | + // form field with an error. | |
| 450 | + focusView.requestFocus(); | |
| 451 | + } else { | |
| 452 | + // Show a progress spinner, and kick off a background task to | |
| 453 | + // perform the user login attempt. | |
| 454 | + showProgress(true,null); | |
| 455 | + | |
| 456 | + //fazer o login aqui | |
| 457 | + fazerLogin(email, password); | |
| 458 | + | |
| 459 | + } | |
| 460 | + } | |
| 461 | + | |
| 462 | + private void fazerLogin(String email, String password) { | |
| 463 | + ParseUser.logInInBackground(email, password, new LogInCallback() { | |
| 464 | + | |
| 465 | + @Override | |
| 466 | + public void done(ParseUser parseUser, com.parse.ParseException e) { | |
| 467 | + if (parseUser != null) { | |
| 468 | + finish(); | |
| 469 | + } else { | |
| 470 | + mPasswordView.setError(getString(R.string.error_incorrect_password)); | |
| 471 | + mPasswordView.requestFocus(); | |
| 472 | + showProgress(false,mLoginFormView); | |
| 473 | + } | |
| 474 | + } | |
| 475 | + | |
| 476 | + | |
| 477 | + }); | |
| 478 | + } | |
| 479 | + | |
| 480 | + private boolean isEmailValid(String email) { | |
| 481 | + //TODO: Replace this with your own logic | |
| 482 | + return email.contains("@"); | |
| 483 | + } | |
| 484 | + | |
| 485 | + private boolean isPasswordValid(String password) { | |
| 486 | + //TODO: Replace this with your own logic | |
| 487 | + return password.length() > 4; | |
| 488 | + } | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + private void updateUI() { | |
| 493 | + showProgress(false, mLoginFormView); | |
| 494 | + verificaLogin(); | |
| 495 | + } | |
| 496 | + | |
| 497 | + | |
| 498 | + private void addEmailsToAutoComplete(List<String> emailAddressCollection) { | |
| 499 | + //Create adapter to tell the AutoCompleteTextView what to show in its dropdown list. | |
| 500 | + ArrayAdapter<String> adapter = | |
| 501 | + new ArrayAdapter<String>(Login2Activity.this, | |
| 502 | + android.R.layout.simple_dropdown_item_1line, emailAddressCollection); | |
| 503 | + | |
| 504 | + mEmailView.setAdapter(adapter); | |
| 505 | + } | |
| 506 | + | |
| 507 | + | |
| 508 | +} | |
| 509 | + | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/LoginActivity.java
0 → 100644
| ... | ... | @@ -0,0 +1,457 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.content.Intent; | |
| 5 | +import android.graphics.Bitmap; | |
| 6 | +import android.graphics.BitmapFactory; | |
| 7 | +import android.net.Uri; | |
| 8 | +import android.os.Bundle; | |
| 9 | +import android.support.design.widget.Snackbar; | |
| 10 | +import android.support.v7.app.AppCompatActivity; | |
| 11 | +import android.support.v7.widget.Toolbar; | |
| 12 | +import android.text.TextUtils; | |
| 13 | +import android.view.KeyEvent; | |
| 14 | +import android.view.View; | |
| 15 | +import android.view.View.OnClickListener; | |
| 16 | +import android.view.inputmethod.EditorInfo; | |
| 17 | +import android.widget.ArrayAdapter; | |
| 18 | +import android.widget.AutoCompleteTextView; | |
| 19 | +import android.widget.Button; | |
| 20 | +import android.widget.EditText; | |
| 21 | +import android.widget.ImageButton; | |
| 22 | +import android.widget.ImageView; | |
| 23 | +import android.widget.TextView; | |
| 24 | + | |
| 25 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 26 | +import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 27 | +import com.nostra13.universalimageloader.core.assist.FailReason; | |
| 28 | +import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; | |
| 29 | +import com.parse.LogInCallback; | |
| 30 | +import com.parse.LogOutCallback; | |
| 31 | +import com.parse.ParseTwitterUtils; | |
| 32 | +import com.parse.ParseUser; | |
| 33 | +import com.parse.SignUpCallback; | |
| 34 | + | |
| 35 | +import java.io.FileNotFoundException; | |
| 36 | +import java.io.InputStream; | |
| 37 | +import java.util.List; | |
| 38 | + | |
| 39 | +/** | |
| 40 | + * A login screen that offers login via email/password. | |
| 41 | + */ | |
| 42 | +public class LoginActivity extends AppCompatActivity { | |
| 43 | + | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * Keep track of the login task to ensure we can cancel it if requested. | |
| 47 | + */ | |
| 48 | + | |
| 49 | + | |
| 50 | + // UI references. | |
| 51 | + private AutoCompleteTextView mEmailView; | |
| 52 | + private EditText mPasswordView; | |
| 53 | + private EditText mNome; | |
| 54 | + private View mProgressView; | |
| 55 | + private View mLoginFormView; | |
| 56 | + private View mLogoutFormView; | |
| 57 | + private Button btnFazerCadastro; | |
| 58 | + private Button btnLogar; | |
| 59 | + private Button btnLogout; | |
| 60 | + private Button btnLoginTwitter; | |
| 61 | + private TextView lblNome; | |
| 62 | + private TextView lblEmail; | |
| 63 | + private ImageView foto; | |
| 64 | + private ParseUser currentUser; | |
| 65 | + private ImageButton btnFoto; | |
| 66 | + | |
| 67 | + private final int PICK_IMAGE=2; | |
| 68 | + | |
| 69 | + @Override | |
| 70 | + protected void onCreate(Bundle savedInstanceState) { | |
| 71 | + super.onCreate(savedInstanceState); | |
| 72 | + setContentView(R.layout.activity_login); | |
| 73 | + setupActionBar(); | |
| 74 | + mLoginFormView = findViewById(R.id.login_form); | |
| 75 | + mLogoutFormView = findViewById(R.id.logout_form); | |
| 76 | + mProgressView = findViewById(R.id.login_progress); | |
| 77 | + btnFoto = (ImageButton) findViewById(R.id.btnFoto); | |
| 78 | + currentUser = ParseUser.getCurrentUser(); | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + if (currentUser != null) { | |
| 84 | + montaFormLogout(); | |
| 85 | + | |
| 86 | + }else{ | |
| 87 | + mLogoutFormView.setVisibility(View.GONE); | |
| 88 | + mLoginFormView.setVisibility(View.VISIBLE); | |
| 89 | + | |
| 90 | + } | |
| 91 | + | |
| 92 | + // Set up the login form. | |
| 93 | + btnFoto.setOnClickListener(new OnClickListener() { | |
| 94 | + @Override | |
| 95 | + public void onClick(View v) { | |
| 96 | + Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT); | |
| 97 | + getIntent.setType("image/*"); | |
| 98 | + | |
| 99 | + Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); | |
| 100 | + pickIntent.setType("image/*"); | |
| 101 | + | |
| 102 | + Intent chooserIntent = Intent.createChooser(getIntent, "Selecione uma foto"); | |
| 103 | + chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent}); | |
| 104 | + | |
| 105 | + startActivityForResult(chooserIntent, PICK_IMAGE); | |
| 106 | + } | |
| 107 | + }); | |
| 108 | + | |
| 109 | + mNome = (EditText)findViewById(R.id.txtNome); | |
| 110 | + mNome.setVisibility(View.GONE); | |
| 111 | + | |
| 112 | + btnLogar = (Button)findViewById(R.id.email_sign_in_button); | |
| 113 | + btnLogout = (Button)findViewById(R.id.btnLogout); | |
| 114 | + | |
| 115 | + btnLogout.setOnClickListener(new OnClickListener() { | |
| 116 | + | |
| 117 | + @Override | |
| 118 | + public void onClick(View v) { | |
| 119 | + showProgress(true,null); | |
| 120 | + ParseUser.logOutInBackground(new LogOutCallback() { | |
| 121 | + @Override | |
| 122 | + public void done(com.parse.ParseException e) { | |
| 123 | + showProgress(false, mLoginFormView); | |
| 124 | + } | |
| 125 | + }); | |
| 126 | + } | |
| 127 | + }); | |
| 128 | + | |
| 129 | + btnFazerCadastro = (Button)findViewById(R.id.fazer_cadastro); | |
| 130 | + btnFazerCadastro.setOnClickListener(new OnClickListener() { | |
| 131 | + @Override | |
| 132 | + public void onClick(View v) { | |
| 133 | + if(btnFazerCadastro.getText().toString().equals("Fazer Cadastro")){ | |
| 134 | + mNome.setVisibility(View.VISIBLE); | |
| 135 | + btnLogar.setVisibility(View.GONE); | |
| 136 | + btnLoginTwitter.setVisibility(View.GONE); | |
| 137 | + btnFazerCadastro.setText("Cadastrar"); | |
| 138 | + View view = mNome; | |
| 139 | + view.requestFocus(); | |
| 140 | + }else{ | |
| 141 | + realizarCadastro(); | |
| 142 | + } | |
| 143 | + | |
| 144 | + } | |
| 145 | + }); | |
| 146 | + | |
| 147 | + btnLoginTwitter = (Button)findViewById(R.id.login_twitter); | |
| 148 | + btnLoginTwitter.setOnClickListener(new OnClickListener() { | |
| 149 | + @Override | |
| 150 | + public void onClick(View v) { | |
| 151 | + ParseTwitterUtils.logIn(v.getContext(), new LogInCallback() { | |
| 152 | + @Override | |
| 153 | + public void done(ParseUser parseUser, com.parse.ParseException e) { | |
| 154 | + if (parseUser == null) { | |
| 155 | + Snackbar.make(mLoginFormView, "Login cancelado ", Snackbar.LENGTH_LONG) | |
| 156 | + .setAction("Action", null).show(); | |
| 157 | + } else if (parseUser.isNew()) { | |
| 158 | + parseUser.put("nome",ParseTwitterUtils.getTwitter().getScreenName()); | |
| 159 | + parseUser.saveInBackground(); | |
| 160 | + montaFormLogout(); | |
| 161 | + } else { | |
| 162 | + montaFormLogout(); | |
| 163 | + } | |
| 164 | + } | |
| 165 | + }); | |
| 166 | + } | |
| 167 | + }); | |
| 168 | + | |
| 169 | + mEmailView = (AutoCompleteTextView) findViewById(R.id.email); | |
| 170 | + | |
| 171 | + | |
| 172 | + mPasswordView = (EditText) findViewById(R.id.password); | |
| 173 | + mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() { | |
| 174 | + @Override | |
| 175 | + public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { | |
| 176 | + if (id == R.id.login || id == EditorInfo.IME_NULL) { | |
| 177 | + attemptLogin(); | |
| 178 | + return true; | |
| 179 | + } | |
| 180 | + return false; | |
| 181 | + } | |
| 182 | + }); | |
| 183 | + | |
| 184 | + Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button); | |
| 185 | + mEmailSignInButton.setOnClickListener(new OnClickListener() { | |
| 186 | + @Override | |
| 187 | + public void onClick(View view) { | |
| 188 | + attemptLogin(); | |
| 189 | + } | |
| 190 | + }); | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + } | |
| 195 | + | |
| 196 | + @Override | |
| 197 | + public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
| 198 | + super.onActivityResult(requestCode, resultCode, data); | |
| 199 | + if (requestCode == PICK_IMAGE && resultCode == Activity.RESULT_OK) { | |
| 200 | + if (data == null) { | |
| 201 | + //Display an error | |
| 202 | + return; | |
| 203 | + } | |
| 204 | + try { | |
| 205 | + Uri selectedImage = data.getData(); | |
| 206 | + InputStream imageStream = getContentResolver().openInputStream(selectedImage); | |
| 207 | + Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream); | |
| 208 | + btnFoto.setImageBitmap(yourSelectedImage); | |
| 209 | + } catch (FileNotFoundException e) { | |
| 210 | + e.printStackTrace(); | |
| 211 | + } | |
| 212 | + //Now you can do whatever you want with your inpustream, save it as file, upload to a server, decode a bitmap... | |
| 213 | + } | |
| 214 | + } | |
| 215 | + | |
| 216 | + private void showProgress(boolean b,View v) { | |
| 217 | + if(b){ | |
| 218 | + mProgressView.setVisibility(View.VISIBLE); | |
| 219 | + mLogoutFormView.setVisibility(View.GONE); | |
| 220 | + mLoginFormView.setVisibility(View.GONE); | |
| 221 | + }else{ | |
| 222 | + mProgressView.setVisibility(View.GONE); | |
| 223 | + v.setVisibility(View.VISIBLE); | |
| 224 | + } | |
| 225 | + } | |
| 226 | + | |
| 227 | + private void montaFormLogout() { | |
| 228 | + lblNome = (TextView)findViewById(R.id.lblNome); | |
| 229 | + lblEmail = (TextView)findViewById(R.id.lblEmail); | |
| 230 | + foto = (ImageView)findViewById(R.id.foto); | |
| 231 | + | |
| 232 | + mLoginFormView.setVisibility(View.GONE); | |
| 233 | + showProgress(false,mLogoutFormView); | |
| 234 | + | |
| 235 | + if(ParseTwitterUtils.getTwitter().getUserId() !=null){ | |
| 236 | + String screenName = ParseTwitterUtils.getTwitter().getScreenName(); | |
| 237 | + lblNome.setText(screenName); | |
| 238 | + lblEmail.setText(""); | |
| 239 | + MyApp.getInstance().getmImagemLoader().loadImage("https://twitter.com/" + screenName + "/profile_image?size=bigger", new ImageLoadingListener() { | |
| 240 | + | |
| 241 | + | |
| 242 | + @Override | |
| 243 | + public void onLoadingStarted(String imageUri, View view) { | |
| 244 | + | |
| 245 | + } | |
| 246 | + | |
| 247 | + @Override | |
| 248 | + public void onLoadingFailed(String imageUri, View view, FailReason failReason) { | |
| 249 | + | |
| 250 | + } | |
| 251 | + | |
| 252 | + @Override | |
| 253 | + public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { | |
| 254 | + foto.setImageBitmap(loadedImage); | |
| 255 | + } | |
| 256 | + | |
| 257 | + @Override | |
| 258 | + public void onLoadingCancelled(String imageUri, View view) { | |
| 259 | + | |
| 260 | + } | |
| 261 | + | |
| 262 | + | |
| 263 | + }); | |
| 264 | + }else{ | |
| 265 | + lblNome.setText(currentUser.get("nome").toString()); | |
| 266 | + lblEmail.setText(currentUser.getEmail()); | |
| 267 | + } | |
| 268 | + } | |
| 269 | + | |
| 270 | + | |
| 271 | + private void realizarCadastro() { | |
| 272 | + | |
| 273 | + // Reset errors. | |
| 274 | + mEmailView.setError(null); | |
| 275 | + mPasswordView.setError(null); | |
| 276 | + mNome.setError(null); | |
| 277 | + | |
| 278 | + // Store values at the time of the login attempt. | |
| 279 | + String email = mEmailView.getText().toString(); | |
| 280 | + String password = mPasswordView.getText().toString(); | |
| 281 | + String nome =mNome.getText().toString(); | |
| 282 | + | |
| 283 | + boolean cancel = false; | |
| 284 | + View focusView = null; | |
| 285 | + | |
| 286 | + if (TextUtils.isEmpty(nome)) { | |
| 287 | + mNome.setError(getString(R.string.error_field_required)); | |
| 288 | + focusView = mNome; | |
| 289 | + cancel = true; | |
| 290 | + } | |
| 291 | + | |
| 292 | + // Check for a valid password, if the user entered one. | |
| 293 | + if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) { | |
| 294 | + mPasswordView.setError(getString(R.string.error_invalid_password)); | |
| 295 | + focusView = mPasswordView; | |
| 296 | + cancel = true; | |
| 297 | + } | |
| 298 | + | |
| 299 | + // Check for a valid email address. | |
| 300 | + if (TextUtils.isEmpty(email)) { | |
| 301 | + mEmailView.setError(getString(R.string.error_field_required)); | |
| 302 | + focusView = mEmailView; | |
| 303 | + cancel = true; | |
| 304 | + } else if (!isEmailValid(email)) { | |
| 305 | + mEmailView.setError(getString(R.string.error_invalid_email)); | |
| 306 | + focusView = mEmailView; | |
| 307 | + cancel = true; | |
| 308 | + } | |
| 309 | + | |
| 310 | + if (cancel) { | |
| 311 | + // There was an error; don't attempt login and focus the first | |
| 312 | + // form field with an error. | |
| 313 | + focusView.requestFocus(); | |
| 314 | + } else { | |
| 315 | + // Show a progress spinner, and kick off a background task to | |
| 316 | + // perform the user login attempt. | |
| 317 | + showProgress(true,null); | |
| 318 | + | |
| 319 | + ParseUser user = new ParseUser(); | |
| 320 | + user.setUsername(email); | |
| 321 | + user.setPassword(password); | |
| 322 | + user.setEmail(email); | |
| 323 | + user.put("nome",mNome.getText().toString()); | |
| 324 | + | |
| 325 | + | |
| 326 | + user.signUpInBackground(new SignUpCallback() { | |
| 327 | + @Override | |
| 328 | + public void done(com.parse.ParseException e) { | |
| 329 | + if (e == null) { | |
| 330 | + montaFormLogout(); | |
| 331 | + } else { | |
| 332 | + showProgress(false,mLoginFormView); | |
| 333 | + Snackbar.make(mLoginFormView, "Houve um erro ao fazer seu cadastro ", Snackbar.LENGTH_LONG) | |
| 334 | + .setAction("Action", null).show(); | |
| 335 | + } | |
| 336 | + } | |
| 337 | + | |
| 338 | + | |
| 339 | + }); | |
| 340 | + | |
| 341 | + } | |
| 342 | + } | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + /** | |
| 347 | + * Set up the {@link android.app.ActionBar}, if the API is available. | |
| 348 | + */ | |
| 349 | +// @TargetApi(Build.VERSION_CODES.HONEYCOMB) | |
| 350 | + private void setupActionBar() { | |
| 351 | + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
| 352 | + | |
| 353 | + // toolbar.setNavigationIcon(R.drawable.ic_good); | |
| 354 | + toolbar.setTitle("Login"); | |
| 355 | + | |
| 356 | + toolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 357 | + toolbar.setSubtitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 358 | + setSupportActionBar(toolbar); | |
| 359 | + getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 360 | + } | |
| 361 | + | |
| 362 | + /** | |
| 363 | + * Attempts to sign in or register the account specified by the login form. | |
| 364 | + * If there are form errors (invalid email, missing fields, etc.), the | |
| 365 | + * errors are presented and no actual login attempt is made. | |
| 366 | + */ | |
| 367 | + public void attemptLogin() { | |
| 368 | + | |
| 369 | + | |
| 370 | + // Reset errors. | |
| 371 | + mEmailView.setError(null); | |
| 372 | + mPasswordView.setError(null); | |
| 373 | + | |
| 374 | + // Store values at the time of the login attempt. | |
| 375 | + String email = mEmailView.getText().toString(); | |
| 376 | + String password = mPasswordView.getText().toString(); | |
| 377 | + | |
| 378 | + boolean cancel = false; | |
| 379 | + View focusView = null; | |
| 380 | + | |
| 381 | + // Check for a valid password, if the user entered one. | |
| 382 | + if (TextUtils.isEmpty(password) && !isPasswordValid(password)) { | |
| 383 | + mPasswordView.setError(getString(R.string.error_invalid_password)); | |
| 384 | + focusView = mPasswordView; | |
| 385 | + cancel = true; | |
| 386 | + } | |
| 387 | + | |
| 388 | + // Check for a valid email address. | |
| 389 | + if (TextUtils.isEmpty(email)) { | |
| 390 | + mEmailView.setError(getString(R.string.error_field_required)); | |
| 391 | + focusView = mEmailView; | |
| 392 | + cancel = true; | |
| 393 | + } else if (!isEmailValid(email)) { | |
| 394 | + mEmailView.setError(getString(R.string.error_invalid_email)); | |
| 395 | + focusView = mEmailView; | |
| 396 | + cancel = true; | |
| 397 | + } | |
| 398 | + | |
| 399 | + if (cancel) { | |
| 400 | + // There was an error; don't attempt login and focus the first | |
| 401 | + // form field with an error. | |
| 402 | + focusView.requestFocus(); | |
| 403 | + } else { | |
| 404 | + // Show a progress spinner, and kick off a background task to | |
| 405 | + // perform the user login attempt. | |
| 406 | + showProgress(true,null); | |
| 407 | + | |
| 408 | + //fazer o login aqui | |
| 409 | + fazerLogin(email, password); | |
| 410 | + | |
| 411 | + } | |
| 412 | + } | |
| 413 | + | |
| 414 | + private void fazerLogin(String email, String password) { | |
| 415 | + ParseUser.logInInBackground(email, password, new LogInCallback() { | |
| 416 | + | |
| 417 | + @Override | |
| 418 | + public void done(ParseUser parseUser, com.parse.ParseException e) { | |
| 419 | + if (parseUser != null) { | |
| 420 | + finish(); | |
| 421 | + } else { | |
| 422 | + mPasswordView.setError(getString(R.string.error_incorrect_password)); | |
| 423 | + mPasswordView.requestFocus(); | |
| 424 | + showProgress(false,mLoginFormView); | |
| 425 | + } | |
| 426 | + } | |
| 427 | + | |
| 428 | + | |
| 429 | + }); | |
| 430 | + } | |
| 431 | + | |
| 432 | + private boolean isEmailValid(String email) { | |
| 433 | + //TODO: Replace this with your own logic | |
| 434 | + return email.contains("@"); | |
| 435 | + } | |
| 436 | + | |
| 437 | + private boolean isPasswordValid(String password) { | |
| 438 | + //TODO: Replace this with your own logic | |
| 439 | + return password.length() > 4; | |
| 440 | + } | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + private void addEmailsToAutoComplete(List<String> emailAddressCollection) { | |
| 447 | + //Create adapter to tell the AutoCompleteTextView what to show in its dropdown list. | |
| 448 | + ArrayAdapter<String> adapter = | |
| 449 | + new ArrayAdapter<String>(LoginActivity.this, | |
| 450 | + android.R.layout.simple_dropdown_item_1line, emailAddressCollection); | |
| 451 | + | |
| 452 | + mEmailView.setAdapter(adapter); | |
| 453 | + } | |
| 454 | + | |
| 455 | + | |
| 456 | +} | |
| 457 | + | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/MainActivity.java
0 → 100644
| ... | ... | @@ -0,0 +1,245 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view; | |
| 2 | + | |
| 3 | +import android.content.Intent; | |
| 4 | +import android.graphics.Bitmap; | |
| 5 | +import android.net.Uri; | |
| 6 | +import android.support.v4.app.FragmentTransaction; | |
| 7 | +import android.os.Bundle; | |
| 8 | +import android.support.v7.app.AppCompatActivity; | |
| 9 | +import android.support.v7.widget.Toolbar; | |
| 10 | +import android.view.Gravity; | |
| 11 | +import android.view.Menu; | |
| 12 | +import android.view.MenuItem; | |
| 13 | +import android.view.View; | |
| 14 | +import android.widget.AdapterView; | |
| 15 | + | |
| 16 | +import com.mikepenz.materialdrawer.Drawer; | |
| 17 | +import com.mikepenz.materialdrawer.DrawerBuilder; | |
| 18 | +import com.mikepenz.materialdrawer.accountswitcher.AccountHeader; | |
| 19 | +import com.mikepenz.materialdrawer.accountswitcher.AccountHeaderBuilder; | |
| 20 | +import com.mikepenz.materialdrawer.model.DividerDrawerItem; | |
| 21 | +import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; | |
| 22 | +import com.mikepenz.materialdrawer.model.ProfileDrawerItem; | |
| 23 | +import com.mikepenz.materialdrawer.model.SecondaryDrawerItem; | |
| 24 | +import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; | |
| 25 | +import com.mikepenz.materialdrawer.model.interfaces.IProfile; | |
| 26 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 27 | +import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 28 | +import com.monitorabrasil.monitoralegislativo.view.fragments.HomeFragment; | |
| 29 | +import com.nostra13.universalimageloader.core.assist.FailReason; | |
| 30 | +import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; | |
| 31 | +import com.parse.ParseTwitterUtils; | |
| 32 | +import com.parse.ParseUser; | |
| 33 | + | |
| 34 | + | |
| 35 | +public class MainActivity extends AppCompatActivity implements HomeFragment.OnFragmentInteractionListener { | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + private Toolbar mToolbar; | |
| 40 | + private AccountHeader headerNavigationLeft; | |
| 41 | + private Drawer navigationDrawerLeft; | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + @Override | |
| 46 | + protected void onCreate(Bundle savedInstanceState) { | |
| 47 | + super.onCreate(savedInstanceState); | |
| 48 | + setContentView(R.layout.activity_main); | |
| 49 | + | |
| 50 | + //FRAGMENT | |
| 51 | + HomeFragment homeFragment = (HomeFragment) getSupportFragmentManager().findFragmentByTag("homeFrag"); | |
| 52 | + if(homeFragment == null) { | |
| 53 | + homeFragment = homeFragment.newInstance(); | |
| 54 | + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); | |
| 55 | + ft.replace(R.id.rl_fragment_container, homeFragment, "homeFrag"); | |
| 56 | + ft.commit(); | |
| 57 | + } | |
| 58 | + | |
| 59 | + // TOOLBAR | |
| 60 | + mToolbar = (Toolbar) findViewById(R.id.tb_main); | |
| 61 | + mToolbar.setTitle(getString(R.string.app_name)); | |
| 62 | + mToolbar.setSubtitle("Ouro Branco - MG"); | |
| 63 | + //mToolbar.setLogo(R.drawable.ic_launcher); | |
| 64 | + setSupportActionBar(mToolbar); | |
| 65 | + mToolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 66 | + mToolbar.setSubtitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 67 | + | |
| 68 | + /*getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 69 | + getSupportActionBar().setHomeButtonEnabled(false);*/ | |
| 70 | + | |
| 71 | + | |
| 72 | + headerNavigationLeft = new AccountHeaderBuilder() | |
| 73 | + .withActivity(this) | |
| 74 | + .withHeaderBackground(R.drawable.rsz_ourobranco) | |
| 75 | + .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() { | |
| 76 | + @Override | |
| 77 | + public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) { | |
| 78 | + startActivity(new Intent(getApplicationContext(), Login2Activity.class)); | |
| 79 | + | |
| 80 | + return false; | |
| 81 | + } | |
| 82 | + }) | |
| 83 | + .build(); | |
| 84 | + | |
| 85 | + ParseUser currentUser = ParseUser.getCurrentUser(); | |
| 86 | + if (currentUser != null) { | |
| 87 | + | |
| 88 | + if(ParseTwitterUtils.getTwitter()!=null){ | |
| 89 | + String screenName = ParseTwitterUtils.getTwitter().getScreenName(); | |
| 90 | + MyApp.getInstance().getmImagemLoader().loadImage("https://twitter.com/" + screenName + "/profile_image?size=bigger", new ImageLoadingListener() { | |
| 91 | + @Override | |
| 92 | + public void onLoadingStarted(String imageUri, View view) { | |
| 93 | + | |
| 94 | + } | |
| 95 | + | |
| 96 | + @Override | |
| 97 | + public void onLoadingFailed(String imageUri, View view, FailReason failReason) { | |
| 98 | + | |
| 99 | + } | |
| 100 | + | |
| 101 | + @Override | |
| 102 | + public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { | |
| 103 | + headerNavigationLeft.addProfiles( | |
| 104 | + new ProfileDrawerItem().withName(ParseTwitterUtils.getTwitter().getScreenName()). | |
| 105 | + withEmail(ParseUser.getCurrentUser().getEmail()). | |
| 106 | + withIcon(loadedImage) | |
| 107 | + | |
| 108 | + ); | |
| 109 | + } | |
| 110 | + | |
| 111 | + @Override | |
| 112 | + public void onLoadingCancelled(String imageUri, View view) { | |
| 113 | + | |
| 114 | + } | |
| 115 | + }); | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + Uri uri = Uri.parse("https://twitter.com/" + screenName + "/profile_image?size=bigger"); | |
| 120 | + | |
| 121 | +// MyApp.getInstance().getmImagemLoader().lo.loadImageSync("https://twitter.com/" + screenName + "/profile_image?size=bigger"); | |
| 122 | +// headerNavigationLeft.getProfiles().get(0).setIcon(uri); | |
| 123 | + | |
| 124 | +// Uri uri = Uri.parse("https://twitter.com/"+screenName+"/profile_image?size=bigger"); | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + }else{ | |
| 129 | + headerNavigationLeft.addProfiles( | |
| 130 | + new ProfileDrawerItem().withName(currentUser.get("nome").toString()). | |
| 131 | + withEmail(currentUser.getEmail()) | |
| 132 | + .withIcon(getResources().getDrawable(R.drawable.person_1)) | |
| 133 | + ); | |
| 134 | + } | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + } else { | |
| 139 | + headerNavigationLeft.addProfiles( | |
| 140 | + new ProfileDrawerItem().withName("Faça seu cadastro")); | |
| 141 | + } | |
| 142 | + | |
| 143 | + navigationDrawerLeft = new DrawerBuilder() | |
| 144 | + .withActivity(this) | |
| 145 | + .withToolbar(mToolbar) | |
| 146 | + .withDisplayBelowToolbar(false) | |
| 147 | + .withActionBarDrawerToggleAnimated(true) | |
| 148 | + .withDrawerGravity(Gravity.START) | |
| 149 | + .withSavedInstance(savedInstanceState) | |
| 150 | + .withActionBarDrawerToggle(true) | |
| 151 | + .withAccountHeader(headerNavigationLeft) | |
| 152 | + .addDrawerItems( | |
| 153 | + new PrimaryDrawerItem().withName("Home"), | |
| 154 | + new DividerDrawerItem(), | |
| 155 | + new PrimaryDrawerItem().withName("Vereadores"), | |
| 156 | + new SecondaryDrawerItem().withName("Indicações"), | |
| 157 | + new SecondaryDrawerItem().withName("Câmara"), | |
| 158 | + new SecondaryDrawerItem().withName("Sobre") | |
| 159 | + ) | |
| 160 | + .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { | |
| 161 | + @Override | |
| 162 | + public boolean onItemClick(AdapterView<?> parent, View view, int position, long id, IDrawerItem drawerItem) { | |
| 163 | + switch (position){ | |
| 164 | + case 0: | |
| 165 | + HomeFragment homeFragment = (HomeFragment) getSupportFragmentManager().findFragmentByTag("homeFrag"); | |
| 166 | + if(homeFragment == null) { | |
| 167 | + homeFragment = homeFragment.newInstance(); | |
| 168 | + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); | |
| 169 | + ft.replace(R.id.rl_fragment_container, homeFragment, "homeFrag"); | |
| 170 | + ft.commit(); | |
| 171 | + } | |
| 172 | + break; | |
| 173 | + | |
| 174 | + | |
| 175 | + case 2: | |
| 176 | + startActivity(new Intent(getApplicationContext(), PoliticosActivity.class)); | |
| 177 | + break; | |
| 178 | + | |
| 179 | + case 3: | |
| 180 | + startActivity(new Intent(getApplicationContext(),ProjetosActivity.class)); | |
| 181 | + break; | |
| 182 | + | |
| 183 | + case 4: | |
| 184 | + startActivity(new Intent(getApplicationContext(), CamaraActivity.class)); | |
| 185 | + break; | |
| 186 | + case 5: | |
| 187 | + startActivity(new Intent(getApplicationContext(), SobreActivity.class)); | |
| 188 | + break; | |
| 189 | + | |
| 190 | + } | |
| 191 | + navigationDrawerLeft.closeDrawer(); | |
| 192 | + | |
| 193 | + return true; | |
| 194 | + } | |
| 195 | + }) | |
| 196 | + .build(); | |
| 197 | + | |
| 198 | + | |
| 199 | + } | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + @Override | |
| 205 | + public boolean onCreateOptionsMenu(Menu menu) { | |
| 206 | + // Inflate the menu; this adds items to the action bar if it is present. | |
| 207 | + getMenuInflater().inflate(R.menu.menu_main, menu); | |
| 208 | + return true; | |
| 209 | + } | |
| 210 | + | |
| 211 | + @Override | |
| 212 | + public boolean onOptionsItemSelected(MenuItem item) { | |
| 213 | + // Handle action bar item clicks here. The action bar will | |
| 214 | + // automatically handle clicks on the Home/Up button, so long | |
| 215 | + // as you specify a parent activity in AndroidManifest.xml. | |
| 216 | + int id = item.getItemId(); | |
| 217 | + | |
| 218 | + //noinspection SimplifiableIfStatement | |
| 219 | + if (id == R.id.action_sobre) { | |
| 220 | + startActivity(new Intent(getApplicationContext(),SobreActivity.class)); | |
| 221 | + return true; | |
| 222 | + } | |
| 223 | + | |
| 224 | + return super.onOptionsItemSelected(item); | |
| 225 | + } | |
| 226 | + | |
| 227 | + @Override | |
| 228 | + public void onBackPressed() { | |
| 229 | + if(navigationDrawerLeft.isDrawerOpen()){ | |
| 230 | + navigationDrawerLeft.closeDrawer(); | |
| 231 | + } | |
| 232 | + /*else if(fab.isOpened()){ | |
| 233 | + fab.close(true); | |
| 234 | + }*/ | |
| 235 | + else{ | |
| 236 | + super.onBackPressed(); | |
| 237 | + } | |
| 238 | + } | |
| 239 | + | |
| 240 | + | |
| 241 | + @Override | |
| 242 | + public void onFragmentInteraction(Uri uri) { | |
| 243 | + | |
| 244 | + } | |
| 245 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/PoliticoFichaActivity.java
0 → 100644
| ... | ... | @@ -0,0 +1,215 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view; | |
| 2 | + | |
| 3 | +import android.content.Intent; | |
| 4 | +import android.content.res.Configuration; | |
| 5 | +import android.os.Bundle; | |
| 6 | +import android.support.design.widget.CollapsingToolbarLayout; | |
| 7 | +import android.support.design.widget.CoordinatorLayout; | |
| 8 | +import android.support.design.widget.FloatingActionButton; | |
| 9 | +import android.support.design.widget.TabLayout; | |
| 10 | +import android.support.v4.app.Fragment; | |
| 11 | +import android.support.v4.app.FragmentManager; | |
| 12 | +import android.support.v4.app.FragmentStatePagerAdapter; | |
| 13 | +import android.support.v4.view.ViewPager; | |
| 14 | +import android.support.v7.app.AppCompatActivity; | |
| 15 | +import android.support.v7.widget.Toolbar; | |
| 16 | +import android.view.Menu; | |
| 17 | +import android.view.MenuItem; | |
| 18 | +import android.view.View; | |
| 19 | + | |
| 20 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 21 | +import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 22 | +import com.monitorabrasil.monitoralegislativo.view.fragments.GastosFragment; | |
| 23 | +import com.monitorabrasil.monitoralegislativo.view.fragments.ListaProjetosFragment; | |
| 24 | +import com.monitorabrasil.monitoralegislativo.view.fragments.PoliticoFichaFragment; | |
| 25 | +import com.parse.ParseObject; | |
| 26 | +import com.parse.ParseQuery; | |
| 27 | + | |
| 28 | +import java.util.ArrayList; | |
| 29 | +import java.util.List; | |
| 30 | + | |
| 31 | +public class PoliticoFichaActivity extends AppCompatActivity { | |
| 32 | + | |
| 33 | + Toolbar toolbar; | |
| 34 | + CollapsingToolbarLayout collapsingToolbarLayout; | |
| 35 | + TabLayout tabLayout; | |
| 36 | + String idPolitico; | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | +// ActionBarDrawerToggle drawerToggle; | |
| 41 | + | |
| 42 | + CoordinatorLayout rootLayout; | |
| 43 | + | |
| 44 | + @Override | |
| 45 | + protected void onCreate(Bundle savedInstanceState) { | |
| 46 | + super.onCreate(savedInstanceState); | |
| 47 | + setContentView(R.layout.activity_politico_ficha); | |
| 48 | + | |
| 49 | + | |
| 50 | + initInstances(); | |
| 51 | + initToolbar(); | |
| 52 | + | |
| 53 | + Bundle bundle = getIntent().getExtras(); | |
| 54 | + idPolitico = bundle.getString("politico"); | |
| 55 | + buscaPolitico(idPolitico) ; | |
| 56 | + | |
| 57 | + // buscaGrafico(); | |
| 58 | + //montaFicha(); | |
| 59 | + | |
| 60 | + ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); | |
| 61 | + if (viewPager != null) { | |
| 62 | + setupViewPager(viewPager); | |
| 63 | + } | |
| 64 | + | |
| 65 | + setSupportActionBar(toolbar); | |
| 66 | + getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 67 | + | |
| 68 | + FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); | |
| 69 | + fab.setOnClickListener(new View.OnClickListener() { | |
| 70 | + @Override | |
| 71 | + public void onClick(View view) { | |
| 72 | + Intent mIntent = new Intent(MyApp.getInstance().getApplicationContext(), ComentarioActivity.class); | |
| 73 | + mIntent.putExtra("politico", idPolitico); | |
| 74 | + | |
| 75 | + mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
| 76 | + | |
| 77 | + MyApp.getInstance().startActivity(mIntent); | |
| 78 | + | |
| 79 | + } | |
| 80 | + }); | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + } | |
| 86 | + | |
| 87 | + private void setupViewPager(ViewPager viewPager) { | |
| 88 | + Adapter adapter = new Adapter(getSupportFragmentManager()); | |
| 89 | + PoliticoFichaFragment ficha = new PoliticoFichaFragment(); | |
| 90 | + ficha.setArguments(getIntent().getExtras()); | |
| 91 | + adapter.addFragment(ficha, "Ficha"); | |
| 92 | + GastosFragment gastos = new GastosFragment(); | |
| 93 | + gastos.setArguments(getIntent().getExtras()); | |
| 94 | + adapter.addFragment(gastos, "Gastos"); | |
| 95 | + | |
| 96 | + //projetos | |
| 97 | + ListaProjetosFragment listaProjetosFragment = ListaProjetosFragment.newInstance(null,idPolitico); | |
| 98 | + // listaProjetosFragment.setArguments(getIntent().getExtras()); | |
| 99 | + adapter.addFragment(listaProjetosFragment, "Projetos"); | |
| 100 | + | |
| 101 | + viewPager.setAdapter(adapter); | |
| 102 | + viewPager.getAdapter().notifyDataSetChanged(); | |
| 103 | + | |
| 104 | + tabLayout = (TabLayout) findViewById(R.id.tabLayout); | |
| 105 | + tabLayout.setupWithViewPager(viewPager); | |
| 106 | + } | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + private ParseObject buscaPolitico(String id) { | |
| 111 | + | |
| 112 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("Politico"); | |
| 113 | + query.fromLocalDatastore(); | |
| 114 | + try { | |
| 115 | + ParseObject politico = query.get(id); | |
| 116 | + setTitle(politico.get("nome").toString()); | |
| 117 | +// collapsingToolbarLayout.setTitle(politico.get("nome").toString()); | |
| 118 | + } catch (com.parse.ParseException e) { | |
| 119 | + e.printStackTrace(); | |
| 120 | + } | |
| 121 | + return null; | |
| 122 | + } | |
| 123 | + | |
| 124 | + private void initToolbar() { | |
| 125 | + toolbar = (Toolbar) findViewById(R.id.toolbar); | |
| 126 | + setSupportActionBar(toolbar); | |
| 127 | + } | |
| 128 | + | |
| 129 | + private void initInstances() { | |
| 130 | +// drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout); | |
| 131 | +// drawerToggle = new ActionBarDrawerToggle(PoliticoFichaActivity.this, drawerLayout, R.string.hello_world, R.string.hello_world); | |
| 132 | +// drawerLayout.setDrawerListener(drawerToggle); | |
| 133 | + | |
| 134 | +// getSupportActionBar().setHomeButtonEnabled(true); | |
| 135 | +// getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 136 | + | |
| 137 | + rootLayout = (CoordinatorLayout) findViewById(R.id.main_content); | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + //collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + } | |
| 149 | + | |
| 150 | + @Override | |
| 151 | + public void onPostCreate(Bundle savedInstanceState) { | |
| 152 | + super.onPostCreate(savedInstanceState); | |
| 153 | +// drawerToggle.syncState(); | |
| 154 | + } | |
| 155 | + | |
| 156 | + @Override | |
| 157 | + public void onConfigurationChanged(Configuration newConfig) { | |
| 158 | + super.onConfigurationChanged(newConfig); | |
| 159 | +// drawerToggle.onConfigurationChanged(newConfig); | |
| 160 | + } | |
| 161 | + | |
| 162 | + @Override | |
| 163 | + public boolean onCreateOptionsMenu(Menu menu) { | |
| 164 | + // Inflate the menu; this adds items to the action bar if it is present. | |
| 165 | + getMenuInflater().inflate(R.menu.menu_main, menu); | |
| 166 | + return true; | |
| 167 | + } | |
| 168 | + | |
| 169 | + @Override | |
| 170 | + public boolean onOptionsItemSelected(MenuItem item) { | |
| 171 | +// if (drawerToggle.onOptionsItemSelected(item)) | |
| 172 | +// return true; | |
| 173 | + | |
| 174 | + // Handle action bar item clicks here. The action bar will | |
| 175 | + // automatically handle clicks on the Home/Up button, so long | |
| 176 | + // as you specify a parent activity in AndroidManifest.xml. | |
| 177 | + int id = item.getItemId(); | |
| 178 | + | |
| 179 | + //noinspection SimplifiableIfStatement | |
| 180 | + | |
| 181 | + | |
| 182 | + return super.onOptionsItemSelected(item); | |
| 183 | + } | |
| 184 | + | |
| 185 | + static class Adapter extends FragmentStatePagerAdapter { | |
| 186 | + private final List<Fragment> mFragments = new ArrayList<>(); | |
| 187 | + private final List<String> mFragmentTitles = new ArrayList<>(); | |
| 188 | + | |
| 189 | + public Adapter(FragmentManager fm) { | |
| 190 | + super(fm); | |
| 191 | + } | |
| 192 | + | |
| 193 | + public void addFragment(Fragment fragment, String title) { | |
| 194 | + mFragments.add(fragment); | |
| 195 | + mFragmentTitles.add(title); | |
| 196 | + } | |
| 197 | + | |
| 198 | + @Override | |
| 199 | + public Fragment getItem(int position) { | |
| 200 | + | |
| 201 | + return mFragments.get(position); | |
| 202 | + } | |
| 203 | + | |
| 204 | + | |
| 205 | + @Override | |
| 206 | + public int getCount() { | |
| 207 | + return mFragments.size(); | |
| 208 | + } | |
| 209 | + | |
| 210 | + @Override | |
| 211 | + public CharSequence getPageTitle(int position) { | |
| 212 | + return mFragmentTitles.get(position); | |
| 213 | + } | |
| 214 | + } | |
| 215 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/PoliticosActivity.java
0 → 100644
| ... | ... | @@ -0,0 +1,68 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view; | |
| 2 | + | |
| 3 | +import android.support.v4.app.FragmentTransaction; | |
| 4 | +import android.os.Bundle; | |
| 5 | +import android.support.v7.app.AppCompatActivity; | |
| 6 | +import android.support.v7.widget.Toolbar; | |
| 7 | +import android.view.Menu; | |
| 8 | +import android.view.MenuItem; | |
| 9 | + | |
| 10 | +import com.crashlytics.android.answers.Answers; | |
| 11 | +import com.crashlytics.android.answers.ContentViewEvent; | |
| 12 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 13 | +import com.monitorabrasil.monitoralegislativo.view.fragments.ListaPoliticoFragment; | |
| 14 | + | |
| 15 | +public class PoliticosActivity extends AppCompatActivity { | |
| 16 | + | |
| 17 | + @Override | |
| 18 | + protected void onCreate(Bundle savedInstanceState) { | |
| 19 | + super.onCreate(savedInstanceState); | |
| 20 | + setContentView(R.layout.activity_politicos); | |
| 21 | + | |
| 22 | + Answers.getInstance().logContentView(new ContentViewEvent() | |
| 23 | + .putContentName("PoliticosActivity") | |
| 24 | + .putContentType("Activity")); | |
| 25 | + | |
| 26 | + ListaPoliticoFragment frag = (ListaPoliticoFragment) getSupportFragmentManager().findFragmentByTag("listaPoliticoFrag"); | |
| 27 | + if(frag == null) { | |
| 28 | + frag = new ListaPoliticoFragment(); | |
| 29 | + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); | |
| 30 | + ft.replace(R.id.rl_fragment_container, frag, "listaPoliticoFrag"); | |
| 31 | + ft.commit(); | |
| 32 | + } | |
| 33 | + | |
| 34 | + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
| 35 | + setSupportActionBar(toolbar); | |
| 36 | + | |
| 37 | + // toolbar.setNavigationIcon(R.drawable.ic_good); | |
| 38 | + toolbar.setTitle("Vereadores"); | |
| 39 | + toolbar.setSubtitle("Ouro Branco - MG"); | |
| 40 | + | |
| 41 | + toolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 42 | + toolbar.setSubtitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 43 | + setSupportActionBar(toolbar); | |
| 44 | + getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 45 | + // toolbar.setLogo(R.drawable.ic_launcher); | |
| 46 | + } | |
| 47 | + | |
| 48 | + | |
| 49 | + @Override | |
| 50 | + public boolean onCreateOptionsMenu(Menu menu) { | |
| 51 | + // Inflate the menu; this adds items to the action bar if it is present. | |
| 52 | +// getMenuInflater().inflate(R.menu.menu_politicos, menu); | |
| 53 | + return true; | |
| 54 | + } | |
| 55 | + | |
| 56 | + @Override | |
| 57 | + public boolean onOptionsItemSelected(MenuItem item) { | |
| 58 | + // Handle action bar item clicks here. The action bar will | |
| 59 | + // automatically handle clicks on the Home/Up button, so long | |
| 60 | + // as you specify a parent activity in AndroidManifest.xml. | |
| 61 | + int id = item.getItemId(); | |
| 62 | + | |
| 63 | + //noinspection SimplifiableIfStatement | |
| 64 | + | |
| 65 | + | |
| 66 | + return super.onOptionsItemSelected(item); | |
| 67 | + } | |
| 68 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/ProjetosActivity.java
0 → 100644
| ... | ... | @@ -0,0 +1,100 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view; | |
| 2 | + | |
| 3 | +import android.os.Bundle; | |
| 4 | +import android.support.v4.app.FragmentTransaction; | |
| 5 | +import android.support.v7.app.AppCompatActivity; | |
| 6 | +import android.support.v7.widget.Toolbar; | |
| 7 | +import android.view.Menu; | |
| 8 | +import android.view.MenuItem; | |
| 9 | + | |
| 10 | +import com.crashlytics.android.answers.Answers; | |
| 11 | +import com.crashlytics.android.answers.ContentViewEvent; | |
| 12 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 13 | +import com.monitorabrasil.monitoralegislativo.view.fragments.EscolhaTipoProjeto; | |
| 14 | + | |
| 15 | +public class ProjetosActivity extends AppCompatActivity { | |
| 16 | + | |
| 17 | + @Override | |
| 18 | + protected void onCreate(Bundle savedInstanceState) { | |
| 19 | + super.onCreate(savedInstanceState); | |
| 20 | + setContentView(R.layout.activity_projetos); | |
| 21 | + | |
| 22 | + | |
| 23 | + Answers.getInstance().logContentView(new ContentViewEvent() | |
| 24 | + .putContentName("ProjetosActivity") | |
| 25 | + .putContentType("Activity")); | |
| 26 | + | |
| 27 | + EscolhaTipoProjeto frag = (EscolhaTipoProjeto) getSupportFragmentManager().findFragmentByTag("listaTipoProjFrag"); | |
| 28 | + if(frag == null) { | |
| 29 | + frag = new EscolhaTipoProjeto(); | |
| 30 | + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); | |
| 31 | + ft.replace(R.id.rl_fragment_container, frag, "listaTipoProjFrag"); | |
| 32 | + ft.commit(); | |
| 33 | + } | |
| 34 | + | |
| 35 | + /*ListaProjetosFragment frag = (ListaProjetosFragment) getSupportFragmentManager().findFragmentByTag("listaProjFrag"); | |
| 36 | + if(frag == null) { | |
| 37 | + frag = new ListaProjetosFragment(); | |
| 38 | + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); | |
| 39 | + ft.replace(R.id.rl_fragment_container, frag, "listaProjFrag"); | |
| 40 | + ft.commit(); | |
| 41 | + }*/ | |
| 42 | + | |
| 43 | + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
| 44 | + setSupportActionBar(toolbar); | |
| 45 | + | |
| 46 | + // toolbar.setNavigationIcon(R.drawable.ic_good); | |
| 47 | + toolbar.setTitle("Indicações"); | |
| 48 | + toolbar.setSubtitle("Ouro Branco - MG"); | |
| 49 | + | |
| 50 | + toolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 51 | + toolbar.setSubtitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 52 | + setSupportActionBar(toolbar); | |
| 53 | + getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 54 | + } | |
| 55 | + | |
| 56 | + @Override | |
| 57 | + public boolean onCreateOptionsMenu(Menu menu) { | |
| 58 | + // Inflate the menu; this adds items to the action bar if it is present. | |
| 59 | + getMenuInflater().inflate(R.menu.menu_projetos, menu); | |
| 60 | + /* MenuItem searchItem = menu.findItem(R.id.ic_procura); | |
| 61 | + | |
| 62 | + SearchView searchView = (SearchView) searchItem.getActionView(); | |
| 63 | + | |
| 64 | + SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); | |
| 65 | + searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); | |
| 66 | + searchView.setIconifiedByDefault(true); | |
| 67 | + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { | |
| 68 | + | |
| 69 | + @Override | |
| 70 | + public boolean onQueryTextSubmit(String query) { | |
| 71 | + if (!query.isEmpty()) { | |
| 72 | + //realizar a busca | |
| 73 | + System.out.println(query); | |
| 74 | + } | |
| 75 | + | |
| 76 | + return false; | |
| 77 | + } | |
| 78 | + | |
| 79 | + @Override | |
| 80 | + public boolean onQueryTextChange(String newText) { | |
| 81 | + | |
| 82 | + return false; | |
| 83 | + } | |
| 84 | + });*/ | |
| 85 | + return true; | |
| 86 | + } | |
| 87 | + | |
| 88 | + @Override | |
| 89 | + public boolean onOptionsItemSelected(MenuItem item) { | |
| 90 | + // Handle action bar item clicks here. The action bar will | |
| 91 | + // automatically handle clicks on the Home/Up button, so long | |
| 92 | + // as you specify a parent activity in AndroidManifest.xml. | |
| 93 | + int id = item.getItemId(); | |
| 94 | + | |
| 95 | + //noinspection SimplifiableIfStatement | |
| 96 | + | |
| 97 | + | |
| 98 | + return super.onOptionsItemSelected(item); | |
| 99 | + } | |
| 100 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/SobreActivity.java
0 → 100644
| ... | ... | @@ -0,0 +1,71 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view; | |
| 2 | + | |
| 3 | +import android.content.pm.PackageManager; | |
| 4 | +import android.support.v7.app.ActionBarActivity; | |
| 5 | +import android.os.Bundle; | |
| 6 | +import android.support.v7.app.AppCompatActivity; | |
| 7 | +import android.support.v7.widget.Toolbar; | |
| 8 | +import android.text.Html; | |
| 9 | +import android.text.method.LinkMovementMethod; | |
| 10 | +import android.view.Menu; | |
| 11 | +import android.view.MenuItem; | |
| 12 | +import android.widget.TextView; | |
| 13 | + | |
| 14 | +import com.crashlytics.android.answers.Answers; | |
| 15 | +import com.crashlytics.android.answers.ContentViewEvent; | |
| 16 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 17 | + | |
| 18 | +import org.w3c.dom.Text; | |
| 19 | + | |
| 20 | +public class SobreActivity extends AppCompatActivity { | |
| 21 | + | |
| 22 | + Toolbar toolbar; | |
| 23 | + | |
| 24 | + @Override | |
| 25 | + protected void onCreate(Bundle savedInstanceState) { | |
| 26 | + super.onCreate(savedInstanceState); | |
| 27 | + setContentView(R.layout.activity_sobre); | |
| 28 | + initToolbar(); | |
| 29 | + toolbar.setTitle("Sobre"); | |
| 30 | + setSupportActionBar(toolbar); | |
| 31 | + getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + TextView versao = (TextView)findViewById(R.id.versao); | |
| 36 | + try { | |
| 37 | + versao.setText("Versão: "+getPackageManager().getPackageInfo(getPackageName(), 0).versionName); | |
| 38 | + } catch (PackageManager.NameNotFoundException e) { | |
| 39 | + e.printStackTrace(); | |
| 40 | + } | |
| 41 | + | |
| 42 | + Answers.getInstance().logContentView(new ContentViewEvent() | |
| 43 | + .putContentName("SobreActivity") | |
| 44 | + .putContentType("Activity")); | |
| 45 | + } | |
| 46 | + | |
| 47 | + private void initToolbar() { | |
| 48 | + toolbar = (Toolbar) findViewById(R.id.toolbar); | |
| 49 | + setSupportActionBar(toolbar); | |
| 50 | + } | |
| 51 | + | |
| 52 | + @Override | |
| 53 | + public boolean onCreateOptionsMenu(Menu menu) { | |
| 54 | + // Inflate the menu; this adds items to the action bar if it is present. | |
| 55 | + getMenuInflater().inflate(R.menu.menu_sobre, menu); | |
| 56 | + return true; | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Override | |
| 60 | + public boolean onOptionsItemSelected(MenuItem item) { | |
| 61 | + // Handle action bar item clicks here. The action bar will | |
| 62 | + // automatically handle clicks on the Home/Up button, so long | |
| 63 | + // as you specify a parent activity in AndroidManifest.xml. | |
| 64 | + int id = item.getItemId(); | |
| 65 | + | |
| 66 | + //noinspection SimplifiableIfStatement | |
| 67 | + | |
| 68 | + | |
| 69 | + return super.onOptionsItemSelected(item); | |
| 70 | + } | |
| 71 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/adapters/ComentarioAdapter.java
0 → 100644
| ... | ... | @@ -0,0 +1,75 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.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.TextView; | |
| 8 | + | |
| 9 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 10 | +import com.monitorabrasil.monitoralegislativo.view.interfaces.RecyclerViewOnClickListenerHack; | |
| 11 | +import com.parse.ParseObject; | |
| 12 | + | |
| 13 | +import java.util.List; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * Created by geral_000 on 05/07/2015. | |
| 17 | + */ | |
| 18 | +public class ComentarioAdapter extends RecyclerView.Adapter<ComentarioAdapter.ViewHolder> { | |
| 19 | + | |
| 20 | + private List<ParseObject> mDataset; | |
| 21 | + private RecyclerViewOnClickListenerHack mRecyclerViewOnClickListenerHack; | |
| 22 | + | |
| 23 | + // Provide a reference to the views for each data item | |
| 24 | + // Complex data items may need more than one view per item, and | |
| 25 | + // you provide access to all the views for a data item in a view holder | |
| 26 | + public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ | |
| 27 | + // each data item is just a string in this case | |
| 28 | + public TextView txtUser; | |
| 29 | + public TextView txtComentario; | |
| 30 | + public ViewHolder(View v) { | |
| 31 | + super(v); | |
| 32 | + txtUser = (TextView) v.findViewById(R.id.txtUser); | |
| 33 | + txtComentario = (TextView) v.findViewById(R.id.txtComentario); | |
| 34 | + | |
| 35 | + itemView.setOnClickListener(this); | |
| 36 | + } | |
| 37 | + | |
| 38 | + @Override | |
| 39 | + public void onClick(View v) { | |
| 40 | + if(mRecyclerViewOnClickListenerHack != null){ | |
| 41 | + mRecyclerViewOnClickListenerHack.onClickListener(v, getPosition()); | |
| 42 | + } | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + public ComentarioAdapter(List<ParseObject> myDataset) { | |
| 47 | + mDataset = myDataset; | |
| 48 | + } | |
| 49 | + | |
| 50 | + @Override | |
| 51 | + public ComentarioAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { | |
| 52 | + // create a new view | |
| 53 | + View v = LayoutInflater.from(viewGroup.getContext()) | |
| 54 | + .inflate(R.layout.item_comentario, viewGroup, false); | |
| 55 | + // set the view's size, margins, paddings and layout parameter | |
| 56 | + ViewHolder vh = new ViewHolder(v); | |
| 57 | + return vh; | |
| 58 | + } | |
| 59 | + public void setRecyclerViewOnClickListenerHack(RecyclerViewOnClickListenerHack r){ | |
| 60 | + mRecyclerViewOnClickListenerHack = r; | |
| 61 | + } | |
| 62 | + | |
| 63 | + @Override | |
| 64 | + public void onBindViewHolder(ComentarioAdapter.ViewHolder viewHolder, int i) { | |
| 65 | + ParseObject comentario = mDataset.get(i); | |
| 66 | + // vereador.pinInBackground(); | |
| 67 | + viewHolder.txtUser.setText(comentario.get("nome").toString()); | |
| 68 | + viewHolder.txtComentario.setText(comentario.get("mensagem").toString()); | |
| 69 | + } | |
| 70 | + | |
| 71 | + @Override | |
| 72 | + public int getItemCount() { | |
| 73 | + return mDataset.size(); | |
| 74 | + } | |
| 75 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/adapters/GastoAdapter.java
0 → 100644
| ... | ... | @@ -0,0 +1,202 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.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.TextView; | |
| 8 | + | |
| 9 | +import com.crashlytics.android.Crashlytics; | |
| 10 | +import com.github.mikephil.charting.animation.Easing; | |
| 11 | +import com.github.mikephil.charting.charts.BarChart; | |
| 12 | +import com.github.mikephil.charting.components.Legend; | |
| 13 | +import com.github.mikephil.charting.components.XAxis; | |
| 14 | +import com.github.mikephil.charting.components.YAxis; | |
| 15 | +import com.github.mikephil.charting.data.BarData; | |
| 16 | +import com.github.mikephil.charting.data.BarDataSet; | |
| 17 | +import com.github.mikephil.charting.utils.ValueFormatter; | |
| 18 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 19 | +import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 20 | +import com.monitorabrasil.monitoralegislativo.model.Grafico; | |
| 21 | +import com.monitorabrasil.monitoralegislativo.view.interfaces.RecyclerViewOnClickListenerHack; | |
| 22 | +import com.monitorabrasil.monitoralegislativo.model.util.MyValueFormatter; | |
| 23 | + | |
| 24 | +import java.util.ArrayList; | |
| 25 | +import java.util.List; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * Created by geral_000 on 26/06/2015. | |
| 29 | + */ | |
| 30 | +public class GastoAdapter extends RecyclerView.Adapter<GastoAdapter.ViewHolder> { | |
| 31 | + | |
| 32 | + private List<Grafico> mDataset; | |
| 33 | + private RecyclerViewOnClickListenerHack mRecyclerViewOnClickListenerHack; | |
| 34 | + | |
| 35 | + // Provide a reference to the views for each data item | |
| 36 | + // Complex data items may need more than one view per item, and | |
| 37 | + // you provide access to all the views for a data item in a view holder | |
| 38 | + public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ | |
| 39 | + // each data item is just a string in this case | |
| 40 | + | |
| 41 | + public BarChart chart; | |
| 42 | + public TextView titulo; | |
| 43 | + public ViewHolder(View v) { | |
| 44 | + super(v); | |
| 45 | + | |
| 46 | + chart = (BarChart) v.findViewById(R.id.chart1); | |
| 47 | + titulo = (TextView) v.findViewById(R.id.titulo); | |
| 48 | + | |
| 49 | + itemView.setOnClickListener(this); | |
| 50 | + } | |
| 51 | + | |
| 52 | + @Override | |
| 53 | + public void onClick(View v) { | |
| 54 | + if(mRecyclerViewOnClickListenerHack != null){ | |
| 55 | + mRecyclerViewOnClickListenerHack.onClickListener(v, getPosition()); | |
| 56 | + } | |
| 57 | + } | |
| 58 | + } | |
| 59 | + | |
| 60 | + public GastoAdapter(List<Grafico> myDataset) { | |
| 61 | + mDataset = myDataset; | |
| 62 | + } | |
| 63 | + | |
| 64 | + @Override | |
| 65 | + public GastoAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { | |
| 66 | + // create a new view | |
| 67 | + View v = LayoutInflater.from(viewGroup.getContext()) | |
| 68 | + .inflate(R.layout.item_grafico, viewGroup, false); | |
| 69 | + // set the view's size, margins, paddings and layout parameter | |
| 70 | + ViewHolder vh = new ViewHolder(v); | |
| 71 | + return vh; | |
| 72 | + } | |
| 73 | + public void setRecyclerViewOnClickListenerHack(RecyclerViewOnClickListenerHack r){ | |
| 74 | + mRecyclerViewOnClickListenerHack = r; | |
| 75 | + } | |
| 76 | + | |
| 77 | + @Override | |
| 78 | + public void onBindViewHolder(GastoAdapter.ViewHolder viewHolder, int i) { | |
| 79 | + | |
| 80 | + //construir grafico | |
| 81 | + buildGraph(viewHolder.chart); | |
| 82 | + //setdata | |
| 83 | + Grafico grafico = mDataset.get(i); | |
| 84 | + setData(grafico,viewHolder.chart); | |
| 85 | + | |
| 86 | + viewHolder.chart.animateX(2500, Easing.EasingOption.EaseInOutQuart); | |
| 87 | + viewHolder.chart.notifyDataSetChanged(); | |
| 88 | + | |
| 89 | + viewHolder.titulo.setText(grafico.getTitulo()); | |
| 90 | + //ParseObject vereador = mDataset.get(i); | |
| 91 | + //vereador.pinInBackground(); | |
| 92 | + //viewHolder.pb.setText(vereador.get("nome").toString()); | |
| 93 | + | |
| 94 | + } | |
| 95 | + | |
| 96 | + @Override | |
| 97 | + public int getItemCount() { | |
| 98 | + return mDataset.size(); | |
| 99 | + } | |
| 100 | + | |
| 101 | + private void buildGraph(BarChart mChart) { | |
| 102 | + | |
| 103 | +// mChart.set | |
| 104 | + | |
| 105 | + mChart.setDrawBarShadow(false); | |
| 106 | + mChart.setDrawValueAboveBar(true); | |
| 107 | + | |
| 108 | + mChart.setDescription(""); | |
| 109 | + | |
| 110 | + // if more than 60 entries are displayed in the chart, no values will be | |
| 111 | + // drawn | |
| 112 | + mChart.setMaxVisibleValueCount(60); | |
| 113 | + | |
| 114 | + // scaling can now only be done on x- and y-axis separately | |
| 115 | + mChart.setPinchZoom(false); | |
| 116 | + | |
| 117 | + // draw shadows for each bar that show the maximum value | |
| 118 | + // mChart.setDrawBarShadow(true); | |
| 119 | + | |
| 120 | + // mChart.setDrawXLabels(false); | |
| 121 | + | |
| 122 | + mChart.setDrawGridBackground(false); | |
| 123 | + // mChart.setDrawYLabels(false); | |
| 124 | + | |
| 125 | +// mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); | |
| 126 | + | |
| 127 | + XAxis xAxis = mChart.getXAxis(); | |
| 128 | + xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); | |
| 129 | +// xAxis.setTypeface(mTf); | |
| 130 | + xAxis.setDrawGridLines(false); | |
| 131 | + xAxis.setSpaceBetweenLabels(2); | |
| 132 | + | |
| 133 | + ValueFormatter custom = new MyValueFormatter(); | |
| 134 | + | |
| 135 | + YAxis leftAxis = mChart.getAxisLeft(); | |
| 136 | +// leftAxis.setTypeface(mTf); | |
| 137 | + leftAxis.setLabelCount(8,true); | |
| 138 | + leftAxis.setValueFormatter(custom); | |
| 139 | + leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART); | |
| 140 | + leftAxis.setSpaceTop(15f); | |
| 141 | + | |
| 142 | + mChart.getAxisRight().setEnabled(false); | |
| 143 | + YAxis rightAxis = mChart.getAxisRight(); | |
| 144 | + rightAxis.setDrawGridLines(false); | |
| 145 | +// rightAxis.setTypeface(mTf); | |
| 146 | + rightAxis.setLabelCount(8,true); | |
| 147 | + rightAxis.setValueFormatter(custom); | |
| 148 | + rightAxis.setSpaceTop(15f); | |
| 149 | + | |
| 150 | + Legend l = mChart.getLegend(); | |
| 151 | + l.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT); | |
| 152 | + l.setForm(Legend.LegendForm.SQUARE); | |
| 153 | + l.setFormSize(9f); | |
| 154 | + l.setTextSize(11f); | |
| 155 | + l.setXEntrySpace(4f); | |
| 156 | + // l.setExtra(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc", | |
| 157 | + // "def", "ghj", "ikl", "mno" }); | |
| 158 | + // l.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc", | |
| 159 | + // "def", "ghj", "ikl", "mno" }); | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + // setting data | |
| 164 | +// mSeekBarY.setProgress(50); | |
| 165 | +// mSeekBarX.setProgress(12); | |
| 166 | +// | |
| 167 | +// mSeekBarY.setOnSeekBarChangeListener(this); | |
| 168 | +// mSeekBarX.setOnSeekBarChangeListener(this); | |
| 169 | + | |
| 170 | + // mChart.setDrawLegend(false); | |
| 171 | + | |
| 172 | + } | |
| 173 | + | |
| 174 | + private void setData(Grafico grafico, BarChart mChart) { | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + BarDataSet set1 = new BarDataSet(grafico.getyAxis(), "Gastos Totais"); | |
| 179 | + set1.setBarSpacePercent(35f); | |
| 180 | + | |
| 181 | + ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>(); | |
| 182 | + dataSets.add(set1); | |
| 183 | + try{ | |
| 184 | + set1.setColor(MyApp.getInstance().getResources().getColor(grafico.getCor())); | |
| 185 | + | |
| 186 | + BarData data = new BarData(grafico.getxVals(), dataSets); | |
| 187 | + // data.setValueFormatter(new MyValueFormatter()); | |
| 188 | + data.setValueTextSize(10f); | |
| 189 | +// data.setValueTypeface(mTf); | |
| 190 | + mChart.setVisibility(View.VISIBLE); | |
| 191 | + mChart.setData(data); | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + }catch (Exception e){ | |
| 196 | + Crashlytics.log("GastosCamaraFragment " + e.toString()); | |
| 197 | + } | |
| 198 | + | |
| 199 | + } | |
| 200 | + | |
| 201 | + | |
| 202 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/adapters/ProjetoAdapter.java
0 → 100644
| ... | ... | @@ -0,0 +1,291 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view.adapters; | |
| 2 | + | |
| 3 | +import android.content.Intent; | |
| 4 | +import android.graphics.drawable.Drawable; | |
| 5 | +import android.os.Build; | |
| 6 | +import android.support.design.widget.Snackbar; | |
| 7 | +import android.support.v4.app.ActivityOptionsCompat; | |
| 8 | +import android.support.v4.app.FragmentActivity; | |
| 9 | +import android.support.v4.content.ContextCompat; | |
| 10 | +import android.support.v4.util.Pair; | |
| 11 | +import android.support.v7.widget.RecyclerView; | |
| 12 | +import android.view.LayoutInflater; | |
| 13 | +import android.view.View; | |
| 14 | +import android.view.ViewGroup; | |
| 15 | +import android.widget.Button; | |
| 16 | +import android.widget.TextView; | |
| 17 | + | |
| 18 | +import com.google.gson.Gson; | |
| 19 | +import com.monitorabrasil.monitoralegislativo.view.ComentarioActivity; | |
| 20 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 21 | +import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 22 | +import com.monitorabrasil.monitoralegislativo.view.interfaces.RecyclerViewOnClickListenerHack; | |
| 23 | +import com.parse.FindCallback; | |
| 24 | +import com.parse.ParseException; | |
| 25 | +import com.parse.ParseObject; | |
| 26 | +import com.parse.ParseQuery; | |
| 27 | +import com.parse.ParseUser; | |
| 28 | +import com.parse.SaveCallback; | |
| 29 | + | |
| 30 | +import java.util.List; | |
| 31 | + | |
| 32 | +/** | |
| 33 | + * Created by geral_000 on 25/06/2015. | |
| 34 | + */ | |
| 35 | +public class ProjetoAdapter extends RecyclerView.Adapter<ProjetoAdapter.ViewHolder> { | |
| 36 | + | |
| 37 | + private List<ParseObject> mDataset; | |
| 38 | + private RecyclerViewOnClickListenerHack mRecyclerViewOnClickListenerHack; | |
| 39 | + private FragmentActivity mActivity; | |
| 40 | + | |
| 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); | |
| 69 | + | |
| 70 | + itemView.setOnClickListener(this); | |
| 71 | + } | |
| 72 | + | |
| 73 | + @Override | |
| 74 | + public void onClick(View v) { | |
| 75 | + if(mRecyclerViewOnClickListenerHack != null){ | |
| 76 | + mRecyclerViewOnClickListenerHack.onClickListener(v, getPosition()); | |
| 77 | + } | |
| 78 | + } | |
| 79 | + } | |
| 80 | + | |
| 81 | + public ProjetoAdapter(List<ParseObject> myDataset, FragmentActivity activity) { | |
| 82 | + mDataset = myDataset; | |
| 83 | + mActivity = activity; | |
| 84 | + } | |
| 85 | + | |
| 86 | + @Override | |
| 87 | + public ProjetoAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { | |
| 88 | + // create a new view | |
| 89 | + View v = LayoutInflater.from(viewGroup.getContext()) | |
| 90 | + .inflate(R.layout.item_projeto, viewGroup, false); | |
| 91 | + // set the view's size, margins, paddings and layout parameter | |
| 92 | + ViewHolder vh = new ViewHolder(v); | |
| 93 | + return vh; | |
| 94 | + } | |
| 95 | + | |
| 96 | + @Override | |
| 97 | + public void onBindViewHolder(final ViewHolder viewHolder, int i) { | |
| 98 | + Drawable apoio = ContextCompat.getDrawable(MyApp.getInstance().getApplicationContext(), R.mipmap.ic_action_like_gray); | |
| 99 | + Drawable napoio = ContextCompat.getDrawable(MyApp.getInstance().getApplicationContext(), R.mipmap.ic_action_unlike_gray); | |
| 100 | + final Drawable napoioVermelho = ContextCompat.getDrawable(MyApp.getInstance().getApplicationContext(), R.mipmap.ic_action_unlike_red); | |
| 101 | + final Drawable apoioVerde = ContextCompat.getDrawable(MyApp.getInstance().getApplicationContext(), R.mipmap.ic_action_like_green); | |
| 102 | + | |
| 103 | + viewHolder.btnConcordo.setBackground(apoio); | |
| 104 | + viewHolder.btnDiscordo.setBackground(napoio); | |
| 105 | + | |
| 106 | + viewHolder.btnDiscordo.setEnabled(true); | |
| 107 | + viewHolder.btnConcordo.setEnabled(true); | |
| 108 | + viewHolder.voto = "sem_voto"; | |
| 109 | + final ParseObject projeto = mDataset.get(i); | |
| 110 | + viewHolder.projeto = projeto; | |
| 111 | + //verifica se ja votou | |
| 112 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("Voto"); | |
| 113 | + query.fromLocalDatastore(); | |
| 114 | + query.whereEqualTo("projeto", projeto); | |
| 115 | + query.findInBackground(new FindCallback<ParseObject>() { | |
| 116 | + @Override | |
| 117 | + public void done(List<ParseObject> list, ParseException e) { | |
| 118 | + if (list.size() > 0) { | |
| 119 | + String voto = list.get(0).get("voto").toString(); | |
| 120 | + viewHolder.projetoVotado = list.get(0); | |
| 121 | + if (voto.equals("s")) { | |
| 122 | + viewHolder.btnConcordo.setBackground(apoioVerde); | |
| 123 | + viewHolder.btnConcordo.setEnabled(false); | |
| 124 | + viewHolder.voto = "apoioado"; | |
| 125 | + ; | |
| 126 | + } else { | |
| 127 | + viewHolder.btnDiscordo.setBackground(napoioVermelho); | |
| 128 | + viewHolder.btnDiscordo.setEnabled(false); | |
| 129 | + viewHolder.voto = "nao_apoioado"; | |
| 130 | + } | |
| 131 | + } | |
| 132 | + } | |
| 133 | + }); | |
| 134 | + | |
| 135 | + viewHolder.numero.setText("ID: "+projeto.getString("numero")); | |
| 136 | + viewHolder.classificacao.setText(projeto.get("classificacao").toString()); | |
| 137 | + viewHolder.data.setText(projeto.get("data").toString()); | |
| 138 | + viewHolder.descricao.setText(projeto.get("descricao").toString()); | |
| 139 | + int numComentario = 0; | |
| 140 | + if(projeto.get("nr_comentarios") != null){ | |
| 141 | + numComentario = Integer.valueOf( projeto.get("nr_comentarios").toString()); | |
| 142 | + } | |
| 143 | + viewHolder.btnComentar.setText(String.valueOf(numComentario)); | |
| 144 | + int num=0; | |
| 145 | + if(projeto.get("apoio") != null){ | |
| 146 | + num = Integer.valueOf( projeto.get("apoio").toString()); | |
| 147 | + } | |
| 148 | + | |
| 149 | + viewHolder.numApoio.setText(String.valueOf(num)); | |
| 150 | + num=0; | |
| 151 | + if(projeto.get("nao_apoio") != null){ | |
| 152 | + num = Integer.valueOf( projeto.get("nao_apoio").toString()); | |
| 153 | + } | |
| 154 | + viewHolder.numNaoApoio.setText(String.valueOf(num)); | |
| 155 | + ParseObject autor = (ParseObject) projeto.get("politico"); | |
| 156 | + try { | |
| 157 | + autor.fetchFromLocalDatastore(); | |
| 158 | + viewHolder.autor.setText(autor.get("nome").toString()); | |
| 159 | + } catch (ParseException e) { | |
| 160 | + e.printStackTrace(); | |
| 161 | + } | |
| 162 | + | |
| 163 | + viewHolder.btnConcordo.setOnClickListener(new View.OnClickListener() { | |
| 164 | + @Override | |
| 165 | + public void onClick(final View v) { | |
| 166 | + registraVoto(v, projeto, "s", viewHolder); | |
| 167 | + | |
| 168 | + } | |
| 169 | + }); | |
| 170 | + | |
| 171 | + viewHolder.btnDiscordo.setOnClickListener(new View.OnClickListener() { | |
| 172 | + @Override | |
| 173 | + public void onClick(View v) { | |
| 174 | + registraVoto(v, projeto, "n", viewHolder); | |
| 175 | + } | |
| 176 | + }); | |
| 177 | + | |
| 178 | + viewHolder.btnComentar.setOnClickListener(new View.OnClickListener() { | |
| 179 | + @Override | |
| 180 | + public void onClick(View v) { | |
| 181 | + Intent mIntent =new Intent(MyApp.getInstance().getApplicationContext(), ComentarioActivity.class); | |
| 182 | + Gson gson = new Gson(); | |
| 183 | + mIntent.putExtra("projeto",viewHolder.projeto.getObjectId()); | |
| 184 | + | |
| 185 | + mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
| 186 | + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ | |
| 187 | + View titulo = viewHolder.descricao; | |
| 188 | + ActivityOptionsCompat options = ActivityOptionsCompat. | |
| 189 | + makeSceneTransitionAnimation(mActivity, | |
| 190 | + Pair.create(titulo, "element1")); | |
| 191 | + mActivity.startActivity(mIntent, options.toBundle()); | |
| 192 | + }else{ | |
| 193 | + MyApp.getInstance().startActivity(mIntent); | |
| 194 | + } | |
| 195 | + | |
| 196 | + | |
| 197 | + } | |
| 198 | + }); | |
| 199 | + } | |
| 200 | + | |
| 201 | + private void registraVoto(final View v, ParseObject projeto, final String tipoVoto, final ViewHolder viewHolder2) { | |
| 202 | + | |
| 203 | + //verificar se esta logado | |
| 204 | + if(ParseUser.getCurrentUser() == null){ | |
| 205 | + Snackbar.make(v, "Para votar é necessário estar logado", Snackbar.LENGTH_LONG) | |
| 206 | + .setAction("Action", null).show(); | |
| 207 | + return; | |
| 208 | + } | |
| 209 | + | |
| 210 | + Drawable apoio = ContextCompat.getDrawable(MyApp.getInstance().getApplicationContext(), R.mipmap.ic_action_like_gray); | |
| 211 | + Drawable napoio = ContextCompat.getDrawable(MyApp.getInstance().getApplicationContext(), R.mipmap.ic_action_unlike_gray); | |
| 212 | + final Drawable napoioVermelho = ContextCompat.getDrawable(MyApp.getInstance().getApplicationContext(), R.mipmap.ic_action_unlike_red); | |
| 213 | + final Drawable apoioVerde = ContextCompat.getDrawable(MyApp.getInstance().getApplicationContext(), R.mipmap.ic_action_like_green); | |
| 214 | + | |
| 215 | + //verificar se ja votou nesse projeto | |
| 216 | + boolean votado; | |
| 217 | + if(viewHolder2.voto.equals("sem_voto")){ | |
| 218 | + | |
| 219 | + votado = false; | |
| 220 | + }else{ | |
| 221 | + votado=true; | |
| 222 | + | |
| 223 | + } | |
| 224 | + if(votado){ | |
| 225 | + | |
| 226 | + if(null!= viewHolder2.projetoVotado){ | |
| 227 | + viewHolder2.projetoVotado.unpinInBackground(); | |
| 228 | + viewHolder2.projetoVotado.deleteInBackground(); | |
| 229 | + } | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + } | |
| 234 | + | |
| 235 | + ParseObject voto = new ParseObject("Voto"); | |
| 236 | + voto.put("projeto", projeto); | |
| 237 | + voto.put("user", ParseUser.getCurrentUser()); | |
| 238 | + voto.put("voto", tipoVoto); | |
| 239 | + Button btnVoto = (Button) v; | |
| 240 | + if(tipoVoto.equals("s")){ | |
| 241 | + if(votado){ | |
| 242 | + viewHolder2.numNaoApoio.setText(String.valueOf(Integer.valueOf(viewHolder2.numNaoApoio.getText().toString()) - 1)); | |
| 243 | + projeto.increment("nao_apoio", -1); | |
| 244 | + } | |
| 245 | + viewHolder2.numApoio.setText(String.valueOf(Integer.valueOf(viewHolder2.numApoio.getText().toString()) + 1)); | |
| 246 | + projeto.increment("apoio"); | |
| 247 | + btnVoto.setBackground(apoioVerde); | |
| 248 | + viewHolder2.btnDiscordo.setBackground(napoio); | |
| 249 | + viewHolder2.voto = "apoiado"; | |
| 250 | + viewHolder2.btnConcordo.setEnabled(false); | |
| 251 | + viewHolder2.btnDiscordo.setEnabled(true); | |
| 252 | + | |
| 253 | + }else{ | |
| 254 | + if(votado){ | |
| 255 | + viewHolder2.numApoio.setText(String.valueOf(Integer.valueOf(viewHolder2.numApoio.getText().toString()) - 1)); | |
| 256 | + projeto.increment("apoio", -1); | |
| 257 | + } | |
| 258 | + projeto.increment("nao_apoio"); | |
| 259 | + viewHolder2.numNaoApoio.setText(String.valueOf(Integer.valueOf(viewHolder2.numNaoApoio.getText().toString()) + 1)); | |
| 260 | + btnVoto.setBackground(napoioVermelho); | |
| 261 | + viewHolder2.btnConcordo.setBackground(apoio); | |
| 262 | + viewHolder2.voto = "nao_apoiado"; | |
| 263 | + viewHolder2.btnDiscordo.setEnabled(false); | |
| 264 | + viewHolder2.btnConcordo.setEnabled(true); | |
| 265 | + | |
| 266 | + } | |
| 267 | + projeto.saveInBackground(); | |
| 268 | + | |
| 269 | + try { | |
| 270 | + voto.pin(); | |
| 271 | + voto.saveInBackground(new SaveCallback() { | |
| 272 | + @Override | |
| 273 | + public void done(ParseException e) { | |
| 274 | + Snackbar.make(v, "Voto registrado", Snackbar.LENGTH_SHORT) | |
| 275 | + .setAction("Action", null).show(); | |
| 276 | + } | |
| 277 | + }); | |
| 278 | + } catch (ParseException e) { | |
| 279 | + e.printStackTrace(); | |
| 280 | + } | |
| 281 | + } | |
| 282 | + | |
| 283 | + public void setRecyclerViewOnClickListenerHack(RecyclerViewOnClickListenerHack r){ | |
| 284 | + mRecyclerViewOnClickListenerHack = r; | |
| 285 | + } | |
| 286 | + | |
| 287 | + @Override | |
| 288 | + public int getItemCount() { | |
| 289 | + return mDataset.size(); | |
| 290 | + } | |
| 291 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/adapters/TipoProjetoAdapter.java
0 → 100644
| ... | ... | @@ -0,0 +1,92 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view.adapters; | |
| 2 | + | |
| 3 | +import android.support.v4.app.FragmentActivity; | |
| 4 | +import android.support.v7.widget.RecyclerView; | |
| 5 | +import android.view.LayoutInflater; | |
| 6 | +import android.view.View; | |
| 7 | +import android.view.ViewGroup; | |
| 8 | +import android.widget.TextView; | |
| 9 | + | |
| 10 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 11 | +import com.monitorabrasil.monitoralegislativo.view.interfaces.RecyclerViewOnClickListenerHack; | |
| 12 | +import com.parse.ParseObject; | |
| 13 | + | |
| 14 | +import java.util.List; | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * Created by geral_000 on 23/07/2015. | |
| 18 | + */ | |
| 19 | +public class TipoProjetoAdapter extends RecyclerView.Adapter<TipoProjetoAdapter.ViewHolder> { | |
| 20 | + | |
| 21 | + private List<ParseObject> mDataset; | |
| 22 | + private RecyclerViewOnClickListenerHack mRecyclerViewOnClickListenerHack; | |
| 23 | + private FragmentActivity mActivity; | |
| 24 | + int[] cores = new int[]{R.color.cor1, R.color.cor2,R.color.cor3, R.color.cor4,R.color.cor5, R.color.cor6, | |
| 25 | + R.color.cor7, R.color.cor8,R.color.cor9, R.color.cor10}; | |
| 26 | + | |
| 27 | + public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ | |
| 28 | + // each data item is just a string in this case | |
| 29 | + | |
| 30 | + public TextView txtTipoProjeto; | |
| 31 | + public ParseObject tipoProjeto; | |
| 32 | + | |
| 33 | + public ViewHolder(View v) { | |
| 34 | + super(v); | |
| 35 | + txtTipoProjeto = (TextView) v.findViewById(R.id.txtTipoProjeto); | |
| 36 | + itemView.setOnClickListener(this); | |
| 37 | + } | |
| 38 | + | |
| 39 | + @Override | |
| 40 | + public void onClick(View v) { | |
| 41 | + if(mRecyclerViewOnClickListenerHack != null){ | |
| 42 | + mRecyclerViewOnClickListenerHack.onClickListener(v, getPosition()); | |
| 43 | + } | |
| 44 | + } | |
| 45 | + } | |
| 46 | + | |
| 47 | + public TipoProjetoAdapter(List<ParseObject> myDataset, FragmentActivity activity) { | |
| 48 | + mDataset = myDataset; | |
| 49 | + mActivity = activity; | |
| 50 | + } | |
| 51 | + | |
| 52 | + @Override | |
| 53 | + public TipoProjetoAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { | |
| 54 | + // create a new view | |
| 55 | + View v = LayoutInflater.from(viewGroup.getContext()) | |
| 56 | + .inflate(R.layout.item_tipo_projeto, viewGroup, false); | |
| 57 | + // set the view's size, margins, paddings and layout parameter | |
| 58 | + ViewHolder vh = new ViewHolder(v); | |
| 59 | + return vh; | |
| 60 | + } | |
| 61 | + | |
| 62 | + @Override | |
| 63 | + public void onBindViewHolder(final ViewHolder viewHolder, int i) { | |
| 64 | + | |
| 65 | + final ParseObject tipoProjeto = mDataset.get(i); | |
| 66 | + viewHolder.tipoProjeto = tipoProjeto; | |
| 67 | + | |
| 68 | + viewHolder.txtTipoProjeto.setText(tipoProjeto.getString("nome")); | |
| 69 | + int posCor=i; | |
| 70 | + if(i > 19) | |
| 71 | + posCor = i-20; | |
| 72 | + else | |
| 73 | + if(i > 9) | |
| 74 | + posCor = i-10; | |
| 75 | + | |
| 76 | + viewHolder.txtTipoProjeto.setBackgroundResource(cores[posCor]); | |
| 77 | + } | |
| 78 | + | |
| 79 | + | |
| 80 | + public void setRecyclerViewOnClickListenerHack(RecyclerViewOnClickListenerHack r){ | |
| 81 | + mRecyclerViewOnClickListenerHack = r; | |
| 82 | + } | |
| 83 | + | |
| 84 | + @Override | |
| 85 | + public int getItemCount() { | |
| 86 | + return mDataset.size(); | |
| 87 | + } | |
| 88 | + | |
| 89 | + public String getItem(int i){ | |
| 90 | + return mDataset.get(i).getString("nome"); | |
| 91 | + } | |
| 92 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/adapters/VereadorAdapter.java
0 → 100644
| ... | ... | @@ -0,0 +1,85 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.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.monitoralegislativo.R; | |
| 12 | +import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 13 | +import com.monitorabrasil.monitoralegislativo.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/monitoralegislativo/view/dialogs/DialogAvaliacao.java
0 → 100644
| ... | ... | @@ -0,0 +1,161 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view.dialogs; | |
| 2 | + | |
| 3 | +import android.annotation.SuppressLint; | |
| 4 | +import android.app.Dialog; | |
| 5 | +import android.app.DialogFragment; | |
| 6 | +import android.content.DialogInterface; | |
| 7 | +import android.os.Bundle; | |
| 8 | +import android.view.LayoutInflater; | |
| 9 | +import android.view.View; | |
| 10 | +import android.view.View.OnClickListener; | |
| 11 | +import android.view.ViewGroup; | |
| 12 | +import android.widget.Button; | |
| 13 | +import android.widget.RatingBar; | |
| 14 | + | |
| 15 | + | |
| 16 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 17 | +import com.parse.ParseException; | |
| 18 | +import com.parse.ParseObject; | |
| 19 | +import com.parse.ParseQuery; | |
| 20 | +import com.parse.ParseUser; | |
| 21 | +import com.parse.SaveCallback; | |
| 22 | + | |
| 23 | +@SuppressLint("ValidFragment") | |
| 24 | +public class DialogAvaliacao extends DialogFragment { | |
| 25 | + | |
| 26 | + int idUser; | |
| 27 | + int idPolitico; | |
| 28 | + private String titulo; | |
| 29 | + private ParseObject mPolitico; | |
| 30 | + private ParseObject mAvaliacao; | |
| 31 | + | |
| 32 | + private DialogInterface.OnDismissListener onDismissListener; | |
| 33 | + | |
| 34 | + private boolean jaVotou; | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + public DialogAvaliacao(ParseObject politico, String titulo) { | |
| 39 | + this.titulo=titulo; | |
| 40 | + this.mPolitico = politico; | |
| 41 | + } | |
| 42 | + | |
| 43 | + @Override | |
| 44 | + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
| 45 | + final View view = inflater.inflate(R.layout.dialog_avaliacao, container, false); | |
| 46 | + | |
| 47 | + final RatingBar rb = (RatingBar) view.findViewById(R.id.ratingBar1); | |
| 48 | + | |
| 49 | + jaVotou = false; | |
| 50 | + | |
| 51 | + // setar avaliacao feita | |
| 52 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("Avaliacao"); | |
| 53 | + query.fromLocalDatastore(); | |
| 54 | + try { | |
| 55 | + query.whereEqualTo("politico", mPolitico); | |
| 56 | + mAvaliacao = query.getFirst(); | |
| 57 | + if(mAvaliacao != null){ | |
| 58 | + jaVotou = true; | |
| 59 | + rb.setRating((float)mAvaliacao.getDouble("avaliacao")); | |
| 60 | + } | |
| 61 | + } catch (Exception e) { | |
| 62 | + e.printStackTrace(); | |
| 63 | + } | |
| 64 | + | |
| 65 | + //rb.setRating(new UserDAO(getActivity()).buscaAvaliacaoSalva(idPolitico)); | |
| 66 | + | |
| 67 | + Button btnCancelar = (Button) view.findViewById(R.id.cancel); | |
| 68 | + btnCancelar.setOnClickListener(new OnClickListener() { | |
| 69 | + | |
| 70 | + @Override | |
| 71 | + public void onClick(View v) { | |
| 72 | + getDialog().dismiss(); | |
| 73 | + | |
| 74 | + } | |
| 75 | + }); | |
| 76 | + | |
| 77 | + Button btnOk = (Button) view.findViewById(R.id.ok); | |
| 78 | + btnOk.setOnClickListener(new OnClickListener() { | |
| 79 | + | |
| 80 | + @Override | |
| 81 | + public void onClick(final View v) { | |
| 82 | + if(ParseUser.getCurrentUser()!= null){ | |
| 83 | + double ultimaAvaliacao=0; | |
| 84 | + //salva a avaliacao | |
| 85 | + if(!jaVotou){ | |
| 86 | + mAvaliacao = new ParseObject("Avaliacao"); | |
| 87 | + mAvaliacao.put("politico",mPolitico); | |
| 88 | + mAvaliacao.put("user", ParseUser.getCurrentUser()); | |
| 89 | + }else{ | |
| 90 | + //guardar a ultima valor da avaliacao anterior | |
| 91 | + ultimaAvaliacao = mAvaliacao.getDouble("avaliacao"); | |
| 92 | + } | |
| 93 | + | |
| 94 | + mAvaliacao.put("avaliacao", rb.getRating()); | |
| 95 | + mAvaliacao.saveInBackground(new SaveCallback() { | |
| 96 | + @Override | |
| 97 | + public void done(ParseException e) { | |
| 98 | + | |
| 99 | + } | |
| 100 | + }); | |
| 101 | + mAvaliacao.pinInBackground(); | |
| 102 | + try { | |
| 103 | + mPolitico.fetchFromLocalDatastore(); | |
| 104 | + } catch (ParseException e) { | |
| 105 | + e.printStackTrace(); | |
| 106 | + } | |
| 107 | + int nrAvalicao = mPolitico.getInt("qtd_avaliacao"); | |
| 108 | + double media = mPolitico.getDouble("avaliacao"); | |
| 109 | + double total = nrAvalicao*media; | |
| 110 | + if(jaVotou){ | |
| 111 | + total = total - ultimaAvaliacao; | |
| 112 | + }else{ | |
| 113 | + nrAvalicao++; | |
| 114 | + mPolitico.increment("qtd_avaliacao"); | |
| 115 | + } | |
| 116 | + | |
| 117 | + mPolitico.put("avaliacao", (rb.getRating() + total) / nrAvalicao); | |
| 118 | + | |
| 119 | + mPolitico.saveInBackground(); | |
| 120 | + mPolitico.pinInBackground(); | |
| 121 | + } | |
| 122 | + | |
| 123 | + getDialog().dismiss(); | |
| 124 | + } | |
| 125 | + }); | |
| 126 | + return view; | |
| 127 | + } | |
| 128 | + | |
| 129 | + @Override | |
| 130 | + public Dialog onCreateDialog(Bundle savedInstanceState) { | |
| 131 | + | |
| 132 | + Dialog dialog = super.onCreateDialog(savedInstanceState); | |
| 133 | + // dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); | |
| 134 | + dialog.setTitle(titulo); | |
| 135 | + | |
| 136 | + // WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); | |
| 137 | + // lp.copyFrom(dialog.getWindow().getAttributes()); | |
| 138 | + // lp.width = WindowManager.LayoutParams.MATCH_PARENT-20; | |
| 139 | + // dialog.show(); | |
| 140 | + // dialog.getWindow().setAttributes(lp); | |
| 141 | + | |
| 142 | + return dialog; | |
| 143 | + } | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) { | |
| 148 | + this.onDismissListener = onDismissListener; | |
| 149 | + } | |
| 150 | + | |
| 151 | + @Override | |
| 152 | + public void onDismiss(DialogInterface dialog) { | |
| 153 | + super.onDismiss(dialog); | |
| 154 | + if (onDismissListener != null) { | |
| 155 | + onDismissListener.onDismiss(dialog); | |
| 156 | + } | |
| 157 | + } | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | +} | |
| 0 | 162 | \ No newline at end of file | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/fragments/EscolhaTipoProjeto.java
0 → 100644
| ... | ... | @@ -0,0 +1,164 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view.fragments; | |
| 2 | + | |
| 3 | +import android.net.Uri; | |
| 4 | +import android.os.Bundle; | |
| 5 | +import android.support.v4.app.Fragment; | |
| 6 | +import android.support.v4.app.FragmentTransaction; | |
| 7 | +import android.support.v7.widget.GridLayoutManager; | |
| 8 | +import android.support.v7.widget.RecyclerView; | |
| 9 | +import android.util.Log; | |
| 10 | +import android.view.LayoutInflater; | |
| 11 | +import android.view.View; | |
| 12 | +import android.view.ViewGroup; | |
| 13 | + | |
| 14 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 15 | +import com.monitorabrasil.monitoralegislativo.view.adapters.TipoProjetoAdapter; | |
| 16 | +import com.monitorabrasil.monitoralegislativo.view.interfaces.RecyclerViewOnClickListenerHack; | |
| 17 | +import com.parse.FindCallback; | |
| 18 | +import com.parse.ParseObject; | |
| 19 | +import com.parse.ParseQuery; | |
| 20 | + | |
| 21 | +import java.util.List; | |
| 22 | + | |
| 23 | +/** | |
| 24 | + * A simple {@link Fragment} subclass. | |
| 25 | + * Activities that contain this fragment must implement the | |
| 26 | + * {@link EscolhaTipoProjeto.OnFragmentInteractionListener} interface | |
| 27 | + * to handle interaction events. | |
| 28 | + * Use the {@link EscolhaTipoProjeto#newInstance} factory method to | |
| 29 | + * create an instance of this fragment. | |
| 30 | + */ | |
| 31 | +public class EscolhaTipoProjeto extends Fragment implements RecyclerViewOnClickListenerHack { | |
| 32 | + // TODO: Rename parameter arguments, choose names that match | |
| 33 | + // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER | |
| 34 | + private static final String ARG_PARAM1 = "param1"; | |
| 35 | + private static final String ARG_PARAM2 = "param2"; | |
| 36 | + private RecyclerView mRecyclerView; | |
| 37 | + private TipoProjetoAdapter mAdapter; | |
| 38 | + | |
| 39 | + // TODO: Rename and change types of parameters | |
| 40 | + private String mParam1; | |
| 41 | + private String mParam2; | |
| 42 | + | |
| 43 | + private OnFragmentInteractionListener mListener; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * Use this factory method to create a new instance of | |
| 47 | + * this fragment using the provided parameters. | |
| 48 | + * | |
| 49 | + * @param param1 Parameter 1. | |
| 50 | + * @param param2 Parameter 2. | |
| 51 | + * @return A new instance of fragment EscolhaTipoProjeto. | |
| 52 | + */ | |
| 53 | + // TODO: Rename and change types and number of parameters | |
| 54 | + public static EscolhaTipoProjeto newInstance(String param1, String param2) { | |
| 55 | + EscolhaTipoProjeto fragment = new EscolhaTipoProjeto(); | |
| 56 | + Bundle args = new Bundle(); | |
| 57 | + args.putString(ARG_PARAM1, param1); | |
| 58 | + args.putString(ARG_PARAM2, param2); | |
| 59 | + fragment.setArguments(args); | |
| 60 | + return fragment; | |
| 61 | + } | |
| 62 | + | |
| 63 | + public EscolhaTipoProjeto() { | |
| 64 | + // Required empty public constructor | |
| 65 | + } | |
| 66 | + | |
| 67 | + @Override | |
| 68 | + public void onCreate(Bundle savedInstanceState) { | |
| 69 | + super.onCreate(savedInstanceState); | |
| 70 | + if (getArguments() != null) { | |
| 71 | + mParam1 = getArguments().getString(ARG_PARAM1); | |
| 72 | + mParam2 = getArguments().getString(ARG_PARAM2); | |
| 73 | + } | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Override | |
| 77 | + public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
| 78 | + Bundle savedInstanceState) { | |
| 79 | + View view = inflater.inflate(R.layout.fragment_escolha_tipo_projeto, container, false); | |
| 80 | + | |
| 81 | + //tableview | |
| 82 | + mRecyclerView = (RecyclerView) view.findViewById(R.id.rv_escolha_tipo); | |
| 83 | + | |
| 84 | + // use this setting to improve performance if you know that changes | |
| 85 | + // in content do not change the layout size of the RecyclerView | |
| 86 | + mRecyclerView.setHasFixedSize(true); | |
| 87 | + | |
| 88 | + GridLayoutManager llm = new GridLayoutManager(getActivity(),2,GridLayoutManager.VERTICAL, false); | |
| 89 | + mRecyclerView.setLayoutManager(llm); | |
| 90 | + | |
| 91 | + //busca os tipos de projetos | |
| 92 | + buscaTiposProjetos(); | |
| 93 | + | |
| 94 | + return view; | |
| 95 | + } | |
| 96 | + | |
| 97 | + private void buscaTiposProjetos() { | |
| 98 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("TipoProjeto"); | |
| 99 | + query.addAscendingOrder("nome"); | |
| 100 | + query.findInBackground(new FindCallback<ParseObject>() { | |
| 101 | + @Override | |
| 102 | + public void done(List<ParseObject> list, com.parse.ParseException e) { | |
| 103 | + if (e == null) { | |
| 104 | + carregaList(list); | |
| 105 | + } else { | |
| 106 | + Log.d("score", "Error: " + e.getMessage()); | |
| 107 | + } | |
| 108 | + } | |
| 109 | + | |
| 110 | + | |
| 111 | + }); | |
| 112 | + } | |
| 113 | + | |
| 114 | + private void carregaList(List<ParseObject> list) { | |
| 115 | + mAdapter = new TipoProjetoAdapter(list,getActivity()); | |
| 116 | + mAdapter.setRecyclerViewOnClickListenerHack(this); | |
| 117 | + mRecyclerView.setAdapter(mAdapter); | |
| 118 | + //pb.setVisibility(View.INVISIBLE); | |
| 119 | + } | |
| 120 | + | |
| 121 | + @Override | |
| 122 | + public void onClickListener(View view, int position) { | |
| 123 | + ListaProjetosFragment frag = (ListaProjetosFragment) getActivity().getSupportFragmentManager().findFragmentByTag("listaProjFrag"); | |
| 124 | + if(frag == null) { | |
| 125 | + frag = ListaProjetosFragment.newInstance(mAdapter.getItem(position),null); | |
| 126 | + FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); | |
| 127 | + ft.replace(R.id.rl_fragment_container, frag, "listaProjFrag"); | |
| 128 | + ft.addToBackStack(null); | |
| 129 | + ft.commit(); | |
| 130 | + } | |
| 131 | + | |
| 132 | + } | |
| 133 | + | |
| 134 | + // TODO: Rename method, update argument and hook method into UI event | |
| 135 | + public void onButtonPressed(Uri uri) { | |
| 136 | + if (mListener != null) { | |
| 137 | + mListener.onFragmentInteraction(uri); | |
| 138 | + } | |
| 139 | + } | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + @Override | |
| 144 | + public void onDetach() { | |
| 145 | + super.onDetach(); | |
| 146 | + mListener = null; | |
| 147 | + } | |
| 148 | + | |
| 149 | + /** | |
| 150 | + * This interface must be implemented by activities that contain this | |
| 151 | + * fragment to allow an interaction in this fragment to be communicated | |
| 152 | + * to the activity and potentially other fragments contained in that | |
| 153 | + * activity. | |
| 154 | + * <p/> | |
| 155 | + * See the Android Training lesson <a href= | |
| 156 | + * "http://developer.android.com/training/basics/fragments/communicating.html" | |
| 157 | + * >Communicating with Other Fragments</a> for more information. | |
| 158 | + */ | |
| 159 | + public interface OnFragmentInteractionListener { | |
| 160 | + // TODO: Update argument type and name | |
| 161 | + public void onFragmentInteraction(Uri uri); | |
| 162 | + } | |
| 163 | + | |
| 164 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/fragments/GastosCamaraFragment.java
0 → 100644
| ... | ... | @@ -0,0 +1,311 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view.fragments; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.net.Uri; | |
| 5 | +import android.os.Bundle; | |
| 6 | +import android.support.v4.app.Fragment; | |
| 7 | +import android.support.v7.widget.LinearLayoutManager; | |
| 8 | +import android.support.v7.widget.RecyclerView; | |
| 9 | +import android.view.LayoutInflater; | |
| 10 | +import android.view.View; | |
| 11 | +import android.view.ViewGroup; | |
| 12 | +import android.widget.ProgressBar; | |
| 13 | + | |
| 14 | +import com.github.mikephil.charting.charts.BarChart; | |
| 15 | +import com.github.mikephil.charting.data.BarEntry; | |
| 16 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 17 | +import com.monitorabrasil.monitoralegislativo.view.adapters.GastoAdapter; | |
| 18 | +import com.monitorabrasil.monitoralegislativo.model.Grafico; | |
| 19 | +import com.parse.FindCallback; | |
| 20 | +import com.parse.ParseException; | |
| 21 | +import com.parse.ParseObject; | |
| 22 | +import com.parse.ParseQuery; | |
| 23 | + | |
| 24 | +import java.util.ArrayList; | |
| 25 | +import java.util.HashMap; | |
| 26 | +import java.util.Iterator; | |
| 27 | +import java.util.List; | |
| 28 | + | |
| 29 | +/** | |
| 30 | + * A simple {@link Fragment} subclass. | |
| 31 | + * Activities that contain this fragment must implement the | |
| 32 | + * {@link GastosCamaraFragment.OnFragmentInteractionListener} interface | |
| 33 | + * to handle interaction events. | |
| 34 | + * Use the {@link GastosCamaraFragment#newInstance} factory method to | |
| 35 | + * create an instance of this fragment. | |
| 36 | + */ | |
| 37 | +public class GastosCamaraFragment extends Fragment { | |
| 38 | + | |
| 39 | + | |
| 40 | + protected BarChart mChart; | |
| 41 | + private View mView; | |
| 42 | + private HashMap<String,HashMap<String,Float>> dataset = new HashMap<String,HashMap<String,Float>>(); | |
| 43 | + private HashMap<String,Float> valorTotal = new HashMap<String,Float>(); | |
| 44 | + ArrayList<String> xVals = new ArrayList<String>(); | |
| 45 | + ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>(); | |
| 46 | + private RecyclerView mRecyclerView; | |
| 47 | + private GastoAdapter mAdapter; | |
| 48 | + List<Grafico> myDataset=new ArrayList<Grafico>(); | |
| 49 | + List<String> tipos = new ArrayList<String>(); | |
| 50 | + int[] cores = new int[]{R.color.cor1, R.color.cor2,R.color.cor3, R.color.cor4,R.color.cor5, R.color.cor6, | |
| 51 | + R.color.cor7, R.color.cor8,R.color.cor9, R.color.cor10}; | |
| 52 | + | |
| 53 | + private ProgressBar pb; | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + private OnFragmentInteractionListener mListener; | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * Use this factory method to create a new instance of | |
| 61 | + * this fragment using the provided parameters. | |
| 62 | + * | |
| 63 | + * @param param1 Parameter 1. | |
| 64 | + * @param param2 Parameter 2. | |
| 65 | + * @return A new instance of fragment GastosCamaraFragment. | |
| 66 | + */ | |
| 67 | + // TODO: Rename and change types and number of parameters | |
| 68 | + public static GastosCamaraFragment newInstance(String param1, String param2) { | |
| 69 | + GastosCamaraFragment fragment = new GastosCamaraFragment(); | |
| 70 | + Bundle args = new Bundle(); | |
| 71 | +// args.putString(ARG_PARAM1, param1); | |
| 72 | +// args.putString(ARG_PARAM2, param2); | |
| 73 | + fragment.setArguments(args); | |
| 74 | + return fragment; | |
| 75 | + } | |
| 76 | + | |
| 77 | + public GastosCamaraFragment() { | |
| 78 | + // Required empty public constructor | |
| 79 | + } | |
| 80 | + | |
| 81 | + @Override | |
| 82 | + public void onCreate(Bundle savedInstanceState) { | |
| 83 | + super.onCreate(savedInstanceState); | |
| 84 | + if (getArguments() != null) { | |
| 85 | +// mParam1 = getArguments().getString(ARG_PARAM1); | |
| 86 | +// mParam2 = getArguments().getString(ARG_PARAM2); | |
| 87 | + } | |
| 88 | + } | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + @Override | |
| 93 | + public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
| 94 | + Bundle savedInstanceState) { | |
| 95 | + // Inflate the layout for this fragment | |
| 96 | + View view =inflater.inflate(R.layout.fragment_lista_projetos, container, false); | |
| 97 | + pb = (ProgressBar) view.findViewById(R.id.progressBar); | |
| 98 | +// pb.setVisibility(View.VISIBLE); | |
| 99 | + mView=view; | |
| 100 | +// mChart = (BarChart) view.findViewById(R.id.chart1); | |
| 101 | +// mChart.setVisibility(View.GONE); | |
| 102 | +// buildGraph(); | |
| 103 | + | |
| 104 | + //tableview | |
| 105 | + mRecyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view); | |
| 106 | + | |
| 107 | + // use this setting to improve performance if you know that changes | |
| 108 | + // in content do not change the layout size of the RecyclerView | |
| 109 | + mRecyclerView.setHasFixedSize(true); | |
| 110 | + | |
| 111 | + LinearLayoutManager llm = new LinearLayoutManager(getActivity()); | |
| 112 | + llm.setOrientation(LinearLayoutManager.VERTICAL); | |
| 113 | + mRecyclerView.setLayoutManager(llm); | |
| 114 | + buscaGastos(); | |
| 115 | + return view; | |
| 116 | + } | |
| 117 | + | |
| 118 | + private ParseObject buscaGastos() { | |
| 119 | + | |
| 120 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("DespesaCamara"); | |
| 121 | + query.setLimit(200); | |
| 122 | + //query.whereEqualTo("politico",politico); | |
| 123 | + | |
| 124 | + query.addAscendingOrder("mes_numero"); | |
| 125 | + query.findInBackground(new FindCallback<ParseObject>() { | |
| 126 | + public void done(List<ParseObject> gastos, ParseException e) { | |
| 127 | + | |
| 128 | + Iterator<ParseObject> gastoIt = gastos.iterator(); | |
| 129 | + | |
| 130 | + while (gastoIt.hasNext()) { | |
| 131 | + | |
| 132 | + ParseObject g = gastoIt.next(); | |
| 133 | + String mes = g.getString("mes"); | |
| 134 | + Float novoValor = Float.valueOf(g.getString("valor")); | |
| 135 | + | |
| 136 | + String tipo = g.getString("tipo"); | |
| 137 | + if(!tipos.contains(tipo)){ | |
| 138 | + tipos.add(tipo); | |
| 139 | + } | |
| 140 | + //verifica tipo | |
| 141 | + HashMap<String,Float> data = dataset.get(tipo); | |
| 142 | + if(data != null){ | |
| 143 | + //verifica se tem o valor por mes | |
| 144 | + Float valorMesTipo = data.get(mes); | |
| 145 | + if(valorMesTipo != null){ | |
| 146 | + valorMesTipo = valorMesTipo +novoValor; | |
| 147 | + data.remove(mes); | |
| 148 | + data.put(mes, valorMesTipo); | |
| 149 | + }else{ | |
| 150 | + data.put(mes,novoValor); | |
| 151 | + } | |
| 152 | + | |
| 153 | + | |
| 154 | + }else{ | |
| 155 | + data = new HashMap<String, Float>(); | |
| 156 | + data.put(mes,novoValor); | |
| 157 | + dataset.put(tipo,data); | |
| 158 | + } | |
| 159 | + | |
| 160 | + | |
| 161 | + Float valor = valorTotal.get(mes); | |
| 162 | + if (valor != null) { | |
| 163 | + valor = valor + novoValor; | |
| 164 | + valorTotal.remove(mes); | |
| 165 | + valorTotal.put(mes, valor); | |
| 166 | + } else { | |
| 167 | + valorTotal.put(mes, novoValor); | |
| 168 | + } | |
| 169 | + if (!xVals.contains(mes)) { | |
| 170 | + xVals.add(mes); | |
| 171 | + } | |
| 172 | + | |
| 173 | + // | |
| 174 | + | |
| 175 | + | |
| 176 | + } | |
| 177 | + for (int j = 0; j < xVals.size(); j++) { | |
| 178 | + Float val = valorTotal.get(xVals.get(j)); | |
| 179 | + yVals1.add(new BarEntry(val, j)); | |
| 180 | + } | |
| 181 | + Grafico grafico = new Grafico("Todos", yVals1, xVals, R.color.cor10); | |
| 182 | + myDataset.add(grafico); | |
| 183 | + | |
| 184 | + //adicionar os outros graficos | |
| 185 | + for(int i=0; i < tipos.size();i++ ){ | |
| 186 | + HashMap<String,Float> temp = dataset.get(tipos.get(i)); | |
| 187 | + ArrayList<String> x = new ArrayList<String>(); | |
| 188 | + for ( int k=0; k < temp.size(); k++ ) { | |
| 189 | + x.add(k,""); | |
| 190 | + } | |
| 191 | + ArrayList<BarEntry> y = new ArrayList<BarEntry>(); | |
| 192 | + for ( String mes : temp.keySet() ) { | |
| 193 | + if(!x.contains(mes)){ | |
| 194 | + int pos = buscaPosicao(mes); | |
| 195 | + x.remove(pos); | |
| 196 | + x.add(pos, mes); | |
| 197 | + } | |
| 198 | + Float val = temp.get(mes); | |
| 199 | + y.add(new BarEntry(val, x.indexOf(mes))); | |
| 200 | + } | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + myDataset.add(new Grafico(tipos.get(i),y,x,cores[i])); | |
| 205 | + } | |
| 206 | + | |
| 207 | + carregaList(); | |
| 208 | + pb.setVisibility(View.INVISIBLE); | |
| 209 | + | |
| 210 | + // setData(); | |
| 211 | + | |
| 212 | + } | |
| 213 | + }); | |
| 214 | + | |
| 215 | + | |
| 216 | + return null; | |
| 217 | + } | |
| 218 | + | |
| 219 | + private int buscaPosicao(String mes) { | |
| 220 | + int ret=0; | |
| 221 | + switch (mes){ | |
| 222 | + case "JAN": | |
| 223 | + ret=0; | |
| 224 | + break; | |
| 225 | + case "FEV": | |
| 226 | + ret=1; | |
| 227 | + break; | |
| 228 | + case "MAR": | |
| 229 | + ret=2; | |
| 230 | + break; | |
| 231 | + case "ABR": | |
| 232 | + ret=3; | |
| 233 | + break; | |
| 234 | + case "MAI": | |
| 235 | + ret=4; | |
| 236 | + break; | |
| 237 | + case "JUN": | |
| 238 | + ret=5; | |
| 239 | + break; | |
| 240 | + case "JUL": | |
| 241 | + ret=6; | |
| 242 | + break; | |
| 243 | + case "AGO": | |
| 244 | + ret=7; | |
| 245 | + break; | |
| 246 | + case "SET": | |
| 247 | + ret=8; | |
| 248 | + break; | |
| 249 | + case "OUT": | |
| 250 | + ret=9; | |
| 251 | + break; | |
| 252 | + case "NOV": | |
| 253 | + ret=10; | |
| 254 | + break; | |
| 255 | + case "DEZ": | |
| 256 | + ret=11; | |
| 257 | + break; | |
| 258 | + | |
| 259 | + } | |
| 260 | + return ret; | |
| 261 | + } | |
| 262 | + | |
| 263 | + public void carregaList(){ | |
| 264 | + mAdapter = new GastoAdapter(myDataset); | |
| 265 | +// mAdapter.setRecyclerViewOnClickListenerHack(this); | |
| 266 | + mRecyclerView.setAdapter(mAdapter); | |
| 267 | +// pb.setVisibility(View.INVISIBLE); | |
| 268 | + } | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + // TODO: Rename method, update argument and hook method into UI event | |
| 273 | + public void onButtonPressed(Uri uri) { | |
| 274 | + if (mListener != null) { | |
| 275 | + mListener.onFragmentInteraction(uri); | |
| 276 | + } | |
| 277 | + } | |
| 278 | + | |
| 279 | + @Override | |
| 280 | + public void onAttach(Activity activity) { | |
| 281 | + super.onAttach(activity); | |
| 282 | +// try { | |
| 283 | +// mListener = (OnFragmentInteractionListener) activity; | |
| 284 | +// } catch (ClassCastException e) { | |
| 285 | +// throw new ClassCastException(activity.toString() | |
| 286 | +// + " must implement OnFragmentInteractionListener"); | |
| 287 | +// } | |
| 288 | + } | |
| 289 | + | |
| 290 | + @Override | |
| 291 | + public void onDetach() { | |
| 292 | + super.onDetach(); | |
| 293 | + mListener = null; | |
| 294 | + } | |
| 295 | + | |
| 296 | + /** | |
| 297 | + * This interface must be implemented by activities that contain this | |
| 298 | + * fragment to allow an interaction in this fragment to be communicated | |
| 299 | + * to the activity and potentially other fragments contained in that | |
| 300 | + * activity. | |
| 301 | + * <p/> | |
| 302 | + * See the Android Training lesson <a href= | |
| 303 | + * "http://developer.android.com/training/basics/fragments/communicating.html" | |
| 304 | + * >Communicating with Other Fragments</a> for more information. | |
| 305 | + */ | |
| 306 | + public interface OnFragmentInteractionListener { | |
| 307 | + // TODO: Update argument type and name | |
| 308 | + public void onFragmentInteraction(Uri uri); | |
| 309 | + } | |
| 310 | + | |
| 311 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/fragments/GastosFragment.java
0 → 100644
| ... | ... | @@ -0,0 +1,212 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view.fragments; | |
| 2 | + | |
| 3 | +import android.graphics.Color; | |
| 4 | +import android.os.Bundle; | |
| 5 | +import android.support.v4.app.Fragment; | |
| 6 | +import android.view.LayoutInflater; | |
| 7 | +import android.view.View; | |
| 8 | +import android.view.ViewGroup; | |
| 9 | + | |
| 10 | +import com.github.mikephil.charting.animation.Easing; | |
| 11 | +import com.github.mikephil.charting.charts.LineChart; | |
| 12 | +import com.github.mikephil.charting.components.Legend; | |
| 13 | +import com.github.mikephil.charting.components.LimitLine; | |
| 14 | +import com.github.mikephil.charting.components.YAxis; | |
| 15 | +import com.github.mikephil.charting.data.Entry; | |
| 16 | +import com.github.mikephil.charting.data.LineData; | |
| 17 | +import com.github.mikephil.charting.data.LineDataSet; | |
| 18 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 19 | +import com.monitorabrasil.monitoralegislativo.model.Grafico; | |
| 20 | +import com.parse.FindCallback; | |
| 21 | +import com.parse.ParseException; | |
| 22 | +import com.parse.ParseObject; | |
| 23 | +import com.parse.ParseQuery; | |
| 24 | + | |
| 25 | +import java.util.ArrayList; | |
| 26 | +import java.util.Iterator; | |
| 27 | +import java.util.List; | |
| 28 | + | |
| 29 | +/** | |
| 30 | + * Created by geral_000 on 20/06/2015. | |
| 31 | + */ | |
| 32 | +public class GastosFragment extends Fragment { | |
| 33 | + | |
| 34 | + private LineChart mChart; | |
| 35 | + private ParseObject politico; | |
| 36 | + float maximo = 0f, minimo = 0f; | |
| 37 | + View mView; | |
| 38 | + ArrayList<String> xVals = new ArrayList<String>(); | |
| 39 | + ArrayList<Entry> yVals = new ArrayList<Entry>(); | |
| 40 | + private ArrayList<Grafico> graficos =new ArrayList<Grafico>(); | |
| 41 | + | |
| 42 | + public View onCreateView(LayoutInflater inflater, | |
| 43 | + ViewGroup container, | |
| 44 | + Bundle savedInstanceState) { | |
| 45 | + View view = inflater.inflate(R.layout.fragment_politico_gastos, container, false); | |
| 46 | + | |
| 47 | + Bundle bundle = getArguments(); | |
| 48 | + politico = buscaGastos(bundle.getString("politico")) ; | |
| 49 | + | |
| 50 | + mView=view; | |
| 51 | + | |
| 52 | + return view; | |
| 53 | + } | |
| 54 | + | |
| 55 | + private void buildGraph(){ | |
| 56 | + mChart = (LineChart)mView.findViewById(R.id.chart1); | |
| 57 | + | |
| 58 | + mChart.setDrawGridBackground(false); | |
| 59 | + | |
| 60 | + | |
| 61 | + mChart.setDescription(""); | |
| 62 | + mChart.setNoDataTextDescription("You need to provide data for the chart."); | |
| 63 | + | |
| 64 | + // enable value highlighting | |
| 65 | + mChart.setHighlightEnabled(true); | |
| 66 | + | |
| 67 | + // enable touch gestures | |
| 68 | + mChart.setTouchEnabled(true); | |
| 69 | + | |
| 70 | + // enable scaling and dragging | |
| 71 | + mChart.setDragEnabled(true); | |
| 72 | + mChart.setScaleEnabled(true); | |
| 73 | + // mChart.setScaleXEnabled(true); | |
| 74 | + // mChart.setScaleYEnabled(true); | |
| 75 | + | |
| 76 | + // if disabled, scaling can be done on x- and y-axis separately | |
| 77 | + mChart.setPinchZoom(true); | |
| 78 | + | |
| 79 | + // enable/disable highlight indicators (the lines that indicate the | |
| 80 | + // highlighted Entry) | |
| 81 | + mChart.setHighlightEnabled(false); | |
| 82 | + | |
| 83 | + LimitLine ll1 = new LimitLine(130f, "Upper Limit"); | |
| 84 | + ll1.setLineWidth(4f); | |
| 85 | + ll1.enableDashedLine(10f, 10f, 0f); | |
| 86 | + ll1.setLabelPosition(LimitLine.LimitLabelPosition.POS_RIGHT); | |
| 87 | + ll1.setTextSize(10f); | |
| 88 | + | |
| 89 | + LimitLine ll2 = new LimitLine(-30f, "Lower Limit"); | |
| 90 | + ll2.setLineWidth(4f); | |
| 91 | + ll2.enableDashedLine(10f, 10f, 0f); | |
| 92 | + ll2.setLabelPosition(LimitLine.LimitLabelPosition.POS_RIGHT); | |
| 93 | + ll2.setTextSize(10f); | |
| 94 | + | |
| 95 | + YAxis leftAxis = mChart.getAxisLeft(); | |
| 96 | + leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines | |
| 97 | + //leftAxis.addLimitLine(ll1); | |
| 98 | + //leftAxis.addLimitLine(ll2); | |
| 99 | + leftAxis.setAxisMaxValue(maximo + 200); | |
| 100 | + minimo = minimo-200; | |
| 101 | + if(minimo < 0f){ | |
| 102 | + minimo=0f; | |
| 103 | + } | |
| 104 | + leftAxis.setAxisMinValue(minimo); | |
| 105 | + leftAxis.setStartAtZero(false); | |
| 106 | + //leftAxis.setYOffset(20f); | |
| 107 | + leftAxis.enableGridDashedLine(10f, 10f, 0f); | |
| 108 | + | |
| 109 | + // limit lines are drawn behind data (and not on top) | |
| 110 | + leftAxis.setDrawLimitLinesBehindData(true); | |
| 111 | + | |
| 112 | + mChart.getAxisRight().setEnabled(false); | |
| 113 | + | |
| 114 | + // add data | |
| 115 | + setData(); | |
| 116 | + | |
| 117 | +// mChart.setVisibleXRange(20); | |
| 118 | +// mChart.setVisibleYRange(20f, AxisDependency.LEFT); | |
| 119 | +// mChart.centerViewTo(20, 50, AxisDependency.LEFT); | |
| 120 | + | |
| 121 | + mChart.animateX(2500, Easing.EasingOption.EaseInOutQuart); | |
| 122 | +// mChart.invalidate(); | |
| 123 | + | |
| 124 | + // get the legend (only possible after setting data) | |
| 125 | + Legend l = mChart.getLegend(); | |
| 126 | + | |
| 127 | + // modify the legend ... | |
| 128 | + // l.setPosition(LegendPosition.LEFT_OF_CHART); | |
| 129 | + l.setForm(Legend.LegendForm.LINE); | |
| 130 | + } | |
| 131 | + | |
| 132 | + private ParseObject buscaGastos(String id) { | |
| 133 | + | |
| 134 | + ParseObject politico = buscaPolitico(id); | |
| 135 | + xVals =new ArrayList<String>(); | |
| 136 | + yVals = new ArrayList<Entry>(); | |
| 137 | + maximo = 0f; | |
| 138 | + minimo = 0f; | |
| 139 | + | |
| 140 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("Verba"); | |
| 141 | + query.whereEqualTo("politico",politico); | |
| 142 | + query.orderByAscending("createdAt"); | |
| 143 | + query.findInBackground(new FindCallback<ParseObject>() { | |
| 144 | + public void done(List<ParseObject> gastos, ParseException e) { | |
| 145 | + Iterator<ParseObject> gastoIt = gastos.iterator(); | |
| 146 | + int i=0; | |
| 147 | + while (gastoIt.hasNext()) { | |
| 148 | + ParseObject g = gastoIt.next(); | |
| 149 | + float possivelMaximo = Float.valueOf(g.getString("valor")); | |
| 150 | + if(possivelMaximo > maximo ){ | |
| 151 | + maximo = possivelMaximo; | |
| 152 | + } | |
| 153 | + if(minimo > possivelMaximo || i==0){ | |
| 154 | + minimo=possivelMaximo; | |
| 155 | + } | |
| 156 | + xVals.add(g.getString("mes").substring(0,3)+" "+g.getString("ano")); | |
| 157 | + yVals.add(new Entry(possivelMaximo, i)); | |
| 158 | + i++; | |
| 159 | + } | |
| 160 | + buildGraph(); | |
| 161 | + } | |
| 162 | + }); | |
| 163 | + | |
| 164 | + return null; | |
| 165 | + } | |
| 166 | + | |
| 167 | + private ParseObject buscaPolitico(String id) { | |
| 168 | + | |
| 169 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("Politico"); | |
| 170 | + query.fromLocalDatastore(); | |
| 171 | + try { | |
| 172 | + return query.get(id); | |
| 173 | + } catch (com.parse.ParseException e) { | |
| 174 | + e.printStackTrace(); | |
| 175 | + } | |
| 176 | + return null; | |
| 177 | + } | |
| 178 | + | |
| 179 | + private void setData() { | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + // create a dataset and give it a type | |
| 184 | + LineDataSet set1 = new LineDataSet(yVals, "Verba idenizatoria"); | |
| 185 | + set1.setFillAlpha(110); | |
| 186 | + set1.setFillColor(Color.RED); | |
| 187 | + | |
| 188 | + // set the line to be drawn like this "- - - - - -" | |
| 189 | + set1.enableDashedLine(10f, 5f, 0f); | |
| 190 | + set1.setColor(Color.BLACK); | |
| 191 | + set1.setCircleColor(Color.BLACK); | |
| 192 | + set1.setLineWidth(1f); | |
| 193 | + set1.setCircleSize(3f); | |
| 194 | + set1.setDrawCircleHole(false); | |
| 195 | + set1.setValueTextSize(9f); | |
| 196 | + set1.setFillAlpha(65); | |
| 197 | + set1.setFillColor(Color.BLACK); | |
| 198 | +// set1.setDrawFilled(true); | |
| 199 | + // set1.setShader(new LinearGradient(0, 0, 0, mChart.getHeight(), | |
| 200 | + // Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR)); | |
| 201 | + | |
| 202 | + ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>(); | |
| 203 | + dataSets.add(set1); // add the datasets | |
| 204 | + | |
| 205 | + // create a data object with the datasets | |
| 206 | + LineData data = new LineData(xVals, dataSets); | |
| 207 | + | |
| 208 | + // set data | |
| 209 | + mChart.setData(data); | |
| 210 | + } | |
| 211 | +} | |
| 212 | + | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/fragments/HomeFragment.java
0 → 100644
| ... | ... | @@ -0,0 +1,359 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view.fragments; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.content.Intent; | |
| 5 | +import android.net.Uri; | |
| 6 | +import android.os.Bundle; | |
| 7 | +import android.support.design.widget.FloatingActionButton; | |
| 8 | +import android.support.v4.app.Fragment; | |
| 9 | +import android.support.v7.widget.LinearLayoutManager; | |
| 10 | +import android.support.v7.widget.RecyclerView; | |
| 11 | +import android.util.Log; | |
| 12 | +import android.view.LayoutInflater; | |
| 13 | +import android.view.View; | |
| 14 | +import android.view.ViewGroup; | |
| 15 | + | |
| 16 | +import com.crashlytics.android.Crashlytics; | |
| 17 | +import com.github.mikephil.charting.animation.Easing; | |
| 18 | +import com.github.mikephil.charting.charts.BarChart; | |
| 19 | +import com.github.mikephil.charting.components.Legend; | |
| 20 | +import com.github.mikephil.charting.components.XAxis; | |
| 21 | +import com.github.mikephil.charting.components.YAxis; | |
| 22 | +import com.github.mikephil.charting.data.BarData; | |
| 23 | +import com.github.mikephil.charting.data.BarDataSet; | |
| 24 | +import com.github.mikephil.charting.data.BarEntry; | |
| 25 | +import com.github.mikephil.charting.utils.ValueFormatter; | |
| 26 | +import com.monitorabrasil.monitoralegislativo.view.PoliticoFichaActivity; | |
| 27 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 28 | +import com.monitorabrasil.monitoralegislativo.view.adapters.VereadorAdapter; | |
| 29 | +import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 30 | +import com.monitorabrasil.monitoralegislativo.model.Grafico; | |
| 31 | +import com.monitorabrasil.monitoralegislativo.view.interfaces.RecyclerViewOnClickListenerHack; | |
| 32 | +import com.monitorabrasil.monitoralegislativo.model.util.MyValueFormatter; | |
| 33 | +import com.parse.FindCallback; | |
| 34 | +import com.parse.ParseException; | |
| 35 | +import com.parse.ParseObject; | |
| 36 | +import com.parse.ParseQuery; | |
| 37 | + | |
| 38 | +import java.util.ArrayList; | |
| 39 | +import java.util.HashMap; | |
| 40 | +import java.util.Iterator; | |
| 41 | +import java.util.List; | |
| 42 | + | |
| 43 | +/** | |
| 44 | + * A simple {@link Fragment} subclass. | |
| 45 | + * Activities that contain this fragment must implement the | |
| 46 | + * {@link HomeFragment.OnFragmentInteractionListener} interface | |
| 47 | + * to handle interaction events. | |
| 48 | + * Use the {@link HomeFragment#newInstance} factory method to | |
| 49 | + * create an instance of this fragment. | |
| 50 | + */ | |
| 51 | +public class HomeFragment extends Fragment implements RecyclerViewOnClickListenerHack { | |
| 52 | + | |
| 53 | + | |
| 54 | + private OnFragmentInteractionListener mListener; | |
| 55 | + private RecyclerView mRecyclerView; | |
| 56 | + private VereadorAdapter mAdapter; | |
| 57 | + private List<ParseObject> ob; | |
| 58 | + private HashMap<String,Float> valorTotal = new HashMap<String,Float>(); | |
| 59 | + ArrayList<String> xVals = new ArrayList<String>(); | |
| 60 | + ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>(); | |
| 61 | + | |
| 62 | + public BarChart mChart; | |
| 63 | + | |
| 64 | + /** | |
| 65 | + * Use this factory method to create a new instance of | |
| 66 | + * this fragment using the provided parameters. | |
| 67 | + * @return A new instance of fragment HomeFragment. | |
| 68 | + */ | |
| 69 | + // TODO: Rename and change types and number of parameters | |
| 70 | + public static HomeFragment newInstance() { | |
| 71 | + HomeFragment fragment = new HomeFragment(); | |
| 72 | + Bundle args = new Bundle(); | |
| 73 | + | |
| 74 | + fragment.setArguments(args); | |
| 75 | + return fragment; | |
| 76 | + } | |
| 77 | + | |
| 78 | + public HomeFragment() { | |
| 79 | + // Required empty public constructor | |
| 80 | + } | |
| 81 | + | |
| 82 | + @Override | |
| 83 | + public void onCreate(Bundle savedInstanceState) { | |
| 84 | + super.onCreate(savedInstanceState); | |
| 85 | + | |
| 86 | + } | |
| 87 | + | |
| 88 | + @Override | |
| 89 | + public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
| 90 | + Bundle savedInstanceState) { | |
| 91 | + // Inflate the layout for this fragment | |
| 92 | + View view = inflater.inflate(R.layout.fragment_home, container, false); | |
| 93 | + //tableview | |
| 94 | + mRecyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view); | |
| 95 | + | |
| 96 | + | |
| 97 | + // use this setting to improve performance if you know that changes | |
| 98 | + // in content do not change the layout size of the RecyclerView | |
| 99 | + mRecyclerView.setHasFixedSize(true); | |
| 100 | + | |
| 101 | + LinearLayoutManager llm = new LinearLayoutManager(getActivity()); | |
| 102 | + llm.setOrientation(LinearLayoutManager.VERTICAL); | |
| 103 | + mRecyclerView.setLayoutManager(llm); | |
| 104 | + | |
| 105 | + //buscar os vereadores | |
| 106 | + buscaVereadores(); | |
| 107 | + | |
| 108 | + //buscar o grafico de gastos | |
| 109 | + mChart = (BarChart)view.findViewById(R.id.chart1); | |
| 110 | + | |
| 111 | + buscaGastos(); | |
| 112 | + | |
| 113 | + FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab); | |
| 114 | + fab.setOnClickListener(new View.OnClickListener() { | |
| 115 | + @Override | |
| 116 | + public void onClick(View view) { | |
| 117 | + Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); | |
| 118 | + sharingIntent.setType("text/plain"); | |
| 119 | + String shareBody = "Recomendo o app Participa Cidadão https://play.google.com/store/apps/details?id=com.monitorabrasil.monitoramunicipio"; | |
| 120 | + sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Participa Cidadão"); | |
| 121 | + sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody); | |
| 122 | + startActivity(Intent.createChooser(sharingIntent, "Compartilhar via")); | |
| 123 | + | |
| 124 | + } | |
| 125 | + }); | |
| 126 | + | |
| 127 | + | |
| 128 | + return view; | |
| 129 | + } | |
| 130 | + | |
| 131 | + private ParseObject buscaGastos() { | |
| 132 | + | |
| 133 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("DespesaCamara"); | |
| 134 | + query.setLimit(200); | |
| 135 | + //query.whereEqualTo("politico",politico); | |
| 136 | + | |
| 137 | + query.addAscendingOrder("mes_numero"); | |
| 138 | + query.findInBackground(new FindCallback<ParseObject>() { | |
| 139 | + public void done(List<ParseObject> gastos, ParseException e) { | |
| 140 | + if(null != gastos){ | |
| 141 | + Iterator<ParseObject> gastoIt = gastos.iterator(); | |
| 142 | + | |
| 143 | + while (gastoIt.hasNext()) { | |
| 144 | + | |
| 145 | + ParseObject g = gastoIt.next(); | |
| 146 | + String mes = g.getString("mes"); | |
| 147 | + Float novoValor = Float.valueOf(g.getString("valor")); | |
| 148 | + Float valor = valorTotal.get(mes); | |
| 149 | + if (valor != null) { | |
| 150 | + valor = valor + novoValor; | |
| 151 | + valorTotal.remove(mes); | |
| 152 | + valorTotal.put(mes, valor); | |
| 153 | + } else { | |
| 154 | + valorTotal.put(mes, novoValor); | |
| 155 | + } | |
| 156 | + if (!xVals.contains(mes)) { | |
| 157 | + xVals.add(mes); | |
| 158 | + } | |
| 159 | + | |
| 160 | + } | |
| 161 | + for (int j = 0; j < xVals.size(); j++) { | |
| 162 | + Float val = valorTotal.get(xVals.get(j)); | |
| 163 | + yVals1.add(new BarEntry(val, j)); | |
| 164 | + } | |
| 165 | + Grafico grafico = new Grafico("Todos", yVals1, xVals, R.color.cor10); | |
| 166 | + buildGraph(grafico); | |
| 167 | + } | |
| 168 | + | |
| 169 | + | |
| 170 | + } | |
| 171 | + }); | |
| 172 | + | |
| 173 | + | |
| 174 | + return null; | |
| 175 | + } | |
| 176 | + | |
| 177 | + private void buildGraph(Grafico grafico) { | |
| 178 | + | |
| 179 | +// mChart.set | |
| 180 | + | |
| 181 | + mChart.setDrawBarShadow(false); | |
| 182 | + mChart.setDrawValueAboveBar(true); | |
| 183 | + | |
| 184 | + mChart.setDescription(""); | |
| 185 | + | |
| 186 | + // if more than 60 entries are displayed in the chart, no values will be | |
| 187 | + // drawn | |
| 188 | + mChart.setMaxVisibleValueCount(60); | |
| 189 | + | |
| 190 | + // scaling can now only be done on x- and y-axis separately | |
| 191 | + mChart.setPinchZoom(false); | |
| 192 | + | |
| 193 | + // draw shadows for each bar that show the maximum value | |
| 194 | + // mChart.setDrawBarShadow(true); | |
| 195 | + | |
| 196 | + // mChart.setDrawXLabels(false); | |
| 197 | + | |
| 198 | + mChart.setDrawGridBackground(false); | |
| 199 | + // mChart.setDrawYLabels(false); | |
| 200 | + | |
| 201 | +// mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); | |
| 202 | + | |
| 203 | + XAxis xAxis = mChart.getXAxis(); | |
| 204 | + xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); | |
| 205 | +// xAxis.setTypeface(mTf); | |
| 206 | + xAxis.setDrawGridLines(false); | |
| 207 | + xAxis.setSpaceBetweenLabels(2); | |
| 208 | + | |
| 209 | + ValueFormatter custom = new MyValueFormatter(); | |
| 210 | + | |
| 211 | + YAxis leftAxis = mChart.getAxisLeft(); | |
| 212 | +// leftAxis.setTypeface(mTf); | |
| 213 | + leftAxis.setLabelCount(8,true); | |
| 214 | + leftAxis.setValueFormatter(custom); | |
| 215 | + leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART); | |
| 216 | + leftAxis.setSpaceTop(15f); | |
| 217 | + | |
| 218 | + mChart.getAxisRight().setEnabled(false); | |
| 219 | + YAxis rightAxis = mChart.getAxisRight(); | |
| 220 | + rightAxis.setDrawGridLines(false); | |
| 221 | +// rightAxis.setTypeface(mTf); | |
| 222 | + rightAxis.setLabelCount(8,true); | |
| 223 | + rightAxis.setValueFormatter(custom); | |
| 224 | + rightAxis.setSpaceTop(15f); | |
| 225 | + | |
| 226 | + Legend l = mChart.getLegend(); | |
| 227 | + l.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT); | |
| 228 | + l.setForm(Legend.LegendForm.SQUARE); | |
| 229 | + l.setFormSize(9f); | |
| 230 | + l.setTextSize(11f); | |
| 231 | + l.setXEntrySpace(4f); | |
| 232 | + // l.setExtra(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc", | |
| 233 | + // "def", "ghj", "ikl", "mno" }); | |
| 234 | + // l.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc", | |
| 235 | + // "def", "ghj", "ikl", "mno" }); | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + // setting data | |
| 240 | +// mSeekBarY.setProgress(50); | |
| 241 | +// mSeekBarX.setProgress(12); | |
| 242 | +// | |
| 243 | +// mSeekBarY.setOnSeekBarChangeListener(this); | |
| 244 | +// mSeekBarX.setOnSeekBarChangeListener(this); | |
| 245 | + | |
| 246 | + // mChart.setDrawLegend(false); | |
| 247 | + | |
| 248 | + | |
| 249 | + //setdata | |
| 250 | + | |
| 251 | + setData(grafico); | |
| 252 | + | |
| 253 | + mChart.animateX(2500, Easing.EasingOption.EaseInOutQuart); | |
| 254 | + mChart.notifyDataSetChanged(); | |
| 255 | + | |
| 256 | + } | |
| 257 | + | |
| 258 | + private void setData(Grafico grafico) { | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + BarDataSet set1 = new BarDataSet(grafico.getyAxis(), "Gastos Totais"); | |
| 263 | + set1.setBarSpacePercent(35f); | |
| 264 | + | |
| 265 | + ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>(); | |
| 266 | + dataSets.add(set1); | |
| 267 | + try{ | |
| 268 | + set1.setColor(MyApp.getInstance().getResources().getColor(grafico.getCor())); | |
| 269 | + | |
| 270 | + BarData data = new BarData(grafico.getxVals(), dataSets); | |
| 271 | + // data.setValueFormatter(new MyValueFormatter()); | |
| 272 | + data.setValueTextSize(10f); | |
| 273 | +// data.setValueTypeface(mTf); | |
| 274 | + mChart.setVisibility(View.VISIBLE); | |
| 275 | + mChart.setData(data); | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + }catch (Exception e){ | |
| 280 | + Crashlytics.log("GastosCamaraFragment " + e.toString()); | |
| 281 | + } | |
| 282 | + | |
| 283 | + } | |
| 284 | + | |
| 285 | + // TODO: Rename method, update argument and hook method into UI event | |
| 286 | + public void onButtonPressed(Uri uri) { | |
| 287 | + if (mListener != null) { | |
| 288 | + mListener.onFragmentInteraction(uri); | |
| 289 | + } | |
| 290 | + } | |
| 291 | + | |
| 292 | + //busca objetos | |
| 293 | + public void buscaVereadores(){ | |
| 294 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("Politico"); | |
| 295 | + query.addDescendingOrder("avaliacao"); | |
| 296 | + //query.whereEqualTo("playerName", "Dan Stemkoski"); | |
| 297 | + query.findInBackground(new FindCallback<ParseObject>() { | |
| 298 | + @Override | |
| 299 | + public void done(List<ParseObject> list, com.parse.ParseException e) { | |
| 300 | + if (e == null) { | |
| 301 | + ob = list; | |
| 302 | + carregaList(list); | |
| 303 | + } else { | |
| 304 | + Log.d("score", "Error: " + e.getMessage()); | |
| 305 | + } | |
| 306 | + } | |
| 307 | + | |
| 308 | + | |
| 309 | + }); | |
| 310 | + } | |
| 311 | + | |
| 312 | + public void carregaList(List<ParseObject> list){ | |
| 313 | + mAdapter = new VereadorAdapter(list); | |
| 314 | + mAdapter.setRecyclerViewOnClickListenerHack(this); | |
| 315 | + mRecyclerView.setAdapter(mAdapter); | |
| 316 | + //pb.setVisibility(View.INVISIBLE); | |
| 317 | + } | |
| 318 | + | |
| 319 | + @Override | |
| 320 | + public void onClickListener(View view, int position) { | |
| 321 | + Intent intent = new Intent(getActivity(),PoliticoFichaActivity.class); | |
| 322 | + intent.putExtra("politico", ob.get(position).getObjectId()); | |
| 323 | + startActivity(intent); | |
| 324 | + | |
| 325 | + } | |
| 326 | + | |
| 327 | + @Override | |
| 328 | + public void onAttach(Activity activity) { | |
| 329 | + super.onAttach(activity); | |
| 330 | + try { | |
| 331 | + mListener = (OnFragmentInteractionListener) activity; | |
| 332 | + } catch (ClassCastException e) { | |
| 333 | + throw new ClassCastException(activity.toString() | |
| 334 | + + " must implement OnFragmentInteractionListener"); | |
| 335 | + } | |
| 336 | + } | |
| 337 | + | |
| 338 | + @Override | |
| 339 | + public void onDetach() { | |
| 340 | + super.onDetach(); | |
| 341 | + mListener = null; | |
| 342 | + } | |
| 343 | + | |
| 344 | + /** | |
| 345 | + * This interface must be implemented by activities that contain this | |
| 346 | + * fragment to allow an interaction in this fragment to be communicated | |
| 347 | + * to the activity and potentially other fragments contained in that | |
| 348 | + * activity. | |
| 349 | + * <p/> | |
| 350 | + * See the Android Training lesson <a href= | |
| 351 | + * "http://developer.android.com/training/basics/fragments/communicating.html" | |
| 352 | + * >Communicating with Other Fragments</a> for more information. | |
| 353 | + */ | |
| 354 | + public interface OnFragmentInteractionListener { | |
| 355 | + // TODO: Update argument type and name | |
| 356 | + public void onFragmentInteraction(Uri uri); | |
| 357 | + } | |
| 358 | + | |
| 359 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/fragments/ListaPoliticoFragment.java
0 → 100644
| ... | ... | @@ -0,0 +1,111 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view.fragments; | |
| 2 | + | |
| 3 | +import android.content.Intent; | |
| 4 | +import android.os.Bundle; | |
| 5 | +import android.support.v4.app.Fragment; | |
| 6 | +import android.support.v7.widget.LinearLayoutManager; | |
| 7 | +import android.support.v7.widget.RecyclerView; | |
| 8 | +import android.util.Log; | |
| 9 | +import android.view.LayoutInflater; | |
| 10 | +import android.view.View; | |
| 11 | +import android.view.ViewGroup; | |
| 12 | +import android.widget.ProgressBar; | |
| 13 | + | |
| 14 | +import com.monitorabrasil.monitoralegislativo.view.PoliticoFichaActivity; | |
| 15 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 16 | +import com.monitorabrasil.monitoralegislativo.view.adapters.VereadorAdapter; | |
| 17 | +import com.monitorabrasil.monitoralegislativo.view.interfaces.RecyclerViewOnClickListenerHack; | |
| 18 | +import com.parse.FindCallback; | |
| 19 | +import com.parse.ParseObject; | |
| 20 | +import com.parse.ParseQuery; | |
| 21 | + | |
| 22 | +import java.util.List; | |
| 23 | + | |
| 24 | +/** | |
| 25 | + * Created by geraugu on 6/10/15. | |
| 26 | + */ | |
| 27 | +public class ListaPoliticoFragment extends Fragment implements RecyclerViewOnClickListenerHack { | |
| 28 | + | |
| 29 | + private RecyclerView mRecyclerView; | |
| 30 | + private VereadorAdapter mAdapter; | |
| 31 | + private List<ParseObject> ob; | |
| 32 | + private ProgressBar pb; | |
| 33 | + | |
| 34 | + @Override | |
| 35 | + public View onCreateView(LayoutInflater inflater, | |
| 36 | + ViewGroup container, | |
| 37 | + Bundle savedInstanceState) { | |
| 38 | + View view = inflater.inflate(R.layout.fragment_list_politico, container, false); | |
| 39 | + | |
| 40 | + pb = (ProgressBar) view.findViewById(R.id.progressBar); | |
| 41 | + | |
| 42 | + | |
| 43 | + //tableview | |
| 44 | + mRecyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view); | |
| 45 | + | |
| 46 | + | |
| 47 | + // use this setting to improve performance if you know that changes | |
| 48 | + // in content do not change the layout size of the RecyclerView | |
| 49 | + mRecyclerView.setHasFixedSize(true); | |
| 50 | + | |
| 51 | + LinearLayoutManager llm = new LinearLayoutManager(getActivity()); | |
| 52 | + llm.setOrientation(LinearLayoutManager.VERTICAL); | |
| 53 | + mRecyclerView.setLayoutManager(llm); | |
| 54 | + | |
| 55 | + buscaVereadores(); | |
| 56 | + | |
| 57 | + return view; | |
| 58 | + | |
| 59 | + } | |
| 60 | + | |
| 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 | + | |
| 78 | + }); | |
| 79 | + } | |
| 80 | + | |
| 81 | + public void carregaList(List<ParseObject> list){ | |
| 82 | + mAdapter = new VereadorAdapter(list); | |
| 83 | + mAdapter.setRecyclerViewOnClickListenerHack(this); | |
| 84 | + mRecyclerView.setAdapter(mAdapter); | |
| 85 | + pb.setVisibility(View.INVISIBLE); | |
| 86 | + } | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + @Override | |
| 91 | + public void onClickListener(View view, int position) { | |
| 92 | + | |
| 93 | + | |
| 94 | +// PoliticoFragment frag = new PoliticoFragment(); | |
| 95 | +// Bundle bundle = new Bundle(); | |
| 96 | +// try { | |
| 97 | +// ob.get(position).pin(); | |
| 98 | +// } catch (ParseException e) { | |
| 99 | +// e.printStackTrace(); | |
| 100 | +// } | |
| 101 | +// bundle.putString("politico", ob.get(position).getObjectId()); | |
| 102 | +// frag.setArguments(bundle); | |
| 103 | +// FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); | |
| 104 | +// ft.replace(R.id.rl_fragment_container, frag, "politicoFrag"); | |
| 105 | +// ft.addToBackStack(null); | |
| 106 | +// ft.commit(); | |
| 107 | + Intent intent = new Intent(getActivity(),PoliticoFichaActivity.class); | |
| 108 | + intent.putExtra("politico", ob.get(position).getObjectId()); | |
| 109 | + startActivity(intent); | |
| 110 | + } | |
| 111 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/fragments/ListaProjetosFragment.java
0 → 100644
| ... | ... | @@ -0,0 +1,160 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view.fragments; | |
| 2 | + | |
| 3 | + | |
| 4 | +import android.os.Bundle; | |
| 5 | +import android.support.v4.app.Fragment; | |
| 6 | +import android.support.v7.widget.LinearLayoutManager; | |
| 7 | +import android.support.v7.widget.RecyclerView; | |
| 8 | +import android.util.Log; | |
| 9 | +import android.view.LayoutInflater; | |
| 10 | +import android.view.View; | |
| 11 | +import android.view.ViewGroup; | |
| 12 | +import android.widget.ProgressBar; | |
| 13 | + | |
| 14 | +import com.crashlytics.android.answers.Answers; | |
| 15 | +import com.crashlytics.android.answers.ContentViewEvent; | |
| 16 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 17 | +import com.monitorabrasil.monitoralegislativo.view.adapters.ProjetoAdapter; | |
| 18 | +import com.monitorabrasil.monitoralegislativo.view.adapters.VereadorAdapter; | |
| 19 | +import com.monitorabrasil.monitoralegislativo.view.interfaces.RecyclerViewOnClickListenerHack; | |
| 20 | +import com.parse.FindCallback; | |
| 21 | +import com.parse.ParseObject; | |
| 22 | +import com.parse.ParseQuery; | |
| 23 | + | |
| 24 | +import java.util.List; | |
| 25 | + | |
| 26 | +/** | |
| 27 | + * A simple {@link Fragment} subclass. | |
| 28 | + */ | |
| 29 | +public class ListaProjetosFragment extends Fragment implements RecyclerViewOnClickListenerHack { | |
| 30 | + | |
| 31 | + private RecyclerView mRecyclerView; | |
| 32 | + private ProjetoAdapter mAdapter; | |
| 33 | + private List<ParseObject> ob; | |
| 34 | + private ProgressBar pb; | |
| 35 | + private static final String TIPO_PROJETO = "tipoProjeto"; | |
| 36 | + private static final String ID_POLITICO = "idPolitico"; | |
| 37 | + private String tipoProjeto; | |
| 38 | + private String idPolitico; | |
| 39 | + | |
| 40 | + | |
| 41 | + public static ListaProjetosFragment newInstance(String tipoProjeto, String idPolitico) { | |
| 42 | + ListaProjetosFragment fragment = new ListaProjetosFragment(); | |
| 43 | + Bundle args = new Bundle(); | |
| 44 | + args.putString(TIPO_PROJETO, tipoProjeto); | |
| 45 | + args.putString(ID_POLITICO, idPolitico); | |
| 46 | + fragment.setArguments(args); | |
| 47 | + return fragment; | |
| 48 | + } | |
| 49 | + public ListaProjetosFragment(){ | |
| 50 | + | |
| 51 | + } | |
| 52 | + | |
| 53 | + @Override | |
| 54 | + public void onCreate(Bundle savedInstanceState) { | |
| 55 | + super.onCreate(savedInstanceState); | |
| 56 | + if (getArguments() != null) { | |
| 57 | + tipoProjeto = getArguments().getString(TIPO_PROJETO); | |
| 58 | + idPolitico = getArguments().getString(ID_POLITICO); | |
| 59 | + } | |
| 60 | + } | |
| 61 | + | |
| 62 | + | |
| 63 | + @Override | |
| 64 | + public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
| 65 | + Bundle savedInstanceState) { | |
| 66 | + // Inflate the layout for this fragment | |
| 67 | + View view = inflater.inflate(R.layout.fragment_lista_projetos, container, false); | |
| 68 | + // View view = inflater.inflate(R.layout.fragment_escolha_tipo_projeto, container, false); | |
| 69 | + | |
| 70 | + pb = (ProgressBar) view.findViewById(R.id.progressBar); | |
| 71 | + | |
| 72 | + | |
| 73 | + //tableview | |
| 74 | + mRecyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view); | |
| 75 | + | |
| 76 | + // use this setting to improve performance if you know that changes | |
| 77 | + // in content do not change the layout size of the RecyclerView | |
| 78 | + mRecyclerView.setHasFixedSize(true); | |
| 79 | + | |
| 80 | + LinearLayoutManager llm = new LinearLayoutManager(getActivity()); | |
| 81 | + llm.setOrientation(LinearLayoutManager.VERTICAL); | |
| 82 | + mRecyclerView.setLayoutManager(llm); | |
| 83 | + | |
| 84 | + buscaProjetos(); | |
| 85 | + return view; | |
| 86 | + } | |
| 87 | + | |
| 88 | + public void buscaProjetos(){ | |
| 89 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("Projeto"); | |
| 90 | + query.addDescendingOrder("createdAt"); | |
| 91 | + | |
| 92 | + if(idPolitico!= null){ | |
| 93 | + | |
| 94 | + query.whereEqualTo("politico", buscaPolitico(idPolitico)); | |
| 95 | + | |
| 96 | + } | |
| 97 | + | |
| 98 | + if(tipoProjeto != null){ | |
| 99 | + query.whereEqualTo("classificacao", tipoProjeto); | |
| 100 | + Answers.getInstance().logContentView(new ContentViewEvent() | |
| 101 | + .putContentName("ListaProjetosFragment") | |
| 102 | + .putContentType("Fragment") | |
| 103 | + .putCustomAttribute("tipoProjeto", tipoProjeto)); | |
| 104 | + } | |
| 105 | + | |
| 106 | + | |
| 107 | + query.findInBackground(new FindCallback<ParseObject>() { | |
| 108 | + @Override | |
| 109 | + public void done(List<ParseObject> list, com.parse.ParseException e) { | |
| 110 | + if (e == null) { | |
| 111 | + ob = list; | |
| 112 | + carregaList(list); | |
| 113 | + } else { | |
| 114 | + Log.d("score", "Error: " + e.getMessage()); | |
| 115 | + } | |
| 116 | + } | |
| 117 | + | |
| 118 | + | |
| 119 | + }); | |
| 120 | + } | |
| 121 | + | |
| 122 | + private ParseObject buscaPolitico(String id) { | |
| 123 | + | |
| 124 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("Politico"); | |
| 125 | + query.fromLocalDatastore(); | |
| 126 | + try { | |
| 127 | + return query.get(id); | |
| 128 | + } catch (com.parse.ParseException e) { | |
| 129 | + e.printStackTrace(); | |
| 130 | + } | |
| 131 | + return null; | |
| 132 | + } | |
| 133 | + | |
| 134 | + public void carregaList(List<ParseObject> list){ | |
| 135 | + mAdapter = new ProjetoAdapter(list,getActivity()); | |
| 136 | + mAdapter.setRecyclerViewOnClickListenerHack(this); | |
| 137 | + mRecyclerView.setAdapter(mAdapter); | |
| 138 | + pb.setVisibility(View.INVISIBLE); | |
| 139 | + } | |
| 140 | + | |
| 141 | + @Override | |
| 142 | + public void onClickListener(View view, int position) { | |
| 143 | + | |
| 144 | + | |
| 145 | +// PoliticoFragment frag = new PoliticoFragment(); | |
| 146 | +// Bundle bundle = new Bundle(); | |
| 147 | +// try { | |
| 148 | +// ob.get(position).pin(); | |
| 149 | +// } catch (ParseException e) { | |
| 150 | +// e.printStackTrace(); | |
| 151 | +// } | |
| 152 | +// bundle.putString("politico", ob.get(position).getObjectId()); | |
| 153 | +// frag.setArguments(bundle); | |
| 154 | +// FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); | |
| 155 | +// ft.replace(R.id.rl_fragment_container, frag, "politicoFrag"); | |
| 156 | +// ft.addToBackStack(null); | |
| 157 | +// ft.commit(); | |
| 158 | + } | |
| 159 | + | |
| 160 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/fragments/PoliticoFichaFragment.java
0 → 100644
| ... | ... | @@ -0,0 +1,153 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view.fragments; | |
| 2 | + | |
| 3 | +import android.content.DialogInterface; | |
| 4 | +import android.graphics.PorterDuff; | |
| 5 | +import android.graphics.drawable.LayerDrawable; | |
| 6 | +import android.os.Build; | |
| 7 | +import android.os.Bundle; | |
| 8 | +import android.support.design.widget.Snackbar; | |
| 9 | +import android.support.v4.app.Fragment; | |
| 10 | +import android.util.Log; | |
| 11 | +import android.view.LayoutInflater; | |
| 12 | +import android.view.View; | |
| 13 | +import android.view.ViewGroup; | |
| 14 | +import android.widget.Button; | |
| 15 | +import android.widget.ImageView; | |
| 16 | +import android.widget.RatingBar; | |
| 17 | +import android.widget.TextView; | |
| 18 | + | |
| 19 | +import com.crashlytics.android.answers.Answers; | |
| 20 | +import com.crashlytics.android.answers.ContentViewEvent; | |
| 21 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 22 | +import com.monitorabrasil.monitoralegislativo.application.MyApp; | |
| 23 | +import com.monitorabrasil.monitoralegislativo.view.dialogs.DialogAvaliacao; | |
| 24 | +import com.parse.ParseException; | |
| 25 | +import com.parse.ParseObject; | |
| 26 | +import com.parse.ParseQuery; | |
| 27 | +import com.parse.ParseUser; | |
| 28 | + | |
| 29 | +/** | |
| 30 | + * Created by geral_000 on 20/06/2015. | |
| 31 | + */ | |
| 32 | +public class PoliticoFichaFragment extends Fragment { | |
| 33 | + | |
| 34 | + | |
| 35 | + private ParseObject politico; | |
| 36 | + private View mView; | |
| 37 | + private RatingBar mRatingBar; | |
| 38 | + private Button btnAvaliar; | |
| 39 | + | |
| 40 | + | |
| 41 | + public View onCreateView(LayoutInflater inflater, | |
| 42 | + ViewGroup container, | |
| 43 | + Bundle savedInstanceState) { | |
| 44 | + View view = inflater.inflate(R.layout.fragment_politico_detalhe, container, false); | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + mView=view; | |
| 49 | + mRatingBar = (RatingBar)view.findViewById(R.id.ratingBar); | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + Bundle bundle = getArguments(); | |
| 56 | + politico = buscaPolitico(bundle.getString("politico")) ; | |
| 57 | + | |
| 58 | + Answers.getInstance().logContentView(new ContentViewEvent() | |
| 59 | + .putContentName("PoliticoFichaFragment") | |
| 60 | + .putContentType("Fragment") | |
| 61 | + .putCustomAttribute("vereador",politico.getString("nome"))); | |
| 62 | + | |
| 63 | + | |
| 64 | + mRatingBar.setRating((float) politico.getDouble("avaliacao")); | |
| 65 | + | |
| 66 | + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ | |
| 67 | + LayerDrawable stars = (LayerDrawable) mRatingBar.getProgressDrawable(); | |
| 68 | + stars.getDrawable(2).setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.SRC_ATOP); | |
| 69 | + stars.getDrawable(1).setColorFilter(getResources().getColor(R.color.colorAccent), PorterDuff.Mode.SRC_ATOP); | |
| 70 | + stars.getDrawable(0).setColorFilter(getResources().getColor(R.color.coloLink), PorterDuff.Mode.SRC_ATOP); | |
| 71 | + } | |
| 72 | + | |
| 73 | + | |
| 74 | + //btnAvaliar | |
| 75 | + btnAvaliar = (Button) view.findViewById(R.id.btnAvalie); | |
| 76 | + btnAvaliar.setOnClickListener(new View.OnClickListener() { | |
| 77 | + @Override | |
| 78 | + public void onClick(final View v) { | |
| 79 | + if(ParseUser.getCurrentUser() != null){ | |
| 80 | + DialogAvaliacao avaliacao =new DialogAvaliacao(politico, "Avalie"); | |
| 81 | + avaliacao.setOnDismissListener(new DialogInterface.OnDismissListener() { | |
| 82 | + @Override | |
| 83 | + public void onDismiss(DialogInterface dialog) { | |
| 84 | + //atualizar a avaliacao | |
| 85 | + try { | |
| 86 | + politico.fetchFromLocalDatastore(); | |
| 87 | + mRatingBar.setRating((float) politico.getDouble("avaliacao")); | |
| 88 | + Snackbar.make(v, "Avaliação salva.", Snackbar.LENGTH_LONG) | |
| 89 | + .setAction("Action", null).show(); | |
| 90 | + } catch (ParseException e) { | |
| 91 | + e.printStackTrace(); | |
| 92 | + } | |
| 93 | + | |
| 94 | + } | |
| 95 | + }); | |
| 96 | + avaliacao.show(getActivity().getFragmentManager(), "dialogAvaliar"); | |
| 97 | + }else{ | |
| 98 | + Snackbar.make(v, "É necessário logar para avaliar.", Snackbar.LENGTH_LONG) | |
| 99 | + .setAction("Action", null).show(); | |
| 100 | + } | |
| 101 | + | |
| 102 | + } | |
| 103 | + }); | |
| 104 | + | |
| 105 | + //foto | |
| 106 | + ImageView foto = (ImageView)view.findViewById(R.id.foto); | |
| 107 | + MyApp.getInstance().getmImagemLoader().displayImage(MyApp.URL_FOTO+politico.get("cpf")+".jpg",foto); | |
| 108 | + | |
| 109 | + //nome | |
| 110 | + TextView txtNome = (TextView) view.findViewById(R.id.txtNome); | |
| 111 | + txtNome.setText(politico.get("nome").toString()); | |
| 112 | + | |
| 113 | + //telefone | |
| 114 | + TextView telefone = (TextView) view.findViewById(R.id.txtTelefone); | |
| 115 | + telefone.setText(politico.get("telefone").toString()); | |
| 116 | + //telefone | |
| 117 | + TextView txtPartido = (TextView) view.findViewById(R.id.txtPartido); | |
| 118 | + txtPartido.setText(politico.get("partido").toString()); | |
| 119 | ||
| 120 | + TextView email = (TextView) view.findViewById(R.id.email); | |
| 121 | + email.setText(politico.get("email").toString()); | |
| 122 | ||
| 123 | + TextView facebook = (TextView) view.findViewById(R.id.facebook); | |
| 124 | + facebook.setText(politico.get("facebook").toString()); | |
| 125 | + //gastos | |
| 126 | + TextView gastos = (TextView) view.findViewById(R.id.gastos); | |
| 127 | + gastos.setText(politico.get("gasto_campanha").toString().replace(",","").replace(".",",")); | |
| 128 | + //bens declarados | |
| 129 | + TextView bens = (TextView) view.findViewById(R.id.bens); | |
| 130 | + bens.setText(politico.get("bens_declarados").toString().replace(",", "").replace(".",",")); | |
| 131 | + | |
| 132 | + return view; | |
| 133 | + } | |
| 134 | + | |
| 135 | + @Override | |
| 136 | + public void onResume() { | |
| 137 | + Log.e("DEBUG", "onResume of HomeFragment"); | |
| 138 | + super.onResume(); | |
| 139 | + } | |
| 140 | + | |
| 141 | + | |
| 142 | + private ParseObject buscaPolitico(String id) { | |
| 143 | + | |
| 144 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("Politico"); | |
| 145 | + query.fromLocalDatastore(); | |
| 146 | + try { | |
| 147 | + return query.get(id); | |
| 148 | + } catch (com.parse.ParseException e) { | |
| 149 | + e.printStackTrace(); | |
| 150 | + } | |
| 151 | + return null; | |
| 152 | + } | |
| 153 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/view/interfaces/RecyclerViewOnClickListenerHack.java
0 → 100644
| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.view.interfaces; | |
| 2 | + | |
| 3 | +import android.view.View; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * Created by viniciusthiengo on 4/5/15. | |
| 7 | + */ | |
| 8 | +public interface RecyclerViewOnClickListenerHack { | |
| 9 | + public void onClickListener(View view, int position); | |
| 10 | +} | ... | ... |
app/src/main/res/layout/activity_comentario.xml
| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | android:layout_width="match_parent" |
| 6 | 6 | android:layout_height="match_parent" |
| 7 | 7 | android:orientation="vertical" |
| 8 | - tools:context="com.monitorabrasil.monitoralegislativo.ComentarioActivity"> | |
| 8 | + tools:context="com.monitorabrasil.monitoralegislativo.view.ComentarioActivity"> | |
| 9 | 9 | |
| 10 | 10 | <android.support.v7.widget.Toolbar |
| 11 | 11 | android:id="@+id/tb_main" | ... | ... |
app/src/main/res/layout/activity_login.xml
| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | android:layout_height="match_parent" |
| 7 | 7 | android:background="@color/grey" |
| 8 | 8 | android:orientation="vertical" |
| 9 | - tools:context="com.monitorabrasil.monitoralegislativo.LoginActivity" | |
| 9 | + tools:context="com.monitorabrasil.monitoralegislativo.view.LoginActivity" | |
| 10 | 10 | android:paddingTop="8dp"> |
| 11 | 11 | |
| 12 | 12 | <android.support.v7.widget.Toolbar | ... | ... |
| ... | ... | @@ -0,0 +1,132 @@ |
| 1 | +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 2 | + xmlns:tools="http://schemas.android.com/tools" | |
| 3 | + xmlns:app="http://schemas.android.com/apk/res-auto" | |
| 4 | + xmlns:fab="http://schemas.android.com/apk/res-auto" | |
| 5 | + android:layout_width="match_parent" | |
| 6 | + android:layout_height="match_parent" | |
| 7 | + android:background="@color/grey" | |
| 8 | + android:orientation="vertical" | |
| 9 | + tools:context="com.monitorabrasil.monitoralegislativo.view.Login2Activity" | |
| 10 | + android:paddingTop="8dp"> | |
| 11 | + | |
| 12 | + <android.support.v7.widget.Toolbar | |
| 13 | + android:id="@+id/toolbar" | |
| 14 | + android:elevation="0dp" | |
| 15 | + android:layout_height="?attr/actionBarSize" | |
| 16 | + android:layout_width="match_parent" | |
| 17 | + android:minHeight="?attr/actionBarSize" | |
| 18 | + android:layout_alignParentLeft="true" | |
| 19 | + android:background="?attr/colorPrimary" | |
| 20 | + app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" /> | |
| 21 | + | |
| 22 | + <!-- Login progress --> | |
| 23 | + <ProgressBar android:id="@+id/login_progress" style="?android:attr/progressBarStyleLarge" | |
| 24 | + android:layout_width="wrap_content" android:layout_height="wrap_content" | |
| 25 | + android:layout_marginBottom="8dp" android:visibility="gone" | |
| 26 | + android:layout_gravity="center_horizontal" /> | |
| 27 | + | |
| 28 | + <ScrollView android:id="@+id/login_form" android:layout_width="match_parent" | |
| 29 | + android:layout_height="match_parent"> | |
| 30 | + | |
| 31 | + <LinearLayout android:id="@+id/email_login_form" android:layout_width="match_parent" | |
| 32 | + android:layout_height="wrap_content" android:orientation="vertical"> | |
| 33 | + <ImageButton | |
| 34 | + android:layout_width="50dp" | |
| 35 | + android:paddingTop="5dp" | |
| 36 | + android:layout_height="50dp" | |
| 37 | + android:visibility="gone" | |
| 38 | + android:layout_gravity="center" | |
| 39 | + android:background="@drawable/person_1" | |
| 40 | + android:id="@+id/btnFoto"/> | |
| 41 | + <android.support.design.widget.TextInputLayout | |
| 42 | + android:layout_width="match_parent" | |
| 43 | + android:layout_height="wrap_content"> | |
| 44 | + <EditText | |
| 45 | + android:layout_width="match_parent" | |
| 46 | + android:layout_height="wrap_content" | |
| 47 | + android:hint="@string/nome" | |
| 48 | + android:id="@+id/txtNome" /> | |
| 49 | + </android.support.design.widget.TextInputLayout> | |
| 50 | + | |
| 51 | + <android.support.design.widget.TextInputLayout | |
| 52 | + android:layout_width="match_parent" | |
| 53 | + android:layout_height="wrap_content"> | |
| 54 | + <AutoCompleteTextView android:id="@+id/email" android:layout_width="match_parent" | |
| 55 | + android:layout_height="wrap_content" android:hint="@string/prompt_email" | |
| 56 | + android:inputType="textEmailAddress" android:maxLines="1" | |
| 57 | + android:singleLine="true" /> | |
| 58 | + </android.support.design.widget.TextInputLayout> | |
| 59 | + <android.support.design.widget.TextInputLayout | |
| 60 | + android:layout_width="match_parent" | |
| 61 | + android:layout_height="wrap_content"> | |
| 62 | + <EditText android:id="@+id/password" android:layout_width="match_parent" | |
| 63 | + android:layout_height="wrap_content" android:hint="@string/prompt_password" | |
| 64 | + android:imeActionId="@+id/login" | |
| 65 | + android:imeActionLabel="@string/action_sign_in_short" | |
| 66 | + android:imeOptions="actionUnspecified" android:inputType="textPassword" | |
| 67 | + android:maxLines="1" android:singleLine="true" /> | |
| 68 | + </android.support.design.widget.TextInputLayout> | |
| 69 | + | |
| 70 | + <Button android:id="@+id/email_sign_in_button" style="?android:textAppearanceSmall" | |
| 71 | + android:layout_width="match_parent" android:layout_height="wrap_content" | |
| 72 | + android:layout_marginTop="16dp" android:text="@string/action_sign_in" | |
| 73 | + android:textStyle="bold" /> | |
| 74 | + | |
| 75 | + <Button android:id="@+id/login_twitter" style="?android:textAppearanceSmall" | |
| 76 | + android:layout_width="match_parent" android:layout_height="wrap_content" | |
| 77 | + android:layout_marginTop="16dp" android:text="@string/login_twitter" | |
| 78 | + android:textStyle="bold" /> | |
| 79 | + | |
| 80 | + <Button android:id="@+id/fazer_cadastro" style="?android:textAppearanceSmall" | |
| 81 | + android:layout_width="match_parent" android:layout_height="wrap_content" | |
| 82 | + android:layout_marginTop="16dp" android:text="@string/fazer_cadastro" | |
| 83 | + android:textStyle="bold" /> | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + </LinearLayout> | |
| 88 | + | |
| 89 | + | |
| 90 | + </ScrollView> | |
| 91 | + <ScrollView android:id="@+id/logout_form" android:layout_width="match_parent" | |
| 92 | + android:layout_height="match_parent"> | |
| 93 | + <LinearLayout android:id="@+id/email_logout_form" android:layout_width="match_parent" | |
| 94 | + android:layout_height="wrap_content" android:orientation="vertical"> | |
| 95 | + | |
| 96 | + <ImageView | |
| 97 | + android:layout_width="100dp" | |
| 98 | + android:layout_height="100dp" | |
| 99 | + android:id="@+id/foto" | |
| 100 | + android:layout_gravity="center_horizontal" | |
| 101 | + android:layout_marginTop="20dp" /> | |
| 102 | + | |
| 103 | + <TextView | |
| 104 | + android:layout_width="wrap_content" | |
| 105 | + android:layout_height="wrap_content" | |
| 106 | + android:textAppearance="?android:attr/textAppearanceMedium" | |
| 107 | + android:text="Medium Text" | |
| 108 | + android:id="@+id/lblNome" | |
| 109 | + android:layout_gravity="center_horizontal" /> | |
| 110 | + <TextView | |
| 111 | + android:layout_width="wrap_content" | |
| 112 | + android:layout_height="wrap_content" | |
| 113 | + android:textAppearance="?android:attr/textAppearanceMedium" | |
| 114 | + android:text="Medium Text" | |
| 115 | + android:id="@+id/lblEmail" | |
| 116 | + android:layout_gravity="center_horizontal" /> | |
| 117 | + <Button | |
| 118 | + style="?android:textAppearanceSmall" | |
| 119 | + android:id="@+id/btnLogout" | |
| 120 | + android:layout_width="match_parent" | |
| 121 | + android:layout_height="wrap_content" | |
| 122 | + android:layout_marginTop="16dp" | |
| 123 | + android:text="@string/logout" | |
| 124 | + android:textStyle="bold" /> | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + </LinearLayout> | |
| 129 | + </ScrollView> | |
| 130 | + | |
| 131 | +</LinearLayout> | |
| 132 | + | ... | ... |
app/src/main/res/layout/fragment_home.xml
| 1 | 1 | <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| 2 | 2 | xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" |
| 3 | 3 | android:layout_height="match_parent" |
| 4 | - tools:context="com.monitorabrasil.monitoralegislativo.fragments.HomeFragment"> | |
| 4 | + tools:context="com.monitorabrasil.monitoralegislativo.view.fragments.HomeFragment"> | |
| 5 | 5 | <android.support.v4.widget.NestedScrollView |
| 6 | 6 | |
| 7 | 7 | android:layout_width="match_parent" | ... | ... |
app/src/main/res/menu/menu_camara.xml
| 1 | 1 | <menu xmlns:android="http://schemas.android.com/apk/res/android" |
| 2 | 2 | xmlns:app="http://schemas.android.com/apk/res-auto" |
| 3 | 3 | xmlns:tools="http://schemas.android.com/tools" |
| 4 | - tools:context="com.monitorabrasil.monitoralegislativo.CamaraActivity"> | |
| 4 | + tools:context="com.monitorabrasil.monitoralegislativo.view.CamaraActivity"> | |
| 5 | 5 | |
| 6 | 6 | </menu> | ... | ... |
app/src/main/res/menu/menu_comentario.xml
| 1 | 1 | <menu xmlns:android="http://schemas.android.com/apk/res/android" |
| 2 | 2 | xmlns:app="http://schemas.android.com/apk/res-auto" |
| 3 | 3 | xmlns:tools="http://schemas.android.com/tools" |
| 4 | - tools:context="com.monitorabrasil.monitoralegislativo.ComentarioActivity"> | |
| 4 | + tools:context="com.monitorabrasil.monitoralegislativo.view.ComentarioActivity"> | |
| 5 | 5 | |
| 6 | 6 | </menu> | ... | ... |
| ... | ... | @@ -0,0 +1,7 @@ |
| 1 | +<menu xmlns:android="http://schemas.android.com/apk/res/android" | |
| 2 | + xmlns:app="http://schemas.android.com/apk/res-auto" | |
| 3 | + xmlns:tools="http://schemas.android.com/tools" | |
| 4 | + tools:context="com.monitorabrasil.monitoralegislativo.view.Login2Activity"> | |
| 5 | + <item android:id="@+id/action_settings" android:title="@string/action_settings" | |
| 6 | + android:orderInCategory="100" app:showAsAction="never" /> | |
| 7 | +</menu> | ... | ... |
app/src/main/res/menu/menu_politico_ficha.xml
| 1 | 1 | <menu xmlns:android="http://schemas.android.com/apk/res/android" |
| 2 | 2 | xmlns:app="http://schemas.android.com/apk/res-auto" |
| 3 | 3 | xmlns:tools="http://schemas.android.com/tools" |
| 4 | - tools:context="com.monitorabrasil.monitoralegislativo.PoliticoFichaActivity"> | |
| 4 | + tools:context="com.monitorabrasil.monitoralegislativo.view.PoliticoFichaActivity"> | |
| 5 | 5 | |
| 6 | 6 | </menu> | ... | ... |
app/src/main/res/menu/menu_politicos.xml
| 1 | 1 | <menu xmlns:android="http://schemas.android.com/apk/res/android" |
| 2 | 2 | xmlns:app="http://schemas.android.com/apk/res-auto" |
| 3 | 3 | xmlns:tools="http://schemas.android.com/tools" |
| 4 | - tools:context="com.monitorabrasil.monitoralegislativo.PoliticosActivity"> | |
| 4 | + tools:context="com.monitorabrasil.monitoralegislativo.view.PoliticosActivity"> | |
| 5 | 5 | |
| 6 | 6 | </menu> | ... | ... |
app/src/main/res/menu/menu_projetos.xml
| 1 | 1 | <menu xmlns:android="http://schemas.android.com/apk/res/android" |
| 2 | 2 | xmlns:app="http://schemas.android.com/apk/res-auto" |
| 3 | 3 | xmlns:tools="http://schemas.android.com/tools" |
| 4 | - tools:context="com.monitorabrasil.monitoralegislativo.ProjetosActivity"> | |
| 4 | + tools:context="com.monitorabrasil.monitoralegislativo.view.ProjetosActivity"> | |
| 5 | 5 | |
| 6 | 6 | </menu> | ... | ... |
app/src/main/res/menu/menu_sobre.xml
| 1 | 1 | <menu xmlns:android="http://schemas.android.com/apk/res/android" |
| 2 | 2 | xmlns:app="http://schemas.android.com/apk/res-auto" |
| 3 | 3 | xmlns:tools="http://schemas.android.com/tools" |
| 4 | - tools:context="com.monitorabrasil.monitoralegislativo.SobreActivity"> | |
| 4 | + tools:context="com.monitorabrasil.monitoralegislativo.view.SobreActivity"> | |
| 5 | 5 | |
| 6 | 6 | </menu> | ... | ... |
app/src/main/res/values/strings.xml
| ... | ... | @@ -27,5 +27,6 @@ |
| 27 | 27 | <string name="sobre">O ParticipaCidadão é um aplicativo em fase experimental destinado a tornar mais fácil e atraente a conexão/interação do cidadão com a Câmara de Vereadores e com temas públicos. Em outras palavras, é também uma plataforma de cidadania e democracia para o cidadão que quer participar mais ativamente do desenvolvimento de sua cidade.\n\n Essa versão piloto, por enquanto, só disponibiliza os dados da Câmara Municipal de Ouro Branco/MG. Entretanto, gradativamente, outros municípios serão incluídos na base de dados. \n\n Mais do que um aplicativo, é uma atitude! Participe! Venha construir conosco as cidades do Brasil de 2030.</string> |
| 28 | 28 | <string name="credito">Agradecimentos:\nWesley Rocha wesleyweb@gmail.com - criador da marca e logo</string> |
| 29 | 29 | <string name="menu_search">Procura</string> |
| 30 | + <string name="title_activity_login2">Login2Activity</string> | |
| 30 | 31 | |
| 31 | 32 | </resources> | ... | ... |