Skip to content

Commit 67a8d09

Browse files
Sujal-Gupta-SGAkshaykomar890nicolas-raoultranslatewikiandy-ife
committed
Migrated contributions folder Files from java to kotlin (#6176)
* Rename .java to .kt * Migrated ContributionController * Rename .java to .kt * Migrated ContributionDao * Rename .java to .kt * Migrated ContributionsContract,ContributionFragment,ContributionListAdapter,ContributionsListContract from java to Kotlin * Rename .java to .kt * converted/Migrated * converted/Migrated * Rename .java to .kt * Migrated ContributionController * Rename .java to .kt * Migrated ContributionDao * Rename .java to .kt * Migrated ContributionsContract,ContributionFragment,ContributionListAdapter,ContributionsListContract from java to Kotlin * Rename .java to .kt * Show placeholder and display depiction section when no depictions are available (#6163) (#6165) * corrected * corrected * Update MediaDetailFragment.kt Spelling correction * Migrated AboutActivity from Java to Kotlin (#6158) * Rename Constants to Follow Kotlin Naming Conventions >This PR refactors constant names in the project to adhere to Kotlin's UPPERCASE_SNAKE_CASE naming convention, improving code readability and maintaining consistency across the codebase. >Renamed the following constants in LoginActivity: >saveProgressDialog → SAVE_PROGRESS_DIALOG >saveErrorMessage → SAVE_ERROR_MESSAGE >saveUsername → SAVE_USERNAME >savePassword → SAVE_PASSWORD >Updated all references to these constants throughout the project. * Update Project_Default.xml * Refactor variable names to adhere to naming conventions Renamed variables to use camel case: -UPLOAD_COUNT_THRESHOLD → uploadCountThreshold -REVERT_PERCENTAGE_FOR_MESSAGE → revertPercentageForMessage -REVERT_SHARED_PREFERENCE → revertSharedPreference -UPLOAD_SHARED_PREFERENCE → uploadSharedPreference Renamed variables with uppercase initials to lowercase for alignment with Kotlin conventions: -Latitude → latitude -Longitude → longitude -Accuracy → accuracy Refactored the following variable names: -NUMBER_OF_QUESTIONS → numberOfQuestions -MULTIPLIER_TO_GET_PERCENTAGE → multiplierToGetPercentage * Refactor Dialog View Initialization with Null-Safe Calls This PR refactors the dialog setup code in CustomSelectorActivity to improve safety and readability by replacing explicit casts with null-safe generic calls for findViewById. >Replaced explicit casting (as Button and as TextView) with the generic findViewById<T>() method for improved type safety. >Added null-safety (?.) to avoid potential crashes if a view is not found in the dialog layout. why changed:- >Prevents runtime crashes caused by NullPointerException when a view is missing in the layout. * Refactor Unit Test: Replace Unsafe Casting with Type-Safe Mocking for findViewById >PR refactors the unit test for NearbyParentFragment by replacing unsafe casting in the findViewById mocking statements with type-safe >Ensured all findViewById mocks now use a consistent, type-safe format (findViewById<View>(...)) to reduce verbosity and potential casting errors. >Verified the functionality of prepareViewsForSheetPosition remains unchanged, ensuring no regression in test behavior. * Update NearbyParentFragmentUnitTest.kt * Refactor: Rename Constants to Follow CamelCase Naming Convention >Updated all constant variable names to follow the camelCase naming convention, removing underscores in the middle or end. >Ensured variable names remain descriptive and align with code readability best practices. * Replace private val with const val for URL constants in QuizController * Renaming the constant to use UPPER_SNAKE_CASE * Renaming the constant to use UPPER_SNAKE_CASE * Update Done * **Refactor: Convert `minimumThresholdForSwipe` to a compile-time constant** * Convert AboutActivity from Java to Kotlin This PR converts the AboutActivity class from Java to Kotlin >Testing: >Verified all functionalities of the AboutActivity, including toolbar setup, intent launches, and dialog interactions, to ensure behavior remains consistent post-conversion. >Successfully ran unit tests for AboutActivity to confirm the correctness of methods and logic. * Thank you for the suggestion! Since these methods all take a single View parameter, replacing them with method references is a great way to simplify the code and improve readability. I'll updated the code accordingly. Added a TODO in the code as a reminder to refactor this in the future. --------- Co-authored-by: Nicolas Raoul <[email protected]> * Localisation updates from https://translatewiki.net. * Feat: Make it smoother to switch between nearby and explore maps (#6164) * Nearby: Add 'Show in Explore' 3-dots menu item * MainActivity: Add methods to pass extras between Nearby and Explore * MainActivity: Extend loadFragment() to support passing fragment arguments * Nearby: Add ability to navigate to Explore fragment on 'Show in Explore' click * Explore: Read fragment arguments for Nearby map data and update Explore map if present * Explore: Add 'Show in Nearby' 3-dots menu item. Only visible when Map tab is selected * Explore: On 'Show in Nearby' click, navigate to Nearby fragment, passing map data as fragment args * Nearby: Read fragment arguments for Explore map data and update Nearby map if present * MainActivity: Fix memory leaks when navigating between bottom nav destinations * Explore: Fix crashes caused by unattached map fragment * Refactor code to pass unit tests * Explore: Format javadocs --------- Co-authored-by: Nicolas Raoul <[email protected]> * Localisation updates from https://translatewiki.net. * enhance spammy category filter (#6167) Signed-off-by: parneet-guraya <[email protected]> * Localisation updates from https://translatewiki.net. * correction * correction * correction * GitHub workflow to build betaDebug (#6174) * [Bug fix] Check if duplicate exist using both original and modified file's checksum (#6169) * check original file's SHA too along with modified one Signed-off-by: parneet-guraya <[email protected]> * fix tests Signed-off-by: parneet-guraya <[email protected]> --------- Signed-off-by: parneet-guraya <[email protected]> * Add multiline input for caption and description (#6173) * allow multiple lines for description/caption * make caption multiline too --------- Co-authored-by: Nicolas Raoul <[email protected]> * correction --------- Signed-off-by: parneet-guraya <[email protected]> Co-authored-by: Akshay Komar <[email protected]> Co-authored-by: Nicolas Raoul <[email protected]> Co-authored-by: translatewiki.net <[email protected]> Co-authored-by: Ifeoluwa Andrew Omole <[email protected]> Co-authored-by: Parneet Singh <[email protected]> Co-authored-by: Matija Nalis <[email protected]>
1 parent 1472224 commit 67a8d09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3630
-3529
lines changed

Diff for: app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.java

-405
This file was deleted.

Diff for: app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.kt

+474
Large diffs are not rendered by default.

Diff for: app/src/main/java/fr/free/nrw/commons/contributions/ContributionDao.java

-145
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package fr.free.nrw.commons.contributions
2+
3+
import android.database.sqlite.SQLiteException
4+
import androidx.paging.DataSource
5+
import androidx.room.Dao
6+
import androidx.room.Delete
7+
import androidx.room.Insert
8+
import androidx.room.OnConflictStrategy
9+
import androidx.room.Query
10+
import androidx.room.Transaction
11+
import androidx.room.Update
12+
import io.reactivex.Completable
13+
import io.reactivex.Single
14+
import java.util.Calendar
15+
16+
@Dao
17+
abstract class ContributionDao {
18+
@Query("SELECT * FROM contribution order by media_dateUploaded DESC")
19+
abstract fun fetchContributions(): DataSource.Factory<Int, Contribution>
20+
21+
@Insert(onConflict = OnConflictStrategy.REPLACE)
22+
abstract fun saveSynchronous(contribution: Contribution)
23+
24+
fun save(contribution: Contribution): Completable {
25+
return Completable
26+
.fromAction {
27+
contribution.dateModified = Calendar.getInstance().time
28+
if (contribution.dateUploadStarted == null) {
29+
contribution.dateUploadStarted = Calendar.getInstance().time
30+
}
31+
saveSynchronous(contribution)
32+
}
33+
}
34+
35+
@Transaction
36+
open fun deleteAndSaveContribution(
37+
oldContribution: Contribution,
38+
newContribution: Contribution
39+
) {
40+
deleteSynchronous(oldContribution)
41+
saveSynchronous(newContribution)
42+
}
43+
44+
@Insert(onConflict = OnConflictStrategy.REPLACE)
45+
abstract fun save(contribution: List<Contribution>): Single<List<Long>>
46+
47+
@Delete
48+
abstract fun deleteSynchronous(contribution: Contribution)
49+
50+
/**
51+
* Deletes contributions with specific states from the database.
52+
*
53+
* @param states The states of the contributions to delete.
54+
* @throws SQLiteException If an SQLite error occurs.
55+
*/
56+
@Query("DELETE FROM contribution WHERE state IN (:states)")
57+
@Throws(SQLiteException::class)
58+
abstract fun deleteContributionsWithStatesSynchronous(states: List<Int>)
59+
60+
fun delete(contribution: Contribution): Completable {
61+
return Completable
62+
.fromAction { deleteSynchronous(contribution) }
63+
}
64+
65+
/**
66+
* Deletes contributions with specific states from the database.
67+
*
68+
* @param states The states of the contributions to delete.
69+
* @return A Completable indicating the result of the operation.
70+
*/
71+
fun deleteContributionsWithStates(states: List<Int>): Completable {
72+
return Completable
73+
.fromAction { deleteContributionsWithStatesSynchronous(states) }
74+
}
75+
76+
@Query("SELECT * from contribution WHERE media_filename=:fileName")
77+
abstract fun getContributionWithTitle(fileName: String): List<Contribution>
78+
79+
@Query("SELECT * from contribution WHERE pageId=:pageId")
80+
abstract fun getContribution(pageId: String): Contribution
81+
82+
@Query("SELECT * from contribution WHERE state IN (:states) order by media_dateUploaded DESC")
83+
abstract fun getContribution(states: List<Int>): Single<List<Contribution>>
84+
85+
/**
86+
* Gets contributions with specific states in descending order by the date they were uploaded.
87+
*
88+
* @param states The states of the contributions to fetch.
89+
* @return A DataSource factory for paginated contributions with the specified states.
90+
*/
91+
@Query("SELECT * from contribution WHERE state IN (:states) order by media_dateUploaded DESC")
92+
abstract fun getContributions(
93+
states: List<Int>
94+
): DataSource.Factory<Int, Contribution>
95+
96+
/**
97+
* Gets contributions with specific states in ascending order by the date the upload started.
98+
*
99+
* @param states The states of the contributions to fetch.
100+
* @return A DataSource factory for paginated contributions with the specified states.
101+
*/
102+
@Query("SELECT * from contribution WHERE state IN (:states) order by dateUploadStarted ASC")
103+
abstract fun getContributionsSortedByDateUploadStarted(
104+
states: List<Int>
105+
): DataSource.Factory<Int, Contribution>
106+
107+
@Query("SELECT COUNT(*) from contribution WHERE state in (:toUpdateStates)")
108+
abstract fun getPendingUploads(toUpdateStates: IntArray): Single<Int>
109+
110+
@Query("Delete FROM contribution")
111+
@Throws(SQLiteException::class)
112+
abstract fun deleteAll()
113+
114+
@Update
115+
abstract fun updateSynchronous(contribution: Contribution)
116+
117+
/**
118+
* Updates the state of contributions with specific states.
119+
*
120+
* @param states The current states of the contributions to update.
121+
* @param newState The new state to set.
122+
*/
123+
@Query("UPDATE contribution SET state = :newState WHERE state IN (:states)")
124+
abstract fun updateContributionsState(states: List<Int>, newState: Int)
125+
126+
fun update(contribution: Contribution): Completable {
127+
return Completable.fromAction {
128+
contribution.dateModified = Calendar.getInstance().time
129+
updateSynchronous(contribution)
130+
}
131+
}
132+
133+
134+
135+
/**
136+
* Updates the state of contributions with specific states asynchronously.
137+
*
138+
* @param states The current states of the contributions to update.
139+
* @param newState The new state to set.
140+
* @return A Completable indicating the result of the operation.
141+
*/
142+
fun updateContributionsWithStates(states: List<Int>, newState: Int): Completable {
143+
return Completable
144+
.fromAction {
145+
updateContributionsState(states, newState)
146+
}
147+
}
148+
}

0 commit comments

Comments
 (0)