diff options
Diffstat (limited to 'app')
3 files changed, 34 insertions, 36 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt index 464f2385..c76cad16 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/IntroActivity.kt @@ -22,18 +22,12 @@ import android.graphics.Color import android.os.Bundle import android.view.View import android.view.WindowManager -import android.widget.Button -import android.widget.ImageButton import android.widget.ImageView -import android.widget.TextView import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentPagerAdapter import androidx.viewpager.widget.ViewPager 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.color import ca.allanwang.kau.utils.fadeScaleTransition @@ -44,6 +38,7 @@ import ca.allanwang.kau.utils.setIcon import ca.allanwang.kau.utils.statusBarColor import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial import com.pitchedapps.frost.R +import com.pitchedapps.frost.databinding.ActivityIntroBinding import com.pitchedapps.frost.intro.BaseIntroFragment import com.pitchedapps.frost.intro.IntroAccountFragment import com.pitchedapps.frost.intro.IntroFragmentAnalytics @@ -69,12 +64,7 @@ import kotlinx.coroutines.launch */ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.OnPageChangeListener { - val ripple: RippleCanvas by bindView(R.id.intro_ripple) - val viewpager: ViewPager by bindView(R.id.intro_viewpager) - lateinit var adapter: IntroPageAdapter - val indicator: InkPageIndicator by bindView(R.id.intro_indicator) - val skip: TextView by bindView(R.id.intro_skip) - val next: ImageButton by bindView(R.id.intro_next) + lateinit var binding: ActivityIntroBinding private var barHasNext = true val fragments = listOf( @@ -89,12 +79,16 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.On override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_intro) - adapter = IntroPageAdapter(supportFragmentManager, fragments) + binding = ActivityIntroBinding.inflate(layoutInflater) + setContentView(binding.root) + binding.init() + } + + private fun ActivityIntroBinding.init() { viewpager.apply { setPageTransformer(true, this@IntroActivity) addOnPageChangeListener(this@IntroActivity) - adapter = this@IntroActivity.adapter + adapter = IntroPageAdapter(supportFragmentManager, fragments) } indicator.setViewPager(viewpager) next.setIcon(GoogleMaterial.Icon.gmd_navigate_next) @@ -110,10 +104,12 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.On fun theme() { statusBarColor = Prefs.headerColor navigationBarColor = Prefs.headerColor - skip.setTextColor(Prefs.textColor) - next.imageTintList = ColorStateList.valueOf(Prefs.textColor) - indicator.setColour(Prefs.textColor) - indicator.invalidate() + with(binding) { + skip.setTextColor(Prefs.textColor) + next.imageTintList = ColorStateList.valueOf(Prefs.textColor) + indicator.setColour(Prefs.textColor) + indicator.invalidate() + } fragments.forEach { it.themeFragment() } setFrostTheme(true) } @@ -142,12 +138,12 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.On 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() } } val lastView: View? = fragments.last().view arrayOf<View?>( - skip, indicator, next, + binding.skip, binding.indicator, binding.next, lastView?.findViewById(R.id.intro_title), lastView?.findViewById(R.id.intro_desc) ).forEach { @@ -187,8 +183,10 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.On } override fun onBackPressed() { - if (viewpager.currentItem > 0) viewpager.setCurrentItem(viewpager.currentItem - 1, true) - else finish() + with(binding) { + if (viewpager.currentItem > 0) viewpager.setCurrentItem(viewpager.currentItem - 1, true) + else finish() + } } override fun onPageScrollStateChanged(state: Int) { @@ -205,13 +203,13 @@ class IntroActivity : KauBaseActivity(), ViewPager.PageTransformer, ViewPager.On val hasNext = position != fragments.size - 1 if (barHasNext == hasNext) return barHasNext = hasNext - next.fadeScaleTransition { + binding.next.fadeScaleTransition { setIcon( if (barHasNext) GoogleMaterial.Icon.gmd_navigate_next else GoogleMaterial.Icon.gmd_done, 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>) : diff --git a/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroFragmentTheme.kt b/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroFragmentTheme.kt index d760d416..64d675e1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroFragmentTheme.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/intro/IntroFragmentTheme.kt @@ -56,7 +56,7 @@ class IntroFragmentTheme : BaseIntroFragment(R.layout.intro_theme) { setOnClickListener { v -> Prefs.theme = theme.ordinal (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() } themeList.forEach { it.animate().scaleXY(if (it == this) 1.6f else 0.8f).start() } diff --git a/app/src/main/res/layout/activity_intro.xml b/app/src/main/res/layout/activity_intro.xml index 3f9dfa1a..5ea43adf 100644 --- a/app/src/main/res/layout/activity_intro.xml +++ b/app/src/main/res/layout/activity_intro.xml @@ -6,7 +6,7 @@ android:fitsSystemWindows="true"> <ca.allanwang.kau.ui.views.RippleCanvas - android:id="@+id/intro_ripple" + android:id="@+id/ripple" android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="parent" @@ -15,49 +15,49 @@ app:layout_constraintTop_toTopOf="parent" /> <androidx.constraintlayout.widget.Guideline - android:id="@+id/intro_bar_guide" + android:id="@+id/bar_guide" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" app:layout_constraintGuide_end="@dimen/intro_bar_height" /> <androidx.viewpager.widget.ViewPager - android:id="@+id/intro_viewpager" + android:id="@+id/viewpager" android:layout_width="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_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView - android:id="@+id/intro_skip" + android:id="@+id/skip" style="@style/IntroBarButton" android:layout_width="wrap_content" android:layout_height="0dp" android:text="@string/skip" app:layout_constraintBottom_toBottomOf="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 - android:id="@+id/intro_indicator" + android:id="@+id/indicator" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" 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" /> <ImageButton - android:id="@+id/intro_next" + android:id="@+id/next" style="@style/IntroBarButton" android:layout_width="wrap_content" android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="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>
\ No newline at end of file |