mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-2831 Tech | Implement Device.Network.State.Set (#1915)
This commit is contained in:
parent
da52fee2b5
commit
31da9e2333
16 changed files with 204 additions and 5 deletions
|
@ -10,6 +10,7 @@ import com.anytypeio.anytype.core_models.DVFilter
|
|||
import com.anytypeio.anytype.core_models.DVSort
|
||||
import com.anytypeio.anytype.core_models.DVViewer
|
||||
import com.anytypeio.anytype.core_models.DVViewerType
|
||||
import com.anytypeio.anytype.core_models.DeviceNetworkType
|
||||
import com.anytypeio.anytype.core_models.Event
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Key
|
||||
|
@ -1070,4 +1071,8 @@ class BlockMiddleware(
|
|||
override suspend fun objectDateByTimestamp(command: Command.ObjectDateByTimestamp): Struct? {
|
||||
return middleware.objectDateByTimestamp(command)
|
||||
}
|
||||
|
||||
override suspend fun setDeviceNetworkState(type: DeviceNetworkType) {
|
||||
middleware.setDeviceNetworkState(type)
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ import com.anytypeio.anytype.core_models.DVFilter
|
|||
import com.anytypeio.anytype.core_models.DVSort
|
||||
import com.anytypeio.anytype.core_models.DVViewer
|
||||
import com.anytypeio.anytype.core_models.DVViewerType
|
||||
import com.anytypeio.anytype.core_models.DeviceNetworkType
|
||||
import com.anytypeio.anytype.core_models.Event
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Key
|
||||
|
@ -2856,6 +2857,16 @@ class Middleware @Inject constructor(
|
|||
return response.details
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun setDeviceNetworkState(type: DeviceNetworkType) {
|
||||
val request = Rpc.Device.NetworkState.Set.Request(
|
||||
deviceNetworkType = type.mw()
|
||||
)
|
||||
logRequestIfDebug(request)
|
||||
val (response, time) = measureTimedValue { service.deviceNetworkStateSet(request) }
|
||||
logResponseIfDebug(response, time)
|
||||
}
|
||||
|
||||
private fun logRequestIfDebug(request: Any) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
logger.logRequest(request).also {
|
||||
|
|
|
@ -109,4 +109,6 @@ typealias MSpaceSyncError = anytype.Event.Space.SyncError
|
|||
|
||||
typealias MP2PStatus = anytype.Event.P2PStatus.Status
|
||||
typealias MP2PStatusUpdate = P2PStatus.Update
|
||||
typealias MSyncStatusUpdate = Space.SyncStatus.Update
|
||||
typealias MSyncStatusUpdate = Space.SyncStatus.Update
|
||||
|
||||
typealias MDeviceNetworkType = anytype.model.DeviceNetworkType
|
|
@ -8,6 +8,7 @@ import com.anytypeio.anytype.core_models.Block
|
|||
import com.anytypeio.anytype.core_models.BlockSplitMode
|
||||
import com.anytypeio.anytype.core_models.Command
|
||||
import com.anytypeio.anytype.core_models.DVSortEmptyType
|
||||
import com.anytypeio.anytype.core_models.DeviceNetworkType
|
||||
import com.anytypeio.anytype.core_models.InternalFlags
|
||||
import com.anytypeio.anytype.core_models.NetworkMode
|
||||
import com.anytypeio.anytype.core_models.ObjectType
|
||||
|
@ -630,3 +631,9 @@ fun Rpc.Object.SearchWithMeta.Response.toCoreModelSearchResults(): List<Command.
|
|||
}
|
||||
}
|
||||
|
||||
fun DeviceNetworkType.mw(): MDeviceNetworkType = when(this) {
|
||||
DeviceNetworkType.WIFI -> MDeviceNetworkType.WIFI
|
||||
DeviceNetworkType.CELLULAR -> MDeviceNetworkType.CELLULAR
|
||||
DeviceNetworkType.NOT_CONNECTED -> MDeviceNetworkType.NOT_CONNECTED
|
||||
}
|
||||
|
||||
|
|
|
@ -609,4 +609,7 @@ interface MiddlewareService {
|
|||
|
||||
@Throws(Exception::class)
|
||||
fun debugAccountSelectTrace(request: Rpc.Debug.AccountSelectTrace.Request): Rpc.Debug.AccountSelectTrace.Response
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun deviceNetworkStateSet(request: Rpc.Device.NetworkState.Set.Request): Rpc.Device.NetworkState.Set.Response
|
||||
}
|
|
@ -2450,4 +2450,17 @@ class MiddlewareServiceImplementation @Inject constructor(
|
|||
return response
|
||||
}
|
||||
}
|
||||
|
||||
override fun deviceNetworkStateSet(request: Rpc.Device.NetworkState.Set.Request): Rpc.Device.NetworkState.Set.Response {
|
||||
val encoded = Service.deviceNetworkStateSet(
|
||||
Rpc.Device.NetworkState.Set.Request.ADAPTER.encode(request)
|
||||
)
|
||||
val response = Rpc.Device.NetworkState.Set.Response.ADAPTER.decode(encoded)
|
||||
val error = response.error
|
||||
if (error != null && error.code != Rpc.Device.NetworkState.Set.Response.Error.Code.NULL) {
|
||||
throw Exception(error.description)
|
||||
} else {
|
||||
return response
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue