Skip to content

Commit

Permalink
Merge commit '515b7600a33f2ced5a15452e8b11af61e8fcfdc9'
Browse files Browse the repository at this point in the history
  • Loading branch information
andreanmasiro committed Oct 21, 2016
2 parents da29813 + 515b760 commit 814136b
Show file tree
Hide file tree
Showing 21 changed files with 452 additions and 116 deletions.
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
package com.mdsgpp.cidadedemocratica.instrumentation;

import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.assertThat;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasToString;


import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import android.widget.ListView;


import com.mdsgpp.cidadedemocratica.MainActivity;
import com.mdsgpp.cidadedemocratica.R;
import com.mdsgpp.cidadedemocratica.model.Proposal;
import com.mdsgpp.cidadedemocratica.model.TagListRow;
import com.mdsgpp.cidadedemocratica.persistence.DataContainer;
import com.mdsgpp.cidadedemocratica.persistence.DataUpdateListener;


import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

Expand All @@ -46,7 +37,7 @@ public class MainActivityTest {

@Test
public void shouldGetNewInstanceOfMainActivity() {
assertThat(mActivityRule.getActivity().findViewById(R.id.button2),isDisplayed());
assertThat(mActivityRule.getActivity().findViewById(R.id.button_tags),isDisplayed());
}

@Test
Expand Down Expand Up @@ -84,7 +75,7 @@ public void usersUpdated() {

latch.await(500, TimeUnit.SECONDS);

onView(withId(R.id.button2)).perform(click());
onView(withId(R.id.button_tags)).perform(click());
onView(withText("cidadania")).check(matches(isDisplayed()));

}
Expand Down
30 changes: 3 additions & 27 deletions app/src/main/java/com/mdsgpp/cidadedemocratica/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mdsgpp.cidadedemocratica;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
Expand All @@ -27,32 +28,17 @@ public class MainActivity extends AppCompatActivity {

ListView proposalListView;
final String proposalsEndpointUrl = "http://cidadedemocraticaapi.herokuapp.com/api/v0/proposals";
final String tagsEndpointUrl = "http://cidadedemocraticaapi.herokuapp.com/api/v0/tags";
final String taggingsEndpointUrl = "http://cidadedemocraticaapi.herokuapp.com/api/v0/taggings";
final String tagsUsersEndpointUrl = "http://cidadedemocraticaapi.herokuapp.com/api/v0/users";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// if (DataContainer.getInstance().getTags().size()==0){
// pullTagData();
// }
//
// if (DataContainer.getInstance().getProposals().size()==0){
// pullProposalData();
// }
//
// if (DataContainer.getInstance().getUsers().size()==0){
// pullUsersData();
// }

pullTagData();
pullProposalData();
pullUsersData();
//pullProposalData();
// Semaphore stops until loads tags & proposals
pullTagginsData();
//pullTagginsData();

}

Expand All @@ -61,21 +47,11 @@ public void pullProposalData() {
requester.request(Requester.RequestType.GET);
}

public void pullTagData() {
Requester requester = new Requester(tagsEndpointUrl, new TagRequestResponseHandler());
requester.request(Requester.RequestType.GET);
}

public void pullTagginsData() {
Requester requester = new Requester(taggingsEndpointUrl, new TaggingsRequestResponseHandler());
requester.request(Requester.RequestType.GET);
}

public void pullUsersData(){
Requester requester = new Requester(tagsUsersEndpointUrl, new UserRequestResponseHandler());
requester.request(Requester.RequestType.GET);
}

public void showProposalList(View view){
Intent proposalIntent = new Intent(this, ProposalsList.class);
startActivity(proposalIntent);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mdsgpp.cidadedemocratica.controller;

import android.app.ProgressDialog;
import android.content.Context;
import android.widget.Toast;

/**
* Created by luisresende on 18/10/16.
*/

public class FeedbackManager {

static public void createToast(Context context, String message){
Toast toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
toast.show();
}

static public ProgressDialog createProgressDialog (Context context, String message){
ProgressDialog dialog = new ProgressDialog(context);
dialog.setMessage(message);
dialog.show();
return dialog;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public View getView(int i, View view, ViewGroup viewGroup) {
ProposalListRow row;
Proposal currentProposal = data.get(i);

if(view == null){
if(view == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.proposal_list_row,viewGroup,false);
row = new ProposalListRow();
row.titleTextView = (TextView) view.findViewById(R.id.titleTextView);
row.descriptionTextView = (TextView) view.findViewById(R.id.descriptionTextView);
view.setTag(row);

}else{
} else {
row = (ProposalListRow)view.getTag();

}
Expand All @@ -67,4 +67,9 @@ public View getView(int i, View view, ViewGroup viewGroup) {

return view;
}

public void updateData(ArrayList<Proposal> data) {
this.data = data;
notifyDataSetChanged();
}
}
Original file line number Diff line number Diff line change
@@ -1,52 +1,100 @@
package com.mdsgpp.cidadedemocratica.controller;

import android.app.ProgressDialog;
import android.net.Uri;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;

import com.mdsgpp.cidadedemocratica.External.SlidingTabLayout;
import com.mdsgpp.cidadedemocratica.R;

import com.mdsgpp.cidadedemocratica.persistence.DataContainer;
import com.mdsgpp.cidadedemocratica.requester.ProposalRequestResponseHandler;
import com.mdsgpp.cidadedemocratica.requester.RequestUpdateListener;
import com.mdsgpp.cidadedemocratica.requester.Requester;
import com.mdsgpp.cidadedemocratica.view.ListProposalFragment;


public class ProposalsList extends AppCompatActivity implements ListProposalFragment.OnFragmentInteractionListener{

private int numberTabs = 3;
public class ProposalsList extends AppCompatActivity implements ListProposalFragment.OnFragmentInteractionListener, RequestUpdateListener {

private int numberOfTabs = 3;
private ProgressDialog progressDialog;
private ViewPagerAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_proposals_list);
if (DataContainer.getInstance().getUsers().size() == 0) {
pullProposalsData();
} else {
loadProposalsList();
}
}


@Override
public void onFragmentInteraction(Uri uri) {

}

public void pullProposalsData() {
if (progressDialog == null) {
progressDialog = FeedbackManager.createProgressDialog(this, getString(R.string.message_load_proposals));
}
ProposalRequestResponseHandler proposalRequestResponseHandler = new ProposalRequestResponseHandler();
setDataUpdateListener(proposalRequestResponseHandler);

Requester requester = new Requester(ProposalRequestResponseHandler.proposalsEndpointUrl, proposalRequestResponseHandler);
requester.setParameter("page", String.valueOf(ProposalRequestResponseHandler.nextPageToRequest));
requester.request(Requester.RequestType.GET);
}

CharSequence titles[] = {getString(R.string.titulo_tab_tudo),getString(R.string.titulo_tab_porAqui),
getString(R.string.titulo_tab_localidade)};
private void loadProposalsList() {

ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager(),titles,numberTabs);
CharSequence titles[] = {getString(R.string.titulo_tab_tudo), getString(R.string.titulo_tab_porAqui),
getString(R.string.titulo_tab_localidade)};

ViewPager pager = (ViewPager)findViewById(R.id.pager);
if (adapter == null) {
adapter = new ViewPagerAdapter(getSupportFragmentManager(), titles, numberOfTabs);
}

ViewPager pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(adapter);

SlidingTabLayout tabs = (SlidingTabLayout) findViewById(R.id.tabs);
tabs.setDistributeEvenly(true);

tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer(){
tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
@Override
public int getIndicatorColor(int position){
public int getIndicatorColor(int position) {
return getResources().getColor(R.color.colorAccent);
}
});

tabs.setViewPager(pager);
}

public void setDataUpdateListener(ProposalRequestResponseHandler handler) {
handler.setRequestUpdateListener(this);
}

public void afterSuccess() {
progressDialog.dismiss();
loadProposalsList();
createToast(getString(R.string.message_success_load_proposals));
ProposalRequestResponseHandler.nextPageToRequest++;
}

@Override
public void onFragmentInteraction(Uri uri) {


private void createToast(String message) {
FeedbackManager.createToast(this, message);
}

public void afterError(String message) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ public View getView(int i, View view, ViewGroup viewGroup) {

return view;
}

public void updateData(ArrayList<Tag> data) {
this.data = data;
notifyDataSetChanged();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mdsgpp.cidadedemocratica.controller;

import android.app.ProgressDialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
Expand All @@ -13,6 +14,9 @@
import com.mdsgpp.cidadedemocratica.model.Proposal;
import com.mdsgpp.cidadedemocratica.model.Tag;
import com.mdsgpp.cidadedemocratica.persistence.DataContainer;
import com.mdsgpp.cidadedemocratica.requester.ProposalRequestResponseHandler;
import com.mdsgpp.cidadedemocratica.requester.Requester;
import com.mdsgpp.cidadedemocratica.requester.TaggingsRequestResponseHandler;

import java.util.ArrayList;

Expand All @@ -25,6 +29,7 @@ public class TagginsList extends AppCompatActivity implements View.OnClickListen
Button shareButton;

Proposal proposal;
ProgressDialog progressDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -83,6 +88,18 @@ private void shareProposal(){
startActivity(Intent.createChooser(intentShare,getString(R.string.name_action_share)));
}

private void pullTaggingsData() {
progressDialog = FeedbackManager.createProgressDialog(this, getString(R.string.message_load_proposals));
TaggingsRequestResponseHandler taggingsRequestResponseHandler = new TaggingsRequestResponseHandler();
setDataUpdateListener(taggingsRequestResponseHandler);
Requester requester = new Requester(ProposalRequestResponseHandler.proposalsEndpointUrl, taggingsRequestResponseHandler);
requester.request(Requester.RequestType.GET);
}

private void setDataUpdateListener(TaggingsRequestResponseHandler handler) {

}

@Override
public void onClick(View view) {
switch (view.getId()){
Expand Down
Loading

0 comments on commit 814136b

Please sign in to comment.