mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-11-03 16:23:54 +01:00
Code cleanup and convert MediaLicenseContract to kotlin
This commit is contained in:
parent
7da4bb6dad
commit
5a117ee9e3
3 changed files with 32 additions and 35 deletions
|
|
@ -1,28 +0,0 @@
|
|||
package fr.free.nrw.commons.upload.license;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.free.nrw.commons.BasePresenter;
|
||||
|
||||
/**
|
||||
* The contract with with MediaLicenseFragment and its presenter would talk to each other
|
||||
*/
|
||||
public interface MediaLicenseContract {
|
||||
|
||||
interface View {
|
||||
void setLicenses(List<String> licenses);
|
||||
|
||||
void setSelectedLicense(String license);
|
||||
|
||||
void updateLicenseSummary(String selectedLicense, int numberOfItems);
|
||||
}
|
||||
|
||||
interface UserActionListener extends BasePresenter<View> {
|
||||
void getLicenses();
|
||||
|
||||
void selectLicense(String licenseName);
|
||||
|
||||
boolean isWLMSupportedForThisPlace();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package fr.free.nrw.commons.upload.license
|
||||
|
||||
import fr.free.nrw.commons.BasePresenter
|
||||
|
||||
/**
|
||||
* The contract with with MediaLicenseFragment and its presenter would talk to each other
|
||||
*/
|
||||
interface MediaLicenseContract {
|
||||
interface View {
|
||||
fun setLicenses(licenses: List<String>?)
|
||||
|
||||
fun setSelectedLicense(license: String)
|
||||
|
||||
fun updateLicenseSummary(selectedLicense: String?, numberOfItems: Int)
|
||||
}
|
||||
|
||||
interface UserActionListener : BasePresenter<View> {
|
||||
fun getLicenses()
|
||||
|
||||
fun selectLicense(licenseName: String)
|
||||
|
||||
fun isWLMSupportedForThisPlace(): Boolean
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package fr.free.nrw.commons.upload.license;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.repository.UploadRepository;
|
||||
|
|
@ -27,14 +28,14 @@ public class MediaLicensePresenter implements MediaLicenseContract.UserActionLis
|
|||
private MediaLicenseContract.View view = DUMMY;
|
||||
|
||||
@Inject
|
||||
public MediaLicensePresenter(UploadRepository uploadRepository,
|
||||
@Named("default_preferences") JsonKvStore defaultKVStore) {
|
||||
public MediaLicensePresenter(final UploadRepository uploadRepository,
|
||||
@Named("default_preferences") final JsonKvStore defaultKVStore) {
|
||||
this.repository = uploadRepository;
|
||||
this.defaultKVStore = defaultKVStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachView(View view) {
|
||||
public void onAttachView(@NonNull final View view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
|
|
@ -48,15 +49,15 @@ public class MediaLicensePresenter implements MediaLicenseContract.UserActionLis
|
|||
*/
|
||||
@Override
|
||||
public void getLicenses() {
|
||||
List<String> licenses = repository.getLicenses();
|
||||
final List<String> licenses = repository.getLicenses();
|
||||
view.setLicenses(licenses);
|
||||
|
||||
String selectedLicense = defaultKVStore.getString(Prefs.DEFAULT_LICENSE,
|
||||
Prefs.Licenses.CC_BY_SA_4);//CC_BY_SA_4 is the default one used by the commons web app
|
||||
try {//I have to make sure that the stored default license was not one of the deprecated one's
|
||||
Utils.licenseNameFor(selectedLicense);
|
||||
} catch (IllegalStateException exception) {
|
||||
Timber.e(exception.getMessage());
|
||||
} catch (final IllegalStateException exception) {
|
||||
Timber.e(exception);
|
||||
selectedLicense = Prefs.Licenses.CC_BY_SA_4;
|
||||
defaultKVStore.putString(Prefs.DEFAULT_LICENSE, Prefs.Licenses.CC_BY_SA_4);
|
||||
}
|
||||
|
|
@ -70,7 +71,7 @@ public class MediaLicensePresenter implements MediaLicenseContract.UserActionLis
|
|||
* @param licenseName
|
||||
*/
|
||||
@Override
|
||||
public void selectLicense(String licenseName) {
|
||||
public void selectLicense(@NonNull final String licenseName) {
|
||||
repository.setSelectedLicense(licenseName);
|
||||
view.updateLicenseSummary(repository.getSelectedLicense(), repository.getCount());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue