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..7e685de82 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,21 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Button +import android.widget.TextView import androidx.fragment.app.Fragment +import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider +import androidx.preference.PreferenceManager +import ch.epfl.sdp.MainApplication import ch.epfl.sdp.R +import ch.epfl.sdp.database.data_manager.SearchGroupDataManager class HomeFragment : Fragment() { private lateinit var homeViewModel: HomeViewModel + private lateinit var groupText : TextView override fun onCreateView( inflater: LayoutInflater, @@ -19,6 +26,30 @@ 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) + return view + } + + override fun onResume() { + super.onResume() + updateGroupText() + } + + private fun updateGroupText() { + val groupId = PreferenceManager + .getDefaultSharedPreferences(MainApplication.applicationContext()) + .getString(MainApplication.applicationContext().getString(R.string.pref_key_current_group_id), null) + if (groupId == null) { + return + } + else{ + SearchGroupDataManager().getGroupById(groupId.toString()).observe (this, Observer { group -> + if (group !=null) { + groupText.text = group.name + } + }) + } + } } diff --git a/app/src/main/res/layout-land/fragment_home.xml b/app/src/main/res/layout-land/fragment_home.xml index 09e170cdc..1bd5826b9 100644 --- a/app/src/main/res/layout-land/fragment_home.xml +++ b/app/src/main/res/layout-land/fragment_home.xml @@ -28,6 +28,7 @@ android:layout_height="match_parent"> + + + + + diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 7a85ec8c7..1a8736844 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -48,10 +48,16 @@ android:onClick="goToSearchGroupSelect" android:text="@string/select_search_group" /> - + android:layout_weight="2" + android:gravity="center" + android:text="" + android:textAllCaps="false" + android:textColor="#ffffff" + android:textSize="14sp" />