Skip to content

Commit a13b84c

Browse files
committed
chore: convert MultimediaImageFragment to ViewBinding
Issue 11116
1 parent a000254 commit a13b84c

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import android.os.Bundle
2929
import android.provider.MediaStore
3030
import android.view.View
3131
import android.webkit.WebView
32-
import android.widget.TextView
3332
import androidx.activity.result.contract.ActivityResultContracts
3433
import androidx.annotation.DrawableRes
3534
import androidx.appcompat.app.AlertDialog
@@ -40,11 +39,11 @@ import androidx.core.content.IntentCompat
4039
import androidx.core.os.BundleCompat
4140
import androidx.fragment.app.Fragment
4241
import androidx.lifecycle.lifecycleScope
43-
import com.google.android.material.button.MaterialButton
4442
import com.ichi2.anki.CollectionManager.TR
4543
import com.ichi2.anki.DrawingFragment
4644
import com.ichi2.anki.R
4745
import com.ichi2.anki.common.annotations.NeedsTest
46+
import com.ichi2.anki.databinding.FragmentMultimediaImageBinding
4847
import com.ichi2.anki.multimedia.MultimediaActivity.Companion.EXTRA_MEDIA_OPTIONS
4948
import com.ichi2.anki.multimedia.MultimediaActivity.Companion.MULTIMEDIA_RESULT
5049
import com.ichi2.anki.multimedia.MultimediaActivity.Companion.MULTIMEDIA_RESULT_FIELD_INDEX
@@ -67,6 +66,7 @@ import com.ichi2.utils.negativeButton
6766
import com.ichi2.utils.openInputStreamSafe
6867
import com.ichi2.utils.positiveButton
6968
import com.ichi2.utils.show
69+
import dev.androidbroadcast.vbpd.viewBinding
7070
import kotlinx.coroutines.flow.collectLatest
7171
import kotlinx.coroutines.launch
7272
import timber.log.Timber
@@ -80,11 +80,11 @@ private const val SVG_IMAGE = "image/svg+xml"
8080

8181
@NeedsTest("Ensure correct option is executed i.e. gallery or camera")
8282
class MultimediaImageFragment : MultimediaFragment(R.layout.fragment_multimedia_image) {
83+
private val binding by viewBinding(FragmentMultimediaImageBinding::bind)
84+
8385
override val title: String
8486
get() = resources.getString(R.string.multimedia_editor_popup_image)
8587

86-
private lateinit var imageFileSize: TextView
87-
8888
private lateinit var selectedImageOptions: ImageOptions
8989

9090
/** Keeps track of the process in case `Don't keep activities` in turned on*/
@@ -282,7 +282,6 @@ class MultimediaImageFragment : MultimediaFragment(R.layout.fragment_multimedia_
282282
) {
283283
super.onViewCreated(view, savedInstanceState)
284284
setupMenu(multimediaMenu)
285-
imageFileSize = view.findViewById(R.id.image_size_textview)
286285

287286
handleImageUri()
288287
setupDoneButton()
@@ -329,7 +328,7 @@ class MultimediaImageFragment : MultimediaFragment(R.layout.fragment_multimedia_
329328
}
330329

331330
private fun setupDoneButton() {
332-
view?.findViewById<MaterialButton>(R.id.action_done)?.setOnClickListener {
331+
binding.actionDone.setOnClickListener {
333332
Timber.d("MultimediaImageFragment:: Done button pressed")
334333
if (viewModel.selectedMediaFileSize == 0L) {
335334
Timber.d("Image length is not valid")
@@ -453,7 +452,7 @@ class MultimediaImageFragment : MultimediaFragment(R.layout.fragment_multimedia_
453452

454453
private fun updateAndDisplayImageSize(file: File) {
455454
viewModel.selectedMediaFileSize = file.length()
456-
imageFileSize.text = file.toHumanReadableSize()
455+
binding.imageFileSize.text = file.toHumanReadableSize()
457456
}
458457

459458
private fun showLargeFileCropDialog(length: Long) {
@@ -564,7 +563,7 @@ class MultimediaImageFragment : MultimediaFragment(R.layout.fragment_multimedia_
564563
val mimeType = context?.contentResolver?.getType(imageUri)
565564

566565
// Get the WebView and set it visible
567-
view?.findViewById<WebView>(R.id.multimedia_webview)?.apply {
566+
binding.multimediaWebView.apply {
568567
visibility = View.VISIBLE
569568

570569
// Load image based on its MIME type
@@ -655,7 +654,7 @@ class MultimediaImageFragment : MultimediaFragment(R.layout.fragment_multimedia_
655654
</html>
656655
""".trimIndent()
657656

658-
view?.findViewById<WebView>(R.id.multimedia_webview)?.loadDataWithBaseURL(null, errorHtml, "text/html", "UTF-8", null)
657+
binding.multimediaWebView.loadDataWithBaseURL(null, errorHtml, "text/html", "UTF-8", null)
659658
}
660659

661660
private fun requestCrop() {

AnkiDroid/src/main/res/layout/fragment_multimedia_image.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
android:layout_marginHorizontal="8dp"
3232
android:layout_height="0dp"
3333
app:layout_constraintTop_toTopOf="parent"
34-
app:layout_constraintBottom_toTopOf="@id/image_size_textview"
34+
app:layout_constraintBottom_toTopOf="@id/image_file_size"
3535
style="@style/CardView.ViewerStyle" >
3636

3737
<WebView
38-
android:id="@+id/multimedia_webview"
38+
android:id="@+id/multimedia_web_view"
3939
android:layout_width="match_parent"
4040
android:layout_height="match_parent"/>
4141

@@ -49,7 +49,7 @@
4949
app:layout_constraintEnd_toEndOf="parent"
5050
app:layout_constraintTop_toBottomOf="@id/imageview_container"
5151
android:gravity="center"
52-
android:id="@+id/image_size_textview"
52+
android:id="@+id/image_file_size"
5353
android:layout_width="match_parent"
5454
android:layout_height="wrap_content"/>
5555

@@ -61,7 +61,7 @@
6161
app:layout_constraintStart_toStartOf="parent"
6262
app:layout_constraintEnd_toEndOf="parent"
6363
app:layout_constraintBottom_toBottomOf="parent"
64-
app:layout_constraintTop_toBottomOf="@id/image_size_textview"
64+
app:layout_constraintTop_toBottomOf="@id/image_file_size"
6565
android:text="@string/multimedia_editor_field_editing_done"/>
6666

6767
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)