@@ -15,8 +15,6 @@ import android.widget.TextView
15
15
import android.widget.Toast
16
16
import androidx.core.content.ContextCompat
17
17
import androidx.lifecycle.ViewModelProvider
18
- import butterknife.BindView
19
- import butterknife.ButterKnife
20
18
import com.facebook.drawee.backends.pipeline.Fresco
21
19
import com.facebook.drawee.controller.BaseControllerListener
22
20
import com.facebook.drawee.controller.ControllerListener
@@ -38,6 +36,7 @@ import fr.free.nrw.commons.customselector.model.Image
38
36
import fr.free.nrw.commons.customselector.model.Result
39
37
import fr.free.nrw.commons.customselector.ui.selector.CustomSelectorViewModel
40
38
import fr.free.nrw.commons.customselector.ui.selector.CustomSelectorViewModelFactory
39
+ import fr.free.nrw.commons.databinding.ActivityZoomableBinding
41
40
import fr.free.nrw.commons.media.zoomControllers.zoomable.DoubleTapGestureListener
42
41
import fr.free.nrw.commons.media.zoomControllers.zoomable.ZoomableDraweeView
43
42
import fr.free.nrw.commons.theme.BaseActivity
@@ -67,20 +66,10 @@ class ZoomableActivity : BaseActivity() {
67
66
*/
68
67
private lateinit var prefs: SharedPreferences
69
68
70
- @JvmField
71
- @BindView(R .id.zoomable)
72
- var photo: ZoomableDraweeView ? = null
69
+ private lateinit var binding: ActivityZoomableBinding
73
70
74
71
var photoBackgroundColor: Int? = null
75
72
76
- @JvmField
77
- @BindView(R .id.zoom_progress_bar)
78
- var spinner: ProgressBar ? = null
79
-
80
- @JvmField
81
- @BindView(R .id.selection_count)
82
- var selectedCount: TextView ? = null
83
-
84
73
/* *
85
74
* Total images present in folder
86
75
*/
@@ -145,8 +134,8 @@ class ZoomableActivity : BaseActivity() {
145
134
146
135
override fun onCreate (savedInstanceState : Bundle ? ) {
147
136
super .onCreate(savedInstanceState)
148
- setContentView( R .layout.activity_zoomable )
149
- ButterKnife .bind( this )
137
+ binding = ActivityZoomableBinding .inflate(layoutInflater )
138
+ setContentView(binding.root )
150
139
151
140
prefs = applicationContext.getSharedPreferences(
152
141
ImageHelper .CUSTOM_SELECTOR_PREFERENCE_KEY ,
@@ -221,7 +210,7 @@ class ZoomableActivity : BaseActivity() {
221
210
onSwipe()
222
211
}
223
212
}
224
- spinner ?.let {
213
+ binding.zoomProgressBar ?.let {
225
214
it.visibility = if (result.status is CallbackStatus .FETCHING ) View .VISIBLE else View .GONE
226
215
}
227
216
}
@@ -236,7 +225,7 @@ class ZoomableActivity : BaseActivity() {
236
225
sharedPreferences.getBoolean(ImageHelper .SHOW_ALREADY_ACTIONED_IMAGES_PREFERENCE_KEY , true )
237
226
238
227
if (! images.isNullOrEmpty()) {
239
- photo !! .setOnTouchListener(object : OnSwipeTouchListener (this ) {
228
+ binding.zoomable !! .setOnTouchListener(object : OnSwipeTouchListener (this ) {
240
229
// Swipe left to view next image in the folder. (if available)
241
230
override fun onSwipeLeft () {
242
231
super .onSwipeLeft()
@@ -271,7 +260,7 @@ class ZoomableActivity : BaseActivity() {
271
260
* Handles down swipe action
272
261
*/
273
262
private fun onDownSwiped () {
274
- if (photo ?.zoomableController?.isIdentity == false )
263
+ if (binding.zoomable ?.zoomableController?.isIdentity == false )
275
264
return
276
265
277
266
scope.launch {
@@ -333,7 +322,7 @@ class ZoomableActivity : BaseActivity() {
333
322
* Handles up swipe action
334
323
*/
335
324
private fun onUpSwiped () {
336
- if (photo ?.zoomableController?.isIdentity == false )
325
+ if (binding.zoomable ?.zoomableController?.isIdentity == false )
337
326
return
338
327
339
328
scope.launch {
@@ -398,7 +387,7 @@ class ZoomableActivity : BaseActivity() {
398
387
* Handles right swipe action
399
388
*/
400
389
private fun onRightSwiped (showAlreadyActionedImages : Boolean ) {
401
- if (photo ?.zoomableController?.isIdentity == false )
390
+ if (binding.zoomable ?.zoomableController?.isIdentity == false )
402
391
return
403
392
404
393
if (showAlreadyActionedImages) {
@@ -432,7 +421,7 @@ class ZoomableActivity : BaseActivity() {
432
421
* Handles left swipe action
433
422
*/
434
423
private fun onLeftSwiped (showAlreadyActionedImages : Boolean ) {
435
- if (photo ?.zoomableController?.isIdentity == false )
424
+ if (binding.zoomable ?.zoomableController?.isIdentity == false )
436
425
return
437
426
438
427
if (showAlreadyActionedImages) {
@@ -558,15 +547,15 @@ class ZoomableActivity : BaseActivity() {
558
547
* Unselect item UI
559
548
*/
560
549
private fun itemUnselected () {
561
- selectedCount !! .visibility = View .INVISIBLE
550
+ binding.selectionCount .visibility = View .INVISIBLE
562
551
}
563
552
564
553
/* *
565
554
* Select item UI
566
555
*/
567
556
private fun itemSelected (i : Int ) {
568
- selectedCount !! .visibility = View .VISIBLE
569
- selectedCount !! .text = i.toString()
557
+ binding.selectionCount .visibility = View .VISIBLE
558
+ binding.selectionCount .text = i.toString()
570
559
}
571
560
572
561
/* *
@@ -586,19 +575,19 @@ class ZoomableActivity : BaseActivity() {
586
575
object : BaseControllerListener <ImageInfo ?>() {
587
576
override fun onSubmit (id : String , callerContext : Any ) {
588
577
// Sometimes the spinner doesn't appear when rapidly switching between images, this fixes that
589
- spinner !! .visibility = View .VISIBLE
578
+ binding.zoomProgressBar .visibility = View .VISIBLE
590
579
}
591
580
592
581
override fun onIntermediateImageSet (id : String , imageInfo : ImageInfo ? ) {
593
- spinner !! .visibility = View .GONE
582
+ binding.zoomProgressBar .visibility = View .GONE
594
583
}
595
584
596
585
override fun onFinalImageSet (
597
586
id : String ,
598
587
imageInfo : ImageInfo ? ,
599
588
animatable : Animatable ?
600
589
) {
601
- spinner !! .visibility = View .GONE
590
+ binding.zoomProgressBar .visibility = View .GONE
602
591
}
603
592
}
604
593
@@ -609,18 +598,20 @@ class ZoomableActivity : BaseActivity() {
609
598
.setProgressBarImage(ProgressBarDrawable ())
610
599
.setProgressBarImageScaleType(ScalingUtils .ScaleType .FIT_CENTER )
611
600
.build()
612
- photo!! .hierarchy = hierarchy
613
- photo!! .setAllowTouchInterceptionWhileZoomed(true )
614
- photo!! .setIsLongpressEnabled(false )
615
- photo!! .setTapListener(DoubleTapGestureListener (photo))
601
+ with (binding.zoomable!! ) {
602
+ setHierarchy(hierarchy)
603
+ setAllowTouchInterceptionWhileZoomed(true )
604
+ setIsLongpressEnabled(false )
605
+ setTapListener(DoubleTapGestureListener (this ))
606
+ }
616
607
val controller: DraweeController = Fresco .newDraweeControllerBuilder()
617
608
.setUri(imageUri)
618
609
.setControllerListener(loadingListener)
619
610
.build()
620
- photo !! .controller = controller
611
+ binding.zoomable !! .controller = controller
621
612
622
613
if (photoBackgroundColor != null ) {
623
- photo !! .setBackgroundColor(photoBackgroundColor!! )
614
+ binding.zoomable !! .setBackgroundColor(photoBackgroundColor!! )
624
615
}
625
616
626
617
if (! images.isNullOrEmpty()) {
@@ -684,4 +675,4 @@ class ZoomableActivity : BaseActivity() {
684
675
685
676
const val PHOTO_BACKGROUND_COLOR = " photo_background_color"
686
677
}
687
- }
678
+ }
0 commit comments