Skip to content

Commit 78f4b3f

Browse files
committed
fix:HttpOptions去掉实现Serializable,HttpLoadingFragment构造函数去掉参数
1 parent 26fb439 commit 78f4b3f

7 files changed

Lines changed: 51 additions & 31 deletions

File tree

FlowHttp/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66

77
//ext.GROUP = "com.lute.network"
88
//ext.POM_ARTIFACT_ID = "NetCore-Flow"
9-
//ext.VERSION_NAME = "1.6.3"
9+
//ext.VERSION_NAME = "1.6.4"
1010
////引用gradle_upload.gradle
1111
//apply from: "${project.rootDir}/maven_upload.gradle"
1212

@@ -19,7 +19,7 @@ afterEvaluate {
1919
// 这里头是artifacts的配置信息,不填会采用默认的
2020
groupId = 'com.github.buhuiming'
2121
artifactId = 'NetCore-Flow'
22-
version = '1.6.3'
22+
version = '1.6.4'
2323

2424
from components.release
2525
artifact androidSourcesJar //打包源码,去除这行打的包将看不到源码

FlowHttp/src/main/java/com/bhm/network/base/HttpLoadingDialog.kt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ open class HttpLoadingDialog {
1313

1414
private var showAgain = false
1515

16+
companion object {
17+
const val KEY_DIALOG_CANCELABLE = "key_dialog_cancelable"
18+
19+
const val KEY_DIALOG_DIALOG_DISMISS_INTERRUPT_REQUEST = "key_dialog_dialogDismissInterruptRequest"
20+
21+
const val KEY_JOB_ID = "key_job_id"
22+
23+
const val KEY_DIALOG_LOADING_TITLE = "key_dialog_loading_title"
24+
}
25+
1626
/**
1727
* rxManager 用户按返回关闭,请求取消
1828
* isCancelable true,单击返回键,dialog关闭;false,1s内双击返回键,dialog关闭,否则dialog不关闭
@@ -42,10 +52,17 @@ open class HttpLoadingDialog {
4252
httpLoadingFragment = null
4353
}
4454

45-
open fun initDialog(builder: HttpOptions): HttpLoadingFragment {
55+
private fun initDialog(builder: HttpOptions): HttpLoadingFragment {
56+
val bundle = Bundle()
57+
bundle.putBoolean(KEY_DIALOG_CANCELABLE, builder.isCancelable)
58+
bundle.putBoolean(KEY_DIALOG_DIALOG_DISMISS_INTERRUPT_REQUEST, builder.isDialogDismissInterruptRequest)
59+
bundle.putString(KEY_JOB_ID, builder.jobKey)
60+
bundle.putString(KEY_DIALOG_LOADING_TITLE, builder.loadingTitle)
61+
return getLoadingFragment(bundle)
62+
}
63+
64+
open fun getLoadingFragment(bundle: Bundle): HttpLoadingFragment {
4665
return HttpLoadingFragment().apply {
47-
val bundle = Bundle()
48-
bundle.putSerializable("httpOptions", builder)
4966
arguments = bundle
5067
}
5168
}

FlowHttp/src/main/java/com/bhm/network/base/HttpLoadingFragment.kt

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
44
import android.app.Dialog
55
import android.content.Context
66
import android.content.DialogInterface
7-
import android.os.Build
87
import android.os.Bundle
98
import android.text.TextUtils
109
import android.view.KeyEvent
@@ -13,26 +12,34 @@ import android.widget.TextView
1312
import androidx.fragment.app.DialogFragment
1413
import androidx.fragment.app.FragmentManager
1514
import com.bhm.network.R
15+
import com.bhm.network.base.HttpLoadingDialog.Companion.KEY_DIALOG_CANCELABLE
16+
import com.bhm.network.base.HttpLoadingDialog.Companion.KEY_DIALOG_DIALOG_DISMISS_INTERRUPT_REQUEST
17+
import com.bhm.network.base.HttpLoadingDialog.Companion.KEY_DIALOG_LOADING_TITLE
18+
import com.bhm.network.base.HttpLoadingDialog.Companion.KEY_JOB_ID
1619
import com.bhm.network.core.HttpOptions
1720
import com.bhm.network.core.JobManager
18-
import java.util.*
21+
import java.util.Objects
1922

2023
open class HttpLoadingFragment : DialogFragment() {
2124

2225
private var textView: TextView? = null
2326

2427
private var cancelDialogEvent: (() -> Unit)? = null
2528

26-
var builder: HttpOptions? = null
29+
var dialogCancelable: Boolean = false
30+
31+
var isDialogDismissInterruptRequest: Boolean = false
32+
33+
var jobKey: String = ""
34+
35+
var loadingTitle: String = ""
2736

2837
override fun onAttach(context: Context) {
2938
super.onAttach(context)
30-
builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
31-
arguments?.getSerializable("httpOptions", HttpOptions::class.java)
32-
} else {
33-
@Suppress("DEPRECATION")
34-
arguments?.getSerializable("httpOptions") as HttpOptions?
35-
}
39+
dialogCancelable = arguments?.getBoolean(KEY_DIALOG_CANCELABLE)?: false
40+
isDialogDismissInterruptRequest = arguments?.getBoolean(KEY_DIALOG_DIALOG_DISMISS_INTERRUPT_REQUEST)?: false
41+
jobKey = arguments?.getString(KEY_JOB_ID)?: ""
42+
loadingTitle = arguments?.getString(KEY_DIALOG_LOADING_TITLE)?: ""
3643
}
3744

3845
override fun show(manager: FragmentManager, tag: String?) {
@@ -88,14 +95,14 @@ open class HttpLoadingFragment : DialogFragment() {
8895
if (activity != null) {
8996
dialog.setOwnerActivity(requireActivity())
9097
dialog.setCanceledOnTouchOutside(false) //这个值最好设置成false,点击其他区域关闭loading,体验效果不佳
91-
dialog.setCancelable(builder?.isCancelable?: false)
98+
dialog.setCancelable(dialogCancelable)
9299
dialog.setOnKeyListener(DialogInterface.OnKeyListener { _, i, keyEvent ->
93100
if (i == KeyEvent.KEYCODE_BACK && dialog.isShowing
94101
&& keyEvent.action == KeyEvent.ACTION_UP
95102
) {
96-
if (builder?.isCancelable == true) {
97-
if (builder?.isDialogDismissInterruptRequest == true) {
98-
JobManager.get().removeJob(builder?.jobKey?: "")
103+
if (dialogCancelable) {
104+
if (isDialogDismissInterruptRequest) {
105+
JobManager.get().removeJob(jobKey)
99106
}
100107
cancelDialogEvent?.invoke()
101108
if (cancelDialogEvent == null) {
@@ -106,7 +113,7 @@ open class HttpLoadingFragment : DialogFragment() {
106113
if (System.currentTimeMillis() - onBackPressed > 1000) {
107114
onBackPressed = System.currentTimeMillis()
108115
} else {
109-
JobManager.get().removeJob(builder?.jobKey?: "")
116+
JobManager.get().removeJob(jobKey)
110117
cancelDialogEvent?.invoke()
111118
if (cancelDialogEvent == null) {
112119
dismiss()
@@ -132,8 +139,8 @@ open class HttpLoadingFragment : DialogFragment() {
132139
) // 设置布局
133140
textView = it.findViewById(R.id.dialog_text_loading)
134141
}
135-
if (!TextUtils.isEmpty(builder?.loadingTitle)) {
136-
textView?.text = builder?.loadingTitle
142+
if (!TextUtils.isEmpty(loadingTitle)) {
143+
textView?.text = loadingTitle
137144
}
138145
return dialog
139146
}

FlowHttp/src/main/java/com/bhm/network/core/HttpOptions.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ import com.bhm.network.define.DATA_KEY
1616
import com.bhm.network.define.MESSAGE_KEY
1717
import com.bhm.network.define.OK_CODE
1818
import okhttp3.OkHttpClient
19-
import java.io.Serializable
2019

2120
/**
2221
* Created by bhm on 2023/5/6.
2322
*/
24-
class HttpOptions(private val builder: Builder) : Serializable {
23+
class HttpOptions(private val builder: Builder) {
2524
var currentRequestDateTamp: Long = 0
2625
val activity: FragmentActivity
2726
get() = builder.activity

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111

1212
dependencies {
13-
implementation 'com.github.buhuiming:NetCore-Flow:1.6.3'
13+
implementation 'com.github.buhuiming:NetCore-Flow:1.6.4'
1414
}
1515

1616
#### 1、Application配置默认的全局配置项(可选)

app/src/main/java/com/bhm/sdk/demo/tools/MyHttpLoadingDialog.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ import com.bhm.network.base.HttpLoadingFragment
99
* Created by bhm on 2023/5/6.
1010
*/
1111
class MyHttpLoadingDialog : HttpLoadingDialog() {
12-
override fun initDialog(builder: HttpOptions): HttpLoadingFragment {
12+
override fun getLoadingFragment(bundle: Bundle): HttpLoadingFragment {
1313
return MyHttpLoadingFragment().apply {
14-
val bundle = Bundle()
15-
bundle.putSerializable("httpOptions", builder)
1614
arguments = bundle
1715
}
1816
}

app/src/main/java/com/bhm/sdk/demo/tools/MyHttpLoadingFragment.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import android.view.LayoutInflater
77
import android.view.ViewGroup
88
import android.widget.TextView
99
import com.bhm.netcore.R
10-
import com.bhm.network.core.HttpOptions
1110
import com.bhm.network.base.HttpLoadingFragment
1211

1312
class MyHttpLoadingFragment : HttpLoadingFragment() {
@@ -16,17 +15,17 @@ class MyHttpLoadingFragment : HttpLoadingFragment() {
1615
@SuppressLint("InflateParams") val v =
1716
inflater.inflate(R.layout.layout_my_loading, null) // 得到加载view
1817
val dialog = Dialog(requireActivity(), com.bhm.network.R.style.loading_dialog) // 创建自定义样式dialog
19-
dialog.setCancelable(builder?.isCancelable?: false) // false不可以用“返回键”取消
18+
dialog.setCancelable(dialogCancelable) // false不可以用“返回键”取消
2019
dialog.setCanceledOnTouchOutside(false)
2120
dialog.setContentView(
2221
v, ViewGroup.LayoutParams(
2322
ViewGroup.LayoutParams.MATCH_PARENT,
2423
ViewGroup.LayoutParams.MATCH_PARENT
2524
)
2625
) // 设置布局
27-
if (!TextUtils.isEmpty(builder?.loadingTitle)) {
26+
if (!TextUtils.isEmpty(loadingTitle)) {
2827
val textView = v.findViewById<TextView>(R.id.dialog_text_loading)
29-
textView.text = builder?.loadingTitle
28+
textView.text = loadingTitle
3029
}
3130
return dialog
3231
}

0 commit comments

Comments
 (0)