-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add room feature #2267
feat: Add room feature #2267
Conversation
The build is failing✨ Good work on this PR so far! ✨ Unfortunately, the Circle CI build is failing as of 394ab75. Here's the output:
|
…into atm_add_room
@iamareebjamal @batbrain7 @arundhati24 please start reviewing it. Its succesfully working now if I whitelist the device IP(have made a seperate pr regarding that #2263). |
I would add the screenshot soon. I need to reflash my device again. So, I need a bit of time for that. |
app/src/main/AndroidManifest.xml
Outdated
@@ -20,6 +20,7 @@ | |||
android:icon="@drawable/ic_launcher" | |||
android:label="@string/app_name" | |||
android:theme="@style/AppTheme" | |||
android:usesCleartextTraffic="true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iamareebjamal as stated in the comment, I was waiting for the pr #2263 to get merged, so to temporary make it work, I added that line. I would remove it, as #2263 is now merged. : )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it
import timber.log.Timber | ||
|
||
class RoomModel : IRoomModel { | ||
private lateinit var addDeviceResponseCall: Call<GetAddDeviceResponse> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to be a class member?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is as per the architecture or the way it has been implemented in other files. So, I created it. Also, we will have more functions related to room in the roomModel class.
package org.fossasia.susi.ai.dataclasses | ||
|
||
data class AddDeviceQuery( | ||
val access_token: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
camel case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
@@ -54,26 +66,41 @@ class DeviceConnectFragment : Fragment(), IDeviceConnectView { | |||
private var checkDevice: Boolean = false | |||
private val REQUEST_LOCATION_ACCESS = 101 | |||
private val REQUEST_WIFI_ACCESS = 102 | |||
lateinit var realm: Realm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tell me which class are you accessing it from
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
@@ -54,26 +66,41 @@ class DeviceConnectFragment : Fragment(), IDeviceConnectView { | |||
private var checkDevice: Boolean = false | |||
private val REQUEST_LOCATION_ACCESS = 101 | |||
private val REQUEST_WIFI_ACCESS = 102 | |||
lateinit var realm: Realm | |||
val availableRoomsList: ArrayList<AvailableRoomsFormat> = ArrayList() | |||
lateinit var availableRoomsRecyclerView: RecyclerView |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
@@ -54,26 +66,41 @@ class DeviceConnectFragment : Fragment(), IDeviceConnectView { | |||
private var checkDevice: Boolean = false | |||
private val REQUEST_LOCATION_ACCESS = 101 | |||
private val REQUEST_WIFI_ACCESS = 102 | |||
lateinit var realm: Realm | |||
val availableRoomsList: ArrayList<AvailableRoomsFormat> = ArrayList() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
val availableRoomsList: ArrayList<AvailableRoomsFormat> = ArrayList() | ||
lateinit var availableRoomsRecyclerView: RecyclerView | ||
private var availableRoomsAdapter: RecyclerView.Adapter<*>? = null | ||
lateinit var roomNameSelected: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
lateinit var availableRoomsRecyclerView: RecyclerView | ||
private var availableRoomsAdapter: RecyclerView.Adapter<*>? = null | ||
lateinit var roomNameSelected: String | ||
lateinit var macid: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
|
||
data class AddDeviceQuery( | ||
val access_token: String, | ||
val macid: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
camel case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
@@ -31,6 +35,8 @@ class DeviceConnectPresenter(context: Context, manager: WifiManager) : IDeviceCo | |||
private var isWifiEnabled = false | |||
lateinit var connections: ArrayList<String> | |||
private var utilModel: UtilModel = UtilModel(context) | |||
lateinit var realm: Realm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
@iamareebjamal please review it. |
PRF |
@iamareebjamal sorry, I couldn't understand what u meant to say. Please explain |
Peer review first. Reviewing 👍 |
Please add screenshots first. |
I will add it by tonight. Need to reflash the memory card with susi installer, so needs time for that. : ) |
@liveHarshit can u please start reviewing it. Actually, all my pending tasks are related to this pr. I will be able to work on those, once this is merged. You can now have a look at the code, I will add the screenshot by tonight. Thank you : ) |
@atm1504 Can you please explain what the room feature is so that I can review? |
@liveHarshit yah sure. See, what we want is that we should associate some room name with the smart speaker that we connect to our account. For that what we have is, initially we show them a list of available rooms. User can add more rooms if he/she wants. These room names are stored locally in the database and are displayed. When a user clicks on any room name, we pass the room name in an intent. We retrieve the room name in a variable. After this when we successfully set up the device(smart speaker with all credentials) we simply make a get request to the server to add this device with the user. The response is not shown to the user. It is done in the background. This is the complete workflow. |
if (activity?.intent?.hasExtra("roomName") as Boolean) { | ||
val roomName = activity?.intent?.getStringExtra("roomName").toString() | ||
roomNameSelected = roomName | ||
activity?.intent?.removeExtra("roomName") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate -3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explain please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can first store activity?.intent in a bundle before the if statement then use that bundle for query e.t.c.
|
||
addDeviceButton.setOnClickListener { | ||
deviceConnectPresenter.searchDevices() | ||
if (activity?.intent?.hasExtra("roomName") as Boolean) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't cast, take a default value instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, here take as a bundle, and the get boolean from that bundle.
private lateinit var availableRoomsRecyclerView: RecyclerView | ||
private var availableRoomsAdapter: RecyclerView.Adapter<*>? = null | ||
private lateinit var roomNameSelected: String | ||
private lateinit var macId: String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To o many lateinit var
make sure that app is not crashing in any case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its not crashing
deviceConnectPresenter.addRoom(roomName) | ||
Toast.makeText(context, "Added " + roomName + " as a room", Toast.LENGTH_SHORT).show() | ||
edt_room.text.clear() | ||
view?.let { it1 -> Utils.hideSoftKeyboard(context, it1) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is view here? You can use rootView instead, no need for a null check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To call the hideSoftKeyboard function we need to pass the view, so simply passing view from getview won't work because of the non-null assertion. So to avoid it, it's better to wrap with let.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To call the hideSoftKeyboard function we need to pass the view,
Yes I know. Here val rootView = inflater.inflate(R.layout.fragment_device_connect, container, false)
decleare rootView
as lateinit var and use that. It won't be nullable.
|
||
class AvailableRoomsFormat { | ||
var id: Long? = null | ||
var room: String? = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be val.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot do so. We cannot reassign the value again later
|
||
<View | ||
android:layout_width="match_parent" | ||
android:layout_height="2dp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In dimension resources file
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/rooms_available" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace ></android.support.v7.widget.RecyclerView>
with />
android:layout_width="match_parent" | ||
android:layout_height="2dp" | ||
android:layout_marginTop="@dimen/margin_large" | ||
android:background="@color/md_grey_200"></View> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
close directly with />
|
||
<View | ||
android:layout_width="match_parent" | ||
android:layout_height="2dp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the dimension resources file
|
||
<ImageView | ||
android:layout_width="20dp" | ||
android:layout_height="20dp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
@liveHarshit please check now : ) |
|
||
addDeviceButton.setOnClickListener { | ||
deviceConnectPresenter.searchDevices() | ||
val intent = activity?.intent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
take bundle not intent, activity.intent.extras
@liveHarshit please have a look now |
app/src/main/java/org/fossasia/susi/ai/device/deviceconnect/DeviceConnectFragment.kt
Outdated
Show resolved
Hide resolved
deviceConnectPresenter.searchDevices() | ||
val bundle = activity?.intent?.extras | ||
|
||
if (bundle?.getString("roomName")?.isNullOrEmpty() == false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why you still require to compare with false after a null check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error is "Type mismatch: Inferred type is Boolean? but boolean was expected"
@iamareebjamal please review it now. |
Fixes #2266
Changes:
Implemented the UI that would handle the addition of rooms
Screenshots for the change: WIll add it soon