@@ -48,7 +48,6 @@ import com.hyphenate.easeui.common.ChatError
48
48
import com.hyphenate.easeui.common.bus.EaseFlowBus
49
49
import com.hyphenate.easeui.common.extensions.catchChatException
50
50
import com.hyphenate.easeui.common.extensions.hideSoftKeyboard
51
- import com.hyphenate.easeui.common.helper.EasePreferenceManager
52
51
import kotlinx.coroutines.flow.SharingStarted
53
52
import kotlinx.coroutines.flow.onCompletion
54
53
import kotlinx.coroutines.flow.onStart
@@ -311,49 +310,56 @@ class LoginFragment : EaseBaseFragment<DemoFragmentLoginBinding>(), View.OnClick
311
310
}
312
311
}
313
312
314
- private val spannable: SpannableString
313
+ private var spannable: SpannableString ? = null
315
314
private get() {
316
- val language = PreferenceManager .getValue(DemoConstant .APP_LANGUAGE ,Locale .getDefault().language)
317
- val isZh = language.startsWith(" zh" )
318
- val spanStr = SpannableString (getString(R .string.em_login_agreement))
319
- var start1 = 29
320
- var end1 = 45
321
- var start2 = 50
322
- var end2 = spanStr.length
323
- if (isZh) {
324
- start1 = 5
325
- end1 = 13
326
- start2 = 14
327
- end2 = spanStr.length
315
+ if (field == null ) {
316
+ field = createSpannable()
328
317
}
329
- // 设置下划线
330
- // spanStr.setSpan(new UnderlineSpan(), 3, 7, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
331
- spanStr.setSpan(object : MyClickableSpan () {
332
- override fun onClick (widget : View ) {
333
- jumpToAgreement()
334
- }
335
- }, start1, end1, Spanned .SPAN_EXCLUSIVE_EXCLUSIVE )
336
- spanStr.setSpan(
337
- ForegroundColorSpan (ContextCompat .getColor(mContext, com.hyphenate.easeui.R .color.ease_color_primary)),
338
- start1,
339
- end1,
340
- Spanned .SPAN_EXCLUSIVE_EXCLUSIVE
341
- )
318
+ return field
319
+ }
342
320
343
- // spanStr.setSpan(new UnderlineSpan(), 10, 14, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
344
- spanStr.setSpan( object : MyClickableSpan () {
345
- override fun onClick ( widget : View ) {
346
- jumpToProtocol( )
347
- }
348
- }, start2, end2, Spanned . SPAN_EXCLUSIVE_EXCLUSIVE )
349
- spanStr.setSpan(
350
- ForegroundColorSpan ( ContextCompat .getColor(mContext, com.hyphenate.easeui. R .color.ease_color_primary)),
351
- start2,
352
- end2,
353
- Spanned . SPAN_EXCLUSIVE_EXCLUSIVE
354
- )
355
- return spanStr
321
+ private fun createSpannable (): SpannableString {
322
+ val language = PreferenceManager .getValue( DemoConstant . APP_LANGUAGE , Locale .getDefault().language)
323
+ val isZh = language.startsWith( " zh " )
324
+ val spanStr = SpannableString (getString( R .string.em_login_agreement) )
325
+ var start1 = 29
326
+ var end1 = 45
327
+ var start2 = 50
328
+ var end2 = spanStr.length
329
+ if (isZh) {
330
+ start1 = 5
331
+ end1 = 13
332
+ start2 = 14
333
+ end2 = spanStr.length
356
334
}
335
+ // 设置下划线
336
+ // spanStr.setSpan(new UnderlineSpan(), 3, 7, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
337
+ spanStr.setSpan(object : MyClickableSpan () {
338
+ override fun onClick (widget : View ) {
339
+ jumpToAgreement()
340
+ }
341
+ }, start1, end1, Spanned .SPAN_EXCLUSIVE_EXCLUSIVE )
342
+ spanStr.setSpan(
343
+ ForegroundColorSpan (ContextCompat .getColor(mContext, com.hyphenate.easeui.R .color.ease_color_primary)),
344
+ start1,
345
+ end1,
346
+ Spanned .SPAN_EXCLUSIVE_EXCLUSIVE
347
+ )
348
+
349
+ // spanStr.setSpan(new UnderlineSpan(), 10, 14, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
350
+ spanStr.setSpan(object : MyClickableSpan () {
351
+ override fun onClick (widget : View ) {
352
+ jumpToProtocol()
353
+ }
354
+ }, start2, end2, Spanned .SPAN_EXCLUSIVE_EXCLUSIVE )
355
+ spanStr.setSpan(
356
+ ForegroundColorSpan (ContextCompat .getColor(mContext, com.hyphenate.easeui.R .color.ease_color_primary)),
357
+ start2,
358
+ end2,
359
+ Spanned .SPAN_EXCLUSIVE_EXCLUSIVE
360
+ )
361
+ return spanStr
362
+ }
357
363
358
364
override fun onEditorAction (v : TextView , actionId : Int , event : KeyEvent ): Boolean {
359
365
if (actionId == EditorInfo .IME_ACTION_DONE ) {
@@ -422,7 +428,8 @@ class LoginFragment : EaseBaseFragment<DemoFragmentLoginBinding>(), View.OnClick
422
428
}
423
429
424
430
override fun onDestroyView () {
425
- spannable.clearSpans()
431
+ spannable?.clearSpans()
432
+ spannable = null
426
433
super .onDestroyView()
427
434
}
428
435
0 commit comments