1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-11-10 04:52:38 +01:00

Merge pull request #1621 from AllanWang/intro-ui

Intro ui updates
This commit is contained in:
Allan Wang 2020-01-19 21:25:07 -08:00 committed by GitHub
commit a2c491f446
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 41 deletions

View File

@ -22,17 +22,12 @@ import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.view.WindowManager import android.view.WindowManager
import android.widget.Button
import android.widget.ImageButton
import android.widget.ImageView import android.widget.ImageView
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.ViewPager import androidx.viewpager.widget.ViewPager
import ca.allanwang.kau.internal.KauBaseActivity import ca.allanwang.kau.internal.KauBaseActivity
import ca.allanwang.kau.ui.views.RippleCanvas
import ca.allanwang.kau.ui.widgets.InkPageIndicator
import ca.allanwang.kau.utils.bindView
import ca.allanwang.kau.utils.blendWith import ca.allanwang.kau.utils.blendWith
import ca.allanwang.kau.utils.color import ca.allanwang.kau.utils.color
import ca.allanwang.kau.utils.fadeScaleTransition import ca.allanwang.kau.utils.fadeScaleTransition
@ -43,6 +38,7 @@ import ca.allanwang.kau.utils.setIcon
import ca.allanwang.kau.utils.statusBarColor import ca.allanwang.kau.utils.statusBarColor
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
import com.pitchedapps.frost.R import com.pitchedapps.frost.R
import com.pitchedapps.frost.databinding.ActivityIntroBinding
import com.pitchedapps.frost.intro.BaseIntroFragment import com.pitchedapps.frost.intro.BaseIntroFragment
import com.pitchedapps.frost.intro.IntroAccountFragment import com.pitchedapps.frost.intro.IntroAccountFragment
import com.pitchedapps.frost.intro.IntroFragmentAnalytics import com.pitchedapps.frost.intro.IntroFragmentAnalytics
@ -68,12 +64,7 @@ import kotlinx.coroutines.launch
*/ */
class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.OnPageChangeListener { class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.OnPageChangeListener {
val ripple: RippleCanvas by bindView(R.id.intro_ripple) lateinit var binding: ActivityIntroBinding
val viewpager: ViewPager by bindView(R.id.intro_viewpager)
lateinit var adapter: IntroPageAdapter
val indicator: InkPageIndicator by bindView(R.id.intro_indicator)
val skip: Button by bindView(R.id.intro_skip)
val next: ImageButton by bindView(R.id.intro_next)
private var barHasNext = true private var barHasNext = true
val fragments = listOf( val fragments = listOf(
@ -88,12 +79,16 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.On
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_intro) binding = ActivityIntroBinding.inflate(layoutInflater)
adapter = IntroPageAdapter(supportFragmentManager, fragments) setContentView(binding.root)
binding.init()
}
private fun ActivityIntroBinding.init() {
viewpager.apply { viewpager.apply {
setPageTransformer(true, this@IntroActivity) setPageTransformer(true, this@IntroActivity)
addOnPageChangeListener(this@IntroActivity) addOnPageChangeListener(this@IntroActivity)
adapter = this@IntroActivity.adapter adapter = IntroPageAdapter(supportFragmentManager, fragments)
} }
indicator.setViewPager(viewpager) indicator.setViewPager(viewpager)
next.setIcon(GoogleMaterial.Icon.gmd_navigate_next) next.setIcon(GoogleMaterial.Icon.gmd_navigate_next)
@ -109,10 +104,12 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.On
fun theme() { fun theme() {
statusBarColor = Prefs.headerColor statusBarColor = Prefs.headerColor
navigationBarColor = Prefs.headerColor navigationBarColor = Prefs.headerColor
skip.setTextColor(Prefs.textColor) with(binding) {
next.imageTintList = ColorStateList.valueOf(Prefs.textColor) skip.setTextColor(Prefs.textColor)
indicator.setColour(Prefs.textColor) next.imageTintList = ColorStateList.valueOf(Prefs.textColor)
indicator.invalidate() indicator.setColour(Prefs.textColor)
indicator.invalidate()
}
fragments.forEach { it.themeFragment() } fragments.forEach { it.themeFragment() }
setFrostTheme(true) setFrostTheme(true)
} }
@ -141,12 +138,12 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.On
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
) )
ripple.ripple(blue, x, y, 600) { binding.ripple.ripple(blue, x, y, 600) {
postDelayed(1000) { finish() } postDelayed(1000) { finish() }
} }
val lastView: View? = fragments.last().view val lastView: View? = fragments.last().view
arrayOf<View?>( arrayOf<View?>(
skip, indicator, next, binding.skip, binding.indicator, binding.next,
lastView?.findViewById(R.id.intro_title), lastView?.findViewById(R.id.intro_title),
lastView?.findViewById(R.id.intro_desc) lastView?.findViewById(R.id.intro_desc)
).forEach { ).forEach {
@ -186,8 +183,10 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.On
} }
override fun onBackPressed() { override fun onBackPressed() {
if (viewpager.currentItem > 0) viewpager.setCurrentItem(viewpager.currentItem - 1, true) with(binding) {
else finish() if (viewpager.currentItem > 0) viewpager.setCurrentItem(viewpager.currentItem - 1, true)
else finish()
}
} }
override fun onPageScrollStateChanged(state: Int) { override fun onPageScrollStateChanged(state: Int) {
@ -204,13 +203,13 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.On
val hasNext = position != fragments.size - 1 val hasNext = position != fragments.size - 1
if (barHasNext == hasNext) return if (barHasNext == hasNext) return
barHasNext = hasNext barHasNext = hasNext
next.fadeScaleTransition { binding.next.fadeScaleTransition {
setIcon( setIcon(
if (barHasNext) GoogleMaterial.Icon.gmd_navigate_next else GoogleMaterial.Icon.gmd_done, if (barHasNext) GoogleMaterial.Icon.gmd_navigate_next else GoogleMaterial.Icon.gmd_done,
color = Prefs.textColor color = Prefs.textColor
) )
} }
skip.animate().scaleXY(if (barHasNext) 1f else 0f) binding.skip.animate().scaleXY(if (barHasNext) 1f else 0f)
} }
class IntroPageAdapter(fm: FragmentManager, private val fragments: List<BaseIntroFragment>) : class IntroPageAdapter(fm: FragmentManager, private val fragments: List<BaseIntroFragment>) :

View File

@ -56,7 +56,7 @@ class IntroFragmentTheme : BaseIntroFragment(R.layout.intro_theme) {
setOnClickListener { v -> setOnClickListener { v ->
Prefs.theme = theme.ordinal Prefs.theme = theme.ordinal
(activity as IntroActivity).apply { (activity as IntroActivity).apply {
ripple.ripple(Prefs.bgColor, v.x + v.pivotX, v.y + v.pivotY) binding.ripple.ripple(Prefs.bgColor, v.x + v.pivotX, v.y + v.pivotY)
theme() theme()
} }
themeList.forEach { it.animate().scaleXY(if (it == this) 1.6f else 0.8f).start() } themeList.forEach { it.animate().scaleXY(if (it == this) 1.6f else 0.8f).start() }

View File

@ -6,7 +6,7 @@
android:fitsSystemWindows="true"> android:fitsSystemWindows="true">
<ca.allanwang.kau.ui.views.RippleCanvas <ca.allanwang.kau.ui.views.RippleCanvas
android:id="@+id/intro_ripple" android:id="@+id/ripple"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
@ -15,49 +15,49 @@
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Guideline <androidx.constraintlayout.widget.Guideline
android:id="@+id/intro_bar_guide" android:id="@+id/bar_guide"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
app:layout_constraintGuide_end="@dimen/intro_bar_height" /> app:layout_constraintGuide_end="@dimen/intro_bar_height" />
<androidx.viewpager.widget.ViewPager <androidx.viewpager.widget.ViewPager
android:id="@+id/intro_viewpager" android:id="@+id/viewpager"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/intro_bar_guide" app:layout_constraintBottom_toTopOf="@id/bar_guide"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<Button <TextView
android:id="@+id/intro_skip" android:id="@+id/skip"
style="@style/IntroBarButton" style="@style/IntroBarButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="0dp" android:layout_height="0dp"
android:text="@string/skip" android:text="@string/skip"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/intro_bar_guide" /> app:layout_constraintTop_toBottomOf="@id/bar_guide" />
<ca.allanwang.kau.ui.widgets.InkPageIndicator <ca.allanwang.kau.ui.widgets.InkPageIndicator
android:id="@+id/intro_indicator" android:id="@+id/indicator"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5" app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/intro_bar_guide" app:layout_constraintTop_toBottomOf="@id/bar_guide"
app:layout_constraintVertical_bias="0.5" /> app:layout_constraintVertical_bias="0.5" />
<ImageButton <ImageButton
android:id="@+id/intro_next" android:id="@+id/next"
style="@style/IntroBarButton" style="@style/IntroBarButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="0dp" android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/intro_bar_guide" /> app:layout_constraintTop_toBottomOf="@id/bar_guide" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -18,7 +18,7 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<Button <TextView
android:id="@+id/intro_theme_light" android:id="@+id/intro_theme_light"
style="@style/IntroButton" style="@style/IntroButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -32,7 +32,7 @@
app:layout_constraintVertical_bias="0.33" app:layout_constraintVertical_bias="0.33"
tools:layout_editor_absoluteX="112dp" /> tools:layout_editor_absoluteX="112dp" />
<Button <TextView
android:id="@+id/intro_theme_dark" android:id="@+id/intro_theme_dark"
style="@style/IntroButton" style="@style/IntroButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -46,7 +46,7 @@
app:layout_constraintVertical_bias="0.33" app:layout_constraintVertical_bias="0.33"
tools:layout_editor_absoluteX="112dp" /> tools:layout_editor_absoluteX="112dp" />
<Button <TextView
android:id="@+id/intro_theme_amoled" android:id="@+id/intro_theme_amoled"
style="@style/IntroButton" style="@style/IntroButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -60,7 +60,7 @@
app:layout_constraintVertical_bias="0.66" app:layout_constraintVertical_bias="0.66"
tools:layout_editor_absoluteX="112dp" /> tools:layout_editor_absoluteX="112dp" />
<Button <TextView
android:id="@+id/intro_theme_glass" android:id="@+id/intro_theme_glass"
style="@style/IntroButton" style="@style/IntroButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@ -74,6 +74,7 @@
<style name="IntroBarButton" parent="Widget.AppCompat.Button.Borderless"> <style name="IntroBarButton" parent="Widget.AppCompat.Button.Borderless">
<item name="android:elevation">0dp</item> <item name="android:elevation">0dp</item>
<item name="android:minWidth">100dp</item> <item name="android:minWidth">100dp</item>
<item name="android:background">?selectableItemBackground</item>
<item name="android:layout_marginStart">@dimen/kau_padding_small</item> <item name="android:layout_marginStart">@dimen/kau_padding_small</item>
<item name="android:layout_marginEnd">@dimen/kau_padding_small</item> <item name="android:layout_marginEnd">@dimen/kau_padding_small</item>
</style> </style>
@ -94,7 +95,7 @@
<style name="IntroButton" parent="TextAppearance.AppCompat.Button"> <style name="IntroButton" parent="TextAppearance.AppCompat.Button">
<item name="android:elevation">0dp</item> <item name="android:elevation">0dp</item>
<item name="android:background">?android:selectableItemBackgroundBorderless</item> <item name="android:background">?selectableItemBackgroundBorderless</item>
<item name="android:padding">@dimen/kau_padding_large</item> <item name="android:padding">@dimen/kau_padding_large</item>
</style> </style>