-
-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Road surfaces: tag either sett or unhewn_cobblestone, not cobblestone See https://forum.openstreetmap.org/viewtopic.php?id=61042&p=2 * fee times WIP * fee times WIP
- Loading branch information
1 parent
2f2e7de
commit 7c59360
Showing
6 changed files
with
297 additions
and
5 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
app/src/androidTest/java/de/westnordost/streetcomplete/quests/AddParkingFeeTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package de.westnordost.streetcomplete.quests; | ||
|
||
import de.westnordost.streetcomplete.data.osm.OsmElementQuestType; | ||
import de.westnordost.streetcomplete.data.osm.changes.StringMapEntryAdd; | ||
import de.westnordost.streetcomplete.quests.parking_fee.AddParkingFee; | ||
import de.westnordost.streetcomplete.quests.parking_fee.AddParkingFeeForm; | ||
|
||
public class AddParkingFeeTest extends AOsmElementQuestTypeTest | ||
{ | ||
|
||
@Override protected OsmElementQuestType createQuestType() | ||
{ | ||
return new AddParkingFee(null); | ||
} | ||
|
||
public void testYes() | ||
{ | ||
bundle.putBoolean(AddParkingFeeForm.FEE, true); | ||
verify(new StringMapEntryAdd("fee", "yes")); | ||
} | ||
|
||
public void testNo() | ||
{ | ||
bundle.putBoolean(AddParkingFeeForm.FEE, false); | ||
verify(new StringMapEntryAdd("fee", "no")); | ||
} | ||
|
||
public void testYesButOnlyAt() | ||
{ | ||
bundle.putBoolean(AddParkingFeeForm.FEE, false); | ||
bundle.putString(AddParkingFeeForm.FEE_CONDITONAL_HOURS, "xyz"); | ||
verify( | ||
new StringMapEntryAdd("fee", "no"), | ||
new StringMapEntryAdd("fee:conditional", "yes @ (xyz)")); | ||
} | ||
|
||
public void testYesButNotAt() | ||
{ | ||
bundle.putBoolean(AddParkingFeeForm.FEE, true); | ||
bundle.putString(AddParkingFeeForm.FEE_CONDITONAL_HOURS, "xyz"); | ||
verify( | ||
new StringMapEntryAdd("fee", "yes"), | ||
new StringMapEntryAdd("fee:conditional", "no @ (xyz)")); | ||
} | ||
} |
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
158 changes: 158 additions & 0 deletions
158
app/src/main/java/de/westnordost/streetcomplete/quests/parking_fee/AddParkingFeeForm.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
package de.westnordost.streetcomplete.quests.parking_fee; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.AdapterView; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.Button; | ||
import android.widget.Spinner; | ||
import android.widget.Toast; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
|
||
import de.westnordost.streetcomplete.Injector; | ||
import de.westnordost.streetcomplete.R; | ||
import de.westnordost.streetcomplete.quests.AbstractQuestAnswerFragment; | ||
import de.westnordost.streetcomplete.quests.opening_hours.AddOpeningHoursAdapter; | ||
import de.westnordost.streetcomplete.quests.opening_hours.OpeningMonths; | ||
import de.westnordost.streetcomplete.util.Serializer; | ||
|
||
public class AddParkingFeeForm extends AbstractQuestAnswerFragment | ||
{ | ||
|
||
public static final String FEE = "fee", | ||
FEE_CONDITONAL_HOURS = "fee_conditional_hours"; | ||
|
||
private static final String OPENING_HOURS_DATA = "oh_data", | ||
IS_FEE_ONLY_AT_HOURS = "oh_fee_only_at", | ||
IS_DEFINING_HOURS = "oh"; | ||
|
||
private boolean isDefiningHours; | ||
private boolean isFeeOnlyAtHours; | ||
private AddOpeningHoursAdapter openingHoursAdapter; | ||
private Button buttonOk, buttonYes, buttonNo; | ||
|
||
private View hoursView; | ||
|
||
@Inject Serializer serializer; | ||
|
||
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) | ||
{ | ||
View view = super.onCreateView(inflater, container, savedInstanceState); | ||
|
||
Injector.instance.getApplicationComponent().inject(this); | ||
|
||
View buttonPanel = setButtonsView(R.layout.quest_buttonpanel_yes_no_ok); | ||
buttonOk = buttonPanel.findViewById(R.id.buttonOk); | ||
buttonOk.setOnClickListener(v -> onClickOk()); | ||
|
||
buttonYes = buttonPanel.findViewById(R.id.buttonYes); | ||
buttonYes.setOnClickListener(v -> onClickYesNo(true)); | ||
|
||
buttonNo = buttonPanel.findViewById(R.id.buttonNo); | ||
buttonNo.setOnClickListener(v -> onClickYesNo(false)); | ||
|
||
addOtherAnswer(R.string.quest_fee_answer_hours, () -> setOpeningHoursMode(true)); | ||
|
||
hoursView = setContentView(R.layout.quest_fee_hours); | ||
|
||
ArrayList<OpeningMonths> data = loadOpeningHoursData(savedInstanceState); | ||
openingHoursAdapter = new AddOpeningHoursAdapter(data, getActivity(), getCountryInfo()); | ||
RecyclerView openingHoursList = hoursView.findViewById(R.id.hours_list); | ||
openingHoursList.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); | ||
openingHoursList.setAdapter(openingHoursAdapter); | ||
openingHoursList.setNestedScrollingEnabled(false); | ||
|
||
Button addTimes = hoursView.findViewById(R.id.btn_add); | ||
addTimes.setOnClickListener((v) -> openingHoursAdapter.addNewWeekdays()); | ||
|
||
isFeeOnlyAtHours = savedInstanceState == null || savedInstanceState.getBoolean(IS_FEE_ONLY_AT_HOURS, true); | ||
|
||
List<String> speedUnits = Arrays.asList( | ||
getString(R.string.quest_fee_only_at_hours), | ||
getString(R.string.quest_fee_not_at_hours)); | ||
Spinner select = hoursView.findViewById(R.id.select); | ||
select.setAdapter(new ArrayAdapter<>(getContext(), R.layout.spinner_item_centered, speedUnits)); | ||
select.setSelection(isFeeOnlyAtHours ? 0 : 1); | ||
select.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() | ||
{ | ||
@Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) | ||
{ | ||
isFeeOnlyAtHours = position == 0; | ||
} | ||
|
||
@Override public void onNothingSelected(AdapterView<?> parent) { } | ||
}); | ||
|
||
setOpeningHoursMode(savedInstanceState != null && savedInstanceState.getBoolean(IS_DEFINING_HOURS)); | ||
|
||
return view; | ||
} | ||
|
||
private void onClickOk() | ||
{ | ||
if(!hasChanges()) | ||
{ | ||
Toast.makeText(getActivity(), R.string.no_changes, Toast.LENGTH_SHORT).show(); | ||
return; | ||
} | ||
Bundle bundle = new Bundle(); | ||
bundle.putBoolean(FEE, !isFeeOnlyAtHours); | ||
bundle.putString(FEE_CONDITONAL_HOURS, openingHoursAdapter.toString()); | ||
applyImmediateAnswer(bundle); | ||
} | ||
|
||
private void onClickYesNo(boolean answer) | ||
{ | ||
Bundle bundle = new Bundle(); | ||
bundle.putBoolean(FEE, answer); | ||
applyImmediateAnswer(bundle); | ||
} | ||
|
||
private ArrayList<OpeningMonths> loadOpeningHoursData(Bundle savedInstanceState) | ||
{ | ||
ArrayList<OpeningMonths> data; | ||
if(savedInstanceState != null) | ||
{ | ||
data = serializer.toObject(savedInstanceState.getByteArray(OPENING_HOURS_DATA),ArrayList.class); | ||
} | ||
else | ||
{ | ||
data = new ArrayList<>(); | ||
data.add(new OpeningMonths()); | ||
} | ||
return data; | ||
} | ||
|
||
@Override public void onSaveInstanceState(Bundle outState) | ||
{ | ||
super.onSaveInstanceState(outState); | ||
outState.putByteArray(OPENING_HOURS_DATA, serializer.toBytes(openingHoursAdapter.getData())); | ||
outState.putBoolean(IS_DEFINING_HOURS, isDefiningHours); | ||
outState.putBoolean(IS_FEE_ONLY_AT_HOURS, isFeeOnlyAtHours); | ||
} | ||
|
||
private void setOpeningHoursMode(boolean isDefiningHours) | ||
{ | ||
this.isDefiningHours = isDefiningHours; | ||
|
||
hoursView.setVisibility(isDefiningHours ? View.VISIBLE : View.GONE); | ||
buttonOk.setVisibility(isDefiningHours ? View.VISIBLE : View.GONE); | ||
buttonNo.setVisibility(isDefiningHours ? View.GONE : View.VISIBLE); | ||
buttonYes.setVisibility(isDefiningHours ? View.GONE : View.VISIBLE); | ||
} | ||
|
||
@Override public boolean hasChanges() | ||
{ | ||
return isDefiningHours && !openingHoursAdapter.toString().isEmpty(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<merge xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<Button | ||
android:id="@+id/buttonOk" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
style="?android:attr/buttonBarButtonStyle" | ||
android:text="@android:string/ok" | ||
/> | ||
|
||
<Button | ||
android:id="@+id/buttonNo" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
style="?android:attr/buttonBarButtonStyle" | ||
android:text="@string/quest_generic_hasFeature_no" /> | ||
|
||
<Button | ||
android:id="@+id/buttonYes" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
style="?android:attr/buttonBarButtonStyle" | ||
android:text="@string/quest_generic_hasFeature_yes" | ||
/> | ||
|
||
|
||
</merge> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<RelativeLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<Spinner | ||
android:id="@+id/select" | ||
android:layout_alignParentStart="true" | ||
android:layout_centerVertical="true" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:textSize="16sp"/> | ||
|
||
<TextView | ||
android:layout_toEndOf="@id/select" | ||
android:layout_centerVertical="true" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
style="@style/TextAppearance.AppCompat.Body1" | ||
android:textSize="16sp" | ||
android:text="@string/quest_fee_hours_title"/> | ||
|
||
</RelativeLayout> | ||
|
||
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/hours_list" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
</android.support.v7.widget.RecyclerView> | ||
|
||
<Button | ||
android:id="@+id/btn_add" | ||
android:text="@string/quest_fee_add_times" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content"/> | ||
</LinearLayout> |
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