diff --git a/AndroidManifest.xml b/AndroidManifest.xml --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -46,7 +46,8 @@ android:name=".ActivityPrincipal" android:label="@string/app_name" android:screenOrientation="portrait" - android:windowSoftInputMode="adjustResize"> + android:windowSoftInputMode="adjustResize" + android:exported="true"> diff --git a/build.gradle b/build.gradle --- a/build.gradle +++ b/build.gradle @@ -10,16 +10,16 @@ //multidex multidex_version = "2.0.1" //libraries versions - fragment_version = "1.3.6" - activity_version = "1.3.1" - appcompat_version = "1.3.1" - preference_version = "1.1.1" - work_version = "2.5.0" + fragment_version = "1.4.1" + activity_version = "1.4.0" + appcompat_version = "1.4.1" + preference_version = "1.2.0" + work_version = "2.7.1" acra_version = "5.7.0" - lifecycle_version = "2.3.1" + lifecycle_version = "2.4.1" arch_version = "2.1.0" - room_version = "2.3.0" + room_version = "2.4.1" //kotlin kotlin_version = '1.6.0' coroutines_version = "1.5.0" @@ -27,7 +27,7 @@ } dependencies { - classpath 'com.android.tools.build:gradle:4.1.3' + classpath 'com.android.tools.build:gradle:4.2.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -46,13 +46,13 @@ apply plugin: 'kotlin-kapt' android { - compileSdkVersion 30 + compileSdkVersion 31 buildToolsVersion '30.0.3' defaultConfig { applicationId "it.reyboz.bustorino" minSdkVersion 16 - targetSdkVersion 30 + targetSdkVersion 31 versionCode 38 versionName "1.16.2" vectorDrawables.useSupportLibrary = true @@ -95,16 +95,16 @@ //new libraries implementation "androidx.fragment:fragment:$fragment_version" implementation "androidx.activity:activity:$activity_version" - implementation "androidx.annotation:annotation:1.2.0" + implementation "androidx.annotation:annotation:1.3.0" implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" implementation "androidx.appcompat:appcompat:$appcompat_version" implementation "androidx.appcompat:appcompat-resources:$appcompat_version" implementation "androidx.preference:preference:$preference_version" implementation "androidx.work:work-runtime:$work_version" - implementation "com.google.android.material:material:1.4.0" - implementation 'androidx.constraintlayout:constraintlayout:2.1.1' - implementation "androidx.coordinatorlayout:coordinatorlayout:1.1.0" + implementation "com.google.android.material:material:1.5.0" + implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation "androidx.coordinatorlayout:coordinatorlayout:1.2.0" implementation 'org.jsoup:jsoup:1.13.1' @@ -119,7 +119,7 @@ implementation 'com.google.protobuf:protobuf-java:3.14.0' // ViewModel - implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version" + implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" // LiveData implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version" // Lifecycles only (without ViewModel or LiveData) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Sat Apr 24 16:03:07 CEST 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/src/it/reyboz/bustorino/data/FavoritesLiveData.java b/src/it/reyboz/bustorino/data/FavoritesLiveData.java --- a/src/it/reyboz/bustorino/data/FavoritesLiveData.java +++ b/src/it/reyboz/bustorino/data/FavoritesLiveData.java @@ -40,7 +40,7 @@ import it.reyboz.bustorino.backend.Stop; public class FavoritesLiveData extends LiveData> implements CustomAsyncQueryHandler.AsyncQueryListener { - private static final String TAG = "FavoritesLiveData"; + private static final String TAG = "BusTO-FavoritesLiveData"; private final boolean notifyChangesDescendants; @@ -132,6 +132,11 @@ @Override public void onQueryComplete(int token, Object cookie, Cursor cursor) { + if (cursor == null){ + //Nothing to do + Log.e(TAG, "Null cursor for token "+token); + return; + } if (token == FAV_TOKEN) { stopsFromFavorites = UserDB.getFavoritesFromCursor(cursor, UserDB.getFavoritesColumnNamesAsArray); cursor.close(); @@ -157,7 +162,7 @@ Stop stopUpdate = stopsFromFavorites.get(index); Stop finalStop; - List result = Arrays.asList(NextGenDB.getStopsFromCursorAllFields(cursor)); + List result = NextGenDB.getStopsFromCursorAllFields(cursor); cursor.close(); if (result.size() < 1){ // stop is not in the DB diff --git a/src/it/reyboz/bustorino/data/NextGenDB.java b/src/it/reyboz/bustorino/data/NextGenDB.java --- a/src/it/reyboz/bustorino/data/NextGenDB.java +++ b/src/it/reyboz/bustorino/data/NextGenDB.java @@ -162,13 +162,10 @@ * double lngFrom = bb.getLonWestE6() / 1E6; * double lngTo = bb.getLonEastE6() / 1E6; */ - public synchronized Stop[] queryAllInsideMapView(double minLat, double maxLat, double minLng, double maxLng) { - Stop[] stops = new Stop[0]; + public synchronized ArrayList queryAllInsideMapView(double minLat, double maxLat, double minLng, double maxLng) { + ArrayList stops = new ArrayList<>(); SQLiteDatabase db = this.getReadableDatabase(); - //Cursor result=null; - int count; - // coordinates must be strings in the where condition String minLatRaw = String.valueOf(minLat); String maxLatRaw = String.valueOf(maxLat); @@ -202,17 +199,17 @@ * @param result cursor from query * @return an Array of the stops found in the query */ - public static Stop[] getStopsFromCursorAllFields(Cursor result){ - int colID = result.getColumnIndex(StopsTable.COL_ID); - int colName = result.getColumnIndex(StopsTable.COL_NAME); - int colLocation = result.getColumnIndex(StopsTable.COL_LOCATION); - int colType = result.getColumnIndex(StopsTable.COL_TYPE); - int colLat = result.getColumnIndex(StopsTable.COL_LAT); - int colLon = result.getColumnIndex(StopsTable.COL_LONG); - int colLines = result.getColumnIndex(StopsTable.COL_LINES_STOPPING); + public static ArrayList getStopsFromCursorAllFields(Cursor result){ + final int colID = result.getColumnIndex(StopsTable.COL_ID); + final int colName = result.getColumnIndex(StopsTable.COL_NAME); + final int colLocation = result.getColumnIndex(StopsTable.COL_LOCATION); + final int colType = result.getColumnIndex(StopsTable.COL_TYPE); + final int colLat = result.getColumnIndex(StopsTable.COL_LAT); + final int colLon = result.getColumnIndex(StopsTable.COL_LONG); + final int colLines = result.getColumnIndex(StopsTable.COL_LINES_STOPPING); int count = result.getCount(); - Stop[] stops = new Stop[count]; + ArrayList stops = new ArrayList<>(count); int i = 0; while(result.moveToNext()) { @@ -228,9 +225,10 @@ locationSometimesEmpty = null; } - stops[i++] = new Stop(stopID, result.getString(colName), null, + stops.add(new Stop(stopID, result.getString(colName), null, locationSometimesEmpty, type, splitLinesString(lines), - result.getDouble(colLat), result.getDouble(colLon)); + result.getDouble(colLat), result.getDouble(colLon)) + ); } return stops; } diff --git a/src/it/reyboz/bustorino/data/UserDB.java b/src/it/reyboz/bustorino/data/UserDB.java --- a/src/it/reyboz/bustorino/data/UserDB.java +++ b/src/it/reyboz/bustorino/data/UserDB.java @@ -190,7 +190,9 @@ Cursor c = db.query(TABLE_NAME, usernameColumnNameAsArray, "ID = ?", new String[] {stopID}, null, null, null); if(c.moveToNext()) { - username = c.getString(c.getColumnIndex("username")); + int userNameIndex = c.getColumnIndex("username"); + if (userNameIndex>=0) + username = c.getString(userNameIndex); } c.close(); } catch(SQLiteException ignored) {} @@ -250,6 +252,10 @@ throw new IllegalArgumentException(); } ArrayList l = new ArrayList<>(); + if (cursor==null){ + Log.e("UserDB-BusTO", "Null cursor given in getFavoritesFromCursor"); + return l; + } final int colID = cursor.getColumnIndex("ID"); final int colUser = cursor.getColumnIndex("username"); while(cursor.moveToNext()) { diff --git a/src/it/reyboz/bustorino/fragments/FragmentHelper.java b/src/it/reyboz/bustorino/fragments/FragmentHelper.java --- a/src/it/reyboz/bustorino/fragments/FragmentHelper.java +++ b/src/it/reyboz/bustorino/fragments/FragmentHelper.java @@ -53,7 +53,6 @@ public static final int NO_FRAME = -3; private static final String DEBUG_TAG = "BusTO FragmHelper"; private WeakReference lastTaskRef; - private SearchRequestType lastTaskType; private boolean shouldHaltAllActivities=false; @@ -214,6 +213,10 @@ */ public void showErrorMessage(Fetcher.Result res, SearchRequestType type){ //TODO: implement a common set of errors for all fragments + if (res==null){ + Log.e(DEBUG_TAG, "Asked to show result with null result"); + return; + } Log.d(DEBUG_TAG, "Showing result for "+res); switch (res){ case OK: diff --git a/src/it/reyboz/bustorino/fragments/MapFragment.java b/src/it/reyboz/bustorino/fragments/MapFragment.java --- a/src/it/reyboz/bustorino/fragments/MapFragment.java +++ b/src/it/reyboz/bustorino/fragments/MapFragment.java @@ -495,7 +495,7 @@ * @param stops the list of stops that must be included */ protected void showStopsMarkers(List stops){ - if (getContext() == null){ + if (getContext() == null || stops == null){ //we are not attached return; } @@ -611,10 +611,10 @@ //Log.d(DEBUG_TAG, "Async Stop Fetcher started working"); NextGenDB dbHelper = new NextGenDB(fragmentWeakReference.get().getContext()); - Stop[] stops = dbHelper.queryAllInsideMapView(limit.latitFrom, limit.latitTo, + ArrayList stops = dbHelper.queryAllInsideMapView(limit.latitFrom, limit.latitTo, limit.longFrom, limit.latitTo); dbHelper.close(); - return Arrays.asList(stops); + return stops; } @Override @@ -625,7 +625,8 @@ Log.w(DEBUG_TAG, "AsyncLoad fragmentWeakreference null"); return; } - Log.d(DEBUG_TAG, "AsyncLoad number of stops: "+stops.size()); + if (stops!=null) + Log.d(DEBUG_TAG, "AsyncLoad number of stops: "+stops.size()); fragmentWeakReference.get().showStopsMarkers(stops); }