Sync fixes
This commit is contained in:
@@ -5,8 +5,10 @@ import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import org.json.JSONObject
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.exceptions.SyncApiException
|
||||
import org.koitharu.kotatsu.parsers.util.await
|
||||
import org.koitharu.kotatsu.parsers.util.parseJson
|
||||
import org.koitharu.kotatsu.parsers.util.removeSurrounding
|
||||
import org.koitharu.kotatsu.utils.ext.toRequestBody
|
||||
|
||||
class SyncAuthApi(
|
||||
@@ -24,7 +26,13 @@ class SyncAuthApi(
|
||||
.url("$baseUrl/auth")
|
||||
.post(body)
|
||||
.build()
|
||||
val response = okHttpClient.newCall(request).await().parseJson()
|
||||
return response.getString("token")
|
||||
val response = okHttpClient.newCall(request).await()
|
||||
if (response.isSuccessful) {
|
||||
return response.parseJson().getString("token")
|
||||
} else {
|
||||
val code = response.code
|
||||
val message = response.use { checkNotNull(it.body).string() }.removeSurrounding('"')
|
||||
throw SyncApiException(message, code)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.koitharu.kotatsu.sync.ui
|
||||
|
||||
import android.accounts.Account
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
|
||||
private const val ACCOUNT_KEY = "account"
|
||||
private const val ACTION_ACCOUNT_SYNC_SETTINGS = "android.settings.ACCOUNT_SYNC_SETTINGS"
|
||||
private const val EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args"
|
||||
|
||||
@Suppress("FunctionName")
|
||||
fun SyncSettingsIntent(account: Account): Intent {
|
||||
val args = Bundle(1)
|
||||
args.putParcelable(ACCOUNT_KEY, account)
|
||||
val intent = Intent(ACTION_ACCOUNT_SYNC_SETTINGS)
|
||||
intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args)
|
||||
return intent
|
||||
}
|
||||
Reference in New Issue
Block a user