Skip to content

Commit 779d12c

Browse files
atm1504iamareebjamal
authored andcommitted
feat: Enhance SUSI.AI smart speaker connection flow (#2297)
* feat: Add main setup screen * enhance ui as suggested * feat: connect button function implemented * feat: wifi credential request sent with error * feat: show page to select room * Add room functionality * feat: get macid of the device * feat: Enhance and fix bugs of room selection * fix: Alignments and minor bugs * feat: Add password layout field * feat: Setup complete workflow as stated * fix: Error * feat: Send room data and finalize the setup * feat: Remove unwanted codes * fix: MAke suggested changes * fix: Alert dialog box * fix: Cancel button intent removed * fix: Fix timber.e issue * fix: Updated suggested changes * fix: Add throwables in a timber message * fix: Remove extra line * fix: Updated suggested changes * fix: Remove unwanted else statements * fix: Updated timber message * fix: Remove unwanted if statements
1 parent 98d30a2 commit 779d12c

28 files changed

+914
-258
lines changed

app/src/main/java/org/fossasia/susi/ai/data/contract/IDeviceModel.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package org.fossasia.susi.ai.data.contract
22

33
import org.fossasia.susi.ai.data.device.SpeakerAuth
44
import org.fossasia.susi.ai.data.device.SpeakerConfiguration
5+
import org.fossasia.susi.ai.rest.responses.others.AddRoomResponse
6+
import retrofit2.Response
57

68
interface IDeviceModel {
79

@@ -20,9 +22,16 @@ interface IDeviceModel {
2022
fun onSetConfigFailure(localMessage: String)
2123
}
2224

25+
interface onSendRoomDetails {
26+
fun onSendRoomSuccess(roomResponse: Response<AddRoomResponse>)
27+
fun onSendRoomFailure(localMessage: String)
28+
}
29+
2330
fun sendWifiCredentials(ssid: String, pass: String, listener: onSendWifiCredentialsListener)
2431

2532
fun setConfiguration(speakerConfig: SpeakerConfiguration, listener: onSetConfigurationListener)
2633

2734
fun sendAuthCredentials(speakerAuth: SpeakerAuth, listener: onSendAuthCredentialsListener)
35+
36+
fun sendRoomDetails(room_name: String, listener: onSendRoomDetails)
2837
}

app/src/main/java/org/fossasia/susi/ai/data/device/DeviceModel.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ class DeviceModel : IDeviceModel {
1616
override fun sendAuthCredentials(speakerAuth: SpeakerAuth, listener: IDeviceModel.onSendAuthCredentialsListener) {
1717
deviceService.submitAuthCredentials(speakerAuth, listener)
1818
}
19+
20+
override fun sendRoomDetails(room_name: String, listener: IDeviceModel.onSendRoomDetails) {
21+
deviceService.submitRoomDetails(room_name, listener)
22+
}
1923
}

app/src/main/java/org/fossasia/susi/ai/data/device/DeviceService.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ interface DeviceService {
99
fun submitConfigSettings(speakerConfig: SpeakerConfiguration, listener: IDeviceModel.onSetConfigurationListener)
1010

1111
fun submitAuthCredentials(speakerAuth: SpeakerAuth, listener: IDeviceModel.onSendAuthCredentialsListener)
12+
13+
fun submitRoomDetails(roomName: String, listener: IDeviceModel.onSendRoomDetails)
1214
}

app/src/main/java/org/fossasia/susi/ai/data/device/DeviceServiceImpl.kt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.fossasia.susi.ai.data.device
22

33
import org.fossasia.susi.ai.data.contract.IDeviceModel
44
import org.fossasia.susi.ai.rest.clients.DeviceClient
5+
import org.fossasia.susi.ai.rest.responses.others.AddRoomResponse
56
import org.fossasia.susi.ai.rest.responses.others.SpeakerAuthResponse
67
import org.fossasia.susi.ai.rest.responses.others.SpeakerConfigResponse
78
import org.fossasia.susi.ai.rest.responses.others.SpeakerWifiResponse
@@ -23,12 +24,7 @@ class DeviceServiceImpl : DeviceService {
2324

2425
deviceApi.ttSSettings(query).enqueue(object : Callback<SpeakerConfigResponse> {
2526
override fun onFailure(call: Call<SpeakerConfigResponse>, t: Throwable?) {
26-
if (t?.localizedMessage != null) {
27-
Timber.d(t.cause)
28-
} else {
29-
Timber.d(t, "An error occurred")
30-
}
31-
Timber.d("Error in Configuration : " + call.toString())
27+
Timber.e(t, "Error in Configuration : " + call.toString())
3228
if (t != null)
3329
listener.onSetConfigFailure(t.localizedMessage)
3430
}
@@ -42,12 +38,7 @@ class DeviceServiceImpl : DeviceService {
4238
override fun submitAuthCredentials(speakerAuth: SpeakerAuth, listener: IDeviceModel.onSendAuthCredentialsListener) {
4339
deviceApi.authCredentials(speakerAuth.choice, speakerAuth.email, speakerAuth.password).enqueue(object : Callback<SpeakerAuthResponse> {
4440
override fun onFailure(call: Call<SpeakerAuthResponse>, t: Throwable?) {
45-
if (t?.localizedMessage != null) {
46-
Timber.d(t.localizedMessage)
47-
} else {
48-
Timber.d(t, "An error occurred")
49-
}
50-
Timber.d("Error in Authentication : " + call.toString())
41+
Timber.e(t, "Error in Authentication : " + call.toString())
5142
if (t != null)
5243
listener.onSendAuthFailure(t.localizedMessage)
5344
}
@@ -61,12 +52,7 @@ class DeviceServiceImpl : DeviceService {
6152
override fun submitWifiCredentials(ssid: String, pass: String, listener: IDeviceModel.onSendWifiCredentialsListener) {
6253
deviceApi.wifiCredentials(ssid, pass).enqueue(object : Callback<SpeakerWifiResponse> {
6354
override fun onFailure(call: Call<SpeakerWifiResponse>, t: Throwable?) {
64-
if (t?.localizedMessage != null) {
65-
Timber.d(t.localizedMessage)
66-
} else {
67-
Timber.d(t, "An error occurred")
68-
}
69-
Timber.d("Error in WiFi : " + call.toString())
55+
Timber.e(t, "Error in WiFi : " + call.toString())
7056
if (t != null)
7157
listener.onSendCredentialFailure(t.localizedMessage)
7258
}
@@ -76,4 +62,18 @@ class DeviceServiceImpl : DeviceService {
7662
}
7763
})
7864
}
65+
66+
override fun submitRoomDetails(roomName: String, listener: IDeviceModel.onSendRoomDetails) {
67+
deviceApi.roomDetails(roomName).enqueue(object : Callback<AddRoomResponse> {
68+
override fun onFailure(call: Call<AddRoomResponse>, t: Throwable) {
69+
Timber.e(t, "Error in WiFi : " + call.toString())
70+
if (t != null)
71+
listener.onSendRoomFailure(t.localizedMessage)
72+
}
73+
74+
override fun onResponse(call: Call<AddRoomResponse>, response: Response<AddRoomResponse>) {
75+
listener.onSendRoomSuccess(response)
76+
}
77+
})
78+
}
7979
}

app/src/main/java/org/fossasia/susi/ai/device/DeviceActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,7 @@ class DeviceActivity : AppCompatActivity() {
6060
const val TAG_DEVICE_CONNECT_FRAGMENT = "DeviceConnectFragment"
6161
const val TAG_CONNECTED_DEVICE_FRAGMNENT = "ConnectedDeviceFragment"
6262
const val CONNECT_TO = "connect_to"
63+
lateinit var macId: String
64+
var ANONYMOUS_MODE: Boolean = false
6365
}
6466
}

0 commit comments

Comments
 (0)