-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
185 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 0 additions & 56 deletions
56
.../java/kr/co/lion/application/finalproject_aparttalk/ui/info/EditUserInfoNumberFragment.kt
This file was deleted.
Oops, something went wrong.
132 changes: 32 additions & 100 deletions
132
app/src/main/java/kr/co/lion/application/finalproject_aparttalk/ui/info/InfoActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,59 @@ | ||
package kr.co.lion.application.finalproject_aparttalk.ui.info | ||
|
||
import android.os.Bundle | ||
import android.os.SystemClock | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.FragmentManager | ||
import com.google.android.material.transition.MaterialSharedAxis | ||
import androidx.lifecycle.ViewModelProvider | ||
import kr.co.lion.application.finalproject_aparttalk.R | ||
import kr.co.lion.application.finalproject_aparttalk.databinding.ActivityInfoBinding | ||
import kr.co.lion.application.finalproject_aparttalk.db.local.LocalUserDataSource | ||
import kr.co.lion.application.finalproject_aparttalk.db.remote.UserDataSource | ||
import kr.co.lion.application.finalproject_aparttalk.repository.UserRepository | ||
import kr.co.lion.application.finalproject_aparttalk.util.InfoFragmentName | ||
|
||
class InfoActivity : AppCompatActivity() { | ||
lateinit var binding: ActivityInfoBinding | ||
|
||
// 프래그먼트의 주소값을 담을 프로퍼티 | ||
var oldFragment: Fragment? = null | ||
var newFragment: Fragment? = null | ||
lateinit var userViewModel: UserViewModel | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_info) | ||
|
||
binding = ActivityInfoBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
// ViewModel 초기화 | ||
val userRepository = UserRepository(UserDataSource(), LocalUserDataSource(this)) | ||
userViewModel = ViewModelProvider(this, UserViewModelFactory(userRepository)).get(UserViewModel::class.java) | ||
|
||
// FireCheckMainFragment 나타나도록 한다. | ||
replaceFragment(InfoFragmentName.INFO_FRAGMENT, false, false, null) | ||
} | ||
|
||
// 지정한 Fragment를 보여주는 메서드 | ||
// name : 프래그먼트 이름 | ||
// addToBackStack : BackStack에 포함 시킬 것인지 | ||
// isAnimate : 애니메이션을 보여줄 것인지 | ||
// data : 새로운 프래그먼트에 전달할 값이 담겨져 있는 Bundle 객체 | ||
fun replaceFragment(name: InfoFragmentName, addToBackStack:Boolean, isAnimate:Boolean, data:Bundle?){ | ||
|
||
SystemClock.sleep(200) | ||
|
||
// Fragment를 교체할 수 있는 객체를 추출한다. | ||
val fragmentTransaction = supportFragmentManager.beginTransaction() | ||
|
||
// oldFragment에 newFragment가 가지고 있는 Fragment 객체를 담아준다. | ||
if(newFragment != null){ | ||
oldFragment = newFragment | ||
// 초기 프래그먼트 설정 | ||
if (savedInstanceState == null) { | ||
replaceFragment(InfoFragmentName.INFO_FRAGMENT, false, false, null) | ||
} | ||
} | ||
|
||
// 이름으로 분기한다. | ||
// Fragment의 객체를 생성하여 변수에 담아준다. | ||
when(name){ | ||
InfoFragmentName.INFO_FRAGMENT -> { | ||
newFragment = InfoFragment() | ||
} | ||
InfoFragmentName.EDIT_USER_INFO_FRAGMENT -> { | ||
newFragment = EditUserInfoFragment() | ||
} | ||
InfoFragmentName.EDIT_USER_INFO_NUMBER_FRAGMENT -> { | ||
newFragment = EditUserInfoNumberFragment() | ||
} | ||
fun replaceFragment( | ||
fragmentName: InfoFragmentName, | ||
addToBackStack: Boolean, | ||
clearBackStack: Boolean, | ||
args: Bundle? | ||
) { | ||
val fragment: Fragment = when (fragmentName) { | ||
InfoFragmentName.INFO_FRAGMENT -> InfoFragment() | ||
InfoFragmentName.EDIT_USER_INFO_FRAGMENT -> EditUserInfoFragment() | ||
} | ||
|
||
// 새로운 Fragment에 전달할 객체가 있다면 arguments 프로퍼티에 넣어준다. | ||
if(data != null){ | ||
newFragment?.arguments = data | ||
if (args != null) { | ||
fragment.arguments = args | ||
} | ||
|
||
if(newFragment != null){ | ||
|
||
// 애니메이션 설정 | ||
if(isAnimate == true){ | ||
// oldFragment -> newFragment | ||
// oldFragment : exitTransition | ||
// newFragment : enterTransition | ||
|
||
// newFragment -> oldFragment | ||
// oldFragment : reenterTransition | ||
// newFragment : returnTransition | ||
val transaction = supportFragmentManager.beginTransaction() | ||
transaction.replace(R.id.infoFragmentContainerView, fragment) | ||
|
||
// MaterialSharedAxis : 좌우, 위아래, 공중 바닥 사이로 이동하는 애니메이션 효과 | ||
// X - 좌우 | ||
// Y - 위아래 | ||
// Z - 공중 바닥 | ||
// 두 번째 매개변수 : 새로운 화면이 나타나는 것인지 여부를 설정해준다. | ||
// true : 새로운 화면이 나타나는 애니메이션이 동작한다. | ||
// false : 이전으로 되돌아가는 애니메이션이 동작한다. | ||
|
||
if(oldFragment != null){ | ||
// old에서 new가 새롭게 보여질 때 old의 애니메이션 | ||
oldFragment?.exitTransition = MaterialSharedAxis(MaterialSharedAxis.X, true) | ||
// new에서 old로 되돌아갈때 old의 애니메이션 | ||
oldFragment?.reenterTransition = MaterialSharedAxis(MaterialSharedAxis.X, false) | ||
|
||
oldFragment?.enterTransition = null | ||
oldFragment?.returnTransition = null | ||
} | ||
|
||
// old에서 new가 새롭게 보여질 때 new의 애니메이션 | ||
newFragment?.enterTransition = MaterialSharedAxis(MaterialSharedAxis.X, true) | ||
// new에서 old로 되돌아갈때 new의 애니메이션 | ||
newFragment?.returnTransition = MaterialSharedAxis(MaterialSharedAxis.X, false) | ||
|
||
newFragment?.exitTransition = null | ||
newFragment?.reenterTransition = null | ||
} | ||
|
||
// Fragment를 교체한다.(이전 Fragment가 없으면 새롭게 추가하는 역할을 수행한다) | ||
// 첫 번째 매개 변수 : Fragment를 배치할 FragmentContainerView의 ID | ||
// 두 번째 매개 변수 : 보여주고하는 Fragment 객체를 | ||
fragmentTransaction.replace(R.id.infoFragmentContainerView, newFragment!!) | ||
|
||
// addToBackStack 변수의 값이 true면 새롭게 보여질 Fragment를 BackStack에 포함시켜 준다. | ||
if(addToBackStack == true){ | ||
// BackStack 포함 시킬때 이름을 지정해주면 원하는 Fragment를 BackStack에서 제거할 수 있다. | ||
fragmentTransaction.addToBackStack(name.str) | ||
} | ||
// Fragment 교체를 확정한다. | ||
fragmentTransaction.commit() | ||
if (addToBackStack) { | ||
transaction.addToBackStack(null) | ||
} | ||
} | ||
|
||
// BackStack에서 Fragment를 제거한다. | ||
fun removeFragment(name: InfoFragmentName){ | ||
SystemClock.sleep(200) | ||
if (clearBackStack) { | ||
supportFragmentManager.popBackStack(null, androidx.fragment.app.FragmentManager.POP_BACK_STACK_INCLUSIVE) | ||
} | ||
|
||
// 지정한 이름으로 있는 Fragment를 BackStack에서 제거한다. | ||
supportFragmentManager.popBackStack(name.str, FragmentManager.POP_BACK_STACK_INCLUSIVE) | ||
transaction.commit() | ||
} | ||
} |
Oops, something went wrong.