mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-11-01 23:33:54 +01:00
Code cleanup, fixed nullability and converted DepictsContract to kotlin
This commit is contained in:
parent
484e56c17c
commit
1ba5b7e6c7
7 changed files with 40 additions and 45 deletions
|
|
@ -1,129 +1,125 @@
|
|||
package fr.free.nrw.commons.upload.depicts;
|
||||
package fr.free.nrw.commons.upload.depicts
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import fr.free.nrw.commons.BasePresenter;
|
||||
import fr.free.nrw.commons.Media;
|
||||
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem;
|
||||
import java.util.List;
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.LiveData
|
||||
import fr.free.nrw.commons.BasePresenter
|
||||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem
|
||||
|
||||
/**
|
||||
* The contract with which DepictsFragment and its presenter would talk to each other
|
||||
*/
|
||||
public interface DepictsContract {
|
||||
|
||||
interface DepictsContract {
|
||||
interface View {
|
||||
/**
|
||||
* Go to category screen
|
||||
*/
|
||||
void goToNextScreen();
|
||||
fun goToNextScreen()
|
||||
|
||||
/**
|
||||
* Go to media detail screen
|
||||
*/
|
||||
void goToPreviousScreen();
|
||||
fun goToPreviousScreen()
|
||||
|
||||
/**
|
||||
* show error in case of no depiction selected
|
||||
*/
|
||||
void noDepictionSelected();
|
||||
fun noDepictionSelected()
|
||||
|
||||
/**
|
||||
* Show progress/Hide progress depending on the boolean value
|
||||
*/
|
||||
void showProgress(boolean shouldShow);
|
||||
fun showProgress(shouldShow: Boolean)
|
||||
|
||||
/**
|
||||
* decides whether to show error values or not depending on the boolean value
|
||||
*/
|
||||
void showError(Boolean value);
|
||||
fun showError(value: Boolean)
|
||||
|
||||
/**
|
||||
* add depictions to list
|
||||
*/
|
||||
void setDepictsList(List<DepictedItem> depictedItemList);
|
||||
fun setDepictsList(depictedItemList: List<DepictedItem>)
|
||||
|
||||
/**
|
||||
* Returns required context
|
||||
*/
|
||||
Context getFragmentContext();
|
||||
fun getFragmentContext(): Context
|
||||
|
||||
/**
|
||||
* Returns to previous fragment
|
||||
*/
|
||||
void goBackToPreviousScreen();
|
||||
fun goBackToPreviousScreen()
|
||||
|
||||
/**
|
||||
* Gets existing depictions IDs from media
|
||||
*/
|
||||
List<String> getExistingDepictions();
|
||||
fun getExistingDepictions(): List<String>?
|
||||
|
||||
/**
|
||||
* Shows the progress dialog
|
||||
*/
|
||||
void showProgressDialog();
|
||||
fun showProgressDialog()
|
||||
|
||||
/**
|
||||
* Hides the progress dialog
|
||||
*/
|
||||
void dismissProgressDialog();
|
||||
fun dismissProgressDialog()
|
||||
|
||||
/**
|
||||
* Update the depictions
|
||||
*/
|
||||
void updateDepicts();
|
||||
fun updateDepicts()
|
||||
|
||||
/**
|
||||
* Navigate the user to Login Activity
|
||||
*/
|
||||
void navigateToLoginScreen();
|
||||
fun navigateToLoginScreen()
|
||||
}
|
||||
|
||||
interface UserActionListener extends BasePresenter<View> {
|
||||
|
||||
interface UserActionListener : BasePresenter<View> {
|
||||
/**
|
||||
* Takes to previous screen
|
||||
*/
|
||||
void onPreviousButtonClicked();
|
||||
fun onPreviousButtonClicked()
|
||||
|
||||
/**
|
||||
* Listener for the depicted items selected from the list
|
||||
*/
|
||||
void onDepictItemClicked(DepictedItem depictedItem);
|
||||
fun onDepictItemClicked(depictedItem: DepictedItem)
|
||||
|
||||
/**
|
||||
* asks the repository to fetch depictions for the query
|
||||
* @param query
|
||||
* @param query
|
||||
*/
|
||||
void searchForDepictions(String query);
|
||||
fun searchForDepictions(query: String)
|
||||
|
||||
/**
|
||||
* Selects all associated places (if any) as depictions
|
||||
*/
|
||||
void selectPlaceDepictions();
|
||||
fun selectPlaceDepictions()
|
||||
|
||||
/**
|
||||
* Check if depictions were selected
|
||||
* from the depiction list
|
||||
*/
|
||||
void verifyDepictions();
|
||||
fun verifyDepictions()
|
||||
|
||||
/**
|
||||
* Clears previous selections
|
||||
*/
|
||||
void clearPreviousSelection();
|
||||
fun clearPreviousSelection()
|
||||
|
||||
LiveData<List<DepictedItem>> getDepictedItems();
|
||||
fun getDepictedItems(): LiveData<List<DepictedItem>>
|
||||
|
||||
/**
|
||||
* Update the depictions
|
||||
*/
|
||||
void updateDepictions(Media media);
|
||||
fun updateDepictions(media: Media)
|
||||
|
||||
/**
|
||||
* Attaches view and media
|
||||
*/
|
||||
void onAttachViewWithMedia(@NonNull View view, Media media);
|
||||
fun onAttachViewWithMedia(view: View, media: Media)
|
||||
}
|
||||
}
|
||||
|
|
@ -218,7 +218,7 @@ public class DepictsFragment extends UploadBaseFragment implements DepictsContra
|
|||
}
|
||||
|
||||
@Override
|
||||
public void showError(Boolean value) {
|
||||
public void showError(boolean value) {
|
||||
if (binding == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import androidx.lifecycle.MutableLiveData
|
|||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.auth.csrf.InvalidLoginTokenException
|
||||
import fr.free.nrw.commons.bookmarks.items.BookmarkItemsController
|
||||
import fr.free.nrw.commons.di.CommonsApplicationModule
|
||||
import fr.free.nrw.commons.di.CommonsApplicationModule.Companion.IO_THREAD
|
||||
import fr.free.nrw.commons.di.CommonsApplicationModule.Companion.MAIN_THREAD
|
||||
import fr.free.nrw.commons.repository.UploadRepository
|
||||
|
|
@ -208,7 +207,7 @@ class DepictsPresenter
|
|||
@SuppressLint("CheckResult")
|
||||
override fun updateDepictions(media: Media) {
|
||||
if (repository.getSelectedDepictions().isNotEmpty() ||
|
||||
repository.getSelectedExistingDepictions().size != view.existingDepictions.size
|
||||
repository.getSelectedExistingDepictions().size != view.getExistingDepictions()?.size
|
||||
) {
|
||||
view.showProgressDialog()
|
||||
val selectedDepictions: MutableList<String> =
|
||||
|
|
@ -225,7 +224,7 @@ class DepictsPresenter
|
|||
|
||||
compositeDisposable.add(
|
||||
depictsHelper
|
||||
.makeDepictionEdit(view.fragmentContext, media, selectedDepictions)
|
||||
.makeDepictionEdit(view.getFragmentContext(), media, selectedDepictions)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
|
|
@ -256,7 +255,7 @@ class DepictsPresenter
|
|||
) {
|
||||
this.view = view
|
||||
this.media = media
|
||||
repository.setSelectedExistingDepictions(view.existingDepictions)
|
||||
repository.setSelectedExistingDepictions(view.getExistingDepictions() ?: emptyList())
|
||||
compositeDisposable.add(
|
||||
searchTerm
|
||||
.observeOn(mainThreadScheduler)
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ interface MediaLicenseContract {
|
|||
interface View {
|
||||
fun setLicenses(licenses: List<String>?)
|
||||
|
||||
fun setSelectedLicense(license: String)
|
||||
fun setSelectedLicense(license: String?)
|
||||
|
||||
fun updateLicenseSummary(selectedLicense: String?, numberOfItems: Int)
|
||||
fun updateLicenseSummary(selectedLicense: String?, numberOfItems: Int?)
|
||||
}
|
||||
|
||||
interface UserActionListener : BasePresenter<View> {
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ public class MediaLicenseFragment extends UploadBaseFragment implements MediaLic
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateLicenseSummary(String licenseSummary, int numberOfItems) {
|
||||
public void updateLicenseSummary(String licenseSummary, Integer numberOfItems) {
|
||||
String licenseHyperLink = "<a href='" + Utils.licenseUrlFor(licenseSummary) + "'>" +
|
||||
getString(Utils.licenseNameFor(licenseSummary)) + "</a><br>";
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class MediaLicensePresenter implements MediaLicenseContract.UserActionLis
|
|||
* @param licenseName
|
||||
*/
|
||||
@Override
|
||||
public void selectLicense(@NonNull final String licenseName) {
|
||||
public void selectLicense(final String licenseName) {
|
||||
repository.setSelectedLicense(licenseName);
|
||||
view.updateLicenseSummary(repository.getSelectedLicense(), repository.getCount());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ class DepictsFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetFragmentContext() {
|
||||
fragment.fragmentContext
|
||||
fragment.getFragmentContext()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue