diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook')
3 files changed, 39 insertions, 45 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/UrlData.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/UrlData.kt index d5f9db6e..c5c2a86b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/UrlData.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/UrlData.kt @@ -7,12 +7,7 @@ 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 +import com.pitchedapps.frost.dbflow.FbTab /** * Created by Allan Wang on 2017-05-29. @@ -30,37 +25,4 @@ enum class FbUrl(@StringRes val titleId: Int, val icon: IIcon, val url: String) } //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<FbTab>.save() { - val list = RealmList(*this.map { FbTabRealm(it) }.toTypedArray()) - realm(RealmFiles.TABS, Realm.Transaction { it.copyToRealmOrUpdate(list) }) -} - -fun loadFbTab(c: Context): List<FbTab> { - val realmList = mutableListOf<FbTabRealm>() - realm(RealmFiles.TABS, Realm.Transaction { it.copyFromRealm(realmList) }) - if (realmList.isNotEmpty()) return realmList.map { FbTab(it) } - return listOf(FbUrl.FEED, FbUrl.MESSAGES, FbUrl.NOTIFICATIONS).map { it.tabInfo(c) } -} - +//SEARCH("https://touch.facebook.com/search"),
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/retro/FrostApi.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/retro/FrostApi.kt index 746bf0df..f82c041c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/retro/FrostApi.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/retro/FrostApi.kt @@ -4,9 +4,9 @@ import android.content.Context import com.facebook.stetho.okhttp3.StethoInterceptor import com.google.gson.GsonBuilder import com.pitchedapps.frost.BuildConfig +import com.pitchedapps.frost.utils.L import io.reactivex.schedulers.Schedulers -import okhttp3.Cache -import okhttp3.OkHttpClient +import okhttp3.* import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory @@ -20,7 +20,7 @@ import java.io.File */ object FrostApi { - internal lateinit var frostApi: IFrost + lateinit var frostApi: IFrost operator fun invoke(context: Context) { val cacheDir = File(context.cacheDir, "responses") @@ -29,6 +29,18 @@ object FrostApi { val client = OkHttpClient.Builder() .addInterceptor(FrostInterceptor(context)) + .cookieJar(object : CookieJar { + override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) { + L.e("COOKIES") + L.e(url.toString()) + cookies.forEach { c -> L.e(c.toString()) } + } + + override fun loadForRequest(url: HttpUrl): List<Cookie> { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + }) .cache(cache) @@ -42,7 +54,7 @@ object FrostApi { val gson = GsonBuilder().setLenient() val retrofit = Retrofit.Builder() - .baseUrl("https://graph.facebook.com/") + .baseUrl("https://touch.facebook.com/") .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io())) .addConverterFactory(GsonConverterFactory.create(gson.create())) .client(client.build()) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/retro/IFrost.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/retro/IFrost.kt index 6c50fa74..b9048fe0 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/retro/IFrost.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/retro/IFrost.kt @@ -1,7 +1,11 @@ package com.pitchedapps.frost.facebook.retro import com.pitchedapps.frost.facebook.token +import com.pitchedapps.frost.utils.L +import okhttp3.ResponseBody import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response import retrofit2.http.GET import retrofit2.http.Query @@ -11,6 +15,22 @@ import retrofit2.http.Query interface IFrost { @GET("me") - fun me(@Query(ACCESS_TOKEN) accessToken: String? = token): Call<Me> + fun me(): Call<ResponseBody> + +} + +fun <T> Call<T>.enqueueFrost(success: (call: Call<T>, response: Response<T>) -> Unit) { + this.enqueue(object : Callback<T> { + override fun onFailure(call: Call<T>?, t: Throwable?) { + L.e("Frost enqueue error") + } + + override fun onResponse(call: Call<T>, response: Response<T>) { + if (response.isSuccessful && !call.isCanceled) + success.invoke(call, response) + else + L.e("Frost response received but not successful") + } + }) }
\ No newline at end of file |