From eecf593af9022c8028b9c6fd2f6d03b7028864eb Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Wed, 11 Oct 2023 20:05:28 +0300 Subject: [PATCH] addons: viewbinding in myMeetups (fixes #2563) (#2567) Co-authored-by: dogi --- app/build.gradle | 4 +- .../ui/mymeetup/MyMeetUpsFragment.java | 14 +++--- .../ui/mymeetup/MyMeetupDetailFragment.java | 44 ++++++++----------- 3 files changed, 29 insertions(+), 33 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0e02ca86f9..5e3dc75cf4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1089 - versionName "0.10.89" + versionCode 1090 + versionName "0.10.90" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/mymeetup/MyMeetUpsFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/mymeetup/MyMeetUpsFragment.java index 06d8e6e7c9..6431d9643f 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/mymeetup/MyMeetUpsFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/mymeetup/MyMeetUpsFragment.java @@ -1,22 +1,24 @@ package org.ole.planet.myplanet.ui.mymeetup; import android.os.Bundle; - -import androidx.fragment.app.Fragment; - import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import org.ole.planet.myplanet.R; +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; + +import org.ole.planet.myplanet.databinding.FragmentMyMeetUpsBinding; public class MyMeetUpsFragment extends Fragment { + private FragmentMyMeetUpsBinding fragmentMyMeetUpsBinding; public MyMeetUpsFragment() { // Required empty public constructor } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_my_meet_ups, container, false); + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + fragmentMyMeetUpsBinding = FragmentMyMeetUpsBinding.inflate(inflater, container, false); + return fragmentMyMeetUpsBinding.getRoot(); } } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/mymeetup/MyMeetupDetailFragment.java b/app/src/main/java/org/ole/planet/myplanet/ui/mymeetup/MyMeetupDetailFragment.java index 61056941c6..1e05a9422f 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/mymeetup/MyMeetupDetailFragment.java +++ b/app/src/main/java/org/ole/planet/myplanet/ui/mymeetup/MyMeetupDetailFragment.java @@ -1,21 +1,19 @@ package org.ole.planet.myplanet.ui.mymeetup; import android.os.Bundle; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; - import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + import org.ole.planet.myplanet.R; +import org.ole.planet.myplanet.databinding.FragmentMyMeetupDetailBinding; import org.ole.planet.myplanet.datamanager.DatabaseService; import org.ole.planet.myplanet.model.RealmMeetup; import org.ole.planet.myplanet.model.RealmUserModel; @@ -29,13 +27,11 @@ import io.realm.RealmResults; public class MyMeetupDetailFragment extends Fragment implements View.OnClickListener { - LinearLayout llContent; + private FragmentMyMeetupDetailBinding fragmentMyMeetupDetailBinding; RealmMeetup meetups; Realm mRealm; String meetUpId; - TextView title; - Button btnLeave; - Button btnInvite; + UserProfileDbHandler profileDbHandler; RealmUserModel user; ListView listUsers; @@ -56,20 +52,17 @@ public void onCreate(@Nullable Bundle savedInstanceState) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_my_meetup_detail, container, false); - listDesc = v.findViewById(R.id.list_desc); - listUsers = v.findViewById(R.id.list_users); - tvJoined = v.findViewById(R.id.tv_joined); - btnInvite = v.findViewById(R.id.btn_invite); - btnInvite.setVisibility(Constants.showBetaFeature(Constants.KEY_MEETUPS, getActivity()) ? View.VISIBLE : View.GONE); - btnLeave = v.findViewById(R.id.btn_leave); - btnLeave.setVisibility(Constants.showBetaFeature(Constants.KEY_MEETUPS, getActivity()) ? View.VISIBLE : View.GONE); - btnLeave.setOnClickListener(this); - title = v.findViewById(R.id.meetup_title); + fragmentMyMeetupDetailBinding = FragmentMyMeetupDetailBinding.inflate(inflater, container, false); + listDesc = fragmentMyMeetupDetailBinding.getRoot().findViewById(R.id.list_desc); + listUsers = fragmentMyMeetupDetailBinding.getRoot().findViewById(R.id.list_users); + tvJoined = fragmentMyMeetupDetailBinding.getRoot().findViewById(R.id.tv_joined); + fragmentMyMeetupDetailBinding.btnInvite.setVisibility(Constants.showBetaFeature(Constants.KEY_MEETUPS, getActivity()) ? View.VISIBLE : View.GONE); + fragmentMyMeetupDetailBinding.btnLeave.setVisibility(Constants.showBetaFeature(Constants.KEY_MEETUPS, getActivity()) ? View.VISIBLE : View.GONE); + fragmentMyMeetupDetailBinding.btnLeave.setOnClickListener(this); mRealm = new DatabaseService(getActivity()).getRealmInstance(); profileDbHandler = new UserProfileDbHandler(getActivity()); user = mRealm.copyFromRealm(profileDbHandler.getUserModel()); - return v; + return fragmentMyMeetupDetailBinding.getRoot(); } @Override @@ -88,7 +81,7 @@ private void setUserList() { } private void setUpData() { - title.setText(meetups.getTitle()); + fragmentMyMeetupDetailBinding.meetupTitle.setText(meetups.getTitle()); final HashMap map = RealmMeetup.getHashMap(meetups); final ArrayList keys = new ArrayList<>(map.keySet()); listDesc.setAdapter(new ArrayAdapter(getActivity(), R.layout.row_description, keys) { @@ -116,11 +109,12 @@ private void leaveJoinMeetUp() { mRealm.executeTransaction(realm -> { if (meetups.getUserId().isEmpty()) { meetups.setUserId(user.getId()); - btnLeave.setText(R.string.leave); + fragmentMyMeetupDetailBinding.btnLeave.setText(R.string.leave); } else { meetups.setUserId(""); - btnLeave.setText(R.string.join); + fragmentMyMeetupDetailBinding.btnLeave.setText(R.string.join); } }); } } +