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

fix: Clicking on room name redirect to connected device fragment #2288

Merged
merged 4 commits into from
Jun 30, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import org.fossasia.susi.ai.device.deviceconnect.DeviceConnectFragment

class DeviceActivity : AppCompatActivity() {

private val TAG_DEVICE_CONNECT_FRAGMENT = "DeviceConnectFragment"
val TAG_DEVICE_CONNECT_FRAGMENT = "DeviceConnectFragment"
private val TAG_DEVICE_DETAILS_FRAGMENT = "DeviceDetailsFragment"
private val TAG_CONNECTED_DEVICE_FRAGMNENT = "ConnectedDeviceFragment"
val TAG_CONNECTED_DEVICE_FRAGMNENT = "ConnectedDeviceFragment"
val CONNECT_TO = "connect_to"

lateinit var mainWifi: WifiManager

Expand All @@ -30,7 +31,7 @@ class DeviceActivity : AppCompatActivity() {

mainWifi = application.getSystemService(Context.WIFI_SERVICE) as WifiManager

if (intent.getStringExtra("connectTo") == "DeviceConnectFragment") {
if (intent.getStringExtra(CONNECT_TO) == TAG_DEVICE_CONNECT_FRAGMENT) {
val deviceConnectFragment = DeviceConnectFragment()
supportFragmentManager.beginTransaction()
.replace(R.id.fragment_container, deviceConnectFragment, TAG_DEVICE_CONNECT_FRAGMENT)
Expand Down Expand Up @@ -58,4 +59,4 @@ class DeviceActivity : AppCompatActivity() {
finish()
super.onBackPressed()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class RoomsAdapter(private val availableRoomsList: ArrayList<DeviceConnectFragme
val roomNameClicked = availableRoomsList[adapterPosition].room
var intent = Intent(context, DeviceActivity::class.java)
intent.putExtra("roomName", roomNameClicked)
intent.putExtra(DeviceActivity().CONNECT_TO, DeviceActivity().TAG_DEVICE_CONNECT_FRAGMENT)
Copy link
Member

Choose a reason for hiding this comment

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

Wow

Copy link
Member

Choose a reason for hiding this comment

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

No need to instantiate activity. Heard of static final variables?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we can do so via using the companion object in kotlin.

context?.startActivity(intent)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ class ChatSettingsFragment : PreferenceFragmentCompat(), ISettingsView {
setupDevice.setOnPreferenceClickListener {

val intent = Intent(activity, DeviceActivity::class.java)
intent.putExtra("connectTo", "DeviceConnectFragment")
intent.putExtra(DeviceActivity().CONNECT_TO, DeviceActivity().TAG_DEVICE_CONNECT_FRAGMENT)
startActivity(intent)
true
}

deviceName.setOnPreferenceClickListener {
val intent = Intent(activity, DeviceActivity::class.java)
intent.putExtra("connectTo", "ConnectedDeviceFragment")
intent.putExtra(DeviceActivity().CONNECT_TO, DeviceActivity().TAG_CONNECTED_DEVICE_FRAGMNENT)
startActivity(intent)
true
}
Expand Down