Minor UI improvements and code cleanup

This commit is contained in:
Bnyro 2023-01-30 16:39:05 +01:00
parent 3265ce81f4
commit 758f559811
3 changed files with 10 additions and 9 deletions

View File

@ -9,9 +9,11 @@ import android.view.ViewGroup.MarginLayoutParams
import android.widget.Toast
import androidx.core.text.parseAsHtml
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R
import com.github.libretube.api.JsonHelper
import com.github.libretube.api.obj.Comment
import com.github.libretube.constants.IntentData
import com.github.libretube.databinding.CommentsRowBinding
@ -23,7 +25,6 @@ import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.TextUtils
import com.github.libretube.util.ThemeHelper
import kotlinx.serialization.json.Json
class CommentsAdapter(
private val fragment: Fragment?,
@ -77,14 +78,13 @@ class CommentsAdapter(
repliesCount.visibility = View.GONE
repliesAvailable.visibility = View.GONE
// highlight the comment that is being replied to
if (position == 0) {
root.setBackgroundColor(
ThemeHelper.getThemeColor(root.context, R.attr.colorSurface)
)
root.updateLayoutParams<MarginLayoutParams> { bottomMargin = 40 }
} else {
root.background = null
root.updateLayoutParams<MarginLayoutParams> { bottomMargin = 0 }
root.updatePadding(top = 20)
root.updateLayoutParams<MarginLayoutParams> { bottomMargin = 20 }
}
}
@ -94,7 +94,7 @@ class CommentsAdapter(
putString(IntentData.videoId, videoId)
putString(
IntentData.comment,
Json.encodeToString(Comment.serializer(), comment)
JsonHelper.json.encodeToString(Comment.serializer(), comment)
)
}
}

View File

@ -9,6 +9,7 @@ import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.libretube.api.JsonHelper
import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.obj.Comment
import com.github.libretube.api.obj.CommentsPage
@ -43,7 +44,7 @@ class CommentsRepliesFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val videoId = arguments?.getString(IntentData.videoId) ?: ""
val comment = Json.decodeFromString(
val comment = JsonHelper.json.decodeFromString(
Comment.serializer(),
arguments?.getString(IntentData.comment) ?: """{}"""
)
@ -53,7 +54,7 @@ class CommentsRepliesFragment : Fragment() {
}
binding.commentsRV.updatePadding(top = 0)
binding.commentsRV.layoutManager = LinearLayoutManager(view.context)
binding.commentsRV.layoutManager = LinearLayoutManager(context)
binding.commentsRV.adapter = repliesAdapter
binding.commentsRV.viewTreeObserver

View File

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground">
android:background="@drawable/rounded_ripple">
<LinearLayout
android:layout_width="match_parent"