aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2020-02-29 19:29:09 -0800
committerAllan Wang <me@allanwang.ca>2020-02-29 19:29:09 -0800
commitc5d38e5122bcb452b1e61ea6526434cf62e9da8c (patch)
tree3b31b15cd40fc81738592b8cb8af15fe23450d65 /app/src/main/kotlin/com
parenta93cdf52cc3b7eff1e2d4cf436b8f8dbc3cf14a2 (diff)
downloadfrost-c5d38e5122bcb452b1e61ea6526434cf62e9da8c.tar.gz
frost-c5d38e5122bcb452b1e61ea6526434cf62e9da8c.tar.bz2
frost-c5d38e5122bcb452b1e61ea6526434cf62e9da8c.zip
Update koin usage
Diffstat (limited to 'app/src/main/kotlin/com')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/BaseActivity.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt12
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt6
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/db/Database.kt7
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/enums/Support.kt1
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragments.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt11
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt4
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt10
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt7
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt5
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt8
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt22
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt6
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt5
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt6
22 files changed, 64 insertions, 64 deletions
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 af49cb33..f41f19e5 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseActivity.kt
@@ -48,7 +48,7 @@ abstract class BaseActivity : KauBaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- if (this !is WebOverlayActivityBase) setFrostTheme()
+ if (this !is WebOverlayActivityBase) setFrostTheme(prefs)
}
override fun onStop() {
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 8d580ebd..bfb87a2f 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt
@@ -313,7 +313,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
val item = FbItem.values[it.itemId]
frostEvent("Drawer Tab", "name" to item.name)
drawer.closeDrawer(navigation)
- launchWebOverlay(item.url, fbCookie)
+ launchWebOverlay(item.url, fbCookie, prefs)
false
}
val navBg = prefs.bgColor.withMinAlpha(200)
@@ -464,7 +464,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
setOptionsIcon(GoogleMaterial.Icon.gmd_exit_to_app)
setOnClickListener {
launch {
- val currentCookie = cookieDao.currentCookie()
+ val currentCookie = cookieDao.currentCookie(prefs)
if (currentCookie == null) {
toast(R.string.account_not_found)
fbCookie.reset()
@@ -596,7 +596,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
.into(this)
setOnClickListener {
if (primary) {
- launchWebOverlay(FbItem.PROFILE.url, fbCookie)
+ launchWebOverlay(FbItem.PROFILE.url, fbCookie, prefs)
} else {
switchAccount(cookie.id)
}
@@ -661,11 +661,11 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
}
textDebounceInterval = 300
searchCallback =
- { query, _ -> launchWebOverlay("${FbItem._SEARCH.url}/?q=$query", fbCookie); true }
+ { query, _ -> launchWebOverlay("${FbItem._SEARCH.url}/?q=$query", fbCookie, prefs); true }
closeListener = { _ -> searchViewCache.clear() }
foregroundColor = prefs.textColor
backgroundColor = prefs.bgColor.withMinAlpha(200)
- onItemClick = { _, key, _, _ -> launchWebOverlay(key, fbCookie) }
+ onItemClick = { _, key, _, _ -> launchWebOverlay(key, fbCookie, prefs) }
}
}
}
@@ -723,7 +723,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
fragmentChannel.offer(REQUEST_REFRESH)
}
if (hasRequest(REQUEST_NAV)) {
- frostNavigationBar()
+ frostNavigationBar(prefs)
}
if (hasRequest(REQUEST_TEXT_ZOOM)) {
fragmentChannel.offer(REQUEST_TEXT_ZOOM)
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 d594963e..232fc56d 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt
@@ -114,7 +114,7 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer,
indicator.invalidate()
}
fragments.forEach { it.themeFragment() }
- setFrostTheme(true)
+ setFrostTheme(prefs, true)
}
/**
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 55ff3fba..67f605be 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/SettingsActivity.kt
@@ -40,6 +40,7 @@ import com.afollestad.materialdialogs.list.listItems
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
import com.pitchedapps.frost.R
+import com.pitchedapps.frost.db.NotificationDao
import com.pitchedapps.frost.enums.Support
import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.settings.getAppearancePrefs
@@ -70,6 +71,7 @@ import org.koin.android.ext.android.inject
class SettingsActivity : KPrefActivity() {
val fbCookie: FbCookie by inject()
+ val notifDao: NotificationDao by inject()
val prefs: Prefs by inject()
private var resultFlag = Activity.RESULT_CANCELED
@@ -218,7 +220,7 @@ class SettingsActivity : KPrefActivity() {
@SuppressLint("MissingSuperCall")
override fun onCreate(savedInstanceState: Bundle?) {
- setFrostTheme(true)
+ setFrostTheme(prefs, true)
super.onCreate(savedInstanceState)
animate = prefs.animate
themeExterior(false)
@@ -229,7 +231,7 @@ class SettingsActivity : KPrefActivity() {
else bgCanvas.set(prefs.bgColor)
if (animate) toolbarCanvas.ripple(prefs.headerColor, RippleCanvas.MIDDLE, RippleCanvas.END)
else toolbarCanvas.set(prefs.headerColor)
- frostNavigationBar()
+ frostNavigationBar(prefs)
}
override fun onBackPressed() {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt b/app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt
index 1b90b1e3..68e7e3de 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt
@@ -68,4 +68,4 @@ suspend fun CookieDao.selectById(id: Long) = dao { _selectById(id) }
suspend fun CookieDao.save(cookie: CookieEntity) = dao { _save(cookie) }
suspend fun CookieDao.save(cookies: List<CookieEntity>) = dao { _save(cookies) }
suspend fun CookieDao.deleteById(id: Long) = dao { _deleteById(id) }
-suspend fun CookieDao.currentCookie() = selectById(Prefs.get().userId)
+suspend fun CookieDao.currentCookie(prefs: Prefs) = selectById(prefs.userId)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/db/Database.kt b/app/src/main/kotlin/com/pitchedapps/frost/db/Database.kt
index e54daa69..9ceb05aa 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/db/Database.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/db/Database.kt
@@ -22,6 +22,7 @@ import androidx.room.Room
import androidx.room.RoomDatabase
import com.pitchedapps.frost.BuildConfig
import org.koin.core.context.GlobalContext
+import org.koin.core.context.KoinContextHandler
import org.koin.dsl.module
interface FrostPrivateDao {
@@ -100,11 +101,5 @@ class FrostDatabase(
single { get<FrostDatabase>().notifDao() }
single { get<FrostDatabase>().genericDao() }
}
-
- /**
- * Get from koin
- * For the most part, you can retrieve directly from other koin components
- */
- fun get(): FrostDatabase = GlobalContext.get().koin.get()
}
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/enums/Support.kt b/app/src/main/kotlin/com/pitchedapps/frost/enums/Support.kt
index 23ea5a8f..1fa56f7e 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/enums/Support.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/enums/Support.kt
@@ -20,6 +20,7 @@ import android.content.Context
import androidx.annotation.StringRes
import ca.allanwang.kau.utils.string
import com.pitchedapps.frost.R
+import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.sendFrostEmail
/**
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragments.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragments.kt
index 35b390c4..b282b36c 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragments.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragments.kt
@@ -40,6 +40,6 @@ class NotificationFragment : FrostParserFragment<FrostNotifs, NotificationIItem>
response.data.notifs.map { NotificationIItem(it, response.cookie) }
override fun bindImpl(recyclerView: FrostRecyclerView) {
- NotificationIItem.bindEvents(adapter, fbCookie)
+ NotificationIItem.bindEvents(adapter, fbCookie, prefs)
}
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt b/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt
index 1262c078..5257be5e 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/iitems/GenericIItems.kt
@@ -44,20 +44,20 @@ interface ClickableIItemContract {
val url: String?
- fun click(context: Context, fbCookie: FbCookie) {
+ fun click(context: Context, fbCookie: FbCookie, prefs: Prefs) {
val url = url ?: return
- context.launchWebOverlay(url, fbCookie)
+ context.launchWebOverlay(url, fbCookie, prefs)
}
companion object {
- fun bindEvents(adapter: IAdapter<GenericItem>, fbCookie: FbCookie) {
+ fun bindEvents(adapter: IAdapter<GenericItem>, fbCookie: FbCookie, prefs: Prefs) {
adapter.fastAdapter?.apply {
selectExtension {
isSelectable = false
}
onClickListener = { v, _, item, _ ->
if (item is ClickableIItemContract) {
- item.click(v!!.context, fbCookie)
+ item.click(v!!.context, fbCookie, prefs)
true
} else
false
@@ -76,7 +76,8 @@ open class HeaderIItem(
itemId: Int = R.layout.iitem_header
) : KauIItem<HeaderIItem.ViewHolder>(R.layout.iitem_header, ::ViewHolder, itemId) {
- class ViewHolder(itemView: View) : FastAdapter.ViewHolder<HeaderIItem>(itemView), KoinComponent {
+ class ViewHolder(itemView: View) : FastAdapter.ViewHolder<HeaderIItem>(itemView),
+ KoinComponent {
private val prefs: Prefs by inject()
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt
index 8624fff0..9d3b59eb 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/iitems/NotificationIItem.kt
@@ -51,7 +51,7 @@ class NotificationIItem(val notification: FrostNotif, val cookie: String) :
) {
companion object {
- fun bindEvents(adapter: ItemAdapter<NotificationIItem>, fbCookie: FbCookie) {
+ fun bindEvents(adapter: ItemAdapter<NotificationIItem>, fbCookie: FbCookie, prefs: Prefs) {
adapter.fastAdapter?.apply {
selectExtension {
isSelectable = false
@@ -65,7 +65,7 @@ class NotificationIItem(val notification: FrostNotif, val cookie: String) :
)
}
// TODO temp fix. If url is dependent, we cannot load it directly
- v!!.context.launchWebOverlay(if (notif.url.isIndependent) notif.url else FbItem.NOTIFICATIONS.url, fbCookie)
+ v!!.context.launchWebOverlay(if (notif.url.isIndependent) notif.url else FbItem.NOTIFICATIONS.url, fbCookie, prefs)
true
}
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
index 7b20e07c..5b62a4ed 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/FrostNotifications.kt
@@ -33,6 +33,7 @@ import com.pitchedapps.frost.R
import com.pitchedapps.frost.activities.FrostWebActivity
import com.pitchedapps.frost.db.CookieEntity
import com.pitchedapps.frost.db.FrostDatabase
+import com.pitchedapps.frost.db.NotificationDao
import com.pitchedapps.frost.db.latestEpoch
import com.pitchedapps.frost.db.saveNotifications
import com.pitchedapps.frost.enums.OverlayContext
@@ -112,8 +113,7 @@ enum class NotificationType(
* Returns the number of notifications generated,
* or -1 if an error occurred
*/
- suspend fun fetch(context: Context, data: CookieEntity, prefs: Prefs): Int {
- val notifDao = FrostDatabase.get().notifDao()
+ suspend fun fetch(context: Context, data: CookieEntity, prefs: Prefs, notifDao: NotificationDao): Int {
val response = try {
parser.parse(data.cookie)
} catch (ignored: Exception) {
@@ -170,7 +170,7 @@ enum class NotificationType(
val ringtone = ringtoneProvider(prefs)
notifs.forEachIndexed { i, notif ->
// Ring at most twice
- notif.withAlert(context, i < 2, ringtone).notify(context)
+ notif.withAlert(context, i < 2, ringtone, prefs).notify(context)
}
return notifs.size
}
@@ -307,8 +307,8 @@ data class FrostNotification(
val notif: NotificationCompat.Builder
) {
- fun withAlert(context: Context, enable: Boolean, ringtone: String): FrostNotification {
- notif.setFrostAlert(context, enable, ringtone)
+ fun withAlert(context: Context, enable: Boolean, ringtone: String, prefs: Prefs): FrostNotification {
+ notif.setFrostAlert(context, enable, ringtone, prefs)
return this
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
index 73c97b5e..4c80f63d 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt
@@ -23,6 +23,7 @@ import com.pitchedapps.frost.BuildConfig
import com.pitchedapps.frost.R
import com.pitchedapps.frost.db.CookieDao
import com.pitchedapps.frost.db.CookieEntity
+import com.pitchedapps.frost.db.NotificationDao
import com.pitchedapps.frost.db.selectAll
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
@@ -34,7 +35,6 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.yield
import org.koin.android.ext.android.inject
-import org.koin.core.inject
/**
* Created by Allan Wang on 2017-06-14.
@@ -47,6 +47,7 @@ import org.koin.core.inject
class NotificationService : BaseJobService() {
private val prefs: Prefs by inject()
+ private val notifDao: NotificationDao by inject()
private val cookieDao: CookieDao by inject()
override fun onStopJob(params: JobParameters?): Boolean {
@@ -119,7 +120,7 @@ class NotificationService : BaseJobService() {
* Also normalized the output to return the number of notifications received
*/
private suspend fun fetch(jobId: Int, type: NotificationType, cookie: CookieEntity): Int {
- val count = type.fetch(this, cookie, prefs)
+ val count = type.fetch(this, cookie, prefs, notifDao)
if (count < 0) {
if (jobId == NOTIFICATION_JOB_NOW)
generalNotification(666, R.string.error_notification, BuildConfig.DEBUG)
@@ -135,7 +136,7 @@ class NotificationService : BaseJobService() {
private fun generalNotification(id: Int, textRes: Int, withDefaults: Boolean) {
val notifBuilder = frostNotification(NOTIF_CHANNEL_GENERAL)
- .setFrostAlert(this, withDefaults, prefs.notificationRingtone)
+ .setFrostAlert(this, withDefaults, prefs.notificationRingtone, prefs)
.setContentTitle(string(R.string.frost_name))
.setContentText(string(textRes))
NotificationManagerCompat.from(this).notify(id, notifBuilder.build())
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt
index 5f01dfd2..60cf874f 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt
@@ -92,10 +92,9 @@ fun Context.frostNotification(id: String) =
fun NotificationCompat.Builder.setFrostAlert(
context: Context,
enable: Boolean,
- ringtone: String
+ ringtone: String,
+ prefs: Prefs
): NotificationCompat.Builder {
- val prefs = Prefs.get()
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setGroupAlertBehavior(
if (enable) NotificationCompat.GROUP_ALERT_CHILDREN
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt
index 8c83850b..65e24ab8 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt
@@ -56,7 +56,7 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = {
item.pref = index
shouldRestartMain()
reload()
- setFrostTheme(true)
+ setFrostTheme(prefs, true)
themeExterior()
invalidateOptionsMenu()
frostEvent("Theme", "Count" to Theme(index).name)
@@ -103,7 +103,7 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = {
prefs.customBackgroundColor = it
bgCanvas.ripple(it, duration = 500L)
invalidateCustomTheme()
- setFrostTheme(true)
+ setFrostTheme(prefs, true)
shouldRestartMain()
}) {
dependsOnCustom()
@@ -112,7 +112,7 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = {
colorPicker(R.string.header_color, prefs::customHeaderColor, {
prefs.customHeaderColor = it
- frostNavigationBar()
+ frostNavigationBar(prefs)
toolbarCanvas.ripple(it, RippleCanvas.MIDDLE, RippleCanvas.END, duration = 500L)
reload()
shouldRestartMain()
@@ -161,7 +161,7 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = {
checkbox(R.string.tint_nav, prefs::tintNavBar, {
prefs.tintNavBar = it
- frostNavigationBar()
+ frostNavigationBar(prefs)
setFrostResult(REQUEST_NAV)
}) {
descRes = R.string.tint_nav_desc
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt
index 9a4751b8..834a78fd 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Debug.kt
@@ -37,13 +37,14 @@ import com.pitchedapps.frost.facebook.parsers.MessageParser
import com.pitchedapps.frost.facebook.parsers.NotifParser
import com.pitchedapps.frost.facebook.parsers.SearchParser
import com.pitchedapps.frost.utils.L
+import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.frostUriFromFile
import com.pitchedapps.frost.utils.sendFrostEmail
-import java.io.File
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
+import java.io.File
/**
* Created by Allan Wang on 2017-06-30.
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt
index 06159ba5..2aaea4b0 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Notifications.kt
@@ -185,7 +185,7 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = {
plainText(R.string.reset_notif_epoch) {
onClick = {
launch {
- FrostDatabase.get().notifDao().deleteAll()
+ notifDao.deleteAll()
}
}
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
index 8052533b..36e3971a 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
@@ -31,6 +31,7 @@ import com.pitchedapps.frost.enums.MainActivityLayout
import com.pitchedapps.frost.enums.Theme
import com.pitchedapps.frost.injectors.InjectorContract
import org.koin.core.context.GlobalContext
+import org.koin.core.context.KoinContextHandler
import org.koin.dsl.module
/**
@@ -202,7 +203,7 @@ class Prefs(factory: KPrefFactory) : KPref("${BuildConfig.APPLICATION_ID}.prefs"
get() = MainActivityLayout(mainActivityLayoutType)
companion object {
- fun get(): Prefs = GlobalContext.get().koin.get()
+ fun get(): Prefs = KoinContextHandler.get().get()
fun module() = module {
single { Prefs(get()) }
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
index 1f266eb9..6db7179d 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
@@ -125,9 +125,9 @@ fun Activity.cookies(): ArrayList<CookieEntity> {
*/
private inline fun <reified T : WebOverlayActivityBase> Context.launchWebOverlayImpl(
url: String,
- fbCookie: FbCookie
+ fbCookie: FbCookie,
+ prefs: Prefs
) {
- val prefs = Prefs.get()
val argUrl = url.formattedFbUrl
L.v { "Launch received: $url\nLaunch web overlay: $argUrl" }
if (argUrl.isFacebookUrl && argUrl.contains("/logout.php")) {
@@ -142,15 +142,15 @@ private inline fun <reified T : WebOverlayActivityBase> Context.launchWebOverlay
}
}
-fun Context.launchWebOverlay(url: String, fbCookie: FbCookie) =
- launchWebOverlayImpl<WebOverlayActivity>(url, fbCookie)
+fun Context.launchWebOverlay(url: String, fbCookie: FbCookie, prefs: Prefs) =
+ launchWebOverlayImpl<WebOverlayActivity>(url, fbCookie, prefs)
// TODO Currently, default is overlay. Switch this if default changes
-fun Context.launchWebOverlayDesktop(url: String, fbCookie: FbCookie) =
- launchWebOverlay(url, fbCookie)
+fun Context.launchWebOverlayDesktop(url: String, fbCookie: FbCookie, prefs: Prefs) =
+ launchWebOverlay(url, fbCookie, prefs)
-fun Context.launchWebOverlayMobile(url: String, fbCookie: FbCookie) =
- launchWebOverlayImpl<WebOverlayMobileActivity>(url, fbCookie)
+fun Context.launchWebOverlayMobile(url: String, fbCookie: FbCookie, prefs: Prefs) =
+ launchWebOverlayImpl<WebOverlayMobileActivity>(url, fbCookie, prefs)
private fun Context.fadeBundle() = ActivityOptions.makeCustomAnimation(
this,
@@ -178,8 +178,7 @@ fun WebOverlayActivity.url(): String {
return intent.getStringExtra(ARG_URL) ?: FbItem.FEED.url
}
-fun Activity.setFrostTheme(forceTransparent: Boolean = false) {
- val prefs = Prefs.get()
+fun Activity.setFrostTheme(prefs: Prefs, forceTransparent: Boolean = false) {
val isTransparent =
forceTransparent || (Color.alpha(prefs.bgColor) != 255) || (Color.alpha(prefs.headerColor) != 255)
if (prefs.bgColor.isColorDark) {
@@ -267,8 +266,7 @@ private inline fun frostSnackbar(crossinline builder: Snackbar.() -> Unit): Snac
}
}
-fun Activity.frostNavigationBar() {
- val prefs = Prefs.get()
+fun Activity.frostNavigationBar(prefs: Prefs) {
navigationBarColor = if (prefs.tintNavBar) prefs.headerColor else Color.BLACK
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt
index d6e8f9e9..2e5d2fce 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt
@@ -71,7 +71,7 @@ enum class WebContextType(
OPEN_LINK(
R.string.open_link,
{ it.hasUrl },
- { c, wc, fc -> c.launchWebOverlay(wc.url!!, fc) }),
+ { c, wc, fc -> c.launchWebOverlay(wc.url!!, fc, Prefs.get()) }),
COPY_LINK(R.string.copy_link, { it.hasUrl }, { c, wc, _ -> c.copyToClipboard(wc.url) }),
COPY_TEXT(R.string.copy_text, { it.hasText }, { c, wc, _ -> c.copyToClipboard(wc.text) }),
SHARE_LINK(R.string.share_link, { it.hasUrl }, { c, wc, _ -> c.shareText(wc.url) }),
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt
index 16df7f8e..ec822bfa 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt
@@ -41,7 +41,7 @@ import com.devbrackets.android.exomedia.listener.VideoControlsVisibilityListener
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
import com.pitchedapps.frost.R
import com.pitchedapps.frost.databinding.ViewVideoBinding
-import com.pitchedapps.frost.db.FrostDatabase
+import com.pitchedapps.frost.db.CookieDao
import com.pitchedapps.frost.db.currentCookie
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
@@ -88,6 +88,7 @@ class FrostVideoViewer @JvmOverloads constructor(
}
private val prefs: Prefs by inject()
+ private val cookieDao: CookieDao by inject()
private val binding: ViewVideoBinding =
ViewVideoBinding.inflate(LayoutInflater.from(context), this, true)
@@ -116,8 +117,7 @@ class FrostVideoViewer @JvmOverloads constructor(
when (it.itemId) {
R.id.action_pip -> video.isExpanded = false
R.id.action_download -> context.ctxCoroutine.launchMain {
- val cookie =
- FrostDatabase.get().cookieDao().currentCookie() ?: return@launchMain
+ val cookie = cookieDao.currentCookie(prefs) ?: return@launchMain
context.frostDownload(cookie, video.videoUri)
}
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
index dd31d303..9ca622a3 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
@@ -28,6 +28,7 @@ import ca.allanwang.kau.utils.launchMain
import com.pitchedapps.frost.contracts.FrostContentContainer
import com.pitchedapps.frost.contracts.FrostContentCore
import com.pitchedapps.frost.contracts.FrostContentParent
+import com.pitchedapps.frost.db.CookieDao
import com.pitchedapps.frost.db.FrostDatabase
import com.pitchedapps.frost.db.currentCookie
import com.pitchedapps.frost.facebook.FB_HOME_URL
@@ -62,6 +63,7 @@ class FrostWebView @JvmOverloads constructor(
val fbCookie: FbCookie by inject()
val prefs: Prefs by inject()
+ val cookieDao: CookieDao by inject()
override fun reload(animate: Boolean) {
if (parent.registerTransition(false, animate))
@@ -92,10 +94,9 @@ class FrostWebView @JvmOverloads constructor(
webChromeClient = FrostChromeClient(this)
addJavascriptInterface(FrostJSI(this), "Frost")
setBackgroundColor(Color.TRANSPARENT)
- val db = FrostDatabase.get()
setDownloadListener { url, userAgent, contentDisposition, mimetype, contentLength ->
context.ctxCoroutine.launchMain {
- val cookie = db.cookieDao().currentCookie() ?: return@launchMain
+ val cookie = cookieDao.currentCookie(prefs) ?: return@launchMain
context.frostDownload(
cookie,
url,
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt
index b4dd93da..d08f80a6 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt
@@ -80,19 +80,19 @@ fun FrostWebView.requestWebOverlay(url: String): Boolean {
// already overlay; manage user agent
if (userAgentString != USER_AGENT_DESKTOP_CONST && shouldUseDesktop) {
L._i { "Switch to desktop agent overlay" }
- context.launchWebOverlayDesktop(url, fbCookie)
+ context.launchWebOverlayDesktop(url, fbCookie, prefs)
return true
}
if (userAgentString == USER_AGENT_DESKTOP_CONST && !shouldUseDesktop) {
L._i { "Switch from desktop agent" }
- context.launchWebOverlayMobile(url, fbCookie)
+ context.launchWebOverlayMobile(url, fbCookie, prefs)
return true
}
L._i { "return false switch" }
return false
}
L.v { "Request web overlay passed" }
- context.launchWebOverlay(url, fbCookie)
+ context.launchWebOverlay(url, fbCookie, prefs)
return true
}