From 2538963be9ef254b3c676af90e229a2efd84d1c5 Mon Sep 17 00:00:00 2001 From: Nolan Chappuis Date: Wed, 3 Jun 2020 17:54:03 +0200 Subject: [PATCH 1/8] GroupButton now shows the groupname --- .../main/java/ch/epfl/sdp/ui/MainActivity.kt | 4 +++ .../java/ch/epfl/sdp/ui/home/HomeFragment.kt | 26 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) 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 1382c69dc..b7ba244ce 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt @@ -11,14 +11,18 @@ import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity import androidx.core.view.GravityCompat import androidx.drawerlayout.widget.DrawerLayout +import androidx.lifecycle.MutableLiveData import androidx.lifecycle.Observer import androidx.navigation.findNavController import androidx.navigation.ui.AppBarConfiguration import androidx.navigation.ui.navigateUp import androidx.navigation.ui.setupWithNavController +import androidx.preference.PreferenceManager +import ch.epfl.sdp.MainApplication import ch.epfl.sdp.R import ch.epfl.sdp.database.data.Role import ch.epfl.sdp.database.data_manager.MainDataManager +import ch.epfl.sdp.database.data_manager.SearchGroupDataManager import ch.epfl.sdp.drone.Drone import ch.epfl.sdp.ui.maps.MapActivity import ch.epfl.sdp.ui.search_group.selection.SearchGroupSelectionActivity 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..d7631fc0f 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,19 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Button import androidx.fragment.app.Fragment 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 groupButton: Button override fun onCreateView( inflater: LayoutInflater, @@ -19,6 +24,25 @@ 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) + groupButton = view.findViewById(R.id.search_group_selection_button) + 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) { + SearchGroupDataManager().getGroupById(groupId.toString()).observeForever { group -> + groupButton.text = group.name + } + } + } } From 52bed703c3c57ab5512377e96117c1b1b039be1a Mon Sep 17 00:00:00 2001 From: Nolan Chappuis Date: Wed, 3 Jun 2020 17:54:51 +0200 Subject: [PATCH 2/8] Remove unnecessary imports --- app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt | 4 ---- app/src/main/java/ch/epfl/sdp/ui/home/HomeFragment.kt | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) 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 b7ba244ce..1382c69dc 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/MainActivity.kt @@ -11,18 +11,14 @@ import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity import androidx.core.view.GravityCompat import androidx.drawerlayout.widget.DrawerLayout -import androidx.lifecycle.MutableLiveData import androidx.lifecycle.Observer import androidx.navigation.findNavController import androidx.navigation.ui.AppBarConfiguration import androidx.navigation.ui.navigateUp import androidx.navigation.ui.setupWithNavController -import androidx.preference.PreferenceManager -import ch.epfl.sdp.MainApplication import ch.epfl.sdp.R import ch.epfl.sdp.database.data.Role import ch.epfl.sdp.database.data_manager.MainDataManager -import ch.epfl.sdp.database.data_manager.SearchGroupDataManager import ch.epfl.sdp.drone.Drone import ch.epfl.sdp.ui.maps.MapActivity import ch.epfl.sdp.ui.search_group.selection.SearchGroupSelectionActivity 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 d7631fc0f..764c3058e 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 @@ -34,11 +34,11 @@ class HomeFragment : Fragment() { updateGroupText() } - private fun 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) { + if (groupId != null) { SearchGroupDataManager().getGroupById(groupId.toString()).observeForever { group -> groupButton.text = group.name } From 45730b071a8d2a2e7bf40eecba0cfbb5dcd78ba2 Mon Sep 17 00:00:00 2001 From: Nolan Chappuis Date: Wed, 3 Jun 2020 18:11:44 +0200 Subject: [PATCH 3/8] make test pass --- app/src/main/java/ch/epfl/sdp/ui/home/HomeFragment.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 764c3058e..04f1f270c 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 @@ -38,9 +38,12 @@ class HomeFragment : Fragment() { val groupId = PreferenceManager .getDefaultSharedPreferences(MainApplication.applicationContext()) .getString(MainApplication.applicationContext().getString(R.string.pref_key_current_group_id), null) - if (groupId != null) { + if (groupId == null) return + else{ SearchGroupDataManager().getGroupById(groupId.toString()).observeForever { group -> - groupButton.text = group.name + if (group !=null) { + groupButton.text = group.name + } } } From c513873b8661e3c6bd7f84eb4336c57dc84a293a Mon Sep 17 00:00:00 2001 From: Nolan Chappuis Date: Fri, 5 Jun 2020 13:17:30 +0200 Subject: [PATCH 4/8] Rewrite search group if no group --- app/src/main/java/ch/epfl/sdp/ui/home/HomeFragment.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 04f1f270c..a3a3454ca 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 @@ -38,7 +38,9 @@ class HomeFragment : Fragment() { val groupId = PreferenceManager .getDefaultSharedPreferences(MainApplication.applicationContext()) .getString(MainApplication.applicationContext().getString(R.string.pref_key_current_group_id), null) - if (groupId == null) return + if (groupId == null) { + groupButton.text = R.string.select_search_group.toString() + } else{ SearchGroupDataManager().getGroupById(groupId.toString()).observeForever { group -> if (group !=null) { From bdefe7212295f60b916be884677b9a430e8a8416 Mon Sep 17 00:00:00 2001 From: Nolan Chappuis Date: Fri, 5 Jun 2020 13:44:29 +0200 Subject: [PATCH 5/8] Change obserforever to observe --- app/src/main/java/ch/epfl/sdp/ui/home/HomeFragment.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 a3a3454ca..fe69880d2 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 @@ -6,6 +6,7 @@ import android.view.View import android.view.ViewGroup import android.widget.Button import androidx.fragment.app.Fragment +import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import androidx.preference.PreferenceManager import ch.epfl.sdp.MainApplication @@ -42,11 +43,11 @@ class HomeFragment : Fragment() { groupButton.text = R.string.select_search_group.toString() } else{ - SearchGroupDataManager().getGroupById(groupId.toString()).observeForever { group -> + SearchGroupDataManager().getGroupById(groupId.toString()).observe (this, Observer { group -> if (group !=null) { groupButton.text = group.name } - } + }) } } From 7a7d6911e8b29f96120ef53573bb191c2dd527b2 Mon Sep 17 00:00:00 2001 From: Nolan Chappuis Date: Fri, 5 Jun 2020 14:16:30 +0200 Subject: [PATCH 6/8] Use textview instead of changing the button text --- .../java/ch/epfl/sdp/ui/home/HomeFragment.kt | 9 +++++---- .../main/res/layout-land/fragment_home.xml | 19 +++++++++++++++++++ app/src/main/res/layout/fragment_home.xml | 10 ++++++++-- 3 files changed, 32 insertions(+), 6 deletions(-) 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 fe69880d2..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 @@ -5,6 +5,7 @@ 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 @@ -17,7 +18,7 @@ import ch.epfl.sdp.database.data_manager.SearchGroupDataManager class HomeFragment : Fragment() { private lateinit var homeViewModel: HomeViewModel - private lateinit var groupButton: Button + private lateinit var groupText : TextView override fun onCreateView( inflater: LayoutInflater, @@ -26,7 +27,7 @@ class HomeFragment : Fragment() { ): View? { homeViewModel = ViewModelProvider(this).get(HomeViewModel::class.java) val view = inflater.inflate(R.layout.fragment_home, container, false) - groupButton = view.findViewById(R.id.search_group_selection_button) + groupText = view.findViewById(R.id.current_group) return view } @@ -40,12 +41,12 @@ class HomeFragment : Fragment() { .getDefaultSharedPreferences(MainApplication.applicationContext()) .getString(MainApplication.applicationContext().getString(R.string.pref_key_current_group_id), null) if (groupId == null) { - groupButton.text = R.string.select_search_group.toString() + return } else{ SearchGroupDataManager().getGroupById(groupId.toString()).observe (this, Observer { group -> if (group !=null) { - groupButton.text = group.name + 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..e1b59ff81 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" />