refactor(ReceiverUtil): 重构
This commit is contained in:
parent
e4f4a357be
commit
4b1a2e084b
|
|
@ -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))
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue