mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
update null checks
This commit is contained in:
parent
d611006438
commit
5f217829b8
@ -48,11 +48,10 @@ fun setupCookies(cookieRaw: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeAllAccounts(context: Context?, callback: RepositoryCallback<Void?>?) {
|
fun removeAllAccounts(context: Context, callback: RepositoryCallback<Void?>?) {
|
||||||
val cookieStore = NET_COOKIE_MANAGER.cookieStore ?: return
|
NET_COOKIE_MANAGER.cookieStore.removeAll()
|
||||||
cookieStore.removeAll()
|
|
||||||
try {
|
try {
|
||||||
AccountRepository.getInstance(AccountDataSource.getInstance(context!!))
|
AccountRepository.getInstance(AccountDataSource.getInstance(context))
|
||||||
.deleteAllAccounts(callback)
|
.deleteAllAccounts(callback)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "setupCookies", e)
|
Log.e(TAG, "setupCookies", e)
|
||||||
@ -60,6 +59,7 @@ fun removeAllAccounts(context: Context?, callback: RepositoryCallback<Void?>?) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getUserIdFromCookie(cookies: String?): Long {
|
fun getUserIdFromCookie(cookies: String?): Long {
|
||||||
|
cookies ?: return 0
|
||||||
val dsUserId = getCookieValue(cookies, "ds_user_id") ?: return 0
|
val dsUserId = getCookieValue(cookies, "ds_user_id") ?: return 0
|
||||||
try {
|
try {
|
||||||
return dsUserId.toLong()
|
return dsUserId.toLong()
|
||||||
@ -69,12 +69,11 @@ fun getUserIdFromCookie(cookies: String?): Long {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCsrfTokenFromCookie(cookies: String?): String? {
|
fun getCsrfTokenFromCookie(cookies: String): String? {
|
||||||
return getCookieValue(cookies, "csrftoken")
|
return getCookieValue(cookies, "csrftoken")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCookieValue(cookies: String?, name: String): String? {
|
private fun getCookieValue(cookies: String, name: String): String? {
|
||||||
if (cookies == null) return null
|
|
||||||
val pattern = Pattern.compile("$name=(.+?);")
|
val pattern = Pattern.compile("$name=(.+?);")
|
||||||
val matcher = pattern.matcher(cookies)
|
val matcher = pattern.matcher(cookies)
|
||||||
return if (matcher.find()) {
|
return if (matcher.find()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user