mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Merge d505266985 into aae9d4a387
This commit is contained in:
commit
980b590022
6 changed files with 354 additions and 235 deletions
|
|
@ -362,9 +362,12 @@ class ContributionController @Inject constructor(@param:Named("default_preferenc
|
|||
|
||||
override fun onImagesPicked(
|
||||
imagesFiles: List<UploadableFile>,
|
||||
source: FilePicker.ImageSource, type: Int
|
||||
source: FilePicker.ImageSource,
|
||||
type: Int
|
||||
) {
|
||||
val intent = handleImagesPicked(activity, imagesFiles)
|
||||
val intent = handleImagesPicked(activity, imagesFiles).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||
}
|
||||
activity.startActivity(intent)
|
||||
}
|
||||
})
|
||||
|
|
@ -385,27 +388,31 @@ class ContributionController @Inject constructor(@param:Named("default_preferenc
|
|||
context: Context,
|
||||
imagesFiles: List<UploadableFile>
|
||||
): Intent {
|
||||
val shareIntent = Intent(context, UploadActivity::class.java)
|
||||
shareIntent.setAction(ACTION_INTERNAL_UPLOADS)
|
||||
shareIntent
|
||||
.putParcelableArrayListExtra(UploadActivity.EXTRA_FILES, ArrayList(imagesFiles))
|
||||
val place = defaultKvStore.getJson<Place>(PLACE_OBJECT, Place::class.java)
|
||||
val shareIntent = Intent(context, UploadActivity::class.java).apply {
|
||||
action = ACTION_INTERNAL_UPLOADS
|
||||
putParcelableArrayListExtra(UploadActivity.EXTRA_FILES, ArrayList(imagesFiles))
|
||||
|
||||
if (place != null) {
|
||||
shareIntent.putExtra(PLACE_OBJECT, place)
|
||||
}
|
||||
val place = defaultKvStore.getJson<Place>(PLACE_OBJECT, Place::class.java)
|
||||
if (place != null) {
|
||||
putExtra(PLACE_OBJECT, place)
|
||||
}
|
||||
|
||||
if (locationBeforeImageCapture != null) {
|
||||
shareIntent.putExtra(
|
||||
UploadActivity.LOCATION_BEFORE_IMAGE_CAPTURE,
|
||||
locationBeforeImageCapture
|
||||
if (locationBeforeImageCapture != null) {
|
||||
putExtra(
|
||||
UploadActivity.LOCATION_BEFORE_IMAGE_CAPTURE,
|
||||
locationBeforeImageCapture
|
||||
)
|
||||
}
|
||||
|
||||
putExtra(
|
||||
UploadActivity.IN_APP_CAMERA_UPLOAD,
|
||||
isInAppCameraUpload
|
||||
)
|
||||
|
||||
// ✅ Prevent multiple UploadActivity instances on backstack
|
||||
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||
}
|
||||
|
||||
shareIntent.putExtra(
|
||||
UploadActivity.IN_APP_CAMERA_UPLOAD,
|
||||
isInAppCameraUpload
|
||||
)
|
||||
isInAppCameraUpload = false // reset the flag for next use
|
||||
return shareIntent
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
package fr.free.nrw.commons.contributions
|
||||
|
||||
import android.Manifest.permission
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
|
|
@ -12,13 +10,7 @@ import android.view.LayoutInflater
|
|||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.AnimationUtils
|
||||
import android.widget.LinearLayout
|
||||
import androidx.activity.result.ActivityResult
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts.RequestMultiplePermissions
|
||||
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.paging.PagedList
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
|
|
@ -34,9 +26,9 @@ import fr.free.nrw.commons.contributions.WikipediaInstructionsDialogFragment.Com
|
|||
import fr.free.nrw.commons.databinding.FragmentContributionsListBinding
|
||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment
|
||||
import fr.free.nrw.commons.di.NetworkingModule
|
||||
import fr.free.nrw.commons.filepicker.FilePicker
|
||||
import fr.free.nrw.commons.media.MediaClient
|
||||
import fr.free.nrw.commons.profile.ProfileActivity
|
||||
import fr.free.nrw.commons.ui.CustomFabController
|
||||
import fr.free.nrw.commons.utils.DialogUtil.showAlertDialog
|
||||
import fr.free.nrw.commons.utils.SystemThemeUtils
|
||||
import fr.free.nrw.commons.utils.ViewUtil.showShortToast
|
||||
|
|
@ -51,7 +43,7 @@ import javax.inject.Named
|
|||
/**
|
||||
* Created by root on 01.06.2018.
|
||||
*/
|
||||
class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsListContract.View,
|
||||
open class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsListContract.View,
|
||||
ContributionsListAdapter.Callback, WikipediaInstructionsDialogFragment.Callback {
|
||||
@JvmField
|
||||
@Inject
|
||||
|
|
@ -83,13 +75,7 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
|||
var sessionManager: SessionManager? = null
|
||||
|
||||
private var binding: FragmentContributionsListBinding? = null
|
||||
private var fab_close: Animation? = null
|
||||
private var fab_open: Animation? = null
|
||||
private var rotate_forward: Animation? = null
|
||||
private var rotate_backward: Animation? = null
|
||||
private var isFabOpen = false
|
||||
|
||||
private lateinit var inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>
|
||||
private lateinit var fabController: CustomFabController
|
||||
|
||||
@VisibleForTesting
|
||||
var rvContributionsList: RecyclerView? = null
|
||||
|
|
@ -106,46 +92,12 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
|||
private var contributionsSize = 0
|
||||
private var userName: String? = null
|
||||
|
||||
private val galleryPickLauncherForResult = registerForActivityResult<Intent, ActivityResult>(
|
||||
StartActivityForResult()
|
||||
) { result: ActivityResult? ->
|
||||
controller!!.handleActivityResultWithCallback(requireActivity()
|
||||
) { callbacks: FilePicker.Callbacks? ->
|
||||
controller!!.onPictureReturnedFromGallery(
|
||||
result!!, requireActivity(), callbacks!!
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private val customSelectorLauncherForResult = registerForActivityResult<Intent, ActivityResult>(
|
||||
StartActivityForResult()
|
||||
) { result: ActivityResult? ->
|
||||
controller!!.handleActivityResultWithCallback(requireActivity()
|
||||
) { callbacks: FilePicker.Callbacks? ->
|
||||
controller!!.onPictureReturnedFromCustomSelector(
|
||||
result!!, requireActivity(), callbacks!!
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private val cameraPickLauncherForResult = registerForActivityResult<Intent, ActivityResult>(
|
||||
StartActivityForResult()
|
||||
) { result: ActivityResult? ->
|
||||
controller!!.handleActivityResultWithCallback(requireActivity()
|
||||
) { callbacks: FilePicker.Callbacks? ->
|
||||
controller!!.onPictureReturnedFromCamera(
|
||||
result!!, requireActivity(), callbacks!!
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
override fun onCreate(
|
||||
savedInstanceState: Bundle?
|
||||
) {
|
||||
super.onCreate(savedInstanceState)
|
||||
//Now that we are allowing this fragment to be started for
|
||||
// any userName- we expect it to be passed as an argument
|
||||
|
||||
if (arguments != null) {
|
||||
userName = requireArguments().getString(ProfileActivity.KEY_USERNAME)
|
||||
}
|
||||
|
|
@ -153,45 +105,18 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
|||
if (StringUtils.isEmpty(userName)) {
|
||||
userName = sessionManager!!.userName
|
||||
}
|
||||
inAppCameraLocationPermissionLauncher =
|
||||
registerForActivityResult(RequestMultiplePermissions()) { result ->
|
||||
val areAllGranted = result.values.all { it }
|
||||
|
||||
if (areAllGranted) {
|
||||
controller?.locationPermissionCallback?.onLocationPermissionGranted()
|
||||
} else {
|
||||
activity?.let { currentActivity ->
|
||||
if (currentActivity.shouldShowRequestPermissionRationale(permission.ACCESS_FINE_LOCATION)) {
|
||||
controller?.handleShowRationaleFlowCameraLocation(
|
||||
currentActivity,
|
||||
inAppCameraLocationPermissionLauncher, // Pass launcher
|
||||
cameraPickLauncherForResult
|
||||
)
|
||||
} else {
|
||||
controller?.locationPermissionCallback?.onLocationPermissionDenied(
|
||||
currentActivity.getString(R.string.in_app_camera_location_permission_denied)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
): View {
|
||||
binding = FragmentContributionsListBinding.inflate(
|
||||
inflater, container, false
|
||||
)
|
||||
rvContributionsList = binding!!.contributionsList
|
||||
|
||||
contributionsListPresenter!!.onAttachView(this)
|
||||
binding!!.fabCustomGallery.setOnClickListener { v: View? -> launchCustomSelector() }
|
||||
binding!!.fabCustomGallery.setOnLongClickListener { view: View? ->
|
||||
showShortToast(context, fr.free.nrw.commons.R.string.custom_selector_title)
|
||||
true
|
||||
}
|
||||
|
||||
if (sessionManager!!.userName == userName) {
|
||||
binding!!.tvContributionsOfUser.visibility = View.GONE
|
||||
|
|
@ -199,7 +124,7 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
|||
} else {
|
||||
binding!!.tvContributionsOfUser.visibility = View.VISIBLE
|
||||
binding!!.tvContributionsOfUser.text =
|
||||
getString(fr.free.nrw.commons.R.string.contributions_of_user, userName)
|
||||
getString(R.string.contributions_of_user, userName)
|
||||
binding!!.fabLayout.visibility = View.GONE
|
||||
}
|
||||
|
||||
|
|
@ -242,9 +167,18 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
|||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
fabController = CustomFabController(
|
||||
this,
|
||||
requireContext(),
|
||||
binding!!.fabPlus,
|
||||
binding!!.fabCamera,
|
||||
binding!!.fabGallery,
|
||||
binding!!.fabCustomGallery,
|
||||
controller!!
|
||||
)
|
||||
fabController.initializeLaunchers()
|
||||
initRecyclerView()
|
||||
initializeAnimations()
|
||||
setListeners()
|
||||
fabController.setListeners(controller!!, requireActivity())
|
||||
}
|
||||
|
||||
private fun initRecyclerView() {
|
||||
|
|
@ -311,9 +245,7 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
|||
*/
|
||||
override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
|
||||
if (e.action == MotionEvent.ACTION_DOWN) {
|
||||
if (isFabOpen) {
|
||||
animateFAB(isFabOpen)
|
||||
}
|
||||
fabController.closeFabMenuIfOpen()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
@ -358,85 +290,20 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
|||
)
|
||||
}
|
||||
|
||||
private fun initializeAnimations() {
|
||||
fab_open = AnimationUtils.loadAnimation(activity, fr.free.nrw.commons.R.anim.fab_open)
|
||||
fab_close = AnimationUtils.loadAnimation(activity, fr.free.nrw.commons.R.anim.fab_close)
|
||||
rotate_forward = AnimationUtils.loadAnimation(activity, fr.free.nrw.commons.R.anim.rotate_forward)
|
||||
rotate_backward = AnimationUtils.loadAnimation(activity, fr.free.nrw.commons.R.anim.rotate_backward)
|
||||
}
|
||||
|
||||
private fun setListeners() {
|
||||
binding!!.fabPlus.setOnClickListener { view: View? -> animateFAB(isFabOpen) }
|
||||
binding!!.fabCamera.setOnClickListener { view: View? ->
|
||||
controller!!.initiateCameraPick(
|
||||
requireActivity(),
|
||||
inAppCameraLocationPermissionLauncher,
|
||||
cameraPickLauncherForResult
|
||||
)
|
||||
animateFAB(isFabOpen)
|
||||
}
|
||||
binding!!.fabCamera.setOnLongClickListener { view: View? ->
|
||||
showShortToast(
|
||||
context,
|
||||
fr.free.nrw.commons.R.string.add_contribution_from_camera
|
||||
)
|
||||
true
|
||||
}
|
||||
binding!!.fabGallery.setOnClickListener { view: View? ->
|
||||
controller!!.initiateGalleryPick(requireActivity(), galleryPickLauncherForResult, true)
|
||||
animateFAB(isFabOpen)
|
||||
}
|
||||
binding!!.fabGallery.setOnLongClickListener { view: View? ->
|
||||
showShortToast(context, fr.free.nrw.commons.R.string.menu_from_gallery)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch Custom Selector.
|
||||
*/
|
||||
protected fun launchCustomSelector() {
|
||||
controller!!.initiateCustomGalleryPickWithPermission(
|
||||
requireActivity(),
|
||||
customSelectorLauncherForResult
|
||||
)
|
||||
animateFAB(isFabOpen)
|
||||
}
|
||||
|
||||
fun scrollToTop() {
|
||||
rvContributionsList!!.smoothScrollToPosition(0)
|
||||
}
|
||||
|
||||
private fun animateFAB(isFabOpen: Boolean) {
|
||||
this.isFabOpen = !isFabOpen
|
||||
if (binding!!.fabPlus.isShown) {
|
||||
if (isFabOpen) {
|
||||
binding!!.fabPlus.startAnimation(rotate_backward)
|
||||
binding!!.fabCamera.startAnimation(fab_close)
|
||||
binding!!.fabGallery.startAnimation(fab_close)
|
||||
binding!!.fabCustomGallery.startAnimation(fab_close)
|
||||
binding!!.fabCamera.hide()
|
||||
binding!!.fabGallery.hide()
|
||||
binding!!.fabCustomGallery.hide()
|
||||
} else {
|
||||
binding!!.fabPlus.startAnimation(rotate_forward)
|
||||
binding!!.fabCamera.startAnimation(fab_open)
|
||||
binding!!.fabGallery.startAnimation(fab_open)
|
||||
binding!!.fabCustomGallery.startAnimation(fab_open)
|
||||
binding!!.fabCamera.show()
|
||||
binding!!.fabGallery.show()
|
||||
binding!!.fabCustomGallery.show()
|
||||
}
|
||||
this.isFabOpen = !isFabOpen
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows welcome message if user has no contributions yet i.e. new user.
|
||||
*/
|
||||
override fun showWelcomeTip(shouldShow: Boolean) {
|
||||
override fun showWelcomeTip(numberOfUploads: Boolean) {
|
||||
binding!!.noContributionsYet.visibility =
|
||||
if (shouldShow) View.VISIBLE else View.GONE
|
||||
if (numberOfUploads) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -469,9 +336,9 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
|||
}
|
||||
}
|
||||
|
||||
override fun openMediaDetail(position: Int, isWikipediaButtonDisplayed: Boolean) {
|
||||
override fun openMediaDetail(contribution: Int, isWikipediaPageExists: Boolean) {
|
||||
if (null != callback) { //Just being safe, ideally they won't be called when detached
|
||||
callback!!.showDetail(position, isWikipediaButtonDisplayed)
|
||||
callback!!.showDetail(contribution, isWikipediaPageExists)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -483,8 +350,8 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
|||
override fun addImageToWikipedia(contribution: Contribution?) {
|
||||
showAlertDialog(
|
||||
requireActivity(),
|
||||
getString(fr.free.nrw.commons.R.string.add_picture_to_wikipedia_article_title),
|
||||
getString(fr.free.nrw.commons.R.string.add_picture_to_wikipedia_article_desc),
|
||||
getString(R.string.add_picture_to_wikipedia_article_title),
|
||||
getString(R.string.add_picture_to_wikipedia_article_desc),
|
||||
{
|
||||
if (contribution != null) {
|
||||
showAddImageToWikipediaInstructions(contribution)
|
||||
|
|
@ -502,7 +369,7 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
|||
val fragment = newInstance(contribution)
|
||||
fragment.callback =
|
||||
WikipediaInstructionsDialogFragment.Callback { contribution: Contribution?, copyWikicode: Boolean ->
|
||||
this.onConfirmClicked(
|
||||
onConfirmClicked(
|
||||
contribution,
|
||||
copyWikicode
|
||||
)
|
||||
|
|
|
|||
167
app/src/main/java/fr/free/nrw/commons/ui/CustomFabController.kt
Normal file
167
app/src/main/java/fr/free/nrw/commons/ui/CustomFabController.kt
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
package fr.free.nrw.commons.ui
|
||||
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.AnimationUtils
|
||||
import fr.free.nrw.commons.R
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.activity.result.ActivityResult
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import fr.free.nrw.commons.contributions.ContributionController
|
||||
import fr.free.nrw.commons.filepicker.FilePicker
|
||||
import android.os.Build
|
||||
import android.Manifest.permission
|
||||
import android.app.Activity
|
||||
import androidx.activity.result.contract.ActivityResultContracts.RequestMultiplePermissions
|
||||
import fr.free.nrw.commons.utils.ViewUtil.showShortToast
|
||||
|
||||
|
||||
class CustomFabController(
|
||||
private val fragment: Fragment,
|
||||
context: Context,
|
||||
private val fabPlus: FloatingActionButton,
|
||||
private val fabCamera: FloatingActionButton,
|
||||
private val fabGallery: FloatingActionButton,
|
||||
private val fabCustomGallery: FloatingActionButton,
|
||||
private val controller: ContributionController
|
||||
) {
|
||||
private var isFabOpen = false
|
||||
private val fabOpen: Animation = AnimationUtils.loadAnimation(context, R.anim.fab_open)
|
||||
private val fabClose: Animation = AnimationUtils.loadAnimation(context, R.anim.fab_close)
|
||||
private val rotateForward: Animation = AnimationUtils.loadAnimation(context, R.anim.rotate_forward)
|
||||
private val rotateBackward: Animation = AnimationUtils.loadAnimation(context, R.anim.rotate_backward)
|
||||
private lateinit var inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>
|
||||
private lateinit var galleryPickLauncherForResult: ActivityResultLauncher<Intent>
|
||||
private lateinit var customSelectorLauncherForResult: ActivityResultLauncher<Intent>
|
||||
private lateinit var cameraPickLauncherForResult: ActivityResultLauncher<Intent>
|
||||
|
||||
fun initializeLaunchers() {
|
||||
inAppCameraLocationPermissionLauncher =
|
||||
fragment.registerForActivityResult(RequestMultiplePermissions()) { result ->
|
||||
val areAllGranted = result.values.all { it }
|
||||
|
||||
if (areAllGranted) {
|
||||
controller.locationPermissionCallback?.onLocationPermissionGranted()
|
||||
} else {
|
||||
val activity = fragment.activity
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
|
||||
activity?.shouldShowRequestPermissionRationale(permission.ACCESS_FINE_LOCATION) == true
|
||||
) {
|
||||
controller.handleShowRationaleFlowCameraLocation(
|
||||
activity,
|
||||
inAppCameraLocationPermissionLauncher,
|
||||
cameraPickLauncherForResult
|
||||
)
|
||||
} else {
|
||||
activity?.getString(R.string.in_app_camera_location_permission_denied)?.let {
|
||||
controller.locationPermissionCallback?.onLocationPermissionDenied(
|
||||
it
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
galleryPickLauncherForResult = fragment.registerForActivityResult(StartActivityForResult()) { result: ActivityResult? ->
|
||||
controller.handleActivityResultWithCallback(fragment.requireActivity()) { callbacks: FilePicker.Callbacks? ->
|
||||
controller.onPictureReturnedFromGallery(result!!, fragment.requireActivity(), callbacks!!)
|
||||
}
|
||||
}
|
||||
|
||||
customSelectorLauncherForResult = fragment.registerForActivityResult(StartActivityForResult()) { result: ActivityResult? ->
|
||||
controller.handleActivityResultWithCallback(fragment.requireActivity()) { callbacks: FilePicker.Callbacks? ->
|
||||
controller.onPictureReturnedFromCustomSelector(result!!, fragment.requireActivity(), callbacks!!)
|
||||
}
|
||||
}
|
||||
|
||||
cameraPickLauncherForResult = fragment.registerForActivityResult(StartActivityForResult()) { result: ActivityResult? ->
|
||||
controller.handleActivityResultWithCallback(fragment.requireActivity()) { callbacks: FilePicker.Callbacks? ->
|
||||
controller.onPictureReturnedFromCamera(result!!, fragment.requireActivity(), callbacks!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun toggleFabMenu() {
|
||||
isFabOpen = !isFabOpen
|
||||
if (fabPlus.isShown) {
|
||||
if (isFabOpen) {
|
||||
fabPlus.startAnimation(rotateForward)
|
||||
fabCamera.startAnimation(fabOpen)
|
||||
fabGallery.startAnimation(fabOpen)
|
||||
fabCustomGallery.startAnimation(fabOpen)
|
||||
|
||||
fabCamera.show()
|
||||
fabGallery.show()
|
||||
fabCustomGallery.show()
|
||||
} else {
|
||||
fabPlus.startAnimation(rotateBackward)
|
||||
fabCamera.startAnimation(fabClose)
|
||||
fabGallery.startAnimation(fabClose)
|
||||
fabCustomGallery.startAnimation(fabClose)
|
||||
|
||||
fabCamera.hide()
|
||||
fabGallery.hide()
|
||||
fabCustomGallery.hide()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun closeFabMenu() {
|
||||
if (isFabOpen) toggleFabMenu()
|
||||
}
|
||||
|
||||
fun closeFabMenuIfOpen() {
|
||||
if (isFabOpen) {
|
||||
closeFabMenu()
|
||||
}
|
||||
}
|
||||
|
||||
fun setListeners(controller: ContributionController, activity: Activity) {
|
||||
fabPlus.setOnClickListener {
|
||||
toggleFabMenu()
|
||||
}
|
||||
|
||||
fabCamera.setOnClickListener {
|
||||
controller.initiateCameraPick(
|
||||
activity,
|
||||
inAppCameraLocationPermissionLauncher,
|
||||
cameraPickLauncherForResult
|
||||
)
|
||||
closeFabMenu()
|
||||
}
|
||||
|
||||
fabCamera.setOnLongClickListener {
|
||||
showShortToast(activity, R.string.add_contribution_from_camera)
|
||||
true
|
||||
}
|
||||
|
||||
fabGallery.setOnClickListener {
|
||||
controller.initiateGalleryPick(activity, galleryPickLauncherForResult, true)
|
||||
closeFabMenu()
|
||||
}
|
||||
|
||||
fabGallery.setOnLongClickListener {
|
||||
showShortToast(activity, R.string.menu_from_gallery)
|
||||
true
|
||||
}
|
||||
|
||||
fabCustomGallery.setOnClickListener {
|
||||
controller.initiateCustomGalleryPickWithPermission(
|
||||
activity,
|
||||
customSelectorLauncherForResult
|
||||
)
|
||||
closeFabMenu()
|
||||
}
|
||||
|
||||
fabCustomGallery.setOnLongClickListener {
|
||||
showShortToast(activity, R.string.custom_selector_title)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -13,10 +13,12 @@ import fr.free.nrw.commons.contributions.Contribution
|
|||
import fr.free.nrw.commons.contributions.Contribution.Companion.STATE_IN_PROGRESS
|
||||
import fr.free.nrw.commons.contributions.Contribution.Companion.STATE_PAUSED
|
||||
import fr.free.nrw.commons.contributions.Contribution.Companion.STATE_QUEUED
|
||||
import fr.free.nrw.commons.contributions.ContributionController
|
||||
import fr.free.nrw.commons.databinding.FragmentPendingUploadsBinding
|
||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment
|
||||
import fr.free.nrw.commons.ui.CustomFabController
|
||||
import fr.free.nrw.commons.utils.DialogUtil.showAlertDialog
|
||||
import fr.free.nrw.commons.utils.ViewUtil
|
||||
import fr.free.nrw.commons.utils.ViewUtil.showShortToast
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -30,17 +32,17 @@ class PendingUploadsFragment :
|
|||
PendingUploadsAdapter.Callback {
|
||||
@Inject
|
||||
lateinit var pendingUploadsPresenter: PendingUploadsPresenter
|
||||
|
||||
private lateinit var binding: FragmentPendingUploadsBinding
|
||||
|
||||
private lateinit var uploadProgressActivity: UploadProgressActivity
|
||||
|
||||
private lateinit var adapter: PendingUploadsAdapter
|
||||
|
||||
private var contributionsSize = 0
|
||||
|
||||
private var contributionsList = mutableListOf<Contribution>()
|
||||
|
||||
@JvmField
|
||||
@Inject
|
||||
var controller: ContributionController? = null
|
||||
private lateinit var fabController: CustomFabController
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
if (context is UploadProgressActivity) {
|
||||
|
|
@ -60,15 +62,23 @@ class PendingUploadsFragment :
|
|||
return binding.root
|
||||
}
|
||||
|
||||
fun initAdapter() {
|
||||
private fun initAdapter() {
|
||||
adapter = PendingUploadsAdapter(this)
|
||||
}
|
||||
|
||||
override fun onViewCreated(
|
||||
view: View,
|
||||
savedInstanceState: Bundle?,
|
||||
) {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
fabController = CustomFabController(
|
||||
this,
|
||||
requireContext(),
|
||||
binding.fabPlus,
|
||||
binding.fabCamera,
|
||||
binding.fabGallery,
|
||||
binding.fabCustomGallery,
|
||||
controller!!
|
||||
)
|
||||
fabController.initializeLaunchers()
|
||||
fabController.setListeners(controller!!, requireActivity())
|
||||
initRecyclerView()
|
||||
}
|
||||
|
||||
|
|
@ -98,14 +108,14 @@ class PendingUploadsFragment :
|
|||
}
|
||||
}
|
||||
if (contributionsSize == 0) {
|
||||
binding.nopendingTextView.visibility = View.VISIBLE
|
||||
binding.pendingUplaodsLl.visibility = View.GONE
|
||||
binding.noPendingTextView.visibility = View.VISIBLE
|
||||
binding.pendingUploadsLl.visibility = View.GONE
|
||||
uploadProgressActivity.hidePendingIcons()
|
||||
} else {
|
||||
binding.nopendingTextView.visibility = View.GONE
|
||||
binding.pendingUplaodsLl.visibility = View.VISIBLE
|
||||
binding.noPendingTextView.visibility = View.GONE
|
||||
binding.pendingUploadsLl.visibility = View.VISIBLE
|
||||
adapter.submitList(list)
|
||||
binding.progressTextView.setText("$contributionsSize uploads left")
|
||||
binding.progressTextView.text = "$contributionsSize uploads left"
|
||||
if ((pausedOrQueuedUploads == contributionsSize) || CommonsApplication.isPaused) {
|
||||
uploadProgressActivity.setPausedIcon(true)
|
||||
} else {
|
||||
|
|
@ -128,7 +138,7 @@ class PendingUploadsFragment :
|
|||
String.format(locale, activity.getString(R.string.yes)),
|
||||
String.format(locale, activity.getString(R.string.no)),
|
||||
{
|
||||
ViewUtil.showShortToast(context, R.string.cancelling_upload)
|
||||
showShortToast(context, R.string.cancelling_upload)
|
||||
pendingUploadsPresenter.deleteUpload(
|
||||
contribution, requireContext().applicationContext,
|
||||
)
|
||||
|
|
@ -162,7 +172,7 @@ class PendingUploadsFragment :
|
|||
String.format(locale, activity.getString(R.string.yes)),
|
||||
String.format(locale, activity.getString(R.string.no)),
|
||||
{
|
||||
ViewUtil.showShortToast(context, R.string.cancelling_upload)
|
||||
showShortToast(context, R.string.cancelling_upload)
|
||||
uploadProgressActivity.hidePendingIcons()
|
||||
pendingUploadsPresenter.deleteUploads(
|
||||
listOf(
|
||||
|
|
|
|||
|
|
@ -1,67 +1,132 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
tools:context=".upload.PendingUploadsFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nopendingTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="You do not have any pending Uploads!"
|
||||
android:visibility="gone" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/pendingUplaodsLl"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:visibility="visible">
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
<TextView
|
||||
android:id="@+id/noPendingTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:gravity="bottom"
|
||||
android:orientation="horizontal">
|
||||
android:gravity="center"
|
||||
android:text="@string/no_pending_uploads"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="Progress:"
|
||||
android:textSize="22sp" />
|
||||
<LinearLayout
|
||||
android:id="@+id/pendingUploadsLl"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:visibility="visible">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:gravity="bottom"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/progress_text_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right"
|
||||
android:text=""
|
||||
android:textSize="21sp" />
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/progress"
|
||||
android:textSize="22sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/progress_text_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="end"
|
||||
android:text=""
|
||||
android:textSize="21sp" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/pending_uploads_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginHorizontal="10dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/pending_uploads_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginHorizontal="10dp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/fab_layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="16dp"
|
||||
android:orientation="vertical"
|
||||
android:focusableInTouchMode="true"
|
||||
android:gravity="center_horizontal">
|
||||
|
||||
</LinearLayout>
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_camera"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/add_contribution_from_camera"
|
||||
android:tint="@color/button_blue"
|
||||
android:visibility="gone"
|
||||
app:backgroundTint="@color/main_background_light"
|
||||
app:elevation="@dimen/tiny_margin"
|
||||
app:fabSize="mini"
|
||||
app:srcCompat="@drawable/ic_photo_camera_white_24dp"
|
||||
app:useCompatPadding="true" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_gallery"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/add_contribution_from_photos"
|
||||
android:tint="@color/button_blue"
|
||||
android:visibility="gone"
|
||||
app:backgroundTint="@color/main_background_light"
|
||||
app:elevation="@dimen/tiny_margin"
|
||||
app:fabSize="mini"
|
||||
app:srcCompat="@drawable/ic_photo_white_24dp"
|
||||
app:useCompatPadding="true" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_custom_gallery"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/commons"
|
||||
android:contentDescription="@string/add_contribution_from_contributions_gallery"
|
||||
android:tint="@color/button_blue"
|
||||
android:visibility="gone"
|
||||
app:backgroundTint="@color/main_background_light"
|
||||
app:elevation="@dimen/tiny_margin"
|
||||
app:fabSize="mini"
|
||||
app:srcCompat="@drawable/ic_custom_image_picker"
|
||||
app:useCompatPadding="true" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab_plus"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/add_new_contribution"
|
||||
android:visibility="visible"
|
||||
app:elevation="@dimen/tiny_margin"
|
||||
app:backgroundTint="@color/status_bar_blue"
|
||||
app:srcCompat="@drawable/ic_add_white_24dp"
|
||||
app:useCompatPadding="true" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
<string name="add_another_description">Add another description</string>
|
||||
<string name="add_new_contribution">Add new contribution</string>
|
||||
<string name="add_contribution_from_camera">Add contribution from camera</string>
|
||||
<string name="add_upload">Add Upload</string>
|
||||
<string name="add_contribution_from_photos">Add contribution from Photos</string>
|
||||
<string name="add_contribution_from_contributions_gallery">Add contribution from previous contributions gallery</string>
|
||||
<string name="show_captions">Captions</string>
|
||||
|
|
@ -22,6 +23,8 @@
|
|||
<string name="nearby_filter_search">Search View</string>
|
||||
<string name="nearby_filter_state">Place State</string>
|
||||
<string name="appwidget_img">Pic of the Day</string>
|
||||
<string name="progress">Progress</string>
|
||||
<string name="no_pending_uploads">You do not have any pending Uploads!</string>
|
||||
|
||||
<!--Other strings-->
|
||||
<plurals name="uploads_pending_notification_indicator">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue