Skip to content

Commit 6c590f0

Browse files
committed
Merge branch 'development'
2 parents 12cbad6 + 57d97f0 commit 6c590f0

32 files changed

+953
-767
lines changed

Hyperrail/build.gradle

+13-13
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ apply plugin: 'com.android.application'
88
apply plugin: 'com.google.gms.google-services'
99
apply plugin: 'com.google.firebase.crashlytics'
1010

11-
def VERSION_CODE = 57
12-
def VERSION_NAME = '1.3.3'
11+
def VERSION_CODE = 58
12+
def VERSION_NAME = '1.3.4'
1313

1414
android {
15-
compileSdk 33
16-
buildToolsVersion '33.0.0'
15+
compileSdk 34
1716
defaultConfig {
1817
applicationId "be.hyperrail.android"
1918
minSdkVersion 21
20-
targetSdkVersion 33
19+
targetSdkVersion 34
2120
versionCode VERSION_CODE
2221
versionName VERSION_NAME
2322
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -42,30 +41,31 @@ android {
4241
lint {
4342
abortOnError false
4443
}
44+
namespace 'be.hyperrail.android'
4545
}
4646

4747
dependencies {
4848
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
49-
implementation 'com.google.android.gms:play-services-maps:18.1.0'
49+
implementation 'com.google.android.gms:play-services-maps:18.2.0'
5050
implementation fileTree(include: ['*.jar'], dir: 'libs')
5151

5252
implementation 'com.android.volley:volley:1.2.1@aar'
5353
implementation 'joda-time:joda-time:2.11.0'
5454
implementation 'com.squareup.picasso:picasso:2.71828'
5555

56-
def lifecycle_version = "2.5.1"
56+
def lifecycle_version = "2.6.2"
5757
// Force the same lifecycle-viewmodel for kotlin and java.
5858
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
5959
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
6060

61-
implementation 'androidx.appcompat:appcompat:1.5.1'
61+
implementation 'androidx.appcompat:appcompat:1.6.1'
6262
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
6363
implementation 'androidx.cardview:cardview:1.0.0'
64-
implementation 'androidx.recyclerview:recyclerview:1.2.1'
65-
implementation 'androidx.preference:preference:1.2.0'
66-
implementation 'com.google.android.material:material:1.6.1'
67-
implementation 'com.google.android.gms:play-services-location:20.0.0'
68-
implementation 'com.google.firebase:firebase-crashlytics:18.2.13'
64+
implementation 'androidx.recyclerview:recyclerview:1.3.2'
65+
implementation 'androidx.preference:preference:1.2.1'
66+
implementation 'com.google.android.material:material:1.10.0'
67+
implementation 'com.google.android.gms:play-services-location:21.0.1'
68+
implementation 'com.google.firebase:firebase-crashlytics:18.6.0'
6969

7070
testImplementation 'junit:junit:4.13.2'
7171
testImplementation 'org.json:json:20220320'

Hyperrail/src/main/AndroidManifest.xml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:tools="http://schemas.android.com/tools"
4-
package="be.hyperrail.android">
3+
xmlns:tools="http://schemas.android.com/tools">
54

65
<uses-permission android:name="android.permission.INTERNET" />
76
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
@@ -31,9 +30,7 @@
3130

3231
<activity
3332
android:name=".activities.MainActivity"
34-
android:exported="true"
35-
android:hardwareAccelerated="true"
36-
android:windowSoftInputMode="stateUnchanged">
33+
android:exported="true">
3734
<intent-filter>
3835
<action android:name="android.intent.action.MAIN" />
3936
<category android:name="android.intent.category.LAUNCHER" />
@@ -76,6 +73,9 @@
7673
<meta-data
7774
android:name="com.google.android.geo.API_KEY"
7875
android:value="@string/google_maps_key" />
76+
<meta-data
77+
android:name="firebase_crashlytics_collection_enabled"
78+
android:value="false" />
7979

8080
<receiver
8181
android:name=".widget.NextDeparturesWidgetProvider"

Hyperrail/src/main/java/be/hyperrail/android/Launcher.java

+15-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212

1313
package be.hyperrail.android;
1414

15+
import android.preference.PreferenceManager;
16+
1517
import com.google.firebase.crashlytics.FirebaseCrashlytics;
1618

1719
import be.hyperrail.android.logging.HyperRailConsoleLogWriter;
1820
import be.hyperrail.android.logging.HyperRailCrashlyticsLogWriter;
1921
import be.hyperrail.android.logging.HyperRailLog;
2022
import be.hyperrail.android.logging.HyperRailLogWriter;
21-
import be.hyperrail.android.util.ReviewDialogProvider;
23+
import be.hyperrail.android.util.CrashlyticsOptInDialog;
24+
import be.hyperrail.android.util.ReviewDialog;
2225
import be.hyperrail.opentransportdata.OpenTransportApi;
2326
import be.hyperrail.opentransportdata.be.IrailDataProvider;
2427

@@ -28,20 +31,25 @@
2831
public class Launcher extends android.app.Application {
2932

3033
public void onCreate() {
31-
3234
// Crashlytics abstraction layer
3335
HyperRailLogWriter logger;
34-
if (BuildConfig.DEBUG) {
36+
boolean enableCrashlytics = BuildConfig.DEBUG
37+
|| PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_crashlytics_enabled", true);
38+
if (enableCrashlytics) {
3539
logger = new HyperRailConsoleLogWriter();
40+
HyperRailLog.initLogWriter(logger);
41+
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true);
42+
HyperRailLog.getLogger(Launcher.class).info("Crashlytics enabled");
3643
} else {
3744
logger = new HyperRailCrashlyticsLogWriter();
45+
HyperRailLog.initLogWriter(logger);
46+
HyperRailLog.getLogger(Launcher.class).info("Crashlytics disabled");
3847
}
39-
HyperRailLog.initLogWriter(logger);
48+
4049
// Setup the factory as soon as the app is created.
4150
OpenTransportApi.init(getApplicationContext(), new IrailDataProvider(), logger);
42-
// Set up Crashlytics, disabled for debug builds
43-
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true);
44-
ReviewDialogProvider.init(this);
51+
ReviewDialog.init(this);
52+
CrashlyticsOptInDialog.init(this);
4553
super.onCreate();
4654
}
4755

Hyperrail/src/main/java/be/hyperrail/android/activities/MainActivity.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
import be.hyperrail.android.fragments.RouteSearchFragment;
6161
import be.hyperrail.android.fragments.VehicleSearchFragment;
6262
import be.hyperrail.android.fragments.searchresult.DisturbanceListFragment;
63-
import be.hyperrail.android.util.ReviewDialogProvider;
63+
import be.hyperrail.android.util.CrashlyticsOptInDialog;
64+
import be.hyperrail.android.util.ReviewDialog;
6465
import be.hyperrail.android.util.ShortcutHelper;
6566

6667
/**
@@ -180,7 +181,9 @@ private void showLaunchDialogsIfNeeded() {
180181
Intent i = new Intent(this, FirstLaunchGuide.class);
181182
startActivity(i);
182183
} else {
183-
ReviewDialogProvider.showDialogIf(this, 7, 3);
184+
// Don't overwhelm the user, keep crashlytics off until the second launch, then ask the user
185+
CrashlyticsOptInDialog.showDialogOnce(this);
186+
ReviewDialog.showDialogIf(this, 7, 3);
184187
}
185188
}
186189

@@ -377,8 +380,8 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
377380

378381
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
379382
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
380-
Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
381-
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
383+
Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
384+
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
382385
}
383386

384387
try {

Hyperrail/src/main/java/be/hyperrail/android/activities/searchresult/LiveboardActivity.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,17 @@ public static Intent createIntent(Context context, LiveboardRequest request) {
5959
i.putExtra("request", request);
6060
return i;
6161
}
62-
63-
private Intent createShortcutIntent() {
64-
Intent i = new Intent(this, LiveboardActivity.class);
62+
public static Intent createShortcutIntent(Context context, String semanticStationId) {
63+
Intent i = new Intent(context, LiveboardActivity.class);
6564
i.putExtra("shortcut", true); // this variable allows to detect launches from shortcuts
66-
i.putExtra("station", mRequest.getStation().getSemanticId()); // shortcut intents should not contain application specific classes - only pass the station ID
65+
i.putExtra("station", semanticStationId); // shortcut intents should not contain application specific classes - only pass the station ID
6766
return i;
6867
}
6968

69+
private Intent createShortcutIntent() {
70+
return createShortcutIntent(this, mRequest.getStation().getSemanticId());
71+
}
72+
7073
@Override
7174
protected void onCreate(Bundle savedInstanceState) {
7275

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
*/
6+
7+
package be.hyperrail.android.util;
8+
9+
import android.app.AlertDialog;
10+
import android.content.Context;
11+
import android.content.SharedPreferences;
12+
import android.preference.PreferenceManager;
13+
14+
import org.joda.time.DateTime;
15+
16+
import be.hyperrail.android.R;
17+
import be.hyperrail.android.logging.HyperRailLog;
18+
19+
public class CrashlyticsOptInDialog {
20+
21+
private static final String PREFERENCES_KEY_OPTIN_REPLIED = "crashreporting_optin_replied";
22+
private static final String PREFERENCES_CRASHLYTICS_ENABLED = "pref_crashlytics_enabled";
23+
24+
private static final HyperRailLog log = HyperRailLog.getLogger(CrashlyticsOptInDialog.class);
25+
private static SharedPreferences sharedPreferences;
26+
private static boolean hasOptedInOrOut;
27+
28+
private CrashlyticsOptInDialog() {
29+
// No public constructor
30+
}
31+
32+
public static void init(Context context) {
33+
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
34+
hasOptedInOrOut = sharedPreferences.getBoolean(PREFERENCES_KEY_OPTIN_REPLIED, false);
35+
}
36+
37+
38+
public static void showDialogOnce(Context context) {
39+
if (!hasOptedInOrOut){
40+
showOptInDialog(context);
41+
}
42+
}
43+
44+
private static void showOptInDialog(final Context context) {
45+
AlertDialog.Builder builder = new AlertDialog.Builder(context);
46+
47+
int titleId = R.string.crashlytics_dialog_title;
48+
int messageId = R.string.crashlytics_dialog_message;
49+
int disableButtonText = R.string.crashlytics_dialog_button_disable;
50+
int enableButtonText = R.string.crashlytics_dialog_button_enable;
51+
builder.setTitle(titleId);
52+
builder.setMessage(messageId);
53+
setDialogButtonActions(builder, enableButtonText, disableButtonText);
54+
builder.show();
55+
}
56+
57+
private static void setDialogButtonActions(AlertDialog.Builder builder, int enableButtonText, int disableButtonText) {
58+
builder.setPositiveButton(enableButtonText, (dialog, which) -> {
59+
optIn();
60+
setOptedInOrOut();
61+
});
62+
builder.setNegativeButton(disableButtonText, (dialog, which) -> {
63+
optOut();
64+
setOptedInOrOut();
65+
});
66+
}
67+
68+
private static void optIn() {
69+
log.info("Storing opt-in from crashlytics");
70+
setPreference(PREFERENCES_CRASHLYTICS_ENABLED, true);
71+
}
72+
private static void optOut() {
73+
log.info("Storing opt-out from crashlytics");
74+
setPreference(PREFERENCES_CRASHLYTICS_ENABLED, false);
75+
}
76+
77+
private static void setOptedInOrOut() {
78+
setPreference(PREFERENCES_KEY_OPTIN_REPLIED, true);
79+
}
80+
81+
private static void setPreference(String preference, boolean value) {
82+
if (sharedPreferences != null) {
83+
sharedPreferences.edit().putBoolean(preference, value).apply();
84+
}
85+
}
86+
87+
}

Hyperrail/src/main/java/be/hyperrail/android/util/ReviewDialogProvider.java Hyperrail/src/main/java/be/hyperrail/android/util/ReviewDialog.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,22 @@
1717
import org.joda.time.Duration;
1818

1919
import be.hyperrail.android.R;
20+
import be.hyperrail.android.activities.MainActivity;
2021
import be.hyperrail.android.logging.HyperRailLog;
2122

22-
public class ReviewDialogProvider {
23+
public class ReviewDialog {
2324

2425
private static final String PREFERENCES_KEY_DONT_SHOW_AGAIN = "rvd_dont_show_again";
2526
private static final String PREFERENCES_KEY_FIRST_LAUNCH = "rvd_app_firstlaunch";
2627
private static final String PREFERENCES_KEY_LAUNCH_COUNT = "rvd_app_launches";
2728

28-
private static final HyperRailLog log = HyperRailLog.getLogger(ReviewDialogProvider.class);
29+
private static final HyperRailLog log = HyperRailLog.getLogger(ReviewDialog.class);
2930

3031
private static SharedPreferences sharedPreferences;
3132
private static int launches;
3233
private static long firstLaunch;
3334

34-
private ReviewDialogProvider() {
35+
private ReviewDialog() {
3536
// No public constructor
3637
}
3738

Hyperrail/src/main/java/be/hyperrail/android/viewgroup/RouteListItemLayout.java

-5
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ public RouteListItemLayout(Context context, @Nullable AttributeSet attrs, int de
8282
super(context, attrs, defStyleAttr);
8383
}
8484

85-
// TODO: use when API > 21
86-
/*public RouteListItemLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
87-
super(context, attrs, defStyleAttr, defStyleRes);
88-
}*/
89-
9085
@Override
9186
protected void onFinishInflate() {
9287
super.onFinishInflate();

0 commit comments

Comments
 (0)