Skip to content
This repository has been archived by the owner on Jun 22, 2022. It is now read-only.

Feature/see group #215

Closed
wants to merge 20 commits into from
9 changes: 6 additions & 3 deletions app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import ch.epfl.sdp.database.data.Role
import ch.epfl.sdp.drone.Drone
import ch.epfl.sdp.ui.maps.MapActivity
import ch.epfl.sdp.ui.search_group.selection.SearchGroupSelectionActivity
import ch.epfl.sdp.ui.search_group.selection.SearchGroupSelectionActivity.Companion.SEARH_GROUP_ID_SELECTION_RESULT_TAG
import ch.epfl.sdp.ui.search_group.selection.SearchGroupSelectionActivity.Companion.SEARCH_GROUP_ID_SELECTION_RESULT_TAG
import ch.epfl.sdp.ui.settings.SettingsActivity
import ch.epfl.sdp.utils.Auth
import ch.epfl.sdp.utils.CentralLocationManager
Expand Down Expand Up @@ -94,7 +94,6 @@ class MainActivity : AppCompatActivity() {
.putString(getString(R.string.pref_key_current_group_id), it)
.apply()
})

//TODO Get role of current search group
}

Expand Down Expand Up @@ -175,9 +174,13 @@ class MainActivity : AppCompatActivity() {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == SEARCH_GROUP_SELECTION_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
currentGroupId.value = data!!.getStringExtra(SEARH_GROUP_ID_SELECTION_RESULT_TAG)
currentGroupId.value = data!!.getStringExtra(SEARCH_GROUP_ID_SELECTION_RESULT_TAG)
}
}
Auth.onActivityResult(requestCode, resultCode, data)
}

fun getCurrentGroupID() : String{
return currentGroupId.value.toString()
}
}
25 changes: 24 additions & 1 deletion app/src/main/java/ch/epfl/sdp/ui/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,44 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModelProvider
import androidx.preference.PreferenceManager
import ch.epfl.sdp.MainApplication
import ch.epfl.sdp.R
import ch.epfl.sdp.database.dao.FirebaseGroupDao
import ch.epfl.sdp.database.data_manager.SearchGroupDataManager
import ch.epfl.sdp.ui.MainActivity


class HomeFragment : Fragment() {

private lateinit var homeViewModel: HomeViewModel
private lateinit var groupText: TextView

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
homeViewModel = ViewModelProvider(this).get(HomeViewModel::class.java)
return inflater.inflate(R.layout.fragment_home, container, false)
val view = inflater.inflate(R.layout.fragment_home, container, false)
groupText = view.findViewById(R.id.current_group_text)
val groupID = PreferenceManager.getDefaultSharedPreferences(MainApplication.applicationContext())
Ph0tonic marked this conversation as resolved.
Show resolved Hide resolved
.getString(getString(R.string.pref_key_current_group_id), "No group")
//groupText.text = MainApplication.applicationContext().getString(R.string.group_name_main_activity,SearchGroupDataManager().getGroupById(MainActivity().getCurrentGroupID()).value?.name)
groupText.text = MainApplication.applicationContext().getString(R.string.group_name_main_activity,FirebaseGroupDao().getGroupById(groupID.toString()).value?.name )
Ph0tonic marked this conversation as resolved.
Show resolved Hide resolved
return view
}

override fun onResume() {
super.onResume()
val groupID = PreferenceManager.getDefaultSharedPreferences(MainApplication.applicationContext())
Ph0tonic marked this conversation as resolved.
Show resolved Hide resolved
.getString(getString(R.string.pref_key_current_group_id), "No group")
//groupText.text = MainApplication.applicationContext().getString(R.string.group_name_main_activity,SearchGroupDataManager().getGroupById(MainActivity().getCurrentGroupID()).value?.name)
groupText.text = MainApplication.applicationContext().getString(R.string.group_name_main_activity,FirebaseGroupDao().getGroupById(groupID.toString()).value?.name )
Ph0tonic marked this conversation as resolved.
Show resolved Hide resolved
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SearchGroupSelectionActivity : AppCompatActivity(), Observer<List<SearchGr
private val searchGroupManager = SearchGroupDataManager()

companion object {
const val SEARH_GROUP_ID_SELECTION_RESULT_TAG = "search_group"
const val SEARCH_GROUP_ID_SELECTION_RESULT_TAG = "search_group"
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -54,7 +54,7 @@ class SearchGroupSelectionActivity : AppCompatActivity(), Observer<List<SearchGr

private fun joinGroup(searchGroupData: SearchGroupData) {
val returnDataIntent = Intent()
returnDataIntent.putExtra(SEARH_GROUP_ID_SELECTION_RESULT_TAG, searchGroupData.uuid)
returnDataIntent.putExtra(SEARCH_GROUP_ID_SELECTION_RESULT_TAG, searchGroupData.uuid)
setResult(RESULT_OK, returnDataIntent)
finish()
}
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
tools:context=".ui.home.HomeFragment">

<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="253dp"
android:orientation="horizontal"
Expand Down Expand Up @@ -48,7 +49,19 @@
android:text="@string/work_offline"
android:textColor="@color/colorBlack"
android:textSize="48sp" />

</LinearLayout>

<TextView
android:id="@+id/current_group_text"
android:layout_width="match_parent"
android:layout_height="77dp"
android:layout_gravity="center"
android:textColor="@color/colorBlack"
android:textSize="32sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions app/src/main/res/layout/nav_header_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
android:name="ch.epfl.sdp.ui.home.LoginNavFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,6 @@

<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="group_name_main_activity">Group ID : %1$s</string>

</resources>