Last active
June 23, 2019 19:13
-
-
Save Chullian/16a1df87aefb3a7c7326edabca512f89 to your computer and use it in GitHub Desktop.
Revisions
-
Chullian revised this gist
Jun 23, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ abstract class BaseActivity<T : BaseViewModel> : AppCompatActivity(), BaseView { protected abstract val layoutId: Int -
Chullian created this gist
Jun 23, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ abstract class BaseActivity<T : BaseViewModel> : FragmentActivity(), BaseView { protected abstract val layoutId: Int protected abstract val containerId: Int protected abstract val viewModelClass: Class<T> protected val viewModel: T by lazy(LazyThreadSafetyMode.NONE) { ViewModelProviders.of(this).get(viewModelClass) } abstract fun observeLiveData() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(layoutId) observeAllLiveData() } private fun observeAllLiveData() { observeLiveData() } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) supportFragmentManager.findFragmentById(containerId)?.onActivityResult(requestCode, resultCode, data) } protected open fun replaceFragment(fragment: Fragment, name: String, needToAddToBackStack: Boolean = true) { hideKeyboard() with(supportFragmentManager.beginTransaction()) { replace(containerId, fragment, name) if (needToAddToBackStack) { addToBackStack(name) } commit() } } protected open fun addFragment(fragment: Fragment, name: String, needToAddToBackStack: Boolean = true) { hideKeyboard() with(supportFragmentManager.beginTransaction()) { add(containerId, fragment, name) if (needToAddToBackStack) { addToBackStack(name) } commit() } } override fun createViewModelFactory(): ViewModelProvider.NewInstanceFactory? = null override fun isNeedProgress(): Boolean = true }