use of io.jawg.osmcontributor.ui.dialogs.EditDaysDialogFragment in project osm-contributor by jawg.
the class OpeningHoursLinearLayoutAdapter method initEditOpeningHours.
private void initEditOpeningHours(final List<OpeningHours> originalHoursList) {
View openingHoursItem = LayoutInflater.from(activity).inflate(R.layout.item_opening_hours, linearLayout, false);
final EditText textViewDaysValue = (EditText) openingHoursItem.findViewById(R.id.opening_hours_days_value);
final EditText textViewHoursValue = (EditText) openingHoursItem.findViewById(R.id.opening_hours_hours_value);
// When the days input text is clicked, we start the dialog to pick
// the opening days and hours
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
EditDaysDialogFragment fragment = new EditDaysDialogFragment();
fragment.setOnEditDaysListener(new EditDaysDialogFragment.OnEditDaysListener() {
@Override
public void onOpeningTimeChanged(OpeningHours openingHours) {
addOpeningHours(openingHours);
originalHoursList.add(openingHours);
eventBus.post(new PleaseApplyOpeningTimeChange(openingTime));
}
});
fragment.show(activity.getFragmentManager(), EditDaysDialogFragment.class.getSimpleName());
}
};
textViewDaysValue.setOnClickListener(onClickListener);
textViewHoursValue.setOnClickListener(onClickListener);
if (this.openingHoursList.size() == linearLayout.getChildCount()) {
linearLayout.addView(openingHoursItem);
}
}
use of io.jawg.osmcontributor.ui.dialogs.EditDaysDialogFragment in project osm-contributor by jawg.
the class OpeningHoursLinearLayoutAdapter method addOpeningHours.
public void addOpeningHours(final OpeningHours openingHours) {
View openingHoursItem = LayoutInflater.from(activity).inflate(R.layout.item_opening_hours, linearLayout, false);
openingHoursList.add(openingHours);
final EditText textViewDaysValue = (EditText) openingHoursItem.findViewById(R.id.opening_hours_days_value);
final EditText textViewHoursValue = (EditText) openingHoursItem.findViewById(R.id.opening_hours_hours_value);
String[] openingHoursPart = openingHoursValueParser.toValue(Collections.singletonList(openingHours)).split(" ");
if (openingHoursPart.length > 1) {
String[] days = openingHoursPart[0].split("-");
if (days.length == 7) {
textViewDaysValue.setText("7/7");
} else {
textViewDaysValue.setText(openingHoursPart[0]);
}
String[] hours = openingHoursPart[1].split("-");
if (hours[0].equals(hours[1])) {
textViewHoursValue.setText("24/24");
} else if (hasToHide) {
textViewHoursValue.setText(openingHoursPart[1].substring(0, 5));
} else {
textViewHoursValue.setText(openingHoursPart[1]);
}
} else {
if (openingHoursPart[0].equals("24/7")) {
textViewDaysValue.setText("7/7");
textViewHoursValue.setText("24/24");
}
}
// When the days input text is clicked, we start the dialog to pick
// the opening days and hours
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
EditDaysDialogFragment fragment = new EditDaysDialogFragment();
fragment.setOpeningHours(openingHours);
fragment.setOnEditDaysListener(new EditDaysDialogFragment.OnEditDaysListener() {
@Override
public void onOpeningTimeChanged(OpeningHours openingHours) {
eventBus.post(new PleaseApplyOpeningTimeChange(openingTime));
String[] openingHoursPart = openingHoursValueParser.toValue(Collections.singletonList(openingHours)).split(" ");
if (openingHoursPart.length > 1) {
textViewDaysValue.setText(openingHoursPart[0]);
if (hasToHide) {
textViewHoursValue.setText(openingHoursPart[1].substring(0, 5));
} else {
textViewHoursValue.setText(openingHoursPart[1]);
}
} else if (openingHoursPart[0].equals("24/7")) {
textViewDaysValue.setText("7/7");
textViewHoursValue.setText("24/24");
}
}
});
fragment.show(activity.getFragmentManager(), EditDaysDialogFragment.class.getSimpleName());
}
};
textViewDaysValue.setOnClickListener(onClickListener);
textViewHoursValue.setOnClickListener(onClickListener);
linearLayout.addView(openingHoursItem, linearLayout.getChildCount() - 1);
}
Aggregations