Skip to content

Commit

Permalink
V1.0 DONE.
Browse files Browse the repository at this point in the history
  • Loading branch information
frapsMatheus committed Jul 15, 2016
1 parent a3f96b7 commit 9c586a2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Observer;
import java.util.TreeMap;

Expand Down Expand Up @@ -217,7 +220,8 @@ public LinkedHashMap<PostoDeSaude,Double> getPostosCloseToLocation(LatLng positi
}
}
// TODO: ORDENAR ISSO AQUI
return postosNaLocalizacao;
return _orderPostosPorDistancia(postosNaLocalizacao);

}

public LinkedHashMap<PostoDeSaude,Double> getPostosPreferidosComDistancia(LatLng position , LinkedHashMap<String, PostoDeSaude> postos)
Expand All @@ -238,12 +242,50 @@ public LinkedHashMap<PostoDeSaude,Double> getPostosPreferidosComDistancia(LatLng

}
// TODO: ORDENAR ISSO AQUI
return postosNaLocalizacao;
return _orderPostosPorDistancia(postosNaLocalizacao);
}

public LinkedHashMap<PostoDeSaude,Double> getPostosCloseToLocation(LatLng position)
{
return getPostosCloseToLocation(position,mPostosDeSaude);
}
public LinkedHashMap<PostoDeSaude,Double> getAllPostosWithLocation(LatLng position)
{
final LinkedHashMap<PostoDeSaude,Double> postosWithLocation = new LinkedHashMap<>();
Location myLocation = new Location("");
myLocation.setLatitude(position.latitude);
myLocation.setLongitude(position.longitude);
for (PostoDeSaude posto : mPostosDeSaude.values()) {
Location currentLocation = new Location("");
currentLocation.setLatitude(posto.location.get(0));
currentLocation.setLongitude(posto.location.get(1));
double distance = myLocation.distanceTo(currentLocation);
postosWithLocation.put(posto, distance);
}
// TODO: ORDENAR ISSO AQUI
return _orderPostosPorDistancia(postosWithLocation);
}

private LinkedHashMap<PostoDeSaude, Double> _orderPostosPorDistancia(LinkedHashMap<PostoDeSaude, Double> postos)
{
LinkedHashMap<PostoDeSaude, Double> postosOrdenados = new LinkedHashMap<>();

List<Map.Entry<PostoDeSaude, Double>> list =
new LinkedList<Map.Entry<PostoDeSaude, Double>>( postos.entrySet() );
Collections.sort( list, new Comparator<Map.Entry<PostoDeSaude, Double>>()
{
@Override
public int compare(Map.Entry<PostoDeSaude, Double> o1, Map.Entry<PostoDeSaude, Double> o2) {
return (o1.getValue()).compareTo( o2.getValue() );
}
} );

for (Map.Entry<PostoDeSaude, Double> entry : list)
{
postosOrdenados.put( entry.getKey(), entry.getValue() );
}
return postosOrdenados;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
View itemView = holder.itemView;
final PostoDeSaude posto = mPostosDeSaude.get(position);
((MeusPostosViewHolder)holder).setView(posto, mPostosSelected.get(posto.uid));
CompoundButton.OnCheckedChangeListener check = new CompoundButton.OnCheckedChangeListener() {
CompoundButton.OnClickListener check = new View.OnClickListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
mPostosSelected.put(posto.uid, b);
public void onClick(View view) {
mPostosSelected.put(posto.uid, !mPostosSelected.get(posto.uid));
}
};
((MeusPostosViewHolder)holder).setOnClickCheckBox(check);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class MeusPostosFragment extends Fragment implements DBObserver {

private RecyclerView.LayoutManager mRecyclerLayout;
private ArrayList<PostoDeSaude> mPostoSearch;

private MeusPostosAdapter mAdapter;
private FloatingActionButton mDone;
boolean mFirstTime = true;
Expand Down Expand Up @@ -127,7 +128,9 @@ public void onStart() {
private void searchList(String text)
{
// TODO: Add section
ArrayList<PostoDeSaude> postosAtuais = new ArrayList<PostoDeSaude>(mPostosInitialList.values());
ArrayList<PostoDeSaude> postosAtuais =
new ArrayList<>(DBMain.shared().getAllPostosWithLocation(
DBUser.shared().lastKnowLocation).keySet());
mPostoSearch = new ArrayList<PostoDeSaude>();
for (PostoDeSaude posto : postosAtuais) {
if (posto.nome.toLowerCase().contains(text.toLowerCase()) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public void setView(PostoDeSaude posto, boolean state)
mCheckBox.setChecked(state);
}

public void setOnClickCheckBox(CompoundButton.OnCheckedChangeListener onChecked )
public void setOnClickCheckBox(View.OnClickListener onChecked )
{
mCheckBox.setOnCheckedChangeListener(onChecked);
mCheckBox.setOnClickListener(onChecked);
}
}

0 comments on commit 9c586a2

Please sign in to comment.