aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/dbflow
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/dbflow')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt52
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/dbflow/FbTabsDb.kt27
2 files changed, 27 insertions, 52 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
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/FbTabsDb.kt b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/FbTabsDb.kt
index 662b97e8..067a07bf 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/FbTabsDb.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/FbTabsDb.kt
@@ -16,6 +16,7 @@ import com.raizlabs.android.dbflow.annotation.PrimaryKey
import com.raizlabs.android.dbflow.annotation.Table
import com.raizlabs.android.dbflow.kotlinextensions.from
import com.raizlabs.android.dbflow.sql.language.SQLite
+import com.raizlabs.android.dbflow.structure.BaseModel
/**
* Created by Allan Wang on 2017-05-30.
@@ -33,7 +34,7 @@ data class FbTab(val title: String, val icon: IIcon, val url: String)
data class FbTabModel(
var title: String = "",
@ForeignKey(saveForeignKeyModel = true, deleteForeignKeyModel = false) var icon: IIconModel = IIconModel(),
- @PrimaryKey var url: String = "") {
+ @PrimaryKey var url: String = "") : BaseModel() {
constructor(fbTab: FbTab) : this(fbTab.title, IIconModel(fbTab.icon), fbTab.url)
fun toFbTab() = FbTab(title, icon.toIIcon(), url)
@@ -56,15 +57,19 @@ data class IIconModel(var type: Int = -1, @PrimaryKey var name: String = "") {
}
}
-enum class FbUrl(@StringRes val titleId: Int, val icon: IIcon, val url: String) {
- LOGIN(R.string.feed, CommunityMaterial.Icon.cmd_newspaper, "https://www.facebook.com/v2.9/dialog/oauth?client_id=${FB_KEY}&redirect_uri=https://touch.facebook.com/&response_type=token,granted_scopes"),
- FEED(R.string.feed, CommunityMaterial.Icon.cmd_newspaper, "https://touch.facebook.com/"),
- PROFILE(R.string.profile, CommunityMaterial.Icon.cmd_account, "https://touch.facebook.com/me/"),
- EVENTS(R.string.events, GoogleMaterial.Icon.gmd_event, "https://touch.facebook.com/events/upcoming"),
- FRIENDS(R.string.friends, GoogleMaterial.Icon.gmd_people, "https://touch.facebook.com/friends/center/requests/"),
- MESSAGES(R.string.messages, MaterialDesignIconic.Icon.gmi_comments, "https://touch.facebook.com/messages"),
- NOTIFICATIONS(R.string.notifications, MaterialDesignIconic.Icon.gmi_globe, "https://touch.facebook.com/notifications");
+const val FB_URL_BASE = "https://m.facebook.com/"
+//const val FB_URL_BASE = "https://touch.facebook.com/"
+enum class FbUrl(@StringRes val titleId: Int, val icon: IIcon, relativeUrl: String) {
+// LOGIN(R.string.feed, CommunityMaterial.Icon.cmd_newspaper, "https://www.facebook.com/v2.9/dialog/oauth?client_id=${FB_KEY}&redirect_uri=https://touch.facebook.com/&response_type=token,granted_scopes"),
+ FEED(R.string.feed, CommunityMaterial.Icon.cmd_newspaper, ""),
+ PROFILE(R.string.profile, CommunityMaterial.Icon.cmd_account, "me"),
+ EVENTS(R.string.events, GoogleMaterial.Icon.gmd_event, "events/upcoming"),
+ FRIENDS(R.string.friends, GoogleMaterial.Icon.gmd_people, "friends/center/requests"),
+ MESSAGES(R.string.messages, MaterialDesignIconic.Icon.gmi_comments, "messages"),
+ NOTIFICATIONS(R.string.notifications, MaterialDesignIconic.Icon.gmi_globe, "notifications");
+
+ val url = "$FB_URL_BASE$relativeUrl"
fun tabInfo(c: Context) = FbTab(c.getString(titleId), icon, url)
}
@@ -79,7 +84,5 @@ fun loadFbTabs(c: Context): List<FbTab> {
}
fun List<FbTab>.saveAsync(c: Context) {
- map { FbTabModel(it) }.replace(c, FbTabsDb.NAME, {
- L.e("Saved successfully")
- })
+ map { FbTabModel(it) }.replace(c, FbTabsDb.NAME)
} \ No newline at end of file