mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Part of issue #5996: Fix IDE warnings in ContributionsListFragment (naming, null-safety, deprecations)
This commit is contained in:
parent
aae9d4a387
commit
d27bff3d26
1 changed files with 35 additions and 40 deletions
|
|
@ -5,7 +5,6 @@ import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.net.Uri
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
|
@ -20,6 +19,8 @@ import androidx.activity.result.ActivityResultLauncher
|
||||||
import androidx.activity.result.contract.ActivityResultContracts.RequestMultiplePermissions
|
import androidx.activity.result.contract.ActivityResultContracts.RequestMultiplePermissions
|
||||||
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
|
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
|
||||||
import androidx.annotation.VisibleForTesting
|
import androidx.annotation.VisibleForTesting
|
||||||
|
import androidx.core.net.toUri
|
||||||
|
import androidx.core.os.BundleCompat
|
||||||
import androidx.paging.PagedList
|
import androidx.paging.PagedList
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
@ -38,12 +39,10 @@ import fr.free.nrw.commons.filepicker.FilePicker
|
||||||
import fr.free.nrw.commons.media.MediaClient
|
import fr.free.nrw.commons.media.MediaClient
|
||||||
import fr.free.nrw.commons.profile.ProfileActivity
|
import fr.free.nrw.commons.profile.ProfileActivity
|
||||||
import fr.free.nrw.commons.utils.DialogUtil.showAlertDialog
|
import fr.free.nrw.commons.utils.DialogUtil.showAlertDialog
|
||||||
import fr.free.nrw.commons.utils.SystemThemeUtils
|
|
||||||
import fr.free.nrw.commons.utils.ViewUtil.showShortToast
|
import fr.free.nrw.commons.utils.ViewUtil.showShortToast
|
||||||
import fr.free.nrw.commons.utils.copyToClipboard
|
import fr.free.nrw.commons.utils.copyToClipboard
|
||||||
import fr.free.nrw.commons.utils.handleWebUrl
|
import fr.free.nrw.commons.utils.handleWebUrl
|
||||||
import fr.free.nrw.commons.wikidata.model.WikiSite
|
import fr.free.nrw.commons.wikidata.model.WikiSite
|
||||||
import org.apache.commons.lang3.StringUtils
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Named
|
import javax.inject.Named
|
||||||
|
|
||||||
|
|
@ -53,10 +52,6 @@ import javax.inject.Named
|
||||||
*/
|
*/
|
||||||
class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsListContract.View,
|
class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsListContract.View,
|
||||||
ContributionsListAdapter.Callback, WikipediaInstructionsDialogFragment.Callback {
|
ContributionsListAdapter.Callback, WikipediaInstructionsDialogFragment.Callback {
|
||||||
@JvmField
|
|
||||||
@Inject
|
|
||||||
var systemThemeUtils: SystemThemeUtils? = null
|
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
@Inject
|
@Inject
|
||||||
var controller: ContributionController? = null
|
var controller: ContributionController? = null
|
||||||
|
|
@ -83,10 +78,10 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
||||||
var sessionManager: SessionManager? = null
|
var sessionManager: SessionManager? = null
|
||||||
|
|
||||||
private var binding: FragmentContributionsListBinding? = null
|
private var binding: FragmentContributionsListBinding? = null
|
||||||
private var fab_close: Animation? = null
|
private var fabClose: Animation? = null
|
||||||
private var fab_open: Animation? = null
|
private var fabOpen: Animation? = null
|
||||||
private var rotate_forward: Animation? = null
|
private var rotateForward: Animation? = null
|
||||||
private var rotate_backward: Animation? = null
|
private var rotateBackward: Animation? = null
|
||||||
private var isFabOpen = false
|
private var isFabOpen = false
|
||||||
|
|
||||||
private lateinit var inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>
|
private lateinit var inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>
|
||||||
|
|
@ -100,8 +95,8 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
var callback: Callback? = null
|
var callback: Callback? = null
|
||||||
|
|
||||||
private val SPAN_COUNT_LANDSCAPE = 3
|
private val spanCountLandscape = 3
|
||||||
private val SPAN_COUNT_PORTRAIT = 1
|
private val spanCountPortrait = 1
|
||||||
|
|
||||||
private var contributionsSize = 0
|
private var contributionsSize = 0
|
||||||
private var userName: String? = null
|
private var userName: String? = null
|
||||||
|
|
@ -150,7 +145,7 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
||||||
userName = requireArguments().getString(ProfileActivity.KEY_USERNAME)
|
userName = requireArguments().getString(ProfileActivity.KEY_USERNAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isEmpty(userName)) {
|
if (userName.isNullOrEmpty()) {
|
||||||
userName = sessionManager!!.userName
|
userName = sessionManager!!.userName
|
||||||
}
|
}
|
||||||
inAppCameraLocationPermissionLauncher =
|
inAppCameraLocationPermissionLauncher =
|
||||||
|
|
@ -189,7 +184,7 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
||||||
contributionsListPresenter!!.onAttachView(this)
|
contributionsListPresenter!!.onAttachView(this)
|
||||||
binding!!.fabCustomGallery.setOnClickListener { v: View? -> launchCustomSelector() }
|
binding!!.fabCustomGallery.setOnClickListener { v: View? -> launchCustomSelector() }
|
||||||
binding!!.fabCustomGallery.setOnLongClickListener { view: View? ->
|
binding!!.fabCustomGallery.setOnLongClickListener { view: View? ->
|
||||||
showShortToast(context, fr.free.nrw.commons.R.string.custom_selector_title)
|
showShortToast(context, R.string.custom_selector_title)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -199,7 +194,7 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
||||||
} else {
|
} else {
|
||||||
binding!!.tvContributionsOfUser.visibility = View.VISIBLE
|
binding!!.tvContributionsOfUser.visibility = View.VISIBLE
|
||||||
binding!!.tvContributionsOfUser.text =
|
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
|
binding!!.fabLayout.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -344,7 +339,7 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSpanCount(orientation: Int): Int {
|
private fun getSpanCount(orientation: Int): Int {
|
||||||
return if (orientation == Configuration.ORIENTATION_LANDSCAPE) SPAN_COUNT_LANDSCAPE else SPAN_COUNT_PORTRAIT
|
return if (orientation == Configuration.ORIENTATION_LANDSCAPE) spanCountLandscape else spanCountPortrait
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
|
|
@ -359,10 +354,10 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initializeAnimations() {
|
private fun initializeAnimations() {
|
||||||
fab_open = AnimationUtils.loadAnimation(activity, fr.free.nrw.commons.R.anim.fab_open)
|
fabOpen = AnimationUtils.loadAnimation(activity, R.anim.fab_open)
|
||||||
fab_close = AnimationUtils.loadAnimation(activity, fr.free.nrw.commons.R.anim.fab_close)
|
fabClose = AnimationUtils.loadAnimation(activity, R.anim.fab_close)
|
||||||
rotate_forward = AnimationUtils.loadAnimation(activity, fr.free.nrw.commons.R.anim.rotate_forward)
|
rotateForward = AnimationUtils.loadAnimation(activity, R.anim.rotate_forward)
|
||||||
rotate_backward = AnimationUtils.loadAnimation(activity, fr.free.nrw.commons.R.anim.rotate_backward)
|
rotateBackward = AnimationUtils.loadAnimation(activity, R.anim.rotate_backward)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setListeners() {
|
private fun setListeners() {
|
||||||
|
|
@ -378,7 +373,7 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
||||||
binding!!.fabCamera.setOnLongClickListener { view: View? ->
|
binding!!.fabCamera.setOnLongClickListener { view: View? ->
|
||||||
showShortToast(
|
showShortToast(
|
||||||
context,
|
context,
|
||||||
fr.free.nrw.commons.R.string.add_contribution_from_camera
|
R.string.add_contribution_from_camera
|
||||||
)
|
)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
@ -387,7 +382,7 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
||||||
animateFAB(isFabOpen)
|
animateFAB(isFabOpen)
|
||||||
}
|
}
|
||||||
binding!!.fabGallery.setOnLongClickListener { view: View? ->
|
binding!!.fabGallery.setOnLongClickListener { view: View? ->
|
||||||
showShortToast(context, fr.free.nrw.commons.R.string.menu_from_gallery)
|
showShortToast(context, R.string.menu_from_gallery)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -395,7 +390,7 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
||||||
/**
|
/**
|
||||||
* Launch Custom Selector.
|
* Launch Custom Selector.
|
||||||
*/
|
*/
|
||||||
protected fun launchCustomSelector() {
|
private fun launchCustomSelector() {
|
||||||
controller!!.initiateCustomGalleryPickWithPermission(
|
controller!!.initiateCustomGalleryPickWithPermission(
|
||||||
requireActivity(),
|
requireActivity(),
|
||||||
customSelectorLauncherForResult
|
customSelectorLauncherForResult
|
||||||
|
|
@ -411,18 +406,18 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
||||||
this.isFabOpen = !isFabOpen
|
this.isFabOpen = !isFabOpen
|
||||||
if (binding!!.fabPlus.isShown) {
|
if (binding!!.fabPlus.isShown) {
|
||||||
if (isFabOpen) {
|
if (isFabOpen) {
|
||||||
binding!!.fabPlus.startAnimation(rotate_backward)
|
binding!!.fabPlus.startAnimation(rotateBackward)
|
||||||
binding!!.fabCamera.startAnimation(fab_close)
|
binding!!.fabCamera.startAnimation(fabClose)
|
||||||
binding!!.fabGallery.startAnimation(fab_close)
|
binding!!.fabGallery.startAnimation(fabClose)
|
||||||
binding!!.fabCustomGallery.startAnimation(fab_close)
|
binding!!.fabCustomGallery.startAnimation(fabClose)
|
||||||
binding!!.fabCamera.hide()
|
binding!!.fabCamera.hide()
|
||||||
binding!!.fabGallery.hide()
|
binding!!.fabGallery.hide()
|
||||||
binding!!.fabCustomGallery.hide()
|
binding!!.fabCustomGallery.hide()
|
||||||
} else {
|
} else {
|
||||||
binding!!.fabPlus.startAnimation(rotate_forward)
|
binding!!.fabPlus.startAnimation(rotateForward)
|
||||||
binding!!.fabCamera.startAnimation(fab_open)
|
binding!!.fabCamera.startAnimation(fabOpen)
|
||||||
binding!!.fabGallery.startAnimation(fab_open)
|
binding!!.fabGallery.startAnimation(fabOpen)
|
||||||
binding!!.fabCustomGallery.startAnimation(fab_open)
|
binding!!.fabCustomGallery.startAnimation(fabOpen)
|
||||||
binding!!.fabCamera.show()
|
binding!!.fabCamera.show()
|
||||||
binding!!.fabGallery.show()
|
binding!!.fabGallery.show()
|
||||||
binding!!.fabCustomGallery.show()
|
binding!!.fabCustomGallery.show()
|
||||||
|
|
@ -456,15 +451,15 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
||||||
|
|
||||||
override fun onSaveInstanceState(outState: Bundle) {
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
super.onSaveInstanceState(outState)
|
super.onSaveInstanceState(outState)
|
||||||
val layoutManager = rvContributionsList
|
val layoutManager = rvContributionsList?.layoutManager as GridLayoutManager?
|
||||||
?.getLayoutManager() as GridLayoutManager?
|
|
||||||
outState.putParcelable(RV_STATE, layoutManager!!.onSaveInstanceState())
|
outState.putParcelable(RV_STATE, layoutManager!!.onSaveInstanceState())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewStateRestored(savedInstanceState: Bundle?) {
|
override fun onViewStateRestored(savedInstanceState: Bundle?) {
|
||||||
super.onViewStateRestored(savedInstanceState)
|
super.onViewStateRestored(savedInstanceState)
|
||||||
if (null != savedInstanceState) {
|
if (null != savedInstanceState) {
|
||||||
val savedRecyclerLayoutState = savedInstanceState.getParcelable<Parcelable>(RV_STATE)
|
val savedRecyclerLayoutState =
|
||||||
|
BundleCompat.getParcelable(savedInstanceState, RV_STATE, Parcelable::class.java)
|
||||||
rvContributionsList!!.layoutManager!!.onRestoreInstanceState(savedRecyclerLayoutState)
|
rvContributionsList!!.layoutManager!!.onRestoreInstanceState(savedRecyclerLayoutState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -483,8 +478,8 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
||||||
override fun addImageToWikipedia(contribution: Contribution?) {
|
override fun addImageToWikipedia(contribution: Contribution?) {
|
||||||
showAlertDialog(
|
showAlertDialog(
|
||||||
requireActivity(),
|
requireActivity(),
|
||||||
getString(fr.free.nrw.commons.R.string.add_picture_to_wikipedia_article_title),
|
getString(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_desc),
|
||||||
{
|
{
|
||||||
if (contribution != null) {
|
if (contribution != null) {
|
||||||
showAddImageToWikipediaInstructions(contribution)
|
showAddImageToWikipediaInstructions(contribution)
|
||||||
|
|
@ -498,11 +493,11 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
||||||
* @param contribution
|
* @param contribution
|
||||||
*/
|
*/
|
||||||
private fun showAddImageToWikipediaInstructions(contribution: Contribution) {
|
private fun showAddImageToWikipediaInstructions(contribution: Contribution) {
|
||||||
val fragmentManager = fragmentManager
|
val fragmentManager = this.parentFragmentManager
|
||||||
val fragment = newInstance(contribution)
|
val fragment = newInstance(contribution)
|
||||||
fragment.callback =
|
fragment.callback =
|
||||||
WikipediaInstructionsDialogFragment.Callback { contribution: Contribution?, copyWikicode: Boolean ->
|
WikipediaInstructionsDialogFragment.Callback { contribution: Contribution?, copyWikicode: Boolean ->
|
||||||
this.onConfirmClicked(
|
onConfirmClicked(
|
||||||
contribution,
|
contribution,
|
||||||
copyWikicode
|
copyWikicode
|
||||||
)
|
)
|
||||||
|
|
@ -534,7 +529,7 @@ class ContributionsListFragment : CommonsDaggerSupportFragment(), ContributionsL
|
||||||
val url =
|
val url =
|
||||||
languageWikipediaSite!!.mobileUrl() + "/wiki/" + (contribution!!.wikidataPlace
|
languageWikipediaSite!!.mobileUrl() + "/wiki/" + (contribution!!.wikidataPlace
|
||||||
?.getWikipediaPageTitle())
|
?.getWikipediaPageTitle())
|
||||||
handleWebUrl(requireContext(), Uri.parse(url))
|
handleWebUrl(requireContext(), url.toUri())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getContributionStateAt(position: Int): Int {
|
fun getContributionStateAt(position: Int): Int {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue