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,
|
||||
"todo"
|
||||
).build()
|
||||
|
||||
INSTANCE = instance
|
||||
instance
|
||||
return instance
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import android.view.View
|
|||
import android.widget.Toast
|
||||
import cn.super12138.todo.ToDoApp
|
||||
|
||||
private var clickInterval = 400L
|
||||
private var clickInterval = 380L
|
||||
private var lastTime = 0L
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ package cn.super12138.todo.views.welcome
|
|||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
|
|
@ -25,6 +23,7 @@ import cn.super12138.todo.views.welcome.pages.ToDoItemPage
|
|||
|
||||
class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
||||
private val viewModel by viewModels<WelcomeViewModel>()
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
@ -42,7 +41,6 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
|||
nextBtn.show()
|
||||
previousBtn.show()
|
||||
|
||||
|
||||
if (currentPage.value == 3) {
|
||||
GlobalValues.welcomePage = true
|
||||
finish()
|
||||
|
|
@ -50,28 +48,27 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
|||
startActivity(intent)
|
||||
} else {
|
||||
currentPage.value = 1
|
||||
nextPage(1)
|
||||
}
|
||||
}
|
||||
|
||||
previousBtn.setOnIntervalClickListener {
|
||||
VibrationUtils.performHapticFeedback(it)
|
||||
|
||||
supportFragmentManager.popBackStack()
|
||||
|
||||
currentPage.value = currentPage.value?.minus(1)
|
||||
}
|
||||
|
||||
nextBtn.setOnIntervalClickListener {
|
||||
VibrationUtils.performHapticFeedback(it)
|
||||
|
||||
nextPage(currentPage.value!!.plus(1))
|
||||
|
||||
currentPage.value = currentPage.value?.plus(1)
|
||||
}
|
||||
|
||||
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) {
|
||||
0 -> {
|
||||
centerBtn.apply {
|
||||
|
|
@ -118,6 +115,7 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
|||
if (currentPage.value == 0) {
|
||||
finish()
|
||||
} else {
|
||||
supportFragmentManager.popBackStack()
|
||||
currentPage.value = currentPage.value?.minus(1)
|
||||
}
|
||||
}
|
||||
|
|
@ -137,4 +135,12 @@ class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
|
|||
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