From 461425eb6054f18cea1990a4117fe8c78e888ddf Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 29 May 2017 19:47:52 -0700 Subject: Add icon tabs and webview observables --- .../kotlin/com/pitchedapps/frost/facebook/FBURL.kt | 15 ----- .../com/pitchedapps/frost/facebook/UrlData.kt | 65 ++++++++++++++++++++++ 2 files changed, 65 insertions(+), 15 deletions(-) delete mode 100644 app/src/main/kotlin/com/pitchedapps/frost/facebook/FBURL.kt create mode 100644 app/src/main/kotlin/com/pitchedapps/frost/facebook/UrlData.kt (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FBURL.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FBURL.kt deleted file mode 100644 index 489f12a7..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FBURL.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.pitchedapps.frost.facebook - -/** - * Created by Allan Wang on 2017-05-29. - */ -enum class FBURL(val url: String) { - FEED("https://touch.facebook.com/"), - PROFILE("https://touch.facebook.com/me/"), - BOOKMARKS("https://touch.facebook.com/bookmarks"), - SEARCH("https://touch.facebook.com/search"), - EVENTS("https://touch.facebook.com/events/upcoming"), - FRIEND_REQUESTS("https://touch.facebook.com/requests"), - MESSAGES("https://touch.facebook.com/messages"), - NOTIFICATIONS("https://touch.facebook.com/notifications"); -} \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/UrlData.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/UrlData.kt new file mode 100644 index 00000000..80972050 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/UrlData.kt @@ -0,0 +1,65 @@ +package com.pitchedapps.frost.facebook + +import android.content.Context +import android.support.annotation.StringRes +import com.mikepenz.community_material_typeface_library.CommunityMaterial +import com.mikepenz.google_material_typeface_library.GoogleMaterial +import com.mikepenz.iconics.typeface.IIcon +import com.mikepenz.material_design_iconic_typeface_library.MaterialDesignIconic +import com.pitchedapps.frost.R +import com.pitchedapps.frost.utils.RealmFiles +import com.pitchedapps.frost.utils.realm +import io.realm.Realm +import io.realm.RealmList +import io.realm.RealmObject +import io.realm.annotations.PrimaryKey + +/** + * Created by Allan Wang on 2017-05-29. + */ +enum class FbUrl(@StringRes val titleId: Int, val icon: IIcon, val url: String) { + 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"); + + fun tabInfo(c: Context) = FbTab(c.getString(titleId), icon, url) +} + +//BOOKMARKS("https://touch.facebook.com/bookmarks"), +//SEARCH("https://touch.facebook.com/search"), + +class FbTab(var title: String, var icon: IIcon, var url: String) { + constructor(realm: FbTabRealm) : this(realm.title, when (realm.iconCategory) { + 0 -> GoogleMaterial.Icon.valueOf(realm.iconString) + 1 -> CommunityMaterial.Icon.valueOf(realm.iconString) + 2 -> MaterialDesignIconic.Icon.valueOf(realm.iconString) + else -> GoogleMaterial.Icon.gmd_error + }, realm.url) +} + +open class FbTabRealm(var title: String, var iconCategory: Int, var iconString: String, @PrimaryKey var url: String) : RealmObject() { + constructor(tab: FbTab) : this(tab.title, when (tab.icon.typeface) { + is GoogleMaterial -> 0 + is CommunityMaterial -> 1 + is MaterialDesignIconic -> 2 + else -> -1 + }, tab.icon.toString(), tab.url) + + constructor() : this("", -1, "", "") +} + +fun List.save() { + val list = RealmList(*this.map { FbTabRealm(it) }.toTypedArray()) + realm(RealmFiles.TABS, Realm.Transaction { it.copyToRealmOrUpdate(list) }) +} + +fun loadFbTab(c: Context): List { + val realmList = mutableListOf() + realm(RealmFiles.TABS, Realm.Transaction { it.copyFromRealm(realmList) }) + if (realmList.isNotEmpty()) return realmList.map { FbTab(it) } + return FbUrl.values().map { it.tabInfo(c) } +} + -- cgit v1.2.3