mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 13:53:54 +01:00
Issue-5662-kotlinstyle (#5833)
* *.kt: bulk correction of formatting using ktlint --format * *.kt: replace wildcard imports and second stage auto format ktlint --format * QuizQuestionTest.kt: modified property names to camel case to meet ktlint standard * LevelControllerTest.kt: modified property names to camel case to meet ktlint standard * QuizActivityUnitTest.kt: modified property names to camel case to meet ktlint standard * MediaDetailFragmentUnitTests.kt: modified property names to camel case to meet ktlint standard * UploadWorker.kt: modified property names to camel case to meet ktlint standard * UploadClient.kt: modified property names to camel case to meet ktlint standard * BasePagingPresenter.kt: modified property names to camel case to meet ktlint standard * DescriptionEditActivity.kt: modified property names to camel case to meet ktlint standard * OnSwipeTouchListener.kt: modified property names to camel case to meet ktlint standard * MediaDetailFragmentUnitTests.kt: corrected excessive line length to meet ktlint standard * DepictedItem.kt: corrected property name format and catch format to for ktlint standard * UploadCategoryAdapter.kt: corrected class definition format to meet ktlint standard * CustomSelectorActivity.kt: reformatted function names to first letter lowercase to meet ktlint standard * MediaDetailFragmentUnitTests.kt: fix string literal indentation to meet ktlint standard * NotForUploadDao.kt: file renamed to match class name, new file NotForUploadStatusDao.kt * UploadedDao.kt: file renamed to match class name, new file UploadedStatusDao.kt * Urls.kt: fixed excessive line length for ktLint standard * Snak_partial.kt & Statement_partial.kt: refactored to remove underscores in class names to meet ktLint standard * *.kt: fixed consecutive KDOC error for ktLint * PageableBaseDataSourceTest.kt & UploadPresenterTest.kt: fixed excessive line lengths to meet ktLint standard * CheckboxTriStatesTest.kt: renamed file to match class name to meet ktLint standard * .kt: resolved backing-property-naming error in ktLint, made matching properties public, matched names and refactored * TestConnectionFactory.kt: fixed property naming to adhere to ktLint standard
This commit is contained in:
parent
950539c55c
commit
2d82a430c4
405 changed files with 11032 additions and 9137 deletions
|
|
@ -20,24 +20,32 @@ import fr.free.nrw.commons.nearby.model.BottomSheetItem
|
|||
* @property itemList The list of BottomSheetItem objects to display.
|
||||
* @constructor Creates an instance of BottomSheetAdapter.
|
||||
*/
|
||||
class BottomSheetAdapter(context: Context?, private val itemList: List<BottomSheetItem>) :
|
||||
RecyclerView.Adapter<BottomSheetAdapter.ViewHolder>() {
|
||||
class BottomSheetAdapter(
|
||||
context: Context?,
|
||||
private val itemList: List<BottomSheetItem>,
|
||||
) : RecyclerView.Adapter<BottomSheetAdapter.ViewHolder>() {
|
||||
private val layoutInflater: LayoutInflater = LayoutInflater.from(context)
|
||||
private var itemClickListener: ItemClickListener? = null
|
||||
|
||||
@NonNull
|
||||
override fun onCreateViewHolder(@NonNull parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
override fun onCreateViewHolder(
|
||||
@NonNull parent: ViewGroup,
|
||||
viewType: Int,
|
||||
): ViewHolder {
|
||||
val view: View = layoutInflater.inflate(R.layout.bottom_sheet_item_layout, parent, false)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(@NonNull holder: ViewHolder, position: Int) {
|
||||
override fun onBindViewHolder(
|
||||
@NonNull holder: ViewHolder,
|
||||
position: Int,
|
||||
) {
|
||||
val item = itemList[position]
|
||||
holder.imageView.setImageDrawable(
|
||||
ContextCompat.getDrawable(
|
||||
getContext(),
|
||||
item.imageResourceId
|
||||
)
|
||||
item.imageResourceId,
|
||||
),
|
||||
)
|
||||
holder.title.setText(item.title)
|
||||
}
|
||||
|
|
@ -47,9 +55,7 @@ class BottomSheetAdapter(context: Context?, private val itemList: List<BottomShe
|
|||
*
|
||||
* @return The total number of items in this adapter.
|
||||
*/
|
||||
override fun getItemCount(): Int {
|
||||
return itemList.size
|
||||
}
|
||||
override fun getItemCount(): Int = itemList.size
|
||||
|
||||
/**
|
||||
* Updates the icon for bookmark item.
|
||||
|
|
@ -58,7 +64,9 @@ class BottomSheetAdapter(context: Context?, private val itemList: List<BottomShe
|
|||
*/
|
||||
fun updateBookmarkIcon(icon: Int) {
|
||||
itemList.forEachIndexed { index, item ->
|
||||
if (item.imageResourceId == R.drawable.ic_round_star_filled_24px || item.imageResourceId == R.drawable.ic_round_star_border_24px) {
|
||||
if (item.imageResourceId == R.drawable.ic_round_star_filled_24px ||
|
||||
item.imageResourceId == R.drawable.ic_round_star_border_24px
|
||||
) {
|
||||
item.imageResourceId = icon
|
||||
this.notifyItemChanged(index)
|
||||
return
|
||||
|
|
@ -66,8 +74,11 @@ class BottomSheetAdapter(context: Context?, private val itemList: List<BottomShe
|
|||
}
|
||||
}
|
||||
|
||||
inner class ViewHolder internal constructor(itemView: View) : RecyclerView.ViewHolder(itemView),
|
||||
View.OnClickListener, OnLongClickListener {
|
||||
inner class ViewHolder internal constructor(
|
||||
itemView: View,
|
||||
) : RecyclerView.ViewHolder(itemView),
|
||||
View.OnClickListener,
|
||||
OnLongClickListener {
|
||||
var imageView: ImageView = itemView.findViewById(R.id.buttonImage)
|
||||
var title: TextView = itemView.findViewById(R.id.buttonText)
|
||||
|
||||
|
|
@ -77,17 +88,21 @@ class BottomSheetAdapter(context: Context?, private val itemList: List<BottomShe
|
|||
}
|
||||
|
||||
override fun onClick(view: View) {
|
||||
if (itemClickListener != null) itemClickListener!!.onBottomSheetItemClick(
|
||||
view,
|
||||
adapterPosition
|
||||
)
|
||||
if (itemClickListener != null) {
|
||||
itemClickListener!!.onBottomSheetItemClick(
|
||||
view,
|
||||
adapterPosition,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onLongClick(view: View): Boolean {
|
||||
if (itemClickListener != null) itemClickListener!!.onBottomSheetItemLongClick(
|
||||
view,
|
||||
adapterPosition
|
||||
)
|
||||
if (itemClickListener != null) {
|
||||
itemClickListener!!.onBottomSheetItemLongClick(
|
||||
view,
|
||||
adapterPosition,
|
||||
)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
@ -96,13 +111,17 @@ class BottomSheetAdapter(context: Context?, private val itemList: List<BottomShe
|
|||
this.itemClickListener = itemClickListener
|
||||
}
|
||||
|
||||
fun getContext(): Context {
|
||||
return layoutInflater.context
|
||||
}
|
||||
fun getContext(): Context = layoutInflater.context
|
||||
|
||||
interface ItemClickListener {
|
||||
fun onBottomSheetItemClick(view: View?, position: Int)
|
||||
fun onBottomSheetItemLongClick(view: View?, position: Int)
|
||||
fun onBottomSheetItemClick(
|
||||
view: View?,
|
||||
position: Int,
|
||||
)
|
||||
|
||||
fun onBottomSheetItemLongClick(
|
||||
view: View?,
|
||||
position: Int,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package fr.free.nrw.commons.nearby
|
||||
|
||||
import android.view.View
|
||||
import android.view.View.*
|
||||
import android.view.View.GONE
|
||||
import android.view.View.INVISIBLE
|
||||
import android.view.View.VISIBLE
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
|
@ -12,7 +14,6 @@ import fr.free.nrw.commons.R
|
|||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao
|
||||
import fr.free.nrw.commons.databinding.ItemPlaceBinding
|
||||
|
||||
|
||||
fun placeAdapterDelegate(
|
||||
bookmarkLocationDao: BookmarkLocationsDao,
|
||||
onItemClick: ((Place) -> Unit)? = null,
|
||||
|
|
@ -26,7 +27,7 @@ fun placeAdapterDelegate(
|
|||
onOverFlowLongPressed: () -> Boolean,
|
||||
onDirectionsClicked: (Place) -> Unit,
|
||||
onDirectionsLongPressed: () -> Boolean,
|
||||
inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>
|
||||
inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>,
|
||||
) = adapterDelegateViewBinding<Place, Place, ItemPlaceBinding>({ layoutInflater, parent ->
|
||||
ItemPlaceBinding.inflate(layoutInflater, parent, false)
|
||||
}) {
|
||||
|
|
@ -47,17 +48,17 @@ fun placeAdapterDelegate(
|
|||
nearbyButtonLayout.cameraButton.setOnLongClickListener { onCameraLongPressed() }
|
||||
|
||||
nearbyButtonLayout.galleryButton.setOnClickListener { onGalleryClicked(item) }
|
||||
nearbyButtonLayout.galleryButton.setOnLongClickListener{onGalleryLongPressed()}
|
||||
nearbyButtonLayout.galleryButton.setOnLongClickListener { onGalleryLongPressed() }
|
||||
bookmarkButtonImage.setOnClickListener {
|
||||
val isBookmarked = bookmarkLocationDao.updateBookmarkLocation(item)
|
||||
bookmarkButtonImage.setImageResource(
|
||||
if (isBookmarked) R.drawable.ic_round_star_filled_24px else R.drawable.ic_round_star_border_24px
|
||||
if (isBookmarked) R.drawable.ic_round_star_filled_24px else R.drawable.ic_round_star_border_24px,
|
||||
)
|
||||
onBookmarkClicked(item, isBookmarked)
|
||||
}
|
||||
bookmarkButtonImage.setOnLongClickListener{onBookmarkLongPressed()}
|
||||
bookmarkButtonImage.setOnLongClickListener { onBookmarkLongPressed() }
|
||||
nearbyButtonLayout.iconOverflow.setOnClickListener { onOverflowIconClicked(item, it) }
|
||||
nearbyButtonLayout.iconOverflow.setOnLongClickListener{onOverFlowLongPressed()}
|
||||
nearbyButtonLayout.iconOverflow.setOnLongClickListener { onOverFlowLongPressed() }
|
||||
nearbyButtonLayout.directionsButton.setOnClickListener { onDirectionsClicked(item) }
|
||||
bind {
|
||||
tvName.text = item.name
|
||||
|
|
@ -68,23 +69,28 @@ fun placeAdapterDelegate(
|
|||
} else {
|
||||
// Remove the label and display only texts inside pharentheses (description) since too long
|
||||
tvDesc.text =
|
||||
descriptionText.substringAfter(tvName.text.toString() + " (")
|
||||
.substringBeforeLast(")");
|
||||
descriptionText
|
||||
.substringAfter(tvName.text.toString() + " (")
|
||||
.substringBeforeLast(")")
|
||||
}
|
||||
distance.text = item.distance
|
||||
icon.setImageResource(item.label.icon)
|
||||
nearbyButtonLayout.iconOverflow.visibility =
|
||||
if (item.hasCommonsLink() || item.hasWikidataLink()) VISIBLE
|
||||
else GONE
|
||||
if (item.hasCommonsLink() || item.hasWikidataLink()) {
|
||||
VISIBLE
|
||||
} else {
|
||||
GONE
|
||||
}
|
||||
|
||||
bookmarkButtonImage.setImageResource(
|
||||
if (bookmarkLocationDao.findBookmarkLocation(item))
|
||||
if (bookmarkLocationDao.findBookmarkLocation(item)) {
|
||||
R.drawable.ic_round_star_filled_24px
|
||||
else
|
||||
} else {
|
||||
R.drawable.ic_round_star_border_24px
|
||||
},
|
||||
)
|
||||
}
|
||||
nearbyButtonLayout.directionsButton.setOnLongClickListener{onDirectionsLongPressed()}
|
||||
nearbyButtonLayout.directionsButton.setOnLongClickListener { onDirectionsLongPressed() }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -101,7 +107,7 @@ private fun AdapterDelegateViewBindingViewHolder<Place, ItemPlaceBinding>.showOr
|
|||
(recyclerView.layoutManager as LinearLayoutManager?)
|
||||
?.scrollToPositionWithOffset(
|
||||
lastPosition,
|
||||
nearbyButtonLayout.buttonLayout.height
|
||||
nearbyButtonLayout.buttonLayout.height,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,13 +49,15 @@ class WikidataFeedback : BaseActivity() {
|
|||
binding.radioButton1.setText(
|
||||
getString(
|
||||
R.string.does_not_exist_anymore_no_picture_can_ever_be_taken_of_it,
|
||||
place
|
||||
))
|
||||
place,
|
||||
),
|
||||
)
|
||||
binding.radioButton2.setText(
|
||||
getString(
|
||||
R.string.is_at_a_different_place_please_specify_the_correct_place_below_if_possible_tell_us_the_correct_latitude_longitude,
|
||||
place
|
||||
))
|
||||
place,
|
||||
),
|
||||
)
|
||||
binding.radioButton3.setText(getString(R.string.other_problem_or_information_please_explain_below))
|
||||
setSupportActionBar(binding.toolbarBinding.toolbar)
|
||||
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
|
||||
|
|
@ -64,21 +66,29 @@ class WikidataFeedback : BaseActivity() {
|
|||
var desc = findViewById<RadioButton>(binding.radioGroup.checkedRadioButtonId).text
|
||||
var det = binding.detailsEditText.text.toString()
|
||||
if (binding.radioGroup.checkedRadioButtonId == R.id.radioButton3 && binding.detailsEditText.text.isNullOrEmpty()) {
|
||||
Toast.makeText(
|
||||
this,
|
||||
getString(R.string.please_enter_some_comments), Toast.LENGTH_SHORT
|
||||
).show()
|
||||
Toast
|
||||
.makeText(
|
||||
this,
|
||||
getString(R.string.please_enter_some_comments),
|
||||
Toast.LENGTH_SHORT,
|
||||
).show()
|
||||
} else {
|
||||
binding.radioGroup.clearCheck()
|
||||
binding.detailsEditText.setText("")
|
||||
Single.defer<Boolean?>(Callable<SingleSource<Boolean?>> {
|
||||
pageEditHelper.makePageEdit(
|
||||
this, pageTitle, preText,
|
||||
desc.toString(),
|
||||
det, lat, lng
|
||||
)
|
||||
} as Callable<SingleSource<Boolean?>>)
|
||||
.subscribeOn(Schedulers.io())
|
||||
Single
|
||||
.defer<Boolean?>(
|
||||
Callable<SingleSource<Boolean?>> {
|
||||
pageEditHelper.makePageEdit(
|
||||
this,
|
||||
pageTitle,
|
||||
preText,
|
||||
desc.toString(),
|
||||
det,
|
||||
lat,
|
||||
lng,
|
||||
)
|
||||
} as Callable<SingleSource<Boolean?>>,
|
||||
).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({ aBoolean: Boolean? ->
|
||||
}, { throwable: Throwable? ->
|
||||
|
|
@ -92,5 +102,4 @@ class WikidataFeedback : BaseActivity() {
|
|||
onBackPressed()
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,8 @@ import androidx.fragment.app.Fragment
|
|||
import fr.free.nrw.commons.databinding.FragmentAdvanceQueryBinding
|
||||
|
||||
class AdvanceQueryFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentAdvanceQueryBinding? = null
|
||||
private val binding get() = _binding
|
||||
val binding get() = _binding
|
||||
|
||||
lateinit var callback: Callback
|
||||
|
||||
|
|
@ -28,7 +27,7 @@ class AdvanceQueryFragment : Fragment() {
|
|||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
savedInstanceState: Bundle?,
|
||||
): View? {
|
||||
_binding = FragmentAdvanceQueryBinding.inflate(inflater, container, false)
|
||||
etQuery = binding?.etQuery
|
||||
|
|
@ -38,7 +37,10 @@ class AdvanceQueryFragment : Fragment() {
|
|||
return binding?.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
override fun onViewCreated(
|
||||
view: View,
|
||||
savedInstanceState: Bundle?,
|
||||
) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
setUi()
|
||||
|
|
@ -79,7 +81,9 @@ class AdvanceQueryFragment : Fragment() {
|
|||
|
||||
interface Callback {
|
||||
fun reset()
|
||||
|
||||
fun apply(query: String)
|
||||
|
||||
fun close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,109 +21,126 @@ import timber.log.Timber
|
|||
import javax.inject.Inject
|
||||
import javax.inject.Named
|
||||
|
||||
|
||||
class CommonPlaceClickActions @Inject constructor(
|
||||
@Named("default_preferences") private val applicationKvStore: JsonKvStore,
|
||||
private val activity: Activity,
|
||||
private val contributionController: ContributionController
|
||||
) {
|
||||
|
||||
fun onCameraClicked(): (Place, ActivityResultLauncher<Array<String>>) -> Unit = { place, launcher ->
|
||||
if (applicationKvStore.getBoolean("login_skipped", false)) {
|
||||
showLoginDialog()
|
||||
} else {
|
||||
Timber.d("Camera button tapped. Image title: ${place.getName()}Image desc: ${place.longDescription}")
|
||||
storeSharedPrefs(place)
|
||||
contributionController.initiateCameraPick(activity, launcher)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the Label for the Icon when it's long pressed
|
||||
**/
|
||||
fun onCameraLongPressed(): () -> Boolean = {
|
||||
Toast.makeText(activity, R.string.menu_from_camera, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
fun onGalleryLongPressed(): () -> Boolean = {
|
||||
Toast.makeText(activity, R.string.menu_from_gallery, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
fun onBookmarkLongPressed(): () -> Boolean = {
|
||||
Toast.makeText(activity, R.string.menu_bookmark, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
fun onDirectionsLongPressed(): () -> Boolean = {
|
||||
Toast.makeText(activity, R.string.nearby_directions, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
fun onOverflowLongPressed(): () -> Boolean = {
|
||||
Toast.makeText(activity, R.string.more, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
|
||||
fun onGalleryClicked(): (Place) -> Unit = {
|
||||
if (applicationKvStore.getBoolean("login_skipped", false)) {
|
||||
showLoginDialog()
|
||||
} else {
|
||||
Timber.d("Gallery button tapped. Image title: ${it.getName()}Image desc: ${it.getLongDescription()}")
|
||||
storeSharedPrefs(it)
|
||||
contributionController.initiateGalleryPick(activity, false)
|
||||
}
|
||||
}
|
||||
|
||||
fun onOverflowClicked(): (Place, View) -> Unit = { place, view ->
|
||||
PopupMenu(view.context, view).apply {
|
||||
inflate(R.menu.nearby_info_dialog_options)
|
||||
enableBy(R.id.nearby_info_menu_commons_article, place.hasCommonsLink())
|
||||
enableBy(R.id.nearby_info_menu_wikidata_article, place.hasWikidataLink())
|
||||
enableBy(R.id.nearby_info_menu_wikipedia_article, place.hasWikipediaLink())
|
||||
setOnMenuItemClickListener { item: MenuItem ->
|
||||
when (item.itemId) {
|
||||
R.id.nearby_info_menu_commons_article -> openWebView(place.siteLinks.commonsLink)
|
||||
R.id.nearby_info_menu_wikidata_article -> openWebView(place.siteLinks.wikidataLink)
|
||||
R.id.nearby_info_menu_wikipedia_article -> openWebView(place.siteLinks.wikipediaLink)
|
||||
else -> false
|
||||
class CommonPlaceClickActions
|
||||
@Inject
|
||||
constructor(
|
||||
@Named("default_preferences") private val applicationKvStore: JsonKvStore,
|
||||
private val activity: Activity,
|
||||
private val contributionController: ContributionController,
|
||||
) {
|
||||
fun onCameraClicked(): (Place, ActivityResultLauncher<Array<String>>) -> Unit =
|
||||
{ place, launcher ->
|
||||
if (applicationKvStore.getBoolean("login_skipped", false)) {
|
||||
showLoginDialog()
|
||||
} else {
|
||||
Timber.d("Camera button tapped. Image title: ${place.getName()}Image desc: ${place.longDescription}")
|
||||
storeSharedPrefs(place)
|
||||
contributionController.initiateCameraPick(activity, launcher)
|
||||
}
|
||||
}
|
||||
}.show()
|
||||
}
|
||||
|
||||
fun onDirectionsClicked(): (Place) -> Unit = {
|
||||
Utils.handleGeoCoordinates(activity, it.getLocation())
|
||||
}
|
||||
|
||||
private fun storeSharedPrefs(selectedPlace: Place) {
|
||||
Timber.d("Store place object %s", selectedPlace.toString())
|
||||
applicationKvStore.putJson(WikidataConstants.PLACE_OBJECT, selectedPlace)
|
||||
}
|
||||
|
||||
private fun openWebView(link: Uri): Boolean {
|
||||
Utils.handleWebUrl(activity, link)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun PopupMenu.enableBy(menuId: Int, hasLink: Boolean) {
|
||||
menu.findItem(menuId).isEnabled = hasLink
|
||||
}
|
||||
|
||||
private fun showLoginDialog() {
|
||||
AlertDialog.Builder(activity)
|
||||
.setMessage(R.string.login_alert_message)
|
||||
.setPositiveButton(R.string.login) { dialog, which ->
|
||||
setPositiveButton()
|
||||
/**
|
||||
* Shows the Label for the Icon when it's long pressed
|
||||
**/
|
||||
fun onCameraLongPressed(): () -> Boolean =
|
||||
{
|
||||
Toast.makeText(activity, R.string.menu_from_camera, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun setPositiveButton() {
|
||||
ActivityUtils.startActivityWithFlags(
|
||||
activity,
|
||||
LoginActivity::class.java,
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP,
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||
)
|
||||
applicationKvStore.putBoolean("login_skipped", false)
|
||||
activity.finish()
|
||||
fun onGalleryLongPressed(): () -> Boolean =
|
||||
{
|
||||
Toast.makeText(activity, R.string.menu_from_gallery, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
|
||||
fun onBookmarkLongPressed(): () -> Boolean =
|
||||
{
|
||||
Toast.makeText(activity, R.string.menu_bookmark, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
|
||||
fun onDirectionsLongPressed(): () -> Boolean =
|
||||
{
|
||||
Toast.makeText(activity, R.string.nearby_directions, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
|
||||
fun onOverflowLongPressed(): () -> Boolean =
|
||||
{
|
||||
Toast.makeText(activity, R.string.more, Toast.LENGTH_SHORT).show()
|
||||
true
|
||||
}
|
||||
|
||||
fun onGalleryClicked(): (Place) -> Unit =
|
||||
{
|
||||
if (applicationKvStore.getBoolean("login_skipped", false)) {
|
||||
showLoginDialog()
|
||||
} else {
|
||||
Timber.d("Gallery button tapped. Image title: ${it.getName()}Image desc: ${it.getLongDescription()}")
|
||||
storeSharedPrefs(it)
|
||||
contributionController.initiateGalleryPick(activity, false)
|
||||
}
|
||||
}
|
||||
|
||||
fun onOverflowClicked(): (Place, View) -> Unit =
|
||||
{ place, view ->
|
||||
PopupMenu(view.context, view)
|
||||
.apply {
|
||||
inflate(R.menu.nearby_info_dialog_options)
|
||||
enableBy(R.id.nearby_info_menu_commons_article, place.hasCommonsLink())
|
||||
enableBy(R.id.nearby_info_menu_wikidata_article, place.hasWikidataLink())
|
||||
enableBy(R.id.nearby_info_menu_wikipedia_article, place.hasWikipediaLink())
|
||||
setOnMenuItemClickListener { item: MenuItem ->
|
||||
when (item.itemId) {
|
||||
R.id.nearby_info_menu_commons_article -> openWebView(place.siteLinks.commonsLink)
|
||||
R.id.nearby_info_menu_wikidata_article -> openWebView(place.siteLinks.wikidataLink)
|
||||
R.id.nearby_info_menu_wikipedia_article -> openWebView(place.siteLinks.wikipediaLink)
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
}.show()
|
||||
}
|
||||
|
||||
fun onDirectionsClicked(): (Place) -> Unit =
|
||||
{
|
||||
Utils.handleGeoCoordinates(activity, it.getLocation())
|
||||
}
|
||||
|
||||
private fun storeSharedPrefs(selectedPlace: Place) {
|
||||
Timber.d("Store place object %s", selectedPlace.toString())
|
||||
applicationKvStore.putJson(WikidataConstants.PLACE_OBJECT, selectedPlace)
|
||||
}
|
||||
|
||||
private fun openWebView(link: Uri): Boolean {
|
||||
Utils.handleWebUrl(activity, link)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun PopupMenu.enableBy(
|
||||
menuId: Int,
|
||||
hasLink: Boolean,
|
||||
) {
|
||||
menu.findItem(menuId).isEnabled = hasLink
|
||||
}
|
||||
|
||||
private fun showLoginDialog() {
|
||||
AlertDialog
|
||||
.Builder(activity)
|
||||
.setMessage(R.string.login_alert_message)
|
||||
.setPositiveButton(R.string.login) { dialog, which ->
|
||||
setPositiveButton()
|
||||
}.show()
|
||||
}
|
||||
|
||||
private fun setPositiveButton() {
|
||||
ActivityUtils.startActivityWithFlags(
|
||||
activity,
|
||||
LoginActivity::class.java,
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP,
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP,
|
||||
)
|
||||
applicationKvStore.putBoolean("login_skipped", false)
|
||||
activity.finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,8 @@ class PlaceAdapter(
|
|||
onPlaceClicked: ((Place) -> Unit)? = null,
|
||||
onBookmarkClicked: (Place, Boolean) -> Unit,
|
||||
commonPlaceClickActions: CommonPlaceClickActions,
|
||||
inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>
|
||||
) :
|
||||
BaseDelegateAdapter<Place>(
|
||||
inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>,
|
||||
) : BaseDelegateAdapter<Place>(
|
||||
placeAdapterDelegate(
|
||||
bookmarkLocationsDao,
|
||||
onPlaceClicked,
|
||||
|
|
@ -27,7 +26,7 @@ class PlaceAdapter(
|
|||
commonPlaceClickActions.onOverflowLongPressed(),
|
||||
commonPlaceClickActions.onDirectionsClicked(),
|
||||
commonPlaceClickActions.onDirectionsLongPressed(),
|
||||
inAppCameraLocationPermissionLauncher
|
||||
inAppCameraLocationPermissionLauncher,
|
||||
),
|
||||
areItemsTheSame = {oldItem, newItem -> oldItem.wikiDataEntityId == newItem.wikiDataEntityId }
|
||||
areItemsTheSame = { oldItem, newItem -> oldItem.wikiDataEntityId == newItem.wikiDataEntityId },
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
package fr.free.nrw.commons.nearby.model
|
||||
|
||||
class BottomSheetItem(var imageResourceId: Int, val title: String)
|
||||
class BottomSheetItem(
|
||||
var imageResourceId: Int,
|
||||
val title: String,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
package fr.free.nrw.commons.nearby.model
|
||||
|
||||
class NearbyResponse(val results: NearbyResults)
|
||||
class NearbyResponse(
|
||||
val results: NearbyResults,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,78 +2,50 @@ package fr.free.nrw.commons.nearby.model
|
|||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
class NearbyResultItem(private val item: ResultTuple?,
|
||||
private val wikipediaArticle: ResultTuple?,
|
||||
private val commonsArticle: ResultTuple?,
|
||||
private val location: ResultTuple?,
|
||||
private val label: ResultTuple?,
|
||||
@field:SerializedName("streetAddress") private val address: ResultTuple?,
|
||||
private val icon: ResultTuple?, @field:SerializedName("class") private val className: ResultTuple?,
|
||||
@field:SerializedName("classLabel") private val classLabel: ResultTuple?,
|
||||
@field:SerializedName("commonsCategory") private val commonsCategory: ResultTuple?,
|
||||
@field:SerializedName("pic") private val pic: ResultTuple?,
|
||||
@field:SerializedName("destroyed") private val destroyed: ResultTuple?,
|
||||
@field:SerializedName("description") private val description: ResultTuple?,
|
||||
@field:SerializedName("endTime") private val endTime: ResultTuple?,
|
||||
@field:SerializedName("monument") private val monument: ResultTuple?) {
|
||||
class NearbyResultItem(
|
||||
private val item: ResultTuple?,
|
||||
private val wikipediaArticle: ResultTuple?,
|
||||
private val commonsArticle: ResultTuple?,
|
||||
private val location: ResultTuple?,
|
||||
private val label: ResultTuple?,
|
||||
@field:SerializedName("streetAddress") private val address: ResultTuple?,
|
||||
private val icon: ResultTuple?,
|
||||
@field:SerializedName("class") private val className: ResultTuple?,
|
||||
@field:SerializedName("classLabel") private val classLabel: ResultTuple?,
|
||||
@field:SerializedName("commonsCategory") private val commonsCategory: ResultTuple?,
|
||||
@field:SerializedName("pic") private val pic: ResultTuple?,
|
||||
@field:SerializedName("destroyed") private val destroyed: ResultTuple?,
|
||||
@field:SerializedName("description") private val description: ResultTuple?,
|
||||
@field:SerializedName("endTime") private val endTime: ResultTuple?,
|
||||
@field:SerializedName("monument") private val monument: ResultTuple?,
|
||||
) {
|
||||
fun getItem(): ResultTuple = item ?: ResultTuple()
|
||||
|
||||
fun getItem(): ResultTuple {
|
||||
return item ?: ResultTuple()
|
||||
}
|
||||
fun getWikipediaArticle(): ResultTuple = wikipediaArticle ?: ResultTuple()
|
||||
|
||||
fun getWikipediaArticle(): ResultTuple {
|
||||
return wikipediaArticle ?: ResultTuple()
|
||||
}
|
||||
fun getCommonsArticle(): ResultTuple = commonsArticle ?: ResultTuple()
|
||||
|
||||
fun getCommonsArticle(): ResultTuple {
|
||||
return commonsArticle ?: ResultTuple()
|
||||
}
|
||||
fun getLocation(): ResultTuple = location ?: ResultTuple()
|
||||
|
||||
fun getLocation(): ResultTuple {
|
||||
return location ?: ResultTuple()
|
||||
}
|
||||
fun getLabel(): ResultTuple = label ?: ResultTuple()
|
||||
|
||||
fun getLabel(): ResultTuple {
|
||||
return label ?: ResultTuple()
|
||||
}
|
||||
fun getIcon(): ResultTuple = icon ?: ResultTuple()
|
||||
|
||||
fun getIcon(): ResultTuple {
|
||||
return icon ?: ResultTuple()
|
||||
}
|
||||
fun getClassName(): ResultTuple = className ?: ResultTuple()
|
||||
|
||||
fun getClassName(): ResultTuple {
|
||||
return className ?: ResultTuple()
|
||||
}
|
||||
fun getClassLabel(): ResultTuple = classLabel ?: ResultTuple()
|
||||
|
||||
fun getClassLabel(): ResultTuple {
|
||||
return classLabel ?: ResultTuple()
|
||||
}
|
||||
fun getCommonsCategory(): ResultTuple = commonsCategory ?: ResultTuple()
|
||||
|
||||
fun getCommonsCategory(): ResultTuple {
|
||||
return commonsCategory ?: ResultTuple()
|
||||
}
|
||||
fun getPic(): ResultTuple = pic ?: ResultTuple()
|
||||
|
||||
fun getPic(): ResultTuple {
|
||||
return pic ?: ResultTuple()
|
||||
}
|
||||
fun getDestroyed(): ResultTuple = destroyed ?: ResultTuple()
|
||||
|
||||
fun getDestroyed(): ResultTuple {
|
||||
return destroyed ?: ResultTuple()
|
||||
}
|
||||
fun getDescription(): ResultTuple = description ?: ResultTuple()
|
||||
|
||||
fun getDescription(): ResultTuple {
|
||||
return description ?: ResultTuple()
|
||||
}
|
||||
fun getEndTime(): ResultTuple = endTime ?: ResultTuple()
|
||||
|
||||
fun getEndTime(): ResultTuple {
|
||||
return endTime ?: ResultTuple()
|
||||
}
|
||||
fun getAddress(): String = address?.value ?: ""
|
||||
|
||||
fun getAddress(): String {
|
||||
return address?.value?:""
|
||||
}
|
||||
|
||||
fun getMonument():ResultTuple?{
|
||||
return monument
|
||||
}
|
||||
}
|
||||
fun getMonument(): ResultTuple? = monument
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
package fr.free.nrw.commons.nearby.model
|
||||
|
||||
class NearbyResults(val bindings: List<NearbyResultItem>)
|
||||
class NearbyResults(
|
||||
val bindings: List<NearbyResultItem>,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,41 +6,40 @@ data class PlaceBindings(
|
|||
@SerializedName("item") val item: Item,
|
||||
@SerializedName("label") val label: Label,
|
||||
@SerializedName("location") val location: Location,
|
||||
@SerializedName("class") val clas: Clas
|
||||
@SerializedName("class") val clas: Clas,
|
||||
)
|
||||
|
||||
data class ItemsClass(
|
||||
@SerializedName("head") val head: Head,
|
||||
@SerializedName("results") val results: Results
|
||||
@SerializedName("results") val results: Results,
|
||||
)
|
||||
|
||||
data class Label(
|
||||
@SerializedName("xml:lang") val xml: String,
|
||||
@SerializedName("type") val type: String,
|
||||
@SerializedName("value") val value: String
|
||||
@SerializedName("value") val value: String,
|
||||
)
|
||||
|
||||
data class Location(
|
||||
@SerializedName("datatype") val datatype: String,
|
||||
@SerializedName("type") val type: String,
|
||||
@SerializedName("value") val value: String
|
||||
@SerializedName("value") val value: String,
|
||||
)
|
||||
|
||||
data class Results(
|
||||
@SerializedName("bindings") val bindings: List<PlaceBindings>
|
||||
@SerializedName("bindings") val bindings: List<PlaceBindings>,
|
||||
)
|
||||
|
||||
data class Item(
|
||||
@SerializedName("type") val type: String,
|
||||
@SerializedName("value") val value: String
|
||||
@SerializedName("value") val value: String,
|
||||
)
|
||||
|
||||
data class Head(
|
||||
@SerializedName("vars") val vars: List<String>
|
||||
@SerializedName("vars") val vars: List<String>,
|
||||
)
|
||||
|
||||
|
||||
data class Clas(
|
||||
@SerializedName("type") val type: String,
|
||||
@SerializedName("value") val value: String
|
||||
)
|
||||
@SerializedName("value") val value: String,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -19,5 +19,4 @@ class ResultTuple {
|
|||
type = ""
|
||||
value = ""
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue