Improve fragment motion
This commit is contained in:
parent
1bf5a83ad7
commit
007668fa97
3 changed files with 18 additions and 11 deletions
|
|
@ -19,8 +19,9 @@ abstract class ToDoRoomDB : RoomDatabase() {
|
||||||
ToDoRoomDB::class.java,
|
ToDoRoomDB::class.java,
|
||||||
"todo"
|
"todo"
|
||||||
).build()
|
).build()
|
||||||
|
|
||||||
INSTANCE = instance
|
INSTANCE = instance
|
||||||
instance
|
return instance
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import android.view.View
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import cn.super12138.todo.ToDoApp
|
import cn.super12138.todo.ToDoApp
|
||||||
|
|
||||||
private var clickInterval = 400L
|
private var clickInterval = 380L
|
||||||
private var lastTime = 0L
|
private var lastTime = 0L
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ package cn.super12138.todo.views.welcome
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.MotionEvent
|
|
||||||
import android.view.View
|
|
||||||
import androidx.activity.OnBackPressedCallback
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.appcompat.content.res.AppCompatResources
|
import androidx.appcompat.content.res.AppCompatResources
|
||||||
|
|
@ -25,6 +23,7 @@ import cn.super12138.todo.views.welcome.pages.ToDoItemPage
|
||||||
|
|
||||||
class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
||||||
private val viewModel by viewModels<WelcomeViewModel>()
|
private val viewModel by viewModels<WelcomeViewModel>()
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
@ -42,7 +41,6 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
||||||
nextBtn.show()
|
nextBtn.show()
|
||||||
previousBtn.show()
|
previousBtn.show()
|
||||||
|
|
||||||
|
|
||||||
if (currentPage.value == 3) {
|
if (currentPage.value == 3) {
|
||||||
GlobalValues.welcomePage = true
|
GlobalValues.welcomePage = true
|
||||||
finish()
|
finish()
|
||||||
|
|
@ -50,28 +48,27 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
} else {
|
} else {
|
||||||
currentPage.value = 1
|
currentPage.value = 1
|
||||||
|
nextPage(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
previousBtn.setOnIntervalClickListener {
|
previousBtn.setOnIntervalClickListener {
|
||||||
VibrationUtils.performHapticFeedback(it)
|
VibrationUtils.performHapticFeedback(it)
|
||||||
|
|
||||||
|
supportFragmentManager.popBackStack()
|
||||||
|
|
||||||
currentPage.value = currentPage.value?.minus(1)
|
currentPage.value = currentPage.value?.minus(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
nextBtn.setOnIntervalClickListener {
|
nextBtn.setOnIntervalClickListener {
|
||||||
VibrationUtils.performHapticFeedback(it)
|
VibrationUtils.performHapticFeedback(it)
|
||||||
|
|
||||||
|
nextPage(currentPage.value!!.plus(1))
|
||||||
|
|
||||||
currentPage.value = currentPage.value?.plus(1)
|
currentPage.value = currentPage.value?.plus(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
currentPage.observe(this, Observer { page ->
|
currentPage.observe(this, Observer { page ->
|
||||||
supportFragmentManager.commit {
|
|
||||||
addToBackStack(System.currentTimeMillis().toString())
|
|
||||||
hide(supportFragmentManager.fragments.last())
|
|
||||||
add(R.id.welcome_page_container, getCurrentPage(page))
|
|
||||||
}
|
|
||||||
|
|
||||||
when (page) {
|
when (page) {
|
||||||
0 -> {
|
0 -> {
|
||||||
centerBtn.apply {
|
centerBtn.apply {
|
||||||
|
|
@ -118,6 +115,7 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
||||||
if (currentPage.value == 0) {
|
if (currentPage.value == 0) {
|
||||||
finish()
|
finish()
|
||||||
} else {
|
} else {
|
||||||
|
supportFragmentManager.popBackStack()
|
||||||
currentPage.value = currentPage.value?.minus(1)
|
currentPage.value = currentPage.value?.minus(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -137,4 +135,12 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
||||||
else -> IntroPage()
|
else -> IntroPage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun nextPage(page: Int) {
|
||||||
|
supportFragmentManager.commit {
|
||||||
|
addToBackStack(System.currentTimeMillis().toString())
|
||||||
|
hide(supportFragmentManager.fragments.last())
|
||||||
|
add(R.id.welcome_page_container, getCurrentPage(page))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue