Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
S
SuperEasyClean
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
songjianyu
SuperEasyClean
Commits
fd94dcc4
Commit
fd94dcc4
authored
Dec 16, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...BaseFragment.kt
parent
2e61c3b6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
2 deletions
+66
-2
build.gradle.kts
app/build.gradle.kts
+2
-2
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+1
-0
BaseFragment.kt
app/src/main/java/com/base/appzxhy/base/BaseFragment.kt
+63
-0
No files found.
app/build.gradle.kts
View file @
fd94dcc4
...
...
@@ -4,11 +4,11 @@ plugins {
}
android
{
namespace
=
"com.base.
localweatherwhite
"
namespace
=
"com.base.
appzxhy
"
compileSdk
=
34
defaultConfig
{
applicationId
=
"com.base.
localweatherwhite
"
applicationId
=
"com.base.
appzxhy
"
minSdk
=
24
targetSdk
=
34
versionCode
=
1
...
...
app/src/main/AndroidManifest.xml
View file @
fd94dcc4
...
...
@@ -3,6 +3,7 @@
xmlns:tools=
"http://schemas.android.com/tools"
>
<application
android:name=
".MyApplication"
android:allowBackup=
"true"
android:dataExtractionRules=
"@xml/data_extraction_rules"
android:fullBackupContent=
"@xml/backup_rules"
...
...
app/src/main/java/com/base/appzxhy/base/BaseFragment.kt
0 → 100644
View file @
fd94dcc4
@file
:
Suppress
(
"unused"
)
package
com.base.appzxhy.base
import
android.app.Activity
import
android.content.Intent
import
android.os.Bundle
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
androidx.fragment.app.Fragment
import
androidx.viewbinding.ViewBinding
/**
*
* @param VB : ViewBinding
* 基本的fragment绑定数据
*/
abstract
class
BaseFragment
<
VB
:
ViewBinding
>(
private
val
bindingInflater
:
(
LayoutInflater
,
ViewGroup
?,
Boolean
)
->
VB
)
:
Fragment
()
{
private
var
_binding
:
VB
?
=
null
private
var
fragmentInit
=
false
open
val
TAG
=
javaClass
.
simpleName
//重写binding get()方法不直接暴露真实的可空_binding数据
@Suppress
(
"MemberVisibilityCanBePrivate"
)
val
binding
:
VB
get
()
=
_binding
!!
override
fun
onCreateView
(
inflater
:
LayoutInflater
,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?
):
View
{
_binding
=
bindingInflater
.
invoke
(
inflater
,
container
,
false
)
return
binding
.
root
}
open
fun
onResumeOneShoot
()
=
Unit
override
fun
onResume
()
{
if
(!
fragmentInit
)
{
onResumeOneShoot
()
fragmentInit
=
true
}
super
.
onResume
()
}
override
fun
onDestroyView
()
{
super
.
onDestroyView
()
//要手动置null防止内存泄漏
_binding
=
null
}
}
inline
fun
<
VB
:
ViewBinding
>
BaseFragment
<
VB
>.
viewBind
(
block
:
VB
.()
->
Unit
)
{
binding
.
apply
(
block
)
}
inline
fun
Fragment
.
goToAc
(
clazz
:
Class
<
out
Activity
>,
block
:
(
Intent
.()
->
Unit
)
=
{})
{
context
?.
startActivity
(
Intent
(
context
,
clazz
).
apply
(
block
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment