-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
增加Fragment基类
- Loading branch information
Showing
6 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package win.regin.base | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.annotation.LayoutRes | ||
import androidx.fragment.app.Fragment | ||
|
||
/** | ||
* @author :Reginer in 2019/11/23 10:00. | ||
* 联系方式:QQ:282921012 | ||
* 功能描述:Fragment基类,普通Activity继承 | ||
*/ | ||
abstract class BaseFragment : Fragment() { | ||
/** | ||
* 获取布局id | ||
* | ||
* @return layoutId | ||
*/ | ||
@LayoutRes | ||
protected abstract fun getLayoutId(): Int | ||
|
||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
return inflater.inflate(getLayoutId(), container, false); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package win.regin.base | ||
|
||
import android.os.Bundle | ||
import androidx.lifecycle.ViewModelProvider | ||
import win.regin.base.ext.getVmClazz | ||
|
||
/** | ||
* @author :Reginer in 2019/11/23 10:11. | ||
* 联系方式:QQ:282921012 | ||
* 功能描述:ViewModelFragment基类,ViewModelFragment继承 | ||
*/ | ||
abstract class BaseVmFragment<VM : BaseViewModel> : BaseFragment() { | ||
|
||
protected lateinit var mViewModel: VM | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
mViewModel = createViewModel() | ||
createObserver() | ||
} | ||
|
||
/** | ||
* 创建viewModel | ||
*/ | ||
private fun createViewModel(): VM { | ||
return ViewModelProvider(this).get(getVmClazz(this) as Class<VM>) | ||
} | ||
|
||
/** | ||
* 创建观察者 | ||
*/ | ||
protected abstract fun createObserver() | ||
} |
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