diff --git a/app/build.gradle b/app/build.gradle
index 2c7c5bcc4..1b8feda78 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -6,6 +6,8 @@ apply plugin: 'kotlin-kapt'
apply plugin: 'com.getkeepsafe.dexcount'
apply plugin: 'com.gladed.androidgitversion'
+apply from: '../spotless.gradle'
+
android {
compileSdkVersion kau.targetSdk
buildToolsVersion kau.buildTools
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt
index c566aa052..7f3d6b62c 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/FrostApp.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost
import android.app.Activity
@@ -21,7 +37,11 @@ import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.glide.GlideApp
import com.pitchedapps.frost.services.scheduleNotifications
import com.pitchedapps.frost.services.setupNotificationChannels
-import com.pitchedapps.frost.utils.*
+import com.pitchedapps.frost.utils.BuildUtils
+import com.pitchedapps.frost.utils.FrostPglAdBlock
+import com.pitchedapps.frost.utils.L
+import com.pitchedapps.frost.utils.Prefs
+import com.pitchedapps.frost.utils.Showcase
import com.raizlabs.android.dbflow.config.DatabaseConfig
import com.raizlabs.android.dbflow.config.FlowConfig
import com.raizlabs.android.dbflow.config.FlowManager
@@ -30,10 +50,9 @@ import io.reactivex.exceptions.UndeliverableException
import io.reactivex.plugins.RxJavaPlugins
import java.net.SocketTimeoutException
import java.net.UnknownHostException
-import java.util.*
+import java.util.Random
import kotlin.reflect.KClass
-
/**
* Created by Allan Wang on 2017-05-28.
*/
@@ -46,10 +65,12 @@ class FrostApp : Application() {
// lateinit var refWatcher: RefWatcher
private fun FlowConfig.Builder.withDatabase(name: String, klass: KClass<*>) =
- addDatabaseConfig(DatabaseConfig.builder(klass.java)
- .databaseName(name)
- .modelNotifier(ContentResolverNotifier("${BuildConfig.APPLICATION_ID}.dbflow.provider"))
- .build())
+ addDatabaseConfig(
+ DatabaseConfig.builder(klass.java)
+ .databaseName(name)
+ .modelNotifier(ContentResolverNotifier("${BuildConfig.APPLICATION_ID}.dbflow.provider"))
+ .build()
+ )
override fun onCreate() {
if (!buildIsLollipopAndUp) { // not supported
@@ -57,11 +78,13 @@ class FrostApp : Application() {
return
}
- FlowManager.init(FlowConfig.Builder(this)
+ FlowManager.init(
+ FlowConfig.Builder(this)
.withDatabase(CookiesDb.NAME, CookiesDb::class)
.withDatabase(FbTabsDb.NAME, FbTabsDb::class)
.withDatabase(NotificationDb.NAME, NotificationDb::class)
- .build())
+ .build()
+ )
Showcase.initialize(this, "${BuildConfig.APPLICATION_ID}.showcase")
Prefs.initialize(this, "${BuildConfig.APPLICATION_ID}.prefs")
// if (LeakCanary.isInAnalyzerProcess(this)) return
@@ -95,9 +118,11 @@ class FrostApp : Application() {
val c = imageView.context
val request = GlideApp.with(c)
val old = request.load(uri).apply(RequestOptions().placeholder(placeholder))
- request.load(uri).apply(RequestOptions()
- .signature(ApplicationVersionSignature.obtain(c)))
- .thumbnail(old).into(imageView)
+ request.load(uri).apply(
+ RequestOptions()
+ .signature(ApplicationVersionSignature.obtain(c))
+ )
+ .thumbnail(old).into(imageView)
}
})
if (BuildConfig.DEBUG)
@@ -127,7 +152,6 @@ class FrostApp : Application() {
L.e(it) { "RxJava error" }
}
}
-
}
private fun initBugsnag() {
@@ -136,7 +160,7 @@ class FrostApp : Application() {
Bugsnag.disableExceptionHandler()
if (!BuildConfig.APPLICATION_ID.startsWith("com.pitchedapps.frost")) return
val version = BuildUtils.match(BuildConfig.VERSION_NAME)
- ?: return L.d { "Bugsnag disabled for ${BuildConfig.VERSION_NAME}" }
+ ?: return L.d { "Bugsnag disabled for ${BuildConfig.VERSION_NAME}" }
Bugsnag.enableExceptionHandler()
Bugsnag.setNotifyReleaseStages(*BuildUtils.getAllStages())
Bugsnag.setAppVersion(version.versionName)
@@ -157,5 +181,4 @@ class FrostApp : Application() {
}
}
}
-
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
index 034dabe22..14cc579f7 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost
import android.content.Intent
@@ -21,7 +37,8 @@ import com.pitchedapps.frost.utils.EXTRA_COOKIES
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.launchNewTask
-import java.util.*
+import java.util.ArrayList
+import java.util.IllegalFormatException
/**
* Created by Allan Wang on 2017-05-28.
@@ -46,7 +63,8 @@ class StartActivity : KauBaseActivity() {
if (Prefs.userId != -1L)
startActivity(intentBuilder = {
putParcelableArrayListExtra(EXTRA_COOKIES, cookies)
- flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
+ flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or
+ Intent.FLAG_ACTIVITY_SINGLE_TOP
})
else
launchNewTask(cookies)
@@ -57,11 +75,10 @@ class StartActivity : KauBaseActivity() {
} catch (e: Exception) {
showInvalidWebView()
}
-
}
private fun showInvalidWebView() =
- showInvalidView(R.string.error_webview)
+ showInvalidView(R.string.error_webview)
private fun showInvalidSdkView() {
val text = try {
@@ -73,12 +90,12 @@ class StartActivity : KauBaseActivity() {
}
private fun showInvalidView(textRes: Int) =
- showInvalidView(string(textRes))
+ showInvalidView(string(textRes))
private fun showInvalidView(text: String) {
setContentView(R.layout.activity_invalid)
findViewById(R.id.invalid_icon)
- .setIcon(GoogleMaterial.Icon.gmd_adb, -1, Color.WHITE)
+ .setIcon(GoogleMaterial.Icon.gmd_adb, -1, Color.WHITE)
findViewById(R.id.invalid_text).text = text
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt
index 4d333099e..a110071c6 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/AboutActivity.kt
@@ -1,17 +1,40 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.activities
-import androidx.constraintlayout.widget.ConstraintLayout
-import androidx.constraintlayout.widget.ConstraintSet
-import androidx.recyclerview.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
+import androidx.constraintlayout.widget.ConstraintLayout
+import androidx.constraintlayout.widget.ConstraintSet
+import androidx.recyclerview.widget.RecyclerView
import ca.allanwang.kau.about.AboutActivityBase
import ca.allanwang.kau.about.LibraryIItem
import ca.allanwang.kau.adapters.FastItemThemedAdapter
import ca.allanwang.kau.adapters.ThemableIItem
import ca.allanwang.kau.adapters.ThemableIItemDelegate
-import ca.allanwang.kau.utils.*
+import ca.allanwang.kau.utils.bindView
+import ca.allanwang.kau.utils.dimenPixelSize
+import ca.allanwang.kau.utils.resolveDrawable
+import ca.allanwang.kau.utils.startLink
+import ca.allanwang.kau.utils.string
+import ca.allanwang.kau.utils.toDrawable
+import ca.allanwang.kau.utils.toast
+import ca.allanwang.kau.utils.withMinAlpha
import com.mikepenz.aboutlibraries.Libs
import com.mikepenz.aboutlibraries.entity.Library
import com.mikepenz.aboutlibraries.entity.License
@@ -25,7 +48,6 @@ import com.pitchedapps.frost.R
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
-
/**
* Created by Allan Wang on 2017-06-26.
*/
@@ -42,21 +64,21 @@ class AboutActivity : AboutActivityBase(null, {
override fun getLibraries(libs: Libs): List {
val include = arrayOf(
- "AboutLibraries",
- "AndroidIconics",
- "androidin_appbillingv3",
- "androidslidinguppanel",
- "Crashlytics",
- "dbflow",
- "fastadapter",
- "glide",
- "Jsoup",
- "kau",
- "kotterknife",
- "materialdialogs",
- "materialdrawer",
- "rxjava",
- "subsamplingscaleimageview"
+ "AboutLibraries",
+ "AndroidIconics",
+ "androidin_appbillingv3",
+ "androidslidinguppanel",
+ "Crashlytics",
+ "dbflow",
+ "fastadapter",
+ "glide",
+ "Jsoup",
+ "kau",
+ "kotterknife",
+ "materialdialogs",
+ "materialdrawer",
+ "rxjava",
+ "subsamplingscaleimageview"
)
val l = libs.prepareLibraries(this, include, null, false, true, true)
@@ -136,11 +158,11 @@ class AboutActivity : AboutActivityBase(null, {
val c = itemView.context
val size = c.dimenPixelSize(R.dimen.kau_avatar_bounds)
images = arrayOf Unit>>(
- GoogleMaterial.Icon.gmd_arrow_downward to { c.startLink(R.string.github_downloads_url) },
- CommunityMaterial.Icon2.cmd_reddit to { c.startLink(R.string.reddit_url) },
- CommunityMaterial.Icon.cmd_github_circle to { c.startLink(R.string.github_url) },
- CommunityMaterial.Icon2.cmd_slack to { c.startLink(R.string.slack_url) },
- CommunityMaterial.Icon2.cmd_xda to { c.startLink(R.string.xda_url) }
+ GoogleMaterial.Icon.gmd_arrow_downward to { c.startLink(R.string.github_downloads_url) },
+ CommunityMaterial.Icon2.cmd_reddit to { c.startLink(R.string.reddit_url) },
+ CommunityMaterial.Icon.cmd_github_circle to { c.startLink(R.string.github_url) },
+ CommunityMaterial.Icon2.cmd_slack to { c.startLink(R.string.slack_url) },
+ CommunityMaterial.Icon2.cmd_xda to { c.startLink(R.string.xda_url) }
).mapIndexed { i, (icon, onClick) ->
ImageView(c).apply {
layoutParams = ViewGroup.LayoutParams(size, size)
@@ -154,10 +176,16 @@ class AboutActivity : AboutActivityBase(null, {
}
val set = ConstraintSet()
set.clone(container)
- set.createHorizontalChain(ConstraintSet.PARENT_ID, ConstraintSet.LEFT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT,
- images.map { it.id }.toIntArray(), null, ConstraintSet.CHAIN_SPREAD_INSIDE)
+ set.createHorizontalChain(ConstraintSet.PARENT_ID,
+ ConstraintSet.LEFT,
+ ConstraintSet.PARENT_ID,
+ ConstraintSet.RIGHT,
+ images.map { it.id }.toIntArray(),
+ null,
+ ConstraintSet.CHAIN_SPREAD_INSIDE
+ )
set.applyTo(container)
}
}
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseActivity.kt
index 3ac8c6ce3..08b5ab0c5 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseActivity.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.activities
import android.content.res.Configuration
@@ -80,7 +96,6 @@ abstract class BaseActivity : KauBaseActivity() {
//// disposeNetworkConnectivity()
// }
-
override fun onStop() {
if (this is VideoViewHolder) videoOnStop()
super.onStop()
@@ -90,4 +105,4 @@ abstract class BaseActivity : KauBaseActivity() {
super.onConfigurationChanged(newConfig)
if (this is VideoViewHolder) videoViewer?.updateLocation()
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
index 8f6bbacbb..20b5727fb 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.activities
import android.annotation.SuppressLint
@@ -8,25 +24,31 @@ import android.graphics.PointF
import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Bundle
-import androidx.annotation.StringRes
-import com.google.android.material.appbar.AppBarLayout
-import androidx.coordinatorlayout.widget.CoordinatorLayout
-import com.google.android.material.floatingactionbutton.FloatingActionButton
-import com.google.android.material.tabs.TabLayout
-import androidx.fragment.app.Fragment
-import androidx.fragment.app.FragmentPagerAdapter
-import androidx.appcompat.widget.Toolbar
import android.view.Menu
import android.view.MenuItem
import android.webkit.ValueCallback
import android.webkit.WebChromeClient
import android.webkit.WebView
import android.widget.FrameLayout
+import androidx.annotation.StringRes
+import androidx.appcompat.widget.Toolbar
+import androidx.coordinatorlayout.widget.CoordinatorLayout
+import androidx.fragment.app.Fragment
+import androidx.fragment.app.FragmentPagerAdapter
import ca.allanwang.kau.searchview.SearchItem
import ca.allanwang.kau.searchview.SearchView
import ca.allanwang.kau.searchview.SearchViewHolder
import ca.allanwang.kau.searchview.bindSearchView
-import ca.allanwang.kau.utils.*
+import ca.allanwang.kau.utils.bindView
+import ca.allanwang.kau.utils.fadeScaleTransition
+import ca.allanwang.kau.utils.restart
+import ca.allanwang.kau.utils.setIcon
+import ca.allanwang.kau.utils.setMenuIcons
+import ca.allanwang.kau.utils.showIf
+import ca.allanwang.kau.utils.string
+import ca.allanwang.kau.utils.tint
+import ca.allanwang.kau.utils.toast
+import ca.allanwang.kau.utils.withMinAlpha
import co.zsmb.materialdrawerkt.builders.Builder
import co.zsmb.materialdrawerkt.builders.accountHeader
import co.zsmb.materialdrawerkt.builders.drawer
@@ -35,6 +57,9 @@ import co.zsmb.materialdrawerkt.draweritems.badgeable.secondaryItem
import co.zsmb.materialdrawerkt.draweritems.divider
import co.zsmb.materialdrawerkt.draweritems.profile.profile
import co.zsmb.materialdrawerkt.draweritems.profile.profileSetting
+import com.google.android.material.appbar.AppBarLayout
+import com.google.android.material.floatingactionbutton.FloatingActionButton
+import com.google.android.material.tabs.TabLayout
import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.mikepenz.iconics.IconicsDrawable
import com.mikepenz.iconics.typeface.IIcon
@@ -57,7 +82,26 @@ import com.pitchedapps.frost.facebook.parsers.SearchParser
import com.pitchedapps.frost.facebook.profilePictureUrl
import com.pitchedapps.frost.fragments.BaseFragment
import com.pitchedapps.frost.fragments.WebFragment
-import com.pitchedapps.frost.utils.*
+import com.pitchedapps.frost.utils.ACTIVITY_SETTINGS
+import com.pitchedapps.frost.utils.EXTRA_COOKIES
+import com.pitchedapps.frost.utils.L
+import com.pitchedapps.frost.utils.MAIN_TIMEOUT_DURATION
+import com.pitchedapps.frost.utils.Prefs
+import com.pitchedapps.frost.utils.REQUEST_NAV
+import com.pitchedapps.frost.utils.REQUEST_REFRESH
+import com.pitchedapps.frost.utils.REQUEST_RESTART
+import com.pitchedapps.frost.utils.REQUEST_RESTART_APPLICATION
+import com.pitchedapps.frost.utils.REQUEST_SEARCH
+import com.pitchedapps.frost.utils.REQUEST_TEXT_ZOOM
+import com.pitchedapps.frost.utils.cookies
+import com.pitchedapps.frost.utils.frostChangelog
+import com.pitchedapps.frost.utils.frostEvent
+import com.pitchedapps.frost.utils.frostNavigationBar
+import com.pitchedapps.frost.utils.launchLogin
+import com.pitchedapps.frost.utils.launchNewTask
+import com.pitchedapps.frost.utils.launchWebOverlay
+import com.pitchedapps.frost.utils.materialDialogThemed
+import com.pitchedapps.frost.utils.setFrostColors
import com.pitchedapps.frost.views.BadgedIcon
import com.pitchedapps.frost.views.FrostVideoViewer
import com.pitchedapps.frost.views.FrostViewPager
@@ -68,8 +112,8 @@ import com.pitchedapps.frost.views.FrostViewPager
* Most of the logic that is unrelated to handling fragments
*/
abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
- FileChooserContract by FileChooserDelegate(),
- VideoViewHolder, SearchViewHolder {
+ FileChooserContract by FileChooserDelegate(),
+ VideoViewHolder, SearchViewHolder {
protected lateinit var adapter: SectionsPagerAdapter
override val frameWrapper: FrameLayout by bindView(R.id.frame_wrapper)
@@ -111,12 +155,14 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
Prefs.versionCode = BuildConfig.VERSION_CODE
if (!BuildConfig.DEBUG) {
frostChangelog()
- frostEvent("Version",
- "Version code" to BuildConfig.VERSION_CODE,
- "Prev version code" to Prefs.prevVersionCode,
- "Version name" to BuildConfig.VERSION_NAME,
- "Build type" to BuildConfig.BUILD_TYPE,
- "Frost id" to Prefs.frostId)
+ frostEvent(
+ "Version",
+ "Version code" to BuildConfig.VERSION_CODE,
+ "Prev version code" to Prefs.prevVersionCode,
+ "Version name" to BuildConfig.VERSION_NAME,
+ "Build type" to BuildConfig.BUILD_TYPE,
+ "Frost id" to Prefs.frostId
+ )
}
}
setupDrawer(savedInstanceState)
@@ -204,7 +250,9 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
identifier = -2L
}
profileSetting(nameRes = R.string.kau_add_account) {
- iconDrawable = IconicsDrawable(this@BaseMainActivity, GoogleMaterial.Icon.gmd_add).actionBar().paddingDp(5).color(Prefs.textColor)
+ iconDrawable =
+ IconicsDrawable(this@BaseMainActivity, GoogleMaterial.Icon.gmd_add).actionBar().paddingDp(5)
+ .color(Prefs.textColor)
textColor = Prefs.textColor.toLong()
identifier = -3L
}
@@ -225,8 +273,12 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
} else {
materialDialogThemed {
title(R.string.kau_logout)
- content(String.format(string(R.string.kau_logout_confirm_as_x), currentCookie.name
- ?: Prefs.userId.toString()))
+ content(
+ String.format(
+ string(R.string.kau_logout_confirm_as_x), currentCookie.name
+ ?: Prefs.userId.toString()
+ )
+ )
positiveText(R.string.kau_yes)
negativeText(R.string.kau_no)
onPositive { _, _ -> FbCookie.logout(this@BaseMainActivity) }
@@ -295,9 +347,11 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
toolbar.tint(Prefs.iconColor)
- setMenuIcons(menu, Prefs.iconColor,
- R.id.action_settings to GoogleMaterial.Icon.gmd_settings,
- R.id.action_search to GoogleMaterial.Icon.gmd_search)
+ setMenuIcons(
+ menu, Prefs.iconColor,
+ R.id.action_settings to GoogleMaterial.Icon.gmd_settings,
+ R.id.action_search to GoogleMaterial.Icon.gmd_search
+ )
searchViewBindIfNull {
bindSearchView(menu, R.id.action_search, Prefs.iconColor) {
textCallback = { query, searchView ->
@@ -309,7 +363,13 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
if (data != null) {
val items = data.mapTo(mutableListOf(), FrostSearch::toSearchItem)
if (items.isNotEmpty())
- items.add(SearchItem("${FbItem._SEARCH.url}?q=$query", string(R.string.show_all_results), iicon = null))
+ items.add(
+ SearchItem(
+ "${FbItem._SEARCH.url}?q=$query",
+ string(R.string.show_all_results),
+ iicon = null
+ )
+ )
searchViewCache[query] = items
searchView.results = items
}
@@ -332,7 +392,8 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
R.id.action_settings -> {
val intent = Intent(this, SettingsActivity::class.java)
intent.putParcelableArrayListExtra(EXTRA_COOKIES, cookies())
- val bundle = ActivityOptions.makeCustomAnimation(this, R.anim.kau_slide_in_right, R.anim.kau_fade_out).toBundle()
+ val bundle =
+ ActivityOptions.makeCustomAnimation(this, R.anim.kau_slide_in_right, R.anim.kau_fade_out).toBundle()
startActivityForResult(intent, ACTIVITY_SETTINGS, bundle)
}
else -> return super.onOptionsItemSelected(item)
@@ -340,7 +401,10 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
return true
}
- override fun openFileChooser(filePathCallback: ValueCallback?>, fileChooserParams: WebChromeClient.FileChooserParams) {
+ override fun openFileChooser(
+ filePathCallback: ValueCallback?>,
+ fileChooserParams: WebChromeClient.FileChooserParams
+ ) {
openMediaPicker(filePathCallback, fileChooserParams)
}
@@ -377,8 +441,10 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
super.onRestoreInstanceState(savedInstanceState)
adapter.forcedFallbacks.clear()
- adapter.forcedFallbacks.addAll(savedInstanceState.getStringArrayList(STATE_FORCE_FALLBACK)
- ?: emptyList())
+ adapter.forcedFallbacks.addAll(
+ savedInstanceState.getStringArrayList(STATE_FORCE_FALLBACK)
+ ?: emptyList()
+ )
}
override fun onResume() {
@@ -444,10 +510,12 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
override fun getItem(position: Int): Fragment {
val item = pages[position]
- return BaseFragment(item.fragmentCreator,
- forcedFallbacks.contains(item.name),
- item,
- position)
+ return BaseFragment(
+ item.fragmentCreator,
+ forcedFallbacks.contains(item.name),
+ item,
+ position
+ )
}
override fun getCount() = pages.size
@@ -455,12 +523,12 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
override fun getPageTitle(position: Int): CharSequence = getString(pages[position].titleId)
override fun getItemPosition(fragment: Any) =
- if (fragment !is BaseFragment)
- POSITION_UNCHANGED
- else if (fragment is WebFragment || fragment.valid)
- POSITION_UNCHANGED
- else
- POSITION_NONE
+ if (fragment !is BaseFragment)
+ POSITION_UNCHANGED
+ else if (fragment is WebFragment || fragment.valid)
+ POSITION_UNCHANGED
+ else
+ POSITION_NONE
}
override val lowerVideoPadding: PointF
@@ -469,4 +537,4 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
PointF(0f, toolbar.height.toFloat())
else
PointF(0f, 0f)
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt
index 3acbf7b3b..6257e6f16 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.activities
import android.app.Activity
@@ -9,9 +25,9 @@ import ca.allanwang.kau.internal.KauBaseActivity
import ca.allanwang.kau.utils.setIcon
import ca.allanwang.kau.utils.visible
import com.mikepenz.google_material_typeface_library.GoogleMaterial
+import com.pitchedapps.frost.R
import com.pitchedapps.frost.facebook.FbItem
import com.pitchedapps.frost.injectors.JsActions
-import com.pitchedapps.frost.R
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.createFreshDir
@@ -73,23 +89,22 @@ class DebugActivity : KauBaseActivity() {
val body = it[1] as? String
screenshot to body
}.observeOn(AndroidSchedulers.mainThread())
- .subscribe { (screenshot, body), err ->
- if (err != null) {
- L.e { "DebugActivity error ${err.message}" }
- setResult(Activity.RESULT_CANCELED)
- finish()
- return@subscribe
- }
- val intent = Intent()
- intent.putExtra(RESULT_URL, debug_webview.url)
- intent.putExtra(RESULT_SCREENSHOT, screenshot)
- if (body != null)
- intent.putExtra(RESULT_BODY, body)
- setResult(Activity.RESULT_OK, intent)
+ .subscribe { (screenshot, body), err ->
+ if (err != null) {
+ L.e { "DebugActivity error ${err.message}" }
+ setResult(Activity.RESULT_CANCELED)
finish()
+ return@subscribe
}
+ val intent = Intent()
+ intent.putExtra(RESULT_URL, debug_webview.url)
+ intent.putExtra(RESULT_SCREENSHOT, screenshot)
+ if (body != null)
+ intent.putExtra(RESULT_BODY, body)
+ setResult(Activity.RESULT_OK, intent)
+ finish()
+ }
}
-
}
override fun onSupportNavigateUp(): Boolean {
@@ -113,4 +128,4 @@ class DebugActivity : KauBaseActivity() {
else
super.onBackPressed()
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt
index 348b36b94..83f617ba0 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.activities
import android.content.Intent
@@ -5,16 +21,25 @@ import android.content.res.ColorStateList
import android.graphics.Color
import android.os.Bundle
import android.os.Environment
-import com.google.android.material.floatingactionbutton.FloatingActionButton
import android.view.View
import ca.allanwang.kau.internal.KauBaseActivity
import ca.allanwang.kau.logging.KauLoggerExtension
import ca.allanwang.kau.mediapicker.scanMedia
import ca.allanwang.kau.permissions.PERMISSION_WRITE_EXTERNAL_STORAGE
import ca.allanwang.kau.permissions.kauRequestPermissions
-import ca.allanwang.kau.utils.*
+import ca.allanwang.kau.utils.colorToForeground
+import ca.allanwang.kau.utils.fadeOut
+import ca.allanwang.kau.utils.fadeScaleTransition
+import ca.allanwang.kau.utils.isHidden
+import ca.allanwang.kau.utils.scaleXY
+import ca.allanwang.kau.utils.setIcon
+import ca.allanwang.kau.utils.tint
+import ca.allanwang.kau.utils.use
+import ca.allanwang.kau.utils.withAlpha
+import ca.allanwang.kau.utils.withMinAlpha
import com.davemorrissey.labs.subscaleview.ImageSource
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
+import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.mikepenz.iconics.typeface.IIcon
import com.pitchedapps.frost.R
@@ -23,7 +48,19 @@ import com.pitchedapps.frost.facebook.get
import com.pitchedapps.frost.facebook.requests.call
import com.pitchedapps.frost.facebook.requests.getFullSizedImageUrl
import com.pitchedapps.frost.facebook.requests.requestBuilder
-import com.pitchedapps.frost.utils.*
+import com.pitchedapps.frost.utils.ARG_COOKIE
+import com.pitchedapps.frost.utils.ARG_IMAGE_URL
+import com.pitchedapps.frost.utils.ARG_TEXT
+import com.pitchedapps.frost.utils.L
+import com.pitchedapps.frost.utils.Prefs
+import com.pitchedapps.frost.utils.createFreshFile
+import com.pitchedapps.frost.utils.frostSnackbar
+import com.pitchedapps.frost.utils.frostUriFromFile
+import com.pitchedapps.frost.utils.isIndirectImageUrl
+import com.pitchedapps.frost.utils.logFrostEvent
+import com.pitchedapps.frost.utils.materialDialogThemed
+import com.pitchedapps.frost.utils.sendFrostEmail
+import com.pitchedapps.frost.utils.setFrostColors
import com.sothree.slidinguppanel.SlidingUpPanelLayout
import kotlinx.android.synthetic.main.activity_image.*
import okhttp3.Response
@@ -34,7 +71,8 @@ import java.io.File
import java.io.FileFilter
import java.io.IOException
import java.text.SimpleDateFormat
-import java.util.*
+import java.util.Date
+import java.util.Locale
/**
* Created by Allan Wang on 2017-07-15.
@@ -94,8 +132,10 @@ class ImageActivity : KauBaseActivity() {
// a unique image identifier based on the id (if it exists), and its hash
private val imageHash: String by lazy {
- "${Math.abs(FB_IMAGE_ID_MATCHER.find(imageUrl)[1]?.hashCode()
- ?: 0)}_${Math.abs(imageUrl.hashCode())}"
+ "${Math.abs(
+ FB_IMAGE_ID_MATCHER.find(imageUrl)[1]?.hashCode()
+ ?: 0
+ )}_${Math.abs(imageUrl.hashCode())}"
}
override fun onCreate(savedInstanceState: Bundle?) {
@@ -105,11 +145,15 @@ class ImageActivity : KauBaseActivity() {
L.v { "Displaying image $imageUrl" }
val layout = if (!imageText.isNullOrBlank()) R.layout.activity_image else R.layout.activity_image_textless
setContentView(layout)
- image_container.setBackgroundColor(if (Prefs.blackMediaBg) Color.BLACK
- else Prefs.bgColor.withMinAlpha(222))
+ image_container.setBackgroundColor(
+ if (Prefs.blackMediaBg) Color.BLACK
+ else Prefs.bgColor.withMinAlpha(222)
+ )
image_text?.setTextColor(if (Prefs.blackMediaBg) Color.WHITE else Prefs.textColor)
- image_text?.setBackgroundColor((if (Prefs.blackMediaBg) Color.BLACK else Prefs.bgColor)
- .colorToForeground(0.2f).withAlpha(255))
+ image_text?.setBackgroundColor(
+ (if (Prefs.blackMediaBg) Color.BLACK else Prefs.bgColor)
+ .colorToForeground(0.2f).withAlpha(255)
+ )
image_text?.text = imageText
image_progress.tint(if (Prefs.blackMediaBg) Color.WHITE else Prefs.accentColor)
image_panel?.addPanelSlideListener(object : SlidingUpPanelLayout.SimplePanelSlideListener() {
@@ -208,16 +252,15 @@ class ImageActivity : KauBaseActivity() {
}
private fun getImageResponse(): Response = cookie.requestBuilder()
- .url(trueImageUrl)
- .get()
- .call()
- .execute()
-
+ .url(trueImageUrl)
+ .get()
+ .call()
+ .execute()
@Throws(IOException::class)
private fun downloadImageTo(file: File) {
val body = getImageResponse().body()
- ?: throw IOException("Failed to retrieve image body")
+ ?: throw IOException("Failed to retrieve image body")
body.byteStream().use { input ->
file.outputStream().use { output ->
input.copyTo(output)
@@ -272,7 +315,11 @@ class ImageActivity : KauBaseActivity() {
}
}
-internal enum class FabStates(val iicon: IIcon, val iconColor: Int = Prefs.iconColor, val backgroundTint: Int = Int.MAX_VALUE) {
+internal enum class FabStates(
+ val iicon: IIcon,
+ val iconColor: Int = Prefs.iconColor,
+ val backgroundTint: Int = Int.MAX_VALUE
+) {
ERROR(GoogleMaterial.Icon.gmd_error, Color.WHITE, Color.RED) {
override fun onClick(activity: ImageActivity) {
activity.materialDialogThemed {
@@ -334,5 +381,4 @@ internal enum class FabStates(val iicon: IIcon, val iconColor: Int = Prefs.iconC
}
abstract fun onClick(activity: ImageActivity)
-
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt
index c41229daa..a3ab61727 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt
@@ -1,31 +1,60 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.activities
import android.animation.ValueAnimator
import android.content.res.ColorStateList
import android.graphics.Color
import android.os.Bundle
-import androidx.fragment.app.Fragment
-import androidx.fragment.app.FragmentManager
-import androidx.fragment.app.FragmentPagerAdapter
-import androidx.viewpager.widget.ViewPager
import android.view.View
import android.view.WindowManager
import android.widget.Button
import android.widget.ImageButton
import android.widget.ImageView
+import androidx.fragment.app.Fragment
+import androidx.fragment.app.FragmentManager
+import androidx.fragment.app.FragmentPagerAdapter
+import androidx.viewpager.widget.ViewPager
import ca.allanwang.kau.internal.KauBaseActivity
import ca.allanwang.kau.ui.views.RippleCanvas
import ca.allanwang.kau.ui.widgets.InkPageIndicator
-import ca.allanwang.kau.utils.*
+import ca.allanwang.kau.utils.bindView
+import ca.allanwang.kau.utils.blendWith
+import ca.allanwang.kau.utils.color
+import ca.allanwang.kau.utils.fadeScaleTransition
+import ca.allanwang.kau.utils.navigationBarColor
+import ca.allanwang.kau.utils.postDelayed
+import ca.allanwang.kau.utils.scaleXY
+import ca.allanwang.kau.utils.setIcon
+import ca.allanwang.kau.utils.statusBarColor
import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.pitchedapps.frost.R
-import com.pitchedapps.frost.intro.*
+import com.pitchedapps.frost.intro.BaseIntroFragment
+import com.pitchedapps.frost.intro.IntroAccountFragment
+import com.pitchedapps.frost.intro.IntroFragmentEnd
+import com.pitchedapps.frost.intro.IntroFragmentTheme
+import com.pitchedapps.frost.intro.IntroFragmentWelcome
+import com.pitchedapps.frost.intro.IntroTabContextFragment
+import com.pitchedapps.frost.intro.IntroTabTouchFragment
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.cookies
import com.pitchedapps.frost.utils.launchNewTask
import org.jetbrains.anko.find
-
/**
* Created by Allan Wang on 2017-07-25.
*
@@ -43,12 +72,12 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.On
private var barHasNext = true
val fragments = listOf(
- IntroFragmentWelcome(),
- IntroFragmentTheme(),
- IntroAccountFragment(),
- IntroTabTouchFragment(),
- IntroTabContextFragment(),
- IntroFragmentEnd()
+ IntroFragmentWelcome(),
+ IntroFragmentTheme(),
+ IntroAccountFragment(),
+ IntroTabTouchFragment(),
+ IntroTabContextFragment(),
+ IntroFragmentEnd()
)
override fun onCreate(savedInstanceState: Bundle?) {
@@ -97,7 +126,6 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.On
page.alpha = 1f
page.translationX = 0f
}
-
}
fun finish(x: Float, y: Float) {
@@ -107,9 +135,11 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.On
postDelayed(1000) { finish() }
}
val lastView: View? = fragments.last().view
- arrayOf(skip, indicator, next,
- lastView?.find(R.id.intro_title),
- lastView?.find(R.id.intro_desc)).forEach {
+ arrayOf(
+ skip, indicator, next,
+ lastView?.find(R.id.intro_title),
+ lastView?.find(R.id.intro_desc)
+ ).forEach {
it?.animate()?.alpha(0f)?.setDuration(600)?.start()
}
if (Prefs.textColor != Color.WHITE) {
@@ -147,7 +177,6 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.On
}
override fun onPageScrollStateChanged(state: Int) {
-
}
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
@@ -162,16 +191,19 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.On
if (barHasNext == hasNext) return
barHasNext = hasNext
next.fadeScaleTransition {
- setIcon(if (barHasNext) GoogleMaterial.Icon.gmd_navigate_next else GoogleMaterial.Icon.gmd_done, color = Prefs.textColor)
+ setIcon(
+ if (barHasNext) GoogleMaterial.Icon.gmd_navigate_next else GoogleMaterial.Icon.gmd_done,
+ color = Prefs.textColor
+ )
}
skip.animate().scaleXY(if (barHasNext) 1f else 0f)
}
- class IntroPageAdapter(fm: FragmentManager, private val fragments: List) : FragmentPagerAdapter(fm) {
+ class IntroPageAdapter(fm: FragmentManager, private val fragments: List) :
+ FragmentPagerAdapter(fm) {
override fun getItem(position: Int): Fragment = fragments[position]
override fun getCount(): Int = fragments.size
}
-
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt
index 9c8a60aa1..8b5fe38da 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt
@@ -1,12 +1,28 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.activities
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.os.Handler
-import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
+import android.widget.ImageView
import androidx.appcompat.widget.AppCompatTextView
import androidx.appcompat.widget.Toolbar
-import android.widget.ImageView
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import ca.allanwang.kau.utils.bindView
import ca.allanwang.kau.utils.fadeIn
import ca.allanwang.kau.utils.fadeOut
@@ -24,14 +40,18 @@ import com.pitchedapps.frost.facebook.profilePictureUrl
import com.pitchedapps.frost.glide.FrostGlide
import com.pitchedapps.frost.glide.GlideApp
import com.pitchedapps.frost.glide.transform
-import com.pitchedapps.frost.utils.*
+import com.pitchedapps.frost.utils.L
+import com.pitchedapps.frost.utils.Showcase
+import com.pitchedapps.frost.utils.frostEvent
+import com.pitchedapps.frost.utils.launchNewTask
+import com.pitchedapps.frost.utils.logFrostEvent
+import com.pitchedapps.frost.utils.setFrostColors
import com.pitchedapps.frost.web.LoginWebView
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.BiFunction
import io.reactivex.subjects.SingleSubject
-
/**
* Created by Allan Wang on 2017-06-01.
*/
@@ -78,51 +98,62 @@ class LoginActivity : BaseActivity() {
private fun loadInfo(cookie: CookieModel) {
refresh = true
Single.zip>(
- profileSubject,
- usernameSubject,
- BiFunction(::Pair))
- .observeOn(AndroidSchedulers.mainThread()).subscribe { (foundImage, name) ->
- refresh = false
- if (!foundImage) {
- L.e { "Could not get profile photo; Invalid userId?" }
- L._i { cookie }
- }
- textview.text = String.format(getString(R.string.welcome), name)
- textview.fadeIn()
- frostEvent("Login", "success" to true)
- /*
- * The user may have logged into an account that is already in the database
- * We will let the db handle duplicates and load it now after the new account has been saved
- */
- loadFbCookiesAsync {
- val cookies = ArrayList(it)
- Handler().postDelayed({
- if (Showcase.intro)
- launchNewTask(cookies, true)
- else
- launchNewTask(cookies, true)
- }, 1000)
- }
- }.disposeOnDestroy()
+ profileSubject,
+ usernameSubject,
+ BiFunction(::Pair)
+ )
+ .observeOn(AndroidSchedulers.mainThread()).subscribe { (foundImage, name) ->
+ refresh = false
+ if (!foundImage) {
+ L.e { "Could not get profile photo; Invalid userId?" }
+ L._i { cookie }
+ }
+ textview.text = String.format(getString(R.string.welcome), name)
+ textview.fadeIn()
+ frostEvent("Login", "success" to true)
+ /*
+ * The user may have logged into an account that is already in the database
+ * We will let the db handle duplicates and load it now after the new account has been saved
+ */
+ loadFbCookiesAsync {
+ val cookies = ArrayList(it)
+ Handler().postDelayed({
+ if (Showcase.intro)
+ launchNewTask(cookies, true)
+ else
+ launchNewTask(cookies, true)
+ }, 1000)
+ }
+ }.disposeOnDestroy()
loadProfile(cookie.id)
loadUsername(cookie)
}
-
private fun loadProfile(id: Long) {
profileLoader.load(profilePictureUrl(id))
- .transform(FrostGlide.roundCorner).listener(object : RequestListener {
- override fun onResourceReady(resource: Drawable?, model: Any?, target: Target?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
- profileSubject.onSuccess(true)
- return false
- }
+ .transform(FrostGlide.roundCorner).listener(object : RequestListener {
+ override fun onResourceReady(
+ resource: Drawable?,
+ model: Any?,
+ target: Target?,
+ dataSource: DataSource?,
+ isFirstResource: Boolean
+ ): Boolean {
+ profileSubject.onSuccess(true)
+ return false
+ }
- override fun onLoadFailed(e: GlideException?, model: Any?, target: Target?, isFirstResource: Boolean): Boolean {
- e.logFrostEvent("Profile loading exception")
- profileSubject.onSuccess(false)
- return false
- }
- }).into(profile)
+ override fun onLoadFailed(
+ e: GlideException?,
+ model: Any?,
+ target: Target?,
+ isFirstResource: Boolean
+ ): Boolean {
+ e.logFrostEvent("Profile loading exception")
+ profileSubject.onSuccess(false)
+ return false
+ }
+ }).into(profile)
}
private fun loadUsername(cookie: CookieModel) {
@@ -146,5 +177,4 @@ class LoginActivity : BaseActivity() {
web.pauseTimers()
super.onPause()
}
-
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
index 2555fe5bb..d03c6496f 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
@@ -1,8 +1,24 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.activities
import android.os.Bundle
-import com.google.android.material.tabs.TabLayout
import androidx.viewpager.widget.ViewPager
+import com.google.android.material.tabs.TabLayout
import com.pitchedapps.frost.facebook.FbItem
import com.pitchedapps.frost.views.BadgedIcon
import io.reactivex.android.schedulers.AndroidSchedulers
@@ -36,19 +52,19 @@ class MainActivity : BaseMainActivity() {
super.onPageScrolled(position, positionOffset, positionOffsetPixels)
val delta = positionOffset * (255 - 128).toFloat()
tabsForEachView { tabPosition, view ->
- view.setAllAlpha(when (tabPosition) {
- position -> 255.0f - delta
- position + 1 -> 128.0f + delta
- else -> 128f
- })
+ view.setAllAlpha(
+ when (tabPosition) {
+ position -> 255.0f - delta
+ position + 1 -> 128.0f + delta
+ else -> 128f
+ }
+ )
}
}
})
viewPager.post { fragmentSubject.onNext(0); lastPosition = 0 } //trigger hook so title is set
-
}
-
private fun setupTabs() {
viewPager.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tabs))
tabs.addOnTabSelectedListener(object : TabLayout.ViewPagerOnTabSelectedListener(viewPager) {
@@ -63,31 +79,31 @@ class MainActivity : BaseMainActivity() {
}
})
headerBadgeObservable.throttleFirst(15, TimeUnit.SECONDS)
- .subscribeOn(Schedulers.newThread())
- .map { Jsoup.parse(it) }
- .filter { it.select("[data-sigil=count]").size >= 0 } //ensure headers exist
- .map {
- val feed = it.select("[data-sigil*=feed] [data-sigil=count]")
- val requests = it.select("[data-sigil*=requests] [data-sigil=count]")
- val messages = it.select("[data-sigil*=messages] [data-sigil=count]")
- val notifications = it.select("[data-sigil*=notifications] [data-sigil=count]")
- return@map arrayOf(feed, requests, messages, notifications).map { e -> e?.getOrNull(0)?.ownText() }
- }
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe { (feed, requests, messages, notifications) ->
- tabsForEachView { _, view ->
- when (view.iicon) {
- FbItem.FEED.icon -> view.badgeText = feed
- FbItem.FRIENDS.icon -> view.badgeText = requests
- FbItem.MESSAGES.icon -> view.badgeText = messages
- FbItem.NOTIFICATIONS.icon -> view.badgeText = notifications
- }
+ .subscribeOn(Schedulers.newThread())
+ .map { Jsoup.parse(it) }
+ .filter { it.select("[data-sigil=count]").size >= 0 } //ensure headers exist
+ .map {
+ val feed = it.select("[data-sigil*=feed] [data-sigil=count]")
+ val requests = it.select("[data-sigil*=requests] [data-sigil=count]")
+ val messages = it.select("[data-sigil*=messages] [data-sigil=count]")
+ val notifications = it.select("[data-sigil*=notifications] [data-sigil=count]")
+ return@map arrayOf(feed, requests, messages, notifications).map { e -> e?.getOrNull(0)?.ownText() }
+ }
+ .observeOn(AndroidSchedulers.mainThread())
+ .subscribe { (feed, requests, messages, notifications) ->
+ tabsForEachView { _, view ->
+ when (view.iicon) {
+ FbItem.FEED.icon -> view.badgeText = feed
+ FbItem.FRIENDS.icon -> view.badgeText = requests
+ FbItem.MESSAGES.icon -> view.badgeText = messages
+ FbItem.NOTIFICATIONS.icon -> view.badgeText = notifications
}
- }.disposeOnDestroy()
+ }
+ }.disposeOnDestroy()
adapter.pages.forEach {
tabs.addTab(tabs.newTab()
- .setCustomView(BadgedIcon(this).apply { iicon = it.icon }))
+ .setCustomView(BadgedIcon(this).apply { iicon = it.icon })
+ )
}
}
-
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/SelectorActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/SelectorActivity.kt
index 514af197a..2907bac6c 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/SelectorActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/SelectorActivity.kt
@@ -1,11 +1,27 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.activities
import android.os.Bundle
-import androidx.constraintlayout.widget.ConstraintLayout
+import android.view.View
import androidx.appcompat.widget.AppCompatTextView
+import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
-import android.view.View
import ca.allanwang.kau.utils.bindView
import com.mikepenz.fastadapter.FastAdapter
import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
@@ -47,4 +63,4 @@ class SelectorActivity : BaseActivity() {
background(container)
}
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt
index 7663b70f1..370474480 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.activities
import android.annotation.SuppressLint
@@ -12,14 +28,33 @@ import ca.allanwang.kau.kpref.activity.CoreAttributeContract
import ca.allanwang.kau.kpref.activity.KPrefActivity
import ca.allanwang.kau.kpref.activity.KPrefAdapterBuilder
import ca.allanwang.kau.ui.views.RippleCanvas
-import ca.allanwang.kau.utils.*
+import ca.allanwang.kau.utils.finishSlideOut
+import ca.allanwang.kau.utils.setMenuIcons
+import ca.allanwang.kau.utils.startActivityForResult
+import ca.allanwang.kau.utils.startLink
+import ca.allanwang.kau.utils.string
+import ca.allanwang.kau.utils.tint
+import ca.allanwang.kau.utils.withSceneTransitionAnimation
import com.mikepenz.community_material_typeface_library.CommunityMaterial
import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.pitchedapps.frost.R
import com.pitchedapps.frost.enums.Support
-import com.pitchedapps.frost.settings.*
-import com.pitchedapps.frost.utils.*
-
+import com.pitchedapps.frost.settings.getAppearancePrefs
+import com.pitchedapps.frost.settings.getBehaviourPrefs
+import com.pitchedapps.frost.settings.getDebugPrefs
+import com.pitchedapps.frost.settings.getExperimentalPrefs
+import com.pitchedapps.frost.settings.getFeedPrefs
+import com.pitchedapps.frost.settings.getNotificationPrefs
+import com.pitchedapps.frost.settings.sendDebug
+import com.pitchedapps.frost.utils.L
+import com.pitchedapps.frost.utils.Prefs
+import com.pitchedapps.frost.utils.REQUEST_RESTART
+import com.pitchedapps.frost.utils.cookies
+import com.pitchedapps.frost.utils.frostChangelog
+import com.pitchedapps.frost.utils.frostNavigationBar
+import com.pitchedapps.frost.utils.launchNewTask
+import com.pitchedapps.frost.utils.materialDialogThemed
+import com.pitchedapps.frost.utils.setFrostTheme
/**
* Created by Allan Wang on 2017-06-06.
@@ -146,7 +181,6 @@ class SettingsActivity : KPrefActivity() {
iicon = CommunityMaterial.Icon.cmd_android_debug_bridge
visible = { Prefs.debugSettings }
}
-
}
fun shouldRestartMain() {
@@ -179,9 +213,11 @@ class SettingsActivity : KPrefActivity() {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_settings, menu)
toolbar.tint(Prefs.iconColor)
- setMenuIcons(menu, Prefs.iconColor,
- R.id.action_email to GoogleMaterial.Icon.gmd_email,
- R.id.action_changelog to GoogleMaterial.Icon.gmd_info)
+ setMenuIcons(
+ menu, Prefs.iconColor,
+ R.id.action_email to GoogleMaterial.Icon.gmd_email,
+ R.id.action_changelog to GoogleMaterial.Icon.gmd_info
+ )
return true
}
@@ -201,4 +237,4 @@ class SettingsActivity : KPrefActivity() {
fun setFrostResult(flag: Int) {
resultFlag = resultFlag or flag
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/TabCustomizerActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/TabCustomizerActivity.kt
index 6222d98fd..7f6329406 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/TabCustomizerActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/TabCustomizerActivity.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.activities
import android.app.Activity
@@ -5,21 +21,18 @@ import android.content.res.ColorStateList
import android.os.Bundle
import android.view.View
import android.view.animation.AnimationUtils
-import android.widget.TextView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import ca.allanwang.kau.kotlin.lazyContext
-import ca.allanwang.kau.utils.bindView
import ca.allanwang.kau.utils.scaleXY
import ca.allanwang.kau.utils.setIcon
-import com.pitchedapps.frost.R
import ca.allanwang.kau.utils.withAlpha
-import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
import com.mikepenz.fastadapter_extensions.drag.ItemTouchCallback
import com.mikepenz.fastadapter_extensions.drag.SimpleDragCallback
import com.mikepenz.google_material_typeface_library.GoogleMaterial
+import com.pitchedapps.frost.R
import com.pitchedapps.frost.dbflow.TAB_COUNT
import com.pitchedapps.frost.dbflow.loadFbTabs
import com.pitchedapps.frost.dbflow.save
@@ -28,7 +41,7 @@ import com.pitchedapps.frost.iitems.TabIItem
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.setFrostColors
import kotlinx.android.synthetic.main.activity_tab_customizer.*
-import java.util.*
+import java.util.Collections
/**
* Created by Allan Wang on 26/11/17.
@@ -96,9 +109,9 @@ class TabCustomizerActivity : BaseActivity() {
override fun itemTouchDropped(oldPosition: Int, newPosition: Int) = Unit
}
-
private class TabDragCallback(
- directions: Int, itemTouchCallback: ItemTouchCallback
+ directions: Int,
+ itemTouchCallback: ItemTouchCallback
) : SimpleDragCallback(directions, itemTouchCallback) {
private var draggingView: TabIItem.ViewHolder? = null
@@ -122,7 +135,5 @@ class TabCustomizerActivity : BaseActivity() {
}
}
}
-
}
-
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt
index 6d930fff9..b706d467a 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.activities
import android.annotation.SuppressLint
@@ -5,25 +21,52 @@ import android.content.Intent
import android.graphics.PointF
import android.net.Uri
import android.os.Bundle
-import androidx.coordinatorlayout.widget.CoordinatorLayout
-import androidx.appcompat.widget.Toolbar
import android.view.Menu
import android.view.MenuItem
import android.webkit.ValueCallback
import android.webkit.WebChromeClient
import android.widget.FrameLayout
+import androidx.appcompat.widget.Toolbar
+import androidx.coordinatorlayout.widget.CoordinatorLayout
import ca.allanwang.kau.swipe.kauSwipeOnCreate
import ca.allanwang.kau.swipe.kauSwipeOnDestroy
-import ca.allanwang.kau.utils.*
+import ca.allanwang.kau.utils.bindView
+import ca.allanwang.kau.utils.copyToClipboard
+import ca.allanwang.kau.utils.darken
+import ca.allanwang.kau.utils.dpToPx
+import ca.allanwang.kau.utils.finishSlideOut
+import ca.allanwang.kau.utils.navigationBarColor
+import ca.allanwang.kau.utils.setMenuIcons
+import ca.allanwang.kau.utils.shareText
+import ca.allanwang.kau.utils.statusBarColor
+import ca.allanwang.kau.utils.tint
+import ca.allanwang.kau.utils.toDrawable
+import ca.allanwang.kau.utils.toast
+import ca.allanwang.kau.utils.withAlpha
import com.google.android.material.snackbar.BaseTransientBottomBar
import com.mikepenz.community_material_typeface_library.CommunityMaterial
import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.pitchedapps.frost.R
-import com.pitchedapps.frost.contracts.*
+import com.pitchedapps.frost.contracts.ActivityContract
+import com.pitchedapps.frost.contracts.FileChooserContract
+import com.pitchedapps.frost.contracts.FileChooserDelegate
+import com.pitchedapps.frost.contracts.FrostContentContainer
+import com.pitchedapps.frost.contracts.VideoViewHolder
import com.pitchedapps.frost.enums.OverlayContext
-import com.pitchedapps.frost.facebook.*
+import com.pitchedapps.frost.facebook.FB_URL_BASE
+import com.pitchedapps.frost.facebook.FbCookie
+import com.pitchedapps.frost.facebook.FbItem
+import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
+import com.pitchedapps.frost.facebook.formattedFbUrl
import com.pitchedapps.frost.services.FrostRunnable
-import com.pitchedapps.frost.utils.*
+import com.pitchedapps.frost.utils.ARG_URL
+import com.pitchedapps.frost.utils.ARG_USER_ID
+import com.pitchedapps.frost.utils.L
+import com.pitchedapps.frost.utils.Prefs
+import com.pitchedapps.frost.utils.Showcase
+import com.pitchedapps.frost.utils.frostSnackbar
+import com.pitchedapps.frost.utils.materialDialogThemed
+import com.pitchedapps.frost.utils.setFrostColors
import com.pitchedapps.frost.views.FrostContentWeb
import com.pitchedapps.frost.views.FrostVideoViewer
import com.pitchedapps.frost.views.FrostWebView
@@ -31,7 +74,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import okhttp3.HttpUrl
-
/**
* Created by Allan Wang on 2017-06-01.
*
@@ -103,8 +145,8 @@ class WebOverlayActivity : WebOverlayActivityBase(false)
@SuppressLint("Registered")
open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : BaseActivity(),
- ActivityContract, FrostContentContainer,
- VideoViewHolder, FileChooserContract by FileChooserDelegate() {
+ ActivityContract, FrostContentContainer,
+ VideoViewHolder, FileChooserContract by FileChooserDelegate() {
override val frameWrapper: FrameLayout by bindView(R.id.frame_wrapper)
val toolbar: Toolbar by bindView(R.id.overlay_toolbar)
@@ -156,9 +198,9 @@ open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : BaseAc
content.bind(this)
content.titleObservable
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe { toolbar.title = it }
- .disposeOnDestroy()
+ .observeOn(AndroidSchedulers.mainThread())
+ .subscribe { toolbar.title = it }
+ .disposeOnDestroy()
with(web) {
if (forceBasicAgent) //todo check; the webview already adds it dynamically
@@ -235,7 +277,10 @@ open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : BaseAc
kauSwipeOnDestroy()
}
- override fun openFileChooser(filePathCallback: ValueCallback?>, fileChooserParams: WebChromeClient.FileChooserParams) {
+ override fun openFileChooser(
+ filePathCallback: ValueCallback?>,
+ fileChooserParams: WebChromeClient.FileChooserParams
+ ) {
openMediaPicker(filePathCallback, fileChooserParams)
}
@@ -247,9 +292,11 @@ open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : BaseAc
menuInflater.inflate(R.menu.menu_web, menu)
overlayContext?.onMenuCreate(this, menu)
toolbar.tint(Prefs.iconColor)
- setMenuIcons(menu, Prefs.iconColor,
- R.id.action_share to CommunityMaterial.Icon2.cmd_share,
- R.id.action_copy_link to GoogleMaterial.Icon.gmd_content_copy)
+ setMenuIcons(
+ menu, Prefs.iconColor,
+ R.id.action_share to CommunityMaterial.Icon2.cmd_share,
+ R.id.action_copy_link to GoogleMaterial.Icon.gmd_content_copy
+ )
return true
}
@@ -270,5 +317,4 @@ open class WebOverlayActivityBase(private val forceBasicAgent: Boolean) : BaseAc
*/
override var videoViewer: FrostVideoViewer? = null
override val lowerVideoPadding: PointF = PointF(0f, 0f)
-
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/ActivityContract.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/ActivityContract.kt
index 1182e6098..2ce838713 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/contracts/ActivityContract.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/ActivityContract.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.contracts
import com.mikepenz.iconics.typeface.IIcon
@@ -25,4 +41,4 @@ interface MainActivityContract : ActivityContract, MainFabContract {
interface MainFabContract {
fun showFab(iicon: IIcon, clickEvent: () -> Unit)
fun hideFab()
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/DynamicUiContract.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/DynamicUiContract.kt
index 303c64b37..736ef72d4 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/contracts/DynamicUiContract.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/DynamicUiContract.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.contracts
/**
@@ -21,10 +37,8 @@ interface DynamicUiContract {
*/
fun reloadTextSize()
-
/**
* Change text size without propagation
*/
fun reloadTextSizeSelf()
-
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FileChooser.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FileChooser.kt
index 15165456a..73d5c56dc 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FileChooser.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FileChooser.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.contracts
import android.app.Activity
@@ -17,12 +33,19 @@ import com.pitchedapps.frost.utils.L
const val MEDIA_CHOOSER_RESULT = 67
interface FileChooserActivityContract {
- fun openFileChooser(filePathCallback: ValueCallback?>, fileChooserParams: WebChromeClient.FileChooserParams)
+ fun openFileChooser(
+ filePathCallback: ValueCallback?>,
+ fileChooserParams: WebChromeClient.FileChooserParams
+ )
}
interface FileChooserContract {
var filePathCallback: ValueCallback?>?
- fun Activity.openMediaPicker(filePathCallback: ValueCallback?>, fileChooserParams: WebChromeClient.FileChooserParams)
+ fun Activity.openMediaPicker(
+ filePathCallback: ValueCallback?>,
+ fileChooserParams: WebChromeClient.FileChooserParams
+ )
+
fun Activity.onActivityResultWeb(requestCode: Int, resultCode: Int, intent: Intent?): Boolean
}
@@ -30,7 +53,10 @@ class FileChooserDelegate : FileChooserContract {
override var filePathCallback: ValueCallback?>? = null
- override fun Activity.openMediaPicker(filePathCallback: ValueCallback?>, fileChooserParams: WebChromeClient.FileChooserParams) {
+ override fun Activity.openMediaPicker(
+ filePathCallback: ValueCallback?>,
+ fileChooserParams: WebChromeClient.FileChooserParams
+ ) {
kauRequestPermissions(PERMISSION_WRITE_EXTERNAL_STORAGE) { granted, _ ->
if (!granted) {
filePathCallback.onReceiveValue(null)
@@ -52,5 +78,4 @@ class FileChooserDelegate : FileChooserContract {
filePathCallback = null
return true
}
-
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt
index 613295e6f..50c2fe778 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.contracts
import android.view.View
@@ -23,7 +39,6 @@ interface FrostContentContainer {
* Update toolbar title
*/
fun setTitle(title: String)
-
}
/**
@@ -84,7 +99,6 @@ interface FrostContentParent : DynamicUiContract {
* For those cases, we will return false to stop it
*/
fun registerTransition(urlChanged: Boolean, animate: Boolean): Boolean
-
}
/**
@@ -147,5 +161,4 @@ interface FrostContentCore : DynamicUiContract {
* Signal destruction to release some content manually
*/
fun destroy()
-
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostObservables.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostObservables.kt
index 882b67a06..b3b93b669 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostObservables.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostObservables.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.contracts
import io.reactivex.subjects.BehaviorSubject
@@ -27,5 +43,4 @@ interface FrostObservables {
other.progressObservable = progressObservable
other.titleObservable = titleObservable
}
-
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostThemable.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostThemable.kt
index 3322f62e1..93d827a6c 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostThemable.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostThemable.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.contracts
import android.view.View
@@ -18,12 +34,11 @@ interface FrostThemable {
fun reloadTheme()
fun setTextColors(color: Int, vararg textViews: TextView?) =
- themeViews(color, *textViews) { setTextColor(it) }
+ themeViews(color, *textViews) { setTextColor(it) }
fun setBackgrounds(color: Int, vararg views: View?) =
- themeViews(color, *views) { setBackgroundColor(it) }
+ themeViews(color, *views) { setBackgroundColor(it) }
fun themeViews(color: Int, vararg views: T?, action: T.(Int) -> Unit) =
- views.filterNotNull().forEach { it.action(color) }
-
-}
\ No newline at end of file
+ views.filterNotNull().forEach { it.action(color) }
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/VideoViewHolder.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/VideoViewHolder.kt
index 13b6a7aa7..e749b0d38 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/contracts/VideoViewHolder.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/VideoViewHolder.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.contracts
import android.app.Activity
@@ -49,5 +65,4 @@ interface FrameWrapper {
setContentView(R.layout.activity_frame_wrapper)
frameWrapper.inflate(layoutRes, true)
}
-
}
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 1fe65d5ae..db3bf9734 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.dbflow
import android.os.Parcel
@@ -11,7 +27,13 @@ import com.raizlabs.android.dbflow.annotation.ConflictAction
import com.raizlabs.android.dbflow.annotation.Database
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.kotlinextensions.async
+import com.raizlabs.android.dbflow.kotlinextensions.delete
+import com.raizlabs.android.dbflow.kotlinextensions.eq
+import com.raizlabs.android.dbflow.kotlinextensions.from
+import com.raizlabs.android.dbflow.kotlinextensions.save
+import com.raizlabs.android.dbflow.kotlinextensions.select
+import com.raizlabs.android.dbflow.kotlinextensions.where
import com.raizlabs.android.dbflow.structure.BaseModel
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
@@ -30,7 +52,8 @@ object CookiesDb {
@PaperParcel
@Table(database = CookiesDb::class, allFields = true, primaryKeyConflict = ConflictAction.REPLACE)
-data class CookieModel(@PrimaryKey var id: Long = -1L, var name: String? = null, var cookie: String? = null) : BaseModel(), Parcelable {
+data class CookieModel(@PrimaryKey var id: Long = -1L, var name: String? = null, var cookie: String? = null) :
+ BaseModel(), Parcelable {
companion object {
@JvmField
val CREATOR = PaperParcelCookieModel.CREATOR
@@ -40,18 +63,22 @@ data class CookieModel(@PrimaryKey var id: Long = -1L, var name: String? = null,
override fun writeToParcel(dest: Parcel, flags: Int) = PaperParcelCookieModel.writeToParcel(this, dest, flags)
}
-fun loadFbCookie(id: Long): CookieModel? = (select from CookieModel::class where (CookieModel_Table.id eq id)).querySingle()
-fun loadFbCookie(name: String): CookieModel? = (select from CookieModel::class where (CookieModel_Table.name eq name)).querySingle()
+fun loadFbCookie(id: Long): CookieModel? =
+ (select from CookieModel::class where (CookieModel_Table.id eq id)).querySingle()
+
+fun loadFbCookie(name: String): CookieModel? =
+ (select from CookieModel::class where (CookieModel_Table.name eq name)).querySingle()
/**
* Loads cookies sorted by name
*/
fun loadFbCookiesAsync(callback: (cookies: List) -> Unit) {
- (select from CookieModel::class).orderBy(CookieModel_Table.name, true).async().queryListResultCallback { _, tResult -> callback(tResult) }.execute()
+ (select from CookieModel::class).orderBy(CookieModel_Table.name, true).async()
+ .queryListResultCallback { _, tResult -> callback(tResult) }.execute()
}
-fun loadFbCookiesSync(): List = (select from CookieModel::class).orderBy(CookieModel_Table.name, true).queryList()
-
+fun loadFbCookiesSync(): List =
+ (select from CookieModel::class).orderBy(CookieModel_Table.name, true).queryList()
inline fun saveFbCookie(cookie: CookieModel, crossinline callback: (() -> Unit) = {}) {
cookie.async save {
@@ -69,24 +96,24 @@ fun removeCookie(id: Long) {
}
inline fun CookieModel.fetchUsername(crossinline callback: (String) -> Unit): Disposable =
- ReactiveNetwork.checkInternetConnectivity().subscribeOn(Schedulers.io()).subscribe { yes, _ ->
- if (!yes) return@subscribe callback("")
- var result = ""
- try {
- result = frostJsoup(cookie, FbItem.PROFILE.url).title()
- L.d { "Fetch username found" }
- } catch (e: Exception) {
- if (e !is UnknownHostException)
- e.logFrostEvent("Fetch username failed")
- } finally {
- if (result.isBlank() && (name?.isNotBlank() == true)) {
- callback(name!!)
- return@subscribe
- }
- if (name != result) {
- name = result
- saveFbCookie(this@fetchUsername)
- }
- callback(result)
+ ReactiveNetwork.checkInternetConnectivity().subscribeOn(Schedulers.io()).subscribe { yes, _ ->
+ if (!yes) return@subscribe callback("")
+ var result = ""
+ try {
+ result = frostJsoup(cookie, FbItem.PROFILE.url).title()
+ L.d { "Fetch username found" }
+ } catch (e: Exception) {
+ if (e !is UnknownHostException)
+ e.logFrostEvent("Fetch username failed")
+ } finally {
+ if (result.isBlank() && (name?.isNotBlank() == true)) {
+ callback(name!!)
+ return@subscribe
}
+ if (name != result) {
+ name = result
+ saveFbCookie(this@fetchUsername)
+ }
+ callback(result)
}
+ }
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/DbUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/DbUtils.kt
index e4aef2a9b..740fef628 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/DbUtils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/DbUtils.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.dbflow
import android.content.Context
@@ -14,11 +30,10 @@ object DbUtils {
fun db(name: String) = FlowManager.getDatabase(name)
fun dbName(name: String) = "$name.db"
fun deleteDatabase(c: Context, name: String) = c.deleteDatabase(dbName(name))
-
}
inline fun List.replace(dbName: String) {
L.d { "Replacing $dbName.db" }
DbUtils.db(dbName).reset()
FastStoreModelTransaction.saveBuilder(FlowManager.getModelAdapter(T::class.java)).addAll(this).build()
-}
\ 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 827881e3f..9d330169e 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/FbTabsDb.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/FbTabsDb.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.dbflow
import com.pitchedapps.frost.facebook.FbItem
@@ -39,4 +55,4 @@ fun loadFbTabs(): List {
fun List.save() {
database().beginTransactionAsync(mapIndexed(::FbTabModel).fastSave().build()).execute()
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/NotificationDb.kt b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/NotificationDb.kt
index b61fc2187..a054d95ec 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/NotificationDb.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/NotificationDb.kt
@@ -1,8 +1,33 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.dbflow
import com.pitchedapps.frost.utils.L
-import com.raizlabs.android.dbflow.annotation.*
-import com.raizlabs.android.dbflow.kotlinextensions.*
+import com.raizlabs.android.dbflow.annotation.ConflictAction
+import com.raizlabs.android.dbflow.annotation.Database
+import com.raizlabs.android.dbflow.annotation.Migration
+import com.raizlabs.android.dbflow.annotation.PrimaryKey
+import com.raizlabs.android.dbflow.annotation.Table
+import com.raizlabs.android.dbflow.kotlinextensions.async
+import com.raizlabs.android.dbflow.kotlinextensions.eq
+import com.raizlabs.android.dbflow.kotlinextensions.from
+import com.raizlabs.android.dbflow.kotlinextensions.save
+import com.raizlabs.android.dbflow.kotlinextensions.select
+import com.raizlabs.android.dbflow.kotlinextensions.where
import com.raizlabs.android.dbflow.sql.SQLiteType
import com.raizlabs.android.dbflow.sql.migration.AlterTableMigration
import com.raizlabs.android.dbflow.structure.BaseModel
@@ -18,7 +43,8 @@ object NotificationDb {
}
@Migration(version = 2, database = NotificationDb::class)
-class NotificationMigration2(modelClass: Class) : AlterTableMigration(modelClass) {
+class NotificationMigration2(modelClass: Class) :
+ AlterTableMigration(modelClass) {
override fun onPreMigrate() {
super.onPreMigrate()
addColumn(SQLiteType.INTEGER, "epochIm")
@@ -27,11 +53,14 @@ class NotificationMigration2(modelClass: Class) : AlterTableM
}
@Table(database = NotificationDb::class, allFields = true, primaryKeyConflict = ConflictAction.REPLACE)
-data class NotificationModel(@PrimaryKey var id: Long = -1L,
- var epoch: Long = -1L,
- var epochIm: Long = -1L) : BaseModel()
+data class NotificationModel(
+ @PrimaryKey var id: Long = -1L,
+ var epoch: Long = -1L,
+ var epochIm: Long = -1L
+) : BaseModel()
-fun lastNotificationTime(id: Long): NotificationModel = (select from NotificationModel::class where (NotificationModel_Table.id eq id)).querySingle()
+fun lastNotificationTime(id: Long): NotificationModel =
+ (select from NotificationModel::class where (NotificationModel_Table.id eq id)).querySingle()
?: NotificationModel(id = id)
fun saveNotificationTime(notificationModel: NotificationModel, callback: (() -> Unit)? = null) {
@@ -40,4 +69,4 @@ fun saveNotificationTime(notificationModel: NotificationModel, callback: (() ->
L._d { notificationModel }
callback?.invoke()
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt b/app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt
index 6298f1f9c..f5009cc55 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/debugger/OfflineWebsite.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.debugger
import ca.allanwang.kau.logging.KauLoggerExtension
@@ -32,21 +48,23 @@ import java.util.zip.ZipOutputStream
*
* Inspired by Save for Offline
*/
-class OfflineWebsite(private val url: String,
- private val cookie: String = "",
- baseUrl: String? = null,
- private val html: String? = null,
- /**
- * Directory that holds all the files
- */
- val baseDir: File,
- private val userAgent: String = USER_AGENT_BASIC) {
+class OfflineWebsite(
+ private val url: String,
+ private val cookie: String = "",
+ baseUrl: String? = null,
+ private val html: String? = null,
+ /**
+ * Directory that holds all the files
+ */
+ val baseDir: File,
+ private val userAgent: String = USER_AGENT_BASIC
+) {
/**
* Supplied url without the queries
*/
private val baseUrl = (baseUrl ?: url.substringBefore("?")
- .substringBefore(".com")).trim('/')
+ .substringBefore(".com")).trim('/')
private val mainFile = File(baseDir, "index.html")
private val assetDir = File(baseDir, "assets")
@@ -67,11 +85,11 @@ class OfflineWebsite(private val url: String,
private val cssQueue = mutableSetOf()
private fun request(url: String) = Request.Builder()
- .header("Cookie", cookie)
- .header("User-Agent", userAgent)
- .url(url)
- .get()
- .call()
+ .header("Cookie", cookie)
+ .header("User-Agent", userAgent)
+ .url(url)
+ .get()
+ .call()
private val compositeDisposable = CompositeDisposable()
@@ -94,7 +112,6 @@ class OfflineWebsite(private val url: String,
return callback(false)
}
-
if (!assetDir.createFreshDir()) {
L.e { "Could not create ${assetDir.absolutePath}" }
return callback(false)
@@ -245,8 +262,10 @@ class OfflineWebsite(private val url: String,
}
})
- private inline fun String.downloadUrl(fallback: () -> T,
- action: (file: File, body: ResponseBody) -> T): T {
+ private inline fun String.downloadUrl(
+ fallback: () -> T,
+ action: (file: File, body: ResponseBody) -> T
+ ): T {
val file = File(assetDir, fileName())
if (!file.createNewFile()) {
@@ -289,11 +308,10 @@ class OfflineWebsite(private val url: String,
if (mapped != null) return mapped
val candidate = substringBefore("?").trim('/')
- .substringAfterLast("/").shorten()
+ .substringAfterLast("/").shorten()
val index = atomicInt.getAndIncrement()
-
var newUrl = "a${index}_$candidate"
/**
@@ -308,10 +326,10 @@ class OfflineWebsite(private val url: String,
}
private fun String.shorten() =
- if (length <= 10) this else substring(length - 10)
+ if (length <= 10) this else substring(length - 10)
private fun Set.clean(): List =
- filter(String::isNotBlank).filter { it.startsWith("http") }
+ filter(String::isNotBlank).filter { it.startsWith("http") }
private fun reset() {
cancelled = false
@@ -326,5 +344,4 @@ class OfflineWebsite(private val url: String,
compositeDisposable.dispose()
L.v { "Request cancelled" }
}
-
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/enums/FeedSort.kt b/app/src/main/kotlin/com/pitchedapps/frost/enums/FeedSort.kt
index d8a0f349e..7312399ea 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/enums/FeedSort.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/enums/FeedSort.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.enums
import androidx.annotation.StringRes
@@ -16,4 +32,4 @@ enum class FeedSort(@StringRes val textRes: Int, val item: FbItem) {
val values = values() //save one instance
operator fun invoke(index: Int) = values[index]
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/enums/MainActivityLayout.kt b/app/src/main/kotlin/com/pitchedapps/frost/enums/MainActivityLayout.kt
index 79b11752a..2d51b032a 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/enums/MainActivityLayout.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/enums/MainActivityLayout.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.enums
import com.pitchedapps.frost.R
@@ -7,23 +23,24 @@ import com.pitchedapps.frost.utils.Prefs
* Created by Allan Wang on 2017-08-19.
*/
enum class MainActivityLayout(
- val titleRes: Int,
- val layoutRes: Int,
- val backgroundColor: () -> Int,
- val iconColor: () -> Int) {
+ val titleRes: Int,
+ val layoutRes: Int,
+ val backgroundColor: () -> Int,
+ val iconColor: () -> Int
+) {
TOP_BAR(R.string.top_bar,
- R.layout.activity_main,
- { Prefs.headerColor },
- { Prefs.iconColor }),
+ R.layout.activity_main,
+ { Prefs.headerColor },
+ { Prefs.iconColor }),
BOTTOM_BAR(R.string.bottom_bar,
- R.layout.activity_main_bottom_tabs,
- { Prefs.bgColor },
- { Prefs.textColor });
+ R.layout.activity_main_bottom_tabs,
+ { Prefs.bgColor },
+ { Prefs.textColor });
companion object {
val values = values() //save one instance
operator fun invoke(index: Int) = values[index]
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/enums/OverlayContext.kt b/app/src/main/kotlin/com/pitchedapps/frost/enums/OverlayContext.kt
index f93a22291..d529db125 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/enums/OverlayContext.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/enums/OverlayContext.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.enums
import android.content.Context
@@ -52,12 +68,13 @@ enum class OverlayContext(private val menuItem: FrostMenuItem?) : EnumBundle.
+ */
package com.pitchedapps.frost.enums
import android.content.Context
@@ -21,4 +37,4 @@ enum class Support(@StringRes val title: Int) {
}
}
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/enums/Theme.kt b/app/src/main/kotlin/com/pitchedapps/frost/enums/Theme.kt
index 934dda07e..345aa88eb 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/enums/Theme.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/enums/Theme.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.enums
import android.graphics.Color
@@ -14,61 +30,63 @@ import com.pitchedapps.frost.utils.Prefs
const val FACEBOOK_BLUE = 0xff3b5998.toInt()
const val BLUE_LIGHT = 0xff5d86dd.toInt()
-enum class Theme(@StringRes val textRes: Int,
- val injector: InjectorContract,
- private val textColorGetter: () -> Int,
- private val accentColorGetter: () -> Int,
- private val backgroundColorGetter: () -> Int,
- private val headerColorGetter: () -> Int,
- private val iconColorGetter: () -> Int) {
+enum class Theme(
+ @StringRes val textRes: Int,
+ val injector: InjectorContract,
+ private val textColorGetter: () -> Int,
+ private val accentColorGetter: () -> Int,
+ private val backgroundColorGetter: () -> Int,
+ private val headerColorGetter: () -> Int,
+ private val iconColorGetter: () -> Int
+) {
DEFAULT(R.string.kau_default,
- JsActions.EMPTY,
- { 0xde000000.toInt() },
- { FACEBOOK_BLUE },
- { 0xfffafafa.toInt() },
- { FACEBOOK_BLUE },
- { Color.WHITE }),
+ JsActions.EMPTY,
+ { 0xde000000.toInt() },
+ { FACEBOOK_BLUE },
+ { 0xfffafafa.toInt() },
+ { FACEBOOK_BLUE },
+ { Color.WHITE }),
LIGHT(R.string.kau_light,
- CssAssets.MATERIAL_LIGHT,
- { 0xde000000.toInt() },
- { FACEBOOK_BLUE },
- { 0xfffafafa.toInt() },
- { FACEBOOK_BLUE },
- { Color.WHITE }),
+ CssAssets.MATERIAL_LIGHT,
+ { 0xde000000.toInt() },
+ { FACEBOOK_BLUE },
+ { 0xfffafafa.toInt() },
+ { FACEBOOK_BLUE },
+ { Color.WHITE }),
DARK(R.string.kau_dark,
- CssAssets.MATERIAL_DARK,
- { Color.WHITE },
- { BLUE_LIGHT },
- { 0xff303030.toInt() },
- { 0xff2e4b86.toInt() },
- { Color.WHITE }),
+ CssAssets.MATERIAL_DARK,
+ { Color.WHITE },
+ { BLUE_LIGHT },
+ { 0xff303030.toInt() },
+ { 0xff2e4b86.toInt() },
+ { Color.WHITE }),
AMOLED(R.string.kau_amoled,
- CssAssets.MATERIAL_AMOLED,
- { Color.WHITE },
- { BLUE_LIGHT },
- { Color.BLACK },
- { Color.BLACK },
- { Color.WHITE }),
+ CssAssets.MATERIAL_AMOLED,
+ { Color.WHITE },
+ { BLUE_LIGHT },
+ { Color.BLACK },
+ { Color.BLACK },
+ { Color.WHITE }),
GLASS(R.string.kau_glass,
- CssAssets.MATERIAL_GLASS,
- { Color.WHITE },
- { BLUE_LIGHT },
- { 0x80000000.toInt() },
- { 0xb3000000.toInt() },
- { Color.WHITE }),
+ CssAssets.MATERIAL_GLASS,
+ { Color.WHITE },
+ { BLUE_LIGHT },
+ { 0x80000000.toInt() },
+ { 0xb3000000.toInt() },
+ { Color.WHITE }),
CUSTOM(R.string.kau_custom,
- CssAssets.CUSTOM,
- { Prefs.customTextColor },
- { Prefs.customAccentColor },
- { Prefs.customBackgroundColor },
- { Prefs.customHeaderColor },
- { Prefs.customIconColor });
+ CssAssets.CUSTOM,
+ { Prefs.customTextColor },
+ { Prefs.customAccentColor },
+ { Prefs.customBackgroundColor },
+ { Prefs.customHeaderColor },
+ { Prefs.customIconColor });
val textColor: Int
get() = textColorGetter()
@@ -89,4 +107,4 @@ enum class Theme(@StringRes val textRes: Int,
val values = values() //save one instance
operator fun invoke(index: Int) = values[index]
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt
index 2b881d1c4..b6207a7b5 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.facebook
/**
@@ -12,9 +28,12 @@ fun profilePictureUrl(id: Long) = "https://graph.facebook.com/$id/picture?type=l
const val FB_LOGIN_URL = "${FB_URL_BASE}login"
const val FB_HOME_URL = "${FB_URL_BASE}home.php"
-const val USER_AGENT_FULL = "Mozilla/5.0 (Linux; Android 4.4.2; en-us; SAMSUNG SM-G900T Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.6 Chrome/28.0.1500.94 Mobile Safari/537.36"
-const val USER_AGENT_BASIC_OLD = "Mozilla/5.0 (Linux; Android 6.0) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.1.0.4633 Mobile Safari/537.10+"
-const val USER_AGENT_MESSENGER = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
+const val USER_AGENT_FULL =
+ "Mozilla/5.0 (Linux; Android 4.4.2; en-us; SAMSUNG SM-G900T Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.6 Chrome/28.0.1500.94 Mobile Safari/537.36"
+const val USER_AGENT_BASIC_OLD =
+ "Mozilla/5.0 (Linux; Android 6.0) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.1.0.4633 Mobile Safari/537.10+"
+const val USER_AGENT_MESSENGER =
+ "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
const val USER_AGENT_BASIC = USER_AGENT_MESSENGER
/**
@@ -27,4 +46,4 @@ const val WEB_LOAD_DELAY = 50L
* Note that transitions are also called from onFinish, so this value
* will never make a load slower than it is
*/
-const val WEB_COMMIT_LOAD_DELAY = 200L
\ No newline at end of file
+const val WEB_COMMIT_LOAD_DELAY = 200L
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 ab7e165a6..c65837128 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.facebook
import android.app.Activity
@@ -38,13 +54,13 @@ object FbCookie {
val cookies = cookie.split(";").map { Pair(it, SingleSubject.create()) }
cookies.forEach { (cookie, callback) -> setCookie(FB_URL_BASE, cookie) { callback.onSuccess(it) } }
Observable.zip(cookies.map { (_, callback) -> callback.toObservable() }) {}
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe {
- callback?.invoke()
- L.d { "Cookies set" }
- L._d { cookie }
- flush()
- }
+ .observeOn(AndroidSchedulers.mainThread())
+ .subscribe {
+ callback?.invoke()
+ L.d { "Cookies set" }
+ L._d { cookie }
+ flush()
+ }
}
}
}
@@ -132,4 +148,4 @@ object FbCookie {
}
} else callback()
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt
index 2f0e4e227..723ed4500 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.facebook
import androidx.annotation.StringRes
@@ -15,10 +31,10 @@ import com.pitchedapps.frost.utils.EnumBundleCompanion
import com.pitchedapps.frost.utils.EnumCompanion
enum class FbItem(
- @StringRes val titleId: Int,
- val icon: IIcon,
- relativeUrl: String,
- val fragmentCreator: () -> BaseFragment = ::WebFragment
+ @StringRes val titleId: Int,
+ val icon: IIcon,
+ relativeUrl: String,
+ val fragmentCreator: () -> BaseFragment = ::WebFragment
) : EnumBundle {
ACTIVITY_LOG(R.string.activity_log, GoogleMaterial.Icon.gmd_list, "me/allactivity"),
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbRegex.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbRegex.kt
index 9b29d009b..2c987a485 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbRegex.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbRegex.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.facebook
/**
@@ -29,4 +45,3 @@ val FB_IMAGE_ID_MATCHER: Regex = Regex("fbcdn.*?/[0-9]+_([0-9]+)_")
val FB_REDIRECT_URL_MATCHER: Regex = Regex("url=(.*?fbcdn.*?)\"")
operator fun MatchResult?.get(groupIndex: Int) = this?.groupValues?.get(groupIndex)
-
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt
index 62675df69..2c171762c 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.facebook
import com.pitchedapps.frost.utils.L
@@ -91,13 +107,13 @@ class FbUrlFormatter(url: String) {
* That shouldn't break anything
*/
val discardable = arrayOf(
- "http://lm.facebook.com/l.php?u=",
- "https://lm.facebook.com/l.php?u=",
- "http://m.facebook.com/l.php?u=",
- "https://m.facebook.com/l.php?u=",
- "http://touch.facebook.com/l.php?u=",
- "https://touch.facebook.com/l.php?u=",
- VIDEO_REDIRECT
+ "http://lm.facebook.com/l.php?u=",
+ "https://lm.facebook.com/l.php?u=",
+ "http://m.facebook.com/l.php?u=",
+ "https://m.facebook.com/l.php?u=",
+ "http://touch.facebook.com/l.php?u=",
+ "https://touch.facebook.com/l.php?u=",
+ VIDEO_REDIRECT
)
/**
@@ -108,13 +124,13 @@ class FbUrlFormatter(url: String) {
val discardableQueries = arrayOf("ref", "refid", "SharedWith")
val converter = listOf(
- "\\3C " to "%3C", "\\3E " to "%3E", "\\23 " to "%23", "\\25 " to "%25",
- "\\7B " to "%7B", "\\7D " to "%7D", "\\7C " to "%7C", "\\5C " to "%5C",
- "\\5E " to "%5E", "\\7E " to "%7E", "\\5B " to "%5B", "\\5D " to "%5D",
- "\\60 " to "%60", "\\3B " to "%3B", "\\2F " to "%2F", "\\3F " to "%3F",
- "\\3A " to "%3A", "\\40 " to "%40", "\\3D " to "%3D", "\\26 " to "%26",
- "\\24 " to "%24", "\\2B " to "%2B", "\\22 " to "%22", "\\2C " to "%2C",
- "\\20 " to "%20"
+ "\\3C " to "%3C", "\\3E " to "%3E", "\\23 " to "%23", "\\25 " to "%25",
+ "\\7B " to "%7B", "\\7D " to "%7D", "\\7C " to "%7C", "\\5C " to "%5C",
+ "\\5E " to "%5E", "\\7E " to "%7E", "\\5B " to "%5B", "\\5D " to "%5D",
+ "\\60 " to "%60", "\\3B " to "%3B", "\\2F " to "%2F", "\\3F " to "%3F",
+ "\\3A " to "%3A", "\\40 " to "%40", "\\3D " to "%3D", "\\26 " to "%26",
+ "\\24 " to "%24", "\\2B " to "%2B", "\\22 " to "%22", "\\2C " to "%2C",
+ "\\20 " to "%20"
)
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt
index 3d5c5bce9..5709bb9f8 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.facebook.parsers
import com.pitchedapps.frost.dbflow.CookieModel
@@ -54,7 +70,6 @@ interface FrostParser {
* Call parsing with given data
*/
fun parseFromData(cookie: String?, text: String): ParseResponse?
-
}
const val FALLBACK_TIME_MOD = 1000000
@@ -92,7 +107,7 @@ internal abstract class FrostParserBase(private val redirectToText:
}
final override fun parseFromUrl(cookie: String?, url: String): ParseResponse? =
- parse(cookie, frostJsoup(cookie, url))
+ parse(cookie, frostJsoup(cookie, url))
override fun parse(cookie: String?, document: Document): ParseResponse? {
cookie ?: return null
@@ -109,17 +124,17 @@ internal abstract class FrostParserBase(private val redirectToText:
* Returns the formatted url, or an empty string if nothing was found
*/
protected fun Element.getInnerImgStyle(): String? =
- select("i.img[style*=url]").getStyleUrl()
+ select("i.img[style*=url]").getStyleUrl()
protected fun Elements.getStyleUrl(): String? =
- FB_CSS_URL_MATCHER.find(attr("style"))[1]?.formattedFbUrl
+ FB_CSS_URL_MATCHER.find(attr("style"))[1]?.formattedFbUrl
protected open fun textToDoc(text: String): Document? =
- if (!redirectToText) Jsoup.parse(text)
- else throw RuntimeException("${this::class.java.simpleName} requires text redirect but did not implement textToDoc")
+ if (!redirectToText) Jsoup.parse(text)
+ else throw RuntimeException("${this::class.java.simpleName} requires text redirect but did not implement textToDoc")
protected fun parseLink(element: Element?): FrostLink? {
val a = element?.getElementsByTag("a")?.first() ?: return null
return FrostLink(a.text(), a.attr("href"))
}
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt
index 27b731bc1..f05c42e9c 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt
@@ -1,7 +1,27 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.facebook.parsers
import com.pitchedapps.frost.dbflow.CookieModel
-import com.pitchedapps.frost.facebook.*
+import com.pitchedapps.frost.facebook.FB_EPOCH_MATCHER
+import com.pitchedapps.frost.facebook.FB_MESSAGE_NOTIF_ID_MATCHER
+import com.pitchedapps.frost.facebook.FbItem
+import com.pitchedapps.frost.facebook.formattedFbUrl
+import com.pitchedapps.frost.facebook.get
import com.pitchedapps.frost.services.NotificationContent
import com.pitchedapps.frost.utils.L
import org.apache.commons.text.StringEscapeUtils
@@ -19,12 +39,12 @@ import org.jsoup.nodes.Element
object MessageParser : FrostParser by MessageParserImpl() {
fun queryUser(cookie: String?, name: String) = parseFromUrl(cookie, "${FbItem.MESSAGES.url}/?q=$name")
-
}
-data class FrostMessages(val threads: List,
- val seeMore: FrostLink?,
- val extraLinks: List
+data class FrostMessages(
+ val threads: List,
+ val seeMore: FrostLink?,
+ val extraLinks: List
) : ParseNotification {
override fun toString() = StringBuilder().apply {
append("FrostMessages {\n")
@@ -35,19 +55,19 @@ data class FrostMessages(val threads: List,
}.toString()
override fun getUnreadNotifications(data: CookieModel) =
- threads.asSequence().filter(FrostThread::unread).map {
- with(it) {
- NotificationContent(
- data = data,
- id = id,
- href = url,
- title = title,
- text = content ?: "",
- timestamp = time,
- profileUrl = img
- )
- }
- }.toList()
+ threads.asSequence().filter(FrostThread::unread).map {
+ with(it) {
+ NotificationContent(
+ data = data,
+ id = id,
+ href = url,
+ title = title,
+ text = content ?: "",
+ timestamp = time,
+ profileUrl = img
+ )
+ }
+ }.toList()
}
/**
@@ -58,14 +78,16 @@ data class FrostMessages(val threads: List,
* [unread] true if image is unread, false otherwise
* [content] optional string for thread
*/
-data class FrostThread(val id: Long,
- val img: String?,
- val title: String,
- val time: Long,
- val url: String,
- val unread: Boolean,
- val content: String?,
- val contentImgUrl: String?)
+data class FrostThread(
+ val id: Long,
+ val img: String?,
+ val title: String,
+ val time: Long,
+ val url: String,
+ val unread: Boolean,
+ val content: String?,
+ val contentImgUrl: String?
+)
private class MessageParserImpl : FrostParserBase(true) {
@@ -92,11 +114,12 @@ private class MessageParserImpl : FrostParserBase(true) {
override fun parseImpl(doc: Document): FrostMessages? {
val threadList = doc.getElementById("threadlist_rows") ?: return null
- val threads: List = threadList.getElementsByAttributeValueMatching("id", ".*${FB_MESSAGE_NOTIF_ID_MATCHER.pattern}.*")
+ val threads: List =
+ threadList.getElementsByAttributeValueMatching("id", ".*${FB_MESSAGE_NOTIF_ID_MATCHER.pattern}.*")
.mapNotNull(this::parseMessage)
val seeMore = parseLink(doc.getElementById("see_older_threads"))
val extraLinks = threadList.nextElementSibling().select("a")
- .mapNotNull(this::parseLink)
+ .mapNotNull(this::parseLink)
return FrostMessages(threads, seeMore, extraLinks)
}
@@ -106,21 +129,20 @@ private class MessageParserImpl : FrostParserBase(true) {
val epoch = FB_EPOCH_MATCHER.find(abbr.attr("data-store"))[1]?.toLongOrNull() ?: -1L
//fetch id
val id = FB_MESSAGE_NOTIF_ID_MATCHER.find(element.id())[1]?.toLongOrNull()
- ?: System.currentTimeMillis() % FALLBACK_TIME_MOD
+ ?: System.currentTimeMillis() % FALLBACK_TIME_MOD
val snippet = element.select("span.snippet").firstOrNull()
val content = snippet?.text()?.trim()
val contentImg = snippet?.select("i[style*=url]")?.getStyleUrl()
val img = element.getInnerImgStyle()
return FrostThread(
- id = id,
- img = img,
- title = a.text(),
- time = epoch,
- url = a.attr("href").formattedFbUrl,
- unread = !element.hasClass("acw"),
- content = content,
- contentImgUrl = contentImg
+ id = id,
+ img = img,
+ title = a.text(),
+ time = epoch,
+ url = a.attr("href").formattedFbUrl,
+ unread = !element.hasClass("acw"),
+ content = content,
+ contentImgUrl = contentImg
)
}
-
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/NotifParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/NotifParser.kt
index 8aa8e7067..b8aa899b8 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/NotifParser.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/NotifParser.kt
@@ -1,7 +1,27 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.facebook.parsers
import com.pitchedapps.frost.dbflow.CookieModel
-import com.pitchedapps.frost.facebook.*
+import com.pitchedapps.frost.facebook.FB_EPOCH_MATCHER
+import com.pitchedapps.frost.facebook.FB_NOTIF_ID_MATCHER
+import com.pitchedapps.frost.facebook.FbItem
+import com.pitchedapps.frost.facebook.formattedFbUrl
+import com.pitchedapps.frost.facebook.get
import com.pitchedapps.frost.services.NotificationContent
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
@@ -13,8 +33,8 @@ import org.jsoup.nodes.Element
object NotifParser : FrostParser by NotifParserImpl()
data class FrostNotifs(
- val notifs: List,
- val seeMore: FrostLink?
+ val notifs: List,
+ val seeMore: FrostLink?
) : ParseNotification {
override fun toString() = StringBuilder().apply {
append("FrostNotifs {\n")
@@ -24,19 +44,19 @@ data class FrostNotifs(
}.toString()
override fun getUnreadNotifications(data: CookieModel) =
- notifs.asSequence().filter(FrostNotif::unread).map {
- with(it) {
- NotificationContent(
- data = data,
- id = id,
- href = url,
- title = null,
- text = content,
- timestamp = time,
- profileUrl = img
- )
- }
- }.toList()
+ notifs.asSequence().filter(FrostNotif::unread).map {
+ with(it) {
+ NotificationContent(
+ data = data,
+ id = id,
+ href = url,
+ title = null,
+ text = content,
+ timestamp = time,
+ profileUrl = img
+ )
+ }
+ }.toList()
}
/**
@@ -49,14 +69,16 @@ data class FrostNotifs(
* [timeString] text version of time from Facebook
* [thumbnailUrl] optional thumbnail url if existent
*/
-data class FrostNotif(val id: Long,
- val img: String?,
- val time: Long,
- val url: String,
- val unread: Boolean,
- val content: String,
- val timeString: String,
- val thumbnailUrl: String?)
+data class FrostNotif(
+ val id: Long,
+ val img: String?,
+ val time: Long,
+ val url: String,
+ val unread: Boolean,
+ val content: String,
+ val timeString: String,
+ val thumbnailUrl: String?
+)
private class NotifParserImpl : FrostParserBase(false) {
@@ -67,8 +89,8 @@ private class NotifParserImpl : FrostParserBase(false) {
override fun parseImpl(doc: Document): FrostNotifs? {
val notificationList = doc.getElementById("notifications_list") ?: return null
val notifications = notificationList
- .getElementsByAttributeValueMatching("id", ".*${FB_NOTIF_ID_MATCHER.pattern}.*")
- .mapNotNull(this::parseNotif)
+ .getElementsByAttributeValueMatching("id", ".*${FB_NOTIF_ID_MATCHER.pattern}.*")
+ .mapNotNull(this::parseNotif)
val seeMore = parseLink(doc.getElementsByAttributeValue("href", "/notifications.php?more").first())
return FrostNotifs(notifications, seeMore)
}
@@ -79,22 +101,20 @@ private class NotifParserImpl : FrostParserBase(false) {
val epoch = FB_EPOCH_MATCHER.find(abbr.attr("data-store"))[1]?.toLongOrNull() ?: -1L
//fetch id
val id = FB_NOTIF_ID_MATCHER.find(element.id())[1]?.toLongOrNull()
- ?: System.currentTimeMillis() % FALLBACK_TIME_MOD
+ ?: System.currentTimeMillis() % FALLBACK_TIME_MOD
val img = element.getInnerImgStyle()
val timeString = abbr.text()
val content = a.text().replace("\u00a0", " ").removeSuffix(timeString).trim() //remove
val thumbnail = element.selectFirst("img.thumbnail")?.attr("src")
return FrostNotif(
- id = id,
- img = img,
- time = epoch,
- url = a.attr("href").formattedFbUrl,
- unread = !element.hasClass("acw"),
- content = content,
- timeString = timeString,
- thumbnailUrl = if (thumbnail?.isNotEmpty() == true) thumbnail else null
+ id = id,
+ img = img,
+ time = epoch,
+ url = a.attr("href").formattedFbUrl,
+ unread = !element.hasClass("acw"),
+ content = content,
+ timeString = timeString,
+ thumbnailUrl = if (thumbnail?.isNotEmpty() == true) thumbnail else null
)
}
-
-
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt
index d33675143..7869d8819 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.facebook.parsers
import ca.allanwang.kau.searchview.SearchItem
@@ -46,9 +62,9 @@ data class FrostSearch(val href: String, val title: String, val description: Str
companion object {
fun create(href: String, title: String, description: String?) = FrostSearch(
- with(href.indexOf("?")) { if (this == -1) href else href.substring(0, this) },
- title.format(),
- description?.format()
+ with(href.indexOf("?")) { if (this == -1) href else href.substring(0, this) },
+ title.format(),
+ description?.format()
)
}
}
@@ -61,17 +77,18 @@ private class SearchParserImpl : FrostParserBase(false) {
override fun parseImpl(doc: Document): FrostSearches? {
val container: Element = doc.getElementById("BrowseResultsContainer")
- ?: doc.getElementById("root")
- ?: return null
+ ?: doc.getElementById("root")
+ ?: return null
/**
*
* Removed [data-store*=result_id]
*/
return FrostSearches(container.select("a.touchable[href]").filter(Element::hasText).map {
- FrostSearch.create(it.attr("href").formattedFbUrl,
- it.select("._uoi").first()?.text() ?: "",
- it.select("._1tcc").first()?.text())
+ FrostSearch.create(
+ it.attr("href").formattedFbUrl,
+ it.select("._uoi").first()?.text() ?: "",
+ it.select("._1tcc").first()?.text()
+ )
}.filter { it.title.isNotBlank() })
}
-
-}
\ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt
index 500c41028..584107cc5 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt
@@ -1,7 +1,29 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.facebook.requests
import com.pitchedapps.frost.BuildConfig
-import com.pitchedapps.frost.facebook.*
+import com.pitchedapps.frost.facebook.FB_DTSG_MATCHER
+import com.pitchedapps.frost.facebook.FB_JSON_URL_MATCHER
+import com.pitchedapps.frost.facebook.FB_REV_MATCHER
+import com.pitchedapps.frost.facebook.FB_URL_BASE
+import com.pitchedapps.frost.facebook.FB_USER_MATCHER
+import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
+import com.pitchedapps.frost.facebook.get
import com.pitchedapps.frost.rx.RxFlyweight
import com.pitchedapps.frost.utils.L
import io.reactivex.Single
@@ -21,10 +43,9 @@ private class RxAuth : RxFlyweight() {
override fun call(input: String) = input.getAuth()
override fun validate(input: String, cond: Long) =
- System.currentTimeMillis() - cond < 3600000 // valid for an hour
+ System.currentTimeMillis() - cond < 3600000 // valid for an hour
override fun cache(input: String) = System.currentTimeMillis()
-
}
private val auth = RxAuth()
@@ -48,10 +69,12 @@ fun String?.fbRequest(fail: () -> Unit = {}, action: RequestAuth.() -> Unit) {
/**
* Underlying container for all fb requests
*/
-data class RequestAuth(val userId: Long = -1,
- val cookie: String = "",
- val fb_dtsg: String = "",
- val rev: String = "") {
+data class RequestAuth(
+ val userId: Long = -1,
+ val cookie: String = "",
+ val fb_dtsg: String = "",
+ val rev: String = ""
+) {
val isComplete
get() = userId > 0 && cookie.isNotEmpty() && fb_dtsg.isNotEmpty() && rev.isNotEmpty()
}
@@ -64,8 +87,8 @@ class FrostRequest(val call: Call, private val invoke: (Call) -> T
}
internal inline fun RequestAuth.frostRequest(
- noinline invoke: (Call) -> T,
- builder: Request.Builder.() -> Request.Builder // to ensure we don't do anything extra at the end
+ noinline invoke: (Call) -> T,
+ builder: Request.Builder.() -> Request.Builder // to ensure we don't do anything extra at the end
): FrostRequest {
val request = cookie.requestBuilder()
request.builder()
@@ -75,8 +98,10 @@ internal inline fun RequestAuth.frostRequest(
val httpClient: OkHttpClient by lazy {
val builder = OkHttpClient.Builder()
if (BuildConfig.DEBUG)
- builder.addInterceptor(HttpLoggingInterceptor()
- .setLevel(HttpLoggingInterceptor.Level.BASIC))
+ builder.addInterceptor(
+ HttpLoggingInterceptor()
+ .setLevel(HttpLoggingInterceptor.Level.BASIC)
+ )
builder.build()
}
@@ -97,7 +122,7 @@ internal fun List>.withEmptyData(vararg key: String): List
lines.forEach {
val text = StringEscapeUtils.unescapeEcmaScript(it)
@@ -135,8 +160,10 @@ fun String.getAuth(): RequestAuth {
return auth
}
-inline fun Array.zip(crossinline mapper: (List) -> O,
- crossinline caller: (T) -> R): Single {
+inline fun Array.zip(
+ crossinline mapper: (List) -> O,
+ crossinline caller: (T) -> R
+): Single {
if (isEmpty())
return Single.just(mapper(emptyList()))
val singles = map { Single.fromCallable { caller(it) }.subscribeOn(Schedulers.io()) }
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt
index 8eeef08dc..e0ccea815 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.facebook.requests
import com.bumptech.glide.Priority
@@ -11,7 +27,11 @@ import com.bumptech.glide.load.model.MultiModelLoaderFactory
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.Target
import com.bumptech.glide.signature.ObjectKey
-import com.pitchedapps.frost.facebook.*
+import com.pitchedapps.frost.facebook.FB_IMAGE_ID_MATCHER
+import com.pitchedapps.frost.facebook.FB_REDIRECT_URL_MATCHER
+import com.pitchedapps.frost.facebook.FB_URL_BASE
+import com.pitchedapps.frost.facebook.formattedFbUrl
+import com.pitchedapps.frost.facebook.get
import io.reactivex.Maybe
import okhttp3.Call
import okhttp3.Request
@@ -33,9 +53,9 @@ val test: () -> InputStream? = { null }
*/
fun String.getFullSizedImageUrl(url: String): Maybe = Maybe.fromCallable {
val redirect = requestBuilder().url(url).get().call()
- .execute().body()?.string() ?: return@fromCallable null
+ .execute().body()?.string() ?: return@fromCallable null
return@fromCallable FB_REDIRECT_URL_MATCHER.find(redirect)[1]?.formattedFbUrl
- ?: return@fromCallable null
+ ?: return@fromCallable null
}.onErrorComplete()
/**
@@ -51,7 +71,6 @@ data class HdImageMaybe(val url: String, val cookie: String) {
val isValid: Boolean by lazy {
id != -1L && cookie.isNotBlank()
}
-
}
/*
@@ -69,18 +88,20 @@ class HdImageLoadingFactory : ModelLoaderFactory {
}
fun RequestBuilder.loadWithPotentialHd(model: HdImageMaybe) =
- thumbnail(clone().load(model.url))
- .load(model)
- .apply(RequestOptions().override(Target.SIZE_ORIGINAL))
+ thumbnail(clone().load(model.url))
+ .load(model)
+ .apply(RequestOptions().override(Target.SIZE_ORIGINAL))
class HdImageLoading : ModelLoader {
- override fun buildLoadData(model: HdImageMaybe,
- width: Int,
- height: Int,
- options: Options): ModelLoader.LoadData? =
- if (!model.isValid) null
- else ModelLoader.LoadData(ObjectKey(model), HdImageFetcher(model))
+ override fun buildLoadData(
+ model: HdImageMaybe,
+ width: Int,
+ height: Int,
+ options: Options
+ ): ModelLoader.LoadData? =
+ if (!model.isValid) null
+ else ModelLoader.LoadData(ObjectKey(model), HdImageFetcher(model))
override fun handles(model: HdImageMaybe) = model.isValid
}
@@ -105,7 +126,7 @@ class HdImageFetcher(private val model: HdImageMaybe) : DataFetcher
model.cookie.fbRequest(fail = { callback.fail("Invalid auth") }) {
if (cancelled) return@fbRequest callback.fail("Cancelled")
val url = getFullSizedImage(model.id).invoke()
- ?: return@fbRequest callback.fail("Null url")
+ ?: return@fbRequest callback.fail("Null url")
if (cancelled) return@fbRequest callback.fail("Cancelled")
if (!url.contains("png") && !url.contains("jpg")) return@fbRequest callback.fail("Invalid format")
urlCall = Request.Builder().url(url).get().call()
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Menu.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Menu.kt
index e83e4e43a..dcb0ce10d 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Menu.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Menu.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
package com.pitchedapps.frost.facebook.requests
import com.fasterxml.jackson.annotation.JsonCreator
@@ -19,28 +35,27 @@ import java.io.IOException
fun RequestAuth.getMenuData(): FrostRequest {
val body = listOf(
- "fb_dtsg" to fb_dtsg,
- "__user" to userId
+ "fb_dtsg" to fb_dtsg,
+ "__user" to userId
).withEmptyData("m_sess", "__dyn", "__req", "__ajax__")
return frostRequest(::parseMenu) {
url("${FB_URL_BASE}bookmarks/flyout/body/?id=u_0_2")
post(body.toForm())
}
-
}
fun parseMenu(call: Call): MenuData? {
val fullString = call.execute().body()?.string() ?: return null
var jsonString = fullString.substringAfter("bookmarkGroups", "")
- .substringAfter("[", "")
+ .substringAfter("[", "")
if (jsonString.isBlank()) return null
jsonString = "{ \"data\" : [${StringEscapeUtils.unescapeEcmaScript(jsonString)}"
val mapper = ObjectMapper()
- .disable(MapperFeature.AUTO_DETECT_SETTERS)
+ .disable(MapperFeature.AUTO_DETECT_SETTERS)
return try {
val data = mapper.readValue(jsonString, MenuData::class.java)
@@ -48,11 +63,14 @@ fun parseMenu(call: Call): MenuData? {
// parse footer content
val footer = fullString.substringAfter("footerMarkup", "")
- .substringAfter("{", "")
- .substringBefore("}", "")
+ .substringAfter("{", "")
+ .substringBefore("}", "")
- val doc = Jsoup.parseBodyFragment(StringEscapeUtils.unescapeEcmaScript(
- StringEscapeUtils.unescapeEcmaScript(footer)))
+ val doc = Jsoup.parseBodyFragment(
+ StringEscapeUtils.unescapeEcmaScript(
+ StringEscapeUtils.unescapeEcmaScript(footer)
+ )
+ )
val footerData = mutableListOf()
val footerSmallData = mutableListOf()
@@ -76,11 +94,14 @@ fun parseMenu(call: Call): MenuData? {
}
@JsonIgnoreProperties(ignoreUnknown = true)
-data class MenuData(val data: List = emptyList(),
- val footer: MenuFooter = MenuFooter()) {
+data class MenuData(
+ val data: List = emptyList(),
+ val footer: MenuFooter = MenuFooter()
+) {
- @JsonCreator constructor(
- @JsonProperty("data") data: List?
+ @JsonCreator
+ constructor(
+ @JsonProperty("data") data: List?
) : this(data ?: emptyList(), MenuFooter())
fun flatMapValid(): List {
@@ -95,7 +116,6 @@ data class MenuData(val data: List = emptyList(),
return items
}
-
}
interface MenuItemData {
@@ -103,17 +123,20 @@ interface MenuItemData {
}
@JsonIgnoreProperties(ignoreUnknown = true)
-data class MenuHeader(val id: String? = null,
- val header: String? = null,
- val visible: List