-
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
51 changed files
with
28,910 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.fizzer.base.lib"> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
</manifest> |
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
39 changes: 38 additions & 1 deletion
39
FizzerBaseLib/src/main/java/com/fizzer/base/lib/android/act/BaseActivity.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,12 +1,49 @@ | ||
package com.fizzer.base.lib.android.act | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.os.Process | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.lifecycle.lifecycleScope | ||
import kotlinx.coroutines.delay | ||
|
||
/** | ||
* @Author: Fizzer | ||
* @Email: fizzer503@sina.com | ||
* @Date: 2023/12/23 | ||
* @Descriptor: 基类Activity | ||
*/ | ||
open class BaseActivity : AppCompatActivity() { | ||
abstract class BaseActivity : AppCompatActivity() { | ||
|
||
/** | ||
* 重启APP | ||
*/ | ||
fun restartApp() { | ||
val restartIntent = packageName?.let { | ||
packageManager?.getLaunchIntentForPackage(it) | ||
} | ||
restartIntent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK) | ||
Process.killProcess(Process.myPid()) | ||
startActivity(restartIntent) | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
preInit() | ||
initView() | ||
initEvent() | ||
lifecycleScope.launchWhenResumed() { | ||
delay(500) | ||
lazyInitData() | ||
} | ||
} | ||
|
||
|
||
/** | ||
* 主要是在这里面做一些预初始化的东西,比如说intent取值的获取 | ||
*/ | ||
open fun preInit(){ } | ||
abstract fun initView() | ||
abstract fun initEvent() | ||
abstract fun lazyInitData() | ||
} |
18 changes: 18 additions & 0 deletions
18
FizzerBaseLib/src/main/java/com/fizzer/base/lib/android/act/BaseVBActivity.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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.fizzer.base.lib.android.act | ||
|
||
import android.os.Bundle | ||
import androidx.viewbinding.ViewBinding | ||
|
||
/** | ||
* 使用了ViewBinding的Activity基类 | ||
*/ | ||
abstract class BaseVBActivity<VB : ViewBinding> : BaseActivity() { | ||
lateinit var binding: VB | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
binding = bindingInflate() | ||
setContentView(binding.root) | ||
super.onCreate(savedInstanceState) | ||
} | ||
|
||
abstract fun bindingInflate(): VB | ||
} |
37 changes: 37 additions & 0 deletions
37
FizzerBaseLib/src/main/java/com/fizzer/base/lib/android/act/BaseVMActivity.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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.fizzer.base.lib.android.act | ||
|
||
import android.os.Bundle | ||
import android.widget.Toast | ||
import androidx.lifecycle.ViewModelProvider | ||
import androidx.lifecycle.lifecycleScope | ||
import androidx.viewbinding.ViewBinding | ||
import com.fizzer.base.lib.android.BaseViewModel | ||
|
||
/** | ||
* 使用了ViewBinding 和ViewModel的Activity基类 | ||
*/ | ||
abstract class BaseVMActivity<VB : ViewBinding, VM : BaseViewModel> : BaseVBActivity<VB>() { | ||
|
||
var mViewModel: VM? = null | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
getViewModel()?.let { | ||
mViewModel = ViewModelProvider(this)[it] | ||
} | ||
super.onCreate(savedInstanceState) | ||
lifecycleScope.launchWhenResumed { | ||
initBaseViewModel() | ||
} | ||
} | ||
|
||
/** | ||
* 初始化基类的ViewModel | ||
*/ | ||
private fun initBaseViewModel() { | ||
//Toast | ||
mViewModel?.toastLiveData?.observe(this) { | ||
Toast.makeText(this, it, Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
|
||
abstract fun getViewModel(): Class<VM>? | ||
} |
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ open class App : Application() { | |
|
||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
mApplication = this | ||
} | ||
} |
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
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
34 changes: 34 additions & 0 deletions
34
FizzerBaseLib/src/main/java/com/fizzer/base/lib/utils/NetUtils.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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.fizzer.base.lib.utils | ||
|
||
import android.content.Context | ||
import android.net.ConnectivityManager | ||
import android.net.NetworkCapabilities | ||
import android.os.Build | ||
import androidx.annotation.RequiresApi | ||
|
||
/** | ||
* @Author: Fizzer | ||
* @Email: fizzer503@sina.com | ||
* @Date: 2024/2/2 | ||
* @Descriptor: 手机网络状态的工具类 | ||
*/ | ||
object NetUtils { | ||
/** | ||
* 获取当前网络是否已连接 | ||
*/ | ||
fun isNetWorkConnected(context: Context?): Boolean { | ||
return context?.let { | ||
val connect = it.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
val netWork = connect.activeNetwork | ||
val caption = connect.getNetworkCapabilities(netWork) | ||
caption?.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) ?: false || | ||
caption?.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) ?: false | ||
} else { | ||
val netInfo = connect.activeNetworkInfo | ||
netInfo?.isConnectedOrConnecting | ||
} | ||
true | ||
} ?: false | ||
} | ||
} |
Oops, something went wrong.