1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-11-08 20:12:39 +01:00

Optimize imports and update changelog

This commit is contained in:
Allan Wang 2019-09-22 22:47:07 -07:00
parent 981d6ffb40
commit 142b95f0ae
No known key found for this signature in database
GPG Key ID: C93E3F9C679D7A56
28 changed files with 36 additions and 37 deletions

View File

@ -41,7 +41,6 @@ import com.mikepenz.aboutlibraries.Libs
import com.mikepenz.aboutlibraries.entity.Library import com.mikepenz.aboutlibraries.entity.Library
import com.mikepenz.aboutlibraries.entity.License import com.mikepenz.aboutlibraries.entity.License
import com.mikepenz.fastadapter.GenericItem import com.mikepenz.fastadapter.GenericItem
import com.mikepenz.fastadapter.IItem
import com.mikepenz.fastadapter.items.AbstractItem import com.mikepenz.fastadapter.items.AbstractItem
import com.mikepenz.iconics.typeface.IIcon import com.mikepenz.iconics.typeface.IIcon
import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial import com.mikepenz.iconics.typeface.library.community.material.CommunityMaterial

View File

@ -467,7 +467,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
fun hasRequest(flag: Int) = resultCode and flag > 0 fun hasRequest(flag: Int) = resultCode and flag > 0
if (requestCode == ACTIVITY_SETTINGS) { if (requestCode == ACTIVITY_SETTINGS) {
if (resultCode and REQUEST_RESTART_APPLICATION > 0) { //completely restart application if (resultCode and REQUEST_RESTART_APPLICATION > 0) { // completely restart application
L.d { "Restart Application Requested" } L.d { "Restart Application Requested" }
val intent = packageManager.getLaunchIntentForPackage(packageName)!! val intent = packageManager.getLaunchIntentForPackage(packageName)!!
Intent.makeRestartActivityTask(intent.component) Intent.makeRestartActivityTask(intent.component)
@ -604,7 +604,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
if (!fragmentChannel.isClosedForSend) { if (!fragmentChannel.isClosedForSend) {
fragmentChannel.offer(0) fragmentChannel.offer(0)
} }
} //trigger hook so title is set } // trigger hook so title is set
} }
fun saveInstanceState(outState: Bundle) { fun saveInstanceState(outState: Bundle) {

View File

@ -258,7 +258,7 @@ class ImageActivity : KauBaseActivity() {
) { ) {
super.onViewPositionChanged(changedView, left, top, dx, dy) super.onViewPositionChanged(changedView, left, top, dx, dy)
with(binding) { with(binding) {
//make sure that we are using the proper axis // make sure that we are using the proper axis
scrollPercent = abs(top.toFloat() / imageContainer.height) scrollPercent = abs(top.toFloat() / imageContainer.height)
scrollToTop = top < 0 scrollToTop = top < 0
val multiplier = max(1f - scrollPercent, 0f) val multiplier = max(1f - scrollPercent, 0f)

View File

@ -123,7 +123,7 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.On
* All fragments are locked in position * All fragments are locked in position
*/ */
override fun transformPage(page: View, position: Float) { override fun transformPage(page: View, position: Float) {
//only apply to adjacent pages // only apply to adjacent pages
if ((position < 0 && position > -1) || (position > 0 && position < 1)) { if ((position < 0 && position > -1) || (position > 0 && position < 1)) {
val pageWidth = page.width val pageWidth = page.width
val translateValue = position * -pageWidth val translateValue = position * -pageWidth

View File

@ -29,7 +29,7 @@ enum class FeedSort(@StringRes val textRes: Int, val item: FbItem) {
TOP(R.string.top_stories, FbItem.FEED_TOP_STORIES); TOP(R.string.top_stories, FbItem.FEED_TOP_STORIES);
companion object { companion object {
val values = values() //save one instance val values = values() // save one instance
operator fun invoke(index: Int) = values[index] operator fun invoke(index: Int) = values[index]
} }
} }

View File

@ -40,7 +40,7 @@ enum class MainActivityLayout(
{ Prefs.textColor }); { Prefs.textColor });
companion object { companion object {
val values = values() //save one instance val values = values() // save one instance
operator fun invoke(index: Int) = values[index] operator fun invoke(index: Int) = values[index]
} }
} }

View File

@ -104,7 +104,7 @@ enum class Theme(
get() = iconColorGetter() get() = iconColorGetter()
companion object { companion object {
val values = values() //save one instance val values = values() // save one instance
operator fun invoke(index: Int) = values[index] operator fun invoke(index: Int) = values[index]
} }
} }

View File

@ -67,7 +67,7 @@ class FbUrlFormatter(url: String) {
return url return url
} }
cleanedUrl = cleanedUrl.replace("&amp;", "&") cleanedUrl = cleanedUrl.replace("&amp;", "&")
if (changed && !cleanedUrl.contains("?")) //ensure we aren't missing '?' if (changed && !cleanedUrl.contains("?")) // ensure we aren't missing '?'
cleanedUrl = cleanedUrl.replaceFirst("&", "?") cleanedUrl = cleanedUrl.replaceFirst("&", "?")
val qm = cleanedUrl.indexOf("?") val qm = cleanedUrl.indexOf("?")
if (qm > -1) { if (qm > -1) {
@ -82,7 +82,7 @@ class FbUrlFormatter(url: String) {
cleanedUrl = cleanedUrl.replaceFirst( cleanedUrl = cleanedUrl.replaceFirst(
".facebook.com//", ".facebook.com//",
".facebook.com/" ".facebook.com/"
) //sometimes we are given a bad url ) // sometimes we are given a bad url
L.v { "Formatted url from $url to $cleanedUrl" } L.v { "Formatted url from $url to $cleanedUrl" }
return cleanedUrl return cleanedUrl
} }

View File

@ -136,7 +136,7 @@ private class MessageParserImpl : FrostParserBase<FrostMessages>(true) {
val a = element.getElementsByTag("a").first() ?: return null val a = element.getElementsByTag("a").first() ?: return null
val abbr = element.getElementsByTag("abbr") val abbr = element.getElementsByTag("abbr")
val epoch = FB_EPOCH_MATCHER.find(abbr.attr("data-store"))[1]?.toLongOrNull() ?: -1L val epoch = FB_EPOCH_MATCHER.find(abbr.attr("data-store"))[1]?.toLongOrNull() ?: -1L
//fetch id // fetch id
val id = FB_MESSAGE_NOTIF_ID_MATCHER.find(element.id())[1]?.toLongOrNull() 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 snippet = element.select("span.snippet").firstOrNull()

View File

@ -105,13 +105,13 @@ private class NotifParserImpl : FrostParserBase<FrostNotifs>(false) {
val a = element.getElementsByTag("a").first() ?: return null val a = element.getElementsByTag("a").first() ?: return null
val abbr = element.getElementsByTag("abbr") val abbr = element.getElementsByTag("abbr")
val epoch = FB_EPOCH_MATCHER.find(abbr.attr("data-store"))[1]?.toLongOrNull() ?: -1L val epoch = FB_EPOCH_MATCHER.find(abbr.attr("data-store"))[1]?.toLongOrNull() ?: -1L
//fetch id // fetch id
val id = FB_NOTIF_ID_MATCHER.find(element.id())[1]?.toLongOrNull() 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 img = element.getInnerImgStyle()
val timeString = abbr.text() val timeString = abbr.text()
val content = val content =
a.text().replace("\u00a0", " ").removeSuffix(timeString).trim() //remove &nbsp; a.text().replace("\u00a0", " ").removeSuffix(timeString).trim() // remove &nbsp;
val thumbnail = element.selectFirst("img.thumbnail")?.attr("src") val thumbnail = element.selectFirst("img.thumbnail")?.attr("src")
return FrostNotif( return FrostNotif(
id = id, id = id,

View File

@ -18,10 +18,8 @@ package com.pitchedapps.frost.fragments
import ca.allanwang.kau.adapters.fastAdapter import ca.allanwang.kau.adapters.fastAdapter
import ca.allanwang.kau.utils.withMainContext import ca.allanwang.kau.utils.withMainContext
import com.mikepenz.fastadapter.FastAdapter
import com.mikepenz.fastadapter.GenericFastAdapter import com.mikepenz.fastadapter.GenericFastAdapter
import com.mikepenz.fastadapter.GenericItem import com.mikepenz.fastadapter.GenericItem
import com.mikepenz.fastadapter.IItem
import com.mikepenz.fastadapter.adapters.ItemAdapter import com.mikepenz.fastadapter.adapters.ItemAdapter
import com.mikepenz.fastadapter.adapters.ModelAdapter import com.mikepenz.fastadapter.adapters.ModelAdapter
import com.pitchedapps.frost.R import com.pitchedapps.frost.R

View File

@ -68,7 +68,7 @@ class NotificationIItem(val notification: FrostNotif, val cookie: String) :
} }
} }
//todo see if necessary // todo see if necessary
val DIFF: DiffCallback<NotificationIItem> by lazy(::Diff) val DIFF: DiffCallback<NotificationIItem> by lazy(::Diff)
} }

View File

@ -71,7 +71,7 @@ abstract class BaseImageIntroFragment(
override fun onPageScrolledImpl(positionOffset: Float) { override fun onPageScrolledImpl(positionOffset: Float) {
super.onPageScrolledImpl(positionOffset) super.onPageScrolledImpl(positionOffset)
val alpha = ((1 - abs(positionOffset)) * 255).toInt() val alpha = ((1 - abs(positionOffset)) * 255).toInt()
//apply alpha to all layers except the phone base // apply alpha to all layers except the phone base
(0 until imageDrawable.numberOfLayers).forEach { (0 until imageDrawable.numberOfLayers).forEach {
val d = imageDrawable.getDrawable(it) val d = imageDrawable.getDrawable(it)
if (d != phone) d.alpha = alpha if (d != phone) d.alpha = alpha

View File

@ -140,7 +140,7 @@ inline fun <reified T : JobService> Context.scheduleJob(id: Int, minutes: Long):
.setPeriodic(minutes * 60000) .setPeriodic(minutes * 60000)
.setExtras(id) .setExtras(id)
.setPersisted(true) .setPersisted(true)
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) //TODO add options .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) // TODO add options
val result = scheduler.schedule(builder.build()) val result = scheduler.schedule(builder.build())
if (result <= 0) { if (result <= 0) {
L.eThrow("${T::class.java.simpleName} scheduler failed") L.eThrow("${T::class.java.simpleName} scheduler failed")

View File

@ -32,6 +32,6 @@ class UpdateReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
if (intent.action != Intent.ACTION_MY_PACKAGE_REPLACED) return if (intent.action != Intent.ACTION_MY_PACKAGE_REPLACED) return
L.d { "Frost has updated" } L.d { "Frost has updated" }
context.scheduleNotifications(Prefs.notificationFreq) //Update notifications context.scheduleNotifications(Prefs.notificationFreq) // Update notifications
} }
} }

View File

@ -144,7 +144,7 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = {
if (it.isBlank()) string(R.string.kau_default) if (it.isBlank()) string(R.string.kau_default)
else RingtoneManager.getRingtone(this@getNotificationPrefs, frostUri(it)) else RingtoneManager.getRingtone(this@getNotificationPrefs, frostUri(it))
?.getTitle(this@getNotificationPrefs) ?.getTitle(this@getNotificationPrefs)
?: "---" //todo figure out why this happens ?: "---" // todo figure out why this happens
} }
onClick = { onClick = {
val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER).apply { val intent = Intent(RingtoneManager.ACTION_RINGTONE_PICKER).apply {

View File

@ -86,7 +86,7 @@ class AnimatedVectorDelegate(
private fun animateImpl(toStart: Boolean) { private fun animateImpl(toStart: Boolean) {
if ((atStart == toStart)) return L.d { "AVD already at ${if (toStart) "start" else "end"}" } if ((atStart == toStart)) return L.d { "AVD already at ${if (toStart) "start" else "end"}" }
if (avd == null) return L.d { "AVD null resource" } //no longer using animated vector; do not modify if (avd == null) return L.d { "AVD null resource" } // no longer using animated vector; do not modify
avd?.stop() avd?.stop()
view.setImageResource(if (toStart) avdEnd else avdStart) view.setImageResource(if (toStart) avdEnd else avdStart)
animatedVectorListener?.invoke(avd!!, !toStart) animatedVectorListener?.invoke(avd!!, !toStart)

View File

@ -25,7 +25,7 @@ import ca.allanwang.kau.kpref.KPref
*/ */
object Showcase : KPref() { object Showcase : KPref() {
//check if this is the first time launching the web overlay; show snackbar if true // check if this is the first time launching the web overlay; show snackbar if true
val firstWebOverlay: Boolean by kprefSingle("first_web_overlay") val firstWebOverlay: Boolean by kprefSingle("first_web_overlay")
val intro: Boolean by kprefSingle("intro_pages") val intro: Boolean by kprefSingle("intro_pages")

View File

@ -242,11 +242,11 @@ fun View.frostSnackbar(@StringRes text: Int, builder: Snackbar.() -> Unit = {})
@SuppressLint("RestrictedApi") @SuppressLint("RestrictedApi")
private inline fun frostSnackbar(crossinline builder: Snackbar.() -> Unit): Snackbar.() -> Unit = { private inline fun frostSnackbar(crossinline builder: Snackbar.() -> Unit): Snackbar.() -> Unit = {
builder() builder()
//hacky workaround, but it has proper checks and shouldn't crash // hacky workaround, but it has proper checks and shouldn't crash
((view as? FrameLayout)?.getChildAt(0) as? SnackbarContentLayout)?.apply { ((view as? FrameLayout)?.getChildAt(0) as? SnackbarContentLayout)?.apply {
messageView.setTextColor(Prefs.textColor) messageView.setTextColor(Prefs.textColor)
actionView.setTextColor(Prefs.accentColor) actionView.setTextColor(Prefs.accentColor)
//only set if previous text colors are set // only set if previous text colors are set
view.setBackgroundColor(Prefs.bgColor.withAlpha(255).colorToForeground(0.1f)) view.setBackgroundColor(Prefs.bgColor.withAlpha(255).colorToForeground(0.1f))
} }
} }
@ -316,10 +316,10 @@ inline val String.isIndirectImageUrl: Boolean
*/ */
inline val String?.isIndependent: Boolean inline val String?.isIndependent: Boolean
get() { get() {
if (this == null || length < 5) return false // ignore short queries if (this == null || length < 5) return false // ignore short queries
if (this[0] == '#' && !contains('/')) return false // ignore element values if (this[0] == '#' && !contains('/')) return false // ignore element values
if (startsWith("http") && !isFacebookUrl) return true // ignore non facebook urls if (startsWith("http") && !isFacebookUrl) return true // ignore non facebook urls
if (dependentSegments.any { contains(it) }) return false // ignore known dependent segments if (dependentSegments.any { contains(it) }) return false // ignore known dependent segments
return true return true
} }

View File

@ -34,7 +34,7 @@ fun Context.showWebContextMenu(wc: WebContext) {
if (wc.isEmpty) return if (wc.isEmpty) return
var title = wc.url ?: string(R.string.menu) var title = wc.url ?: string(R.string.menu)
title = title =
title.substring(title.indexOf("m/") + 1) //just so if defaults to 0 in case it's not .com/ title.substring(title.indexOf("m/") + 1) // just so if defaults to 0 in case it's not .com/
if (title.length > 100) title = title.substring(0, 100) + '\u2026' if (title.length > 100) title = title.substring(0, 100) + '\u2026'
val menuItems = WebContextType.values val menuItems = WebContextType.values
@ -46,7 +46,7 @@ fun Context.showWebContextMenu(wc: WebContext) {
menuItems[position].onClick(this@showWebContextMenu, wc) menuItems[position].onClick(this@showWebContextMenu, wc)
} }
onDismiss { onDismiss {
//showing the dialog interrupts the touch down event, so we must ensure that the viewpager's swipe is enabled // showing the dialog interrupts the touch down event, so we must ensure that the viewpager's swipe is enabled
(this@showWebContextMenu as? MainActivity)?.viewPager?.enableSwipe = true (this@showWebContextMenu as? MainActivity)?.viewPager?.enableSwipe = true
} }
} }

View File

@ -67,7 +67,7 @@ class BadgedIcon @JvmOverloads constructor(
} }
fun setAllAlpha(alpha: Float) { fun setAllAlpha(alpha: Float) {
//badgeTextView.setTextColor(Prefs.textColor.withAlpha(alpha.toInt())) // badgeTextView.setTextColor(Prefs.textColor.withAlpha(alpha.toInt()))
badge_image.drawable.alpha = alpha.toInt() badge_image.drawable.alpha = alpha.toInt()
} }

View File

@ -78,7 +78,7 @@ class FrostJSI(val web: FrostWebView) {
@JavascriptInterface @JavascriptInterface
fun contextMenu(url: String?, text: String?) { fun contextMenu(url: String?, text: String?) {
//url will be formatted through webcontext // url will be formatted through webcontext
web.post { context.showWebContextMenu(WebContext(url.takeIf { it.isIndependent }, text)) } web.post { context.showWebContextMenu(WebContext(url.takeIf { it.isIndependent }, text)) }
} }

View File

@ -106,7 +106,7 @@ class LoginWebView @JvmOverloads constructor(
} }
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean { override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
//For now, we will ignore all attempts to launch external apps during login // For now, we will ignore all attempts to launch external apps during login
if (request.url == null || request.url.scheme == "intent" || request.url.scheme == "android-app") if (request.url == null || request.url.scheme == "intent" || request.url.scheme == "android-app")
return true return true
return super.shouldOverrideUrlLoading(view, request) return super.shouldOverrideUrlLoading(view, request)

View File

@ -1,3 +1,4 @@
v2.4.1 v2.4.1
* Notification tab will keep first page in the same window; fixes marking notifications as read * Notification tab will keep first page in the same window; fixes marking notifications as read
* Fix nav and status bar icon colors for custom themes (Android O+)

View File

@ -8,7 +8,7 @@
<version title="v2.4.1" /> <version title="v2.4.1" />
<item text="Notification tab will keep first page in the same window; fixes marking notifications as read" /> <item text="Notification tab will keep first page in the same window; fixes marking notifications as read" />
<item text="" /> <item text="Fix nav and status bar icon colors for custom themes (Android O+)" />
<item text="" /> <item text="" />
<item text="" /> <item text="" />

View File

@ -103,7 +103,7 @@ class FbUrlTest {
@Test @Test
fun video() { fun video() {
//note that the video numbers have been changed to maintain privacy // note that the video numbers have been changed to maintain privacy
val url = val url =
"/video_redirect/?src=https%3A%2F%2Fvideo-yyz1-1.xx.fbcdn.net%2Fv%2Ft42.1790-2%2F2349078999904_n.mp4%3Fefg%3DeyJ87J9%26oh%3Df5777784%26oe%3D56FD4&source=media_collage&id=1735049&refid=8&_ft_=qid.6484464%3Amf_story_key.-43172431214%3Atop_level_post_id.102773&__tn__=FEH-R" "/video_redirect/?src=https%3A%2F%2Fvideo-yyz1-1.xx.fbcdn.net%2Fv%2Ft42.1790-2%2F2349078999904_n.mp4%3Fefg%3DeyJ87J9%26oh%3Df5777784%26oe%3D56FD4&source=media_collage&id=1735049&refid=8&_ft_=qid.6484464%3Amf_story_key.-43172431214%3Atop_level_post_id.102773&__tn__=FEH-R"
val expected = val expected =

View File

@ -25,7 +25,7 @@ import kotlin.test.assertEquals
*/ */
class PrefsTest { class PrefsTest {
//Replicate logic // Replicate logic
var test: Long = -1L var test: Long = -1L
get() { get() {
if (field == -1L) field = file if (field == -1L) field = file

View File

@ -2,6 +2,7 @@
## v2.4.1 ## v2.4.1
* Notification tab will keep first page in the same window; fixes marking notifications as read * Notification tab will keep first page in the same window; fixes marking notifications as read
* Fix nav and status bar icon colors for custom themes (Android O+)
## v2.4.0 ## v2.4.0
* Removed request services, which potentially caused phishing warnings. * Removed request services, which potentially caused phishing warnings.