Skip to content

Commit

Permalink
Order transport networks by continents
Browse files Browse the repository at this point in the history
  • Loading branch information
ialokim authored and grote committed Mar 7, 2018
1 parent 93decfb commit 70f98bf
Show file tree
Hide file tree
Showing 51 changed files with 907 additions and 366 deletions.
8 changes: 3 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ dependencies {
implementation 'com.google.android:flexbox:0.3.1'
implementation 'com.mikepenz:materialdrawer:6.0.0'
implementation 'com.mikepenz:aboutlibraries:6.0.0'
implementation 'com.mikepenz:fastadapter-commons:3.0.3@aar'
implementation 'com.mikepenz:fastadapter-extensions-expandable:3.0.3@aar'
implementation 'com.mikepenz:fastadapter:3.2.3@aar'
implementation 'com.mikepenz:fastadapter-commons:3.2.3@aar'
implementation 'com.mikepenz:fastadapter-extensions-expandable:3.2.3@aar'
implementation 'uk.co.samuelwall:material-tap-target-prompt:2.1.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:5.4.1'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-locationlayer:0.3.0'
Expand Down Expand Up @@ -228,9 +229,6 @@ dependencyVerification {
'com.mapbox.mapboxsdk:mapbox-java-geojson:2.2.9:mapbox-java-geojson-2.2.9.jar:e888f38e36173a1ac39f3ba08fe6ba50d809b5d05ca8de5c143dee35114bfd91',
'com.mapzen.android:lost:3.0.4:lost-3.0.4.aar:7c95374ddd406356a6a3085c93e1a549feb68e919b29a8f0f194bc47f27788c0',
'com.mikepenz:aboutlibraries:6.0.0:aboutlibraries-6.0.0.aar:9d59e0c6caddda8bdcac1f8dd46ca824dde671b3201e6612a9ca297470da66a1',
'com.mikepenz:fastadapter-commons:3.0.3:fastadapter-commons-3.0.3.aar:c73e2b079523431ec9313fbcf82f5d659ce47aeae1838965869eaadf81a2c0bd',
'com.mikepenz:fastadapter-extensions-expandable:3.0.3:fastadapter-extensions-expandable-3.0.3.aar:5f4b78a877ab9e44e7f15dd69decbfcfc38ba45359bb6ee659d5043fdd931a7b',
'com.mikepenz:fastadapter:3.0.0:fastadapter-3.0.0.aar:6a75d94586448e9222fc36a3e0a0a6d61d3bd30bedb125f681a956b310816e7e',
'com.mikepenz:iconics-core:2.9.5:iconics-core-2.9.5.aar:4250d3082eb20029137574f2f9240bfc6a1f0dd2ce72b7290e75bea8a9cf3b14',
'com.mikepenz:materialdrawer:6.0.0:materialdrawer-6.0.0.aar:e3c43bf540fa220c90108c96e6f6c76ccc971fb100cb4616158650a495a44bf3',
'com.mikepenz:materialize:1.1.1:materialize-1.1.1.aar:0b85d3df906c36ad423271efdaafd4fa3dfb6211400ee91328201c341e7028b8',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import android.support.test.InstrumentationRegistry
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.action.ViewActions.click
import android.support.test.espresso.assertion.ViewAssertions.matches
import android.support.test.espresso.contrib.RecyclerViewActions.actionOnItem
import android.support.test.espresso.contrib.RecyclerViewActions.scrollToPosition
import android.support.test.espresso.contrib.RecyclerViewActions.*
import android.support.test.espresso.matcher.ViewMatchers.*
import android.support.test.filters.LargeTest
import android.support.test.rule.ActivityTestRule
Expand All @@ -34,12 +33,14 @@ import android.support.v7.widget.RecyclerView
import de.grobox.transportr.R
import de.grobox.transportr.ScreengrabTest
import de.grobox.transportr.map.MapActivity
import de.grobox.transportr.networks.TransportNetwork
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.util.*
import javax.inject.Inject
import de.schildbach.pte.NetworkId


@LargeTest
Expand Down Expand Up @@ -73,15 +74,33 @@ class PickTransportNetworkActivityTest : ScreengrabTest() {
.check(matches(withText(R.string.pick_network_first_run)))
makeScreenshot("1_FirstStart")

// hack to find region position in list
val regionList = ArrayList(EnumSet.allOf(Region::class.java))
// some hacking to find network position in list
val context = InstrumentationRegistry.getTargetContext()
Collections.sort(regionList) { r1, r2 -> context.getString(r1.getName()).compareTo(context.getString(r2.getName())) }

val continentList = ArrayList(EnumSet.allOf(Continent::class.java))
Collections.sort(continentList) { r1, r2 -> r1.getName(context).compareTo(r2.getName(context)) }

val countryList = Continent.EUROPE.getSubRegions()
Collections.sort(countryList) { r1, r2 -> r1.getName(context).compareTo(r2.getName(context)) }

val networkList = Country.GERMANY.getSubRegions()

// select DB network provider
val continentIndex = continentList.indexOf(Continent.EUROPE)
val countryIndex = countryList.indexOf(Country.GERMANY)
var networkIndex = -1
for (network in networkList) {
networkIndex++
if ((network as TransportNetwork).getId() == NetworkId.DB) {
break
}
}
onView(withId(R.id.list))
.perform(scrollToPosition<RecyclerView.ViewHolder>(regionList.indexOf(Region.GERMANY) + 5))
.perform(scrollToPosition<RecyclerView.ViewHolder>(continentIndex + 5))
.perform(actionOnItem<RecyclerView.ViewHolder>(withChild(withText(R.string.np_continent_europe)), click()))
.perform(scrollToPosition<RecyclerView.ViewHolder>(continentIndex + countryIndex + 5))
.perform(actionOnItem<RecyclerView.ViewHolder>(withChild(withText(R.string.np_region_germany)), click()))
.perform(scrollToPosition<RecyclerView.ViewHolder>(continentIndex + countryIndex + networkIndex + 5))
.perform(actionOnItem<RecyclerView.ViewHolder>(withChild(withText(R.string.np_name_db)), click()))
}

Expand Down
82 changes: 82 additions & 0 deletions app/src/main/java/de/grobox/transportr/networks/Continent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Transportr
*
* Copyright (c) 2013 - 2017 Torsten Grote
*
* This program is Free Software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.grobox.transportr.networks;

import android.content.Context;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.ParametersAreNonnullByDefault;

import de.grobox.transportr.R;

@ParametersAreNonnullByDefault
enum Continent implements ParentRegion {

EUROPE(R.string.np_continent_europe, R.drawable.continent_europe),
AFRICA(R.string.np_continent_africa, R.drawable.continent_africa),
NORTH_AMERICA(R.string.np_continent_north_america, R.drawable.continent_north_america),
CENTRAL_AMERICA(R.string.np_continent_central_america, R.drawable.continent_central_america),
SOUTH_AMERICA(R.string.np_continent_south_america, R.drawable.continent_south_america),
ASIA(R.string.np_continent_asia, R.drawable.continent_asia),
OCEANIA(R.string.np_continent_oceania, R.drawable.continent_oceania);


private final @StringRes int name;
private final @DrawableRes int contour;
private List<Region> subRegions;

Continent(@StringRes int name, @DrawableRes int contour) {
this.name = name;
this.contour = contour;
this.subRegions = new ArrayList<>();
}

@Override
@StringRes
public int getName() {
return name;
}

@DrawableRes
public int getContour() {
return contour;
}

@Override
public String getName(Context context) {
return context.getString(name);
}

@Override
public void addSubRegion(Region subRegion) {
subRegions.add(subRegion);
}

@Override
public List<Region> getSubRegions() {
return subRegions;
}

}
76 changes: 76 additions & 0 deletions app/src/main/java/de/grobox/transportr/networks/ContinentItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Transportr
*
* Copyright (c) 2013 - 2017 Torsten Grote
*
* This program is Free Software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.grobox.transportr.networks;

import android.content.Context;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.view.View;

import java.util.List;

import javax.annotation.ParametersAreNonnullByDefault;

import de.grobox.transportr.R;

@ParametersAreNonnullByDefault
class ContinentItem extends ParentRegionItem<ParentRegionItem, ContinentViewHolder, RegionItem> {

private final Continent continent;

ContinentItem(Continent continent) {
super();
this.continent = continent;
}

@Override
protected String getName(Context context) {
return continent.getName(context);
}

@IdRes
@Override
public int getType() {
return R.id.list_item_transport_continent;
}

@Override
@LayoutRes
public int getLayoutRes() {
return R.layout.list_item_transport_continent;
}

@Override
public void bindView(ContinentViewHolder ui, List<Object> payloads) {
super.bindView(ui, payloads);
ui.bind(continent, isExpanded());
}

@Override
public ContinentViewHolder getViewHolder(View view) {
return new ContinentViewHolder(view);
}

@Override
public long getIdentifier() {
return continent.getName();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Transportr
*
* Copyright (c) 2013 - 2017 Torsten Grote
*
* This program is Free Software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.grobox.transportr.networks;

import android.os.Build;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import de.grobox.transportr.R;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;

class ContinentViewHolder extends ParentRegionViewHolder<Continent> {

private final ImageView contour;

ContinentViewHolder(View v) {
super(v);
contour = v.findViewById(R.id.contour);
}

@Override
void bind(Continent continent, boolean expanded) {
super.bind(continent, expanded);
contour.setImageResource(continent.getContour());
}
}
99 changes: 99 additions & 0 deletions app/src/main/java/de/grobox/transportr/networks/Country.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Transportr
*
* Copyright (c) 2013 - 2017 Torsten Grote
*
* This program is Free Software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.grobox.transportr.networks;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.ParametersAreNonnullByDefault;

import de.grobox.transportr.R;

@ParametersAreNonnullByDefault
enum Country implements ParentRegion {

GERMANY(R.string.np_region_germany, "🇩🇪", Continent.EUROPE),
AUSTRIA(R.string.np_region_austria, "🇦🇹", Continent.EUROPE),
LIECHTENSTEIN(R.string.np_region_liechtenstein, "🇱🇮", Continent.EUROPE),
SWITZERLAND(R.string.np_region_switzerland, "🇨🇭", Continent.EUROPE),
LUXEMBOURG(R.string.np_region_luxembourg, "🇱🇺", Continent.EUROPE),
NETHERLANDS(R.string.np_region_netherlands, "🇳🇱", Continent.EUROPE),
DENMARK(R.string.np_region_denmark, "🇩🇰", Continent.EUROPE),
SWEDEN(R.string.np_region_sweden, "🇸🇪", Continent.EUROPE),
NORWAY(R.string.np_region_norway, "🇳🇴", Continent.EUROPE),
FINLAND(R.string.np_region_finland, "🇫🇮", Continent.EUROPE),
GREAT_BRITAIN(R.string.np_region_gb, "🇬🇧", Continent.EUROPE),
IRELAND(R.string.np_region_ireland, "🇮🇪", Continent.EUROPE),
POLAND(R.string.np_region_poland, "🇵🇱", Continent.EUROPE),
UAE(R.string.np_region_uae, "🇦🇪", Continent.ASIA),
USA(R.string.np_region_usa, "🇺🇸", Continent.NORTH_AMERICA), //TODO: it seems there's a problem with the flag
AUSTRALIA(R.string.np_region_australia, "🇦🇺", Continent.OCEANIA),
FRANCE(R.string.np_region_france, "🇫🇷", Continent.EUROPE),
BRAZIL(R.string.np_region_br, "🇧🇷", Continent.SOUTH_AMERICA),
CANADA(R.string.np_region_canada, "🇨🇦", Continent.NORTH_AMERICA);

private final @StringRes int name;
private final @Nullable String flag;
private final Continent continent;
private List<Region> subRegions;

Country(@StringRes int name, @Nullable String flag, Continent continent) {
this.name = name;
this.flag = flag;
this.continent = continent;
this.continent.addSubRegion(this);
this.subRegions = new ArrayList<>();
}

@Override
@StringRes
public int getName() {
return name;
}

@Override
public String getName(Context context) {
return context.getString(name);
}

@Nullable
public String getFlag() {
return flag;
}

public Continent getContinent() {
return continent;
}

@Override
public void addSubRegion(Region subRegion) {
subRegions.add(subRegion);
}

@Override
public List<Region> getSubRegions() {
return subRegions;
}

}
Loading

0 comments on commit 70f98bf

Please sign in to comment.