Bimba.git

commit 7fce24f5504a2d7fdfb634b7a86dd534d00b5d41

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

fixed downloading timetable by https

%!v(PANIC=String method: strings: negative Repeat count)


diff --git a/app/src/main/java/ml/adamsprogs/bimba/datasources/TimetableDownloader.kt b/app/src/main/java/ml/adamsprogs/bimba/datasources/TimetableDownloader.kt
index 43abad683f14f6a998d82ad52533142e37288077..6f88678004f21be61fcca03fb9c0ec650d1f7a65 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/datasources/TimetableDownloader.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/datasources/TimetableDownloader.kt
@@ -38,25 +38,26 @@             }
 
             val localETag = prefs.getString("etag", "")
 
-            var httpCon: HttpURLConnection
+            val httpCon: HttpURLConnection
             try {
-                val sourceUrl = getDefaultSharedPreferences(this).getString(getString(R.string.key_timetable_source_url), getString(R.string.timetable_source_url))
-                sourceUrl.replace(Regex("^.*://", RegexOption.IGNORE_CASE), "")
+                var sourceUrl = getDefaultSharedPreferences(this).getString(getString(R.string.key_timetable_source_url), getString(R.string.timetable_source_url))
+                sourceUrl = sourceUrl.replace(Regex("^.*://", RegexOption.IGNORE_CASE), "")
+                sourceUrl = "https://$sourceUrl"
                 val url = URL(sourceUrl)
                 try {
                     httpCon = url.openConnection() as HttpsURLConnection
                     httpCon.addRequestProperty("If-None-Match", localETag)
                     httpCon.connect()
                 } catch (e: SSLException) {
-                    httpCon = url.openConnection() as HttpURLConnection
-                    httpCon.addRequestProperty("If-None-Match", localETag)
-                    httpCon.connect()
+                    sendResult(RESULT_NO_CONNECTIVITY)
+                    return
                 }
                 if (httpCon.responseCode == HttpsURLConnection.HTTP_NOT_MODIFIED) {
                     sendResult(RESULT_UP_TO_DATE)
                     return
                 }
                 if (httpCon.responseCode != HttpsURLConnection.HTTP_OK) {
+                    println(httpCon.responseMessage)
                     sendResult(RESULT_NO_CONNECTIVITY)
                     return
                 }




diff --git a/build.gradle b/build.gradle
index 098acc4f97a71d2164c9e7cff8395e12fb7e2c54..0668dc9970d10f9ac7d1a60344647da1ad8b46ef 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,7 +1,7 @@
 // Top-level build file where you can add configuration options common to all sub-projects/modules.
 
 buildscript {
-    ext.kotlin_version = '1.2.41'
+    ext.kotlin_version = '1.2.50'
     repositories {
         jcenter()
         maven { url 'https://maven.google.com' }
@@ -9,7 +9,7 @@         //maven { url 'https://dl.bintray.com/guardian/android' } // TooLargeTool
         google()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:3.1.2'
+        classpath 'com.android.tools.build:gradle:3.1.3'
         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
 
         // NOTE: Do not place your application dependencies here; they belong