Bimba.git

commit 9f5be268ff5be69c26a3899905c6af696cfbe599

Author: Adam Pioterek <adam.pioterek@protonmail.ch>

NoDb can be skipped

 README.md | 20 
 app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt | 41 +
 app/src/main/java/ml/adamsprogs/bimba/activities/NoDbActivity.kt | 9 
 app/src/main/res/drawable/ic_skip.xml | 5 


diff --git a/README.md b/README.md
index 4d73410bd1ac2e52853b33a547f77b21b5b68269..b37b334b115c3c10d8170bd052ab08baaf6d3006 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ * [x] favourite stops
     * [x] offline timetable
     * [x] Virtual Monitor
     * [x] peek all departures in a favourite
-* [x] less nonintuitive timetable refresh gesture
+* [x] less non-intuitive timetable refresh gesture
 * [ ] nearest stop(s) by GPS
 * [ ] ‘through mid-stop’ on lines with only 1 direction
 * [ ] city bike stations on map
@@ -32,8 +32,22 @@ * [ ] ticket machines on map
 * [ ] ever-present searchbar
 * [ ] other things on map
 
-Also
-* efficiency
+
+## If You want to help…
+
+### …be sure to…
+
+* check the issues, both closed and open;
+* check the most recent commit. Master contains published snapshots; most recent commit will be on other branch (there’s a branch with upcomming version and branches with betas that are periodically merged into it).
+
+### …then You can…
+
+* add a new translation. Just translate `strings.xml` and make a pull request or an issue;
+* set up Your own converter instance. For more info head to the [converter readme](converter/README.md)
+* help me move my own converter to some PaaS (like Heroku or other I-don’t-know-because-I-cannot-into-cloud)
+* think about any other way
+* <small> donate. More info [there](http://adamsprogs.tk/w/donate/)</small>
+
 
 ## Thanks to…
 




diff --git a/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
index 59aab9334d2fe0d571c05c6552c5c52e49b682d4..01f9e43077ee55fadab86bdb766076a4d27aa11e 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
@@ -3,6 +3,7 @@
 import android.annotation.SuppressLint
 import android.app.Activity
 import android.content.*
+import android.database.sqlite.SQLiteException
 import android.os.*
 import android.support.design.widget.*
 import android.support.v4.widget.*
@@ -33,7 +34,7 @@         FavouritesAdapter.OnMenuItemClickListener, Favourite.OnVmPreparedListener,
         FavouritesAdapter.ViewHolder.OnClickListener {
     val context: Context = this
     private val receiver = MessageReceiver.getMessageReceiver()
-    lateinit var timetable: Timetable
+    var timetable: Timetable? = null
     private var suggestions: List<GtfsSuggestion>? = null
     private lateinit var drawerLayout: DrawerLayout
     private lateinit var drawerView: NavigationView
@@ -54,7 +55,11 @@         setContentView(R.layout.activity_dash)
 
         setSupportActionBar(toolbar)
 
-        timetable = Timetable.getTimetable(this)
+        timetable = try {
+            Timetable.getTimetable(this)
+        } catch (e: SQLiteException) {
+            null
+        }
 
         getSuggestions()
 
@@ -146,13 +151,17 @@         searchView.attachNavigationDrawerToMenuButton(drawer_layout as DrawerLayout)
     }
 
     private fun showValidityInDrawer() {
-        val formatter = DateFormat.getDateInstance(DateFormat.SHORT)
-        var calendar = calendarFromIsoD(timetable.getValidSince())
-        formatter.timeZone = calendar.timeZone
-        drawerView.menu.findItem(R.id.drawer_validity_since).title = getString(R.string.valid_since, formatter.format(calendar.time))
-        calendar = calendarFromIsoD(timetable.getValidTill())
-        formatter.timeZone = calendar.timeZone
-        drawerView.menu.findItem(R.id.drawer_validity_till).title = getString(R.string.valid_till, formatter.format(calendar.time))
+        if (timetable == null) {
+            drawerView.menu.findItem(R.id.drawer_validity_since).title = getString(R.string.validity_offline_unavailable)
+        } else {
+            val formatter = DateFormat.getDateInstance(DateFormat.SHORT)
+            var calendar = calendarFromIsoD(timetable!!.getValidSince())
+            formatter.timeZone = calendar.timeZone
+            drawerView.menu.findItem(R.id.drawer_validity_since).title = getString(R.string.valid_since, formatter.format(calendar.time))
+            calendar = calendarFromIsoD(timetable!!.getValidTill())
+            formatter.timeZone = calendar.timeZone
+            drawerView.menu.findItem(R.id.drawer_validity_till).title = getString(R.string.valid_till, formatter.format(calendar.time))
+        }
     }
 
     private fun filterSuggestions(newQuery: String) {
@@ -164,14 +173,16 @@     }
 
     private fun warnTimetableValidity() {
         //todo not on turn
-        val validTill = timetable.getValidTill()
+        if (timetable == null)
+            return
+        val validTill = timetable!!.getValidTill()
         val today = Calendar.getInstance().toIsoDate()
         val tomorrow = Calendar.getInstance().apply {
             this.add(Calendar.DAY_OF_MONTH, 1)
         }.toIsoDate()
 
         try {
-            timetable.getServiceForToday()
+            timetable!!.getServiceForToday()
             if (today > validTill) {
                 notifyTimetableValidity(-1)
                 suggestions = ArrayList()
@@ -188,7 +199,7 @@             return
         }
 
         try {
-            timetable.getServiceForTomorrow()
+            timetable!!.getServiceForTomorrow()
             if (tomorrow == validTill) {
                 notifyTimetableValidity(1)
                 return
@@ -232,7 +243,10 @@         favouritesList.adapter.notifyDataSetChanged()
     }
 
     private fun getSuggestions() {
-        suggestions = (timetable.getStopSuggestions(context)).sorted() //+ timetable.getLineSuggestions()).sorted() //todo<p:v+1> + bike stations, train stations, &c
+        suggestions = if (timetable != null)
+            (timetable!!.getStopSuggestions(context)).sorted() //+ timetable.getLineSuggestions()).sorted() //todo<p:v+1> + bike stations, train stations, &c
+        else
+            emptyList()
     }
 
     private fun prepareListeners() {
@@ -295,7 +309,6 @@         Snackbar.make(findViewById(R.id.drawer_layout), message, Snackbar.LENGTH_LONG).show()
         if (result == TimetableDownloader.RESULT_FINISHED) {
             timetable = Timetable.getTimetable(this, true)
             getSuggestions()
-
             showValidityInDrawer()
         }
     }




diff --git a/app/src/main/java/ml/adamsprogs/bimba/activities/NoDbActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/activities/NoDbActivity.kt
index c266917efff4a9403be80eb110224bda659ae1f4..fa109fc9da1d81f858ddb6b1231f1dd153ad6cff 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/activities/NoDbActivity.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/activities/NoDbActivity.kt
@@ -31,6 +31,15 @@             registerReceiver(networkStateReceiver, filter)
             networkStateReceiver.addOnConnectivityChangeListener(this)
         } else
             downloadTimetable()
+
+        skip_button.setOnClickListener {
+            /*
+            val editor = getSharedPreferences("ml.adamsprogs.bimba.prefs", Context.MODE_PRIVATE).edit()
+            editor.putBoolean(Timetable.ONLY_ONLINE, true)
+            editor.apply()*/
+            startActivity(Intent(this, DashActivity::class.java))
+            finish()
+        }
     }
 
     override fun onResume() {




diff --git a/app/src/main/res/drawable/ic_skip.xml b/app/src/main/res/drawable/ic_skip.xml
new file mode 100644
index 0000000000000000000000000000000000000000..5248d32c9cdb23b266a221cb87153c4569215b06
--- /dev/null
+++ b/app/src/main/res/drawable/ic_skip.xml
@@ -0,0 +1,5 @@
+<vector android:autoMirrored="true" android:height="24dp"
+    android:viewportHeight="24.0" android:viewportWidth="24.0"
+    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="#FF000000" android:pathData="M10.09,15.59L11.5,17l5,-5 -5,-5 -1.41,1.41L12.67,11H3v2h9.67l-2.58,2.59zM19,3H5c-1.11,0 -2,0.9 -2,2v4h2V5h14v14H5v-4H3v4c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2z"/>
+</vector>