Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/ActivityExperiments.java
Show All 12 Lines | BusTO - Data components | ||||
GNU General Public License for more details. | GNU General Public License for more details. | ||||
You should have received a copy of the GNU General Public License | You should have received a copy of the GNU General Public License | ||||
along with this program. If not, see <http://www.gnu.org/licenses/>. | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
package it.reyboz.bustorino; | package it.reyboz.bustorino; | ||||
import android.content.Context; | import android.content.Context; | ||||
import android.os.AsyncTask; | |||||
import android.os.Handler; | |||||
import android.os.Looper; | |||||
import android.util.Log; | import android.util.Log; | ||||
import android.view.View; | import android.view.View; | ||||
import android.widget.Button; | import android.widget.Button; | ||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import androidx.appcompat.app.AppCompatActivity; | |||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import it.reyboz.bustorino.backend.Fetcher; | import it.reyboz.bustorino.backend.Fetcher; | ||||
import it.reyboz.bustorino.backend.gtfs.GtfsDataParser; | import it.reyboz.bustorino.backend.gtfs.GtfsDataParser; | ||||
import it.reyboz.bustorino.backend.networkTools; | import it.reyboz.bustorino.backend.networkTools; | ||||
import it.reyboz.bustorino.backend.utils; | |||||
import it.reyboz.bustorino.data.gtfs.GtfsDatabase; | import it.reyboz.bustorino.data.gtfs.GtfsDatabase; | ||||
import it.reyboz.bustorino.data.gtfs.StaticGtfsDao; | import it.reyboz.bustorino.data.gtfs.GtfsDBDao; | ||||
import it.reyboz.bustorino.middleware.GeneralActivity; | import it.reyboz.bustorino.middleware.GeneralActivity; | ||||
import java.io.*; | import java.io.*; | ||||
import java.net.MalformedURLException; | import java.net.MalformedURLException; | ||||
import java.net.URL; | import java.net.URL; | ||||
import java.util.*; | import java.util.*; | ||||
import java.util.concurrent.ExecutorService; | import java.util.concurrent.ExecutorService; | ||||
import java.util.concurrent.Executors; | import java.util.concurrent.Executors; | ||||
import java.util.concurrent.atomic.AtomicReference; | import java.util.concurrent.atomic.AtomicReference; | ||||
import java.util.zip.ZipEntry; | import java.util.zip.ZipEntry; | ||||
import java.util.zip.ZipFile; | import java.util.zip.ZipFile; | ||||
import java.util.zip.ZipInputStream; | |||||
public class ActivityExperiments extends GeneralActivity { | public class ActivityExperiments extends GeneralActivity { | ||||
ExecutorService executorService; | ExecutorService executorService; | ||||
final static String DEBUG_TAG = "ExperimentsGTFS"; | final static String DEBUG_TAG = "ExperimentsGTFS"; | ||||
@Override | @Override | ||||
protected void onCreate(Bundle savedInstanceState) { | protected void onCreate(Bundle savedInstanceState) { | ||||
Show All 30 Lines | public void runExp(View v){ | ||||
AtomicReference<Fetcher.Result> res = new AtomicReference<>(); | AtomicReference<Fetcher.Result> res = new AtomicReference<>(); | ||||
//List<String> files = GtfsDataParser.readFilesList(res); | //List<String> files = GtfsDataParser.readFilesList(res); | ||||
Date updateDate = GtfsDataParser.getLastGTFSUpdateDate(res); | Date updateDate = GtfsDataParser.getLastGTFSUpdateDate(res); | ||||
Log.w( | Log.w( | ||||
"ExperimentGTFS", "Last update date is " + updateDate//utils.joinList(files, "\n") | "ExperimentGTFS", "Last update date is " + updateDate//utils.joinList(files, "\n") | ||||
); | ); | ||||
//Toast.makeText(v.getContext(), "Gtfs data already downloaded", Toast.LENGTH_SHORT).show(); | //Toast.makeText(v.getContext(), "Gtfs data already downloaded", Toast.LENGTH_SHORT).show(); | ||||
StaticGtfsDao dao = GtfsDatabase.Companion.getGtfsDatabase(appContext).gtfsDao(); | GtfsDBDao dao = GtfsDatabase.Companion.getGtfsDatabase(appContext).gtfsDao(); | ||||
Log.d(DEBUG_TAG, String.valueOf(dao)); | Log.d(DEBUG_TAG, String.valueOf(dao)); | ||||
dao.deleteAllStopTimes(); | dao.deleteAllStopTimes(); | ||||
File saveFile = new File(getFilesDir(), "gtfs_data.zip"); | File saveFile = new File(getFilesDir(), "gtfs_data.zip"); | ||||
if (!saveFile.isDirectory() && saveFile.exists()) { | if (!saveFile.isDirectory() && saveFile.exists()) { | ||||
Log.w(DEBUG_TAG, "Zip exists: " + saveFile); | Log.w(DEBUG_TAG, "Zip exists: " + saveFile); | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | public class ActivityExperiments extends GeneralActivity { | ||||
} | } | ||||
public void deleteDatabase(View v){ | public void deleteDatabase(View v){ | ||||
final Context con = getApplicationContext().getApplicationContext(); | final Context con = getApplicationContext().getApplicationContext(); | ||||
Toast.makeText(this, "Deleting GTFS DB contents, wait a few seconds", Toast.LENGTH_SHORT).show(); | Toast.makeText(this, "Deleting GTFS DB contents, wait a few seconds", Toast.LENGTH_SHORT).show(); | ||||
Runnable deleteDB = new Runnable() { | Runnable deleteDB = new Runnable() { | ||||
@Override | @Override | ||||
public void run() { | public void run() { | ||||
StaticGtfsDao dao = GtfsDatabase.Companion.getGtfsDatabase(con).gtfsDao(); | GtfsDBDao dao = GtfsDatabase.Companion.getGtfsDatabase(con).gtfsDao(); | ||||
Log.d(DEBUG_TAG, String.valueOf(dao)); | Log.d(DEBUG_TAG, String.valueOf(dao)); | ||||
dao.deleteAllStopTimes(); | dao.deleteAllStopTimes(); | ||||
dao.deleteAllTrips(); | dao.deleteAllTrips(); | ||||
dao.deleteAllRoutes(); | dao.deleteAllRoutes(); | ||||
dao.deleteAllStops(); | dao.deleteAllStops(); | ||||
dao.deleteAllServices(); | dao.deleteAllServices(); | ||||
Log.d(DEBUG_TAG, "Deleted stuff"); | Log.d(DEBUG_TAG, "Deleted stuff"); | ||||
} | } | ||||
}; | }; | ||||
executorService.execute(deleteDB); | executorService.execute(deleteDB); | ||||
} | } | ||||
} | } | ||||
No newline at end of file | No newline at end of file |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register