Skip to content

Commit

Permalink
Merge pull request #32 from hyperrail/development
Browse files Browse the repository at this point in the history
Version 4 (0.9.2)
  • Loading branch information
Bertware authored Jun 27, 2017
2 parents 1bb1123 + 21e932d commit 64c1d94
Show file tree
Hide file tree
Showing 34 changed files with 267 additions and 73 deletions.
11 changes: 7 additions & 4 deletions Hyperrail/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-perf'
apply plugin: 'com.google.firebase.firebase-crash'

def VERSION_CODE = 4
def VERSION_NAME = '0.9.2'

android {
signingConfigs {
Expand All @@ -24,8 +28,8 @@ android {
applicationId "be.hyperrail.android"
minSdkVersion 19
targetSdkVersion 25
versionCode 3
versionName '0.9.2'
versionCode VERSION_CODE
versionName VERSION_NAME
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
Expand All @@ -50,18 +54,17 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'

compile 'com.google.android.gms:play-services-location:10.2.6'
compile 'com.google.firebase:firebase-crash:10.2.6'
compile 'com.google.firebase:firebase-perf:10.2.6'
compile 'com.google.firebase:firebase-core:10.2.6'
testCompile 'junit:junit:4.12'
}


apply plugin: 'com.google.gms.google-services'
1 change: 1 addition & 0 deletions Hyperrail/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-keepattributes SourceFile,LineNumberTable
68 changes: 68 additions & 0 deletions Hyperrail/src/main/java/be/hyperrail/android/FeedbackFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package be.hyperrail.android;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

/**
* A simple {@link Fragment} subclass.
*/
public class FeedbackFragment extends Fragment {

public FeedbackFragment() {
// Required empty public constructor
}

public static FeedbackFragment newInstance() {
return new FeedbackFragment();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_feedback, container, false);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final EditText vFeedbackText = ((EditText) view.findViewById(R.id.input_text));

view.findViewById(R.id.button_send).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Context context = FeedbackFragment.this.getActivity();
String version = "unknown";

try {
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
version = pInfo.versionName;
} catch (Exception e) {
// Ignored
}

Intent feedbackEmail = new Intent(Intent.ACTION_SEND);

feedbackEmail.setType("text/email");
feedbackEmail.putExtra(Intent.EXTRA_EMAIL, new String[]{"feedback@hyperrail.be"});
feedbackEmail.putExtra(Intent.EXTRA_SUBJECT, "Feedback for hyperrail " + version);
feedbackEmail.putExtra(Intent.EXTRA_TEXT, vFeedbackText.getText());
startActivity(Intent.createChooser(feedbackEmail, "Send feedback mail:"));
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void markFavorite(boolean favorite) {
}

if (favorite) {
persistentQueryProvider.addFavoriteStation(mCurrentStation);
mPersistentQuaryProvider.addFavoriteStation(mCurrentStation);
Snackbar.make(vLayoutRoot, R.string.marked_station_favorite, Snackbar.LENGTH_SHORT)
.setAction(R.string.undo, new View.OnClickListener() {
@Override
Expand All @@ -268,7 +268,7 @@ public void onClick(View v) {
})
.show();
} else {
persistentQueryProvider.removeFavoriteStation(mCurrentStation);
mPersistentQuaryProvider.removeFavoriteStation(mCurrentStation);
Snackbar.make(vLayoutRoot, R.string.unmarked_station_favorite, Snackbar.LENGTH_SHORT)
.setAction(R.string.undo, new View.OnClickListener() {
@Override
Expand All @@ -284,7 +284,7 @@ public void onClick(View v) {
@Override
public boolean isFavorite() {
// If it's not loaded, it's not a favorite
return mCurrentStation != null && persistentQueryProvider.isFavoriteStation(mCurrentStation);
return mCurrentStation != null && mPersistentQuaryProvider.isFavoriteStation(mCurrentStation);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
private static final int VIEW_TYPE_ROUTE = 1;
private static final int VIEW_TYPE_DISTURBANCE = 2;
private static final int VIEW_TYPE_SETTINGS = 3;
private static final int VIEW_TYPE_FEEDBACK = 4;

private boolean mDualPane = false;

Expand Down Expand Up @@ -178,6 +179,10 @@ private void setView(int i, Bundle args) {
frg = DisturbanceListFragment.newInstance();
setSubTitle(R.string.title_disturbances);
break;
case VIEW_TYPE_FEEDBACK:
frg = FeedbackFragment.newInstance();
setSubTitle(R.string.title_feedback);
break;
}
if (args != null){
frg.setArguments(args);
Expand Down Expand Up @@ -221,6 +226,9 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
Intent i = new Intent(this, SettingsActivity.class);
startActivity(i);
break;
case R.id.action_feedback:
setView(VIEW_TYPE_FEEDBACK,null);
break;
}
if (!mDualPane) {
vDrawerLayout.closeDrawers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public abstract class RecyclerViewActivity<T> extends AppCompatActivity implemen
/**
* History & favorites provider
*/
PersistentQueryProvider persistentQueryProvider;
PersistentQueryProvider mPersistentQuaryProvider;

/**
* Favorite button in menu
Expand All @@ -98,9 +98,9 @@ public abstract class RecyclerViewActivity<T> extends AppCompatActivity implemen
protected SharedPreferences mSharedPreferences;

/**
* Wether or not to show dividers between list items
* Whether or not to show dividers between list items
*/
protected boolean show_dividers = true;
protected boolean mShowDividers = true;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -115,7 +115,7 @@ protected void onCreate(Bundle savedInstanceState) {
setSupportActionBar(toolbar);

// Initialize history & favorites, preferences
persistentQueryProvider = new PersistentQueryProvider(this.getApplicationContext());
mPersistentQuaryProvider = new PersistentQueryProvider(this.getApplicationContext());
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());

// Initialize pull to refresh
Expand Down Expand Up @@ -145,7 +145,7 @@ public void onRefresh() {
vRecyclerView.setLayoutManager(mLayoutManager);

// Show dividers in case wanted & not using the card layout
if (show_dividers && !PreferenceManager.getDefaultSharedPreferences(this.getApplication()).getBoolean("use_card_layout", false)) {
if (mShowDividers && !PreferenceManager.getDefaultSharedPreferences(this.getApplication()).getBoolean("use_card_layout", false)) {
// Cards have their own division by margin, others need a divider
vRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public void loadMoreRecyclerviewItems() {

public void markFavorite(boolean favorite) {
if (favorite) {
persistentQueryProvider.addFavoriteRoute(mSearchFrom, mSearchTo);
mPersistentQuaryProvider.addFavoriteRoute(mSearchFrom, mSearchTo);
Snackbar.make(vLayoutRoot, R.string.marked_route_favorite, Snackbar.LENGTH_SHORT)
.setAction(R.string.undo, new View.OnClickListener() {
@Override
Expand All @@ -305,7 +305,7 @@ public void onClick(View v) {
})
.show();
} else {
persistentQueryProvider.removeFavoriteRoute(mSearchFrom, mSearchTo);
mPersistentQuaryProvider.removeFavoriteRoute(mSearchFrom, mSearchTo);
Snackbar.make(vLayoutRoot, R.string.unmarked_route_favorite, Snackbar.LENGTH_SHORT)
.setAction(R.string.undo, new View.OnClickListener() {
@Override
Expand All @@ -319,6 +319,6 @@ public void onClick(View v) {
}

public boolean isFavorite() {
return persistentQueryProvider.isFavoriteRoute(mSearchFrom, mSearchTo);
return mPersistentQuaryProvider.isFavoriteRoute(mSearchFrom, mSearchTo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static Intent createIntent(Context c, Route r) {
@Override
protected void onCreate(Bundle savedInstanceState) {
route = (Route) getIntent().getSerializableExtra("route");
this.show_dividers = false;
this.mShowDividers = false;

super.onCreate(savedInstanceState);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ public void onBindViewHolder(TrainStopViewHolder holder, int position) {
}
}

// TODO: fix this as soon as hasLeft is reliable
if (s.hasLeft() || true) {
if (s.hasLeft()) {
if (position == 0) {
holder.vIcon.setImageDrawable(ContextCompat.getDrawable(context,R.drawable.timeline_departure_filled));
} else if (position == this.getItemCount() - 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ public int compare(Station o1, Station o2) {
*/
@Override
public String[] getStationNames(Station[] Stations) {

if (Stations == null ||Stations.length == 0){
FirebaseCrash.logcat(WARNING.intValue(),LOGTAG,"Tried to load station names on empty station list!");
return new String[0];
}

String[] results = new String[Stations.length];
for (int i = 0; i < Stations.length; i++) {
results[i] = Stations[i].getLocalizedName();
Expand Down Expand Up @@ -450,6 +456,12 @@ public Station getStationByName(String name) {
*/
private Station[] loadStationCursor(Cursor c) {
if (c.isClosed()) {
FirebaseCrash.logcat(SEVERE.intValue(),LOGTAG,"Tried to load closed cursor");
return null;
}

if (c.getCount() == 0){
FirebaseCrash.logcat(SEVERE.intValue(),LOGTAG,"Tried to load cursor with 0 results!");
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private TrainStop parseTrainStop(Station destination, TrainStub t, JSONObject it
item.getInt("arrivalDelay"),
item.getInt("departureCanceled") != 0,
item.getInt("arrivalCanceled") != 0,
false
item.getInt("left") == 1
);
}

Expand All @@ -275,19 +275,11 @@ public Train parseTrain(JSONObject jsonData, Date searchdate) throws JSONExcepti
TrainStop[] stops = new TrainStop[jsonStops.length()];
TrainStub t = new TrainStub(id, destination);

TrainStop lastHaltedStop = null;

for (int i = 0; i < jsonStops.length(); i++) {
stops[i] = parseTrainStop(destination, t, jsonStops.getJSONObject(i));
if (stops[i].getStation().getLatitude() == latitude && stops[i].getStation().getLongitude() == longitude) {
lastHaltedStop = stops[i];
for (int j = i; j >=0; j--){
stops[j].setHasLeft(true);
}
}
}

return new Train(id, destination, stops[0].getStation(), longitude, latitude, stops, lastHaltedStop);
return new Train(id, destination, stops[0].getStation(), longitude, latitude, stops);
}

private static Date timestamp2date(String time) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,20 @@ public class Train extends TrainStub implements Serializable {
private final Station origin;

private final TrainStop[] stops;
private final TrainStop lastHaltedStop;
private TrainStop lastHaltedStop;

Train(String id, Station destination, Station origin, double longitude, double latitude, TrainStop[] stops, TrainStop lastHaltedStop) {
Train(String id, Station destination, Station origin, double longitude, double latitude, TrainStop[] stops) {
super(id, destination);
this.origin = origin;
this.longitude = longitude;
this.latitude = latitude;
this.stops = stops;
this.lastHaltedStop = lastHaltedStop;

for (int i = 0; i < stops.length; i++){
if (stops[i].hasLeft()){
lastHaltedStop = stops[i];
}
}
}

public Station getOrigin() {
Expand Down
Loading

0 comments on commit 64c1d94

Please sign in to comment.