diff --git a/app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt b/app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt index ee66b3fb0..30c3cd27e 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt @@ -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 @@ -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 } @@ -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() + } } diff --git a/app/src/main/java/ch/epfl/sdp/ui/home/HomeFragment.kt b/app/src/main/java/ch/epfl/sdp/ui/home/HomeFragment.kt index fac2acde6..2a9c7ec8c 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/home/HomeFragment.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/home/HomeFragment.kt @@ -4,14 +4,23 @@ 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.database.providers.SearchGroupRepositoryProvider +import ch.epfl.sdp.ui.MainActivity class HomeFragment : Fragment() { private lateinit var homeViewModel: HomeViewModel + private lateinit var groupText: TextView override fun onCreateView( inflater: LayoutInflater, @@ -19,6 +28,24 @@ class HomeFragment : Fragment() { 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) + updateGroupText() + return view + } + + override fun onResume() { + super.onResume() + updateGroupText() + } + + private fun updateGroupText(){ + val groupID = PreferenceManager.getDefaultSharedPreferences(MainApplication.applicationContext()) + .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) + SearchGroupDataManager().getGroupById(groupID.toString()).observeForever{group-> + groupText.text = MainApplication.applicationContext().getString(R.string.group_name_main_activity, group.name) + } + // groupText.text = MainApplication.applicationContext().getString(R.string.group_name_main_activity,SearchGroupDataManager().getGroupById(groupID.toString()).observe{}) } } diff --git a/app/src/main/java/ch/epfl/sdp/ui/search_group/selection/SearchGroupSelectionActivity.kt b/app/src/main/java/ch/epfl/sdp/ui/search_group/selection/SearchGroupSelectionActivity.kt index 3f44a088a..909971131 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/search_group/selection/SearchGroupSelectionActivity.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/search_group/selection/SearchGroupSelectionActivity.kt @@ -20,7 +20,7 @@ class SearchGroupSelectionActivity : AppCompatActivity(), Observer + + + \ No newline at end of file diff --git a/app/src/main/res/layout/nav_header_main.xml b/app/src/main/res/layout/nav_header_main.xml index a8fb3e072..0852ff5f5 100644 --- a/app/src/main/res/layout/nav_header_main.xml +++ b/app/src/main/res/layout/nav_header_main.xml @@ -17,4 +17,5 @@ android:name="ch.epfl.sdp.ui.home.LoginNavFragment" android:layout_width="match_parent" android:layout_height="match_parent" /> + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e7c4a4d29..9eb39e56f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -94,5 +94,6 @@ Hello blank fragment + Group ID : %1$s