diff --git a/app/src/main/java/fr/free/nrw/commons/customselector/ui/adapter/ImageAdapter.kt b/app/src/main/java/fr/free/nrw/commons/customselector/ui/adapter/ImageAdapter.kt index 4180f00822..99e394e726 100644 --- a/app/src/main/java/fr/free/nrw/commons/customselector/ui/adapter/ImageAdapter.kt +++ b/app/src/main/java/fr/free/nrw/commons/customselector/ui/adapter/ImageAdapter.kt @@ -151,7 +151,7 @@ class ImageAdapter( val isSelected = selectedIndex != -1 if (isSelected) { - holder.itemSelected(selectedImages.size) + holder.itemSelected() } else { holder.itemUnselected() } @@ -407,7 +407,6 @@ class ImageAdapter( */ class ImageViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) { val image: ImageView = itemView.findViewById(R.id.image_thumbnail) - private val selectedNumber: TextView = itemView.findViewById(R.id.selected_count) private val uploadedGroup: Group = itemView.findViewById(R.id.uploaded_group) private val notForUploadGroup: Group = itemView.findViewById(R.id.not_for_upload_group) private val selectedGroup: Group = itemView.findViewById(R.id.selected_group) @@ -415,9 +414,8 @@ class ImageAdapter( /** * Item selected view. */ - fun itemSelected(index: Int) { + fun itemSelected() { selectedGroup.visibility = View.VISIBLE - selectedNumber.text = index.toString() } /** diff --git a/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt b/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt index 8fd5ff746e..dd6d248777 100644 --- a/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt +++ b/app/src/main/java/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivity.kt @@ -28,6 +28,7 @@ import fr.free.nrw.commons.media.ZoomableActivity import fr.free.nrw.commons.theme.BaseActivity import fr.free.nrw.commons.upload.FileUtilsWrapper import fr.free.nrw.commons.utils.CustomSelectorUtils +import kotlinx.android.synthetic.main.activity_login.view.title import kotlinx.coroutines.* import java.io.File import javax.inject.Inject @@ -142,7 +143,7 @@ class CustomSelectorActivity : BaseActivity(), FolderClickListener, ImageSelectL data!! .getParcelableArrayListExtra(CustomSelectorConstants.NEW_SELECTED_IMAGES)!! val shouldRefresh = data.getBooleanExtra(SHOULD_REFRESH, false) - imageFragment!!.passSelectedImages(selectedImages, shouldRefresh) + imageFragment?.passSelectedImages(selectedImages, shouldRefresh) } } @@ -280,6 +281,7 @@ class CustomSelectorActivity : BaseActivity(), FolderClickListener, ImageSelectL val bottomLayout: ConstraintLayout = findViewById(R.id.bottom_layout) bottomLayout.visibility = View.GONE } + changeTitle(bucketName, 0) } /** @@ -292,10 +294,17 @@ class CustomSelectorActivity : BaseActivity(), FolderClickListener, ImageSelectL /** * Change the title of the toolbar. */ - private fun changeTitle(title: String) { - val titleText = findViewById(R.id.title) - if (titleText != null) { - titleText.text = title + private fun changeTitle(title: String, selectedImageCount:Int) { + if (title.isNotEmpty()){ + val titleText = findViewById(R.id.title) + var titleWithAppendedImageCount = title + if (selectedImageCount > 0) { + titleWithAppendedImageCount += " (${resources.getQuantityString(R.plurals.custom_picker_images_selected_title_appendix, + selectedImageCount, selectedImageCount)})" + } + if (titleText != null) { + titleText.text = titleWithAppendedImageCount + } } } @@ -316,7 +325,7 @@ class CustomSelectorActivity : BaseActivity(), FolderClickListener, ImageSelectL .addToBackStack(null) .commit() - changeTitle(folderName) + changeTitle(folderName, 0) bucketId = folderId bucketName = folderName @@ -331,6 +340,7 @@ class CustomSelectorActivity : BaseActivity(), FolderClickListener, ImageSelectL selectedNotForUploadImages: Int ) { viewModel.selectedImages.value = selectedImages + changeTitle(bucketName, selectedImages.size) if (selectedNotForUploadImages > 0) { bottomSheetBinding.upload.isEnabled = false @@ -418,7 +428,7 @@ class CustomSelectorActivity : BaseActivity(), FolderClickListener, ImageSelectL val fragment = supportFragmentManager.findFragmentById(R.id.fragment_container) if (fragment != null && fragment is FolderFragment) { isImageFragmentOpen = false - changeTitle(getString(R.string.custom_selector_title)) + changeTitle(getString(R.string.custom_selector_title), 0) } } diff --git a/app/src/main/res/drawable/ic_done_black.xml b/app/src/main/res/drawable/ic_done_black.xml index 2d3858a70b..dd0da0e275 100644 --- a/app/src/main/res/drawable/ic_done_black.xml +++ b/app/src/main/res/drawable/ic_done_black.xml @@ -2,9 +2,10 @@ android:width="24dp" android:height="24dp" android:viewportWidth="24" - android:viewportHeight="24" - android:tint="?attr/colorControlNormal"> + android:viewportHeight="24"> diff --git a/app/src/main/res/layout/item_custom_selector_image.xml b/app/src/main/res/layout/item_custom_selector_image.xml index 4a44dbb98d..8d44c9aad4 100644 --- a/app/src/main/res/layout/item_custom_selector_image.xml +++ b/app/src/main/res/layout/item_custom_selector_image.xml @@ -33,18 +33,14 @@ android:background="@color/divider_grey" /> - @@ -55,7 +51,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" - app:constraint_referenced_ids="selected_overlay,selected_count"/> + app:constraint_referenced_ids="selected_overlay,selected_image"/> Swipe fast and long to perform these actions: \n- Left/Right: Go to previous/next \n- Up: Select\n- Down: Mark as not for upload. To set up your leaderboard avatar, tap \"Set as avatar\" in the three-dots menu of any image. The coordinates are not the exact coordinates, but the person who uploaded this picture thinks they are close enough. + + %d image selected + %d images selected + diff --git a/app/src/test/kotlin/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivityTest.kt b/app/src/test/kotlin/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivityTest.kt index 7d6d2f9e89..0b5f9b0169 100644 --- a/app/src/test/kotlin/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivityTest.kt +++ b/app/src/test/kotlin/fr/free/nrw/commons/customselector/ui/selector/CustomSelectorActivityTest.kt @@ -73,9 +73,10 @@ class CustomSelectorActivityTest { @Test @Throws(Exception::class) fun testChangeTitle() { - val func = activity.javaClass.getDeclaredMethod("changeTitle", String::class.java) + activity.onFolderClick(1, "test", 0) + val func = activity.javaClass.getDeclaredMethod("changeTitle", String::class.java, Int::class.java) func.isAccessible = true - func.invoke(activity, "test") + func.invoke(activity, "test", 0) } /** @@ -141,6 +142,7 @@ class CustomSelectorActivityTest { @Test @Throws(Exception::class) fun testOnSelectedImagesChanged() { + activity.onFolderClick(1, "test", 0) activity.onSelectedImagesChanged(ArrayList(), 0) } @@ -151,6 +153,7 @@ class CustomSelectorActivityTest { @Throws(Exception::class) fun testOnDone() { activity.onDone() + activity.onFolderClick(1, "test", 0) activity.onSelectedImagesChanged( ArrayList(arrayListOf(Image(1, "test", Uri.parse("test"), "test", 1))), 1 @@ -164,6 +167,7 @@ class CustomSelectorActivityTest { @Test @Throws(Exception::class) fun testOnClickNotForUpload() { + activity.onFolderClick(1, "test", 0) val method: Method = CustomSelectorActivity::class.java.getDeclaredMethod( "onClickNotForUpload" )