Convert few model classes to kotlin (#3270)

This commit is contained in:
Vivek Maskara 2019-12-06 22:06:53 +05:30 committed by Josephine Lim
parent d0f97398a5
commit b0be4970ef
86 changed files with 661 additions and 1300 deletions

View file

@ -58,13 +58,20 @@ dependencies {
kapt "com.google.dagger:dagger-android-processor:$DAGGER_VERSION"
kapt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$KOTLIN_VERSION"
implementation "org.jetbrains.kotlin:kotlin-reflect:$KOTLIN_VERSION"
//Mocking
testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'
testImplementation 'org.mockito:mockito-inline:2.8.47'
testImplementation 'org.mockito:mockito-core:2.23.0'
testImplementation "org.powermock:powermock-module-junit4:2.0.0-beta.5"
testImplementation "org.powermock:powermock-api-mockito2:2.0.0-beta.5"
// Unit testing
testImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$KOTLIN_VERSION"
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$KOTLIN_VERSION"
testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:4.3'
testImplementation 'androidx.test:core:1.2.0'
testImplementation 'com.nhaarman:mockito-kotlin:1.5.0'
testImplementation 'com.squareup.okhttp3:mockwebserver:3.12.1'
testImplementation "org.powermock:powermock-module-junit4:2.0.0-beta.5"
testImplementation "org.powermock:powermock-api-mockito2:2.0.0-beta.5"

View file

@ -1,103 +0,0 @@
package fr.free.nrw.commons.achievements;
/**
* Represents Achievements class and stores all the parameters
*/
public class Achievements {
private int uniqueUsedImages;
private int thanksReceived;
private int featuredImages;
private int imagesUploaded;
private int revertCount;
public Achievements(){
}
/**
* constructor for achievements class to set its data members
* @param uniqueUsedImages
* @param thanksReceived
* @param featuredImages
* @param imagesUploaded
* @param revertCount
*/
public Achievements(int uniqueUsedImages,
int thanksReceived,
int featuredImages,
int imagesUploaded,
int revertCount) {
this.uniqueUsedImages = uniqueUsedImages;
this.thanksReceived = thanksReceived;
this.featuredImages = featuredImages;
this.imagesUploaded = imagesUploaded;
this.revertCount = revertCount;
}
/**
* Get Achievements object from FeedbackResponse
*
* @param response
* @return
*/
public static Achievements from(FeedbackResponse response) {
return new Achievements(response.getUniqueUsedImages(),
response.getThanksReceived(),
response.getFeaturedImages().getQualityImages()
+ response.getFeaturedImages().getFeaturedPicturesOnWikimediaCommons(),
0,
response.getDeletedUploads());
}
/**
* getter function to get count of images uploaded
* @return
*/
public int getImagesUploaded() {
return imagesUploaded;
}
/**
* getter function to get count of featured images
* @return
*/
public int getFeaturedImages() {
return featuredImages;
}
/**
* getter function to get count of thanks received
* @return
*/
public int getThanksReceived() {
return thanksReceived;
}
/**
* getter function to get count of unique images used by wiki
* @return
*/
public int getUniqueUsedImages() {
return uniqueUsedImages;
}
/**
* setter function to count of images uploaded
* @param imagesUploaded
*/
public void setImagesUploaded(int imagesUploaded) {
this.imagesUploaded = imagesUploaded;
}
/**
* used to calculate the percentages of images that haven't been reverted
* @return
*/
public int getNotRevertPercentage(){
try {
return ((imagesUploaded - revertCount) * 100)/imagesUploaded;
} catch (ArithmeticException divideByZero ){
return 100;
}
}
}

View file

@ -0,0 +1,98 @@
package fr.free.nrw.commons.achievements
/**
* Represents Achievements class and stores all the parameters
*/
class Achievements {
/**
* getter function to get count of unique images used by wiki
* @return
*/
/**
* setter function to set count of uniques images used by wiki
* @param uniqueUsedImages
*/
var uniqueUsedImages = 0
private var articlesUsingImages = 0
/**
* getter function to get count of thanks received
* @return
*/
/**
* setter function to set count of thanks received
* @param thanksReceived
*/
var thanksReceived = 0
/**
* getter function to get count of featured images
* @return
*/
/**
* setter function to set count of featured images
* @param featuredImages
*/
var featuredImages = 0
/**
* getter function to get count of images uploaded
* @return
*/
/**
* setter function to count of images uploaded
* @param imagesUploaded
*/
var imagesUploaded = 0
private var revertCount = 0
constructor() {}
/**
* constructor for achievements class to set its data members
* @param uniqueUsedImages
* @param articlesUsingImages
* @param thanksReceived
* @param featuredImages
* @param imagesUploaded
* @param revertCount
*/
constructor(uniqueUsedImages: Int,
articlesUsingImages: Int,
thanksReceived: Int,
featuredImages: Int,
imagesUploaded: Int,
revertCount: Int) {
this.uniqueUsedImages = uniqueUsedImages
this.articlesUsingImages = articlesUsingImages
this.thanksReceived = thanksReceived
this.featuredImages = featuredImages
this.imagesUploaded = imagesUploaded
this.revertCount = revertCount
}
/**
* used to calculate the percentages of images that haven't been reverted
* @return
*/
val notRevertPercentage: Int
get() = try {
(imagesUploaded - revertCount) * 100 / imagesUploaded
} catch (divideByZero: ArithmeticException) {
100
}
companion object {
/**
* Get Achievements object from FeedbackResponse
*
* @param response
* @return
*/
@JvmStatic
fun from(response: FeedbackResponse): Achievements {
return Achievements(response.uniqueUsedImages,
response.articlesUsingImages,
response.thanksReceived,
response.featuredImages.qualityImages
+ response.featuredImages.featuredPicturesOnWikimediaCommons, 0,
response.deletedUploads)
}
}
}

View file

@ -351,7 +351,7 @@ public class AchievementsActivity extends NavigationBaseActivity {
private void inflateAchievements(Achievements achievements) {
thanksReceived.setText(String.valueOf(achievements.getThanksReceived()));
imagesUsedByWikiProgressBar.setProgress
(100*achievements.getUniqueUsedImages()/levelInfo.getMaxUniqueImages() );
(100 * achievements.getUniqueUsedImages() / levelInfo.getMaxUniqueImages());
imagesUsedByWikiProgressBar.setProgressTextFormatPattern
(achievements.getUniqueUsedImages() + "/" + levelInfo.getMaxUniqueImages());
imagesFeatured.setText(String.valueOf(achievements.getFeaturedImages()));

View file

@ -1,25 +0,0 @@
package fr.free.nrw.commons.achievements;
import com.google.gson.annotations.SerializedName;
public class FeaturedImages {
@SerializedName("Quality_images")
private final int qualityImages;
@SerializedName("Featured_pictures_on_Wikimedia_Commons")
private final int featuredPicturesOnWikimediaCommons;
public FeaturedImages(int qualityImages, int featuredPicturesOnWikimediaCommons) {
this.qualityImages = qualityImages;
this.featuredPicturesOnWikimediaCommons = featuredPicturesOnWikimediaCommons;
}
public int getQualityImages() {
return qualityImages;
}
public int getFeaturedPicturesOnWikimediaCommons() {
return featuredPicturesOnWikimediaCommons;
}
}

View file

@ -0,0 +1,5 @@
package fr.free.nrw.commons.achievements
import com.google.gson.annotations.SerializedName
class FeaturedImages(@field:SerializedName("Quality_images") val qualityImages: Int, @field:SerializedName("Featured_pictures_on_Wikimedia_Commons") val featuredPicturesOnWikimediaCommons: Int)

View file

@ -1,51 +0,0 @@
package fr.free.nrw.commons.achievements;
public class FeedbackResponse {
private final int uniqueUsedImages;
private final int articlesUsingImages;
private final int deletedUploads;
private final FeaturedImages featuredImages;
private final int thanksReceived;
private final String user;
public FeedbackResponse(int uniqueUsedImages,
int articlesUsingImages,
int deletedUploads,
FeaturedImages featuredImages,
int thanksReceived,
String user) {
this.uniqueUsedImages = uniqueUsedImages;
this.articlesUsingImages = articlesUsingImages;
this.deletedUploads = deletedUploads;
this.featuredImages = featuredImages;
this.thanksReceived = thanksReceived;
this.user = user;
}
public int getUniqueUsedImages() {
return uniqueUsedImages;
}
public int getArticlesUsingImages() {
return articlesUsingImages;
}
public int getDeletedUploads() {
return deletedUploads;
}
public FeaturedImages getFeaturedImages() {
return featuredImages;
}
public int getThanksReceived() {
return thanksReceived;
}
public String getUser() {
return user;
}
}

View file

@ -0,0 +1,8 @@
package fr.free.nrw.commons.achievements
data class FeedbackResponse(val uniqueUsedImages: Int,
val articlesUsingImages: Int,
val deletedUploads: Int,
val featuredImages: FeaturedImages,
val thanksReceived: Int,
val user: String)

View file

@ -1,95 +0,0 @@
package fr.free.nrw.commons.achievements;
import fr.free.nrw.commons.R;
/**
* calculates the level of the user
*/
public class LevelController {
public LevelInfo level;
public enum LevelInfo{
LEVEL_1(1, R.style.LevelOne, 5, 20, 85),
LEVEL_2(2, R.style.LevelTwo, 10, 30, 86),
LEVEL_3(3, R.style.LevelThree, 15,40, 87),
LEVEL_4(4, R.style.LevelFour,20,50, 88),
LEVEL_5(5, R.style.LevelFive, 25, 60, 89),
LEVEL_6(6,R.style.LevelOne,30,70, 90),
LEVEL_7(7, R.style.LevelTwo, 40, 80, 90),
LEVEL_8(8, R.style.LevelThree, 45, 90, 90),
LEVEL_9(9, R.style.LevelFour, 50, 100, 90),
LEVEL_10(10, R.style.LevelFive, 55, 110, 90),
LEVEL_11(11,R.style.LevelOne, 60, 120, 90),
LEVEL_12(12,R.style.LevelTwo,65 , 130, 90),
LEVEL_13(13,R.style.LevelThree, 70, 140, 90),
LEVEL_14(14,R.style.LevelFour, 75 , 150, 90),
LEVEL_15(15,R.style.LevelFive, 80, 160, 90),
LEVEL_16(16,R.style.LevelOne, 160, 320, 91),
LEVEL_17(17,R.style.LevelTwo, 320, 640, 92),
LEVEL_18(18,R.style.LevelThree, 640, 1280, 93),
LEVEL_19(19,R.style.LevelFour, 1280, 2560, 94),
LEVEL_20(20,R.style.LevelFive, 2560, 5120, 95),
LEVEL_21(21,R.style.LevelOne, 5120, 10240, 96),
LEVEL_22(22,R.style.LevelTwo, 10240, 20480, 97),
LEVEL_23(23,R.style.LevelThree, 20480, 40960, 98),
LEVEL_24(24,R.style.LevelFour, 40960, 81920, 98),
LEVEL_25(25,R.style.LevelFive, 81920, 163840, 98),
LEVEL_26(26,R.style.LevelOne, 163840, 327680, 98),
LEVEL_27(27,R.style.LevelTwo, 327680, 655360, 98);
private int levelNumber;
private int levelStyle;
private int maxUniqueImages;
private int maxUploadCount;
private int minNonRevertPercentage;
LevelInfo(int levelNumber,
int levelStyle,
int maxUniqueImages,
int maxUploadCount,
int minNonRevertPercentage) {
this.levelNumber = levelNumber;
this.levelStyle = levelStyle;
this.maxUniqueImages = maxUniqueImages;
this.maxUploadCount = maxUploadCount;
this.minNonRevertPercentage = minNonRevertPercentage;
}
public static LevelInfo from(int imagesUploaded,
int uniqueImagesUsed,
int nonRevertRate) {
LevelInfo level = LEVEL_15;
for (LevelInfo levelInfo : LevelInfo.values()) {
if (imagesUploaded < levelInfo.maxUploadCount
|| uniqueImagesUsed < levelInfo.maxUniqueImages
|| nonRevertRate < levelInfo.minNonRevertPercentage ) {
level = levelInfo;
return level;
}
}
return level;
}
public int getLevelStyle() {
return levelStyle;
}
public int getLevelNumber() {
return levelNumber;
}
public int getMaxUniqueImages() {
return maxUniqueImages;
}
public int getMaxUploadCount() {
return maxUploadCount;
}
public int getMinNonRevertPercentage(){
return minNonRevertPercentage;
}
}
}

View file

@ -0,0 +1,35 @@
package fr.free.nrw.commons.achievements
import fr.free.nrw.commons.R
/**
* calculates the level of the user
*/
class LevelController {
var level: LevelInfo? = null
enum class LevelInfo(val levelNumber: Int,
val levelStyle: Int,
val maxUniqueImages: Int,
val maxUploadCount: Int,
val minNonRevertPercentage: Int) {
LEVEL_1(1, R.style.LevelOne, 5, 20, 85), LEVEL_2(2, R.style.LevelTwo, 10, 30, 86), LEVEL_3(3, R.style.LevelThree, 15, 40, 87), LEVEL_4(4, R.style.LevelFour, 20, 50, 88), LEVEL_5(5, R.style.LevelFive, 25, 60, 89), LEVEL_6(6, R.style.LevelOne, 30, 70, 90), LEVEL_7(7, R.style.LevelTwo, 40, 80, 90), LEVEL_8(8, R.style.LevelThree, 45, 90, 90), LEVEL_9(9, R.style.LevelFour, 50, 100, 90), LEVEL_10(10, R.style.LevelFive, 55, 110, 90), LEVEL_11(11, R.style.LevelOne, 60, 120, 90), LEVEL_12(12, R.style.LevelTwo, 65, 130, 90), LEVEL_13(13, R.style.LevelThree, 70, 140, 90), LEVEL_14(14, R.style.LevelFour, 75, 150, 90), LEVEL_15(15, R.style.LevelFive, 80, 160, 90), LEVEL_16(16, R.style.LevelOne, 160, 320, 91), LEVEL_17(17, R.style.LevelTwo, 320, 640, 92), LEVEL_18(18, R.style.LevelThree, 640, 1280, 93), LEVEL_19(19, R.style.LevelFour, 1280, 2560, 94), LEVEL_20(20, R.style.LevelFive, 2560, 5120, 95), LEVEL_21(21, R.style.LevelOne, 5120, 10240, 96), LEVEL_22(22, R.style.LevelTwo, 10240, 20480, 97), LEVEL_23(23, R.style.LevelThree, 20480, 40960, 98), LEVEL_24(24, R.style.LevelFour, 40960, 81920, 98), LEVEL_25(25, R.style.LevelFive, 81920, 163840, 98), LEVEL_26(26, R.style.LevelOne, 163840, 327680, 98), LEVEL_27(27, R.style.LevelTwo, 327680, 655360, 98);
companion object {
@JvmStatic
fun from(imagesUploaded: Int,
uniqueImagesUsed: Int,
nonRevertRate: Int): LevelInfo {
var level = LEVEL_15
for (levelInfo in values()) {
if (imagesUploaded < levelInfo.maxUploadCount || uniqueImagesUsed < levelInfo.maxUniqueImages || nonRevertRate < levelInfo.minNonRevertPercentage) {
level = levelInfo
return level
}
}
return level
}
}
}
}

View file

@ -1,41 +0,0 @@
package fr.free.nrw.commons.bookmarks;
import android.net.Uri;
public class Bookmark {
private Uri contentUri;
private String mediaName;
private String mediaCreator;
public Bookmark(String mediaName, String mediaCreator, Uri contentUri) {
this.contentUri = contentUri;
this.mediaName = mediaName == null ? "" : mediaName;
this.mediaCreator = mediaCreator == null ? "" : mediaCreator;
}
/**
* Gets the media name
* @return the media name
*/
public String getMediaName() {
return mediaName;
}
/**
* Gets media creator
* @return creator name
*/
public String getMediaCreator() { return mediaCreator; }
/**
* Gets the content URI for this bookmark
* @return content URI
*/
public Uri getContentUri() {
return contentUri;
}
}

View file

@ -0,0 +1,26 @@
package fr.free.nrw.commons.bookmarks
import android.net.Uri
class Bookmark(mediaName: String?, mediaCreator: String?,
/**
* Modifies the content URI - marking this bookmark as already saved in the database
* @param contentUri the content URI
*/
var contentUri: Uri?) {
/**
* Gets the content URI for this bookmark
* @return content URI
*/
/**
* Gets the media name
* @return the media name
*/
val mediaName: String = mediaName ?: ""
/**
* Gets media creator
* @return creator name
*/
val mediaCreator: String = mediaCreator ?: ""
}

View file

@ -1,55 +0,0 @@
package fr.free.nrw.commons.campaigns;
import com.google.gson.annotations.SerializedName;
/**
* A data class to hold a campaign
*/
public class Campaign {
@SerializedName("title") private String title;
@SerializedName("description") private String description;
@SerializedName("startDate") private String startDate;
@SerializedName("endDate") private String endDate;
@SerializedName("link") private String link;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
}

View file

@ -0,0 +1,10 @@
package fr.free.nrw.commons.campaigns
/**
* A data class to hold a campaign
*/
data class Campaign(var title: String? = null,
var description: String? = null,
var startDate: String? = null,
var endDate: String? = null,
var link: String? = null)

View file

@ -1,12 +0,0 @@
package fr.free.nrw.commons.campaigns;
import com.google.gson.annotations.SerializedName;
/**
* A data class to hold the campaign configs
*/
class CampaignConfig {
@SerializedName("showOnlyLiveCampaigns") private boolean showOnlyLiveCampaigns;
@SerializedName("sortBy") private String sortBy;
}

View file

@ -0,0 +1,13 @@
package fr.free.nrw.commons.campaigns
import com.google.gson.annotations.SerializedName
/**
* A data class to hold the campaign configs
*/
class CampaignConfig {
@SerializedName("showOnlyLiveCampaigns")
private val showOnlyLiveCampaigns = false
@SerializedName("sortBy")
private val sortBy: String? = null
}

View file

@ -1,25 +0,0 @@
package fr.free.nrw.commons.campaigns;
import com.google.gson.annotations.SerializedName;
import java.util.List;
/**
* Data class to hold the response from the campaigns api
*/
public class CampaignResponseDTO {
@SerializedName("config")
private CampaignConfig campaignConfig;
@SerializedName("campaigns")
private List<Campaign> campaigns;
public CampaignConfig getCampaignConfig() {
return campaignConfig;
}
public List<Campaign> getCampaigns() {
return campaigns;
}
}

View file

@ -0,0 +1,14 @@
package fr.free.nrw.commons.campaigns
import com.google.gson.annotations.SerializedName
/**
* Data class to hold the response from the campaigns api
*/
class CampaignResponseDTO {
@SerializedName("config")
val campaignConfig: CampaignConfig? = null
@SerializedName("campaigns")
val campaigns: List<Campaign>? = null
}

View file

@ -1,24 +0,0 @@
package fr.free.nrw.commons.category;
/**
* For APIs that return paginated responses, MediaWiki APIs uses the QueryContinue to facilitate fetching of subsequent pages
* https://www.mediawiki.org/wiki/API:Raw_query_continue
*/
public class QueryContinue {
private String continueParam;
private String gcmContinueParam;
public QueryContinue(String continueParam, String gcmContinueParam) {
this.continueParam = continueParam;
this.gcmContinueParam = gcmContinueParam;
}
public String getGcmContinueParam() {
return gcmContinueParam;
}
public String getContinueParam() {
return continueParam;
}
}

View file

@ -1,71 +0,0 @@
package fr.free.nrw.commons.explore.recentsearches;
import android.net.Uri;
import java.util.Date;
/**
* Represents a recently searched query
* Example - query = "butterfly"
*/
public class RecentSearch {
private Uri contentUri;
private String query;
private Date lastSearched;
/**
* Constructor
* @param contentUri the content URI for this query
* @param query query name
* @param lastSearched last searched date
*/
public RecentSearch(Uri contentUri, String query, Date lastSearched) {
this.contentUri = contentUri;
this.query = query;
this.lastSearched = lastSearched;
}
/**
* Gets query name
* @return query name
*/
public String getQuery() {
return query;
}
/**
* Gets last searched date
* @return Last searched date
*/
public Date getLastSearched() {
// warning: Date objects are mutable.
return (Date)lastSearched.clone();
}
/**
* Updates the last searched date
* @param lastSearched Last searched date
*/
public void setLastSearched(Date lastSearched) {
this.lastSearched = lastSearched;
}
/**
* Gets the content URI for this query
* @return content URI
*/
public Uri getContentUri() {
return contentUri;
}
/**
* Modifies the content URI - marking this query as already saved in the database
*
* @param contentUri the content URI
*/
public void setContentUri(Uri contentUri) {
this.contentUri = contentUri;
}
}

View file

@ -0,0 +1,29 @@
package fr.free.nrw.commons.explore.recentsearches
import android.net.Uri
import java.util.*
/**
* Represents a recently searched query
* Example - query = "butterfly"
*/
class RecentSearch
/**
* Constructor
* @param contentUri the content URI for this query
* @param query query name
* @param lastSearched last searched date
*/(
/**
* Modifies the content URI - marking this query as already saved in the database
*
* @param contentUri the content URI
*/
var contentUri: Uri?,
/**
* Gets query name
* @return query name
*/
val query: String, var lastSearched: Date) {
}

View file

@ -58,9 +58,7 @@ class PickedFiles implements Constants {
}
static void copyFilesInSeparateThread(final Context context, final List<UploadableFile> filesToCopy) {
new Thread(new Runnable() {
@Override
public void run() {
new Thread(() -> {
List<File> copiedFiles = new ArrayList<>();
int i = 1;
for (UploadableFile uploadableFile : filesToCopy) {
@ -83,7 +81,6 @@ class PickedFiles implements Constants {
i++;
}
scanCopiedImages(context, copiedFiles);
}
}).run();
}

View file

@ -6,6 +6,16 @@ import androidx.annotation.NonNull;
import com.google.gson.Gson;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import javax.inject.Inject;
import javax.inject.Singleton;
import fr.free.nrw.commons.achievements.FeaturedImages;
import fr.free.nrw.commons.achievements.FeedbackResponse;
import fr.free.nrw.commons.campaigns.CampaignResponseDTO;
@ -18,23 +28,11 @@ import fr.free.nrw.commons.utils.ConfigUtils;
import fr.free.nrw.commons.wikidata.model.GetWikidataEditCountResponse;
import io.reactivex.Observable;
import io.reactivex.Single;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import javax.inject.Inject;
import javax.inject.Singleton;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.apache.commons.lang3.StringUtils;
import timber.log.Timber;
/**

View file

@ -1,13 +0,0 @@
package fr.free.nrw.commons.nearby.model;
public class NearbyResponse {
private final NearbyResults results;
public NearbyResponse(NearbyResults results) {
this.results = results;
}
public NearbyResults getResults() {
return results;
}
}

View file

@ -0,0 +1,3 @@
package fr.free.nrw.commons.nearby.model
class NearbyResponse(val results: NearbyResults)

View file

@ -1,82 +0,0 @@
package fr.free.nrw.commons.nearby.model;
import com.google.gson.annotations.SerializedName;
public class NearbyResultItem {
private final ResultTuple item;
private final ResultTuple wikipediaArticle;
private final ResultTuple commonsArticle;
private final ResultTuple location;
private final ResultTuple label;
private final ResultTuple icon;
@SerializedName("class") private final ResultTuple className;
@SerializedName("classLabel") private final ResultTuple classLabel;
@SerializedName("commonsCategory") private final ResultTuple commonsCategory;
@SerializedName("pic") private final ResultTuple pic;
@SerializedName("destroyed") private final ResultTuple destroyed;
public NearbyResultItem(ResultTuple item,
ResultTuple wikipediaArticle,
ResultTuple commonsArticle,
ResultTuple location,
ResultTuple label,
ResultTuple icon, ResultTuple className,
ResultTuple classLabel,
ResultTuple commonsCategory,
ResultTuple pic,
ResultTuple destroyed) {
this.item = item;
this.wikipediaArticle = wikipediaArticle;
this.commonsArticle = commonsArticle;
this.location = location;
this.label = label;
this.icon = icon;
this.className = className;
this.classLabel = classLabel;
this.commonsCategory = commonsCategory;
this.pic = pic;
this.destroyed = destroyed;
}
public ResultTuple getItem() {
return item == null ? new ResultTuple(): item;
}
public ResultTuple getWikipediaArticle() {
return wikipediaArticle == null ? new ResultTuple():wikipediaArticle;
}
public ResultTuple getCommonsArticle() {
return commonsArticle == null ? new ResultTuple():commonsArticle;
}
public ResultTuple getLocation() {
return location == null ? new ResultTuple():location;
}
public ResultTuple getLabel() {
return label == null ? new ResultTuple():label;
}
public ResultTuple getIcon() {
return icon == null ? new ResultTuple():icon;
}
public ResultTuple getClassName() {
return className == null ? new ResultTuple():className;
}
public ResultTuple getClassLabel() {
return classLabel == null ? new ResultTuple():classLabel;
}
public ResultTuple getCommonsCategory() {
return commonsCategory == null ? new ResultTuple():commonsCategory;
}
public ResultTuple getPic() {
return pic == null ? new ResultTuple():pic;
}
public ResultTuple getDestroyed() {
return destroyed == null ? new ResultTuple(): destroyed;
}
}

View file

@ -0,0 +1,60 @@
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?,
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?) {
fun getItem(): ResultTuple {
return item ?: ResultTuple()
}
fun getWikipediaArticle(): ResultTuple {
return wikipediaArticle ?: ResultTuple()
}
fun getCommonsArticle(): ResultTuple {
return commonsArticle ?: ResultTuple()
}
fun getLocation(): ResultTuple {
return location ?: ResultTuple()
}
fun getLabel(): ResultTuple {
return label ?: ResultTuple()
}
fun getIcon(): ResultTuple {
return icon ?: ResultTuple()
}
fun getClassName(): ResultTuple {
return className ?: ResultTuple()
}
fun getClassLabel(): ResultTuple {
return classLabel ?: ResultTuple()
}
fun getCommonsCategory(): ResultTuple {
return commonsCategory ?: ResultTuple()
}
fun getPic(): ResultTuple {
return pic ?: ResultTuple()
}
fun getDestroyed(): ResultTuple {
return destroyed ?: ResultTuple()
}
}

View file

@ -1,15 +0,0 @@
package fr.free.nrw.commons.nearby.model;
import java.util.List;
public class NearbyResults {
private final List<NearbyResultItem> bindings;
public NearbyResults(List<NearbyResultItem> bindings) {
this.bindings = bindings;
}
public List<NearbyResultItem> getBindings() {
return bindings;
}
}

View file

@ -0,0 +1,3 @@
package fr.free.nrw.commons.nearby.model
class NearbyResults(val bindings: List<NearbyResultItem>)

View file

@ -1,24 +0,0 @@
package fr.free.nrw.commons.nearby.model;
public class ResultTuple {
private final String type;
private final String value;
public ResultTuple(String type, String value) {
this.type = type;
this.value = value;
}
public ResultTuple() {
this.type = "";
this.value = "";
}
public String getType() {
return type;
}
public String getValue() {
return value;
}
}

View file

@ -0,0 +1,17 @@
package fr.free.nrw.commons.nearby.model
class ResultTuple {
val type: String
val value: String
constructor(type: String, value: String) {
this.type = type
this.value = value
}
constructor() {
type = ""
value = ""
}
}

View file

@ -1,16 +0,0 @@
package fr.free.nrw.commons.notification;
import androidx.annotation.Nullable;
public class MarkReadResponse {
@SuppressWarnings("unused") @Nullable
private String result;
public String result() {
return result;
}
public static class QueryMarkReadResponse {
@SuppressWarnings("unused") @Nullable private MarkReadResponse echomarkread;
}
}

View file

@ -1,54 +0,0 @@
package fr.free.nrw.commons.notification;
import org.wikipedia.util.DateUtil;
/**
* Created by root on 18.12.2017.
*/
public class Notification {
public NotificationType notificationType;
public String notificationText;
public String date;
public String link;
public String iconUrl;
public String notificationId;
public Notification(NotificationType notificationType,
String notificationText,
String date,
String link,
String iconUrl,
String notificationId) {
this.notificationType = notificationType;
this.notificationText = notificationText;
this.date = date;
this.link = link;
this.iconUrl = iconUrl;
this.notificationId=notificationId;
}
public static Notification from(org.wikipedia.notifications.Notification wikiNotification) {
org.wikipedia.notifications.Notification.Contents contents = wikiNotification.getContents();
String notificationLink = contents == null || contents.getLinks() == null
|| contents.getLinks().getPrimary() == null ? "" : contents.getLinks().getPrimary().getUrl();
return new Notification(NotificationType.UNKNOWN,
contents == null ? "" : contents.getCompactHeader(),
DateUtil.getMonthOnlyDateString(wikiNotification.getTimestamp()),
notificationLink,
"",
String.valueOf(wikiNotification.id()));
}
@Override
public String toString() {
return "Notification" +
"notificationType='" + notificationType + '\'' +
", notificationText='" + notificationText + '\'' +
", date='" + date + '\'' +
", link='" + link + '\'' +
", iconUrl='" + iconUrl + '\'' +
", notificationId='" + notificationId + '\'' +
'}';
}
}

View file

@ -0,0 +1,38 @@
package fr.free.nrw.commons.notification
import org.wikipedia.util.DateUtil
/**
* Created by root on 18.12.2017.
*/
data class Notification(var notificationType: NotificationType,
var notificationText: String,
var date: String,
var link: String,
var iconUrl: String,
var notificationId: String) {
override fun toString(): String {
return "Notification" +
"notificationType='" + notificationType + '\'' +
", notificationText='" + notificationText + '\'' +
", date='" + date + '\'' +
", link='" + link + '\'' +
", iconUrl='" + iconUrl + '\'' +
", notificationId='" + notificationId + '\'' +
'}'
}
companion object {
@JvmStatic
fun from(wikiNotification: org.wikipedia.notifications.Notification): Notification {
val contents = wikiNotification.contents
val notificationLink = if (contents == null || contents.links == null || contents.links!!.primary == null) "" else contents.links!!.primary!!.url
return Notification(NotificationType.UNKNOWN,
contents?.compactHeader ?: "",
DateUtil.getMonthOnlyDateString(wikiNotification.timestamp),
notificationLink,
"", wikiNotification.id().toString())
}
}
}

View file

@ -225,14 +225,14 @@ public class NotificationActivity extends NavigationBaseActivity {
notificationAdapterFactory = new NotificationAdapterFactory(new NotificationRenderer.NotificationClicked() {
@Override
public void notificationClicked(Notification notification) {
Timber.d("Notification clicked %s", notification.link);
handleUrl(notification.link);
Timber.d("Notification clicked %s", notification.getLink());
handleUrl(notification.getLink());
removeNotification(notification);
}
@Override
public void markNotificationAsRead(Notification notification) {
Timber.d("Notification to mark as read %s", notification.notificationId);
Timber.d("Notification to mark as read %s", notification.getNotificationId());
removeNotification(notification);
}
}, isarchivedvisible);

View file

@ -27,6 +27,6 @@ public class NotificationController {
}
Observable<Boolean> markAsRead(Notification notification) {
return notificationClient.markNotificationAsRead(notification.notificationId);
return notificationClient.markNotificationAsRead(notification.getNotificationId());
}
}

View file

@ -63,8 +63,8 @@ public class NotificationRenderer extends Renderer<Notification> {
@Override
public void render() {
Notification notification = getContent();
setTitle(notification.notificationText);
time.setText(notification.date);
setTitle(notification.getNotificationText());
time.setText(notification.getDate());
}
/**

View file

@ -1,62 +0,0 @@
package fr.free.nrw.commons.quiz;
import android.net.Uri;
/**
* class contains information about all the quiz questions
*/
public class QuizQuestion {
private int questionNumber;
private String question;
private boolean answer;
private String url;
private String answerMessage;
QuizQuestion(int questionNumber, String question, String url, boolean answer, String answerMessage){
this.questionNumber = questionNumber;
this.question = question;
this.url = url;
this.answer = answer;
this.answerMessage = answerMessage;
}
public Uri getUrl() {
return Uri.parse(url);
}
public void setUrl(String url) {
this.url = url;
}
public boolean isAnswer() {
return answer;
}
public int getQuestionNumber() {
return questionNumber;
}
public String getQuestion() {
return question;
}
public void setAnswer(boolean answer) {
this.answer = answer;
}
public void setQuestion(String question) {
this.question = question;
}
public void setQuestionNumber(int questionNumber) {
this.questionNumber = questionNumber;
}
public String getAnswerMessage() {
return answerMessage;
}
public void setAnswerMessage(String answerMessage) {
this.answerMessage = answerMessage;
}
}

View file

@ -0,0 +1,17 @@
package fr.free.nrw.commons.quiz
import android.net.Uri
/**
* class contains information about all the quiz questions
*/
class QuizQuestion internal constructor(var questionNumber: Int, var question: String, private var url: String, var isAnswer: Boolean, var answerMessage: String) {
fun getUrl(): Uri {
return Uri.parse(url)
}
fun setUrl(url: String) {
this.url = url
}
}

View file

@ -1,87 +0,0 @@
package fr.free.nrw.commons.upload;
import java.io.IOException;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okio.Buffer;
import okio.BufferedSink;
import okio.ForwardingSink;
import okio.Okio;
import okio.Sink;
/**
* Decorates an OkHttp request body to count the number of bytes written when writing it. Can
* decorate any request body, but is most useful for tracking the upload progress of large multipart
* requests.
*
* @author Ashish Kumar
*/
public class CountingRequestBody extends RequestBody {
protected RequestBody delegate;
protected Listener listener;
protected CountingSink countingSink;
public CountingRequestBody(RequestBody delegate, Listener listener) {
this.delegate = delegate;
this.listener = listener;
}
@Override
public MediaType contentType() {
return delegate.contentType();
}
@Override
public long contentLength() {
try {
return delegate.contentLength();
} catch (IOException e) {
e.printStackTrace();
}
return -1;
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
countingSink = new CountingSink(sink);
BufferedSink bufferedSink = Okio.buffer(countingSink);
delegate.writeTo(bufferedSink);
bufferedSink.flush();
}
protected final class CountingSink extends ForwardingSink {
private long bytesWritten = 0;
public CountingSink(Sink delegate) {
super(delegate);
}
@Override
public void write(Buffer source, long byteCount) throws IOException {
super.write(source, byteCount);
bytesWritten += byteCount;
listener.onRequestProgress(bytesWritten, contentLength());
}
}
public interface Listener {
/**
* Will be triggered when write progresses
* @param bytesWritten
* @param contentLength
*/
void onRequestProgress(long bytesWritten, long contentLength);
}
}

View file

@ -0,0 +1,57 @@
package fr.free.nrw.commons.upload
import okhttp3.MediaType
import okhttp3.RequestBody
import okio.*
import java.io.IOException
/**
* Decorates an OkHttp request body to count the number of bytes written when writing it. Can
* decorate any request body, but is most useful for tracking the upload progress of large multipart
* requests.
*
* @author Ashish Kumar
*/
class CountingRequestBody(protected var delegate: RequestBody, protected var listener: Listener) : RequestBody() {
protected var countingSink: CountingSink? = null
override fun contentType(): MediaType? {
return delegate.contentType()
}
override fun contentLength(): Long {
try {
return delegate.contentLength()
} catch (e: IOException) {
e.printStackTrace()
}
return -1
}
@Throws(IOException::class)
override fun writeTo(sink: BufferedSink) {
countingSink = CountingSink(sink)
val bufferedSink = countingSink!!.buffer()
delegate.writeTo(bufferedSink)
bufferedSink.flush()
}
protected inner class CountingSink(delegate: Sink?) : ForwardingSink(delegate!!) {
private var bytesWritten: Long = 0
@Throws(IOException::class)
override fun write(source: Buffer, byteCount: Long) {
super.write(source, byteCount)
bytesWritten += byteCount
listener.onRequestProgress(bytesWritten, contentLength())
}
}
interface Listener {
/**
* Will be triggered when write progresses
* @param bytesWritten
* @param contentLength
*/
fun onRequestProgress(bytesWritten: Long, contentLength: Long)
}
}

View file

@ -1,88 +0,0 @@
package fr.free.nrw.commons.upload;
import java.util.List;
/**
* Holds a description of an item being uploaded by {@link UploadActivity}
*/
public class Description {
private String languageCode;
private String descriptionText;
private int selectedLanguageIndex = -1;
private boolean isManuallyAdded=false;
/**
* @return The language code ie. "en" or "fr"
*/
String getLanguageCode() {
return languageCode;
}
/**
* @param languageCode The language code ie. "en" or "fr"
*/
void setLanguageCode(String languageCode) {
this.languageCode = languageCode;
}
String getDescriptionText() {
return descriptionText;
}
void setDescriptionText(String descriptionText) {
this.descriptionText = descriptionText;
}
/**
* @return the index of the language selected in a spinner with {@link SpinnerLanguagesAdapter}
*/
int getSelectedLanguageIndex() {
return selectedLanguageIndex;
}
/**
* @param selectedLanguageIndex the index of the language selected in a spinner with {@link SpinnerLanguagesAdapter}
*/
void setSelectedLanguageIndex(int selectedLanguageIndex) {
this.selectedLanguageIndex = selectedLanguageIndex;
}
/**
* returns if the description was added manually (by the user, or we have added it programaticallly)
* @return
*/
public boolean isManuallyAdded() {
return isManuallyAdded;
}
/**
* sets to true if the description was manually added by the user
* @param manuallyAdded
*/
public void setManuallyAdded(boolean manuallyAdded) {
isManuallyAdded = manuallyAdded;
}
/**
* Formats the list of descriptions into the format Commons requires for uploads.
*
* @param descriptions the list of descriptions, description is ignored if text is null.
* @return a string with the pattern of {{en|1=descriptionText}}
*/
static String formatList(List<Description> descriptions) {
StringBuilder descListString = new StringBuilder();
for (Description description : descriptions) {
if (!description.isEmpty()) {
String individualDescription = String.format("{{%s|1=%s}}", description.getLanguageCode(),
description.getDescriptionText());
descListString.append(individualDescription);
}
}
return descListString.toString();
}
public boolean isEmpty() {
return descriptionText == null || descriptionText.isEmpty();
}
}

View file

@ -0,0 +1,55 @@
package fr.free.nrw.commons.upload
/**
* Holds a description of an item being uploaded by [UploadActivity]
*/
class Description {
/**
* @return The language code ie. "en" or "fr"
*/
/**
* @param languageCode The language code ie. "en" or "fr"
*/
var languageCode: String? = null
var descriptionText: String? = null
/**
* @return the index of the language selected in a spinner with [SpinnerLanguagesAdapter]
*/
/**
* @param selectedLanguageIndex the index of the language selected in a spinner with [SpinnerLanguagesAdapter]
*/
var selectedLanguageIndex = -1
/**
* returns if the description was added manually (by the user, or we have added it programaticallly)
* @return
*/
/**
* sets to true if the description was manually added by the user
* @param manuallyAdded
*/
var isManuallyAdded = false
val isEmpty: Boolean
get() = descriptionText == null || descriptionText!!.isEmpty()
companion object {
/**
* Formats the list of descriptions into the format Commons requires for uploads.
*
* @param descriptions the list of descriptions, description is ignored if text is null.
* @return a string with the pattern of {{en|1=descriptionText}}
*/
@JvmStatic
fun formatList(descriptions: List<Description>): String {
val descListString = StringBuilder()
for (description in descriptions) {
if (!description.isEmpty) {
val individualDescription = String.format("{{%s|1=%s}}", description.languageCode,
description.descriptionText)
descListString.append(individualDescription)
}
}
return descListString.toString()
}
}
}

View file

@ -126,8 +126,7 @@ public class DescriptionsAdapter extends RecyclerView.Adapter<DescriptionsAdapte
}
descItemEditText.addTextChangedListener(new AbstractTextWatcher(
descriptionText -> descriptions.get(position)
.setDescriptionText(descriptionText)));
descriptionText -> descriptions.get(position).setDescriptionText(descriptionText)));
initLanguageSpinner(position, description);
//If the description was manually added by the user, it deserves focus, if not, let the user decide

View file

@ -1,28 +0,0 @@
package fr.free.nrw.commons.upload;
import java.util.Locale;
public class Language {
private Locale locale;
private boolean isSet = false;
public Language(Locale locale) {
this.locale = locale;
}
public Locale getLocale() {
return locale;
}
public void setLocale(Locale locale) {
this.locale = locale;
}
public boolean isSet() {
return isSet;
}
public void setSet(boolean set) {
isSet = set;
}
}

View file

@ -0,0 +1,8 @@
package fr.free.nrw.commons.upload
import java.util.*
class Language(var locale: Locale) {
var isSet = false
}

View file

@ -1,38 +0,0 @@
package fr.free.nrw.commons.upload;
import android.text.TextUtils;
public class Title{
private String titleText;
private boolean set;
@Override
public String toString() {
return titleText;
}
public void setTitleText(String titleText) {
this.titleText = titleText;
if (!TextUtils.isEmpty(titleText)) {
set = true;
}
}
public boolean isSet() {
return set;
}
public void setSet(boolean set) {
this.set = set;
}
public boolean isEmpty() {
return titleText==null || titleText.isEmpty();
}
public String getTitleText() {
return titleText;
}
}

View file

@ -0,0 +1,29 @@
package fr.free.nrw.commons.upload
import android.text.TextUtils
class Title {
private var titleText: String? = null
var isSet = false
override fun toString(): String {
if (titleText == null) {
return ""
} else {
return titleText!!
}
}
fun setTitleText(titleText: String?) {
this.titleText = titleText
if (!TextUtils.isEmpty(titleText)) {
isSet = true
}
}
val isEmpty: Boolean
get() = titleText == null || titleText!!.isEmpty()
fun getTitleText(): String? {
return titleText
}
}

View file

@ -1,13 +0,0 @@
package fr.free.nrw.commons.upload;
public class UploadResponse {
private final UploadResult upload;
public UploadResponse(UploadResult upload) {
this.upload = upload;
}
public UploadResult getUpload() {
return upload;
}
}

View file

@ -0,0 +1,3 @@
package fr.free.nrw.commons.upload
class UploadResponse(val upload: UploadResult)

View file

@ -1,39 +0,0 @@
package fr.free.nrw.commons.upload;
import org.wikipedia.gallery.ImageInfo;
public class UploadResult {
private final String result;
private final String filekey;
private final String filename;
private final String sessionkey;
private final ImageInfo imageinfo;
public UploadResult(String result, String filekey, String filename, String sessionkey, ImageInfo imageinfo) {
this.result = result;
this.filekey = filekey;
this.filename = filename;
this.sessionkey = sessionkey;
this.imageinfo = imageinfo;
}
public String getResult() {
return result;
}
public String getFilekey() {
return filekey;
}
public String getSessionkey() {
return sessionkey;
}
public ImageInfo getImageinfo() {
return imageinfo;
}
public String getFilename() {
return filename;
}
}

View file

@ -0,0 +1,5 @@
package fr.free.nrw.commons.upload
import org.wikipedia.gallery.ImageInfo
class UploadResult(val result: String, val filekey: String, val filename: String, val sessionkey: String, val imageinfo: ImageInfo)

View file

@ -1,16 +0,0 @@
package fr.free.nrw.commons.utils.model;
public enum ConnectionType {
WIFI_NETWORK("wifi"), CELLULAR_4G("cellular-4g"), CELLULAR_3G("cellular-3g"), CELLULAR("cellular"), NO_INTERNET("no-internet");
private final String text;
ConnectionType(String text) {
this.text = text;
}
@Override
public String toString() {
return text;
}
}

View file

@ -0,0 +1,9 @@
package fr.free.nrw.commons.utils.model
enum class ConnectionType(private val text: String) {
WIFI_NETWORK("wifi"), CELLULAR_4G("cellular-4g"), CELLULAR_3G("cellular-3g"), CELLULAR("cellular"), NO_INTERNET("no-internet");
override fun toString(): String {
return text
}
}

View file

@ -1,25 +0,0 @@
package fr.free.nrw.commons.wikidata.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.List;
/**
* Response class for add edit tag
*/
public class AddEditTagResponse {
@SerializedName("tag")
@Expose
private List<EditTag> tag = null;
public List<EditTag> getTag() {
return tag;
}
public void setTag(List<EditTag> tag) {
this.tag = tag;
}
}

View file

@ -0,0 +1,13 @@
package fr.free.nrw.commons.wikidata.model
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName
/**
* Response class for add edit tag
*/
class AddEditTagResponse {
@SerializedName("tag")
@Expose
var tag: List<EditTag>? = null
}

View file

@ -1,56 +0,0 @@
package fr.free.nrw.commons.wikidata.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.List;
/**
* Tag class used when adding wikidata edit tag
*/
public class EditTag {
@SerializedName("revid")
@Expose
private Integer revid;
@SerializedName("status")
@Expose
private String status;
@SerializedName("actionlogid")
@Expose
private Integer actionlogid;
@SerializedName("added")
@Expose
private List<String> added;
@SerializedName("removed")
@Expose
private List<Object> removed;
public EditTag(Integer revid, String status, Integer actionlogid, List<String> added, List<Object> removed) {
this.revid = revid;
this.status = status;
this.actionlogid = actionlogid;
this.added = added;
this.removed = removed;
}
public Integer getRevid() {
return revid;
}
public String getStatus() {
return status;
}
public Integer getActionlogid() {
return actionlogid;
}
public List<String> getAdded() {
return added;
}
public List<Object> getRemoved() {
return removed;
}
}

View file

@ -0,0 +1,9 @@
package fr.free.nrw.commons.wikidata.model
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName
/**
* Tag class used when adding wikidata edit tag
*/
class EditTag(@field:Expose @field:SerializedName("revid") val revid: Int, @field:Expose @field:SerializedName("status") val status: String, @field:Expose @field:SerializedName("actionlogid") val actionlogid: Int, @field:Expose @field:SerializedName("added") val added: List<String>, @field:Expose @field:SerializedName("removed") val removed: List<Any>)

View file

@ -1,16 +0,0 @@
package fr.free.nrw.commons.wikidata.model;
import com.google.gson.annotations.SerializedName;
public class GetWikidataEditCountResponse {
@SerializedName("edits")
private final int wikidataEditCount;
public GetWikidataEditCountResponse(int wikidataEditCount) {
this.wikidataEditCount = wikidataEditCount;
}
public int getWikidataEditCount() {
return wikidataEditCount;
}
}

View file

@ -0,0 +1,5 @@
package fr.free.nrw.commons.wikidata.model
import com.google.gson.annotations.SerializedName
class GetWikidataEditCountResponse(@field:SerializedName("edits") val wikidataEditCount: Int)

View file

@ -1,21 +0,0 @@
package fr.free.nrw.commons.wikidata.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* PageInfo model class with last revision id of the edited Wikidata entity
*/
public class PageInfo {
@SerializedName("lastrevid")
@Expose
private Long lastrevid;
public PageInfo(Long lastrevid) {
this.lastrevid = lastrevid;
}
public Long getLastrevid() {
return lastrevid;
}
}

View file

@ -0,0 +1,9 @@
package fr.free.nrw.commons.wikidata.model
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName
/**
* PageInfo model class with last revision id of the edited Wikidata entity
*/
class PageInfo(@field:Expose @field:SerializedName("lastrevid") val lastrevid: Long)

View file

@ -1,30 +0,0 @@
package fr.free.nrw.commons.wikidata.model;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* Wikidata create claim response model class
*/
public class WbCreateClaimResponse {
@SerializedName("pageinfo")
@Expose
private PageInfo pageinfo;
@SerializedName("success")
@Expose
private Integer success;
public WbCreateClaimResponse(PageInfo pageinfo, Integer success) {
this.pageinfo = pageinfo;
this.success = success;
}
public PageInfo getPageinfo() {
return pageinfo;
}
public Integer getSuccess() {
return success;
}
}

View file

@ -0,0 +1,9 @@
package fr.free.nrw.commons.wikidata.model
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName
/**
* Wikidata create claim response model class
*/
class WbCreateClaimResponse(@field:Expose @field:SerializedName("pageinfo") val pageinfo: PageInfo, @field:Expose @field:SerializedName("success") val success: Int)

View file

@ -4,7 +4,7 @@ import android.content.ContentProviderClient
import android.content.Context
import androidx.collection.LruCache
import com.google.gson.Gson
import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockitokotlin2.mock
import com.squareup.leakcanary.RefWatcher
import fr.free.nrw.commons.auth.AccountUtil
import fr.free.nrw.commons.data.DBOpenHelper

View file

@ -1,7 +1,7 @@
package fr.free.nrw.commons.actions
import com.nhaarman.mockito_kotlin.eq
import com.nhaarman.mockito_kotlin.verify
import com.nhaarman.mockitokotlin2.eq
import com.nhaarman.mockitokotlin2.verify
import org.junit.Before
import org.junit.Test
import org.mockito.Mock

View file

@ -1,7 +1,7 @@
package fr.free.nrw.commons.actions
import com.nhaarman.mockito_kotlin.eq
import com.nhaarman.mockito_kotlin.verify
import com.nhaarman.mockitokotlin2.eq
import com.nhaarman.mockitokotlin2.verify
import fr.free.nrw.commons.CommonsApplication
import org.junit.Before
import org.junit.Test

View file

@ -1,13 +1,12 @@
package fr.free.nrw.commons.auth
import com.nhaarman.mockito_kotlin.verify
import com.nhaarman.mockitokotlin2.verify
import io.reactivex.Observable
import org.junit.Before
import org.junit.Test
import org.mockito.ArgumentMatchers.anyString
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito.*
import org.mockito.MockitoAnnotations
import org.wikipedia.dataclient.Service
@ -29,8 +28,8 @@ class LogoutClientTest {
@Throws(Exception::class)
fun setUp() {
MockitoAnnotations.initMocks(this)
val mwQueryResponse = Mockito.mock(MwQueryResponse::class.java)
val mwQueryResult = Mockito.mock(MwQueryResult::class.java)
val mwQueryResponse = mock(MwQueryResponse::class.java)
val mwQueryResult = mock(MwQueryResult::class.java)
`when`(mwQueryResult!!.csrfToken()).thenReturn("test_token")
`when`(mwQueryResponse.query()).thenReturn(mwQueryResult)
`when`(service!!.csrfToken)

View file

@ -7,8 +7,7 @@ import android.database.MatrixCursor
import android.database.sqlite.SQLiteDatabase
import android.net.Uri
import android.os.RemoteException
import com.nhaarman.mockito_kotlin.*
import fr.free.nrw.commons.BuildConfig
import com.nhaarman.mockitokotlin2.*
import fr.free.nrw.commons.TestCommonsApplication
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsContentProvider.BASE_URI
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao.Table.*

View file

@ -7,7 +7,7 @@ import android.database.MatrixCursor
import android.database.sqlite.SQLiteDatabase
import android.net.Uri
import android.os.RemoteException
import com.nhaarman.mockito_kotlin.*
import com.nhaarman.mockitokotlin2.*
import fr.free.nrw.commons.BuildConfig
import fr.free.nrw.commons.TestCommonsApplication
import fr.free.nrw.commons.bookmarks.Bookmark

View file

@ -14,13 +14,11 @@ import java.util.List;
import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.bookmarks.Bookmark;
import fr.free.nrw.commons.media.MediaClient;
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
import io.reactivex.Single;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

View file

@ -2,13 +2,13 @@ package fr.free.nrw.commons.cache
import com.github.varunpant.quadtree.Point
import com.github.varunpant.quadtree.QuadTree
import com.nhaarman.mockito_kotlin.verify
import fr.free.nrw.commons.caching.CacheController
import org.junit.Before
import org.junit.Test
import org.mockito.ArgumentMatchers
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations
class CacheControllerTest {

View file

@ -1,6 +1,6 @@
package fr.free.nrw.commons.campaigns
import com.nhaarman.mockito_kotlin.verify
import com.nhaarman.mockitokotlin2.verify
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient
import io.reactivex.Single
import io.reactivex.schedulers.TestScheduler

View file

@ -6,7 +6,7 @@ import android.database.Cursor
import android.database.MatrixCursor
import android.database.sqlite.SQLiteDatabase
import android.os.RemoteException
import com.nhaarman.mockito_kotlin.*
import com.nhaarman.mockitokotlin2.*
import fr.free.nrw.commons.BuildConfig
import fr.free.nrw.commons.TestCommonsApplication
import fr.free.nrw.commons.category.CategoryContentProvider.BASE_URI

View file

@ -6,7 +6,7 @@ import android.database.MatrixCursor
import android.database.sqlite.SQLiteDatabase
import android.net.Uri
import android.os.RemoteException
import com.nhaarman.mockito_kotlin.*
import com.nhaarman.mockitokotlin2.*
import fr.free.nrw.commons.BuildConfig
import fr.free.nrw.commons.TestCommonsApplication
import fr.free.nrw.commons.Utils

View file

@ -3,7 +3,7 @@ package fr.free.nrw.commons.contributions
import android.database.Cursor
import androidx.loader.content.CursorLoader
import androidx.loader.content.Loader
import com.nhaarman.mockito_kotlin.verify
import com.nhaarman.mockitokotlin2.verify
import org.junit.Before
import org.junit.Test
import org.mockito.Mock

View file

@ -2,7 +2,6 @@ package fr.free.nrw.commons.delete
import android.content.Context
import android.content.res.Resources
import com.nhaarman.mockito_kotlin.verify
import fr.free.nrw.commons.Media
import fr.free.nrw.commons.achievements.FeedbackResponse
import fr.free.nrw.commons.auth.SessionManager
@ -14,6 +13,7 @@ import org.junit.Test
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito.*
import org.mockito.MockitoAnnotations
import java.util.*

View file

@ -6,7 +6,7 @@ import android.database.Cursor
import android.database.MatrixCursor
import android.database.sqlite.SQLiteDatabase
import android.os.RemoteException
import com.nhaarman.mockito_kotlin.*
import com.nhaarman.mockitokotlin2.*
import fr.free.nrw.commons.BuildConfig
import fr.free.nrw.commons.TestCommonsApplication
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesContentProvider.BASE_URI

View file

@ -1,10 +1,10 @@
package fr.free.nrw.commons.notification
import com.nhaarman.mockito_kotlin.eq
import io.reactivex.Observable
import org.junit.Before
import org.junit.Test
import org.mockito.ArgumentMatchers
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito.verify

View file

@ -1,11 +1,12 @@
package fr.free.nrw.commons.notification
import com.nhaarman.mockito_kotlin.verify
import org.junit.Before
import org.junit.Test
import org.mockito.ArgumentMatchers
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mock
import org.mockito.Mockito.`when`
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations
class NotificationControllerTest {
@ -40,7 +41,7 @@ class NotificationControllerTest {
*/
@Test
fun testMarkNotificationsAsRead() {
notification.notificationId = "test"
`when`(notification.notificationId).thenReturn("test")
notificationController.markAsRead(notification)
verify(notificationClient).markNotificationAsRead(eq("test"))
}

View file

@ -1,6 +1,6 @@
package fr.free.nrw.commons.upload
import com.nhaarman.mockito_kotlin.verify
import com.nhaarman.mockitokotlin2.verify
import fr.free.nrw.commons.category.CategoryItem
import fr.free.nrw.commons.repository.UploadRepository
import fr.free.nrw.commons.upload.categories.CategoriesContract

View file

@ -1,6 +1,6 @@
package fr.free.nrw.commons.upload
import com.nhaarman.mockito_kotlin.verify
import com.nhaarman.mockitokotlin2.verify
import fr.free.nrw.commons.Utils
import fr.free.nrw.commons.repository.UploadRepository
import fr.free.nrw.commons.upload.license.MediaLicenseContract

View file

@ -122,7 +122,7 @@ class UploadMediaPresenterTest {
Mockito.`when`(repository?.getPreviousUploadItem(ArgumentMatchers.anyInt())).thenReturn(uploadItem)
Mockito.`when`(uploadItem?.descriptions).thenReturn(descriptions)
Mockito.`when`(uploadItem?.title).thenReturn(title)
Mockito.`when`(title?.titleText).thenReturn(ArgumentMatchers.anyString())
Mockito.`when`(title?.getTitleText()).thenReturn(ArgumentMatchers.anyString())
uploadMediaPresenter?.fetchPreviousTitleAndDescription(0)
verify(view)?.setTitleAndDescription(ArgumentMatchers.anyString(),ArgumentMatchers.any())

View file

@ -1,6 +1,6 @@
package fr.free.nrw.commons.upload
import com.nhaarman.mockito_kotlin.verify
import com.nhaarman.mockitokotlin2.verify
import fr.free.nrw.commons.contributions.Contribution
import fr.free.nrw.commons.filepicker.UploadableFile
import fr.free.nrw.commons.repository.UploadRepository

View file

@ -1,7 +1,7 @@
package fr.free.nrw.commons.wikidata
import android.content.Context
import com.nhaarman.mockito_kotlin.verifyZeroInteractions
import com.nhaarman.mockitokotlin2.verifyZeroInteractions
import fr.free.nrw.commons.kvstore.JsonKvStore
import fr.free.nrw.commons.wikidata.model.AddEditTagResponse
import io.reactivex.Observable

View file

@ -0,0 +1 @@
mock-maker-inline