@@ -76,10 +76,15 @@ fun TextView.injectPanguText(injectHint: Boolean = true, config: PanguTextConfig
7676fun TextView.injectRealTimePanguText (injectHint : Boolean = true, config : PanguTextConfig = PanguText .globalConfig) {
7777 if (! config.isEnabled) return
7878 val observerKey = R .id.tag_inject_real_time_pangu_text
79- if (getTag<Boolean >(observerKey) == true ) return run {
80- Log .w(PangutextAndroidProperties .PROJECT_NAME , " Duplicate injection of real-time PanguText ($this )." )
81- }
82- setTag(observerKey, injectHint)
79+ var lastSetTimes = getTag<Int >(observerKey) ? : 0
80+ setTag(observerKey, ++ lastSetTimes)
81+ // Only print warning log once after one time.
82+ if (lastSetTimes == 2 ) Log .w(
83+ PangutextAndroidProperties .PROJECT_NAME ,
84+ " Duplicate injection of real-time PanguText ($this ), subsequent operations will be ignored."
85+ )
86+ // It will no longer be executed if it exceeds one time.
87+ if (lastSetTimes > 1 ) return
8388 injectPanguText(injectHint, config)
8489 var currentHint = this .hint
8590 val textWatcher = PanguTextWatcher (base = this , config)
@@ -97,7 +102,7 @@ fun TextView.injectRealTimePanguText(injectHint: Boolean = true, config: PanguTe
97102 removeTextChangedListener(textWatcher)
98103 // Remove the global layout listener when the view is detached.
99104 if (injectHint) viewTreeObserver?.removeOnGlobalLayoutListener(listener)
100- setTag(observerKey, false )
105+ setTag(observerKey, 0 )
101106 }
102107 }
103108}
0 commit comments