From 6b85bc72a864e65d99ae65802ce03f977a98c906 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 11 Mar 2018 22:21:40 -0400 Subject: misc (#781) * Rename image vars * Add black media option, resolves #726 * Update changelog * Fix menu parsin * Update changelog * Fix menu badges --- .../pitchedapps/frost/activities/ImageActivity.kt | 36 ++++++++++++---------- .../pitchedapps/frost/facebook/requests/Menu.kt | 9 ++++-- .../com/pitchedapps/frost/iitems/MenuIItem.kt | 5 ++- .../kotlin/com/pitchedapps/frost/rx/RxFlyweight.kt | 2 +- .../com/pitchedapps/frost/settings/Appearance.kt | 6 ++++ .../kotlin/com/pitchedapps/frost/utils/Prefs.kt | 2 ++ .../pitchedapps/frost/views/FrostVideoViewer.kt | 6 +++- .../main/res/values/strings_pref_appearance.xml | 2 ++ app/src/main/res/xml/frost_changelog.xml | 3 ++ .../pitchedapps/frost/facebook/FbRequestTest.kt | 1 + docs/Changelog.md | 5 +++ 11 files changed, 54 insertions(+), 23 deletions(-) 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 9f191460..1bc3334f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt @@ -86,28 +86,30 @@ class ImageActivity : KauBaseActivity() { private val L = KauLoggerExtension("Image", com.pitchedapps.frost.utils.L) } - val IMAGE_URL: String by lazy { intent.getStringExtra(ARG_IMAGE_URL).trim('"') } + val imageUrl: String by lazy { intent.getStringExtra(ARG_IMAGE_URL).trim('"') } - private val TEXT: String? by lazy { intent.getStringExtra(ARG_TEXT) } + private val imageText: String? by lazy { intent.getStringExtra(ARG_TEXT) } // a unique image identifier based on the id (if it exists), and its hash - private val IMAGE_HASH: String by lazy { - "${Math.abs(FB_IMAGE_ID_MATCHER.find(IMAGE_URL)[1]?.hashCode() - ?: 0)}_${Math.abs(IMAGE_URL.hashCode())}" + private val imageHash: String by lazy { + "${Math.abs(FB_IMAGE_ID_MATCHER.find(imageUrl)[1]?.hashCode() + ?: 0)}_${Math.abs(imageUrl.hashCode())}" } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) intent?.extras ?: return finish() L.i { "Displaying image" } - L.v { "Displaying image $IMAGE_URL" } - val layout = if (!TEXT.isNullOrBlank()) R.layout.activity_image else R.layout.activity_image_textless + L.v { "Displaying image $imageUrl" } + val layout = if (!imageText.isNullOrBlank()) R.layout.activity_image else R.layout.activity_image_textless setContentView(layout) - container.setBackgroundColor(Prefs.bgColor.withMinAlpha(222)) - caption?.setTextColor(Prefs.textColor) - caption?.setBackgroundColor(Prefs.bgColor.colorToForeground(0.2f).withAlpha(255)) - caption?.text = TEXT - progress.tint(Prefs.accentColor) + container.setBackgroundColor(if (Prefs.blackMediaBg) Color.BLACK + else Prefs.bgColor.withMinAlpha(222)) + caption?.setTextColor(if (Prefs.blackMediaBg) Color.WHITE else Prefs.textColor) + caption?.setBackgroundColor((if (Prefs.blackMediaBg) Color.BLACK else Prefs.bgColor) + .colorToForeground(0.2f).withAlpha(255)) + caption?.text = imageText + progress.tint(if (Prefs.blackMediaBg) Color.WHITE else Prefs.accentColor) panel?.addPanelSlideListener(object : SlidingUpPanelLayout.SimplePanelSlideListener() { override fun onPanelSlide(panel: View, slideOffset: Float) { if (slideOffset == 0f && !fab.isShown) fab.show() @@ -120,7 +122,7 @@ class ImageActivity : KauBaseActivity() { override fun onImageLoadError(e: Exception?) { errorRef = e e.logFrostAnswers("Image load error") - L.e { "Failed to load image $IMAGE_URL" } + L.e { "Failed to load image $imageUrl" } tempFile?.delete() fabAction = FabStates.ERROR } @@ -129,7 +131,7 @@ class ImageActivity : KauBaseActivity() { themeWindow = false } doAsync({ - L.e(it) { "Failed to load image $IMAGE_HASH" } + L.e(it) { "Failed to load image $imageHash" } errorRef = it runOnUiThread { progress.fadeOut() } tempFile?.delete() @@ -156,7 +158,7 @@ class ImageActivity : KauBaseActivity() { * Returns a file pointing to the image, or null if something goes wrong */ private inline fun loadImage(callback: (file: File?) -> Unit) { - val local = File(tempDir, IMAGE_HASH) + val local = File(tempDir, imageHash) if (local.exists() && local.length() > 1) { local.setLastModified(System.currentTimeMillis()) L.d { "Loading from local cache ${local.absolutePath}" } @@ -204,7 +206,7 @@ class ImageActivity : KauBaseActivity() { } private fun getImageResponse() = Request.Builder() - .url(IMAGE_URL) + .url(imageUrl) .get() .call() .execute() @@ -279,7 +281,7 @@ internal enum class FabStates(val iicon: IIcon, val iconColor: Int = Prefs.iconC if (activity.errorRef != null) L.e(activity.errorRef) { "ImageActivity error report" } activity.sendFrostEmail(R.string.debug_image_link_subject) { - addItem("Url", activity.IMAGE_URL) + addItem("Url", activity.imageUrl) addItem("Message", activity.errorRef?.message ?: "Null") } } 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 6f327662..e83e4e43 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 @@ -125,7 +125,7 @@ data class MenuItem(val id: String? = null, val name: String? = null, val pic: String? = null, val url: String? = null, - val count: Int = 0, + val badge: String? = null, val countDetails: String? = null) : MenuItemData { @JsonCreator constructor( @@ -133,10 +133,13 @@ data class MenuItem(val id: String? = null, @JsonProperty("name") name: String?, @JsonProperty("pic") pic: String?, @JsonProperty("url") url: String?, - @JsonProperty("count") count: Int?, + @JsonProperty("count") badge: String?, @JsonProperty("count_details") countDetails: String?, @JsonProperty("fake") fake: Boolean? - ) : this(id, name, pic?.formattedFbUrl, url?.formattedFbUrl, count ?: 0, countDetails) + ) : this(id, name, pic?.formattedFbUrl, + url?.formattedFbUrl, + if (badge == "0") null else badge, + countDetails) override val isValid: Boolean get() = !name.isNullOrBlank() && !url.isNullOrBlank() diff --git a/app/src/main/kotlin/com/pitchedapps/frost/iitems/MenuIItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/iitems/MenuIItem.kt index f5b1df17..4a7356b0 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/iitems/MenuIItem.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/iitems/MenuIItem.kt @@ -48,10 +48,13 @@ class MenuContentIItem(val data: MenuItem) else icon.gone() content.text = item.data.name + badge.text = item.data.badge } override fun unbindView(item: MenuContentIItem) { - badge.gone() + GlideApp.with(itemView).clear(icon) + content.text = null + badge.text = null } } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/rx/RxFlyweight.kt b/app/src/main/kotlin/com/pitchedapps/frost/rx/RxFlyweight.kt index 5d2c78ed..d174cfec 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/rx/RxFlyweight.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/rx/RxFlyweight.kt @@ -60,7 +60,7 @@ abstract class RxFlyweight { val newSource = createNewSource(input).cache().doOnError { sources.remove(input) } - sources.put(input, newSource) + sources[input] = newSource return newSource } } 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 07aff0aa..eeeca01f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Appearance.kt @@ -157,4 +157,10 @@ fun SettingsActivity.getAppearancePrefs(): KPrefAdapterBuilder.() -> Unit = { KPrefSeekbar.KPrefSeekbarBuilder( globalOptions, R.string.web_text_scaling, Prefs::webTextScaling, { Prefs.webTextScaling = it; setFrostResult(REQUEST_TEXT_ZOOM) }))) + + checkbox(R.string.enforce_black_media_bg, Prefs::blackMediaBg, { + Prefs.blackMediaBg = it + }) { + descRes = R.string.enforce_black_media_bg_desc + } } \ No newline at end of file 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 6db3f83c..26d7894e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -163,6 +163,8 @@ object Prefs : KPref() { var mainActivityLayoutType: Int by kpref("main_activity_layout_type", 0) + var blackMediaBg: Boolean by kpref("black_media_bg", false) + inline val mainActivityLayout: MainActivityLayout get() = MainActivityLayout(mainActivityLayoutType) 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 ceb3d487..2d5e376d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt @@ -59,7 +59,11 @@ class FrostVideoViewer @JvmOverloads constructor( init { inflate(R.layout.view_video, true) alpha = 0f - background.setBackgroundColor(if (Prefs.bgColor.isColorDark) Prefs.bgColor.withMinAlpha(200) else Color.BLACK) + background.setBackgroundColor( + if (!Prefs.blackMediaBg && Prefs.bgColor.isColorDark) + Prefs.bgColor.withMinAlpha(200) + else + Color.BLACK) video.setViewerContract(this) video.pause() toolbar.inflateMenu(R.menu.menu_video) diff --git a/app/src/main/res/values/strings_pref_appearance.xml b/app/src/main/res/values/strings_pref_appearance.xml index a179b096..4f74bae3 100644 --- a/app/src/main/res/values/strings_pref_appearance.xml +++ b/app/src/main/res/values/strings_pref_appearance.xml @@ -26,4 +26,6 @@ Web Text Scaling Text Scaling Example; Long press the percentage text to reset. + Enforce black media background + Make media backgrounds black; default is the selected background above \ No newline at end of file diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml index 2b343ba5..de90da73 100644 --- a/app/src/main/res/xml/frost_changelog.xml +++ b/app/src/main/res/xml/frost_changelog.xml @@ -12,6 +12,9 @@ + + + diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRequestTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRequestTest.kt index 9f44779f..07e02249 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRequestTest.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRequestTest.kt @@ -66,6 +66,7 @@ class FbRequestTest { val data = AUTH.getMenuData().invoke() assertNotNull(data) println(ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(data!!)) + assertTrue(data.data.isNotEmpty()) assertTrue(data.footer.hasContent, "Footer may be badly parsed") val items = data.flatMapValid() assertTrue(items.size > 15, "Something may be badly parsed") diff --git a/docs/Changelog.md b/docs/Changelog.md index 561fe768..26ed8ad7 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -3,6 +3,11 @@ ## v1.8.3 * Add full notification channel support * Fix sound spam for multiple notifications +* Send feedback if no new notifications exist after manual refresh +* Automatically refresh if idled for a long time +* Clean up url queries +* Add option to force black background for media views +* Fix menu fragment parsing ## v1.8.2 * Fix duplicate notification sounds -- cgit v1.2.3