mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
make new changes
This commit is contained in:
parent
d1f08c6cd5
commit
773324a7f2
4 changed files with 190 additions and 11 deletions
|
|
@ -90,6 +90,41 @@ class Media constructor(
|
||||||
captions = captions,
|
captions = captions,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
captions: Map<String, String>,
|
||||||
|
categories: List<String>?,
|
||||||
|
filename: String?,
|
||||||
|
fallbackDescription: String?,
|
||||||
|
author: String?,
|
||||||
|
user: String?,
|
||||||
|
dateUploaded: Date? = Date(),
|
||||||
|
license: String? = null,
|
||||||
|
licenseUrl: String? = null,
|
||||||
|
imageUrl: String? = null,
|
||||||
|
thumbUrl: String? = null,
|
||||||
|
coordinates: LatLng? = null,
|
||||||
|
descriptions: Map<String, String> = emptyMap(),
|
||||||
|
depictionIds: List<String> = emptyList(),
|
||||||
|
categoriesHiddenStatus: Map<String, Boolean> = emptyMap()
|
||||||
|
) : this(
|
||||||
|
pageId = UUID.randomUUID().toString(),
|
||||||
|
filename = filename,
|
||||||
|
fallbackDescription = fallbackDescription,
|
||||||
|
dateUploaded = dateUploaded,
|
||||||
|
author = author,
|
||||||
|
user = user,
|
||||||
|
categories = categories,
|
||||||
|
captions = captions,
|
||||||
|
license = license,
|
||||||
|
licenseUrl = licenseUrl,
|
||||||
|
imageUrl = imageUrl,
|
||||||
|
thumbUrl = thumbUrl,
|
||||||
|
coordinates = coordinates,
|
||||||
|
descriptions = descriptions,
|
||||||
|
depictionIds = depictionIds,
|
||||||
|
categoriesHiddenStatus = categoriesHiddenStatus
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets media display title
|
* Gets media display title
|
||||||
* @return Media title
|
* @return Media title
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import android.view.KeyEvent
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.view.ViewTreeObserver
|
||||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener
|
import android.view.ViewTreeObserver.OnGlobalLayoutListener
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
|
|
@ -405,9 +406,14 @@ class MediaDetailFragment : CommonsDaggerSupportFragment(), CategoryEditHelper.C
|
||||||
* Gets the height of the frame layout as soon as the view is ready and updates aspect ratio
|
* Gets the height of the frame layout as soon as the view is ready and updates aspect ratio
|
||||||
* of the picture.
|
* of the picture.
|
||||||
*/
|
*/
|
||||||
view.post {
|
view.post{
|
||||||
frameLayoutHeight = binding.mediaDetailFrameLayout.measuredHeight
|
val width = binding.mediaDetailScrollView.width
|
||||||
updateAspectRatio(binding.mediaDetailScrollView.width)
|
if (width > 0) {
|
||||||
|
frameLayoutHeight = binding.mediaDetailFrameLayout.measuredHeight
|
||||||
|
updateAspectRatio(width)
|
||||||
|
} else {
|
||||||
|
view.postDelayed({ updateAspectRatio(binding.root.width) }, 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return view
|
return view
|
||||||
|
|
|
||||||
|
|
@ -185,10 +185,12 @@ public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment imple
|
||||||
* or a fragment
|
* or a fragment
|
||||||
*/
|
*/
|
||||||
private void initProvider() {
|
private void initProvider() {
|
||||||
if (getParentFragment() != null) {
|
if (getParentFragment() instanceof MediaDetailProvider) {
|
||||||
provider = (MediaDetailProvider) getParentFragment();
|
provider = (MediaDetailProvider) getParentFragment();
|
||||||
} else {
|
} else if (getActivity() instanceof MediaDetailProvider) {
|
||||||
provider = (MediaDetailProvider) getActivity();
|
provider = (MediaDetailProvider) getActivity();
|
||||||
|
} else {
|
||||||
|
throw new ClassCastException("Parent must implement MediaDetailProvider");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.lifecycle.LifecycleCoroutineScope
|
import androidx.lifecycle.LifecycleCoroutineScope
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.DividerItemDecoration
|
import androidx.recyclerview.widget.DividerItemDecoration
|
||||||
|
|
@ -51,6 +52,7 @@ import com.jakewharton.rxbinding2.view.RxView
|
||||||
import com.jakewharton.rxbinding3.appcompat.queryTextChanges
|
import com.jakewharton.rxbinding3.appcompat.queryTextChanges
|
||||||
import fr.free.nrw.commons.CommonsApplication
|
import fr.free.nrw.commons.CommonsApplication
|
||||||
import fr.free.nrw.commons.MapController.NearbyPlacesInfo
|
import fr.free.nrw.commons.MapController.NearbyPlacesInfo
|
||||||
|
import fr.free.nrw.commons.Media
|
||||||
import fr.free.nrw.commons.R
|
import fr.free.nrw.commons.R
|
||||||
import fr.free.nrw.commons.Utils
|
import fr.free.nrw.commons.Utils
|
||||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao
|
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao
|
||||||
|
|
@ -69,6 +71,8 @@ import fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType
|
||||||
import fr.free.nrw.commons.location.LocationUpdateListener
|
import fr.free.nrw.commons.location.LocationUpdateListener
|
||||||
import fr.free.nrw.commons.media.MediaClient
|
import fr.free.nrw.commons.media.MediaClient
|
||||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment
|
import fr.free.nrw.commons.media.MediaDetailPagerFragment
|
||||||
|
import fr.free.nrw.commons.media.MediaDetailPagerFragment.MediaDetailProvider
|
||||||
|
import fr.free.nrw.commons.navtab.NavTab
|
||||||
import fr.free.nrw.commons.nearby.BottomSheetAdapter
|
import fr.free.nrw.commons.nearby.BottomSheetAdapter
|
||||||
import fr.free.nrw.commons.nearby.BottomSheetAdapter.ItemClickListener
|
import fr.free.nrw.commons.nearby.BottomSheetAdapter.ItemClickListener
|
||||||
import fr.free.nrw.commons.nearby.CheckBoxTriStates
|
import fr.free.nrw.commons.nearby.CheckBoxTriStates
|
||||||
|
|
@ -120,17 +124,25 @@ import timber.log.Timber
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.net.URLDecoder
|
||||||
|
import java.nio.charset.StandardCharsets
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
import java.util.UUID
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Named
|
import javax.inject.Named
|
||||||
import kotlin.concurrent.Volatile
|
import kotlin.concurrent.Volatile
|
||||||
|
|
||||||
|
|
||||||
class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmentContract.View,
|
class NearbyParentFragment : CommonsDaggerSupportFragment(),
|
||||||
WikidataP18EditListener, LocationUpdateListener, LocationPermissionCallback, ItemClickListener {
|
NearbyParentFragmentContract.View,
|
||||||
|
WikidataP18EditListener,
|
||||||
|
LocationUpdateListener,
|
||||||
|
LocationPermissionCallback,
|
||||||
|
ItemClickListener,
|
||||||
|
MediaDetailPagerFragment.MediaDetailProvider {
|
||||||
var binding: FragmentNearbyParentBinding? = null
|
var binding: FragmentNearbyParentBinding? = null
|
||||||
|
|
||||||
val mapEventsOverlay: MapEventsOverlay = MapEventsOverlay(object : MapEventsReceiver {
|
val mapEventsOverlay: MapEventsOverlay = MapEventsOverlay(object : MapEventsReceiver {
|
||||||
|
|
@ -165,6 +177,13 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
||||||
@Named("default_preferences")
|
@Named("default_preferences")
|
||||||
lateinit var applicationKvStore: JsonKvStore
|
lateinit var applicationKvStore: JsonKvStore
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var mediaClient: MediaClient
|
||||||
|
|
||||||
|
lateinit var mediaDetails: MediaDetailPagerFragment
|
||||||
|
|
||||||
|
lateinit var media: Media
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var bookmarkLocationDao: BookmarkLocationsDao
|
lateinit var bookmarkLocationDao: BookmarkLocationsDao
|
||||||
|
|
||||||
|
|
@ -717,6 +736,10 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
||||||
presenter?.attachView(this)
|
presenter?.attachView(this)
|
||||||
registerNetworkReceiver()
|
registerNetworkReceiver()
|
||||||
|
|
||||||
|
binding?.coordinatorLayout?.visibility = View.VISIBLE
|
||||||
|
binding?.map?.setMultiTouchControls(true)
|
||||||
|
binding?.map?.isClickable = true
|
||||||
|
|
||||||
if (isResumed && (activity as? MainActivity)?.activeFragment == ActiveFragment.NEARBY) {
|
if (isResumed && (activity as? MainActivity)?.activeFragment == ActiveFragment.NEARBY) {
|
||||||
if (activity?.let { locationPermissionsHelper?.checkLocationPermission(it) } == true) {
|
if (activity?.let { locationPermissionsHelper?.checkLocationPermission(it) } == true) {
|
||||||
locationPermissionGranted()
|
locationPermissionGranted()
|
||||||
|
|
@ -1853,7 +1876,31 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
||||||
}
|
}
|
||||||
|
|
||||||
fun backButtonClicked(): Boolean {
|
fun backButtonClicked(): Boolean {
|
||||||
return presenter!!.backButtonClicked()
|
if (::mediaDetails.isInitialized && mediaDetails.isVisible) {
|
||||||
|
removeFragment(mediaDetails)
|
||||||
|
|
||||||
|
binding?.coordinatorLayout?.visibility = View.VISIBLE
|
||||||
|
binding?.map?.setMultiTouchControls(true)
|
||||||
|
binding?.map?.isClickable = true
|
||||||
|
|
||||||
|
val transaction = childFragmentManager.beginTransaction()
|
||||||
|
val fragmentContainer = childFragmentManager.findFragmentById(R.id.coordinator_layout)
|
||||||
|
|
||||||
|
if (fragmentContainer != null) {
|
||||||
|
transaction.show(fragmentContainer)
|
||||||
|
}
|
||||||
|
|
||||||
|
transaction.commit()
|
||||||
|
childFragmentManager.executePendingTransactions()
|
||||||
|
|
||||||
|
(activity as? MainActivity)?.showTabs()
|
||||||
|
(activity as? MainActivity)?.supportActionBar?.setDisplayHomeAsUpEnabled(false)
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
(activity as? MainActivity)?.setSelectedItemId(NavTab.NEARBY.code())
|
||||||
|
}
|
||||||
|
|
||||||
|
return presenter?.backButtonClicked() ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onLocationPermissionDenied(toastMessage: String) {
|
override fun onLocationPermissionDenied(toastMessage: String) {
|
||||||
|
|
@ -2342,9 +2389,98 @@ class NearbyParentFragment : CommonsDaggerSupportFragment(), NearbyParentFragmen
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleMediaClick(imageName: String) {
|
private fun handleMediaClick(imageName: String) {
|
||||||
val intent = Intent(Intent.ACTION_VIEW)
|
val decodedImageName = URLDecoder.decode(imageName, StandardCharsets.UTF_8.toString())
|
||||||
intent.data = Uri.parse("https://commons.wikimedia.org/wiki/File:$imageName")
|
|
||||||
startActivity(intent)
|
mediaClient.getMedia("File:$decodedImageName")
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe({ mediaResponse ->
|
||||||
|
if (mediaResponse != null) {
|
||||||
|
// Create a Media object from the response
|
||||||
|
media = Media(
|
||||||
|
pageId = mediaResponse.pageId ?: UUID.randomUUID().toString(),
|
||||||
|
thumbUrl = mediaResponse.thumbUrl,
|
||||||
|
imageUrl = mediaResponse.imageUrl,
|
||||||
|
filename = mediaResponse.filename,
|
||||||
|
fallbackDescription = mediaResponse.fallbackDescription,
|
||||||
|
dateUploaded = mediaResponse.dateUploaded,
|
||||||
|
license = mediaResponse.license,
|
||||||
|
licenseUrl = mediaResponse.licenseUrl,
|
||||||
|
author = mediaResponse.author,
|
||||||
|
user = mediaResponse.user,
|
||||||
|
categories = mediaResponse.categories,
|
||||||
|
coordinates = mediaResponse.coordinates,
|
||||||
|
captions = mediaResponse.captions ?: emptyMap(),
|
||||||
|
descriptions = mediaResponse.descriptions ?: emptyMap(),
|
||||||
|
depictionIds = mediaResponse.depictionIds ?: emptyList(),
|
||||||
|
categoriesHiddenStatus = mediaResponse.categoriesHiddenStatus ?: emptyMap()
|
||||||
|
)
|
||||||
|
// Remove existing fragment before showing new details
|
||||||
|
if (::mediaDetails.isInitialized && mediaDetails.isAdded) {
|
||||||
|
removeFragment(mediaDetails)
|
||||||
|
}
|
||||||
|
showMediaDetails()
|
||||||
|
} else {
|
||||||
|
Timber.e("Fetched media is null for image: $decodedImageName")
|
||||||
|
}
|
||||||
|
}, { throwable ->
|
||||||
|
Timber.e(throwable, "Error fetching media for image: $decodedImageName")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showMediaDetails() {
|
||||||
|
binding?.map?.setMultiTouchControls(false)
|
||||||
|
binding?.map?.isClickable = false
|
||||||
|
|
||||||
|
mediaDetails = MediaDetailPagerFragment.newInstance(false, true)
|
||||||
|
|
||||||
|
|
||||||
|
val transaction = childFragmentManager.beginTransaction()
|
||||||
|
|
||||||
|
val fragmentContainer = childFragmentManager.findFragmentById(R.id.coordinator_layout)
|
||||||
|
if (fragmentContainer != null) {
|
||||||
|
transaction.hide(fragmentContainer)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace instead of add to ensure new fragment is used
|
||||||
|
transaction.replace(R.id.coordinator_layout, mediaDetails, "MediaDetailFragmentTag")
|
||||||
|
transaction.addToBackStack("Nearby_Parent_Fragment_Tag").commit()
|
||||||
|
childFragmentManager.executePendingTransactions()
|
||||||
|
|
||||||
|
(activity as? MainActivity)?.supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
|
|
||||||
|
if (mediaDetails.isAdded) {
|
||||||
|
mediaDetails.showImage(0)
|
||||||
|
} else {
|
||||||
|
Timber.e("Error: MediaDetailPagerFragment is NOT added")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getMediaAtPosition(i: Int): Media? {
|
||||||
|
return media
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getTotalMediaCount(): Int {
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getContributionStateAt(position: Int): Int? {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun refreshNominatedMedia(index: Int) {
|
||||||
|
if (this::mediaDetails.isInitialized && !binding?.map?.isClickable!! == true) {
|
||||||
|
removeFragment(mediaDetails)
|
||||||
|
showMediaDetails()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun removeFragment(fragment: Fragment) {
|
||||||
|
childFragmentManager
|
||||||
|
.beginTransaction()
|
||||||
|
.remove(fragment)
|
||||||
|
.commit()
|
||||||
|
childFragmentManager.executePendingTransactions()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun storeSharedPrefs(selectedPlace: Place) {
|
private fun storeSharedPrefs(selectedPlace: Place) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue