apps-android-commons/app/src/main/java/fr/free/nrw/commons/Media.kt
Ashish 7476b0a24d
Merge changes from 3.1-release (#4629)
* Cherry-Picked NPE fix from master (#4569)

* Fix notification bug #4547 (#4570)

* Make Single Query for Nearby and WLM pins (#4573)

* Merge nearby and monument queries

* Bug Fix- query resource path change on shouldQueryForMonuments

* Bug Fixes
1. Propagate exceptions for nearby API calls to caller
2. Fix too much work on main thread exception in NearbyParentFragment

* Modify parameters for Nearby query

* Bug fix- current location marker (#4580)

* Move WLM template below geolocation template (#4582)

* Modify string for WLM upload notice

* Fix bug #4583 (#4591)

* Fix bug #4585 by updating kotlin and acra version (#4592)

* Fixes #4554 - only use WLM2021 template for countries that are included in it (#4574)

* Fixes #4554
1. For WLM uploads reverse geo code and see if the country code is supported -only then is the WLM upload flow triggered, otherwise usual nearby uploads happen
2. Bug Fix - Current Location marker and area

* Fixed compile error added after rebasing

* Bug fix for country code in reverse geo code

* Update WLM camaign dates [Do not merge now, merge only after alpha release] (#4584)

* Updates dates for WML campaign

* Bug fix- campaign dates

* Fixed logic for WLM enablement - stick to the month of September

* Add countries supported by WLM2021 template, except Italy

* Versioning for v3.1.0

* Update changelog.md

* Fix empty default lang bug (#4608)

* Fix bug #4583

* Fix empty default lang bug

* Fixes #4595 - Updated nearby query (#4622)

* Fixes #4595 - Updated nearby query

* Removed logic to replace local language in nearby query - that might acccidentally replace other strings

* Fetch property location in usual nearby query

* Remove duplicate line (#4626)

* Change "learn more" link to new wiki

* Add Sweden's P3426 to property filter

* Fixes #4601 - 1. Handle possible exceptions in upload file from stash 2. Modify MWException, as error is nullable, update getTitle and getMessage to rever that (#4627)

* Versioning for v3.1.1

* Update changelog.md

* Updated DB version to rever integrity

Co-authored-by: Madhur Gupta <30932899+madhurgupta10@users.noreply.github.com>
Co-authored-by: Josephine Lim <josephinelim86@gmail.com>
2021-09-16 23:09:29 +10:00

137 lines
3.7 KiB
Kotlin

package fr.free.nrw.commons
import android.os.Parcelable
import fr.free.nrw.commons.location.LatLng
import kotlinx.android.parcel.Parcelize
import org.wikipedia.page.PageTitle
import java.util.*
@Parcelize
class Media constructor(
/**
* @return pageId for the current media object
* Wikibase Identifier associated with media files
*/
var pageId: String = UUID.randomUUID().toString(),
var thumbUrl: String? = null,
/**
* Gets image URL
* @return Image URL
*/
var imageUrl: String? = null,
/**
* Gets the name of the file.
* @return file name as a string
*/
var filename: String? = null,
/**
* Gets the file description.
* @return file description as a string
*/
// monolingual description on input...
/**
* Sets the file description.
* @param fallbackDescription the new description of the file
*/
var fallbackDescription: String? = null,
/**
* Gets the upload date of the file.
* Can be null.
* @return upload date as a Date
*/
var dateUploaded: Date? = null,
/**
* Gets the license name of the file.
* @return license as a String
*/
/**
* Sets the license name of the file.
*
* @param license license name as a String
*/
var license: String? = null,
var licenseUrl: String? = null,
/**
* Gets the name of the creator of the file.
* @return author name as a String
*/
/**
* Sets the author name of the file.
* @param author creator name as a string
*/
var author: String? = null,
var user:String?=null,
/**
* Gets the categories the file falls under.
* @return file categories as an ArrayList of Strings
*/
var categories: List<String>? = null,
/**
* Gets the coordinates of where the file was created.
* @return file coordinates as a LatLng
*/
var coordinates: LatLng? = null,
var captions: Map<String, String> = emptyMap(),
var descriptions: Map<String, String> = emptyMap(),
var depictionIds: List<String> = emptyList()
) : Parcelable {
constructor(
captions: Map<String, String>,
categories: List<String>?,
filename: String?,
fallbackDescription: String?,
author: String?, user:String?
) : this(
filename = filename,
fallbackDescription = fallbackDescription,
dateUploaded = Date(),
author = author,
user=user,
categories = categories,
captions = captions
)
/**
* Gets media display title
* @return Media title
*/
val displayTitle: String
get() =
if (filename != null)
pageTitle.displayTextWithoutNamespace.replaceFirst("[.][^.]+$".toRegex(), "")
else
""
/**
* Gets file page title
* @return New media page title
*/
val pageTitle: PageTitle get() = Utils.getPageTitle(filename!!)
/**
* Returns wikicode to use the media file on a MediaWiki site
* @return
*/
val wikiCode: String
get() = String.format("[[%s|thumb|%s]]", filename, mostRelevantCaption)
val mostRelevantCaption: String
get() = captions[Locale.getDefault().language]
?: captions.values.firstOrNull()
?: displayTitle
/**
* Gets the categories the file falls under.
* @return file categories as an ArrayList of Strings
*/
var addedCategories: List<String>? = null
// TODO added categories should be removed. It is added for a short fix. On category update,
// categories should be re-fetched instead
get() = field // getter
set(value) { field = value } // setter
}