mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	fixed errors and warnings
This commit is contained in:
		
							parent
							
								
									3777f18bf9
								
							
						
					
					
						commit
						2cd91c512e
					
				
					 1 changed files with 47 additions and 77 deletions
				
			
		|  | @ -17,19 +17,16 @@ import fr.free.nrw.commons.profile.ProfileActivity | ||||||
| import fr.free.nrw.commons.utils.DialogUtil | import fr.free.nrw.commons.utils.DialogUtil | ||||||
| import fr.free.nrw.commons.utils.ViewUtil | import fr.free.nrw.commons.utils.ViewUtil | ||||||
| import org.apache.commons.lang3.StringUtils | import org.apache.commons.lang3.StringUtils | ||||||
| import java.util.Locale |  | ||||||
| import javax.inject.Inject | import javax.inject.Inject | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Fragment for displaying a list of failed uploads in Upload Progress Activity. This fragment provides |  * Fragment for displaying a list of failed uploads in Upload Progress Activity. It provides | ||||||
|  * functionality for the user to retry or cancel failed uploads. |  * functionality for the user to retry or cancel failed uploads. | ||||||
|  */ |  */ | ||||||
| class FailedUploadsFragment : | class FailedUploadsFragment : | ||||||
|     CommonsDaggerSupportFragment(), |     CommonsDaggerSupportFragment(), | ||||||
|     PendingUploadsContract.View, |     PendingUploadsContract.View, | ||||||
|     FailedUploadsAdapter.Callback { |     FailedUploadsAdapter.Callback { | ||||||
|     @Inject |  | ||||||
|     lateinit var pendingUploadsPresenter: PendingUploadsPresenter |  | ||||||
| 
 | 
 | ||||||
|     @Inject |     @Inject | ||||||
|     lateinit var mediaClient: MediaClient |     lateinit var mediaClient: MediaClient | ||||||
|  | @ -38,14 +35,11 @@ class FailedUploadsFragment : | ||||||
|     lateinit var sessionManager: SessionManager |     lateinit var sessionManager: SessionManager | ||||||
| 
 | 
 | ||||||
|     private var userName: String? = null |     private var userName: String? = null | ||||||
| 
 |     private lateinit var binding: FragmentFailedUploadsBinding | ||||||
|     lateinit var binding: FragmentFailedUploadsBinding |  | ||||||
| 
 |  | ||||||
|     private lateinit var adapter: FailedUploadsAdapter |     private lateinit var adapter: FailedUploadsAdapter | ||||||
| 
 |     private val contributionsList = ArrayList<Contribution>() | ||||||
|     var contributionsList = ArrayList<Contribution>() |  | ||||||
| 
 |  | ||||||
|     private lateinit var uploadProgressActivity: UploadProgressActivity |     private lateinit var uploadProgressActivity: UploadProgressActivity | ||||||
|  |     lateinit var pendingUploadsPresenter: PendingUploadsPresenter | ||||||
| 
 | 
 | ||||||
|     override fun onAttach(context: Context) { |     override fun onAttach(context: Context) { | ||||||
|         super.onAttach(context) |         super.onAttach(context) | ||||||
|  | @ -56,12 +50,8 @@ class FailedUploadsFragment : | ||||||
| 
 | 
 | ||||||
|     override fun onCreate(savedInstanceState: Bundle?) { |     override fun onCreate(savedInstanceState: Bundle?) { | ||||||
|         super.onCreate(savedInstanceState) |         super.onCreate(savedInstanceState) | ||||||
|         // Now that we are allowing this fragment to be started for |         // Expecting userName as an argument; fallback to sessionManager's userName if not provided | ||||||
|         // any userName- we expect it to be passed as an argument |         userName = arguments?.getString(ProfileActivity.KEY_USERNAME) | ||||||
|         if (arguments != null) { |  | ||||||
|             userName = requireArguments().getString(ProfileActivity.KEY_USERNAME) |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         if (StringUtils.isEmpty(userName)) { |         if (StringUtils.isEmpty(userName)) { | ||||||
|             userName = sessionManager.userName |             userName = sessionManager.userName | ||||||
|         } |         } | ||||||
|  | @ -71,14 +61,14 @@ class FailedUploadsFragment : | ||||||
|         inflater: LayoutInflater, |         inflater: LayoutInflater, | ||||||
|         container: ViewGroup?, |         container: ViewGroup?, | ||||||
|         savedInstanceState: Bundle?, |         savedInstanceState: Bundle?, | ||||||
|     ): View? { |     ): View { | ||||||
|         binding = FragmentFailedUploadsBinding.inflate(layoutInflater) |         binding = FragmentFailedUploadsBinding.inflate(inflater, container, false) | ||||||
|         pendingUploadsPresenter.onAttachView(this) |         pendingUploadsPresenter.onAttachView(this) | ||||||
|         initAdapter() |         initAdapter() | ||||||
|         return binding.root |         return binding.root | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fun initAdapter() { |     private fun initAdapter() { | ||||||
|         adapter = FailedUploadsAdapter(this) |         adapter = FailedUploadsAdapter(this) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -93,21 +83,19 @@ class FailedUploadsFragment : | ||||||
|     /** |     /** | ||||||
|      * Initializes the recycler view. |      * Initializes the recycler view. | ||||||
|      */ |      */ | ||||||
|     fun initRecyclerView() { |     private fun initRecyclerView() { | ||||||
|         binding.failedUploadsRecyclerView.setLayoutManager(LinearLayoutManager(this.context)) |         binding.failedUploadsRecyclerView.layoutManager = LinearLayoutManager(context) | ||||||
|         binding.failedUploadsRecyclerView.adapter = adapter |         binding.failedUploadsRecyclerView.adapter = adapter | ||||||
|         pendingUploadsPresenter.getFailedContributions() |         pendingUploadsPresenter.getFailedContributions() | ||||||
|         pendingUploadsPresenter.failedContributionList.observe( |         pendingUploadsPresenter.failedContributionList.observe( | ||||||
|             viewLifecycleOwner, |             viewLifecycleOwner, | ||||||
|         ) { list: PagedList<Contribution?> -> |         ) { list: PagedList<Contribution?> -> | ||||||
|             adapter.submitList(list) |             adapter.submitList(list) | ||||||
|             contributionsList = ArrayList() |             contributionsList.clear() | ||||||
|             list.forEach { |             list.forEach { contribution -> | ||||||
|                 if (it != null) { |                 contribution?.let { contributionsList.add(it) } | ||||||
|                     contributionsList.add(it) |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|             if (list.size == 0) { |             if (list.isEmpty()) { | ||||||
|                 uploadProgressActivity.setErrorIconsVisibility(false) |                 uploadProgressActivity.setErrorIconsVisibility(false) | ||||||
|                 binding.nofailedTextView.visibility = View.VISIBLE |                 binding.nofailedTextView.visibility = View.VISIBLE | ||||||
|                 binding.failedUplaodsLl.visibility = View.GONE |                 binding.failedUplaodsLl.visibility = View.GONE | ||||||
|  | @ -115,7 +103,7 @@ class FailedUploadsFragment : | ||||||
|                 uploadProgressActivity.setErrorIconsVisibility(true) |                 uploadProgressActivity.setErrorIconsVisibility(true) | ||||||
|                 binding.nofailedTextView.visibility = View.GONE |                 binding.nofailedTextView.visibility = View.GONE | ||||||
|                 binding.failedUplaodsLl.visibility = View.VISIBLE |                 binding.failedUplaodsLl.visibility = View.VISIBLE | ||||||
|                 binding.failedUploadsRecyclerView.setAdapter(adapter) |                 // Setting the adapter again is redundant; it's already set above | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | @ -124,26 +112,22 @@ class FailedUploadsFragment : | ||||||
|      * Restarts all the failed uploads. |      * Restarts all the failed uploads. | ||||||
|      */ |      */ | ||||||
|     fun restartUploads() { |     fun restartUploads() { | ||||||
|         if (contributionsList != null) { |         pendingUploadsPresenter.restartUploads( | ||||||
|             pendingUploadsPresenter.restartUploads( |             contributionsList, | ||||||
|                 contributionsList, |             0, | ||||||
|                 0, |             requireContext().applicationContext, | ||||||
|                 this.requireContext().applicationContext, |         ) | ||||||
|             ) |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Restarts a specific upload. |      * Restarts a specific upload. | ||||||
|      */ |      */ | ||||||
|     override fun restartUpload(index: Int) { |     override fun restartUpload(index: Int) { | ||||||
|         if (contributionsList != null) { |         pendingUploadsPresenter.restartUpload( | ||||||
|             pendingUploadsPresenter.restartUpload( |             contributionsList, | ||||||
|                 contributionsList, |             index, | ||||||
|                 index, |             requireContext().applicationContext, | ||||||
|                 this.requireContext().applicationContext, |         ) | ||||||
|             ) |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | @ -152,24 +136,18 @@ class FailedUploadsFragment : | ||||||
|     override fun deleteUpload(contribution: Contribution?) { |     override fun deleteUpload(contribution: Contribution?) { | ||||||
|         DialogUtil.showAlertDialog( |         DialogUtil.showAlertDialog( | ||||||
|             requireActivity(), |             requireActivity(), | ||||||
|             String.format( |             getString(R.string.cancelling_upload), | ||||||
|                 Locale.getDefault(), |             getString(R.string.cancel_upload_dialog), | ||||||
|                 requireActivity().getString(R.string.cancelling_upload), |             getString(R.string.yes), | ||||||
|             ), |             getString(R.string.no), | ||||||
|             String.format( |  | ||||||
|                 Locale.getDefault(), |  | ||||||
|                 requireActivity().getString(R.string.cancel_upload_dialog), |  | ||||||
|             ), |  | ||||||
|             String.format(Locale.getDefault(), requireActivity().getString(R.string.yes)), |  | ||||||
|             String.format(Locale.getDefault(), requireActivity().getString(R.string.no)), |  | ||||||
|             { |             { | ||||||
|                 ViewUtil.showShortToast(context, R.string.cancelling_upload) |                 ViewUtil.showShortToast(context, R.string.cancelling_upload) | ||||||
|                 pendingUploadsPresenter.deleteUpload( |                 pendingUploadsPresenter.deleteUpload( | ||||||
|                     contribution, |                     contribution, | ||||||
|                     this.requireContext().applicationContext, |                     requireContext().applicationContext, | ||||||
|                 ) |                 ) | ||||||
|             }, |             }, | ||||||
|             {}, |             {} | ||||||
|         ) |         ) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -177,28 +155,20 @@ class FailedUploadsFragment : | ||||||
|      * Deletes all the uploads after getting a confirmation from the user using Dialog. |      * Deletes all the uploads after getting a confirmation from the user using Dialog. | ||||||
|      */ |      */ | ||||||
|     fun deleteUploads() { |     fun deleteUploads() { | ||||||
|         if (contributionsList != null) { |         DialogUtil.showAlertDialog( | ||||||
|             DialogUtil.showAlertDialog( |             requireActivity(), | ||||||
|                 requireActivity(), |             getString(R.string.cancelling_all_the_uploads), | ||||||
|                 String.format( |             getString(R.string.are_you_sure_that_you_want_cancel_all_the_uploads), | ||||||
|                     Locale.getDefault(), |             getString(R.string.yes), | ||||||
|                     requireActivity().getString(R.string.cancelling_all_the_uploads), |             getString(R.string.no), | ||||||
|                 ), |             { | ||||||
|                 String.format( |                 ViewUtil.showShortToast(context, R.string.cancelling_upload) | ||||||
|                     Locale.getDefault(), |                 uploadProgressActivity.hidePendingIcons() | ||||||
|                     requireActivity().getString(R.string.are_you_sure_that_you_want_cancel_all_the_uploads), |                 pendingUploadsPresenter.deleteUploads( | ||||||
|                 ), |                     listOf(Contribution.STATE_FAILED), | ||||||
|                 String.format(Locale.getDefault(), requireActivity().getString(R.string.yes)), |                 ) | ||||||
|                 String.format(Locale.getDefault(), requireActivity().getString(R.string.no)), |             }, | ||||||
|                 { |             {} | ||||||
|                     ViewUtil.showShortToast(context, R.string.cancelling_upload) |         ) | ||||||
|                     uploadProgressActivity.hidePendingIcons() |  | ||||||
|                     pendingUploadsPresenter.deleteUploads( |  | ||||||
|                         listOf(Contribution.STATE_FAILED), |  | ||||||
|                     ) |  | ||||||
|                 }, |  | ||||||
|                 {}, |  | ||||||
|             ) |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Yash Kumar
						Yash Kumar