-
-
Notifications
You must be signed in to change notification settings - Fork 30
Enhance Movie Detail Screen Experience #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,6 +31,7 @@ import com.wirelessalien.android.moviedb.R | |||||||||||||||||||||||||||||||||||||||||||||||
| import com.wirelessalien.android.moviedb.databinding.ReviewItemBinding | ||||||||||||||||||||||||||||||||||||||||||||||||
| import org.json.JSONObject | ||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Locale | ||||||||||||||||||||||||||||||||||||||||||||||||
| import android.graphics.Typeface | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| class ReviewAdapter : | ||||||||||||||||||||||||||||||||||||||||||||||||
| PagingDataAdapter<JSONObject, ReviewAdapter.ReviewViewHolder>(ReviewDiffCallback()) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -77,18 +78,26 @@ class ReviewAdapter : | |||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| binding.root.context.getString(R.string.rating_na) | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| // Set content with max lines and click listener | ||||||||||||||||||||||||||||||||||||||||||||||||
| // Set content with spoiler warning, max lines and click listener | ||||||||||||||||||||||||||||||||||||||||||||||||
| val content = review.optString("content") | ||||||||||||||||||||||||||||||||||||||||||||||||
| binding.textViewContent.text = content | ||||||||||||||||||||||||||||||||||||||||||||||||
| binding.textViewContent.post { | ||||||||||||||||||||||||||||||||||||||||||||||||
| if (binding.textViewContent.lineCount > 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| binding.textViewContent.maxLines = 3 | ||||||||||||||||||||||||||||||||||||||||||||||||
| isContentExpanded = false | ||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| isContentExpanded = true | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| val isSpoiler = content.startsWith("⚠️ Possible spoiler") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| if (isSpoiler) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| val cleanedContent = content | ||||||||||||||||||||||||||||||||||||||||||||||||
| .replace("⚠️ Possible spoiler", "") | ||||||||||||||||||||||||||||||||||||||||||||||||
| .trim() | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| binding.textViewContent.text = "⚠️ SPOILER WARNING\n\n$cleanedContent" | ||||||||||||||||||||||||||||||||||||||||||||||||
| binding.textViewContent.setTypeface(null, Typeface.BOLD) | ||||||||||||||||||||||||||||||||||||||||||||||||
| binding.textViewContent.alpha = 0.9f | ||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| binding.textViewContent.text = content | ||||||||||||||||||||||||||||||||||||||||||||||||
| binding.textViewContent.setTypeface(null, Typeface.NORMAL) | ||||||||||||||||||||||||||||||||||||||||||||||||
| binding.textViewContent.alpha = 1.0f | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| binding.textViewContent.post { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| binding.textViewContent.setOnClickListener { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+81
to
101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The // Set content with spoiler warning, max lines and click listener
val content = review.optString("content")
val isSpoiler = content.startsWith("⚠️ Possible spoiler")
if (isSpoiler) {
val cleanedContent = content
.replace("⚠️ Possible spoiler", "")
.trim()
binding.textViewContent.text = "⚠️ SPOILER WARNING\n\n$cleanedContent"
binding.textViewContent.setTypeface(null, Typeface.BOLD)
binding.textViewContent.alpha = 0.9f
} else {
binding.textViewContent.text = content
binding.textViewContent.setTypeface(null, Typeface.NORMAL)
binding.textViewContent.alpha = 1.0f
}
binding.textViewContent.post {
if (binding.textViewContent.lineCount > 3) {
binding.textViewContent.maxLines = 3
isContentExpanded = false
} else {
isContentExpanded = true
}
}
binding.textViewContent.setOnClickListener { |
||||||||||||||||||||||||||||||||||||||||||||||||
| if (binding.textViewContent.lineCount > 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| isContentExpanded = !isContentExpanded | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -111,6 +120,17 @@ class ReviewAdapter : | |||||||||||||||||||||||||||||||||||||||||||||||
| return oldItem.getString("id") == newItem.getString("id") | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| override fun areContentsTheSame(oldItem: JSONObject, newItem: JSONObject): Boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return oldItem.toString() == newItem.toString() | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| class ReviewDiffCallback : DiffUtil.ItemCallback<JSONObject>() { | ||||||||||||||||||||||||||||||||||||||||||||||||
| override fun areItemsTheSame(oldItem: JSONObject, newItem: JSONObject): Boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return oldItem.optString("id") == newItem.optString("id") | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| override fun areContentsTheSame(oldItem: JSONObject, newItem: JSONObject): Boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return oldItem.toString() == newItem.toString() | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
120
to
136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a duplicated definition of
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -75,6 +75,8 @@ class HomeFragment : BaseFragment() { | |||||
| private lateinit var mTVShowAdapter: NowPlayingMovieAdapter | ||||||
| private lateinit var mUpcomingMovieAdapter: NowPlayingMovieAdapter | ||||||
| private lateinit var mUpcomingTVAdapter: NowPlayingMovieAdapter | ||||||
| private lateinit var mTopRatedMovieArrayList: ArrayList<JSONObject> | ||||||
| private lateinit var mTopRatedMovieAdapter: NowPlayingMovieAdapter | ||||||
| private lateinit var binding: FragmentHomeBinding | ||||||
| private lateinit var activityBinding: ActivityMainBinding | ||||||
| private lateinit var menuProvider: MenuProvider | ||||||
|
|
@@ -101,6 +103,7 @@ class HomeFragment : BaseFragment() { | |||||
| fetchTrendingList() | ||||||
| fetchUpcomingMovies() | ||||||
| fetchUpcomingTVShows() | ||||||
|
|
||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -117,6 +120,7 @@ class HomeFragment : BaseFragment() { | |||||
| showTrendingList() | ||||||
| showUpcomingMovieList() | ||||||
| showUpcomingTVShowList() | ||||||
| // showTopRatedMovieList() | ||||||
| activityBinding.fab2.visibility = View.GONE | ||||||
| activityBinding.fab.visibility = View.GONE | ||||||
| activityBinding.searchView.setupWithSearchBar(binding.searchbar) | ||||||
|
|
@@ -227,11 +231,13 @@ class HomeFragment : BaseFragment() { | |||||
| mUpcomingTVAdapter = NowPlayingMovieAdapter(mUpcomingTVShowArrayList) | ||||||
| mUpcomingMovieArrayList = ArrayList() | ||||||
| mUpcomingMovieAdapter = NowPlayingMovieAdapter(mUpcomingMovieArrayList) | ||||||
| mTopRatedMovieArrayList = ArrayList() | ||||||
| mTopRatedMovieAdapter = NowPlayingMovieAdapter(mTopRatedMovieArrayList) | ||||||
| (requireActivity() as BaseActivity).checkNetwork() | ||||||
| } | ||||||
|
|
||||||
| private fun setupRecyclerView( | ||||||
| recyclerView: RecyclerView?, | ||||||
| recyclerView: RecyclerView, | ||||||
| layoutManager: LinearLayoutManager, | ||||||
| adapter: RecyclerView.Adapter<*>? | ||||||
| ) { | ||||||
|
|
@@ -258,7 +264,10 @@ class HomeFragment : BaseFragment() { | |||||
| val layoutManager = LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false) | ||||||
| setupRecyclerView(binding.upcomingMovieRecyclerView, layoutManager, mUpcomingMovieAdapter) | ||||||
| } | ||||||
|
|
||||||
| private fun showTopRatedMovieList() { | ||||||
| val layoutManager = LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false) | ||||||
| setupRecyclerView(binding.upcomingMovieRecyclerView, layoutManager, mTopRatedMovieAdapter) | ||||||
| } | ||||||
| private suspend fun fetchUpcomingTVShows() { | ||||||
| withContext(Dispatchers.Main) { | ||||||
| binding.shimmerFrameLayout5.visibility = View.VISIBLE | ||||||
|
|
@@ -272,7 +281,7 @@ class HomeFragment : BaseFragment() { | |||||
| val response = fetchData(url) | ||||||
| withContext(Dispatchers.Main) { | ||||||
| if (isAdded && !response.isNullOrEmpty()) { | ||||||
| handleUpcomingTVResponse(response) | ||||||
| handleMovieResponse(response) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In
Suggested change
|
||||||
| } else { | ||||||
| binding.shimmerFrameLayout5.visibility = View.GONE | ||||||
| binding.shimmerFrameLayout5.stopShimmer() | ||||||
|
|
@@ -323,7 +332,7 @@ class HomeFragment : BaseFragment() { | |||||
| val response = fetchData(url) | ||||||
| withContext(Dispatchers.Main) { | ||||||
| if (isAdded && !response.isNullOrEmpty()) { | ||||||
| handleMovieResponse(response) | ||||||
| //SDFKLNHGJKSHKDJFGHSJKLGHDFJKFDGHKJFDHJKFGDHJGIDFK | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The keyboard smash comment completely disables handling the movie response for now playing movies, leaving the UI in a permanent shimmer state when data is successfully fetched. Let's restore the correct call to
Suggested change
|
||||||
| } else { | ||||||
| binding.shimmerFrameLayout2.visibility = View.GONE | ||||||
| binding.shimmerFrameLayout2.stopShimmer() | ||||||
|
|
@@ -374,10 +383,12 @@ class HomeFragment : BaseFragment() { | |||||
| val reader = JSONObject(response) | ||||||
| val arrayData = reader.getJSONArray("results") | ||||||
| mHomeShowArrayList.clear() | ||||||
|
|
||||||
| for (i in 0 until arrayData.length()) { | ||||||
| val websiteData = arrayData.getJSONObject(i) | ||||||
| mHomeShowArrayList.add(websiteData) | ||||||
| } | ||||||
|
|
||||||
| binding.nowPlayingRecyclerView.adapter = mHomeShowAdapter | ||||||
| mShowListLoaded = true | ||||||
| binding.shimmerFrameLayout2.visibility = View.GONE | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of integer division and the time component of
today, any future release date that is less than 24 hours away will result indiffInDaysbeing0, causing it to be incorrectly labeled asNewinstead ofUpcoming. UsingreleaseDate.after(today)directly resolves this issue.