-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
372 additions
and
55 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
app/src/main/java/de/grobox/transportr/networks/Continent.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,56 @@ | ||
/* | ||
* 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 javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
import de.grobox.transportr.R; | ||
|
||
@ParametersAreNonnullByDefault | ||
enum Continent { | ||
|
||
EUROPE(R.string.np_continent_europe), | ||
AFRICA(R.string.np_continent_africa), | ||
NORTH_AMERICA(R.string.np_continent_north_america), | ||
SOUTH_AMERICA(R.string.np_continent_south_america), | ||
ASIA(R.string.np_continent_asia), | ||
AUSTRALIA(R.string.np_continent_australia); | ||
|
||
|
||
private final @StringRes int name; | ||
|
||
Continent(@StringRes int name) { | ||
this.name = name; | ||
} | ||
|
||
@StringRes | ||
public int getName() { | ||
return name; | ||
} | ||
|
||
public String getName(Context context) { | ||
return context.getString(name); | ||
} | ||
|
||
} |
111 changes: 111 additions & 0 deletions
111
app/src/main/java/de/grobox/transportr/networks/ContinentItem.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,111 @@ | ||
/* | ||
* 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.support.v4.view.ViewCompat; | ||
import android.view.View; | ||
|
||
import com.mikepenz.fastadapter.IItem; | ||
import com.mikepenz.fastadapter.expandable.items.AbstractExpandableItem; | ||
import com.mikepenz.fastadapter.listeners.OnClickListener; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
import de.grobox.transportr.R; | ||
|
||
@ParametersAreNonnullByDefault | ||
class ContinentItem extends AbstractExpandableItem<ContinentItem, ContinentViewHolder, RegionItem> { | ||
|
||
private final Continent continent; | ||
|
||
ContinentItem(Continent continent) { | ||
super(); | ||
this.continent = continent; | ||
} | ||
|
||
@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(); | ||
} | ||
|
||
@Override | ||
public OnClickListener<ContinentItem> getOnItemClickListener() { | ||
return (v, adapter, item, position) -> { | ||
if (item.getSubItems() != null) { | ||
if (!item.isExpanded()) { | ||
ViewCompat.animate(v.findViewById(R.id.chevron)).rotation(180).start(); | ||
} else { | ||
ViewCompat.animate(v.findViewById(R.id.chevron)).rotation(0).start(); | ||
} | ||
return true; | ||
} | ||
return false; | ||
}; | ||
} | ||
|
||
static class ContinentComparator implements Comparator<IItem> { | ||
|
||
private final Context context; | ||
|
||
ContinentComparator(Context context) { | ||
super(); | ||
this.context = context; | ||
} | ||
|
||
@Override | ||
public int compare(IItem i1, IItem i2) { | ||
if (i1 instanceof ContinentItem && i2 instanceof ContinentItem) { | ||
// sort continents alphabetically | ||
return ((ContinentItem) i1).continent.getName(context).compareTo(((ContinentItem) i2).continent.getName(context)); | ||
} | ||
return 0; | ||
} | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
app/src/main/java/de/grobox/transportr/networks/ContinentViewHolder.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,50 @@ | ||
/* | ||
* 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 RecyclerView.ViewHolder { | ||
|
||
private final TextView name; | ||
private final ImageView chevron; | ||
|
||
ContinentViewHolder(View v) { | ||
super(v); | ||
name = v.findViewById(R.id.name); | ||
chevron = v.findViewById(R.id.chevron); | ||
} | ||
|
||
void bind(Continent continent, boolean expanded) { | ||
name.setText(continent.getName()); | ||
if (expanded) chevron.setRotation(0); | ||
else chevron.setRotation(180); | ||
} | ||
|
||
} |
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
Oops, something went wrong.