Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertware committed Dec 3, 2023
2 parents 12cbad6 + 57d97f0 commit 6c590f0
Show file tree
Hide file tree
Showing 32 changed files with 953 additions and 767 deletions.
26 changes: 13 additions & 13 deletions Hyperrail/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'

def VERSION_CODE = 57
def VERSION_NAME = '1.3.3'
def VERSION_CODE = 58
def VERSION_NAME = '1.3.4'

android {
compileSdk 33
buildToolsVersion '33.0.0'
compileSdk 34
defaultConfig {
applicationId "be.hyperrail.android"
minSdkVersion 21
targetSdkVersion 33
targetSdkVersion 34
versionCode VERSION_CODE
versionName VERSION_NAME
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -42,30 +41,31 @@ android {
lint {
abortOnError false
}
namespace 'be.hyperrail.android'
}

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

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

def lifecycle_version = "2.5.1"
def lifecycle_version = "2.6.2"
// Force the same lifecycle-viewmodel for kotlin and java.
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"

implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.preference:preference:1.2.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'com.google.android.gms:play-services-location:20.0.0'
implementation 'com.google.firebase:firebase-crashlytics:18.2.13'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'androidx.preference:preference:1.2.1'
implementation 'com.google.android.material:material:1.10.0'
implementation 'com.google.android.gms:play-services-location:21.0.1'
implementation 'com.google.firebase:firebase-crashlytics:18.6.0'

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.json:json:20220320'
Expand Down
10 changes: 5 additions & 5 deletions Hyperrail/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="be.hyperrail.android">
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down Expand Up @@ -31,9 +30,7 @@

<activity
android:name=".activities.MainActivity"
android:exported="true"
android:hardwareAccelerated="true"
android:windowSoftInputMode="stateUnchanged">
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down Expand Up @@ -76,6 +73,9 @@
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="false" />

<receiver
android:name=".widget.NextDeparturesWidgetProvider"
Expand Down
22 changes: 15 additions & 7 deletions Hyperrail/src/main/java/be/hyperrail/android/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@

package be.hyperrail.android;

import android.preference.PreferenceManager;

import com.google.firebase.crashlytics.FirebaseCrashlytics;

import be.hyperrail.android.logging.HyperRailConsoleLogWriter;
import be.hyperrail.android.logging.HyperRailCrashlyticsLogWriter;
import be.hyperrail.android.logging.HyperRailLog;
import be.hyperrail.android.logging.HyperRailLogWriter;
import be.hyperrail.android.util.ReviewDialogProvider;
import be.hyperrail.android.util.CrashlyticsOptInDialog;
import be.hyperrail.android.util.ReviewDialog;
import be.hyperrail.opentransportdata.OpenTransportApi;
import be.hyperrail.opentransportdata.be.IrailDataProvider;

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

public void onCreate() {

// Crashlytics abstraction layer
HyperRailLogWriter logger;
if (BuildConfig.DEBUG) {
boolean enableCrashlytics = BuildConfig.DEBUG
|| PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_crashlytics_enabled", true);
if (enableCrashlytics) {
logger = new HyperRailConsoleLogWriter();
HyperRailLog.initLogWriter(logger);
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true);
HyperRailLog.getLogger(Launcher.class).info("Crashlytics enabled");
} else {
logger = new HyperRailCrashlyticsLogWriter();
HyperRailLog.initLogWriter(logger);
HyperRailLog.getLogger(Launcher.class).info("Crashlytics disabled");
}
HyperRailLog.initLogWriter(logger);

// Setup the factory as soon as the app is created.
OpenTransportApi.init(getApplicationContext(), new IrailDataProvider(), logger);
// Set up Crashlytics, disabled for debug builds
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true);
ReviewDialogProvider.init(this);
ReviewDialog.init(this);
CrashlyticsOptInDialog.init(this);
super.onCreate();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
import be.hyperrail.android.fragments.RouteSearchFragment;
import be.hyperrail.android.fragments.VehicleSearchFragment;
import be.hyperrail.android.fragments.searchresult.DisturbanceListFragment;
import be.hyperrail.android.util.ReviewDialogProvider;
import be.hyperrail.android.util.CrashlyticsOptInDialog;
import be.hyperrail.android.util.ReviewDialog;
import be.hyperrail.android.util.ShortcutHelper;

/**
Expand Down Expand Up @@ -180,7 +181,9 @@ private void showLaunchDialogsIfNeeded() {
Intent i = new Intent(this, FirstLaunchGuide.class);
startActivity(i);
} else {
ReviewDialogProvider.showDialogIf(this, 7, 3);
// Don't overwhelm the user, keep crashlytics off until the second launch, then ask the user
CrashlyticsOptInDialog.showDialogOnce(this);
ReviewDialog.showDialogIf(this, 7, 3);
}
}

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

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY |
Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,17 @@ public static Intent createIntent(Context context, LiveboardRequest request) {
i.putExtra("request", request);
return i;
}

private Intent createShortcutIntent() {
Intent i = new Intent(this, LiveboardActivity.class);
public static Intent createShortcutIntent(Context context, String semanticStationId) {
Intent i = new Intent(context, LiveboardActivity.class);
i.putExtra("shortcut", true); // this variable allows to detect launches from shortcuts
i.putExtra("station", mRequest.getStation().getSemanticId()); // shortcut intents should not contain application specific classes - only pass the station ID
i.putExtra("station", semanticStationId); // shortcut intents should not contain application specific classes - only pass the station ID
return i;
}

private Intent createShortcutIntent() {
return createShortcutIntent(this, mRequest.getStation().getSemanticId());
}

@Override
protected void onCreate(Bundle savedInstanceState) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package be.hyperrail.android.util;

import android.app.AlertDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import org.joda.time.DateTime;

import be.hyperrail.android.R;
import be.hyperrail.android.logging.HyperRailLog;

public class CrashlyticsOptInDialog {

private static final String PREFERENCES_KEY_OPTIN_REPLIED = "crashreporting_optin_replied";
private static final String PREFERENCES_CRASHLYTICS_ENABLED = "pref_crashlytics_enabled";

private static final HyperRailLog log = HyperRailLog.getLogger(CrashlyticsOptInDialog.class);
private static SharedPreferences sharedPreferences;
private static boolean hasOptedInOrOut;

private CrashlyticsOptInDialog() {
// No public constructor
}

public static void init(Context context) {
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
hasOptedInOrOut = sharedPreferences.getBoolean(PREFERENCES_KEY_OPTIN_REPLIED, false);
}


public static void showDialogOnce(Context context) {
if (!hasOptedInOrOut){
showOptInDialog(context);
}
}

private static void showOptInDialog(final Context context) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);

int titleId = R.string.crashlytics_dialog_title;
int messageId = R.string.crashlytics_dialog_message;
int disableButtonText = R.string.crashlytics_dialog_button_disable;
int enableButtonText = R.string.crashlytics_dialog_button_enable;
builder.setTitle(titleId);
builder.setMessage(messageId);
setDialogButtonActions(builder, enableButtonText, disableButtonText);
builder.show();
}

private static void setDialogButtonActions(AlertDialog.Builder builder, int enableButtonText, int disableButtonText) {
builder.setPositiveButton(enableButtonText, (dialog, which) -> {
optIn();
setOptedInOrOut();
});
builder.setNegativeButton(disableButtonText, (dialog, which) -> {
optOut();
setOptedInOrOut();
});
}

private static void optIn() {
log.info("Storing opt-in from crashlytics");
setPreference(PREFERENCES_CRASHLYTICS_ENABLED, true);
}
private static void optOut() {
log.info("Storing opt-out from crashlytics");
setPreference(PREFERENCES_CRASHLYTICS_ENABLED, false);
}

private static void setOptedInOrOut() {
setPreference(PREFERENCES_KEY_OPTIN_REPLIED, true);
}

private static void setPreference(String preference, boolean value) {
if (sharedPreferences != null) {
sharedPreferences.edit().putBoolean(preference, value).apply();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@
import org.joda.time.Duration;

import be.hyperrail.android.R;
import be.hyperrail.android.activities.MainActivity;
import be.hyperrail.android.logging.HyperRailLog;

public class ReviewDialogProvider {
public class ReviewDialog {

private static final String PREFERENCES_KEY_DONT_SHOW_AGAIN = "rvd_dont_show_again";
private static final String PREFERENCES_KEY_FIRST_LAUNCH = "rvd_app_firstlaunch";
private static final String PREFERENCES_KEY_LAUNCH_COUNT = "rvd_app_launches";

private static final HyperRailLog log = HyperRailLog.getLogger(ReviewDialogProvider.class);
private static final HyperRailLog log = HyperRailLog.getLogger(ReviewDialog.class);

private static SharedPreferences sharedPreferences;
private static int launches;
private static long firstLaunch;

private ReviewDialogProvider() {
private ReviewDialog() {
// No public constructor
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ public RouteListItemLayout(Context context, @Nullable AttributeSet attrs, int de
super(context, attrs, defStyleAttr);
}

// TODO: use when API > 21
/*public RouteListItemLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}*/

@Override
protected void onFinishInflate() {
super.onFinishInflate();
Expand Down
Loading

0 comments on commit 6c590f0

Please sign in to comment.