Created
December 18, 2016 05:56
-
-
Save iahmedhendi/789d93f83064decd71feff3978eac1e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void loadSpinners() { | |
dialog = ProgressDialog.show(AddVisitActivity.this, "", getResources().getString(R.string.loading), true); | |
WebService.getService().getLocations().enqueue(new Callback<LocationListResponse>() { | |
@Override | |
public void onResponse(Call<LocationListResponse> call, Response<LocationListResponse> response) { | |
countries = response.body().getCountry(); | |
cities = response.body().getCity(); | |
categories = response.body().getLandmarkCategory(); | |
landmarks = response.body().getLandmark(); | |
LocationListResponse.Country header = new LocationListResponse.Country(); | |
header.setEnName(AddVisitActivity.this.getResources().getString(R.string.countryh)); | |
countries.add(0, header); | |
spinnerCountry.setAdapter(new ArrayAdapter<>(AddVisitActivity.this, android.R.layout.simple_list_item_1, countries)); | |
spinnerCountry.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | |
@Override | |
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | |
LocationListResponse.Country country = countries.get(position); | |
int cid = country.getOId(); | |
List<LocationListResponse.City> newcities = getCitiesofCountry(cid, cities); | |
spinnerCities.setAdapter(new ArrayAdapter<>(AddVisitActivity.this, android.R.layout.simple_list_item_1, newcities)); | |
} | |
@Override | |
public void onNothingSelected(AdapterView<?> parent) { | |
} | |
}); | |
LocationListResponse.LandmarkCategory header2 = new LocationListResponse.LandmarkCategory(); | |
header2.setEnName(AddVisitActivity.this.getResources().getString(R.string.categoryh)); | |
categories.add(0, header2); | |
spinnerLandmarkCategory.setAdapter(new ArrayAdapter<>(AddVisitActivity.this, android.R.layout.simple_list_item_1, categories)); | |
spinnerLandmarkCategory.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | |
@Override | |
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | |
LocationListResponse.LandmarkCategory landmarkCategory = categories.get(position); | |
int catid = landmarkCategory.getOId(); | |
List<LocationListResponse.Landmark> newLandMarks = getLandMarksofCategory(catid, landmarks); | |
spinnerLandmark.setAdapter(new ArrayAdapter<>(AddVisitActivity.this, android.R.layout.simple_list_item_1, newLandMarks)); | |
} | |
@Override | |
public void onNothingSelected(AdapterView<?> parent) { | |
} | |
}); | |
dialog.dismiss(); | |
} | |
@Override | |
public void onFailure(Call<LocationListResponse> call, Throwable t) { | |
dialog.dismiss(); | |
} | |
}); | |
} | |
private List<LocationListResponse.City> getCitiesofCountry(int countryID, List<LocationListResponse.City> sourcCities) { | |
List<LocationListResponse.City> citiesofc = new ArrayList<>(); | |
for (int i = 0; i < sourcCities.size(); i++) { | |
LocationListResponse.City current = sourcCities.get(i); | |
if (current.getCountryId() == countryID) { | |
citiesofc.add(current); | |
} | |
} | |
LocationListResponse.City header = new LocationListResponse.City(); | |
header.setEnName(AddVisitActivity.this.getResources().getString(R.string.city)); | |
citiesofc.add(0, header); | |
return citiesofc; | |
} | |
private List<LocationListResponse.Landmark> getLandMarksofCategory(int categoryID, List<LocationListResponse.Landmark> sourcLandmarks) { | |
List<LocationListResponse.Landmark> landmarkofc = new ArrayList<>(); | |
for (int i = 0; i < sourcLandmarks.size(); i++) { | |
LocationListResponse.Landmark current = sourcLandmarks.get(i); | |
if (current.getCategoryId() == categoryID) { | |
landmarkofc.add(current); | |
} | |
} | |
LocationListResponse.Landmark header = new LocationListResponse.Landmark(); | |
header.setEnName(AddVisitActivity.this.getResources().getString(R.string.landmarkheader)); | |
landmarkofc.add(0, header); | |
return landmarkofc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment