@@ -20,12 +20,14 @@ import fr.free.nrw.commons.customselector.helper.CustomSelectorConstants.SHOULD_
20
20
import fr.free.nrw.commons.customselector.listeners.FolderClickListener
21
21
import fr.free.nrw.commons.customselector.listeners.ImageSelectListener
22
22
import fr.free.nrw.commons.customselector.model.Image
23
+ import fr.free.nrw.commons.databinding.ActivityCustomSelectorBinding
24
+ import fr.free.nrw.commons.databinding.CustomSelectorBottomLayoutBinding
25
+ import fr.free.nrw.commons.databinding.CustomSelectorToolbarBinding
23
26
import fr.free.nrw.commons.filepicker.Constants
24
27
import fr.free.nrw.commons.media.ZoomableActivity
25
28
import fr.free.nrw.commons.theme.BaseActivity
26
29
import fr.free.nrw.commons.upload.FileUtilsWrapper
27
30
import fr.free.nrw.commons.utils.CustomSelectorUtils
28
- import kotlinx.android.synthetic.main.custom_selector_bottom_layout.*
29
31
import kotlinx.coroutines.*
30
32
import java.io.File
31
33
import javax.inject.Inject
@@ -34,7 +36,14 @@ import javax.inject.Inject
34
36
/* *
35
37
* Custom Selector Activity.
36
38
*/
37
- class CustomSelectorActivity : BaseActivity (), FolderClickListener, ImageSelectListener {
39
+ class CustomSelectorActivity : BaseActivity (), FolderClickListener, ImageSelectListener {
40
+
41
+ /* *
42
+ * ViewBindings
43
+ */
44
+ private lateinit var binding: ActivityCustomSelectorBinding
45
+ private lateinit var toolbarBinding: CustomSelectorToolbarBinding
46
+ private lateinit var bottomSheetBinding: CustomSelectorBottomLayoutBinding
38
47
39
48
/* *
40
49
* View model.
@@ -60,7 +69,8 @@ class CustomSelectorActivity: BaseActivity(), FolderClickListener, ImageSelectLi
60
69
/* *
61
70
* View Model Factory.
62
71
*/
63
- @Inject lateinit var customSelectorViewModelFactory: CustomSelectorViewModelFactory
72
+ @Inject
73
+ lateinit var customSelectorViewModelFactory: CustomSelectorViewModelFactory
64
74
65
75
/* *
66
76
* NotForUploadStatus Dao class for database operations
@@ -77,8 +87,8 @@ class CustomSelectorActivity: BaseActivity(), FolderClickListener, ImageSelectLi
77
87
/* *
78
88
* Coroutine Dispatchers and Scope.
79
89
*/
80
- private val scope : CoroutineScope = MainScope ()
81
- private var ioDispatcher : CoroutineDispatcher = Dispatchers .IO
90
+ private val scope: CoroutineScope = MainScope ()
91
+ private var ioDispatcher: CoroutineDispatcher = Dispatchers .IO
82
92
83
93
/* *
84
94
* Image Fragment instance
@@ -90,23 +100,27 @@ class CustomSelectorActivity: BaseActivity(), FolderClickListener, ImageSelectLi
90
100
*/
91
101
override fun onCreate (savedInstanceState : Bundle ? ) {
92
102
super .onCreate(savedInstanceState)
93
- setContentView(R .layout.activity_custom_selector)
103
+ binding = ActivityCustomSelectorBinding .inflate(layoutInflater)
104
+ toolbarBinding = CustomSelectorToolbarBinding .bind(binding.root)
105
+ bottomSheetBinding = CustomSelectorBottomLayoutBinding .bind(binding.root)
106
+ val view = binding.root
107
+ setContentView(view)
94
108
95
- prefs = applicationContext.getSharedPreferences(" CustomSelector" , MODE_PRIVATE )
109
+ prefs = applicationContext.getSharedPreferences(" CustomSelector" , MODE_PRIVATE )
96
110
viewModel = ViewModelProvider (this , customSelectorViewModelFactory).get(
97
111
CustomSelectorViewModel ::class .java
98
112
)
99
113
100
114
setupViews()
101
115
102
- if (prefs.getBoolean(" customSelectorFirstLaunch" , true )) {
116
+ if (prefs.getBoolean(" customSelectorFirstLaunch" , true )) {
103
117
// show welcome dialog on first launch
104
118
showWelcomeDialog()
105
119
prefs.edit().putBoolean(" customSelectorFirstLaunch" , false ).apply ()
106
120
}
107
121
108
122
// Open folder if saved in prefs.
109
- if (prefs.contains(FOLDER_ID )){
123
+ if (prefs.contains(FOLDER_ID )) {
110
124
val lastOpenFolderId: Long = prefs.getLong(FOLDER_ID , 0L )
111
125
val lastOpenFolderName: String? = prefs.getString(FOLDER_NAME , null )
112
126
val lastItemId: Long = prefs.getLong(ITEM_ID , 0 )
@@ -120,7 +134,8 @@ class CustomSelectorActivity: BaseActivity(), FolderClickListener, ImageSelectLi
120
134
override fun onActivityResult (requestCode : Int , resultCode : Int , data : Intent ? ) {
121
135
super .onActivityResult(requestCode, resultCode, data)
122
136
if (requestCode == Constants .RequestCodes .RECEIVE_DATA_FROM_FULL_SCREEN_MODE &&
123
- resultCode == Activity .RESULT_OK ) {
137
+ resultCode == Activity .RESULT_OK
138
+ ) {
124
139
val selectedImages: ArrayList <Image > =
125
140
data!!
126
141
.getParcelableArrayListExtra(CustomSelectorConstants .NEW_SELECTED_IMAGES )!!
@@ -156,19 +171,19 @@ class CustomSelectorActivity: BaseActivity(), FolderClickListener, ImageSelectLi
156
171
* Set up bottom layout
157
172
*/
158
173
private fun setUpBottomLayout () {
159
- val done : Button = findViewById(R .id.upload)
174
+ val done: Button = findViewById(R .id.upload)
160
175
done.setOnClickListener { onDone() }
161
176
162
- val notForUpload : Button = findViewById(R .id.not_for_upload)
163
- notForUpload.setOnClickListener{ onClickNotForUpload() }
177
+ val notForUpload: Button = findViewById(R .id.not_for_upload)
178
+ notForUpload.setOnClickListener { onClickNotForUpload() }
164
179
}
165
180
166
181
/* *
167
182
* Gets selected images and proceed for database operations
168
183
*/
169
184
private fun onClickNotForUpload () {
170
185
val selectedImages = viewModel.selectedImages.value
171
- if (selectedImages.isNullOrEmpty()) {
186
+ if (selectedImages.isNullOrEmpty()) {
172
187
markAsNotForUpload(arrayListOf ())
173
188
return
174
189
}
@@ -207,7 +222,7 @@ class CustomSelectorActivity: BaseActivity(), FolderClickListener, ImageSelectLi
207
222
private fun insertIntoNotForUpload (images : ArrayList <Image >) {
208
223
scope.launch {
209
224
var allImagesAlreadyNotForUpload = true
210
- images.forEach{
225
+ images.forEach {
211
226
val imageSHA1 = CustomSelectorUtils .getImageSHA1(
212
227
it.uri,
213
228
ioDispatcher,
@@ -254,7 +269,7 @@ class CustomSelectorActivity: BaseActivity(), FolderClickListener, ImageSelectLi
254
269
}
255
270
256
271
imageFragment!! .refresh()
257
- val bottomLayout : ConstraintLayout = findViewById(R .id.bottom_layout)
272
+ val bottomLayout: ConstraintLayout = findViewById(R .id.bottom_layout)
258
273
bottomLayout.visibility = View .GONE
259
274
}
260
275
}
@@ -270,8 +285,8 @@ class CustomSelectorActivity: BaseActivity(), FolderClickListener, ImageSelectLi
270
285
* Change the title of the toolbar.
271
286
*/
272
287
private fun changeTitle (title : String ) {
273
- val titleText = findViewById<TextView >(R .id.title)
274
- if (titleText != null ) {
288
+ val titleText = findViewById<TextView >(R .id.title)
289
+ if (titleText != null ) {
275
290
titleText.text = title
276
291
}
277
292
}
@@ -280,7 +295,7 @@ class CustomSelectorActivity: BaseActivity(), FolderClickListener, ImageSelectLi
280
295
* Set up the toolbar, back listener, done listener.
281
296
*/
282
297
private fun setUpToolbar () {
283
- val back : ImageButton = findViewById(R .id.back)
298
+ val back: ImageButton = findViewById(R .id.back)
284
299
back.setOnClickListener { onBackPressed() }
285
300
}
286
301
@@ -303,24 +318,27 @@ class CustomSelectorActivity: BaseActivity(), FolderClickListener, ImageSelectLi
303
318
/* *
304
319
* override Selected Images Change, update view model selected images and change UI.
305
320
*/
306
- override fun onSelectedImagesChanged (selectedImages : ArrayList <Image >,
307
- selectedNotForUploadImages : Int ) {
321
+ override fun onSelectedImagesChanged (
322
+ selectedImages : ArrayList <Image >,
323
+ selectedNotForUploadImages : Int
324
+ ) {
308
325
viewModel.selectedImages.value = selectedImages
309
326
310
327
if (selectedNotForUploadImages > 0 ) {
311
- upload.isEnabled = false
312
- upload.alpha = 0.5f
328
+ bottomSheetBinding. upload.isEnabled = false
329
+ bottomSheetBinding. upload.alpha = 0.5f
313
330
} else {
314
- upload.isEnabled = true
315
- upload.alpha = 1f
331
+ bottomSheetBinding. upload.isEnabled = true
332
+ bottomSheetBinding. upload.alpha = 1f
316
333
}
317
334
318
- not_for_upload.text = when (selectedImages.size == selectedNotForUploadImages) {
335
+ bottomSheetBinding.notForUpload.text =
336
+ when (selectedImages.size == selectedNotForUploadImages) {
319
337
true -> getString(R .string.unmark_as_not_for_upload)
320
338
else -> getString(R .string.mark_as_not_for_upload)
321
- }
339
+ }
322
340
323
- val bottomLayout : ConstraintLayout = findViewById(R .id.bottom_layout)
341
+ val bottomLayout: ConstraintLayout = findViewById(R .id.bottom_layout)
324
342
bottomLayout.visibility = if (selectedImages.isEmpty()) View .GONE else View .VISIBLE
325
343
}
326
344
@@ -334,7 +352,7 @@ class CustomSelectorActivity: BaseActivity(), FolderClickListener, ImageSelectLi
334
352
selectedImages : ArrayList <Image >
335
353
) {
336
354
val intent = Intent (this , ZoomableActivity ::class .java)
337
- intent.putExtra(CustomSelectorConstants .PRESENT_POSITION , position);
355
+ intent.putExtra(CustomSelectorConstants .PRESENT_POSITION , position)
338
356
intent.putParcelableArrayListExtra(
339
357
CustomSelectorConstants .TOTAL_SELECTED_IMAGES ,
340
358
selectedImages
@@ -349,8 +367,8 @@ class CustomSelectorActivity: BaseActivity(), FolderClickListener, ImageSelectLi
349
367
*/
350
368
fun onDone () {
351
369
val selectedImages = viewModel.selectedImages.value
352
- if (selectedImages.isNullOrEmpty()) {
353
- finishPickImages(arrayListOf ())
370
+ if (selectedImages.isNullOrEmpty()) {
371
+ finishPickImages(arrayListOf ())
354
372
return
355
373
}
356
374
var i = 0
@@ -384,7 +402,7 @@ class CustomSelectorActivity: BaseActivity(), FolderClickListener, ImageSelectLi
384
402
override fun onBackPressed () {
385
403
super .onBackPressed()
386
404
val fragment = supportFragmentManager.findFragmentById(R .id.fragment_container)
387
- if (fragment != null && fragment is FolderFragment ){
405
+ if (fragment != null && fragment is FolderFragment ) {
388
406
isImageFragmentOpen = false
389
407
changeTitle(getString(R .string.custom_selector_title))
390
408
}
@@ -395,7 +413,7 @@ class CustomSelectorActivity: BaseActivity(), FolderClickListener, ImageSelectLi
395
413
* If image fragment is open, overwrite its attributes otherwise discard the values.
396
414
*/
397
415
override fun onDestroy () {
398
- if (isImageFragmentOpen){
416
+ if (isImageFragmentOpen) {
399
417
prefs.edit().putLong(FOLDER_ID , bucketId).putString(FOLDER_NAME , bucketName).apply ()
400
418
} else {
401
419
prefs.edit().remove(FOLDER_ID ).remove(FOLDER_NAME ).apply ()
@@ -404,8 +422,8 @@ class CustomSelectorActivity: BaseActivity(), FolderClickListener, ImageSelectLi
404
422
}
405
423
406
424
companion object {
407
- const val FOLDER_ID : String = " FolderId"
408
- const val FOLDER_NAME : String = " FolderName"
409
- const val ITEM_ID : String = " ItemId"
425
+ const val FOLDER_ID : String = " FolderId"
426
+ const val FOLDER_NAME : String = " FolderName"
427
+ const val ITEM_ID : String = " ItemId"
410
428
}
411
429
}
0 commit comments