-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
components/fxa-client/android/src/main/java/org/mozilla/fxaclient/internal/AccountEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fxaclient.internal | ||
|
||
data class TabData( | ||
val title: String, | ||
val url: String | ||
) | ||
|
||
sealed class AccountEvent { | ||
class TabReceived(val from: Device?, val entries: Array<TabData>) : AccountEvent() | ||
|
||
companion object { | ||
private fun fromMessage(msg: MsgTypes.AccountEvent): AccountEvent { | ||
when (msg.type) { | ||
MsgTypes.AccountEvent.AccountEventType.TAB_RECEIVED -> { | ||
val data = msg.tabReceivedData | ||
return TabReceived( | ||
from = if (data.hasFrom()) Device.fromMessage(data.from) else null, | ||
entries = data.entriesList.map { | ||
TabData(title = it.title, url = it.url) | ||
}.toTypedArray() | ||
) | ||
} | ||
} | ||
} | ||
internal fun fromCollectionMessage(msg: MsgTypes.AccountEvents): Array<AccountEvent> { | ||
return msg.eventsList.map { | ||
AccountEvent.fromMessage(it) | ||
}.toTypedArray() | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
components/fxa-client/android/src/main/java/org/mozilla/fxaclient/internal/Device.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fxaclient.internal | ||
|
||
data class Device( | ||
val id: String, | ||
val displayName: String, | ||
val deviceType: Device.Type, | ||
val pushSubscription: Device.PushSubscription?, | ||
val pushEndpointExpired: Boolean, | ||
val isCurrentDevice: Boolean, | ||
val location: Device.Location, | ||
val lastAccessTime: Long? | ||
) { | ||
enum class Type { | ||
DESKTOP, | ||
MOBILE, | ||
UNKNOWN; | ||
|
||
companion object { | ||
internal fun fromMessage(msg: MsgTypes.Device.Type): Type { | ||
return when (msg) { | ||
MsgTypes.Device.Type.DESKTOP -> DESKTOP | ||
MsgTypes.Device.Type.MOBILE -> MOBILE | ||
else -> UNKNOWN | ||
} | ||
} | ||
} | ||
} | ||
data class PushSubscription( | ||
val endpoint: String, | ||
val publicKey: String, | ||
val authKey: String | ||
) { | ||
companion object { | ||
internal fun fromMessage(msg: MsgTypes.Device.PushSubscription): PushSubscription { | ||
return PushSubscription( | ||
endpoint = msg.endpoint, | ||
publicKey = msg.publicKey, | ||
authKey = msg.authKey | ||
) | ||
} | ||
} | ||
} | ||
data class Location( | ||
val city: String, | ||
val country: String, | ||
val state: String, | ||
val stateCode: String | ||
) { | ||
companion object { | ||
internal fun fromMessage(msg: MsgTypes.Device.Location): Location { | ||
return Location( | ||
city = msg.city, | ||
country = msg.country, | ||
state = msg.state, | ||
stateCode = msg.stateCode | ||
) | ||
} | ||
} | ||
} | ||
companion object { | ||
internal fun fromMessage(msg: MsgTypes.Device): Device { | ||
return Device( | ||
id = msg.id, | ||
displayName = msg.displayName, | ||
deviceType = Device.Type.fromMessage(msg.type), | ||
pushSubscription = if (msg.hasPushSubscription()) Device.PushSubscription.fromMessage(msg.pushSubscription) else null, | ||
pushEndpointExpired = msg.pushEndpointExpired, | ||
isCurrentDevice = msg.isCurrentDevice, | ||
location = Device.Location.fromMessage(msg.location), | ||
lastAccessTime = if (msg.hasLastAccessTime()) msg.lastAccessTime else null | ||
) | ||
} | ||
internal fun fromCollectionMessage(msg: MsgTypes.Devices): Array<Device> { | ||
return msg.devicesList.map { | ||
Device.fromMessage(it) | ||
}.toTypedArray() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters