diff --git a/AndroidManifest.xml b/AndroidManifest.xml
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2,8 +2,6 @@
-
-
@@ -14,13 +12,19 @@
+ android:name=".BustoApp"
+ android:allowBackup="true"
+ android:icon="@mipmap/ic_launcher"
+ android:label="@string/app_name"
+ android:networkSecurityConfig="@xml/networks_security_config"
+ android:roundIcon="@mipmap/ic_launcher_round"
+ android:theme="@style/AppTheme.NoActionBar">
+
+
+
+ android:name=".ActivityMap"
+ android:label="@string/title_activity_map"
+ android:parentActivityName=".ActivityMain"
+ android:theme="@style/MapTheme">
+ android:name="android.support.PARENT_ACTIVITY"
+ android:value=".ActivityMain"/>
-
+ android:label="@string/app_name"
+ android:screenOrientation="portrait">
-
-
+
@@ -132,4 +134,4 @@
-
+
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
--- a/build.gradle
+++ b/build.gradle
@@ -6,11 +6,9 @@
}
- dependencies {
-
- classpath 'com.android.tools.build:gradle:4.1.3'
- }
ext {
+ //multidex
+ multidex_version = "2.0.1"
//libraries versions
fragment_version = "1.3.6"
activity_version = "1.2.4"
@@ -21,8 +19,17 @@
acra_version = "5.7.0"
lifecycle_version = "2.3.1"
arch_version = "2.1.0"
+ room_version = "2.3.0"
+ //kotlin
+ kotlin_version = '1.5.0'
+ coroutines_version = "1.5.0"
}
+ dependencies {
+
+ classpath 'com.android.tools.build:gradle:4.1.3'
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
+ }
}
allprojects {
repositories {
@@ -34,6 +41,8 @@
}
apply plugin: 'com.android.application'
+apply plugin: 'kotlin-android'
+apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 29
@@ -41,11 +50,12 @@
defaultConfig {
applicationId "it.reyboz.bustorino"
- minSdkVersion 14
+ minSdkVersion 16
targetSdkVersion 29
versionCode 35
versionName "1.15.4"
vectorDrawables.useSupportLibrary = true
+ multiDexEnabled true
}
compileOptions {
@@ -91,8 +101,8 @@
implementation "androidx.preference:preference:$preference_version"
implementation "androidx.work:work-runtime:$work_version"
-
- implementation "com.google.android.material:material:1.3.0"
+ implementation "com.google.android.material:material:1.4.0"
+ implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'org.jsoup:jsoup:1.13.1'
@@ -113,5 +123,18 @@
// Lifecycles only (without ViewModel or LiveData)
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
+ // Room components
+ implementation "androidx.room:room-ktx:$room_version"
+ kapt "androidx.room:room-compiler:$room_version"
+ androidTestImplementation "androidx.room:room-testing:$room_version"
+ //multidex - we need this to build the app
+ implementation "androidx.multidex:multidex:$multidex_version"
}
}
+
+dependencies {
+
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
+ api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
+ api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
+}
\ No newline at end of file
diff --git a/res/layout/activity_experiments.xml b/res/layout/activity_experiments.xml
new file mode 100644
--- /dev/null
+++ b/res/layout/activity_experiments.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/res/menu/extra_menu_items.xml b/res/menu/principal_menu.xml
rename from res/menu/extra_menu_items.xml
rename to res/menu/principal_menu.xml
--- a/res/menu/extra_menu_items.xml
+++ b/res/menu/principal_menu.xml
@@ -21,4 +21,9 @@
android:orderInCategory="8"
android:title="@string/action_licence"
app:showAsAction="never" />
+
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -157,7 +157,8 @@
storageThe application has crashed because you encountered a bug.
\nIf you want, you can help the developers by sending the crash report via email.
- \nNote that no sensitive data is contained in the report, just small bits of info on your phone and app configuration/state.
+ \nNote that no sensitive data is contained in the report, just small bits of info on your phone and app
+ configuration/state.
The application crashed and the crash report is in the attachments. Please
describe what you were doing before the crash: \n
@@ -171,4 +172,6 @@
Buy us a coffeeMapSearch by stop
+
+
diff --git a/res/values/theme.xml b/res/values/theme.xml
--- a/res/values/theme.xml
+++ b/res/values/theme.xml
@@ -21,4 +21,6 @@
+
+
\ No newline at end of file
diff --git a/res/xml/networks_security_config.xml b/res/xml/networks_security_config.xml
--- a/res/xml/networks_security_config.xml
+++ b/res/xml/networks_security_config.xml
@@ -3,6 +3,6 @@
5t.torino.itgtt.to.it
-
+ comune.torino.it
\ No newline at end of file
diff --git a/src/it/reyboz/bustorino/ActivityExperiments.java b/src/it/reyboz/bustorino/ActivityExperiments.java
new file mode 100644
--- /dev/null
+++ b/src/it/reyboz/bustorino/ActivityExperiments.java
@@ -0,0 +1,106 @@
+/*
+ BusTO - Data components
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
+package it.reyboz.bustorino;
+
+import android.os.AsyncTask;
+import android.util.Log;
+import android.view.View;
+import androidx.appcompat.app.AppCompatActivity;
+import android.os.Bundle;
+import it.reyboz.bustorino.backend.Fetcher;
+import it.reyboz.bustorino.backend.gtfs.GtfsDataParser;
+import it.reyboz.bustorino.backend.networkTools;
+import it.reyboz.bustorino.backend.utils;
+import it.reyboz.bustorino.middleware.GeneralActivity;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipInputStream;
+
+public class ActivityExperiments extends GeneralActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_experiments);
+ }
+
+ public void runExp(View v){
+
+ Thread th = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ final String DEBUG_TAG = "ExperimentsGTFS";
+ AtomicReference res = new AtomicReference<>();
+ //List files = GtfsDataParser.readFilesList(res);
+ Date updateDate = GtfsDataParser.getLastGTFSUpdateDate(res);
+ Log.w(
+ "ExperimentGTFS", "Last update date is "+updateDate//utils.joinList(files, "\n")
+ );
+
+ File saveFile = new File(getFilesDir(), "gtfs_data.zip");
+ if(!saveFile.isDirectory() && saveFile.exists()){
+ Log.w(DEBUG_TAG, "Zip exists: "+saveFile);
+ try (FileInputStream fileStream = new FileInputStream(saveFile);) {
+ ZipInputStream stream = new ZipInputStream(fileStream);
+ // now iterate through each item in the stream. The get next
+ // entry call will return a ZipEntry for each file in the
+ // stream
+ ZipEntry entry;
+ while ((entry = stream.getNextEntry()) != null) {
+ String s = String.format(Locale.ENGLISH, "Entry: %s len %d added",
+ entry.getName(),
+ entry.getSize()
+ );
+ Log.d(DEBUG_TAG,s);
+
+ // Once we get the entry from the stream, the stream is
+ // positioned read to read the raw data, and we keep
+ // reading until read returns 0 or less.
+ //result.add(entry.getName());
+ }
+ stream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ //saveFile.delete();
+ } else
+ try {
+ networkTools.saveFileInCache(saveFile,new URL(GtfsDataParser.GTFS_ADDRESS));
+ Log.w(DEBUG_TAG, "File saved");
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ th.start();
+
+
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/it/reyboz/bustorino/ActivityPrincipal.java b/src/it/reyboz/bustorino/ActivityPrincipal.java
--- a/src/it/reyboz/bustorino/ActivityPrincipal.java
+++ b/src/it/reyboz/bustorino/ActivityPrincipal.java
@@ -1,3 +1,20 @@
+/*
+ BusTO - Arrival times for Turin public transport.
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
package it.reyboz.bustorino;
import android.Manifest;
@@ -23,6 +40,7 @@
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
+import androidx.preference.PreferenceManager;
import androidx.work.BackoffPolicy;
import androidx.work.Constraints;
import androidx.work.ExistingPeriodicWorkPolicy;
@@ -300,7 +318,11 @@
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.extra_menu_items, menu);
+ getMenuInflater().inflate(R.menu.principal_menu, menu);
+ MenuItem experimentsMenuItem = menu.findItem(R.id.action_experiments);
+ SharedPreferences shPr = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+ boolean exper_On = shPr.getBoolean(getString(R.string.pref_key_experimental), false);
+ experimentsMenuItem.setVisible(exper_On);
return super.onCreateOptionsMenu(menu);
}
@@ -569,6 +591,8 @@
case R.id.action_licence:
openIceweasel("https://www.gnu.org/licenses/gpl-3.0.html", activityContext);
return true;
+ case R.id.action_experiments:
+ startActivity(new Intent(ActivityPrincipal.this, ActivityExperiments.class));
default:
}
return false;
diff --git a/src/it/reyboz/bustorino/BustoApp.java b/src/it/reyboz/bustorino/BustoApp.java
--- a/src/it/reyboz/bustorino/BustoApp.java
+++ b/src/it/reyboz/bustorino/BustoApp.java
@@ -1,8 +1,25 @@
+/*
+ BusTO - Arrival times for Turin public transport.
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
package it.reyboz.bustorino;
-import android.app.Application;
import android.content.Context;
+import androidx.multidex.MultiDexApplication;
import org.acra.ACRA;
import org.acra.BuildConfig;
import org.acra.ReportField;
@@ -14,7 +31,7 @@
import static org.acra.ReportField.*;
-public class BustoApp extends Application {
+public class BustoApp extends MultiDexApplication {
private static final ReportField[] REPORT_FIELDS = {REPORT_ID, APP_VERSION_CODE, APP_VERSION_NAME,
PACKAGE_NAME, PHONE_MODEL, BRAND, PRODUCT, ANDROID_VERSION, BUILD_CONFIG, CUSTOM_DATA,
IS_SILENT, STACK_TRACE, INITIAL_CONFIGURATION, CRASH_CONFIGURATION, DISPLAY, USER_COMMENT,
diff --git a/src/it/reyboz/bustorino/backend/Fetcher.java b/src/it/reyboz/bustorino/backend/Fetcher.java
--- a/src/it/reyboz/bustorino/backend/Fetcher.java
+++ b/src/it/reyboz/bustorino/backend/Fetcher.java
@@ -31,6 +31,7 @@
* QUERY_TOO_SHORT: input more characters and retry.
*/
enum Result {
- OK, CLIENT_OFFLINE, SERVER_ERROR, SETUP_ERROR,PARSER_ERROR, EMPTY_RESULT_SET, QUERY_TOO_SHORT,SERVER_ERROR_404
+ OK, CLIENT_OFFLINE, SERVER_ERROR, SETUP_ERROR,PARSER_ERROR, EMPTY_RESULT_SET, QUERY_TOO_SHORT, SERVER_ERROR_404,
+ CONNECTION_ERROR
}
}
diff --git a/src/it/reyboz/bustorino/backend/gtfs/GtfsDataParser.java b/src/it/reyboz/bustorino/backend/gtfs/GtfsDataParser.java
new file mode 100644
--- /dev/null
+++ b/src/it/reyboz/bustorino/backend/gtfs/GtfsDataParser.java
@@ -0,0 +1,142 @@
+package it.reyboz.bustorino.backend.gtfs;
+
+import android.util.Log;
+import it.reyboz.bustorino.backend.Fetcher;
+import it.reyboz.bustorino.backend.networkTools;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URI;
+import java.net.URL;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Locale;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+abstract public class GtfsDataParser {
+ public static final String GTFS_ADDRESS="https://www.gtt.to.it/open_data/gtt_gtfs.zip";
+ public static final String GTFS_PAGE_ADDRESS="http://aperto.comune.torino.it/dataset/feed-gtfs-trasporti-gtt";
+
+ private static final String DEBUG_TAG = "BusTO-GTFSDataParser";
+ /**
+ * First trial for a function to download the zip
+ * @param res Fetcher.result
+ * @return the list of files inside the ziè
+ */
+ public static ArrayList readFilesList(AtomicReference res){
+
+ HttpURLConnection urlConnection;
+ InputStream in;
+ ArrayList result = new ArrayList<>();
+ try {
+ final URL gtfsUrl = new URL(GTFS_ADDRESS);
+ urlConnection = (HttpURLConnection) gtfsUrl.openConnection();
+ } catch(IOException e) {
+ //e.printStackTrace();
+ res.set(Fetcher.Result.SERVER_ERROR); // even when offline, urlConnection works fine. WHY.
+ return null;
+ }
+ urlConnection.setConnectTimeout(4000);
+ urlConnection.setReadTimeout(50*1000);
+
+ try {
+ in = urlConnection.getInputStream();
+ } catch (Exception e) {
+ try {
+ if(urlConnection.getResponseCode()==404)
+ res.set(Fetcher.Result.SERVER_ERROR_404);
+ } catch (IOException e2) {
+ e2.printStackTrace();
+ }
+ return null;
+
+ }
+ try (ZipInputStream stream = new ZipInputStream(in)) {
+
+ // now iterate through each item in the stream. The get next
+ // entry call will return a ZipEntry for each file in the
+ // stream
+ ZipEntry entry;
+ while ((entry = stream.getNextEntry()) != null) {
+ String s = String.format(Locale.ENGLISH, "Entry: %s len %d added",
+ entry.getName(),
+ entry.getSize()
+ );
+ System.out.println(s);
+
+ // Once we get the entry from the stream, the stream is
+ // positioned read to read the raw data, and we keep
+ // reading until read returns 0 or less.
+ result.add(entry.getName());
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ // we must always close the zip file.
+ return result;
+ }
+
+ public static Date getLastGTFSUpdateDate(AtomicReference res) {
+ URL theURL;
+ final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
+ //final Date baseDate = dateFormat.parse("1970-00-00T00:00:00+0000");
+ final Date nullDate = new Date(0);
+ try{
+ theURL = new URL(GTFS_PAGE_ADDRESS);
+ } catch (IOException ex){
+ Log.e(DEBUG_TAG, "Fixed URL is null, this is a real issue");
+ return nullDate;
+ }
+ res.set(Fetcher.Result.OK);
+ final String fullPageDOM = networkTools.getDOM(theURL, res);
+ if(fullPageDOM== null){
+ //Something wrong happend
+ Log.e(DEBUG_TAG, "Cannot get URL");
+ return nullDate;
+ }
+ res.set(Fetcher.Result.OK);
+ Document doc = Jsoup.parse(fullPageDOM);
+
+ Elements sections = doc.select("section.additional-info");
+ Date finalDate = new Date(0);
+ for (Element sec: sections){
+ Element head = sec.select("h3").first();
+ String headTitle = head.text();
+ if(!headTitle.trim().toLowerCase(Locale.ITALIAN).equals("informazioni supplementari"))
+ continue;
+
+ for (Element row: sec.select("tr")){
+ if(!row.selectFirst("th").text().trim()
+ .toLowerCase(Locale.ITALIAN).equals("ultimo aggiornamento"))
+ continue;
+
+ Attributes spanAttributes = row.selectFirst("td > span").attributes();
+ String dateAsString = spanAttributes.get("data-datetime");
+ try {
+ finalDate = dateFormat.parse(dateAsString);
+ return finalDate;
+ }catch (ParseException ex){
+ Log.e(DEBUG_TAG, "Wrong date for the last update of GTFS Data: "+dateAsString);
+ res.set(Fetcher.Result.PARSER_ERROR);
+ ex.printStackTrace();
+ }
+ break;
+ }
+ }
+ res.set(Fetcher.Result.PARSER_ERROR);
+ return finalDate;
+
+ }
+}
diff --git a/src/it/reyboz/bustorino/backend/networkTools.java b/src/it/reyboz/bustorino/backend/networkTools.java
--- a/src/it/reyboz/bustorino/backend/networkTools.java
+++ b/src/it/reyboz/bustorino/backend/networkTools.java
@@ -18,22 +18,20 @@
package it.reyboz.bustorino.backend;
+import android.content.Context;
import androidx.annotation.Nullable;
import android.util.Log;
-import java.io.BufferedInputStream;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicReference;
public abstract class networkTools {
- static String getDOM(final URL url, final AtomicReference res) {
+ public static String getDOM(final URL url, final AtomicReference res) {
//Log.d("asyncwget", "Catching URL in background: " + uri[0]);
HttpURLConnection urlConnection;
StringBuilder result = null;
@@ -70,6 +68,52 @@
res.set(Fetcher.Result.PARSER_ERROR); // will be set to "OK" later, this is a safety net in case StringBuilder returns null, the website returns an HTTP 204 or something like that.
return result.toString();
}
+
+ public static Fetcher.Result saveFileInCache(File outputFile, URL url) {
+ HttpURLConnection urlConnection;
+ try {
+ urlConnection = (HttpURLConnection) url.openConnection();
+ } catch (IOException e) {
+ //e.printStackTrace();
+ return Fetcher.Result.CONNECTION_ERROR;
+ }
+ urlConnection.setConnectTimeout(4000);
+ urlConnection.setReadTimeout(50 * 1000);
+
+ Log.d("BusTO net Tools", "Download file "+url);
+ try (InputStream inputStream = urlConnection.getInputStream()) {
+ //File outputFile = new File(con.getFilesDir(), fileName);
+ //BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
+ FileOutputStream outputStream = new FileOutputStream(outputFile);
+ byte buffer[] = new byte[16384];
+ boolean inProgress = true;
+ while(inProgress){
+ int numread = inputStream.read(buffer);
+ inProgress = (numread > 0);
+ if(inProgress) outputStream.write(buffer, 0, numread);
+ }
+ outputStream.close();
+ //while (bufferedInputStream.available())
+ } catch (IOException e) {
+ e.printStackTrace();
+ try {
+ final Fetcher.Result res;
+ if(urlConnection.getResponseCode()==404)
+ res= Fetcher.Result.SERVER_ERROR_404;
+ else if(urlConnection.getResponseCode()!=200)
+ res= Fetcher.Result.SERVER_ERROR;
+ else res= Fetcher.Result.PARSER_ERROR;
+ urlConnection.disconnect();
+ return res;
+ } catch (IOException ioException) {
+ ioException.printStackTrace();
+ urlConnection.disconnect();
+ return Fetcher.Result.PARSER_ERROR;
+ }
+ }
+ urlConnection.disconnect();
+ return Fetcher.Result.OK;
+ }
@Nullable
static String queryURL(URL url, AtomicReference res){
return queryURL(url,res,null);
diff --git a/src/it/reyboz/bustorino/backend/utils.java b/src/it/reyboz/bustorino/backend/utils.java
--- a/src/it/reyboz/bustorino/backend/utils.java
+++ b/src/it/reyboz/bustorino/backend/utils.java
@@ -8,10 +8,12 @@
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
+import androidx.annotation.Nullable;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Arrays;
+import java.util.List;
public abstract class utils {
private static final double EarthRadius = 6371e3;
@@ -153,4 +155,17 @@
return "Trace too Short.";
}
*/
+ public static String joinList(@Nullable List dat, String separator){
+ StringBuilder sb = new StringBuilder();
+ if(dat==null || dat.size()==0)
+ return "";
+ else if(dat.size()==1)
+ return dat.get(0);
+ sb.append(dat.get(0));
+ for (int i=1; i.
+ */
+package it.reyboz.bustorino.data;
+
+import android.content.ContentValues;
+import it.reyboz.bustorino.data.gtfs.GtfsStopTimes;
+
+public class AppRepository {
+
+
+}
diff --git a/src/it/reyboz/bustorino/data/DBUpdateWorker.java b/src/it/reyboz/bustorino/data/DBUpdateWorker.java
--- a/src/it/reyboz/bustorino/data/DBUpdateWorker.java
+++ b/src/it/reyboz/bustorino/data/DBUpdateWorker.java
@@ -1,3 +1,20 @@
+/*
+ BusTO - Data components
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
package it.reyboz.bustorino.data;
import android.annotation.SuppressLint;
diff --git a/src/it/reyboz/bustorino/data/DatabaseUpdate.java b/src/it/reyboz/bustorino/data/DatabaseUpdate.java
--- a/src/it/reyboz/bustorino/data/DatabaseUpdate.java
+++ b/src/it/reyboz/bustorino/data/DatabaseUpdate.java
@@ -1,3 +1,20 @@
+/*
+ BusTO - Data components
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
package it.reyboz.bustorino.data;
import android.content.ContentValues;
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
@@ -1,3 +1,20 @@
+/*
+ BusTO - Data components
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
package it.reyboz.bustorino.data;
diff --git a/src/it/reyboz/bustorino/data/GTTInfoInject.java b/src/it/reyboz/bustorino/data/GTTInfoInject.java
--- a/src/it/reyboz/bustorino/data/GTTInfoInject.java
+++ b/src/it/reyboz/bustorino/data/GTTInfoInject.java
@@ -1,3 +1,20 @@
+/*
+ BusTO - Data components
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
package it.reyboz.bustorino.data;
import java.util.Locale;
diff --git a/src/it/reyboz/bustorino/data/gtfs/Converters.kt b/src/it/reyboz/bustorino/data/gtfs/Converters.kt
new file mode 100644
--- /dev/null
+++ b/src/it/reyboz/bustorino/data/gtfs/Converters.kt
@@ -0,0 +1,59 @@
+/*
+ BusTO - Data components
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
+package it.reyboz.bustorino.data.gtfs
+
+import androidx.room.TypeConverter
+import java.text.SimpleDateFormat
+import java.util.*
+
+/**
+ * Class to convert values for objects into
+ * the needed columns
+ *
+ * handled automatically by Room with TypeConverter
+ */
+class Converters {
+
+
+ @TypeConverter
+ fun fromString(value: String?): Date? {
+ return value?.let {
+
+ stringFormat.parse(it)
+ }
+ }
+
+ @TypeConverter
+ fun dateToString(date: Date?): String? {
+ return date?.let { stringFormat.format(it)}
+ }
+
+ @TypeConverter
+ fun exceptionToInt(type: GtfsDates.ExceptionType?): Int? {
+ return type?.value
+ }
+ @TypeConverter
+ fun fromInt(value: Int?): GtfsDates.ExceptionType? {
+ return value?.let { GtfsDates.ExceptionType.getByValue(it) }
+ }
+
+ companion object{
+ const val DATE_FMT_STRING = "yyyyMMdd"
+ val stringFormat = SimpleDateFormat(DATE_FMT_STRING, Locale.US)
+ }
+}
\ No newline at end of file
diff --git a/src/it/reyboz/bustorino/data/gtfs/GtfsDatabase.kt b/src/it/reyboz/bustorino/data/gtfs/GtfsDatabase.kt
new file mode 100644
--- /dev/null
+++ b/src/it/reyboz/bustorino/data/gtfs/GtfsDatabase.kt
@@ -0,0 +1,57 @@
+/*
+ BusTO - Data components
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
+package it.reyboz.bustorino.data.gtfs
+
+import android.content.Context
+import androidx.room.Database
+import androidx.room.Room
+import androidx.room.RoomDatabase
+import androidx.room.TypeConverters
+
+@Database(
+ entities = [
+ GtfsStop::class,
+ GtfsRoute::class,
+ GtfsStopTimes::class,
+ GtfsTrips::class,
+ GtfsShape::class],
+ version = GtfsDatabase.VERSION,
+ exportSchema = false,
+)
+@TypeConverters(Converters::class)
+public abstract class GtfsDatabase : RoomDatabase() {
+
+ abstract fun gtfsDao() : StaticGtfsDao
+
+ companion object{
+ @Volatile
+ private var INSTANCE: GtfsDatabase? =null;
+
+ fun getGtfsDatabase(context: Context): GtfsDatabase{
+ return INSTANCE ?: synchronized(this){
+ val instance = Room.databaseBuilder(context.applicationContext,
+ GtfsDatabase::class.java,
+ "gtfs_database").build()
+ INSTANCE = instance
+ instance
+ }
+ }
+
+ const val VERSION = 1;
+ }
+}
\ No newline at end of file
diff --git a/src/it/reyboz/bustorino/data/gtfs/GtfsDates.kt b/src/it/reyboz/bustorino/data/gtfs/GtfsDates.kt
new file mode 100644
--- /dev/null
+++ b/src/it/reyboz/bustorino/data/gtfs/GtfsDates.kt
@@ -0,0 +1,54 @@
+/*
+ BusTO - Data components
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
+package it.reyboz.bustorino.data.gtfs
+
+import androidx.room.ColumnInfo
+import androidx.room.Entity
+import java.util.Date
+
+
+@Entity(
+ tableName = GtfsDates.DB_TABLE,
+ primaryKeys = [GtfsDates.COL_SERVICE_ID, GtfsDates.COL_DATE]
+)
+data class GtfsDates(
+ @ColumnInfo(name= COL_SERVICE_ID)
+ val serviceID: String,
+ @ColumnInfo(name=COL_DATE)
+ val date: Date,
+ @ColumnInfo(name=COL_EXCEPTION)
+ val exceptionType: ExceptionType,
+){
+ companion object{
+ const val DB_TABLE="gtfs_calendar_dates"
+ const val COL_SERVICE_ID="service_id"
+ const val COL_DATE="date"
+ const val COL_EXCEPTION="exception_type"
+
+ }
+ enum class ExceptionType(val value: Int){
+ ADDED(1),
+ REMOVED(2);
+
+ companion object {
+ private val VALUES = values()
+ fun getByValue(value: Int) = VALUES.firstOrNull { it.value == value }
+ }
+ }
+}
+
diff --git a/src/it/reyboz/bustorino/data/gtfs/GtfsRoute.kt b/src/it/reyboz/bustorino/data/gtfs/GtfsRoute.kt
new file mode 100644
--- /dev/null
+++ b/src/it/reyboz/bustorino/data/gtfs/GtfsRoute.kt
@@ -0,0 +1,51 @@
+/*
+ BusTO - Data components
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
+package it.reyboz.bustorino.data.gtfs
+
+import androidx.room.ColumnInfo
+import androidx.room.Entity
+import androidx.room.PrimaryKey
+
+@Entity(tableName=GtfsRoute.DB_TABLE)
+data class GtfsRoute(
+ @PrimaryKey @ColumnInfo(name = "route_id")
+ val ID: String,
+ @ColumnInfo(name = "agency_id")
+ val agencyID: String,
+ @ColumnInfo(name = "route_short_name")
+ val shortName: String,
+ @ColumnInfo(name = "route_long_name")
+ val longName: String,
+ @ColumnInfo(name = "route_desc")
+ val description: String,
+ @ColumnInfo(name ="route_type")
+ val type: String,
+ @ColumnInfo(name ="route_url")
+ val url: String,
+ @ColumnInfo(name ="route_color")
+ val color: String,
+ @ColumnInfo(name ="route_text_color")
+ val textColor: String,
+ @ColumnInfo(name = SORT_ORDER)
+ val sortOrder: Int
+){
+ companion object {
+ const val DB_TABLE: String="routes_table"
+ const val SORT_ORDER: String="route_sort_order"
+ }
+}
diff --git a/src/it/reyboz/bustorino/data/gtfs/GtfsService.kt b/src/it/reyboz/bustorino/data/gtfs/GtfsService.kt
new file mode 100644
--- /dev/null
+++ b/src/it/reyboz/bustorino/data/gtfs/GtfsService.kt
@@ -0,0 +1,63 @@
+/*
+ BusTO - Data components
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
+package it.reyboz.bustorino.data.gtfs
+
+import androidx.room.ColumnInfo
+import androidx.room.Entity
+import androidx.room.PrimaryKey
+import java.util.Date
+
+@Entity(tableName = GtfsService.DB_TABLE)
+data class GtfsService(
+ @PrimaryKey
+ @ColumnInfo(name = COL_SERVICE_ID)
+ val serviceID: String,
+ @ColumnInfo(name = COL_MONDAY)
+ val onMonday: Boolean,
+ @ColumnInfo(name = COL_TUESDAY)
+ val onTuesday: Boolean,
+ @ColumnInfo(name = COL_WEDNESDAY)
+ val onWednesday: Boolean,
+ @ColumnInfo(name = COL_THURSDAY)
+ val onThursday: Boolean,
+ @ColumnInfo(name = COL_FRIDAY)
+ val onFriday: Boolean,
+ @ColumnInfo(name = COL_SATURDAY)
+ val onSaturday: Boolean,
+ @ColumnInfo(name = COL_SUNDAY)
+ val onSunday: Boolean,
+ @ColumnInfo(name = COL_START_DATE)
+ val startDate: Date,
+ @ColumnInfo(name = COL_END_DATE)
+ val endDate: Date,
+){
+ companion object{
+ const val DB_TABLE="gtfs_calendar"
+ const val COL_SERVICE_ID="service_id"
+ const val COL_MONDAY="monday"
+ const val COL_TUESDAY="tuesday"
+ const val COL_WEDNESDAY="wednesday"
+ const val COL_THURSDAY="thursday"
+ const val COL_FRIDAY="friday"
+ const val COL_SATURDAY="saturday"
+ const val COL_SUNDAY="sunday"
+ const val COL_START_DATE="start_date"
+
+ const val COL_END_DATE="end_date"
+ }
+}
diff --git a/src/it/reyboz/bustorino/data/gtfs/GtfsShape.kt b/src/it/reyboz/bustorino/data/gtfs/GtfsShape.kt
new file mode 100644
--- /dev/null
+++ b/src/it/reyboz/bustorino/data/gtfs/GtfsShape.kt
@@ -0,0 +1,50 @@
+/*
+ BusTO - Data components
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
+package it.reyboz.bustorino.data.gtfs
+
+import androidx.room.ColumnInfo
+import androidx.room.Entity
+
+@Entity(tableName = GtfsShape.DB_TABLE,
+primaryKeys = [GtfsShape.COL_SHAPEID, GtfsShape.COL_POINT_SEQ])
+data class GtfsShape(
+ @ColumnInfo(name = COL_SHAPEID)
+ val shapeID: String,
+ @ColumnInfo(name = COL_POINT_LAT)
+ val pointLat: Double,
+ @ColumnInfo(name = COL_POINT_LON)
+ val pointLon: Double,
+ @ColumnInfo(name = COL_POINT_SEQ)
+ val pointSequence: Int,
+){
+
+ companion object{
+ const val DB_TABLE="gtfs_shapes"
+ const val COL_SHAPEID = "shape_id"
+ const val COL_POINT_LAT="shape_pt_lat"
+ const val COL_POINT_LON="shape_pt_lon"
+ const val COL_POINT_SEQ="shape_pt_sequence"
+
+ val COLUMNS= arrayOf(
+ COL_SHAPEID,
+ COL_POINT_LAT,
+ COL_POINT_LON,
+ COL_POINT_SEQ
+ )
+ }
+}
diff --git a/src/it/reyboz/bustorino/data/gtfs/GtfsStop.kt b/src/it/reyboz/bustorino/data/gtfs/GtfsStop.kt
new file mode 100644
--- /dev/null
+++ b/src/it/reyboz/bustorino/data/gtfs/GtfsStop.kt
@@ -0,0 +1,63 @@
+/*
+ BusTO - Data components
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
+package it.reyboz.bustorino.data.gtfs
+
+import androidx.room.ColumnInfo
+import androidx.room.Entity
+import androidx.room.PrimaryKey
+
+@Entity(tableName = GtfsStop.DB_TABLE)
+data class GtfsStop(
+ @PrimaryKey
+ @ColumnInfo(name= COL_STOPID)
+ val internalID: Int,
+ @ColumnInfo(name= COL_STOP_CODE)
+ val stopID: String,
+ @ColumnInfo(name= COL_STOP_NAME)
+ val stopName: String,
+ @ColumnInfo(name= COL_GTT_PLACE)
+ val gttPlaceName: String,
+ @ColumnInfo(name= COL_LATITUDE)
+ val latitude: Double,
+ @ColumnInfo(name= COL_LONGITUDE)
+ val longitude: Double,
+ @ColumnInfo(name="zone_id")
+ val zoneID: Int,
+ @ColumnInfo(name="wheelchair_boarding")
+ val wheelchair: Int,
+
+
+){
+ companion object{
+ const val DB_TABLE="stops_gtfs"
+ const val COL_STOP_CODE="stop_code"
+ const val COL_STOPID = "stop_id"
+ const val COL_GTT_PLACE="stop_desc"
+ const val COL_STOP_NAME="stop_name"
+ const val COL_LATITUDE="stop_lat"
+ const val COL_LONGITUDE="stop_lon"
+ val COLUMNS = arrayOf(
+ COL_STOP_CODE,
+ COL_STOPID,
+ COL_GTT_PLACE,
+ COL_STOP_NAME,
+ COL_LATITUDE,
+ COL_LONGITUDE,
+ )
+ }
+}
diff --git a/src/it/reyboz/bustorino/data/gtfs/GtfsStopTimes.kt b/src/it/reyboz/bustorino/data/gtfs/GtfsStopTimes.kt
new file mode 100644
--- /dev/null
+++ b/src/it/reyboz/bustorino/data/gtfs/GtfsStopTimes.kt
@@ -0,0 +1,54 @@
+/*
+ BusTO - Data components
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
+package it.reyboz.bustorino.data.gtfs
+
+import androidx.room.ColumnInfo
+import androidx.room.Entity
+
+@Entity(tableName = GtfsStopTimes.DB_TABLE,
+ primaryKeys = [GtfsStopTimes.COL_TRIPID, GtfsStopTimes.COL_STOPID]
+)
+data class GtfsStopTimes(
+ @ColumnInfo(name= COL_TRIPID)
+ val tripID: String,
+ @ColumnInfo(name= COL_ARRIVAL_TIME)
+ val arrivalTime: String,
+ @ColumnInfo(name= COL_DEPARTURE_TIME)
+ val departureTime:String,
+ @ColumnInfo(name= COL_STOPID)
+ val stopID: Int,
+ @ColumnInfo(name= COL_STOP_SEQUENCE)
+ val stopSequence: Int,
+){
+ companion object{
+ const val DB_TABLE="gtfs_stop_times"
+ const val COL_TRIPID="trip_id"
+ const val COL_ARRIVAL_TIME="arrival_time"
+ const val COL_DEPARTURE_TIME="departure_time"
+ const val COL_STOPID="stop_id"
+ const val COL_STOP_SEQUENCE="stop_sequence"
+
+ val COLUMNS = arrayOf(
+ COL_TRIPID,
+ COL_ARRIVAL_TIME,
+ COL_DEPARTURE_TIME,
+ COL_STOPID,
+ COL_STOP_SEQUENCE
+ )
+ }
+}
diff --git a/src/it/reyboz/bustorino/data/gtfs/GtfsTrips.kt b/src/it/reyboz/bustorino/data/gtfs/GtfsTrips.kt
new file mode 100644
--- /dev/null
+++ b/src/it/reyboz/bustorino/data/gtfs/GtfsTrips.kt
@@ -0,0 +1,79 @@
+/*
+ BusTO - Data components
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
+package it.reyboz.bustorino.data.gtfs
+
+import android.content.ContentValues
+import androidx.room.ColumnInfo
+import androidx.room.Entity
+import androidx.room.PrimaryKey
+
+@Entity(tableName = GtfsTrips.DB_TABLE)
+data class GtfsTrips(
+ @ColumnInfo(name = COL_ROUTE_ID )
+ val routeID: String,
+ @ColumnInfo(name = COL_SERVICE_ID)
+ val serviceID: String,
+ @PrimaryKey
+ @ColumnInfo(name = COL_TRIP_ID)
+ val tripID: String,
+ @ColumnInfo(name = COL_HEADSIGN)
+ val tripHeadsign: String,
+ @ColumnInfo(name = COL_DIRECTION_ID)
+ val directionID: Int,
+ @ColumnInfo(name = COL_BLOCK_ID)
+ val blockID: String,
+ @ColumnInfo(name = COL_SHAPE_ID)
+ val shapeID: String,
+ @ColumnInfo(name = COL_WHEELCHAIR)
+ val isWheelchairAccess: Boolean,
+ @ColumnInfo(name = COL_LIMITED_R)
+ val isLimitedRoute: Boolean,
+
+){
+
+ companion object{
+ const val DB_TABLE="gtfs_trips"
+ const val COL_ROUTE_ID="route_id"
+ const val COL_SERVICE_ID="service_id"
+ const val COL_TRIP_ID = "trip_id"
+ const val COL_HEADSIGN="trip_headsign"
+ //const val COL_SHORT_NAME="trip_short_name",
+ const val COL_DIRECTION_ID="direction_id"
+ const val COL_BLOCK_ID="block_id"
+ const val COL_SHAPE_ID = "shape_id"
+ const val COL_WHEELCHAIR="wheelchair_accessible"
+ const val COL_LIMITED_R="limited_route"
+
+ val COLUMNS= arrayOf(
+ COL_ROUTE_ID,
+ COL_SERVICE_ID,
+ COL_TRIP_ID,
+ COL_HEADSIGN,
+ COL_DIRECTION_ID,
+ COL_BLOCK_ID,
+ COL_SHAPE_ID,
+ COL_WHEELCHAIR,
+ COL_LIMITED_R
+ )
+ /*
+ open fun fromContentValues(values: ContentValues) {
+ val tripItem = GtfsTrips();
+ }
+ */
+ }
+}
\ No newline at end of file
diff --git a/src/it/reyboz/bustorino/data/gtfs/StaticGtfsDao.kt b/src/it/reyboz/bustorino/data/gtfs/StaticGtfsDao.kt
new file mode 100644
--- /dev/null
+++ b/src/it/reyboz/bustorino/data/gtfs/StaticGtfsDao.kt
@@ -0,0 +1,61 @@
+/*
+ BusTO - Data components
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
+package it.reyboz.bustorino.data.gtfs
+
+import androidx.lifecycle.LiveData
+import androidx.room.*
+
+@Dao
+interface StaticGtfsDao {
+ @Query("SELECT * FROM "+GtfsRoute.DB_TABLE+" ORDER BY "+GtfsRoute.SORT_ORDER)
+ fun getAllRoutes() : LiveData>
+
+ @Query("SELECT * FROM "+GtfsStop.DB_TABLE+" WHERE "+GtfsStop.COL_STOP_CODE+" LIKE :queryID")
+ fun getStopByStopID(queryID: String): LiveData>
+
+ @Query("SELECT * FROM "+GtfsShape.DB_TABLE+
+ " WHERE "+GtfsShape.COL_SHAPEID+" LIKE :shapeID"+
+ " ORDER BY "+GtfsShape.COL_POINT_SEQ+ " ASC"
+ )
+ fun getShapeByID(shapeID: String) : LiveData>
+
+ @Transaction
+ open fun clearAndInsertRoutes(routes: List){
+ deleteAllRoutes()
+ insertRoutes(routes)
+ }
+
+ @Insert
+ fun insertRoutes(users: List)
+ @Insert
+ fun insertStops(stops: List)
+
+
+ @Query("DELETE FROM "+GtfsRoute.DB_TABLE)
+ fun deleteAllRoutes()
+ @Query("DELETE FROM "+GtfsStop.DB_TABLE)
+ fun deleteAllStops()
+ @Update(onConflict = OnConflictStrategy.REPLACE)
+ fun updateShapes(shapes: List) : Int
+
+ @Transaction
+ fun updateStops(stops: List){
+ deleteAllStops()
+ insertStops(stops)
+ }
+}
\ No newline at end of file
diff --git a/src/it/reyboz/bustorino/fragments/FavoritesFragment.java b/src/it/reyboz/bustorino/fragments/FavoritesFragment.java
--- a/src/it/reyboz/bustorino/fragments/FavoritesFragment.java
+++ b/src/it/reyboz/bustorino/fragments/FavoritesFragment.java
@@ -1,3 +1,20 @@
+/*
+ BusTO - Fragments components
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
package it.reyboz.bustorino.fragments;
import android.app.AlertDialog;
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
@@ -1,3 +1,21 @@
+/*
+ BusTO - Fragments components
+ Copyright (C) 2020 Andrea Ugo
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
package it.reyboz.bustorino.fragments;
import android.Manifest;
diff --git a/src/it/reyboz/bustorino/fragments/SettingsFragment.java b/src/it/reyboz/bustorino/fragments/SettingsFragment.java
--- a/src/it/reyboz/bustorino/fragments/SettingsFragment.java
+++ b/src/it/reyboz/bustorino/fragments/SettingsFragment.java
@@ -1,3 +1,20 @@
+/*
+ BusTO - Fragments components
+ Copyright (C) 2020 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
package it.reyboz.bustorino.fragments;
import android.content.Context;
diff --git a/src/it/reyboz/bustorino/map/CustomInfoWindow.java b/src/it/reyboz/bustorino/map/CustomInfoWindow.java
--- a/src/it/reyboz/bustorino/map/CustomInfoWindow.java
+++ b/src/it/reyboz/bustorino/map/CustomInfoWindow.java
@@ -1,3 +1,21 @@
+/*
+ BusTO - Map components
+ Copyright (C) 2020 Andrea Ugo
+ Copyright (C) 2021 Fabio Mazza
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
package it.reyboz.bustorino.map;
import android.annotation.SuppressLint;
diff --git a/src/it/reyboz/bustorino/map/LocationOverlay.java b/src/it/reyboz/bustorino/map/LocationOverlay.java
--- a/src/it/reyboz/bustorino/map/LocationOverlay.java
+++ b/src/it/reyboz/bustorino/map/LocationOverlay.java
@@ -1,5 +1,5 @@
/*
- BusTO (middleware)
+ BusTO - Map components
Copyright (C) 2021 Fabio Mazza
This program is free software: you can redistribute it and/or modify