showFiltersBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ArrayList<String> cities = new ArrayList<>();
try {
Pair<ArrayList<String>, Integer> cityListGetResult = objectDataExchange.cityListGet(getContext(), sharedPreferences.getLong("id", 0));
if (cityListGetResult.second != null) {
toastCreator.createToast(getContext(), getLayoutInflater(), getResources().getStringArray(R.array.errors)[cityListGetResult.second]);
return;
}
else {
cities.addAll(cityListGetResult.first);
}
} catch (IOException e) {
throw new RuntimeException(e);
} catch (JSONException e) {
throw new RuntimeException(e);
}
cities.add(getContext().getString(R.string.ObjectCityFilterEdit));
ArrayAdapter<String> citiesAdapter = new ArrayAdapter<String>(getContext(), R.layout.city_dropdown_item, cities) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
if (position == getCount()) {
((TextView)v.findViewById(android.R.id.text1)).setText("");
((TextView)v.findViewById(android.R.id.text1)).setHint(cities.get(getCount())); //"Hint to be displayed"
}
return v;
}
@Override
public int getCount() {
return super.getCount()-1; // you dont display last item. It is used as hint.
}
};
cityFilterSpinner.setAdapter(citiesAdapter);
cityFilterSpinner.setSelection(citiesAdapter.getPosition(filters.get("city")));
//mainActivity.getProfileBtn().setVisibility(View.GONE);
filtersCard.setVisibility(View.VISIBLE);
closeFiltersBtn.setVisibility(View.VISIBLE);
clearFiltersBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cityFilterSpinner.setSelection(citiesAdapter.getCount());
addressIndexFilterEdit.setText(null);
filters.replace("addressIndex", getContext().getString(R.string.ObjectCityFilterEdit));
filters.replace("city", null);
}
});
closeFiltersBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
filtersCard.setVisibility(View.GONE);
closeFiltersBtn.setVisibility(View.GONE);
}
});
}
});
ListOfWorkersFragment listOfWorkersFragment = new ListOfWorkersFragment();
ChangePasswordFragment changePasswordFragment = new ChangePasswordFragment();
ListOfObjectsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
if (roleModel.HaveAccess(context, "***url***")) {
Pair<Company, Integer> getCompanyResult = companyDataExchange.CompanyDataGetByUser(getApplicationContext());
if (getCompanyResult.first != null) {
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.frameLayoutMain);
String tag = currentFragment.getTag();
menuController.changeFragment(tag, "listofobjects");
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.frameLayoutMain, listOfObjectsFragment, "listofobjects");
ft.commit();
}
else if (getCompanyResult.first == null && getCompanyResult.second == null) {
toastCreator.createToast(getApplicationContext(), getLayoutInflater(), getResources().getStringArray(R.array.errors)[15]);
}
else if (getCompanyResult.first == null && getCompanyResult.second != null) {
toastCreator.createToast(getApplicationContext(), getLayoutInflater(), getResources().getStringArray(R.array.errors)[getCompanyResult.second]);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
});
ListOfWorkersBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
if (roleModel.HaveAccess(context, "***url***")) {
Pair<Company, Integer> getCompanyResult = companyDataExchange.CompanyDataGetByUser(getApplicationContext());
if (getCompanyResult.first != null) {
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.frameLayoutMain);
String tag = currentFragment.getTag();
menuController.changeFragment(tag, "listofworkers");
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.frameLayoutMain, listOfWorkersFragment, "listofworkers");
ft.commit();
}
else if (getCompanyResult.first == null && getCompanyResult.second == null) {
toastCreator.createToast(getApplicationContext(), getLayoutInflater(), getResources().getStringArray(R.array.errors)[15]);
}
else if (getCompanyResult.first == null && getCompanyResult.second != null) {
toastCreator.createToast(getApplicationContext(), getLayoutInflater(), getResources().getStringArray(R.array.errors)[getCompanyResult.second]);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
});
showFiltersBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ArrayList<String> cities = new ArrayList<>();
try {
Pair<ArrayList<String>, Integer> cityListGetResult = objectDataExchange.cityListGet(getContext(), sharedPreferences.getLong("id", 0));
if (cityListGetResult.second != null) {
toastCreator.createToast(getContext(), getLayoutInflater(), getResources().getStringArray(R.array.errors)[cityListGetResult.second]);
return;
}
else {
cities.addAll(cityListGetResult.first);
}
} catch (IOException e) {
throw new RuntimeException(e);
} catch (JSONException e) {
throw new RuntimeException(e);
}
cities.add(getContext().getString(R.string.ObjectCityFilterEdit));
ArrayAdapter<String> citiesAdapter = new ArrayAdapter<String>(getContext(), R.layout.city_dropdown_item, cities) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
if (position == getCount()-1) {
((TextView)v.findViewById(android.R.id.text1)).setText("");
((TextView)v.findViewById(android.R.id.text1)).setHint(cities.get(getCount()-1)); //"Hint to be displayed"
}
return v;
}
@Override
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View v = super.getDropDownView(position, convertView, parent);
if (position == getCount()-1) {
return new View(getContext());
}
return v;
}
@Nullable
@Override
public String getItem(int position) {
return position != getCount() - 1 ? super.getItem(position) : "";
}
@Override
public int getCount() {
return super.getCount(); // you dont display last item. It is used as hint.
}
};
filtersCard.setVisibility(View.VISIBLE);
closeFiltersBtn.setVisibility(View.VISIBLE);
cityFilterSpinner.setAdapter(citiesAdapter);
cityFilterSpinner.setSelection(citiesAdapter.getCount()-1);
addressIndexFilterEdit.setText(null);
cityFilterSpinner.setSelection(citiesAdapter.getPosition(filters.get("city")));
addressIndexFilterEdit.setText(filters.get("addressIndex"));
//mainActivity.getProfileBtn().setVisibility(View.GONE);
clearFiltersBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cityFilterSpinner.setSelection(citiesAdapter.getCount());
addressIndexFilterEdit.setText(null);
filters.replace("addressIndex", getContext().getString(R.string.ObjectCityFilterEdit));
filters.replace("city", null);
}
});
closeFiltersBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
filtersCard.setVisibility(View.GONE);
closeFiltersBtn.setVisibility(View.GONE);
}
});
applyFiltersBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
filters.replace("addressIndex", addressIndexFilterEdit.getText().toString());
filters.replace("city", cityFilterSpinner.getSelectedItem().toString());
cityFilterSpinner.setSelection(citiesAdapter.getCount());
addressIndexFilterEdit.setText(null);
filtersCard.setVisibility(View.GONE);
closeFiltersBtn.setVisibility(View.GONE);
ShowObjects(searchPlain.getText().toString(), linear, sharedPreferences, ft);
//mainActivity.getProfileBtn().setVisibility(View.VISIBLE);
}
});
}
});