Skip to content

Commit

Permalink
feedback: smoother empty list (fixes #3726) (#3783)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
rlam20 and dogi committed Jul 8, 2024
1 parent 3a65ee9 commit 54f59ed
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1657
versionName "0.16.57"
versionCode 1658
versionName "0.16.58"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ abstract class BaseRecyclerFragment<LI> : BaseRecyclerParentFragment<Any?>(), On
"submission" -> (v as TextView).setText(R.string.no_submissions)
"teams" -> (v as TextView).setText(R.string.no_teams)
"chatHistory" -> (v as TextView).setText(R.string.no_chats)
"feedback" -> (v as TextView).setText(R.string.no_feedback)
else -> (v as TextView).setText(R.string.no_data_available_please_check_and_try_again)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.ole.planet.myplanet.model.RealmFeedback
import org.ole.planet.myplanet.model.RealmUserModel
import org.ole.planet.myplanet.service.UserProfileDbHandler
import org.ole.planet.myplanet.ui.feedback.FeedbackFragment.OnFeedbackSubmittedListener
import org.ole.planet.myplanet.base.BaseRecyclerFragment.Companion.showNoData

class FeedbackListFragment : Fragment(), OnFeedbackSubmittedListener {
private lateinit var fragmentFeedbackListBinding: FragmentFeedbackListBinding
Expand All @@ -25,6 +26,7 @@ class FeedbackListFragment : Fragment(), OnFeedbackSubmittedListener {
fragmentFeedbackListBinding = FragmentFeedbackListBinding.inflate(inflater, container, false)
mRealm = DatabaseService(requireActivity()).realmInstance
userModel = UserProfileDbHandler(requireContext()).userModel

fragmentFeedbackListBinding.fab.setOnClickListener {
val feedbackFragment = FeedbackFragment()
feedbackFragment.setOnFeedbackSubmittedListener(this)
Expand All @@ -33,15 +35,13 @@ class FeedbackListFragment : Fragment(), OnFeedbackSubmittedListener {
}
}

mRealm.executeTransactionAsync(
Realm.Transaction { },
Realm.Transaction.OnSuccess {
feedbackList = mRealm.where(RealmFeedback::class.java)
.equalTo("owner", userModel?.name).findAllAsync()
feedbackList?.addChangeListener { results ->
updatedFeedbackList(results)
}
})
feedbackList = mRealm.where(RealmFeedback::class.java)
.equalTo("owner", userModel?.name).findAllAsync()

feedbackList?.addChangeListener { results ->
updatedFeedbackList(results)
}

return fragmentFeedbackListBinding.root
}

Expand All @@ -53,6 +53,11 @@ class FeedbackListFragment : Fragment(), OnFeedbackSubmittedListener {
if (userModel?.isManager() == true) list = mRealm.where(RealmFeedback::class.java).findAll()
val adapterFeedback = AdapterFeedback(requireActivity(), list)
fragmentFeedbackListBinding.rvFeedback.adapter = adapterFeedback

val itemCount = feedbackList?.size ?: 0
showNoData(fragmentFeedbackListBinding.tvMessage, itemCount, "feedback")

updateTextViewsVisibility(itemCount)
}

override fun onDestroy() {
Expand All @@ -74,11 +79,25 @@ class FeedbackListFragment : Fragment(), OnFeedbackSubmittedListener {
updatedFeedbackList(updatedList)
})
}

private fun updatedFeedbackList(updatedList: RealmResults<RealmFeedback>?) {
activity?.runOnUiThread {
val adapterFeedback = updatedList?.let { AdapterFeedback(requireActivity(), it) }
fragmentFeedbackListBinding.rvFeedback.adapter = adapterFeedback
adapterFeedback?.notifyDataSetChanged()

val itemCount = updatedList?.size ?: 0
showNoData(fragmentFeedbackListBinding.tvMessage, itemCount, "feedback")
updateTextViewsVisibility(itemCount)
}
}

private fun updateTextViewsVisibility(itemCount: Int) {
val visibility = if (itemCount == 0) View.GONE else View.VISIBLE
fragmentFeedbackListBinding.tvTitle.visibility = visibility
fragmentFeedbackListBinding.tvType.visibility = visibility
fragmentFeedbackListBinding.tvPriority.visibility = visibility
fragmentFeedbackListBinding.tvStatus.visibility = visibility
fragmentFeedbackListBinding.tvOpenDate.visibility = visibility
}
}
11 changes: 7 additions & 4 deletions app/src/main/res/layout/fragment_feedback_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">


<TextView
android:id="@+id/tv_title"
android:layout_width="0dp"
Expand All @@ -41,7 +40,6 @@
android:textColor="@color/md_black_1000"
android:textSize="@dimen/text_size_mid" />


<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand All @@ -59,7 +57,6 @@
android:textSize="@dimen/text_size_mid" />
</LinearLayout>


<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -112,4 +109,10 @@
android:src="@drawable/ic_add"
android:contentDescription="@string/add" />

</FrameLayout>
<TextView
android:visibility="gone"
android:id="@+id/tvMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@
<string name="planet_name">كوكب %s</string>
<string name="no_submissions">التقديمات غير متاحة</string>
<string name="no_chats">لا توجد محادثات سابقة</string>
<string name="no_feedback">لا توجد تعليقات متاحة</string>
<string name="empty_text"></string>
<string name="message_placeholder">%s</string>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@
<string name="planet_name">%s Planeta</string>
<string name="no_submissions">envíos no disponibles</string>
<string name="no_chats">no hay chats anteriores</string>
<string name="no_feedback">No hay comentarios aquí</string>
<string name="empty_text"></string>
<string name="message_placeholder">%s</string>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@
<string name="planet_name">%s planète</string>
<string name="no_submissions">soumissions non disponibles</string>
<string name="no_chats">aucune discussion précédente</string>
<string name="no_feedback">aucun commentaire disponible</string>
<string name="empty_text"></string>
<string name="message_placeholder">%s</string>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ne/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@
<string name="planet_name">%s ग्रह</string>
<string name="no_submissions">पेशाहरू उपलब्ध छैनन्</string>
<string name="no_chats">अघिल्ला कुराकानीहरू छैनन्</string>
<string name="no_feedback">कुनै प्रतिक्रिया उपलब्ध छैन</string>
<string name="empty_text"></string>
<string name="message_placeholder">%s</string>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-so/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@
<string name="planet_name">%s Meerah</string>
<string name="no_submissions">soo gudbin lama heli karo</string>
<string name="no_chats">ma jiraan wada sheekaysi hore</string>
<string name="no_feedback">wax jawaab celin ah lama hayo</string>
<string name="empty_text"></string>
<string name="message_placeholder">%s</string>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@
<string name="planet_name">%s\'s Planet</string>
<string name="no_submissions">submissions not available</string>
<string name="no_chats">no previous chats</string>
<string name ="no_feedback">no feedback available</string>
<string name="empty_text"></string>
<string name="message_placeholder">%s</string>

Expand Down

0 comments on commit 54f59ed

Please sign in to comment.