Using AI to improve function documentation
This commit is contained in:
@@ -7,12 +7,17 @@ import com.v2ray.ang.handler.MmkvManager
|
||||
import com.v2ray.ang.service.V2RayServiceManager
|
||||
|
||||
class BootReceiver : BroadcastReceiver() {
|
||||
/**
|
||||
* This method is called when the BroadcastReceiver is receiving an Intent broadcast.
|
||||
* It checks if the context is not null and the action is ACTION_BOOT_COMPLETED.
|
||||
* If the conditions are met, it starts the V2Ray service.
|
||||
*
|
||||
* @param context The Context in which the receiver is running.
|
||||
* @param intent The Intent being received.
|
||||
*/
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
//Check if context is not null and action is the one we want
|
||||
if (context == null || intent?.action != Intent.ACTION_BOOT_COMPLETED) return
|
||||
//Check if flag is true and a server is selected
|
||||
if (!MmkvManager.decodeStartOnBoot() || MmkvManager.getSelectServer().isNullOrEmpty()) return
|
||||
//Start v2ray
|
||||
V2RayServiceManager.startVService(context)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,15 @@ import com.v2ray.ang.service.V2RayServiceManager
|
||||
|
||||
class TaskerReceiver : BroadcastReceiver() {
|
||||
|
||||
/**
|
||||
* This method is called when the BroadcastReceiver is receiving an Intent broadcast.
|
||||
* It retrieves the bundle from the intent and checks the switch and guid values.
|
||||
* Depending on the switch value, it starts or stops the V2Ray service.
|
||||
*
|
||||
* @param context The Context in which the receiver is running.
|
||||
* @param intent The Intent being received.
|
||||
*/
|
||||
override fun onReceive(context: Context, intent: Intent?) {
|
||||
|
||||
try {
|
||||
val bundle = intent?.getBundleExtra(AppConfig.TASKER_EXTRA_BUNDLE)
|
||||
val switch = bundle?.getBoolean(AppConfig.TASKER_EXTRA_BUNDLE_SWITCH, false)
|
||||
|
||||
@@ -14,14 +14,26 @@ import com.v2ray.ang.service.V2RayServiceManager
|
||||
|
||||
class WidgetProvider : AppWidgetProvider() {
|
||||
/**
|
||||
* 每次窗口小部件被更新都调用一次该方法
|
||||
* This method is called every time the widget is updated.
|
||||
* It updates the widget background based on the V2Ray service running state.
|
||||
*
|
||||
* @param context The Context in which the receiver is running.
|
||||
* @param appWidgetManager The AppWidgetManager instance.
|
||||
* @param appWidgetIds The appWidgetIds for which an update is needed.
|
||||
*/
|
||||
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
||||
super.onUpdate(context, appWidgetManager, appWidgetIds)
|
||||
updateWidgetBackground(context, appWidgetManager, appWidgetIds, V2RayServiceManager.isRunning())
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the widget background based on whether the V2Ray service is running.
|
||||
*
|
||||
* @param context The Context in which the receiver is running.
|
||||
* @param appWidgetManager The AppWidgetManager instance.
|
||||
* @param appWidgetIds The appWidgetIds for which an update is needed.
|
||||
* @param isRunning Boolean indicating if the V2Ray service is running.
|
||||
*/
|
||||
private fun updateWidgetBackground(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray, isRunning: Boolean) {
|
||||
val remoteViews = RemoteViews(context.packageName, R.layout.widget_switch)
|
||||
val intent = Intent(context, WidgetProvider::class.java)
|
||||
@@ -51,7 +63,11 @@ class WidgetProvider : AppWidgetProvider() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收窗口小部件发送的广播
|
||||
* This method is called when the BroadcastReceiver is receiving an Intent broadcast.
|
||||
* It handles widget click actions and updates the widget background based on the V2Ray service state.
|
||||
*
|
||||
* @param context The Context in which the receiver is running.
|
||||
* @param intent The Intent being received.
|
||||
*/
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
super.onReceive(context, intent)
|
||||
|
||||
Reference in New Issue
Block a user