Skip to content
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

Merged
merged 18 commits into from
Jun 22, 2019
Merged

feat: Add room feature #2267

merged 18 commits into from
Jun 22, 2019

Conversation

atm1504
Copy link
Member

@atm1504 atm1504 commented Jun 16, 2019

Fixes #2266

Changes:
Implemented the UI that would handle the addition of rooms

Screenshots for the change: WIll add it soon

@auto-label auto-label bot added the feature label Jun 16, 2019
@ci-reporter
Copy link

ci-reporter bot commented Jun 16, 2019

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:

Run Tests
> Task :app:preBuild UP-TO-DATE

I'm sure you can fix it! If you need help, don't hesitate to ask a maintainer of the project!


Failed build for 377e75f
Run Tests
> Task :app:preBuild UP-TO-DATE
Failed build for cc79055
spotless check
> Task :app:spotlessKotlin FAILED
Failed build for 888e658
spotless check
> Task :app:spotlessKotlin FAILED
Failed build for 1e6d664
lint check
> Task :app:preBuild UP-TO-DATE
Failed build for 1e6d664
lint check
> Task :app:preBuild UP-TO-DATE

This comment was automagically generated by ci-reporter. If you see a problem, open an issue here.

@atm1504 atm1504 changed the title feat: Implement the UI for adding rooms to devices [WIP]: Add room feature Jun 17, 2019
@auto-label auto-label bot removed the feature label Jun 17, 2019
@atm1504
Copy link
Member Author

atm1504 commented Jun 20, 2019

@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).
The apk is: app-fdroid-debug.apk.zip(it has cleartext communication but that is not included in this pr).

@atm1504
Copy link
Member Author

atm1504 commented Jun 20, 2019

I would add the screenshot soon. I need to reflash my device again. So, I need a bit of time for that.

@atm1504 atm1504 changed the title [WIP]: Add room feature feat: Add room feature Jun 20, 2019
@auto-label auto-label bot added the feature label Jun 20, 2019
@@ -20,6 +20,7 @@
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad

Copy link
Member Author

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. : )

Copy link
Member Author

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>
Copy link
Member

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?

Copy link
Member Author

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camel case

Copy link
Member Author

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
Copy link
Member

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

Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Member Author

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Member Author

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camel case

Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@atm1504
Copy link
Member Author

atm1504 commented Jun 22, 2019

@iamareebjamal please review it.

@iamareebjamal
Copy link
Member

PRF

@atm1504
Copy link
Member Author

atm1504 commented Jun 22, 2019

PRF

@iamareebjamal sorry, I couldn't understand what u meant to say. Please explain

@liveHarshit
Copy link
Member

PRF

@iamareebjamal sorry, I couldn't understand what u meant to say. Please explain

Peer review first. Reviewing 👍

@liveHarshit
Copy link
Member

Implemented the UI that would handle the addition of rooms

Please add screenshots first.

@atm1504
Copy link
Member Author

atm1504 commented Jun 22, 2019

Implemented the UI that would handle the addition of rooms

Please add screenshots first.

I will add it by tonight. Need to reflash the memory card with susi installer, so needs time for that. : )

@atm1504
Copy link
Member Author

atm1504 commented Jun 22, 2019

@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 : )

@liveHarshit
Copy link
Member

@atm1504 Can you please explain what the room feature is so that I can review?

@atm1504
Copy link
Member Author

atm1504 commented Jun 22, 2019

@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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate -3

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain please

Copy link
Member

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) {
Copy link
Member

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.

Copy link
Member

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
Copy link
Member

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.

Copy link
Member Author

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) }
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@liveHarshit liveHarshit Jun 22, 2019

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be val.

Copy link
Member Author

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"
Copy link
Member

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>
Copy link
Member

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>
Copy link
Member

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"
Copy link
Member

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@atm1504
Copy link
Member Author

atm1504 commented Jun 22, 2019

@liveHarshit please check now : )


addDeviceButton.setOnClickListener {
deviceConnectPresenter.searchDevices()
val intent = activity?.intent
Copy link
Member

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

@atm1504
Copy link
Member Author

atm1504 commented Jun 22, 2019

@liveHarshit please have a look now

deviceConnectPresenter.searchDevices()
val bundle = activity?.intent?.extras

if (bundle?.getString("roomName")?.isNullOrEmpty() == false) {
Copy link
Member

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.

Copy link
Member Author

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"

@atm1504
Copy link
Member Author

atm1504 commented Jun 22, 2019

Screenshot:
ezgif com-video-to-gif

@atm1504
Copy link
Member Author

atm1504 commented Jun 22, 2019

@iamareebjamal please review it now.

@iamareebjamal iamareebjamal merged commit ae46c39 into fossasia:development Jun 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add room to devices
3 participants