aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt31
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/TabCustomizerActivity.kt34
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt32
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt114
-rw-r--r--app/src/main/res/layout/activity_debug.xml8
-rw-r--r--app/src/main/res/layout/view_video.xml4
6 files changed, 131 insertions, 92 deletions
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 c8177604..b0a148d1 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/DebugActivity.kt
@@ -27,13 +27,13 @@ import ca.allanwang.kau.utils.setIcon
import ca.allanwang.kau.utils.visible
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
import com.pitchedapps.frost.R
+import com.pitchedapps.frost.databinding.ActivityDebugBinding
import com.pitchedapps.frost.facebook.FbItem
import com.pitchedapps.frost.injectors.JsActions
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.createFreshDir
import com.pitchedapps.frost.utils.setFrostColors
-import kotlinx.android.synthetic.main.activity_debug.*
import kotlinx.coroutines.CoroutineExceptionHandler
import java.io.File
import kotlin.coroutines.resume
@@ -51,9 +51,16 @@ class DebugActivity : KauBaseActivity() {
fun baseDir(context: Context) = File(context.externalCacheDir, "offline_debug")
}
+ lateinit var binding: ActivityDebugBinding
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_debug)
+ binding = ActivityDebugBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ binding.init()
+ }
+
+ fun ActivityDebugBinding.init() {
setSupportActionBar(toolbar)
supportActionBar?.apply {
setDisplayHomeAsUpEnabled(true)
@@ -64,10 +71,10 @@ class DebugActivity : KauBaseActivity() {
setFrostColors {
toolbar(toolbar)
}
- debug_webview.loadUrl(FbItem.FEED.url)
- debug_webview.onPageFinished = { swipe_refresh.isRefreshing = false }
+ debugWebview.loadUrl(FbItem.FEED.url)
+ debugWebview.onPageFinished = { swipeRefresh.isRefreshing = false }
- swipe_refresh.setOnRefreshListener(debug_webview::reload)
+ swipeRefresh.setOnRefreshListener(debugWebview::reload)
fab.visible().setIcon(GoogleMaterial.Icon.gmd_bug_report, Prefs.iconColor)
fab.backgroundTintList = ColorStateList.valueOf(Prefs.accentColor)
@@ -85,16 +92,16 @@ class DebugActivity : KauBaseActivity() {
parent.createFreshDir()
val body: String? = suspendCoroutine { cont ->
- debug_webview.evaluateJavascript(JsActions.RETURN_BODY.function) {
+ debugWebview.evaluateJavascript(JsActions.RETURN_BODY.function) {
cont.resume(it)
}
}
val hasScreenshot: Boolean =
- debug_webview.getScreenshot(File(parent, "screenshot.png"))
+ debugWebview.getScreenshot(File(parent, "screenshot.png"))
val intent = Intent()
- intent.putExtra(RESULT_URL, debug_webview.url)
+ intent.putExtra(RESULT_URL, debugWebview.url)
intent.putExtra(RESULT_SCREENSHOT, hasScreenshot)
if (body != null)
intent.putExtra(RESULT_BODY, body)
@@ -111,17 +118,17 @@ class DebugActivity : KauBaseActivity() {
override fun onResume() {
super.onResume()
- debug_webview.resumeTimers()
+ binding.debugWebview.resumeTimers()
}
override fun onPause() {
- debug_webview.pauseTimers()
+ binding.debugWebview.pauseTimers()
super.onPause()
}
override fun onBackPressed() {
- if (debug_webview.canGoBack())
- debug_webview.goBack()
+ if (binding.debugWebview.canGoBack())
+ binding.debugWebview.goBack()
else
super.onBackPressed()
}
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 743a4733..caae8e89 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/TabCustomizerActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/TabCustomizerActivity.kt
@@ -34,6 +34,7 @@ import com.mikepenz.fastadapter.drag.ItemTouchCallback
import com.mikepenz.fastadapter.drag.SimpleDragCallback
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
import com.pitchedapps.frost.R
+import com.pitchedapps.frost.databinding.ActivityTabCustomizerBinding
import com.pitchedapps.frost.db.GenericDao
import com.pitchedapps.frost.db.TAB_COUNT
import com.pitchedapps.frost.db.getTabs
@@ -43,7 +44,6 @@ import com.pitchedapps.frost.iitems.TabIItem
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.setFrostColors
-import kotlinx.android.synthetic.main.activity_tab_customizer.*
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.launch
import org.koin.android.ext.android.inject
@@ -60,16 +60,22 @@ class TabCustomizerActivity : BaseActivity() {
private val wobble = lazyContext { AnimationUtils.loadAnimation(it, R.anim.rotate_delta) }
+ private lateinit var binding: ActivityTabCustomizerBinding
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_tab_customizer)
+ binding = ActivityTabCustomizerBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ binding.init()
+ }
- pseudo_toolbar.setBackgroundColor(Prefs.headerColor)
+ fun ActivityTabCustomizerBinding.init() {
+ pseudoToolbar.setBackgroundColor(Prefs.headerColor)
- tab_recycler.layoutManager =
- GridLayoutManager(this, TAB_COUNT, RecyclerView.VERTICAL, false)
- tab_recycler.adapter = adapter
- tab_recycler.setHasFixedSize(true)
+ tabRecycler.layoutManager =
+ GridLayoutManager(this@TabCustomizerActivity, TAB_COUNT, RecyclerView.VERTICAL, false)
+ tabRecycler.adapter = adapter
+ tabRecycler.setHasFixedSize(true)
divider.setBackgroundColor(Prefs.textColor.withAlpha(30))
instructions.setTextColor(Prefs.textColor)
@@ -82,16 +88,16 @@ class TabCustomizerActivity : BaseActivity() {
tabs.addAll(remaining)
adapter.set(tabs.map(::TabIItem))
- bindSwapper(adapter, tab_recycler)
+ bindSwapper(adapter, tabRecycler)
adapter.onClickListener = { view, _, _, _ -> view!!.wobble(); true }
}
setResult(Activity.RESULT_CANCELED)
- fab_save.setIcon(GoogleMaterial.Icon.gmd_check, Prefs.iconColor)
- fab_save.backgroundTintList = ColorStateList.valueOf(Prefs.accentColor)
- fab_save.setOnClickListener {
+ fabSave.setIcon(GoogleMaterial.Icon.gmd_check, Prefs.iconColor)
+ fabSave.backgroundTintList = ColorStateList.valueOf(Prefs.accentColor)
+ fabSave.setOnClickListener {
launchMain(NonCancellable) {
val tabs = adapter.adapterItems.subList(0, TAB_COUNT).map(TabIItem::item)
genericDao.saveTabs(tabs)
@@ -99,9 +105,9 @@ class TabCustomizerActivity : BaseActivity() {
finish()
}
}
- fab_cancel.setIcon(GoogleMaterial.Icon.gmd_close, Prefs.iconColor)
- fab_cancel.backgroundTintList = ColorStateList.valueOf(Prefs.accentColor)
- fab_cancel.setOnClickListener { finish() }
+ fabCancel.setIcon(GoogleMaterial.Icon.gmd_close, Prefs.iconColor)
+ fabCancel.backgroundTintList = ColorStateList.valueOf(Prefs.accentColor)
+ fabCancel.setOnClickListener { finish() }
setFrostColors {
themeWindow = true
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt
index 19bf9f69..097aea32 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/BadgedIcon.kt
@@ -19,6 +19,7 @@ package com.pitchedapps.frost.views
import android.content.Context
import android.graphics.drawable.GradientDrawable
import android.util.AttributeSet
+import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import ca.allanwang.kau.utils.colorToForeground
import ca.allanwang.kau.utils.dpToPx
@@ -27,9 +28,8 @@ import ca.allanwang.kau.utils.toDrawable
import ca.allanwang.kau.utils.visible
import ca.allanwang.kau.utils.withAlpha
import com.mikepenz.iconics.typeface.IIcon
-import com.pitchedapps.frost.R
+import com.pitchedapps.frost.databinding.ViewBadgedIconBinding
import com.pitchedapps.frost.utils.Prefs
-import kotlinx.android.synthetic.main.view_badged_icon.view.*
/**
* Created by Allan Wang on 2017-06-19.
@@ -40,8 +40,14 @@ class BadgedIcon @JvmOverloads constructor(
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
+ private val binding: ViewBadgedIconBinding =
+ ViewBadgedIconBinding.inflate(LayoutInflater.from(context), this, true)
+
init {
- inflate(context, R.layout.view_badged_icon, this)
+ binding.init()
+ }
+
+ fun ViewBadgedIconBinding.init() {
val badgeColor =
Prefs.mainActivityLayout.backgroundColor().withAlpha(255).colorToForeground(0.2f)
val badgeBackground =
@@ -50,14 +56,14 @@ class BadgedIcon @JvmOverloads constructor(
intArrayOf(badgeColor, badgeColor)
)
badgeBackground.cornerRadius = 13.dpToPx.toFloat()
- badge_text.background = badgeBackground
- badge_text.setTextColor(Prefs.mainActivityLayout.iconColor())
+ badgeText.background = badgeBackground
+ badgeText.setTextColor(Prefs.mainActivityLayout.iconColor())
}
var iicon: IIcon? = null
set(value) {
field = value
- badge_image.setImageDrawable(
+ binding.badgeImage.setImageDrawable(
value?.toDrawable(
context,
sizeDp = 20,
@@ -68,15 +74,17 @@ class BadgedIcon @JvmOverloads constructor(
fun setAllAlpha(alpha: Float) {
// badgeTextView.setTextColor(Prefs.textColor.withAlpha(alpha.toInt()))
- badge_image.drawable.alpha = alpha.toInt()
+ binding.badgeImage.drawable.alpha = alpha.toInt()
}
var badgeText: String?
- get() = badge_text.text.toString()
+ get() = binding.badgeText.text.toString()
set(value) {
- if (badge_text.text == value) return
- badge_text.text = value
- if (value != null && value != "0") badge_text.visible()
- else badge_text.gone()
+ with(binding) {
+ if (badgeText.text == value) return
+ badgeText.text = value
+ if (value != null && value != "0") badgeText.visible()
+ else badgeText.gone()
+ }
}
}
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 3889300d..bc565527 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt
@@ -21,6 +21,7 @@ import android.graphics.Color
import android.graphics.PointF
import android.net.Uri
import android.util.AttributeSet
+import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.ViewTreeObserver
import android.widget.FrameLayout
@@ -28,7 +29,6 @@ import ca.allanwang.kau.utils.fadeIn
import ca.allanwang.kau.utils.fadeOut
import ca.allanwang.kau.utils.gone
import ca.allanwang.kau.utils.goneIf
-import ca.allanwang.kau.utils.inflate
import ca.allanwang.kau.utils.isColorDark
import ca.allanwang.kau.utils.isGone
import ca.allanwang.kau.utils.isVisible
@@ -40,13 +40,13 @@ import ca.allanwang.kau.utils.withMinAlpha
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.currentCookie
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
import com.pitchedapps.frost.utils.ctxCoroutine
import com.pitchedapps.frost.utils.frostDownload
-import kotlinx.android.synthetic.main.view_video.view.*
/**
* Created by Allan Wang on 2017-10-13.
@@ -78,31 +78,37 @@ class FrostVideoViewer @JvmOverloads constructor(
container.addView(videoViewer)
videoViewer.bringToFront()
videoViewer.setVideo(url, repeat)
- videoViewer.video.containerContract = contract
- videoViewer.video.onFinishedListener =
+ videoViewer.binding.video.containerContract = contract
+ videoViewer.binding.video.onFinishedListener =
{ container.removeView(videoViewer); contract.onVideoFinished() }
return videoViewer
}
}
+ private val binding: ViewVideoBinding =
+ ViewVideoBinding.inflate(LayoutInflater.from(context), this, true)
+
init {
- inflate(R.layout.view_video, true)
+ binding.init()
+ }
+
+ fun ViewVideoBinding.init() {
alpha = 0f
- video_background.setBackgroundColor(
+ videoBackground.setBackgroundColor(
if (!Prefs.blackMediaBg && Prefs.bgColor.isColorDark)
Prefs.bgColor.withMinAlpha(200)
else
Color.BLACK
)
- video.setViewerContract(this)
+ video.setViewerContract(this@FrostVideoViewer)
video.pause()
- video_toolbar.inflateMenu(R.menu.menu_video)
+ videoToolbar.inflateMenu(R.menu.menu_video)
context.setMenuIcons(
- video_toolbar.menu, Prefs.iconColor,
+ videoToolbar.menu, Prefs.iconColor,
R.id.action_pip to GoogleMaterial.Icon.gmd_picture_in_picture_alt,
R.id.action_download to GoogleMaterial.Icon.gmd_file_download
)
- video_toolbar.setOnMenuItemClickListener {
+ videoToolbar.setOnMenuItemClickListener {
when (it.itemId) {
R.id.action_pip -> video.isExpanded = false
R.id.action_download -> context.ctxCoroutine.launchMain {
@@ -113,19 +119,21 @@ class FrostVideoViewer @JvmOverloads constructor(
}
true
}
- video_restart.gone().setIcon(GoogleMaterial.Icon.gmd_replay, 64)
- video_restart.setOnClickListener {
+ videoRestart.gone().setIcon(GoogleMaterial.Icon.gmd_replay, 64)
+ videoRestart.setOnClickListener {
video.restart()
- video_restart.fadeOut { video_restart.gone() }
+ videoRestart.fadeOut { videoRestart.gone() }
}
}
fun setVideo(url: String, repeat: Boolean = false) {
- L.d { "Load video; repeat: $repeat" }
- L._d { "Video Url: $url" }
- animate().alpha(1f).setDuration(FrostVideoView.ANIMATION_DURATION).start()
- video.setVideoURI(Uri.parse(url))
- video.repeat = repeat
+ with(binding) {
+ L.d { "Load video; repeat: $repeat" }
+ L._d { "Video Url: $url" }
+ animate().alpha(1f).setDuration(FrostVideoView.ANIMATION_DURATION).start()
+ video.setVideoURI(Uri.parse(url))
+ video.repeat = repeat
+ }
}
/**
@@ -133,15 +141,17 @@ class FrostVideoViewer @JvmOverloads constructor(
* returns true if consumed, false otherwise
*/
fun onBackPressed(): Boolean {
- parent ?: return false
- if (video.isExpanded)
- video.isExpanded = false
- else
- video.destroy()
- return true
+ with(binding) {
+ parent ?: return false
+ if (video.isExpanded)
+ video.isExpanded = false
+ else
+ video.destroy()
+ return true
+ }
}
- fun pause() = video.pause()
+ fun pause() = binding.video.pause()
/*
* -------------------------------------------------------------
@@ -150,43 +160,55 @@ class FrostVideoViewer @JvmOverloads constructor(
*/
override fun onExpand(progress: Float) {
- video_toolbar.goneIf(progress == 0f).alpha = progress
- video_background.alpha = progress
+ with(binding) {
+ videoToolbar.goneIf(progress == 0f).alpha = progress
+ videoBackground.alpha = progress
+ }
}
override fun onSingleTapConfirmed(event: MotionEvent): Boolean {
- if (video_restart.isVisible) {
- video_restart.performClick()
- return true
+ with(binding) {
+ if (videoRestart.isVisible) {
+ videoRestart.performClick()
+ return true
+ }
+ return false
}
- return false
}
override fun onVideoComplete() {
- video.jumpToStart()
- video_restart.fadeIn()
+ with(binding) {
+ video.jumpToStart()
+ videoRestart.fadeIn()
+ }
}
fun updateLocation() {
- viewTreeObserver.addOnGlobalLayoutListener(object :
- ViewTreeObserver.OnGlobalLayoutListener {
- override fun onGlobalLayout() {
- video.updateLocation()
- viewTreeObserver.removeOnGlobalLayoutListener(this)
- }
- })
+ with(binding) {
+ viewTreeObserver.addOnGlobalLayoutListener(object :
+ ViewTreeObserver.OnGlobalLayoutListener {
+ override fun onGlobalLayout() {
+ video.updateLocation()
+ viewTreeObserver.removeOnGlobalLayoutListener(this)
+ }
+ })
+ }
}
override fun onControlsShown() {
- if (video.isExpanded)
- video_toolbar.fadeIn(
- duration = CONTROL_ANIMATION_DURATION,
- onStart = { video_toolbar.visible() })
+ with(binding) {
+ if (video.isExpanded)
+ videoToolbar.fadeIn(
+ duration = CONTROL_ANIMATION_DURATION,
+ onStart = { videoToolbar.visible() })
+ }
}
override fun onControlsHidden() {
- if (!video_toolbar.isGone)
- video_toolbar.fadeOut(duration = CONTROL_ANIMATION_DURATION) { video_toolbar.gone() }
+ with(binding) {
+ if (!videoToolbar.isGone)
+ videoToolbar.fadeOut(duration = CONTROL_ANIMATION_DURATION) { videoToolbar.gone() }
+ }
}
}
diff --git a/app/src/main/res/layout/activity_debug.xml b/app/src/main/res/layout/activity_debug.xml
index d2f9a397..8480053b 100644
--- a/app/src/main/res/layout/activity_debug.xml
+++ b/app/src/main/res/layout/activity_debug.xml
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -9,12 +8,9 @@
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
- android:layout_width="match_parent"
- android:layout_height="?attr/actionBarSize"
+ style="@style/Main.Toolbar"
android:background="?attr/colorPrimary"
- android:theme="@style/AppTheme.AppBarOverlay"
- app:layout_scrollFlags="scroll|enterAlways"
- app:popupTheme="@style/AppTheme.PopupOverlay" />
+ android:theme="@style/AppTheme.AppBarOverlay" />
<com.pitchedapps.frost.views.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
diff --git a/app/src/main/res/layout/view_video.xml b/app/src/main/res/layout/view_video.xml
index 69e75135..56cdeb6c 100644
--- a/app/src/main/res/layout/view_video.xml
+++ b/app/src/main/res/layout/view_video.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<merge xmlns:android="http://schemas.android.com/apk/res/android"
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/video_container"
android:layout_width="match_parent"
@@ -38,4 +38,4 @@
android:background="@drawable/exomedia_default_controls_interactive_background"
android:layout_height="?attr/actionBarSize" />
-</merge> \ No newline at end of file
+</FrameLayout> \ No newline at end of file