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

Feature/see group2 #264

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
33 changes: 32 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,52 @@ 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,
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)
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
}
})
}

}
}
19 changes: 19 additions & 0 deletions app/src/main/res/layout-land/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
Expand Down Expand Up @@ -80,8 +81,26 @@
android:layout_weight="1" />

</LinearLayout>

<TextView
android:id="@+id/current_group"
android:layout_width="161dp"
android:layout_height="27dp"
android:layout_marginTop="16dp"
android:gravity="center"
android:text=""
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.071"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>



</LinearLayout>


Expand Down
10 changes: 8 additions & 2 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@
android:onClick="goToSearchGroupSelect"
android:text="@string/select_search_group" />

<Space
<TextView
android:id="@+id/current_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2" />
android:layout_weight="2"
android:gravity="center"
android:text=""
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="14sp" />

<Button
android:id="@+id/start_mission_button"
Expand Down