diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook')
7 files changed, 24 insertions, 151 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt index 3316bb65..e44b872a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt @@ -1,7 +1,6 @@ package com.pitchedapps.frost.facebook import android.webkit.CookieManager -import com.pitchedapps.frost.dbflow.FB_URL_BASE import com.pitchedapps.frost.dbflow.loadFbCookie import com.pitchedapps.frost.dbflow.removeCookie import com.pitchedapps.frost.dbflow.saveFbCookie diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTabs.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTabs.kt new file mode 100644 index 00000000..d391d20f --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTabs.kt @@ -0,0 +1,24 @@ +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 + +enum class FbTab(@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?disable_interstitial=1&rdr"), + NOTIFICATIONS(R.string.notifications, MaterialDesignIconic.Icon.gmi_globe, "notifications"); + + val url = "$FB_URL_BASE$relativeUrl" +} + +const val FACEBOOK_COM = "facebook.com" +const val FB_URL_BASE = "https://m.facebook.com/"
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbToken.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbToken.kt deleted file mode 100644 index 22dc25f7..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbToken.kt +++ /dev/null @@ -1,13 +0,0 @@ -package com.pitchedapps.frost.facebook - -import com.facebook.AccessToken - -/** - * Created by Allan Wang on 2017-05-30. - */ -val token: String? - get() = AccessToken.getCurrentAccessToken()?.token - -fun setToken() { - -}
\ 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 deleted file mode 100644 index f82c041c..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/retro/FrostApi.kt +++ /dev/null @@ -1,64 +0,0 @@ -package com.pitchedapps.frost.facebook.retro - -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.* -import okhttp3.logging.HttpLoggingInterceptor -import retrofit2.Retrofit -import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory -import retrofit2.converter.gson.GsonConverterFactory -import java.io.File - -/** - * Created by Allan Wang on 2017-05-30. - * - * API for data retrieval - */ -object FrostApi { - - lateinit var frostApi: IFrost - - operator fun invoke(context: Context) { - val cacheDir = File(context.cacheDir, "responses") - val cacheSize = 5L * 1024 * 1024 //10MiB - val cache = Cache(cacheDir, cacheSize) - - 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) - - - //add logger and stetho last - - if (BuildConfig.DEBUG || BuildConfig.BUILD_TYPE == "releaseTest") { //log if not full release - client.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC)) - client.addNetworkInterceptor(StethoInterceptor()) - } - - val gson = GsonBuilder().setLenient() - - val retrofit = Retrofit.Builder() - .baseUrl("https://touch.facebook.com/") - .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io())) - .addConverterFactory(GsonConverterFactory.create(gson.create())) - .client(client.build()) - .build(); - frostApi = retrofit.create(IFrost::class.java) - } -}
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/retro/FrostData.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/retro/FrostData.kt deleted file mode 100644 index 07d686a7..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/retro/FrostData.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.pitchedapps.frost.facebook.retro - -/** - * Created by Allan Wang on 2017-05-30. - * - * Collection of Graph API outputs - */ -data class Me(val name: String, val id: String)
\ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/retro/FrostInterceptor.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/retro/FrostInterceptor.kt deleted file mode 100644 index f745aedf..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/retro/FrostInterceptor.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.pitchedapps.frost.facebook.retro - -import android.content.Context -import com.pitchedapps.frost.facebook.token -import com.pitchedapps.frost.utils.Utils -import okhttp3.Interceptor -import okhttp3.Response - -/** - * Created by Allan Wang on 2017-05-30. - */ -private val maxStale = 60 * 60 * 24 * 28 //maxAge to get from cache if online (4 weeks) -const val ACCESS_TOKEN = "access_token" - -class FrostInterceptor(val context: Context) : Interceptor { - - override fun intercept(chain: Interceptor.Chain): Response? { - val request = chain.request() - val requestBuilder = request.newBuilder() - val urlBase = request.url() - val urlWithToken = urlBase.newBuilder() - if (urlBase.queryParameter(ACCESS_TOKEN) == null && token != null) - urlWithToken.addQueryParameter(ACCESS_TOKEN, token) - requestBuilder.url(urlWithToken.build()) - if (!Utils.isNetworkAvailable(context)) requestBuilder.addHeader("Cache-Control", "public, only-if-cached, max-stale=" + maxStale) - return chain.proceed(requestBuilder.build()) - } - -}
\ No newline at end of file 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 deleted file mode 100644 index b9048fe0..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/retro/IFrost.kt +++ /dev/null @@ -1,36 +0,0 @@ -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 - -/** - * Created by Allan Wang on 2017-05-30. - */ -interface IFrost { - - @GET("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 |