Skip to content
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8e69ee2
Rename .java to .kt
Sujal-Gupta-SG Jan 29, 2025
835c756
Migrated ContributionController
Sujal-Gupta-SG Jan 29, 2025
a688180
Rename .java to .kt
Sujal-Gupta-SG Jan 29, 2025
2201be5
Migrated ContributionDao
Sujal-Gupta-SG Jan 29, 2025
177394b
Rename .java to .kt
Sujal-Gupta-SG Jan 31, 2025
66bb450
Migrated ContributionsContract,ContributionFragment,ContributionListA…
Sujal-Gupta-SG Jan 31, 2025
2d1834a
Rename .java to .kt
Sujal-Gupta-SG Feb 3, 2025
adf15f2
converted/Migrated
Sujal-Gupta-SG Feb 3, 2025
fc5e3b0
converted/Migrated
Sujal-Gupta-SG Feb 3, 2025
bdcc02b
Rename .java to .kt
Sujal-Gupta-SG Jan 29, 2025
7efed21
Migrated ContributionController
Sujal-Gupta-SG Jan 29, 2025
506588d
Rename .java to .kt
Sujal-Gupta-SG Jan 29, 2025
8b8f70c
Migrated ContributionDao
Sujal-Gupta-SG Jan 29, 2025
ac93568
Rename .java to .kt
Sujal-Gupta-SG Jan 31, 2025
daca7b3
Migrated ContributionsContract,ContributionFragment,ContributionListA…
Sujal-Gupta-SG Jan 31, 2025
c07203b
Rename .java to .kt
Sujal-Gupta-SG Feb 3, 2025
5d46614
Show placeholder and display depiction section when no depictions are…
Sujal-Gupta-SG Jan 29, 2025
6e656e8
Migrated AboutActivity from Java to Kotlin (#6158)
Akshaykomar890 Jan 30, 2025
8eb3152
Localisation updates from https://translatewiki.net.
translatewiki Jan 30, 2025
70bbf1c
Feat: Make it smoother to switch between nearby and explore maps (#6164)
andy-ife Jan 30, 2025
6329baf
Localisation updates from https://translatewiki.net.
translatewiki Jan 31, 2025
2a6367e
enhance spammy category filter (#6167)
parneet-guraya Feb 1, 2025
b04c4d8
Localisation updates from https://translatewiki.net.
translatewiki Feb 3, 2025
cf726c4
Merge remote-tracking branch 'origin/Migrated-Contributions-from-java…
Sujal-Gupta-SG Feb 3, 2025
5964fe5
correction
Sujal-Gupta-SG Feb 3, 2025
36bfeac
correction
Sujal-Gupta-SG Feb 3, 2025
0aed032
correction
Sujal-Gupta-SG Feb 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Large diffs are not rendered by default.

This file was deleted.

148 changes: 148 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/contributions/ContributionDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package fr.free.nrw.commons.contributions

import android.database.sqlite.SQLiteException
import androidx.paging.DataSource
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Update
import io.reactivex.Completable
import io.reactivex.Single
import java.util.Calendar

@Dao
abstract class ContributionDao {
@Query("SELECT * FROM contribution order by media_dateUploaded DESC")
abstract fun fetchContributions(): DataSource.Factory<Int, Contribution>

@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract fun saveSynchronous(contribution: Contribution)

fun save(contribution: Contribution): Completable {
return Completable
.fromAction {
contribution.dateModified = Calendar.getInstance().time
if (contribution.dateUploadStarted == null) {
contribution.dateUploadStarted = Calendar.getInstance().time
}
saveSynchronous(contribution)
}
}

@Transaction
open fun deleteAndSaveContribution(
oldContribution: Contribution,
newContribution: Contribution
) {
deleteSynchronous(oldContribution)
saveSynchronous(newContribution)
}

@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract fun save(contribution: List<Contribution>): Single<List<Long>>

@Delete
abstract fun deleteSynchronous(contribution: Contribution)

/**
* Deletes contributions with specific states from the database.
*
* @param states The states of the contributions to delete.
* @throws SQLiteException If an SQLite error occurs.
*/
@Query("DELETE FROM contribution WHERE state IN (:states)")
@Throws(SQLiteException::class)
abstract fun deleteContributionsWithStatesSynchronous(states: List<Int>)

fun delete(contribution: Contribution): Completable {
return Completable
.fromAction { deleteSynchronous(contribution) }
}

/**
* Deletes contributions with specific states from the database.
*
* @param states The states of the contributions to delete.
* @return A Completable indicating the result of the operation.
*/
fun deleteContributionsWithStates(states: List<Int>): Completable {
return Completable
.fromAction { deleteContributionsWithStatesSynchronous(states) }
}

@Query("SELECT * from contribution WHERE media_filename=:fileName")
abstract fun getContributionWithTitle(fileName: String): List<Contribution>

@Query("SELECT * from contribution WHERE pageId=:pageId")
abstract fun getContribution(pageId: String): Contribution

@Query("SELECT * from contribution WHERE state IN (:states) order by media_dateUploaded DESC")
abstract fun getContribution(states: List<Int>): Single<List<Contribution>>

/**
* Gets contributions with specific states in descending order by the date they were uploaded.
*
* @param states The states of the contributions to fetch.
* @return A DataSource factory for paginated contributions with the specified states.
*/
@Query("SELECT * from contribution WHERE state IN (:states) order by media_dateUploaded DESC")
abstract fun getContributions(
states: List<Int>
): DataSource.Factory<Int, Contribution>

/**
* Gets contributions with specific states in ascending order by the date the upload started.
*
* @param states The states of the contributions to fetch.
* @return A DataSource factory for paginated contributions with the specified states.
*/
@Query("SELECT * from contribution WHERE state IN (:states) order by dateUploadStarted ASC")
abstract fun getContributionsSortedByDateUploadStarted(
states: List<Int>
): DataSource.Factory<Int, Contribution>

@Query("SELECT COUNT(*) from contribution WHERE state in (:toUpdateStates)")
abstract fun getPendingUploads(toUpdateStates: IntArray): Single<Int>

@Query("Delete FROM contribution")
@Throws(SQLiteException::class)
abstract fun deleteAll()

@Update
abstract fun updateSynchronous(contribution: Contribution)

/**
* Updates the state of contributions with specific states.
*
* @param states The current states of the contributions to update.
* @param newState The new state to set.
*/
@Query("UPDATE contribution SET state = :newState WHERE state IN (:states)")
abstract fun updateContributionsState(states: List<Int>, newState: Int)

fun update(contribution: Contribution): Completable {
return Completable.fromAction {
contribution.dateModified = Calendar.getInstance().time
updateSynchronous(contribution)
}
}



/**
* Updates the state of contributions with specific states asynchronously.
*
* @param states The current states of the contributions to update.
* @param newState The new state to set.
* @return A Completable indicating the result of the operation.
*/
fun updateContributionsWithStates(states: List<Int>, newState: Int): Completable {
return Completable
.fromAction {
updateContributionsState(states, newState)
}
}
}
Loading