refactor(ReceiverUtil): 重构

This commit is contained in:
HuanCheng65 2023-01-26 12:30:41 +08:00
parent e4f4a357be
commit 4b1a2e084b
No known key found for this signature in database
GPG Key ID: E9031EF91A805148
3 changed files with 10 additions and 13 deletions

View File

@ -44,8 +44,8 @@ import com.huanchengfly.tieba.post.ui.utils.isSeparating
import com.huanchengfly.tieba.post.utils.AccountUtil import com.huanchengfly.tieba.post.utils.AccountUtil
import com.huanchengfly.tieba.post.utils.JobServiceUtil import com.huanchengfly.tieba.post.utils.JobServiceUtil
import com.huanchengfly.tieba.post.utils.PermissionUtils import com.huanchengfly.tieba.post.utils.PermissionUtils
import com.huanchengfly.tieba.post.utils.ReceiverUtil
import com.huanchengfly.tieba.post.utils.TiebaUtil import com.huanchengfly.tieba.post.utils.TiebaUtil
import com.huanchengfly.tieba.post.utils.newIntentFilter
import com.huanchengfly.tieba.post.utils.requestPermission import com.huanchengfly.tieba.post.utils.requestPermission
import com.ramcosta.composedestinations.DestinationsNavHost import com.ramcosta.composedestinations.DestinationsNavHost
import com.ramcosta.composedestinations.animations.defaults.RootNavGraphDefaultAnimations import com.ramcosta.composedestinations.animations.defaults.RootNavGraphDefaultAnimations
@ -137,7 +137,7 @@ class MainActivityV2 : BaseComposeActivity() {
ContextCompat.registerReceiver( ContextCompat.registerReceiver(
this, this,
newMessageReceiver, newMessageReceiver,
ReceiverUtil.createIntentFilter(NotifyJobService.ACTION_NEW_MESSAGE), newIntentFilter(NotifyJobService.ACTION_NEW_MESSAGE),
ContextCompat.RECEIVER_NOT_EXPORTED ContextCompat.RECEIVER_NOT_EXPORTED
) )
startService(Intent(this, NotifyJobService::class.java)) startService(Intent(this, NotifyJobService::class.java))

View File

@ -268,13 +268,13 @@ open class MainActivity : BaseActivity(), NavigationBarView.OnItemSelectedListen
ContextCompat.registerReceiver( ContextCompat.registerReceiver(
this, this,
newMessageReceiver, newMessageReceiver,
ReceiverUtil.createIntentFilter(NotifyJobService.ACTION_NEW_MESSAGE), newIntentFilter(NotifyJobService.ACTION_NEW_MESSAGE),
ContextCompat.RECEIVER_NOT_EXPORTED ContextCompat.RECEIVER_NOT_EXPORTED
) )
ContextCompat.registerReceiver( ContextCompat.registerReceiver(
this, this,
accountSwitchReceiver, accountSwitchReceiver,
ReceiverUtil.createIntentFilter(AccountUtil.ACTION_SWITCH_ACCOUNT), newIntentFilter(AccountUtil.ACTION_SWITCH_ACCOUNT),
ContextCompat.RECEIVER_NOT_EXPORTED ContextCompat.RECEIVER_NOT_EXPORTED
) )
try { try {

View File

@ -1,11 +1,8 @@
package com.huanchengfly.tieba.post.utils; package com.huanchengfly.tieba.post.utils
import android.content.IntentFilter; import android.content.IntentFilter
public class ReceiverUtil { fun newIntentFilter(action: String) =
public static IntentFilter createIntentFilter(String action) { IntentFilter().apply {
IntentFilter filter = new IntentFilter(); addAction(action)
filter.addAction(action);
return filter;
} }
}