aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt52
1 files changed, 12 insertions, 40 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt
index 38d55a17..d8f349a0 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt
@@ -1,12 +1,14 @@
package com.pitchedapps.frost.dbflow
+import com.pitchedapps.frost.facebook.FbCookie
+import com.pitchedapps.frost.utils.L
+import com.pitchedapps.frost.utils.Prefs
+import com.raizlabs.android.dbflow.annotation.ConflictAction
import com.raizlabs.android.dbflow.annotation.Database
-import com.raizlabs.android.dbflow.annotation.ForeignKey
import com.raizlabs.android.dbflow.annotation.PrimaryKey
import com.raizlabs.android.dbflow.annotation.Table
+import com.raizlabs.android.dbflow.kotlinextensions.*
import com.raizlabs.android.dbflow.structure.BaseModel
-import okhttp3.Cookie
-import java.io.Serializable
/**
* Created by Allan Wang on 2017-05-30.
@@ -18,43 +20,13 @@ object CookiesDb {
const val VERSION = 1
}
-//@Database(name = CookieDb.NAME, version = CookieDb.VERSION)
-//object CookieDb {
-// const val NAME = "Cookie"
-// const val VERSION = 1
-//}
+@Table(database = CookiesDb::class, allFields = true, primaryKeyConflict = ConflictAction.REPLACE)
+data class CookieModel(@PrimaryKey var id: Long = Prefs.userIdDefault, var cookie: String? = null) : BaseModel()
-@Table(database = CookiesDb::class, allFields = true)
-data class CookieModel(@PrimaryKey var name: String,
- var value: String,
- var expiresAt: Long,
- var domain: String,
- var path: String,
- var secure: Boolean,
- var httpOnly: Boolean) {
+fun loadFbCookie(): CookieModel? = (select from CookieModel::class where (CookieModel_Table.id eq Prefs.userId)).querySingle()
- constructor(cookie: Cookie) : this(cookie.name(), cookie.value(), cookie.expiresAt(), cookie.domain(), cookie.path(), cookie.secure(), cookie.httpOnly())
- constructor() : this("", "", 0L, "", "", false, false)
-
- fun toCookie(): Cookie {
- val builder = Cookie.Builder().name(name).value(value).expiresAt(expiresAt).domain(domain).path(path)
- if (secure) builder.secure()
- if (httpOnly) builder.httpOnly()
- return builder.build()
+fun saveFbCookie() {
+ CookieModel(FbCookie.userId, FbCookie.webCookie).async save {
+ L.d("Fb cookie saved")
}
-
- fun isSecure() = secure
- fun isHttpOnly() = httpOnly
-}
-
-//class CookieList(val cookies: List<Cookie>)
-//class CookieDbList(val cookies: List<CookieDb>)
-
-//@com.raizlabs.android.dbflow.annotation.TypeConverter
-//class CookieTypeConverter() : TypeConverter<CookieDbList, CookieList>() {
-// override fun getModelValue(data: CookieDbList): CookieList = CookieList(data.cookies.map { it.toCookie() })
-// override fun getDBValue(model: CookieList): CookieDbList = CookieDbList(model.cookies.map { CookieDb(it) })
-//}
-
-@Table(database = CookiesDb::class)
-data class Cookies(@PrimaryKey var url: String = "", @ForeignKey var cookie: CookieModel = CookieModel()) \ No newline at end of file
+} \ No newline at end of file