Commit 5f6144e3 authored by Ricki Hirner's avatar Ricki Hirner 🐑
Browse files

Fix AddCalendarValidationFragment

parent 508bef25
Pipeline #174011980 passed with stage
in 3 minutes and 14 seconds
......@@ -21,7 +21,7 @@ android {
minSdkVersion 21
targetSdkVersion 29
versionCode 44
versionCode 46
versionName "1.8.8"
setProperty "archivesBaseName", "icsx5-" + getVersionCode() + "-" + getVersionName()
......
......@@ -3,6 +3,7 @@ package at.bitfire.icsdroid
import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.util.Log
import androidx.core.content.ContextCompat
import okhttp3.Credentials
import okhttp3.MediaType
......@@ -50,7 +51,7 @@ open class CalendarFetcher(
}
open fun onRedirect(httpCode: Int, target: URL) {
url = target
Log.v(Constants.TAG, "Get redirect $httpCode to $target")
// only network resources can be redirected
if (++redirectCount > MAX_REDIRECT_COUNT)
......@@ -60,7 +61,10 @@ open class CalendarFetcher(
if (url.protocol.equals("https", true) && !target.protocol.equals("https", true))
throw IOException("Received redirect from HTTPS to ${target.protocol}")
// update URL if this is a permanent redirect and we've never followed a temporary redirect
// update URL
url = target
// call onNewPermanentUrl if this is a permanent redirect and we've never followed a temporary redirect
if (!hasFollowedTempRedirect) {
when (httpCode) {
// 301: Moved Permanently, 308: Permanent Redirect
......
......@@ -77,6 +77,7 @@ class ProcessEventsTask(
}
override fun onNewPermanentUrl(target: URL) {
super.onNewPermanentUrl(target)
Log.i(Constants.TAG, "Got permanent redirect, saving new URL: $target")
calendar.updateUrl(target.toString())
}
......
......@@ -104,7 +104,7 @@ class AddCalendarValidationFragment: DialogFragment() {
Log.i(Constants.TAG, "Validating Webcal feed $originalUrl (authentication: $username)")
val info = ResourceInfo()
val info = ResourceInfo(originalUrl)
val downloader = object: CalendarFetcher(getApplication(), originalUrl) {
override fun onSuccess(data: InputStream, contentType: MediaType?, eTag: String?, lastModified: Long?) {
InputStreamReader(data, contentType?.charset() ?: Charsets.UTF_8).use { reader ->
......
......@@ -10,13 +10,13 @@ package at.bitfire.icsdroid.ui
import java.net.URL
class ResourceInfo {
data class ResourceInfo(
var url: URL? = null
var url: URL,
var exception: Exception? = null
var exception: Exception? = null,
var calendarName: String? = null
var eventsFound = -1
var calendarName: String? = null,
var eventsFound: Int = 0
}
)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment