From 582c72c8b4ab9f2a160c77c291dc821a6e896e98 Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Wed, 25 May 2022 23:04:17 +0200 Subject: [PATCH 01/12] ViewModel: keep view and context of fragments --- .../main/java/ch/sdp/vibester/helper/ViewModel.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 app/src/main/java/ch/sdp/vibester/helper/ViewModel.kt diff --git a/app/src/main/java/ch/sdp/vibester/helper/ViewModel.kt b/app/src/main/java/ch/sdp/vibester/helper/ViewModel.kt new file mode 100644 index 000000000..41f7f68dc --- /dev/null +++ b/app/src/main/java/ch/sdp/vibester/helper/ViewModel.kt @@ -0,0 +1,12 @@ +package ch.sdp.vibester.helper + +import android.content.Context +import android.view.View + +/* +* Class to set/get view, activity, context for fragment +*/ +class ViewModel { + lateinit var view: View + lateinit var ctx: Context +} \ No newline at end of file From 4e1c26cb6739724c5d0111d28d3a72c7dbd8db3d Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Wed, 25 May 2022 23:04:32 +0200 Subject: [PATCH 02/12] fragments: rename the files/ids --- ...{fragment_game_setup.xml => fragment_layout_game_setup.xml} | 3 +-- ...{fragment_scoreboard.xml => fragment_layout_scoreboard.xml} | 3 +-- ...ragment_search_user.xml => fragment_layout_search_user.xml} | 2 -- 3 files changed, 2 insertions(+), 6 deletions(-) rename app/src/main/res/layout/{fragment_game_setup.xml => fragment_layout_game_setup.xml} (99%) rename app/src/main/res/layout/{fragment_scoreboard.xml => fragment_layout_scoreboard.xml} (94%) rename app/src/main/res/layout/{fragment_search_user.xml => fragment_layout_search_user.xml} (96%) diff --git a/app/src/main/res/layout/fragment_game_setup.xml b/app/src/main/res/layout/fragment_layout_game_setup.xml similarity index 99% rename from app/src/main/res/layout/fragment_game_setup.xml rename to app/src/main/res/layout/fragment_layout_game_setup.xml index 72faf0ecb..07b0b0f41 100644 --- a/app/src/main/res/layout/fragment_game_setup.xml +++ b/app/src/main/res/layout/fragment_layout_game_setup.xml @@ -4,8 +4,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/floral_white" - android:noHistory="true" - android:id="@+id/fragment_game_setup"> + android:noHistory="true"> + android:layout_height="match_parent"> Date: Wed, 25 May 2022 23:04:46 +0200 Subject: [PATCH 03/12] ProfileFollowinfAdapter: fix type --- .../java/ch/sdp/vibester/user/ProfileFollowingAdapter.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/ch/sdp/vibester/user/ProfileFollowingAdapter.kt b/app/src/main/java/ch/sdp/vibester/user/ProfileFollowingAdapter.kt index e757f63e7..e81a58d2a 100644 --- a/app/src/main/java/ch/sdp/vibester/user/ProfileFollowingAdapter.kt +++ b/app/src/main/java/ch/sdp/vibester/user/ProfileFollowingAdapter.kt @@ -7,6 +7,7 @@ import android.widget.ImageView import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import ch.sdp.vibester.R +import ch.sdp.vibester.activity.profile.ProfileActivity import ch.sdp.vibester.auth.FireBaseAuthenticator import ch.sdp.vibester.database.DataGetter import ch.sdp.vibester.helper.AdapterHelper @@ -15,11 +16,11 @@ import ch.sdp.vibester.helper.loadImg /** * Set friends in userProfile with profile photo and username in RecycleView. */ -class ProfileFollowingAdapter constructor( +class ProfileFollowingAdapter( private val following: MutableList, val dataGetter: DataGetter, authenticator: FireBaseAuthenticator, - private val listener: OnItemClickListener?, + private val listener: OnItemClickListener, ): RecyclerView.Adapter() { private val currentUser = authenticator.getCurrUser() From 9b071cebadecf94f23f555e1cc0ebf4af92138f2 Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Wed, 25 May 2022 23:05:00 +0200 Subject: [PATCH 04/12] bottom_navigation: set correct ids, clean the code --- .../main/res/navigation/bottom_navigation.xml | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/res/navigation/bottom_navigation.xml b/app/src/main/res/navigation/bottom_navigation.xml index 361571b53..074062c4c 100644 --- a/app/src/main/res/navigation/bottom_navigation.xml +++ b/app/src/main/res/navigation/bottom_navigation.xml @@ -5,12 +5,19 @@ android:id="@+id/bottom_nav" app:startDestination="@id/welcomeScreenBtn"> - - - - + + + + + + + \ No newline at end of file From b35e59089322faebed54cf2396899343b36964a7 Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Wed, 25 May 2022 23:05:14 +0200 Subject: [PATCH 05/12] bottom_menu: set correct ids --- app/src/main/res/menu/bottom_menu.xml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/src/main/res/menu/bottom_menu.xml b/app/src/main/res/menu/bottom_menu.xml index 92003b7ba..e7108e7a2 100644 --- a/app/src/main/res/menu/bottom_menu.xml +++ b/app/src/main/res/menu/bottom_menu.xml @@ -8,21 +8,20 @@ android:icon="@drawable/profile_selector" /> - + tools:ignore="MenuTitle" + /> - From 059ab108a7c7c3aded563f4511addbb3a6bbacd3 Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Wed, 25 May 2022 23:05:35 +0200 Subject: [PATCH 06/12] SearchUserFragment: set correct layout, add view model --- .../vibester/fragment/SearchUserFragment.kt | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/ch/sdp/vibester/fragment/SearchUserFragment.kt b/app/src/main/java/ch/sdp/vibester/fragment/SearchUserFragment.kt index 509971bc2..72955afe3 100644 --- a/app/src/main/java/ch/sdp/vibester/fragment/SearchUserFragment.kt +++ b/app/src/main/java/ch/sdp/vibester/fragment/SearchUserFragment.kt @@ -4,9 +4,7 @@ import android.content.Intent import android.os.Bundle import android.text.Editable import android.text.TextWatcher -import android.view.LayoutInflater import android.view.View -import android.view.ViewGroup import android.widget.EditText import androidx.fragment.app.Fragment import androidx.recyclerview.widget.LinearLayoutManager @@ -17,6 +15,7 @@ import ch.sdp.vibester.activity.profile.PublicProfileActivity import ch.sdp.vibester.auth.FireBaseAuthenticator import ch.sdp.vibester.database.DataGetter import ch.sdp.vibester.database.ImageGetter +import ch.sdp.vibester.helper.ViewModel import ch.sdp.vibester.user.OnItemClickListener import ch.sdp.vibester.user.User @@ -29,7 +28,7 @@ import javax.inject.Inject * Search for users based on their usernames. */ @AndroidEntryPoint -class SearchUserFragment : Fragment(R.layout.fragment_search_user), OnItemClickListener { +class SearchUserFragment : Fragment(R.layout.fragment_layout_search_user), OnItemClickListener { @Inject lateinit var usersRepo: DataGetter @@ -40,6 +39,8 @@ class SearchUserFragment : Fragment(R.layout.fragment_search_user), OnItemClickL @Inject lateinit var authenticator: FireBaseAuthenticator + private val vmSearchUser = ViewModel() + var users = arrayListOf() lateinit var userProfileAdapter: UserProfileAdapter @@ -49,22 +50,23 @@ class SearchUserFragment : Fragment(R.layout.fragment_search_user), OnItemClickL override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + vmSearchUser.view = view + vmSearchUser.ctx = view.context - setUpRecycleView(view) - - searchEditText = view.findViewById(R.id.searchUserET) + setUpRecycleView() + searchEditText = vmSearchUser.view.findViewById(R.id.searchUserET) searchForUsers("") - setScanBtnListener(view) + setScanBtnListener() setSearchFieldListener() } - private fun setScanBtnListener(view: View) { - val buttonScan: FloatingActionButton = view.findViewById(R.id.searchUser_scanning) + private fun setScanBtnListener() { + val buttonScan: FloatingActionButton = vmSearchUser.view.findViewById(R.id.searchUser_scanning) buttonScan.setOnClickListener { - val qrIntent = Intent(requireActivity(), QrScanningActivity::class.java) + val qrIntent = Intent(activity, QrScanningActivity::class.java) qrIntent.putExtra("uidList", uidList) startActivity(qrIntent) } @@ -80,8 +82,8 @@ class SearchUserFragment : Fragment(R.layout.fragment_search_user), OnItemClickL }) } - private fun setUpRecycleView(view: View) { - view.findViewById(R.id.searchList).apply { + private fun setUpRecycleView() { + vmSearchUser.view.findViewById(R.id.searchList).apply { layoutManager = LinearLayoutManager(context) userProfileAdapter = UserProfileAdapter(users, authenticator, usersRepo, imageGetter, this@SearchUserFragment) adapter = userProfileAdapter @@ -113,7 +115,7 @@ class SearchUserFragment : Fragment(R.layout.fragment_search_user), OnItemClickL } override fun onItemClick(position: Int) { - val intent = Intent(requireActivity(), PublicProfileActivity::class.java) + val intent = Intent(activity, PublicProfileActivity::class.java) intent.putExtra("UserId", users[position].uid) intent.putExtra("ScoresOrFollowing", R.string.profile_following.toString()) startActivity(intent) From a61e114e3af288b307d18d4a1ef0197dbb18aa51 Mon Sep 17 00:00:00 2001 From: Kamila Babayeva Date: Wed, 25 May 2022 23:05:42 +0200 Subject: [PATCH 07/12] ScoreBoardFragment: set correct layout, add view model --- .../vibester/fragment/ScoreBoardFragment.kt | 67 ++++++++----------- 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/ch/sdp/vibester/fragment/ScoreBoardFragment.kt b/app/src/main/java/ch/sdp/vibester/fragment/ScoreBoardFragment.kt index b63b44903..c2cf0ee14 100644 --- a/app/src/main/java/ch/sdp/vibester/fragment/ScoreBoardFragment.kt +++ b/app/src/main/java/ch/sdp/vibester/fragment/ScoreBoardFragment.kt @@ -1,15 +1,12 @@ package ch.sdp.vibester.fragment import android.content.ContentValues -import android.content.Context import android.content.Intent import android.os.Bundle import android.util.Log -import android.view.LayoutInflater import android.view.View import android.view.View.GONE import android.view.View.VISIBLE -import android.view.ViewGroup import android.widget.Button import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.widget.NestedScrollView @@ -20,6 +17,7 @@ import ch.sdp.vibester.R import ch.sdp.vibester.activity.profile.PublicProfileActivity import ch.sdp.vibester.database.Database import ch.sdp.vibester.database.ImageGetter +import ch.sdp.vibester.helper.ViewModel import ch.sdp.vibester.user.OnItemClickListener import ch.sdp.vibester.user.User import ch.sdp.vibester.user.UserScoreboardAdapter @@ -31,68 +29,59 @@ import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject @AndroidEntryPoint -class ScoreBoardFragment : Fragment(), OnItemClickListener { +class ScoreBoardFragment : Fragment(R.layout.fragment_layout_scoreboard), OnItemClickListener { private val dbRef: DatabaseReference = Database.get().getReference("users") private var players: MutableList = mutableListOf() private var userScoreboardAdapter: UserScoreboardAdapter? = null private var genre: String = "" - private var testView: View? = null - + private var vmScoreBoard = ViewModel() @Inject lateinit var imageGetter: ImageGetter - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - return inflater.inflate(R.layout.fragment_scoreboard, container, false).rootView - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val ctx = view.context - - testView = view - - view.findViewById