diff --git a/Hyperrail/build.gradle b/Hyperrail/build.gradle index 55e64292..08166c55 100644 --- a/Hyperrail/build.gradle +++ b/Hyperrail/build.gradle @@ -8,8 +8,8 @@ apply plugin: 'com.android.application' apply plugin: 'com.google.firebase.firebase-perf' apply plugin: 'io.fabric' -def VERSION_CODE = 45 -def VERSION_NAME = '1.1.0-beta2' +def VERSION_CODE = 47 +def VERSION_NAME = '1.1.0' android { compileSdkVersion 28 @@ -20,7 +20,7 @@ android { targetSdkVersion 28 versionCode VERSION_CODE versionName VERSION_NAME - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled true } buildTypes { @@ -44,10 +44,10 @@ android { } dependencies { - implementation 'com.android.support.constraint:constraint-layout:1.1.3' - implementation 'com.google.android.gms:play-services-maps:16.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'com.google.android.gms:play-services-maps:17.0.0' implementation fileTree(include: ['*.jar'], dir: 'libs') - androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { + androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-alpha4', { exclude group: 'com.android.support', module: 'support-annotations' }) @@ -57,22 +57,22 @@ dependencies { implementation 'com.android.volley:volley:1.1.0@aar' implementation 'joda-time:joda-time:2.9.9' - implementation 'com.android.support:appcompat-v7:28.0.0' - implementation 'com.android.support:exifinterface:28.0.0' - implementation 'com.android.support:support-v4:28.0.0' - implementation 'com.android.support:cardview-v7:28.0.0' - implementation 'com.android.support:recyclerview-v7:28.0.0' - implementation 'com.android.support:design:28.0.0' - implementation 'com.google.android.gms:play-services-location:16.0.0' - implementation 'com.google.firebase:firebase-perf:16.2.5' - implementation 'com.google.firebase:firebase-core:16.0.8' + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.exifinterface:exifinterface:1.0.0' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + implementation 'androidx.cardview:cardview:1.0.0' + implementation 'androidx.recyclerview:recyclerview:1.0.0' + implementation 'com.google.android.material:material:1.0.0' + implementation 'com.google.android.gms:play-services-location:17.0.0' + implementation 'com.google.firebase:firebase-perf:18.0.1' + implementation 'com.google.firebase:firebase-core:17.0.1' implementation 'com.squareup.picasso:picasso:2.71828' testImplementation 'junit:junit:4.12' testImplementation 'org.json:json:20160810' testImplementation "org.mockito:mockito-core:2.18.3" // org.json is included with Android, but Android.jar can not be used from unit tests - androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:2.2.2', { + androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0-alpha4', { exclude group: 'com.android.support', module: 'support-annotations' exclude group: 'com.android.support', module: 'support-v4' exclude group: 'com.android.support', module: 'design' diff --git a/Hyperrail/src/main/java/be/hyperrail/android/VehiclePopupContextMenu.java b/Hyperrail/src/main/java/be/hyperrail/android/VehiclePopupContextMenu.java index 88b529b6..effc0a43 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/VehiclePopupContextMenu.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/VehiclePopupContextMenu.java @@ -15,11 +15,11 @@ import android.graphics.Color; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; -import android.support.annotation.NonNull; -import android.support.design.widget.Snackbar; -import android.support.v4.app.NotificationCompat.Builder; -import android.support.v4.app.NotificationCompat.DecoratedCustomViewStyle; -import android.support.v4.content.ContextCompat; +import androidx.annotation.NonNull; +import com.google.android.material.snackbar.Snackbar; +import androidx.core.app.NotificationCompat.Builder; +import androidx.core.app.NotificationCompat.DecoratedCustomViewStyle; +import androidx.core.content.ContextCompat; import android.view.View; import android.view.View.OnClickListener; import android.widget.LinearLayout; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/activities/FirstLaunchGuide.java b/Hyperrail/src/main/java/be/hyperrail/android/activities/FirstLaunchGuide.java index 23f1fd5c..8b39df4f 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/activities/FirstLaunchGuide.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/activities/FirstLaunchGuide.java @@ -17,15 +17,15 @@ import android.os.AsyncTask; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.annotation.DrawableRes; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.design.widget.TabLayout; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; -import android.support.v4.view.ViewPager; -import android.support.v7.app.AppCompatActivity; +import androidx.annotation.DrawableRes; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import com.google.android.material.tabs.TabLayout; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentPagerAdapter; +import androidx.viewpager.widget.ViewPager; +import androidx.appcompat.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -139,7 +139,7 @@ public boolean onOptionsItemSelected(MenuItem item) { /** * A placeholder fragment containing a simple view. */ - public static class FirstLaunchFragment extends android.support.v4.app.Fragment { + public static class FirstLaunchFragment extends Fragment { private static final String ARG_DESCRIPTION = "description"; private static final String ARG_IMG = "image"; /** diff --git a/Hyperrail/src/main/java/be/hyperrail/android/activities/MainActivity.java b/Hyperrail/src/main/java/be/hyperrail/android/activities/MainActivity.java index d1e83f8c..56af8ecf 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/activities/MainActivity.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/activities/MainActivity.java @@ -32,19 +32,20 @@ import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.annotation.IntDef; -import android.support.annotation.NonNull; -import android.support.annotation.StringRes; -import android.support.design.widget.NavigationView; -import android.support.v4.app.Fragment; -import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.ActionBarDrawerToggle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.view.Gravity; import android.view.MenuItem; import android.view.View; +import com.google.android.material.navigation.NavigationView; + +import androidx.annotation.IntDef; +import androidx.annotation.NonNull; +import androidx.annotation.StringRes; +import androidx.appcompat.app.ActionBarDrawerToggle; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.view.GravityCompat; +import androidx.drawerlayout.widget.DrawerLayout; +import androidx.fragment.app.Fragment; import be.hyperrail.android.R; import be.hyperrail.android.fragments.FeedbackFragment; import be.hyperrail.android.fragments.LiveboardSearchFragment; @@ -239,7 +240,7 @@ private void setView(@ViewType int i, Bundle args) { android.R.animator.fade_in, android.R.animator.fade_out).commit(); // Close drawer before loading next fragment - mDrawerLayout.closeDrawer(Gravity.START); + mDrawerLayout.closeDrawer(GravityCompat.START); } @Override diff --git a/Hyperrail/src/main/java/be/hyperrail/android/activities/NextDeparturesWidgetConfiguration.java b/Hyperrail/src/main/java/be/hyperrail/android/activities/NextDeparturesWidgetConfiguration.java index 6052e2fc..9f866fbf 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/activities/NextDeparturesWidgetConfiguration.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/activities/NextDeparturesWidgetConfiguration.java @@ -17,9 +17,9 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.RecyclerView; +import androidx.appcompat.widget.Toolbar; import android.widget.RemoteViews; import be.hyperrail.android.R; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/activities/SettingsActivity.java b/Hyperrail/src/main/java/be/hyperrail/android/activities/SettingsActivity.java index 73f7eb63..4b70f882 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/activities/SettingsActivity.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/activities/SettingsActivity.java @@ -21,8 +21,8 @@ import android.os.Bundle; import android.preference.PreferenceActivity; import android.preference.PreferenceFragment; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import be.hyperrail.android.R; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/activities/StationActivity.java b/Hyperrail/src/main/java/be/hyperrail/android/activities/StationActivity.java index 68d16e16..d8162f68 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/activities/StationActivity.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/activities/StationActivity.java @@ -16,14 +16,15 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.ActivityCompat; -import android.support.v7.app.AlertDialog; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; import android.view.View; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.core.app.ActivityCompat; + import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.OnMapReadyCallback; @@ -67,13 +68,8 @@ protected void onCreate(Bundle savedInstanceState) { mStation = (StopLocation) getIntent().getSerializableExtra("station"); findViewById(R.id.floating_action_button).setOnClickListener( - new View.OnClickListener() { - @Override - public void onClick(View v) { - startActivity(LiveboardActivity.createIntent(StationActivity.this, - new LiveboardRequest(mStation, QueryTimeDefinition.EQUAL_OR_LATER, LiveboardType.DEPARTURES, null))); - } - } + v -> startActivity(LiveboardActivity.createIntent(StationActivity.this, + new LiveboardRequest(mStation, QueryTimeDefinition.EQUAL_OR_LATER, LiveboardType.DEPARTURES, null))) ); setTitle(mStation.getLocalizedName()); diff --git a/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/LiveboardActivity.java b/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/LiveboardActivity.java index 638b1363..c2d8d54d 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/LiveboardActivity.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/LiveboardActivity.java @@ -11,16 +11,17 @@ import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.os.Bundle; -import android.support.design.widget.Snackbar; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; -import android.support.v4.view.ViewPager; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Toast; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentPagerAdapter; +import androidx.viewpager.widget.ViewPager; + +import com.google.android.material.snackbar.Snackbar; import com.google.firebase.analytics.FirebaseAnalytics; import com.google.firebase.analytics.FirebaseAnalytics.Event; import com.google.firebase.analytics.FirebaseAnalytics.Param; @@ -68,7 +69,7 @@ private Intent createShortcutIntent() { Intent i = new Intent(this, LiveboardActivity.class); i.putExtra("shortcut", true); // this variable allows to detect launches from shortcuts i.putExtra("station", - mRequest.getStation().getHafasId()); // shortcut intents should not contain application specific classes - only pass the station ID + mRequest.getStation().getHafasId()); // shortcut intents should not contain application specific classes - only pass the station ID return i; } @@ -154,27 +155,28 @@ public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case id.action_from: startActivity(MainActivity.createRouteFromIntent(getApplicationContext(), - mRequest.getStation().getName())); + mRequest.getStation().getName())); return true; case id.action_to: startActivity(MainActivity.createRouteToIntent(getApplicationContext(), - mRequest.getStation().getName())); + mRequest.getStation().getName())); return true; case id.action_details: startActivity(StationActivity.createIntent(getApplicationContext(), - mRequest.getStation())); + mRequest.getStation())); return true; case id.action_shortcut: Intent shortcutIntent = createShortcutIntent(); ShortcutHelper.createShortcut(this, - vLayoutRoot, - shortcutIntent, - mRequest.getStation().getLocalizedName(), - "Departures from " + mRequest.getStation().getLocalizedName(), - R.mipmap.ic_shortcut_liveboard); + vLayoutRoot, + shortcutIntent, + mRequest.getStation().getSemanticId(), + mRequest.getStation().getLocalizedName(), + "Departures from " + mRequest.getStation().getLocalizedName(), + R.mipmap.ic_shortcut_liveboard); return true; default: diff --git a/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/ResultActivity.java b/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/ResultActivity.java index c901fcd2..d92d213b 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/ResultActivity.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/ResultActivity.java @@ -20,13 +20,13 @@ import android.net.NetworkInfo; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.annotation.ColorRes; -import android.support.annotation.LayoutRes; -import android.support.annotation.MenuRes; -import android.support.annotation.StringRes; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; +import androidx.annotation.ColorRes; +import androidx.annotation.LayoutRes; +import androidx.annotation.MenuRes; +import androidx.annotation.StringRes; +import androidx.core.content.ContextCompat; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/RouteActivity.java b/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/RouteActivity.java index 9d5932b2..61ab5a59 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/RouteActivity.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/RouteActivity.java @@ -9,12 +9,13 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.design.widget.Snackbar; import android.view.MenuItem; import android.view.View; import android.widget.Toast; +import androidx.annotation.NonNull; + +import com.google.android.material.snackbar.Snackbar; import com.google.firebase.analytics.FirebaseAnalytics; import org.joda.time.DateTime; @@ -122,11 +123,12 @@ public boolean onOptionsItemSelected(MenuItem item) { case R.id.action_shortcut: Intent shortcutIntent = createShortcutIntent(); ShortcutHelper.createShortcut(this, - vLayoutRoot, - shortcutIntent, - mRequest.getOrigin().getLocalizedName() + " - " + mRequest.getDestination().getLocalizedName(), - "Route from " + mRequest.getOrigin().getLocalizedName() + " to " + mRequest.getDestination().getLocalizedName(), - R.mipmap.ic_launcher); + vLayoutRoot, + shortcutIntent, + mRequest.getOrigin().getSemanticId() + "::" + mRequest.getDestination().getSemanticId(), + mRequest.getOrigin().getLocalizedName() + " - " + mRequest.getDestination().getLocalizedName(), + "Route from " + mRequest.getOrigin().getLocalizedName() + " to " + mRequest.getDestination().getLocalizedName(), + R.mipmap.ic_launcher); return true; default: diff --git a/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/RouteDetailActivity.java b/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/RouteDetailActivity.java index d007dfdf..0d8437a5 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/RouteDetailActivity.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/RouteDetailActivity.java @@ -10,7 +10,7 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.support.v4.app.Fragment; +import androidx.fragment.app.Fragment; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/VehicleActivity.java b/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/VehicleActivity.java index 0efe1962..9ba82599 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/VehicleActivity.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/VehicleActivity.java @@ -9,11 +9,11 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.support.design.widget.Snackbar; import android.view.MenuItem; import android.view.View; import com.crashlytics.android.Crashlytics; +import com.google.android.material.snackbar.Snackbar; import com.google.firebase.analytics.FirebaseAnalytics; import org.joda.time.DateTime; @@ -86,6 +86,7 @@ public boolean onOptionsItemSelected(MenuItem item) { ShortcutHelper.createShortcut(this, vLayoutRoot, shortcutIntent, + mRequest.getVehicleId(), IrailVehicleJourneyStub.getVehicleName(mRequest.getVehicleId()), "VehicleJourney " + IrailVehicleJourneyStub.getVehicleName(mRequest.getVehicleId()), R.mipmap.ic_shortcut_train); diff --git a/Hyperrail/src/main/java/be/hyperrail/android/adapter/DateSeparatorViewHolder.java b/Hyperrail/src/main/java/be/hyperrail/android/adapter/DateSeparatorViewHolder.java index 5e4cae2b..d14988f1 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/adapter/DateSeparatorViewHolder.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/adapter/DateSeparatorViewHolder.java @@ -6,7 +6,7 @@ package be.hyperrail.android.adapter; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView; import android.view.View; import android.widget.TextView; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/adapter/DisturbanceCardAdapter.java b/Hyperrail/src/main/java/be/hyperrail/android/adapter/DisturbanceCardAdapter.java index d8d95000..7feb198e 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/adapter/DisturbanceCardAdapter.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/adapter/DisturbanceCardAdapter.java @@ -14,8 +14,8 @@ import android.content.Context; import android.preference.PreferenceManager; -import android.support.annotation.NonNull; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/adapter/LiveboardCardAdapter.java b/Hyperrail/src/main/java/be/hyperrail/android/adapter/LiveboardCardAdapter.java index 22c9aeb9..131e90e0 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/adapter/LiveboardCardAdapter.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/adapter/LiveboardCardAdapter.java @@ -15,7 +15,7 @@ import android.app.Activity; import android.content.Context; import android.preference.PreferenceManager; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/adapter/OnRecyclerItemClickListener.java b/Hyperrail/src/main/java/be/hyperrail/android/adapter/OnRecyclerItemClickListener.java index 8767b56f..461b115b 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/adapter/OnRecyclerItemClickListener.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/adapter/OnRecyclerItemClickListener.java @@ -12,7 +12,7 @@ package be.hyperrail.android.adapter; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView; /** * Interface for item click callbacks diff --git a/Hyperrail/src/main/java/be/hyperrail/android/adapter/OnRecyclerItemLongClickListener.java b/Hyperrail/src/main/java/be/hyperrail/android/adapter/OnRecyclerItemLongClickListener.java index e1290b7c..076bf3b2 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/adapter/OnRecyclerItemLongClickListener.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/adapter/OnRecyclerItemLongClickListener.java @@ -18,7 +18,7 @@ package be.hyperrail.android.adapter; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView; /** * Interface for item click callbacks diff --git a/Hyperrail/src/main/java/be/hyperrail/android/adapter/RouteCardAdapter.java b/Hyperrail/src/main/java/be/hyperrail/android/adapter/RouteCardAdapter.java index 40378063..be119907 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/adapter/RouteCardAdapter.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/adapter/RouteCardAdapter.java @@ -15,7 +15,7 @@ import android.app.Activity; import android.content.Context; import android.preference.PreferenceManager; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/adapter/RouteDetailCardAdapter.java b/Hyperrail/src/main/java/be/hyperrail/android/adapter/RouteDetailCardAdapter.java index da420a44..961f8133 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/adapter/RouteDetailCardAdapter.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/adapter/RouteDetailCardAdapter.java @@ -15,8 +15,8 @@ import android.app.Activity; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.annotation.NonNull; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/adapter/RouteSuggestionsCardAdapter.java b/Hyperrail/src/main/java/be/hyperrail/android/adapter/RouteSuggestionsCardAdapter.java index 11323d3a..d8c2e85b 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/adapter/RouteSuggestionsCardAdapter.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/adapter/RouteSuggestionsCardAdapter.java @@ -14,8 +14,8 @@ import android.content.Context; import android.preference.PreferenceManager; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.RecyclerView; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/adapter/StationSuggestionsCardAdapter.java b/Hyperrail/src/main/java/be/hyperrail/android/adapter/StationSuggestionsCardAdapter.java index 3b7fae37..1a66dc3f 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/adapter/StationSuggestionsCardAdapter.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/adapter/StationSuggestionsCardAdapter.java @@ -14,9 +14,9 @@ import android.content.Context; import android.preference.PreferenceManager; -import android.support.annotation.NonNull; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/adapter/VehicleStopCardAdapter.java b/Hyperrail/src/main/java/be/hyperrail/android/adapter/VehicleStopCardAdapter.java index afd4eedd..9fc410ba 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/adapter/VehicleStopCardAdapter.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/adapter/VehicleStopCardAdapter.java @@ -8,8 +8,8 @@ import android.content.Context; import android.preference.PreferenceManager; -import android.support.annotation.NonNull; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/adapter/VehicleSuggestionsCardAdapter.java b/Hyperrail/src/main/java/be/hyperrail/android/adapter/VehicleSuggestionsCardAdapter.java index 60043356..13ed4f76 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/adapter/VehicleSuggestionsCardAdapter.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/adapter/VehicleSuggestionsCardAdapter.java @@ -8,9 +8,9 @@ import android.content.Context; import android.preference.PreferenceManager; -import android.support.annotation.NonNull; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/fragments/FeedbackFragment.java b/Hyperrail/src/main/java/be/hyperrail/android/fragments/FeedbackFragment.java index a4f0fd8e..639724c0 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/fragments/FeedbackFragment.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/fragments/FeedbackFragment.java @@ -16,9 +16,9 @@ import android.content.Intent; import android.content.pm.PackageInfo; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/fragments/LiveboardSearchFragment.java b/Hyperrail/src/main/java/be/hyperrail/android/fragments/LiveboardSearchFragment.java index c26ba6fb..5b019c90 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/fragments/LiveboardSearchFragment.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/fragments/LiveboardSearchFragment.java @@ -29,14 +29,14 @@ import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.design.widget.Snackbar; -import android.support.v4.app.Fragment; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import com.google.android.material.snackbar.Snackbar; +import androidx.fragment.app.Fragment; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.text.Editable; import android.text.TextWatcher; import android.view.ContextMenu; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/fragments/RouteSearchFragment.java b/Hyperrail/src/main/java/be/hyperrail/android/fragments/RouteSearchFragment.java index ee89a67b..39644ac9 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/fragments/RouteSearchFragment.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/fragments/RouteSearchFragment.java @@ -21,11 +21,11 @@ import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.design.widget.Snackbar; -import android.support.v4.app.Fragment; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import com.google.android.material.snackbar.Snackbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.text.Editable; import android.view.ContextMenu; import android.view.KeyEvent; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/fragments/VehicleSearchFragment.java b/Hyperrail/src/main/java/be/hyperrail/android/fragments/VehicleSearchFragment.java index 32be220e..094e6338 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/fragments/VehicleSearchFragment.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/fragments/VehicleSearchFragment.java @@ -27,13 +27,13 @@ import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.design.widget.Snackbar; -import android.support.v4.app.Fragment; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import com.google.android.material.snackbar.Snackbar; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.view.ContextMenu; import android.view.KeyEvent; import android.view.LayoutInflater; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/DisturbanceListFragment.java b/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/DisturbanceListFragment.java index 7125491f..b442c100 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/DisturbanceListFragment.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/DisturbanceListFragment.java @@ -16,8 +16,8 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/LiveboardFragment.java b/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/LiveboardFragment.java index 0f85a89c..85f4827b 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/LiveboardFragment.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/LiveboardFragment.java @@ -8,10 +8,10 @@ import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/RecyclerViewFragment.java b/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/RecyclerViewFragment.java index b7dd6a6d..c19ae7a1 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/RecyclerViewFragment.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/RecyclerViewFragment.java @@ -15,15 +15,15 @@ import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.StringRes; -import android.support.v4.app.Fragment; -import android.support.v4.widget.SwipeRefreshLayout; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.DividerItemDecoration; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.fragment.app.Fragment; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.view.View; import android.widget.TextView; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/ResultFragment.java b/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/ResultFragment.java index 5f179567..bfe899e3 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/ResultFragment.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/ResultFragment.java @@ -12,7 +12,7 @@ package be.hyperrail.android.fragments.searchresult; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import be.hyperrail.android.util.OnDateTimeSetListener; import be.hyperrail.opentransportdata.common.contracts.TransportDataRequest; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/RouteFragment.java b/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/RouteFragment.java index 63ccb79c..23107348 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/RouteFragment.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/RouteFragment.java @@ -8,9 +8,9 @@ import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/RoutesFragment.java b/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/RoutesFragment.java index 040cbd67..a83e0471 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/RoutesFragment.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/RoutesFragment.java @@ -15,10 +15,10 @@ import android.content.Intent; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/VehicleFragment.java b/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/VehicleFragment.java index fd66c7ca..29d3a826 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/VehicleFragment.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/fragments/searchresult/VehicleFragment.java @@ -14,11 +14,11 @@ import android.graphics.drawable.Drawable; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.RecyclerView; import android.view.Display; import android.view.LayoutInflater; import android.view.View; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/infiniteScrolling/InfiniteScrollingAdapter.java b/Hyperrail/src/main/java/be/hyperrail/android/infiniteScrolling/InfiniteScrollingAdapter.java index e77597f7..4227da7b 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/infiniteScrolling/InfiniteScrollingAdapter.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/infiniteScrolling/InfiniteScrollingAdapter.java @@ -14,9 +14,9 @@ import android.app.Activity; import android.graphics.PorterDuff; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/util/ErrorDialogFactory.java b/Hyperrail/src/main/java/be/hyperrail/android/util/ErrorDialogFactory.java index d5ce2d64..17845d38 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/util/ErrorDialogFactory.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/util/ErrorDialogFactory.java @@ -9,7 +9,7 @@ import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; -import android.support.annotation.StringRes; +import androidx.annotation.StringRes; import android.util.Log; import be.hyperrail.android.R; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/util/NotificationLayoutBuilder.java b/Hyperrail/src/main/java/be/hyperrail/android/util/NotificationLayoutBuilder.java index bb7163a4..9c2ecca1 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/util/NotificationLayoutBuilder.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/util/NotificationLayoutBuilder.java @@ -13,7 +13,7 @@ package be.hyperrail.android.util; import android.content.Context; -import android.support.v4.content.ContextCompat; +import androidx.core.content.ContextCompat; import android.view.View; import android.widget.RemoteViews; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/util/ShortcutHelper.java b/Hyperrail/src/main/java/be/hyperrail/android/util/ShortcutHelper.java index 4b393d43..85c7cafe 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/util/ShortcutHelper.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/util/ShortcutHelper.java @@ -8,20 +8,21 @@ import android.app.AlertDialog; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutManager; import android.graphics.drawable.Icon; import android.os.Build; -import android.support.annotation.DrawableRes; -import android.support.design.widget.Snackbar; import android.text.InputType; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; import android.widget.FrameLayout; +import androidx.annotation.DrawableRes; + +import com.google.android.material.snackbar.Snackbar; + import be.hyperrail.android.R; /** @@ -33,7 +34,7 @@ private ShortcutHelper(){ // No public constructor } - public static void createShortcut(final Context context, final View layoutRoot, final Intent intent, String defaultTitle, final String longLabel, @DrawableRes final int icon) { + public static void createShortcut(final Context context, final View layoutRoot, final Intent intent, String id, String defaultTitle, final String longLabel, @DrawableRes final int icon) { // Ask users if they want to set a custom title AlertDialog.Builder builder = new AlertDialog.Builder(context); @@ -54,27 +55,17 @@ public static void createShortcut(final Context context, final View layoutRoot, builder.setView(container); // Set up the buttons - builder.setPositiveButton(R.string.button_add, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - addShortcut(context, layoutRoot, intent, input.getText().toString(), longLabel, icon); - } - }); - builder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.cancel(); - } - }); + builder.setPositiveButton(R.string.button_add, (dialog, which) -> addShortcut(context, layoutRoot, intent, id, input.getText().toString(), longLabel, icon)); + builder.setNegativeButton(R.string.button_cancel, (dialog, which) -> dialog.cancel()); builder.show(); } - private static void addShortcut(Context context, View layoutRoot, Intent intent, String shortLabel, String longLabel, @DrawableRes int icon) { + private static void addShortcut(Context context, View layoutRoot, Intent intent, String id, String shortLabel, String longLabel, @DrawableRes int icon) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - ShortcutInfo.Builder mShortcutInfoBuilder = new ShortcutInfo.Builder(context, shortLabel); + ShortcutInfo.Builder mShortcutInfoBuilder = new ShortcutInfo.Builder(context, id); mShortcutInfoBuilder.setShortLabel(shortLabel); mShortcutInfoBuilder.setLongLabel(longLabel); mShortcutInfoBuilder.setIcon(Icon.createWithResource(context, icon)); diff --git a/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/LiveboardStopLayout.java b/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/LiveboardStopLayout.java index b1107e27..6cc2c889 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/LiveboardStopLayout.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/LiveboardStopLayout.java @@ -9,8 +9,8 @@ import android.content.Context; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; -import android.support.annotation.Nullable; -import android.support.v4.content.ContextCompat; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/RouteListItemLayout.java b/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/RouteListItemLayout.java index 19e73bed..3fdd68f4 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/RouteListItemLayout.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/RouteListItemLayout.java @@ -18,11 +18,11 @@ import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.DefaultItemAnimator; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/RouteTrainItemLayout.java b/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/RouteTrainItemLayout.java index d7d0b80c..fccc6d0b 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/RouteTrainItemLayout.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/RouteTrainItemLayout.java @@ -19,8 +19,8 @@ package be.hyperrail.android.viewgroup; import android.content.Context; -import android.support.annotation.Nullable; -import android.support.v4.content.ContextCompat; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/RouteTransferItemLayout.java b/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/RouteTransferItemLayout.java index 52d639bf..83398b12 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/RouteTransferItemLayout.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/RouteTransferItemLayout.java @@ -21,8 +21,8 @@ import android.content.Context; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; -import android.support.annotation.Nullable; -import android.support.v4.content.ContextCompat; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/VehicleStopLayout.java b/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/VehicleStopLayout.java index 7b38fe83..a5aac93a 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/VehicleStopLayout.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/viewgroup/VehicleStopLayout.java @@ -9,8 +9,8 @@ import android.content.Context; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; -import android.support.annotation.Nullable; -import android.support.v4.content.ContextCompat; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/widget/NextDeparturesRemoteViewsDataProvider.java b/Hyperrail/src/main/java/be/hyperrail/android/widget/NextDeparturesRemoteViewsDataProvider.java index 6dc39d1b..23eeb427 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/widget/NextDeparturesRemoteViewsDataProvider.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/widget/NextDeparturesRemoteViewsDataProvider.java @@ -9,7 +9,7 @@ import android.content.Context; import android.content.Intent; import android.graphics.drawable.BitmapDrawable; -import android.support.v4.content.ContextCompat; +import androidx.core.content.ContextCompat; import android.util.Log; import android.view.View; import android.widget.RemoteViews; diff --git a/Hyperrail/src/main/java/be/hyperrail/android/widget/NextDeparturesWidgetProvider.java b/Hyperrail/src/main/java/be/hyperrail/android/widget/NextDeparturesWidgetProvider.java index 3e639c26..9c4a3eaf 100644 --- a/Hyperrail/src/main/java/be/hyperrail/android/widget/NextDeparturesWidgetProvider.java +++ b/Hyperrail/src/main/java/be/hyperrail/android/widget/NextDeparturesWidgetProvider.java @@ -17,6 +17,7 @@ import be.hyperrail.android.R; import be.hyperrail.android.activities.searchresult.LiveboardActivity; +import be.hyperrail.android.logging.HyperRailLog; import be.hyperrail.opentransportdata.OpenTransportApi; import be.hyperrail.opentransportdata.common.contracts.QueryTimeDefinition; import be.hyperrail.opentransportdata.common.exceptions.StopLocationNotResolvedException; @@ -28,6 +29,7 @@ public class NextDeparturesWidgetProvider extends AppWidgetProvider { SharedPreferences prefs; + HyperRailLog log = HyperRailLog.getLogger(NextDeparturesWidgetProvider.class); public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { prefs = context.getSharedPreferences("widgets", 0); @@ -43,18 +45,31 @@ private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { String id = this.prefs.getString("NextDepartures:" + appWidgetId, null); if (id == null) { - Log.w("widgets", "No station ID found for " + "NextDepartures:" + appWidgetId); + Log.w("widgets", "No station ID found for NextDepartures widget id: " + appWidgetId); return; } - StopLocation mStation = null; + StopLocation mStation; try { mStation = OpenTransportApi.getStopLocationProviderInstance().getStoplocationBySemanticId(id); - } catch (StopLocationNotResolvedException e) { + } catch (StopLocationNotResolvedException searchException) { + log.warning("Failed to lookup station URI for widget: " + id); + log.logException(searchException); + try { + mStation = OpenTransportApi.getStopLocationProviderInstance().getStoplocationByHafasId(id); + } catch (StopLocationNotResolvedException fallbackSearchException) { + log.warning("Failed to lookup station ID for widget: " + id); + log.logException(fallbackSearchException); + mStation = null; + } + } + + if (mStation == null) { RemoteViews views = new RemoteViews(context.getPackageName(), - R.layout.widget_nextdepartures_error); + R.layout.widget_nextdepartures_error); appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, android.R.id.list); appWidgetManager.updateAppWidget(appWidgetId, views); + return; } // Set up the intent that starts the NextDeparturesWidgetService, which will @@ -64,16 +79,16 @@ private void updateAppWidget(Context context, AppWidgetManager appWidgetManager, // Create an Intent to launch ExampleActivity Intent onClickIntent = LiveboardActivity.createIntent(context, - new LiveboardRequest(mStation, - QueryTimeDefinition.EQUAL_OR_LATER, - LiveboardType.DEPARTURES, - null)); + new LiveboardRequest(mStation, + QueryTimeDefinition.EQUAL_OR_LATER, + LiveboardType.DEPARTURES, + null)); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, onClickIntent, 0); // Get the layout for the App Widget and attach an on-click listener // to the button RemoteViews views = new RemoteViews(context.getPackageName(), - R.layout.widget_nextdepartures); + R.layout.widget_nextdepartures); views.setTextViewText(R.id.text_station, mStation.getLocalizedName()); // Set up the RemoteViews object to use a RemoteViews adapter. // This adapter connects diff --git a/Hyperrail/src/main/res/layout/activity_first_launch_guide.xml b/Hyperrail/src/main/res/layout/activity_first_launch_guide.xml index 72e31380..e3bfba21 100644 --- a/Hyperrail/src/main/res/layout/activity_first_launch_guide.xml +++ b/Hyperrail/src/main/res/layout/activity_first_launch_guide.xml @@ -9,7 +9,7 @@ android:layout_height="match_parent" android:background="@color/colorPrimary"> - - - - - + \ No newline at end of file diff --git a/Hyperrail/src/main/res/layout/activity_result_tabbed.xml b/Hyperrail/src/main/res/layout/activity_result_tabbed.xml index 7ac0f893..50cda36a 100644 --- a/Hyperrail/src/main/res/layout/activity_result_tabbed.xml +++ b/Hyperrail/src/main/res/layout/activity_result_tabbed.xml @@ -11,13 +11,13 @@ - - - + - - - + - - + - - + diff --git a/Hyperrail/src/main/res/layout/cardview_disturbance.xml b/Hyperrail/src/main/res/layout/cardview_disturbance.xml index ad17920f..f9e3010d 100644 --- a/Hyperrail/src/main/res/layout/cardview_disturbance.xml +++ b/Hyperrail/src/main/res/layout/cardview_disturbance.xml @@ -1,5 +1,5 @@ - - + diff --git a/Hyperrail/src/main/res/layout/cardview_liveboard.xml b/Hyperrail/src/main/res/layout/cardview_liveboard.xml index aef3fddf..8da719f7 100644 --- a/Hyperrail/src/main/res/layout/cardview_liveboard.xml +++ b/Hyperrail/src/main/res/layout/cardview_liveboard.xml @@ -1,5 +1,5 @@ - - + diff --git a/Hyperrail/src/main/res/layout/cardview_route.xml b/Hyperrail/src/main/res/layout/cardview_route.xml index a83abe4e..d91d7a5f 100644 --- a/Hyperrail/src/main/res/layout/cardview_route.xml +++ b/Hyperrail/src/main/res/layout/cardview_route.xml @@ -1,5 +1,5 @@ - - + diff --git a/Hyperrail/src/main/res/layout/cardview_route_detail_train.xml b/Hyperrail/src/main/res/layout/cardview_route_detail_train.xml index 52db32fd..dd92dac3 100644 --- a/Hyperrail/src/main/res/layout/cardview_route_detail_train.xml +++ b/Hyperrail/src/main/res/layout/cardview_route_detail_train.xml @@ -1,5 +1,5 @@ - - + diff --git a/Hyperrail/src/main/res/layout/cardview_route_detail_transfer.xml b/Hyperrail/src/main/res/layout/cardview_route_detail_transfer.xml index 9fb7a781..e4cbe67b 100644 --- a/Hyperrail/src/main/res/layout/cardview_route_detail_transfer.xml +++ b/Hyperrail/src/main/res/layout/cardview_route_detail_transfer.xml @@ -1,5 +1,5 @@ - - + diff --git a/Hyperrail/src/main/res/layout/cardview_route_history.xml b/Hyperrail/src/main/res/layout/cardview_route_history.xml index ef0ecd0d..e95be592 100644 --- a/Hyperrail/src/main/res/layout/cardview_route_history.xml +++ b/Hyperrail/src/main/res/layout/cardview_route_history.xml @@ -1,5 +1,5 @@ - - + diff --git a/Hyperrail/src/main/res/layout/cardview_station.xml b/Hyperrail/src/main/res/layout/cardview_station.xml index a2550ea9..c9f860d5 100644 --- a/Hyperrail/src/main/res/layout/cardview_station.xml +++ b/Hyperrail/src/main/res/layout/cardview_station.xml @@ -1,5 +1,5 @@ - - + diff --git a/Hyperrail/src/main/res/layout/cardview_vehiclestop.xml b/Hyperrail/src/main/res/layout/cardview_vehiclestop.xml index cca48f72..d2ea05aa 100644 --- a/Hyperrail/src/main/res/layout/cardview_vehiclestop.xml +++ b/Hyperrail/src/main/res/layout/cardview_vehiclestop.xml @@ -1,5 +1,5 @@ - - + diff --git a/Hyperrail/src/main/res/layout/fragment_liveboard_search.xml b/Hyperrail/src/main/res/layout/fragment_liveboard_search.xml index 4a46b863..a3b777d4 100644 --- a/Hyperrail/src/main/res/layout/fragment_liveboard_search.xml +++ b/Hyperrail/src/main/res/layout/fragment_liveboard_search.xml @@ -22,7 +22,7 @@ - - @@ -15,7 +15,7 @@ android:layout_height="match_parent" android:orientation="vertical"> - - + diff --git a/Hyperrail/src/main/res/layout/fragment_recyclerview_list_map.xml b/Hyperrail/src/main/res/layout/fragment_recyclerview_list_map.xml index 48d37d78..62f63f43 100644 --- a/Hyperrail/src/main/res/layout/fragment_recyclerview_list_map.xml +++ b/Hyperrail/src/main/res/layout/fragment_recyclerview_list_map.xml @@ -18,7 +18,7 @@ android:layout_weight="4" tools:context=".MapsActivity" /> - - - + diff --git a/Hyperrail/src/main/res/layout/fragment_route_search.xml b/Hyperrail/src/main/res/layout/fragment_route_search.xml index e76366bc..3dae1856 100644 --- a/Hyperrail/src/main/res/layout/fragment_route_search.xml +++ b/Hyperrail/src/main/res/layout/fragment_route_search.xml @@ -106,7 +106,7 @@ - - - - - translations; + private String semanticId; private StopLocationFacilities stationFacilities; - protected StopLocationImpl() { - - } - - public StopLocationImpl(String hafasId, String name, Map translations, String localizedName, String country, double latitude, double longitude, float avgStopTimes) { + public StopLocationImpl(String hafasId, String semanticIdentifier, String name, Map translations, + String localizedName, String country, double latitude, double longitude, float avgStopTimes) { if (hafasId.startsWith("BE.NMBS.")) { throw new IllegalArgumentException("Station IDs should not start with BE.NMBS!"); } this.hafasId = hafasId; + this.semanticId = semanticIdentifier; this.name = name; this.translations = translations; this.localizedName = localizedName; @@ -43,16 +42,17 @@ public StopLocationImpl(StopLocation stopLocation) { copy(stopLocation); } - public void copy(StopLocation copy) { - this.hafasId = copy.getHafasId(); - this.name = copy.getName(); - this.translations = copy.getTranslations(); - this.localizedName = copy.getLocalizedName(); - this.country_code = copy.getCountryCode(); - this.country_uri = copy.getCountryUri(); - this.latitude = copy.getLatitude(); - this.longitude = copy.getLongitude(); - this.avgStopTimes = copy.getAvgStopTimes(); + private void copy(StopLocation original) { + this.hafasId = original.getHafasId(); + this.semanticId = original.getSemanticId(); + this.name = original.getName(); + this.translations = original.getTranslations(); + this.localizedName = original.getLocalizedName(); + this.country_code = original.getCountryCode(); + this.country_uri = original.getCountryUri(); + this.latitude = original.getLatitude(); + this.longitude = original.getLongitude(); + this.avgStopTimes = original.getAvgStopTimes(); } public String getName() { @@ -86,7 +86,7 @@ public String getUicId() { } public String getSemanticId() { - return "http://irail.be/stations/NMBS/" + hafasId; + return semanticId; } /** diff --git a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/models/implementation/TransferImpl.java b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/models/implementation/TransferImpl.java index b3ef9716..4d9363dc 100644 --- a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/models/implementation/TransferImpl.java +++ b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/models/implementation/TransferImpl.java @@ -6,7 +6,7 @@ package be.hyperrail.opentransportdata.common.models.implementation; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import org.joda.time.DateTime; import org.joda.time.Duration; diff --git a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/models/implementation/VehicleStopImpl.java b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/models/implementation/VehicleStopImpl.java index ef619d77..33b8461d 100644 --- a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/models/implementation/VehicleStopImpl.java +++ b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/models/implementation/VehicleStopImpl.java @@ -18,7 +18,7 @@ package be.hyperrail.opentransportdata.common.models.implementation; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import org.joda.time.DateTime; import org.joda.time.Duration; diff --git a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/requests/LiveboardRequest.java b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/requests/LiveboardRequest.java index be4fd6dd..7d8375b9 100644 --- a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/requests/LiveboardRequest.java +++ b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/requests/LiveboardRequest.java @@ -18,7 +18,7 @@ package be.hyperrail.opentransportdata.common.requests; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import org.joda.time.DateTime; import org.json.JSONException; diff --git a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/requests/OpenTransportBaseRequest.java b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/requests/OpenTransportBaseRequest.java index 6c63a2f4..33a428dc 100644 --- a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/requests/OpenTransportBaseRequest.java +++ b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/requests/OpenTransportBaseRequest.java @@ -12,7 +12,7 @@ package be.hyperrail.opentransportdata.common.requests; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import org.joda.time.DateTime; import org.json.JSONException; diff --git a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/requests/RoutePlanningRequest.java b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/requests/RoutePlanningRequest.java index 2a910737..928e02a7 100644 --- a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/requests/RoutePlanningRequest.java +++ b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/requests/RoutePlanningRequest.java @@ -7,7 +7,7 @@ package be.hyperrail.opentransportdata.common.requests; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import org.joda.time.DateTime; import org.json.JSONException; diff --git a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/requests/VehicleRequest.java b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/requests/VehicleRequest.java index 0582ec0f..58b8cc41 100644 --- a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/requests/VehicleRequest.java +++ b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/requests/VehicleRequest.java @@ -6,7 +6,7 @@ package be.hyperrail.opentransportdata.common.requests; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import org.joda.time.DateTime; import org.json.JSONException; diff --git a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/webdb/WebDb.java b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/webdb/WebDb.java deleted file mode 100644 index 99a7488f..00000000 --- a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/webdb/WebDb.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * 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/. - */ - -/* - * 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.opentransportdata.common.webdb; - -import android.content.Context; -import android.database.sqlite.SQLiteDatabase; -import android.net.ConnectivityManager; -import android.net.Network; -import android.net.NetworkCapabilities; -import android.net.NetworkInfo; -import android.os.AsyncTask; -import android.util.ArrayMap; - -import org.joda.time.DateTime; - -import java.util.Arrays; -import java.util.Map; - -import be.hyperrail.opentransportdata.logging.OpenTransportLog; - -/** - * A database which can automatically update from a predefined web page. - * Using this database removes the need for application updates every time something changes - */ -public class WebDb { - - private static final Object instanceGetterLock = new Object(); - private static final Map instances = new ArrayMap<>(); - private static final OpenTransportLog log = OpenTransportLog.getLogger(WebDb.class); - private final Object databaseModificationLock = new Object(); - private volatile WebDbSqliteBackend db; - private Context context; - private WebDbDataDefinition dataDefinition; - private WebDbConfig webDbConfig; - - /** - * Instantiate a new WebDb, according to the parameters defined in the WebDbDataDefinition. - * Don't run this code on the main thread as it contains blocking I/O - * - * @param appContext The Android application context - * @param dataDefinition The data definition, containing both local and remote names as well as methods to create the database. - */ - private WebDb(Context appContext, WebDbDataDefinition dataDefinition) { - this.context = appContext; - this.webDbConfig = new WebDbConfig(appContext); - this.dataDefinition = dataDefinition; - - log.info("Creating a new WebDb instance for " + dataDefinition.getDatabaseName()); - - - int currentVersion = webDbConfig.getCurrentDatabaseVersion(dataDefinition.getDatabaseName()); - int embeddedVersion = getVersionCodeForDateTime(dataDefinition.getLastModifiedLocalDate()); - if (currentVersion < embeddedVersion) { - currentVersion = embeddedVersion; - } - - synchronized (databaseModificationLock) { - this.db = new WebDbSqliteBackend(appContext, currentVersion, dataDefinition, null); - } - - //updateDatabaseIfConnected(); - log.debug("Created a new WebDb instance for " + dataDefinition.getDatabaseName()); - } - - /** - * Instantiate a new WebDb, according to the parameters defined in the WebDbDataDefinition. - * Don't run this code on the main thread as it contains blocking I/O - * - * @param appContext The Android application context - * @param dataDefinition The data definition, containing both local and remote names as well as methods to create the database. - */ - public static WebDb getInstance(Context appContext, WebDbDataDefinition dataDefinition) { - synchronized (instanceGetterLock) { - if (!instances.containsKey(dataDefinition.getDatabaseName())) { - instances.put(dataDefinition.getDatabaseName(), new WebDb(appContext, dataDefinition)); - } - return instances.get(dataDefinition.getDatabaseName()); - } - } - - private static int getVersionCodeForDateTime(DateTime dateTime) { - return Integer.valueOf(dateTime.toString("YYMMDD") + "00"); - } - - private void updateDatabaseIfConnected() { - // If the last check was more than 2 days ago, try to check - if (webDbConfig.getTimeOfLastCheck(dataDefinition.getDatabaseName()).isBefore(DateTime.now().minusDays(2))) { - // If not restricted to Wifi, or if connecected to wifi, check for updates - boolean isConnectedToWifi = isConnectedToWifi(); - log.info("WLAN: " + isConnectedToWifi); - if (!dataDefinition.updateOnlyOnWifi() || isConnectedToWifi) { - log.info("Starting update check for " + dataDefinition.getDatabaseName()); - UpdateDatabaseIfNeeded updateTask = new UpdateDatabaseIfNeeded(this, dataDefinition); - updateTask.execute(dataDefinition); - } else { - log.info("Not starting update check for " + dataDefinition.getDatabaseName()); - } - } - } - - private boolean isConnectedToWifi() { - ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { - Network wifiNetwork = connectivityManager.getActiveNetwork(); - final NetworkCapabilities capabilities = connectivityManager - .getNetworkCapabilities(wifiNetwork); - return capabilities != null - && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED) - && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED) && !capabilities.hasCapability(NetworkCapabilities.TRANSPORT_CELLULAR); - } else { - // For older devices - NetworkInfo wifiNetwork = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); - return wifiNetwork.isConnected(); - } - - } - - public SQLiteDatabase getReadableDatabase() { - log.debug("GETTING READABLE DATABASE " + dataDefinition.getDatabaseName()); - log.debug(Arrays.toString(Thread.currentThread().getStackTrace())); - synchronized (databaseModificationLock) { - // This will cause database creation - return db.getReadableDatabase(); - } - } - - private static class UpdateDatabaseIfNeeded extends AsyncTask { - private WebDb webDbRef; - private WebDbDataDefinition definition; - - // only retain a weak reference to the activity - UpdateDatabaseIfNeeded(WebDb webDb, WebDbDataDefinition definition) { - webDbRef = webDb; - this.definition = definition; - } - - @Override - protected Boolean doInBackground(WebDbDataDefinition... definitions) { - DateTime lastModifiedOnline = definitions[0].getLastModifiedOnlineDate(); - - log.info("Online last modified date check for " + - definition.getDatabaseName() + " resulted in " + lastModifiedOnline.toString("YYYY-MM-HH HH:mm")); - String databaseName = definition.getDatabaseName(); - - WebDb webDb = webDbRef; - - if (webDb == null) { - return false; - } - - if (!lastModifiedOnline.isAfter(webDb.webDbConfig.getTimeOfLastOnlineUpdate(databaseName))) { - log.info("No newer data available: " + databaseName); - return false; - } - - Object newData = definition.downloadOnlineData(); - if (newData == null) { - log.warning("Failed to get updated data from internet for database " + definition.getDatabaseName() + ", aborting update"); - return false; - } - - log.info("Re-creating database using online data: " + databaseName); - synchronized (webDb.databaseModificationLock) { - try { - // Allow other threads to finish their database queries which happen outside synchronized blocks - wait(1000); - } catch (Exception e) { - // Ignored - } - webDb.db.close(); - webDb.db = new WebDbSqliteBackend(webDb.context, getVersionCodeForDateTime(lastModifiedOnline), definition, newData); - webDb.db.getReadableDatabase(); // Ensure we populate the database as well - } - log.info("Re-created database using online data: " + databaseName); - webDb.webDbConfig.setTimeOfLastOnlineUpdateToNow(databaseName); - webDb.webDbConfig.setTimeOfLastCheckToNow(databaseName); - return true; - } - } -} \ No newline at end of file diff --git a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/webdb/WebDbConfig.java b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/webdb/WebDbConfig.java deleted file mode 100644 index 62325e40..00000000 --- a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/webdb/WebDbConfig.java +++ /dev/null @@ -1,47 +0,0 @@ -package be.hyperrail.opentransportdata.common.webdb; - -import android.content.Context; -import android.content.SharedPreferences; - -import org.joda.time.DateTime; - -public class WebDbConfig { - - private final SharedPreferences preferences; - - WebDbConfig(Context applicationContext) { - this.preferences = applicationContext.getSharedPreferences("webdb", Context.MODE_PRIVATE); - } - - void setCurrentDatabaseVersion(String databaseName, int version) { - preferences.edit().putInt(databaseName + "_version", version).apply(); - } - - int getCurrentDatabaseVersion(String databaseName) { - return preferences.getInt(databaseName + "_version", 0); - } - - DateTime getTimeOfLastCheck(String databaseName) { - return new DateTime(preferences.getLong(databaseName + "_lastupdatecheck", 0)); - } - - DateTime getTimeOfLastOnlineUpdate(String databaseName) { - return new DateTime(preferences.getLong(databaseName + "_lastonlineupdate", 0)); - } - - DateTime getTimeOfLastOfflineUpdate(String databaseName) { - return new DateTime(preferences.getLong(databaseName + "_lastofflineupdate", 0)); - } - - void setTimeOfLastCheckToNow(String databaseName) { - preferences.edit().putLong(databaseName + "_lastupdatecheck", DateTime.now().getMillis()).apply(); - } - - void setTimeOfLastOnlineUpdateToNow(String databaseName) { - preferences.edit().putLong(databaseName + "_lastonlineupdate", DateTime.now().getMillis()).apply(); - } - - void setTimeOfLastOfflineUpdateToNow(String databaseName) { - preferences.edit().putLong(databaseName + "_lastofflineupdate", DateTime.now().getMillis()).apply(); - } -} diff --git a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/webdb/WebDbDataDefinition.java b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/webdb/WebDbDataDefinition.java deleted file mode 100644 index 7246bb2c..00000000 --- a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/webdb/WebDbDataDefinition.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.opentransportdata.common.webdb; - -import android.database.sqlite.SQLiteDatabase; -import android.support.annotation.RawRes; - -import org.joda.time.DateTime; - -/** - * This interface describes how the data structure for WebDb should be applied to the database. - */ -public interface WebDbDataDefinition { - - /** - * Whether or not updating the data should be limited to moments when the user is connected to Wi-Fi. - * - * @return True if updates should only happen when connected to Wi-Fi. - */ - boolean updateOnlyOnWifi(); - - /** - * Get the default data embedded with the application. - * - * @return The raw resource holding the data to be used when no internet connectivity is available. - */ - @RawRes - int getEmbeddedDataResourceId(); - - /** - * Get the online location of the data. - * - * @return The URL pointing to the data on the internet. - */ - String getOnlineDataURL(); - - /** - * Get the local name for the database. - * - * @return The local name for the database. - */ - String getDatabaseName(); - - /** - * Get the last modified timestamp for the embedded data. - * - * @return The datetime at which the embedded data was last modified. - */ - DateTime getLastModifiedLocalDate(); - - /** - * Get the last modified timestamp for the online data. - * - * @return The datetime at which the online data was last modified. - */ - DateTime getLastModifiedOnlineDate(); - - void createDatabaseStructure(SQLiteDatabase db); - - boolean loadLocalData(SQLiteDatabase db); - - boolean importDownloadedData(SQLiteDatabase db, Object onlineUpdateData); - - Object downloadOnlineData(); - - void clearDatabase(SQLiteDatabase db); -} diff --git a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/webdb/WebDbSqliteBackend.java b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/webdb/WebDbSqliteBackend.java deleted file mode 100644 index 499f9fb1..00000000 --- a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/common/webdb/WebDbSqliteBackend.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.opentransportdata.common.webdb; - -import android.content.Context; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteOpenHelper; - -import be.hyperrail.opentransportdata.logging.OpenTransportLog; - -/** - * Database for querying stations - */ -class WebDbSqliteBackend extends SQLiteOpenHelper { - - private static final OpenTransportLog log = OpenTransportLog.getLogger(WebDbSqliteBackend.class); - - private final WebDbDataDefinition mDefinition; - private Object onlineUpdateData; - - WebDbSqliteBackend(Context context, int version, WebDbDataDefinition definition, Object onlineUpdateData) { - // Calculate the version based on a code version and the last modified date, followed by a revision - super(context, definition.getDatabaseName(), null, version); - log.info("Creating a new WebDbSqliteBackend instance for " + definition.getDatabaseName()); - this.mDefinition = definition; - this.onlineUpdateData = onlineUpdateData; - } - - /** - * Create the database. - * - * @param db Handle in which the database should be created. - */ - public synchronized void onCreate(SQLiteDatabase db) { - log.info("onCreate WebDbBackend instance " + mDefinition.getDatabaseName()); - wipeDatabase(db); - createAndFillDb(db); - log.info("onCreate WebDbBackend instance " + mDefinition.getDatabaseName()); - } - - public synchronized void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - log.info("onUpgrade WebDbBackend instance " + mDefinition.getDatabaseName()); - wipeDatabase(db); - createAndFillDb(db); - log.info("onUpgrade WebDbBackend instance " + mDefinition.getDatabaseName()); - } - - public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { - // Do nothing - } - - private void createAndFillDb(SQLiteDatabase db) { - mDefinition.createDatabaseStructure(db); - if (onlineUpdateData != null) { - // If online fetching failed - if (!mDefinition.importDownloadedData(db, onlineUpdateData)) { - log.warning("Failed to update WebDb instance using online data. " + - "Reverting to local data instead " + mDefinition.getDatabaseName()); - mDefinition.loadLocalData(db); - } - } else { - mDefinition.loadLocalData(db); - } - } - - private void wipeDatabase(SQLiteDatabase db) { - log.info("Wiping WebDbBackend " + mDefinition.getDatabaseName()); - mDefinition.clearDatabase(db); - } -} \ No newline at end of file diff --git a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/util/OccupancyHelper.java b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/util/OccupancyHelper.java index 1827e330..0de1aa45 100644 --- a/OpenTransport/src/main/java/be/hyperrail/opentransportdata/util/OccupancyHelper.java +++ b/OpenTransport/src/main/java/be/hyperrail/opentransportdata/util/OccupancyHelper.java @@ -6,7 +6,7 @@ package be.hyperrail.opentransportdata.util; -import android.support.annotation.DrawableRes; +import androidx.annotation.DrawableRes; import be.hyperrail.opentransportdata.R; import be.hyperrail.opentransportdata.common.contracts.TransportOccupancyLevel; diff --git a/OpenTransport/src/test/java/be/hyperrail/opentransportdata/common/models/implementation/StopLocationTest.java b/OpenTransport/src/test/java/be/hyperrail/opentransportdata/common/models/implementation/StopLocationTest.java index daa3df0c..bffc7f78 100644 --- a/OpenTransport/src/test/java/be/hyperrail/opentransportdata/common/models/implementation/StopLocationTest.java +++ b/OpenTransport/src/test/java/be/hyperrail/opentransportdata/common/models/implementation/StopLocationTest.java @@ -33,9 +33,9 @@ class StopLocationTest { @Test void testStopLocations() { - StopLocation station1 = new StopLocationImpl("1", "Brussels", getTranslationMap("Brussel", "fr", "de", "en"), "Brussel", "BE", 1, 2, 3); - StopLocation station2 = new StopLocationImpl("1", "Brussels-south", getTranslationMap("Brussel-zuid", "fr", "de", "en"), "Brussel-zuid", "BE", 1, 2, 3); - StopLocationImpl station3 = new StopLocationImpl("2", "Ghent", getTranslationMap("Gent", "Gand", "Gent", "Ghent"), "Gent", "BE", 1, 2, 3); + StopLocation station1 = new StopLocationImpl("1","http://irail.be/stations/NMBS/1", "Brussels", getTranslationMap("Brussel", "fr", "de", "en"), "Brussel", "BE", 1, 2, 3); + StopLocation station2 = new StopLocationImpl("1","http://irail.be/stations/NMBS/1", "Brussels-south", getTranslationMap("Brussel-zuid", "fr", "de", "en"), "Brussel-zuid", "BE", 1, 2, 3); + StopLocationImpl station3 = new StopLocationImpl("2","http://irail.be/stations/NMBS/2", "Ghent", getTranslationMap("Gent", "Gand", "Gent", "Ghent"), "Gent", "BE", 1, 2, 3); assertEquals(station1, station2); assertNotEquals(station1, station3); assertNotEquals(station2, station3); @@ -51,7 +51,7 @@ void testStopLocations() { assertEquals("http://irail.be/stations/NMBS/1", station1.getSemanticId()); - station3.copy(station1); + station3 = new StopLocationImpl(station1); assertEquals(station1.getHafasId(), station3.getHafasId()); assertEquals(station1.getName(), station3.getName()); assertEquals(station1.getTranslations().get("nl_BE"), station3.getTranslations().get("nl_BE")); @@ -79,7 +79,7 @@ void testStopLocationInvalidId() { Assertions.assertThrows( IllegalArgumentException.class, () -> { - new StopLocationImpl("BE.NMBS.000000001", "Brussels", getTranslationMap("Brussel", "fr", "de", "en"), "Brussel", "BE", 1, 2, 3); + new StopLocationImpl("BE.NMBS.000000001", "http://irail.be/stations/NMBS/000000001","Brussels", getTranslationMap("Brussel", "fr", "de", "en"), "Brussel", "BE", 1, 2, 3); } ); diff --git a/OpenTransport_be_experimental/build.gradle b/OpenTransport_be_experimental/build.gradle index fb31b78c..ae8bf53d 100644 --- a/OpenTransport_be_experimental/build.gradle +++ b/OpenTransport_be_experimental/build.gradle @@ -11,7 +11,7 @@ android { targetSdkVersion 28 versionCode VERSION_CODE versionName VERSION_NAME - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled true } @@ -65,7 +65,7 @@ dependencies { testImplementation "org.mockito:mockito-core:2.18.3" testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + androidTestImplementation 'androidx.test:runner:1.1.0-alpha4' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4' androidTestImplementation "org.mockito:mockito-core:2.18.3" } diff --git a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/lc2Irail/Lc2IrailDataSource.java b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/lc2Irail/Lc2IrailDataSource.java index c49f27a2..ddcf68cd 100644 --- a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/lc2Irail/Lc2IrailDataSource.java +++ b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/lc2Irail/Lc2IrailDataSource.java @@ -9,7 +9,6 @@ import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; -import android.support.annotation.NonNull; import com.android.volley.DefaultRetryPolicy; import com.android.volley.NoConnectionError; @@ -37,6 +36,8 @@ import java.util.List; import java.util.Map; +import androidx.annotation.NonNull; +import be.hyperrail.opentransportdata.be.experimental.BuildConfig; import be.hyperrail.opentransportdata.be.irail.IrailApi; import be.hyperrail.opentransportdata.be.irail.IrailLiveboardExtendHelper; import be.hyperrail.opentransportdata.be.irail.IrailRouteExtendHelper; @@ -63,7 +64,6 @@ import be.hyperrail.opentransportdata.common.requests.VehicleRequest; import be.hyperrail.opentransportdata.common.requests.VehicleStopRequest; import be.hyperrail.opentransportdata.logging.OpenTransportLog; -import be.hyperrail.opentransportdata.be.experimental.BuildConfig; /** * Created in be.hyperrail.android.irail.implementation on 13/04/2018. @@ -71,7 +71,8 @@ public class Lc2IrailDataSource implements TransportDataSource, MeteredDataSource { private static final OpenTransportLog log = OpenTransportLog.getLogger(Lc2IrailDataSource.class); - private static final String UA = "OpenTransport for Android - " + BuildConfig.VERSION_NAME; + + private static final String UA = "OpenTransport-be-experimental for Android - " + BuildConfig.VERSION_NAME; private final Context mContext; private final Lc2IrailParser parser; diff --git a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/lc2Irail/Lc2IrailParser.java b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/lc2Irail/Lc2IrailParser.java index 6c309dda..e588fe81 100644 --- a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/lc2Irail/Lc2IrailParser.java +++ b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/lc2Irail/Lc2IrailParser.java @@ -30,7 +30,7 @@ package be.hyperrail.opentransportdata.be.experimental.lc2Irail; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import org.joda.time.DateTime; import org.joda.time.Duration; diff --git a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LinkedConnection.java b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LinkedConnection.java index afe682a8..ca97e543 100644 --- a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LinkedConnection.java +++ b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LinkedConnection.java @@ -18,96 +18,77 @@ class LinkedConnection { @JsonField(name = "@id") - private String semanticId; + String semanticId; @JsonField(name = "departureStop") - private String departureStationUri; + String departureStationUri; @JsonField(name = "arrivalStop") - private String arrivalStationUri; + String arrivalStationUri; @JsonField(name = "departureTime", typeConverter = DateTimeConverter.class) - private DateTime departureTime; + DateTime departureTime; @JsonField(name = "arrivalTime", typeConverter = DateTimeConverter.class) private DateTime arrivalTime; @JsonField(name = "departureDelay") - private int departureDelay = 0; + int departureDelay = 0; @JsonField(name = "arrivalDelay") - private int arrivalDelay = 0; + int arrivalDelay = 0; @JsonField(name = "direction") - private String direction; + protected String direction; @JsonField(name = "gtfs:route") - private String route; + protected String route; @JsonField(name = "gtfs:trip") private String trip; @JsonField(name = "gtfs:pickupType") - private String pickupType; + String pickupType; @JsonField(name = "gtfs:dropOffType") - private String dropoffType; + String dropoffType; - int getArrivalDelay() { - return arrivalDelay; - } - - String getArrivalStationUri() { - return arrivalStationUri; - } - - public void setArrivalStationUri(String arrivalStationUri) { - this.arrivalStationUri = arrivalStationUri; - } - DateTime getArrivalTime() { - return arrivalTime; - } - - void setArrivalTime(DateTime arrivalTime) { - this.arrivalTime = arrivalTime; + DateTime getDelayedDepartureTime() { + return getDepartureTime().plusSeconds(getDepartureDelay()); } DateTime getDelayedArrivalTime() { return getArrivalTime().plusSeconds(getArrivalDelay()); } - DateTime getDelayedDepartureTime() { - return getDepartureTime().plusSeconds(getDepartureDelay()); - } - - int getDepartureDelay() { - return departureDelay; + public String getSemanticId() { + return semanticId; } String getDepartureStationUri() { return departureStationUri; } - public void setDepartureStationUri(String departureStationUri) { - this.departureStationUri = departureStationUri; + String getArrivalStationUri() { + return arrivalStationUri; } public DateTime getDepartureTime() { return departureTime; } - String getDirection() { - return direction; + public DateTime getArrivalTime() { + return arrivalTime; } - public void setDirection(String direction) { - this.direction = direction; + void setArrivalTime(DateTime arrivalTime) { + this.arrivalTime = arrivalTime; } - String getRoute() { - return route; + public int getDepartureDelay() { + return departureDelay; } - public void setRoute(String route) { - this.route = route; + public int getArrivalDelay() { + return arrivalDelay; } - String getSemanticId() { - return semanticId; + public String getDirection() { + return direction; } - public void setSemanticId(String semanticId) { - this.semanticId = semanticId; + public String getRoute() { + return route; } String getTrip() { @@ -121,13 +102,5 @@ void setTrip(String trip) { boolean isNormal() { return pickupType != null && dropoffType != null && pickupType.equals("gtfs:Regular") && dropoffType.equals("gtfs:Regular"); } - - public void setDropoffType(String dropoffType) { - this.dropoffType = dropoffType; - } - - public void setPickupType(String pickupType) { - this.pickupType = pickupType; - } } diff --git a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LinkedConnectionsDataSource.java b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LinkedConnectionsDataSource.java index e7b7e26f..a68e9d04 100644 --- a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LinkedConnectionsDataSource.java +++ b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LinkedConnectionsDataSource.java @@ -4,7 +4,7 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.AsyncTask; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import android.util.Log; import org.joda.time.DateTime; diff --git a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LinkedConnectionsProvider.java b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LinkedConnectionsProvider.java index 5de866ff..d664e8e8 100644 --- a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LinkedConnectionsProvider.java +++ b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LinkedConnectionsProvider.java @@ -9,7 +9,6 @@ import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; -import android.support.annotation.NonNull; import android.util.Log; import com.android.volley.DefaultRetryPolicy; @@ -37,10 +36,11 @@ import java.util.HashMap; import java.util.Map; +import androidx.annotation.NonNull; +import be.hyperrail.opentransportdata.be.experimental.BuildConfig; import be.hyperrail.opentransportdata.common.contracts.MeteredDataSource; import be.hyperrail.opentransportdata.common.contracts.TransportDataErrorResponseListener; import be.hyperrail.opentransportdata.common.contracts.TransportDataSuccessResponseListener; -import be.opentransport.BuildConfig; /** * Created in be.hyperrail.android.irail.implementation.linkedconnections on 15/03/2018. @@ -60,7 +60,7 @@ public class LinkedConnectionsProvider { private boolean mCacheEnabled = true; - private static final String UA = "OpenTransport for Android - " + BuildConfig.VERSION_NAME; + private static final String UA = "OpenTransport-be-experimental for Android - " + BuildConfig.VERSION_NAME; private boolean isInternetAvailable() { NetworkInfo activeNetwork = mConnectivityManager.getActiveNetworkInfo(); diff --git a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LiveboardExtendHelper.java b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LiveboardExtendHelper.java index 30031cca..52234a0e 100644 --- a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LiveboardExtendHelper.java +++ b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LiveboardExtendHelper.java @@ -6,7 +6,7 @@ package be.hyperrail.opentransportdata.be.experimental.linkedconnections; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import be.hyperrail.opentransportdata.common.contracts.MeteredDataSource; import be.hyperrail.opentransportdata.common.contracts.NextDataPointer; diff --git a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LiveboardResponseListener.java b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LiveboardResponseListener.java index bef3f3e5..4d0f38cb 100644 --- a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LiveboardResponseListener.java +++ b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/LiveboardResponseListener.java @@ -6,7 +6,7 @@ package be.hyperrail.opentransportdata.be.experimental.linkedconnections; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import android.util.Log; import com.google.firebase.perf.metrics.AddTrace; diff --git a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/QueryResponseListener.java b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/QueryResponseListener.java index a310a4fc..3769bfa0 100644 --- a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/QueryResponseListener.java +++ b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/QueryResponseListener.java @@ -6,7 +6,7 @@ package be.hyperrail.opentransportdata.be.experimental.linkedconnections; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import be.hyperrail.opentransportdata.common.contracts.TransportDataErrorResponseListener; import be.hyperrail.opentransportdata.common.contracts.TransportDataSuccessResponseListener; diff --git a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/RouteExtendHelper.java b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/RouteExtendHelper.java index 13731f99..d580dd4c 100644 --- a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/RouteExtendHelper.java +++ b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/RouteExtendHelper.java @@ -6,7 +6,7 @@ package be.hyperrail.opentransportdata.be.experimental.linkedconnections; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import org.joda.time.DateTime; diff --git a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/RouteResponseListener.java b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/RouteResponseListener.java index 8776b2ab..8adf5372 100644 --- a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/RouteResponseListener.java +++ b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/RouteResponseListener.java @@ -6,8 +6,8 @@ package be.hyperrail.opentransportdata.be.experimental.linkedconnections; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import android.util.Log; import com.google.firebase.perf.metrics.AddTrace; diff --git a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/TimespanQueryResponseListener.java b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/TimespanQueryResponseListener.java index d540c3b7..e27617bd 100644 --- a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/TimespanQueryResponseListener.java +++ b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/TimespanQueryResponseListener.java @@ -6,7 +6,7 @@ package be.hyperrail.opentransportdata.be.experimental.linkedconnections; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import org.joda.time.DateTime; diff --git a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/UrlSpanQueryResponseListener.java b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/UrlSpanQueryResponseListener.java index 27a4d3f4..340c8026 100644 --- a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/UrlSpanQueryResponseListener.java +++ b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/UrlSpanQueryResponseListener.java @@ -6,7 +6,7 @@ package be.hyperrail.opentransportdata.be.experimental.linkedconnections; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import java.util.ArrayList; import java.util.Collections; diff --git a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/VehicleResponseListener.java b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/VehicleResponseListener.java index 5fb6c80d..2bfc3f58 100644 --- a/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/VehicleResponseListener.java +++ b/OpenTransport_be_experimental/src/main/java/be/hyperrail/opentransportdata/be/experimental/linkedconnections/VehicleResponseListener.java @@ -6,7 +6,7 @@ package be.hyperrail.opentransportdata.be.experimental.linkedconnections; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import android.util.Log; import com.google.firebase.perf.metrics.AddTrace; diff --git a/build.gradle b/build.gradle index d7f824a3..6a001ed9 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { } } dependencies { - classpath 'com.android.tools.build:gradle:3.3.2' + classpath 'com.android.tools.build:gradle:3.4.1' classpath 'com.google.gms:google-services:4.2.0' classpath ('com.google.firebase:firebase-plugins:1.1.0'){ exclude group: 'com.google.guava', module: 'guava-jdk5' @@ -30,6 +30,7 @@ allprojects { maven { url 'https://maven.fabric.io/public' } + google() } } diff --git a/gradle.properties b/gradle.properties index f1c49f39..1e0c1d3b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,6 +9,8 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. +android.enableJetifier=true +android.useAndroidX=true org.gradle.jvmargs=-Xmx1536m # When configured, Gradle will run in incubating parallel mode. diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 94564e00..cccb13d6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Mar 19 21:35:23 CET 2019 +#Wed May 29 00:16:05 CEST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip diff --git a/opentransport_be/build.gradle b/opentransport_be/build.gradle index 5b19cbc9..4478a7c3 100644 --- a/opentransport_be/build.gradle +++ b/opentransport_be/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'com.android.library' -def VERSION_CODE = 1 -def VERSION_NAME = '1.0.0' +def VERSION_CODE = 2 +def VERSION_NAME = '1.0.1' android { compileSdkVersion 28 @@ -11,7 +11,7 @@ android { targetSdkVersion 28 versionCode VERSION_CODE versionName VERSION_NAME - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled true } @@ -43,8 +43,8 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.google.firebase:firebase-perf:16.2.5' - implementation 'com.google.firebase:firebase-core:16.0.8' + implementation 'com.google.firebase:firebase-perf:18.0.1' + implementation 'com.google.firebase:firebase-core:17.0.1' // Advanced DateTime library implementation 'joda-time:joda-time:2.9.9' @@ -56,7 +56,7 @@ dependencies { testImplementation "org.mockito:mockito-core:2.18.3" testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02' androidTestImplementation "org.mockito:mockito-core:2.18.3" } diff --git a/opentransport_be/src/androidTest/java/be/hyperrail/opentransportdata/be/irail/IrailParserInstrumentedTest.java b/opentransport_be/src/androidTest/java/be/hyperrail/opentransportdata/be/irail/IrailParserInstrumentedTest.java index 2562df34..873e3f91 100644 --- a/opentransport_be/src/androidTest/java/be/hyperrail/opentransportdata/be/irail/IrailParserInstrumentedTest.java +++ b/opentransport_be/src/androidTest/java/be/hyperrail/opentransportdata/be/irail/IrailParserInstrumentedTest.java @@ -12,8 +12,8 @@ package be.hyperrail.opentransportdata.be.irail; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.InstrumentationRegistry; +import androidx.test.runner.AndroidJUnit4; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; diff --git a/opentransport_be/src/androidTest/java/be/hyperrail/opentransportdata/be/irail/StationsDbInstrumentedTest.java b/opentransport_be/src/androidTest/java/be/hyperrail/opentransportdata/be/irail/StationsDbInstrumentedTest.java index 93fb8f3f..3beb171e 100644 --- a/opentransport_be/src/androidTest/java/be/hyperrail/opentransportdata/be/irail/StationsDbInstrumentedTest.java +++ b/opentransport_be/src/androidTest/java/be/hyperrail/opentransportdata/be/irail/StationsDbInstrumentedTest.java @@ -12,8 +12,8 @@ package be.hyperrail.opentransportdata.be.irail; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; +import androidx.test.InstrumentationRegistry; +import androidx.test.runner.AndroidJUnit4; import org.junit.Assert; import org.junit.Test; diff --git a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailApi.java b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailApi.java index 2d3b0e67..69e746b9 100644 --- a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailApi.java +++ b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailApi.java @@ -430,9 +430,11 @@ public Map getHeaders() { * @param errorListener The listener for unsuccessful responses */ private void tryOnlineOrServerCache(JsonObjectRequest jsObjRequest, Response.Listener successListener, Response.ErrorListener errorListener) { + log.debug("Making request to iRail API at " + jsObjRequest.getUrl()); if (isInternetAvailable()) { requestQueue.add(jsObjRequest); } else { + log.debug("Offline, using cache for " + jsObjRequest.getUrl()); if (requestQueue.getCache().get(jsObjRequest.getCacheKey()) != null) { try { JSONObject cache = new JSONObject(new String(requestQueue.getCache().get(jsObjRequest.getCacheKey()).data)); @@ -443,6 +445,7 @@ private void tryOnlineOrServerCache(JsonObjectRequest jsObjRequest, Response.Lis } } else { + log.debug("No cache for " + jsObjRequest.getUrl()); errorListener.onErrorResponse(new NoConnectionError()); } } diff --git a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailApiParser.java b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailApiParser.java index 1fca0069..947592d9 100644 --- a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailApiParser.java +++ b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailApiParser.java @@ -30,8 +30,8 @@ package be.hyperrail.opentransportdata.be.irail; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; diff --git a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailFacilitiesDataProvider.java b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailFacilitiesDataProvider.java index 2dfafe1f..df763313 100644 --- a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailFacilitiesDataProvider.java +++ b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailFacilitiesDataProvider.java @@ -9,6 +9,7 @@ import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; import org.joda.time.LocalTime; import org.joda.time.format.DateTimeFormat; @@ -19,7 +20,6 @@ import be.hyperrail.opentransportdata.common.models.StopLocation; import be.hyperrail.opentransportdata.common.models.StopLocationFacilities; import be.hyperrail.opentransportdata.common.models.implementation.StopLocationFacilitiesImpl; -import be.hyperrail.opentransportdata.common.webdb.WebDb; import be.hyperrail.opentransportdata.logging.OpenTransportLog; /** @@ -30,15 +30,15 @@ public class IrailFacilitiesDataProvider implements TransportStopFacilitiesDataS private final static OpenTransportLog log = OpenTransportLog.getLogger(IrailFacilitiesDataProvider.class); private final Context context; - private WebDb mWebDb; + private SQLiteOpenHelper mWebDb; public IrailFacilitiesDataProvider(Context appContext) { this.context = appContext; - this.mWebDb = WebDb.getInstance(context, IrailFacilitiesWebDbDataDefinition.getInstance(context)); + this.mWebDb = new IrailFacilitiesDatabase(appContext); } @Override - public StopLocationFacilities getStationFacilitiesByUri(String id) { + public StopLocationFacilities getStationFacilitiesByUri(String uri) { SQLiteDatabase db = mWebDb.getReadableDatabase(); Cursor c = db.query( StationFacilityColumns.TABLE_NAME, @@ -80,7 +80,7 @@ public StopLocationFacilities getStationFacilitiesByUri(String id) { StationFacilityColumns.COLUMN_SALES_CLOSE_SUNDAY, }, StationFacilityColumns._ID + "=?", - new String[]{id}, + new String[]{uri}, null, null, null, diff --git a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailFacilitiesWebDbDataDefinition.java b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailFacilitiesDatabase.java similarity index 53% rename from opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailFacilitiesWebDbDataDefinition.java rename to opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailFacilitiesDatabase.java index b412629b..76e33deb 100644 --- a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailFacilitiesWebDbDataDefinition.java +++ b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailFacilitiesDatabase.java @@ -1,13 +1,7 @@ /* - * 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/. - */ - -/* - * 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/. + * 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.opentransportdata.be.irail; @@ -16,23 +10,15 @@ import android.content.Context; import android.content.res.Resources; import android.database.sqlite.SQLiteDatabase; -import android.support.annotation.NonNull; -import android.support.annotation.RawRes; +import android.database.sqlite.SQLiteOpenHelper; -import org.joda.time.DateTime; +import androidx.annotation.RawRes; -import java.io.BufferedReader; -import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; import java.util.NoSuchElementException; import java.util.Scanner; import be.hyperrail.opentransportdata.be.R; -import be.hyperrail.opentransportdata.common.webdb.WebDbDataDefinition; import be.hyperrail.opentransportdata.logging.OpenTransportLog; import static be.hyperrail.opentransportdata.be.irail.IrailStationFacilitiesDataContract.SQL_CREATE_INDEX_FACILITIES_ID; @@ -40,41 +26,28 @@ import static be.hyperrail.opentransportdata.be.irail.IrailStationFacilitiesDataContract.SQL_DELETE_TABLE_FACILITIES; import static be.hyperrail.opentransportdata.be.irail.IrailStationFacilitiesDataContract.StationFacilityColumns; -/** - * 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 https://mozilla.org/MPL/2.0/. - * (c) Bert Marcelis 2018 - */ -class IrailFacilitiesWebDbDataDefinition implements WebDbDataDefinition { - private final static OpenTransportLog log = OpenTransportLog.getLogger(IrailFacilitiesWebDbDataDefinition.class); - private static IrailFacilitiesWebDbDataDefinition instance; +class IrailFacilitiesDatabase extends SQLiteOpenHelper { + private static final OpenTransportLog log = OpenTransportLog.getLogger(IrailFacilitiesDatabase.class); + private static IrailFacilitiesDatabase instance; private final Resources mResources; - private IrailFacilitiesWebDbDataDefinition(Context context) { - mResources = context.getResources(); + IrailFacilitiesDatabase(Context context) { + super(context, "irail-facilities.db", null, 2019060900); + this.mResources = context.getResources(); } - public static IrailFacilitiesWebDbDataDefinition getInstance(Context context) { + public static IrailFacilitiesDatabase getInstance(Context context) { if (instance == null) { - instance = new IrailFacilitiesWebDbDataDefinition(context); + instance = new IrailFacilitiesDatabase(context); } return instance; } - @Override - public boolean updateOnlyOnWifi() { - return true; - } - - @Override @RawRes - public int getEmbeddedDataResourceId() { + private int getEmbeddedDataResourceId() { return R.raw.stationfacilities; } - @Override - public String getOnlineDataURL() { - return "https://raw.githubusercontent.com/iRail/stations/master/facilities.csv"; - } @Override public String getDatabaseName() { @@ -82,44 +55,19 @@ public String getDatabaseName() { } @Override - public DateTime getLastModifiedLocalDate() { - return new DateTime(2019, 4, 1, 0, 0); - - } - - @NonNull - private DateTime getSaturdayBeforeToday() { - DateTime now = DateTime.now(); - // On a saturday (6) this will be now (+0), on sunday it will be saturday (+1), on monday it will be +2, ... - // This way we update every saturday - return now.minusDays(now.dayOfWeek().get() + 1 % 7); + public void onCreate(SQLiteDatabase db) { + createDatabaseStructure(db); + loadLocalData(db); } @Override - public DateTime getLastModifiedOnlineDate() { - // Github doesn't send a proper last modified header. Instead we use the last saturday (can be today) - return getSaturdayBeforeToday(); - - /* - URL url; - try { - url = new URL(getOnlineDataURL()); - } catch (MalformedURLException e) { - return new DateTime(0); - } - HttpURLConnection httpCon; - try { - httpCon = (HttpURLConnection) url.openConnection(); - } catch (IOException e) { - return new DateTime(0); - } - - return new DateTime(httpCon.getLastModified()); - */ + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + deleteDatabase(db); + createDatabaseStructure(db); + loadLocalData(db); } - @Override - public boolean loadLocalData(SQLiteDatabase db) { + private void loadLocalData(SQLiteDatabase db) { db.beginTransaction(); try (Scanner lines = new Scanner(getLocalData())) { importFacilities(db, lines); @@ -128,59 +76,10 @@ public boolean loadLocalData(SQLiteDatabase db) { } catch (Exception e) { log.severe("Failed to fill facilities db with offline data!", e); db.endTransaction(); - return false; } - return true; } - @Override - public boolean importDownloadedData(SQLiteDatabase db, Object onlineUpdateData) { - db.beginTransaction(); - try (Scanner lines = new Scanner((String) onlineUpdateData)) { - importFacilities(db, lines); - db.setTransactionSuccessful(); - db.endTransaction(); - log.info("Filled station facilities database with online data"); - return true; - } catch (Exception e) { - log.severe("Failed to fill facilities db with online data!", e); - db.endTransaction(); - return false; - } - } - - @Override - public String downloadOnlineData() { - URL url; - try { - url = new URL(getOnlineDataURL()); - } catch (MalformedURLException e) { - log.warning("Failed to get data URL for database " + getDatabaseName()); - return null; - } - HttpURLConnection httpCon; - try { - httpCon = (HttpURLConnection) url.openConnection(); - return dataStreamToString(httpCon.getInputStream()); - } catch (IOException e) { - log.warning("Failed to get online for database " + getDatabaseName() + " from " + url.toString()); - return null; - } - } - - private String dataStreamToString(InputStream stream) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); - StringBuilder stringBuilder = new StringBuilder(); - - String line; - while ((line = reader.readLine()) != null) { - stringBuilder.append(line).append("\n"); - } - return stringBuilder.toString(); - } - - @Override - public void clearDatabase(SQLiteDatabase db) { + private void deleteDatabase(SQLiteDatabase db) { db.execSQL(SQL_DELETE_TABLE_FACILITIES); } @@ -188,8 +87,7 @@ private InputStream getLocalData() { return mResources.openRawResource(getEmbeddedDataResourceId()); } - @Override - public void createDatabaseStructure(SQLiteDatabase db) { + private void createDatabaseStructure(SQLiteDatabase db) { db.execSQL(SQL_CREATE_TABLE_FACILITIES); db.execSQL(SQL_CREATE_INDEX_FACILITIES_ID); } @@ -207,15 +105,9 @@ private void importFacilities(SQLiteDatabase db, Scanner lines) { String id = fields.next(); - // By default, the CSV contains ids in iRail URI format, - // reformat them to 9 digit HAFAS ids - if (id.startsWith("http")) { - id = id.replace("http://irail.be/stations/NMBS/", ""); - } - - // Store ID as 9 digit IDs + // Store ID as URIs values.put(StationFacilityColumns._ID, id); - // Skip name + // Skip name, already in stations.csv fields.next(); values.put(StationFacilityColumns.COLUMN_STREET, fields.next()); values.put(StationFacilityColumns.COLUMN_ZIP, fields.next()); @@ -272,7 +164,7 @@ private void getOpeningHourValues(Scanner fields, ContentValues values, String c } field = fields.next(); if (field != null && !field.isEmpty()) { - values.put(columnSalesClose, field); + values.put(columnSalesClose, field.trim()); } } } diff --git a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailStationsDataContract.java b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailStationsDataContract.java index 113dd160..cc832929 100644 --- a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailStationsDataContract.java +++ b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailStationsDataContract.java @@ -25,11 +25,8 @@ */ class IrailStationsDataContract { - static final String SQL_CREATE_INDEX_NAME = " CREATE INDEX stations_station_name ON " + StationsDataColumns.TABLE_NAME + " (" + StationsDataColumns.COLUMN_NAME_NAME + ");"; static final String SQL_CREATE_INDEX_ID = " CREATE INDEX stations_station_id ON " + StationsDataColumns.TABLE_NAME + " (" + StationsDataColumns._ID + ");"; - static final String SQL_DELETE_TABLE_STATIONS = - "DROP TABLE IF EXISTS " + StationsDataColumns.TABLE_NAME + ";"; - + static final String SQL_CREATE_INDEX_NAME = " CREATE INDEX stations_station_name ON " + StationsDataColumns.TABLE_NAME + " (" + StationsDataColumns.COLUMN_NAME_NAME + ");"; /** * Create table + index for lookup by name. No index for sort since little performance gains. */ @@ -48,24 +45,26 @@ class IrailStationsDataContract { StationsDataColumns.COLUMN_NAME_AVG_STOP_TIMES + " REAL," + StationsDataColumns.COLUMN_NAME_OFFICIAL_TRANSFER_TIME + " REAL);"; + static final String SQL_DELETE_TABLE_STATIONS = "DROP TABLE IF EXISTS " + StationsDataColumns.TABLE_NAME + ";"; + + private IrailStationsDataContract() { + // don't instantiate + } + public static final class StationsDataColumns implements BaseColumns { - protected static final String TABLE_NAME = "stations"; - protected static final String _ID = "station_id"; - protected static final String COLUMN_NAME_NAME = "name"; - protected static final String COLUMN_NAME_ALTERNATIVE_NL = "alternative_nl"; - protected static final String COLUMN_NAME_ALTERNATIVE_FR = "alternative_fr"; protected static final String COLUMN_NAME_ALTERNATIVE_DE = "alternative_de"; protected static final String COLUMN_NAME_ALTERNATIVE_EN = "alternative_en"; + protected static final String COLUMN_NAME_ALTERNATIVE_FR = "alternative_fr"; + protected static final String COLUMN_NAME_ALTERNATIVE_NL = "alternative_nl"; + protected static final String COLUMN_NAME_AVG_STOP_TIMES = "avg_stop_times"; protected static final String COLUMN_NAME_COUNTRY_CODE = "country_code"; - protected static final String COLUMN_NAME_LONGITUDE = "longitude"; protected static final String COLUMN_NAME_LATITUDE = "latitude"; - protected static final String COLUMN_NAME_AVG_STOP_TIMES = "avg_stop_times"; + protected static final String COLUMN_NAME_LONGITUDE = "longitude"; + protected static final String COLUMN_NAME_NAME = "name"; protected static final String COLUMN_NAME_OFFICIAL_TRANSFER_TIME = "official_transfer_time"; - } - - private IrailStationsDataContract() { - // don't instantiate + protected static final String TABLE_NAME = "stations"; + protected static final String _ID = "station_id"; } diff --git a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailStationsDataProvider.java b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailStationsDataProvider.java index 5c1b9e22..eae93ad6 100644 --- a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailStationsDataProvider.java +++ b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailStationsDataProvider.java @@ -9,10 +9,12 @@ import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; import android.location.Location; import android.preference.PreferenceManager; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.google.firebase.perf.metrics.AddTrace; @@ -25,7 +27,6 @@ import be.hyperrail.opentransportdata.common.exceptions.StopLocationNotResolvedException; import be.hyperrail.opentransportdata.common.models.StopLocation; import be.hyperrail.opentransportdata.common.models.implementation.StopLocationImpl; -import be.hyperrail.opentransportdata.common.webdb.WebDb; import be.hyperrail.opentransportdata.logging.OpenTransportLog; import be.hyperrail.opentransportdata.util.StringUtils; @@ -46,14 +47,14 @@ public class IrailStationsDataProvider implements TransportStopsDataSource { private final Context context; private final Object getStoplocationsOrderedBySizeLock = new Object(); // The underlying webDb instance, ensuring that the local SQLite database stays up-to-date with the online data - private WebDb mWebDb; + private SQLiteOpenHelper mDbInstance; private HashMap mStationIdCache = new HashMap<>(); private HashMap mStationNameCache = new HashMap<>(); private StopLocation[] stationsOrderedBySizeCache; public IrailStationsDataProvider(Context appContext) { this.context = appContext; - this.mWebDb = WebDb.getInstance(appContext, IrailStopsWebDbDataDefinition.getInstance(context)); + this.mDbInstance = new IrailStopsDatabase(appContext); } private String[] getLocationQueryColumns(double longitude, double latitude) { @@ -100,7 +101,7 @@ public StopLocation[] getStoplocationsOrderedBySize() { return stationsOrderedBySizeCache; } - SQLiteDatabase db = mWebDb.getReadableDatabase(); + SQLiteDatabase db = mDbInstance.getReadableDatabase(); Cursor c = db.query( StationsDataColumns.TABLE_NAME, getDefaultQueryColumns(), @@ -137,7 +138,7 @@ public StopLocation[] getStoplocationsOrderedByLocation(Location location) { @AddTrace(name = "StationsDb.getStoplocationsOrderedByLocationAndSize") @NonNull public StopLocation[] getStoplocationsOrderedByLocationAndSize(Location location, int limit) { - SQLiteDatabase db = mWebDb.getReadableDatabase(); + SQLiteDatabase db = mDbInstance.getReadableDatabase(); double longitude = Math.round(location.getLongitude() * 1000000.0) / 1000000.0; double latitude = Math.round(location.getLatitude() * 1000000.0) / 1000000.0; @@ -163,7 +164,7 @@ public StopLocation[] getStoplocationsOrderedByLocationAndSize(Location location @Override public void preloadDatabase() { // Getting a readable database ensures onCreate and onUpgrade are called as needed - mWebDb.getReadableDatabase(); + mDbInstance.getReadableDatabase(); } /** @@ -193,15 +194,24 @@ public StopLocation getStoplocationByHafasId(String id) throws StopLocationNotRe } if (id.startsWith("BE.NMBS.")) { + // TODO: remove in the future when it is 100% sure this is no longer used id = id.substring(8); + log.info("Incorrect call to getStopLocationByHafasId"); + log.info(Arrays.toString(Thread.currentThread().getStackTrace())); } - SQLiteDatabase db = mWebDb.getReadableDatabase(); + return getStoplocationBySemanticId("http://irail.be/stations/NMBS/" + id); + } + + @Nullable + @Override + public StopLocation getStoplocationBySemanticId(String uri) throws StopLocationNotResolvedException { + SQLiteDatabase db = mDbInstance.getReadableDatabase(); Cursor c = db.query( StationsDataColumns.TABLE_NAME, getDefaultQueryColumns(), StationsDataColumns._ID + "=?", - new String[]{id}, + new String[]{uri}, null, null, null, @@ -213,27 +223,13 @@ public StopLocation getStoplocationByHafasId(String id) throws StopLocationNotRe c.close(); if (results.length == 0) { - log.logException(new IllegalStateException("ID Not found in station database! " + id)); - throw new StopLocationNotResolvedException(id); + log.logException(new IllegalStateException("URI not found in station database! " + uri)); + throw new StopLocationNotResolvedException(uri); } - mStationIdCache.put(id, results[0]); + mStationIdCache.put(uri, results[0]); return results[0]; } - @Nullable - @Override - public StopLocation getStoplocationBySemanticId(String id) throws StopLocationNotResolvedException { - if (id.startsWith("BE.NMBS.")) { - // Handle old iRail ids - id = id.substring(8); - } - if (id.contains("/")) { - // Handle URIs - id = id.substring(id.lastIndexOf('/') + 1); - } - return getStoplocationByHafasId(id); - } - /** * @inheritDoc */ @@ -266,7 +262,7 @@ public StopLocation[] getStoplocationsByNameOrderBySize(@NonNull String name) { @NonNull private StopLocation[] getStationsByNameOrderBySize(@NonNull String name, boolean exact) { - SQLiteDatabase db = mWebDb.getReadableDatabase(); + SQLiteDatabase db = mDbInstance.getReadableDatabase(); name = StringUtils.cleanAccents(name); name = name.replaceAll("\\(\\w\\)", ""); @@ -319,7 +315,7 @@ private StopLocation[] getStationsByNameOrderBySize(@NonNull String name, boolea @Override @AddTrace(name = "StationsDb.getStoplocationsByNameOrderByLocation") public StopLocation[] getStoplocationsByNameOrderByLocation(String name, Location location) { - SQLiteDatabase db = mWebDb.getReadableDatabase(); + SQLiteDatabase db = mDbInstance.getReadableDatabase(); double longitude = Math.round(location.getLongitude() * 1000000.0) / 1000000.0; double latitude = Math.round(location.getLatitude() * 1000000.0) / 1000000.0; @@ -409,8 +405,15 @@ private StopLocation[] loadStationCursor(@NonNull Cursor c) { localizedName = name; } + String uri = c.getString(c.getColumnIndex(StationsDataColumns._ID)); + + // Handle URIs + String id = uri.substring(uri.lastIndexOf('/') + 1); + + StopLocation s = new StopLocationImpl( - c.getString(c.getColumnIndex(StationsDataColumns._ID)), + id, + uri, name, localizedNames, localizedName, diff --git a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailStopsWebDbDataDefinition.java b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailStopsDatabase.java similarity index 56% rename from opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailStopsWebDbDataDefinition.java rename to opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailStopsDatabase.java index 1f5e109a..c5ec3bd9 100644 --- a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailStopsWebDbDataDefinition.java +++ b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailStopsDatabase.java @@ -10,22 +10,14 @@ import android.content.Context; import android.content.res.Resources; import android.database.sqlite.SQLiteDatabase; -import android.support.annotation.NonNull; -import android.support.annotation.RawRes; +import android.database.sqlite.SQLiteOpenHelper; -import org.joda.time.DateTime; +import androidx.annotation.RawRes; -import java.io.BufferedReader; -import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; import java.util.Scanner; import be.hyperrail.opentransportdata.be.R; -import be.hyperrail.opentransportdata.common.webdb.WebDbDataDefinition; import be.hyperrail.opentransportdata.logging.OpenTransportLog; import be.hyperrail.opentransportdata.util.StringUtils; @@ -39,63 +31,53 @@ * 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 https://mozilla.org/MPL/2.0/. * (c) Bert Marcelis 2018 */ -class IrailStopsWebDbDataDefinition implements WebDbDataDefinition { - private static final OpenTransportLog log = OpenTransportLog.getLogger(IrailStopsWebDbDataDefinition.class); - private static IrailStopsWebDbDataDefinition instance; +class IrailStopsDatabase extends SQLiteOpenHelper { + private static final OpenTransportLog log = OpenTransportLog.getLogger(IrailStopsDatabase.class); + private static IrailStopsDatabase instance; private final Resources mResources; - private IrailStopsWebDbDataDefinition(Context context) { - mResources = context.getResources(); + IrailStopsDatabase(Context context) { + super(context, "irail-stations.db", null, 2019060900); + this.mResources = context.getResources(); } - public static IrailStopsWebDbDataDefinition getInstance(Context context) { + public static IrailStopsDatabase getInstance(Context context) { if (instance == null) { - instance = new IrailStopsWebDbDataDefinition(context); + instance = new IrailStopsDatabase(context); } return instance; } - @Override - public boolean updateOnlyOnWifi() { - return true; - } - - @Override @RawRes - public int getEmbeddedDataResourceId() { + private int getEmbeddedDataResourceId() { return R.raw.stations; } - @Override - public String getOnlineDataURL() { - return "https://raw.githubusercontent.com/iRail/stations/master/stations.csv"; - } - @Override public String getDatabaseName() { return "irail-stations.db"; } @Override - public DateTime getLastModifiedLocalDate() { - return new DateTime(2019, 4, 1, 0, 0); + public void onCreate(SQLiteDatabase db) { + createDatabaseStructure(db); + loadLocalData(db); } @Override - public DateTime getLastModifiedOnlineDate() { - // Github doesn't send a proper last modified header. Instead we use the last saturday (can be today) - return getSaturdayBeforeToday(); + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + deleteDatabase(db); + createDatabaseStructure(db); + loadLocalData(db); } - @Override - public void createDatabaseStructure(SQLiteDatabase db) { + private void createDatabaseStructure(SQLiteDatabase db) { db.execSQL(SQL_CREATE_TABLE_STATIONS); db.execSQL(SQL_CREATE_INDEX_ID); db.execSQL(SQL_CREATE_INDEX_NAME); } - @Override - public boolean loadLocalData(SQLiteDatabase db) { + private void loadLocalData(SQLiteDatabase db) { db.beginTransaction(); try (Scanner lines = new Scanner(getLocalData())) { importData(db, lines); @@ -104,70 +86,13 @@ public boolean loadLocalData(SQLiteDatabase db) { } catch (Exception e) { log.severe("Failed to fill stations db with local data!", e); db.endTransaction(); - return false; - } - return true; - } - - @Override - public boolean importDownloadedData(SQLiteDatabase db, Object onlineUpdateData) { - db.beginTransaction(); - try (Scanner lines = new Scanner((String) onlineUpdateData)) { - importData(db, lines); - db.setTransactionSuccessful(); - log.info("Filled stations database with online data"); - return true; - } catch (Exception e) { - db.endTransaction(); - log.severe("Failed to fill stations db with online data!", e); - return false; } } - @Override - public void clearDatabase(SQLiteDatabase db) { + private void deleteDatabase(SQLiteDatabase db) { db.execSQL(SQL_DELETE_TABLE_STATIONS); } - @NonNull - private DateTime getSaturdayBeforeToday() { - DateTime now = DateTime.now(); - // On a saturday (6) this will be now (+0), on sunday it will be saturday (+1), on monday it will be +2, ... - // This way we update every saturday - return now.minusDays(now.dayOfWeek().get() + 1 % 7); - } - - @Override - public String downloadOnlineData() { - URL url; - try { - url = new URL(getOnlineDataURL()); - } catch (MalformedURLException e) { - log.warning("Failed to get data URL for database " + getDatabaseName()); - return null; - } - HttpURLConnection httpCon; - try { - httpCon = (HttpURLConnection) url.openConnection(); - return dataStreamToString(httpCon.getInputStream()); - } catch (IOException e) { - log.warning("Failed to get online for database " + getDatabaseName() + " from " + url.toString()); - return null; - } - } - - private String dataStreamToString(InputStream stream) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); - StringBuilder stringBuilder = new StringBuilder(); - - String line; - while ((line = reader.readLine()) != null) - { - stringBuilder.append(line).append("\n"); - } - return stringBuilder.toString(); - } - private InputStream getLocalData() { return mResources.openRawResource(getEmbeddedDataResourceId()); } @@ -195,13 +120,7 @@ private void importRow(SQLiteDatabase db, Scanner fields) { String id = fields.next(); - // By default, the CSV contains ids in iRail URI format, - // reformat them to 9-digit HAFAS IDs, as HAFAS IDs are an extension upon UIC station codes. - if (id.startsWith("http")) { - id = id.replace("http://irail.be/stations/NMBS/", ""); - } - - // Store ID as XXXXXXXX + // Store ID as URI values.put(StationsDataColumns._ID, id); // Replace special characters (for search purposes) values.put( diff --git a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailVehicleJourney.java b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailVehicleJourney.java index d1b89b77..56a2f678 100644 --- a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailVehicleJourney.java +++ b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailVehicleJourney.java @@ -18,7 +18,7 @@ package be.hyperrail.opentransportdata.be.irail; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import org.joda.time.DateTime; diff --git a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailVehicleJourneyStub.java b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailVehicleJourneyStub.java index 1c97f5e5..411d607e 100644 --- a/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailVehicleJourneyStub.java +++ b/opentransport_be/src/main/java/be/hyperrail/opentransportdata/be/irail/IrailVehicleJourneyStub.java @@ -18,7 +18,7 @@ package be.hyperrail.opentransportdata.be.irail; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; import java.io.Serializable; import java.util.regex.Matcher; @@ -124,25 +124,35 @@ public String getType() { */ private static String getVehicleClass(String id) { - // S trains are special - if (id.startsWith("S")) { - if (id.length() > 5) { - return id.substring(0, id.length() - 4); - } else { - // Logging an exception will make it more visible, allowing possible new formats to be detected more easily. - log.logException(new IllegalArgumentException("Failed to get vehicle class for id " + id)); - } + if (id == null){ + log.logException(new NullPointerException("Tried to get a VehicleClass from an empty id")); + return ""; } - String pattern = "(\\w+?)(\\d+)"; + try { + // S trains are special + if (id.startsWith("S")) { + if (id.length() > 5) { + return id.substring(0, id.length() - 4); + } else { + // Logging an exception will make it more visible, allowing possible new formats to be detected more easily. + log.logException(new IllegalArgumentException("Failed to get vehicle class for id " + id)); + } + } + + String pattern = "(\\w+?)(\\d+)"; - // Create a Pattern object - Pattern r = Pattern.compile(pattern); + // Create a Pattern object + Pattern r = Pattern.compile(pattern); - // Now create matcher object. - Matcher m = r.matcher(id); - if (m.find()) { - return m.group(1); + // Now create matcher object. + Matcher m = r.matcher(id); + if (m.find()) { + return m.group(1); + } + } catch (Exception exception) { + log.severe("Failed to get vehicle number for vehicle " + id); + log.logException(exception); } return ""; } @@ -165,20 +175,30 @@ public String getNumber() { */ private static String getVehicleNumber(String vehicleId) { - // S trains are special - if (vehicleId.startsWith("S")) { - return vehicleId.substring(vehicleId.length() - 4); + if (vehicleId == null){ + log.logException(new NullPointerException("Tried to get a VehicleNumber from an empty id")); + return ""; } - String pattern = "(\\w+?)(\\d+)"; + try { + // S trains are special + if (vehicleId.startsWith("S")) { + return vehicleId.substring(vehicleId.length() - 4); + } + + String pattern = "(\\w+?)(\\d+)"; - // Create a Pattern object - Pattern r = Pattern.compile(pattern); + // Create a Pattern object + Pattern r = Pattern.compile(pattern); - // Now create matcher object. - Matcher m = r.matcher(vehicleId); - if (m.find()) { - return m.group(2); + // Now create matcher object. + Matcher m = r.matcher(vehicleId); + if (m.find()) { + return m.group(2); + } + } catch (Exception exception){ + log.severe("Failed to get vehicle number for vehicle " + vehicleId); + log.logException(exception); } return ""; }