mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-11-10 04:52:38 +01:00
Update koin usage
This commit is contained in:
parent
a93cdf52cc
commit
c5d38e5122
@ -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() {
|
||||
|
@ -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)
|
||||
|
@ -114,7 +114,7 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer,
|
||||
indicator.invalidate()
|
||||
}
|
||||
fragments.forEach { it.themeFragment() }
|
||||
setFrostTheme(true)
|
||||
setFrostTheme(prefs, true)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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() {
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
/**
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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())
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -185,7 +185,7 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = {
|
||||
plainText(R.string.reset_notif_epoch) {
|
||||
onClick = {
|
||||
launch {
|
||||
FrostDatabase.get().notifDao().deleteAll()
|
||||
notifDao.deleteAll()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()) }
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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) }),
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user