mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Migrated ContributionsContract,ContributionFragment,ContributionListAdapter,ContributionsListContract from java to Kotlin
This commit is contained in:
parent
ac9356835a
commit
daca7b31c1
10 changed files with 723 additions and 659 deletions
|
|
@ -1,23 +1,19 @@
|
||||||
package fr.free.nrw.commons.contributions;
|
package fr.free.nrw.commons.contributions
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context
|
||||||
import fr.free.nrw.commons.BasePresenter;
|
import fr.free.nrw.commons.BasePresenter
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The contract for Contributions View & Presenter
|
* The contract for Contributions View & Presenter
|
||||||
*/
|
*/
|
||||||
public class ContributionsContract {
|
interface ContributionsContract {
|
||||||
|
|
||||||
public interface View {
|
interface View {
|
||||||
|
fun showMessage(localizedMessage: String)
|
||||||
void showMessage(String localizedMessage);
|
fun getContext(): Context
|
||||||
|
|
||||||
Context getContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface UserActionListener extends BasePresenter<ContributionsContract.View> {
|
interface UserActionListener : BasePresenter<View> {
|
||||||
|
fun getContributionsWithTitle(uri: String): Contribution
|
||||||
Contribution getContributionsWithTitle(String uri);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,77 +1,72 @@
|
||||||
package fr.free.nrw.commons.contributions;
|
package fr.free.nrw.commons.contributions
|
||||||
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup
|
||||||
import androidx.annotation.NonNull;
|
import androidx.paging.PagedListAdapter
|
||||||
import androidx.paging.PagedListAdapter;
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import androidx.recyclerview.widget.DiffUtil;
|
import fr.free.nrw.commons.R
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.media.MediaClient
|
||||||
import fr.free.nrw.commons.media.MediaClient;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents The View Adapter for the List of Contributions
|
* Represents The View Adapter for the List of Contributions
|
||||||
*/
|
*/
|
||||||
public class ContributionsListAdapter extends
|
class ContributionsListAdapter internal constructor(
|
||||||
PagedListAdapter<Contribution, ContributionViewHolder> {
|
private val callback: Callback,
|
||||||
|
private val mediaClient: MediaClient
|
||||||
private final Callback callback;
|
) : PagedListAdapter<Contribution, ContributionViewHolder>(DIFF_CALLBACK) {
|
||||||
private final MediaClient mediaClient;
|
|
||||||
|
|
||||||
ContributionsListAdapter(final Callback callback,
|
|
||||||
final MediaClient mediaClient) {
|
|
||||||
super(DIFF_CALLBACK);
|
|
||||||
this.callback = callback;
|
|
||||||
this.mediaClient = mediaClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uses DiffUtil to calculate the changes in the list
|
|
||||||
* It has methods that check ID and the content of the items to determine if its a new item
|
|
||||||
*/
|
|
||||||
private static final DiffUtil.ItemCallback<Contribution> DIFF_CALLBACK =
|
|
||||||
new DiffUtil.ItemCallback<Contribution>() {
|
|
||||||
@Override
|
|
||||||
public boolean areItemsTheSame(final Contribution oldContribution, final Contribution newContribution) {
|
|
||||||
return oldContribution.getPageId().equals(newContribution.getPageId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean areContentsTheSame(final Contribution oldContribution, final Contribution newContribution) {
|
|
||||||
return oldContribution.equals(newContribution);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the view holder with contribution data
|
* Initializes the view holder with contribution data
|
||||||
*/
|
*/
|
||||||
@Override
|
override fun onBindViewHolder(holder: ContributionViewHolder, position: Int) {
|
||||||
public void onBindViewHolder(@NonNull ContributionViewHolder holder, int position) {
|
holder.init(position, getItem(position))
|
||||||
holder.init(position, getItem(position));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Contribution getContributionForPosition(final int position) {
|
fun getContributionForPosition(position: Int): Contribution? {
|
||||||
return getItem(position);
|
return getItem(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the new View Holder which will be used to display items(contributions) using the
|
* Creates the new View Holder which will be used to display items(contributions) using the
|
||||||
* onBindViewHolder(viewHolder,position)
|
* onBindViewHolder(viewHolder,position)
|
||||||
*/
|
*/
|
||||||
@NonNull
|
override fun onCreateViewHolder(
|
||||||
@Override
|
parent: ViewGroup,
|
||||||
public ContributionViewHolder onCreateViewHolder(@NonNull final ViewGroup parent,
|
viewType: Int
|
||||||
final int viewType) {
|
): ContributionViewHolder {
|
||||||
final ContributionViewHolder viewHolder = new ContributionViewHolder(
|
val viewHolder = ContributionViewHolder(
|
||||||
LayoutInflater.from(parent.getContext())
|
LayoutInflater.from(parent.context)
|
||||||
.inflate(R.layout.layout_contribution, parent, false),
|
.inflate(R.layout.layout_contribution, parent, false),
|
||||||
callback, mediaClient);
|
callback, mediaClient
|
||||||
return viewHolder;
|
)
|
||||||
|
return viewHolder
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Callback {
|
interface Callback {
|
||||||
|
fun openMediaDetail(contribution: Int, isWikipediaPageExists: Boolean)
|
||||||
|
|
||||||
void openMediaDetail(int contribution, boolean isWikipediaPageExists);
|
fun addImageToWikipedia(contribution: Contribution?)
|
||||||
|
}
|
||||||
|
|
||||||
void addImageToWikipedia(Contribution contribution);
|
companion object {
|
||||||
|
/**
|
||||||
|
* Uses DiffUtil to calculate the changes in the list
|
||||||
|
* It has methods that check ID and the content of the items to determine if its a new item
|
||||||
|
*/
|
||||||
|
private val DIFF_CALLBACK: DiffUtil.ItemCallback<Contribution> =
|
||||||
|
object : DiffUtil.ItemCallback<Contribution>() {
|
||||||
|
override fun areItemsTheSame(
|
||||||
|
oldContribution: Contribution,
|
||||||
|
newContribution: Contribution
|
||||||
|
): Boolean {
|
||||||
|
return oldContribution.pageId == newContribution.pageId
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areContentsTheSame(
|
||||||
|
oldContribution: Contribution,
|
||||||
|
newContribution: Contribution
|
||||||
|
): Boolean {
|
||||||
|
return oldContribution == newContribution
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,21 @@
|
||||||
package fr.free.nrw.commons.contributions;
|
package fr.free.nrw.commons.contributions
|
||||||
|
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
import fr.free.nrw.commons.BasePresenter;
|
import fr.free.nrw.commons.BasePresenter
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The contract for Contributions list View & Presenter
|
* The contract for Contributions list View & Presenter
|
||||||
*/
|
*/
|
||||||
public class ContributionsListContract {
|
class ContributionsListContract {
|
||||||
|
interface View {
|
||||||
|
fun showWelcomeTip(numberOfUploads: Boolean)
|
||||||
|
|
||||||
public interface View {
|
fun showProgress(shouldShow: Boolean)
|
||||||
|
|
||||||
void showWelcomeTip(boolean numberOfUploads);
|
fun showNoContributionsUI(shouldShow: Boolean)
|
||||||
|
|
||||||
void showProgress(boolean shouldShow);
|
|
||||||
|
|
||||||
void showNoContributionsUI(boolean shouldShow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface UserActionListener extends BasePresenter<View> {
|
interface UserActionListener : BasePresenter<View?> {
|
||||||
|
fun refreshList(swipeRefreshLayout: SwipeRefreshLayout?)
|
||||||
void refreshList(SwipeRefreshLayout swipeRefreshLayout);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,26 @@
|
||||||
package fr.free.nrw.commons.contributions;
|
package fr.free.nrw.commons.contributions;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
import dagger.Binds;
|
import dagger.Binds;
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Dagger Module for contributions related presenters and (some other objects maybe in future)
|
* The Dagger Module for contributions-related presenters and other dependencies
|
||||||
*/
|
*/
|
||||||
@Module
|
@Module
|
||||||
public abstract class ContributionsModule {
|
public abstract class ContributionsModule {
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
public abstract ContributionsContract.UserActionListener bindsContibutionsPresenter(
|
public abstract ContributionsContract.UserActionListener bindsContributionsPresenter(
|
||||||
ContributionsPresenter presenter);
|
ContributionsPresenter presenter
|
||||||
|
);
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
static JsonKvStore providesApplicationKvStore(
|
||||||
|
@Named("default_preferences") JsonKvStore kvStore
|
||||||
|
) {
|
||||||
|
return kvStore;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ abstract class CommonsDaggerSupportFragment : Fragment(), HasSupportFragmentInje
|
||||||
@Inject @JvmField
|
@Inject @JvmField
|
||||||
var childFragmentInjector: DispatchingAndroidInjector<Fragment>? = null
|
var childFragmentInjector: DispatchingAndroidInjector<Fragment>? = null
|
||||||
|
|
||||||
@JvmField
|
// Removed @JvmField to allow overriding
|
||||||
protected var compositeDisposable: CompositeDisposable = CompositeDisposable()
|
protected open var compositeDisposable: CompositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
override fun onAttach(context: Context) {
|
override fun onAttach(context: Context) {
|
||||||
inject()
|
inject()
|
||||||
|
|
@ -63,4 +63,9 @@ abstract class CommonsDaggerSupportFragment : Fragment(), HasSupportFragmentInje
|
||||||
|
|
||||||
return getInstance(activity.applicationContext)
|
return getInstance(activity.applicationContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure getContext() returns a non-null Context
|
||||||
|
override fun getContext(): Context {
|
||||||
|
return super.getContext() ?: throw IllegalStateException("Context is null")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -467,7 +467,7 @@ public class ExploreMapFragment extends CommonsDaggerSupportFragment
|
||||||
nearbyPlacesInfoObservable = presenter.loadAttractionsFromLocation(getLastMapFocus(),
|
nearbyPlacesInfoObservable = presenter.loadAttractionsFromLocation(getLastMapFocus(),
|
||||||
currentLatLng, false);
|
currentLatLng, false);
|
||||||
}
|
}
|
||||||
compositeDisposable.add(nearbyPlacesInfoObservable
|
getCompositeDisposable().add(nearbyPlacesInfoObservable
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(explorePlacesInfo -> {
|
.subscribe(explorePlacesInfo -> {
|
||||||
|
|
|
||||||
|
|
@ -493,7 +493,7 @@ class MediaDetailFragment : CommonsDaggerSupportFragment(), CategoryEditHelper.C
|
||||||
|
|
||||||
val contributionsFragment: ContributionsFragment? = this.getContributionsFragmentParent()
|
val contributionsFragment: ContributionsFragment? = this.getContributionsFragmentParent()
|
||||||
if (contributionsFragment?.binding != null) {
|
if (contributionsFragment?.binding != null) {
|
||||||
contributionsFragment.binding.cardViewNearby.visibility = View.GONE
|
contributionsFragment.binding!!.cardViewNearby.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
// detail provider is null when fragment is shown in review activity
|
// detail provider is null when fragment is shown in review activity
|
||||||
|
|
|
||||||
|
|
@ -742,7 +742,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
binding.map.onPause();
|
binding.map.onPause();
|
||||||
compositeDisposable.clear();
|
getCompositeDisposable().clear();
|
||||||
presenter.detachView();
|
presenter.detachView();
|
||||||
registerUnregisterLocationListener(true);
|
registerUnregisterLocationListener(true);
|
||||||
try {
|
try {
|
||||||
|
|
@ -857,7 +857,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
0.75);
|
0.75);
|
||||||
binding.nearbyFilterList.searchListView.setAdapter(nearbyFilterSearchRecyclerViewAdapter);
|
binding.nearbyFilterList.searchListView.setAdapter(nearbyFilterSearchRecyclerViewAdapter);
|
||||||
LayoutUtils.setLayoutHeightAlignedToWidth(1.25, binding.nearbyFilterList.getRoot());
|
LayoutUtils.setLayoutHeightAlignedToWidth(1.25, binding.nearbyFilterList.getRoot());
|
||||||
compositeDisposable.add(
|
getCompositeDisposable().add(
|
||||||
RxSearchView.queryTextChanges(binding.nearbyFilter.searchViewLayout.searchView)
|
RxSearchView.queryTextChanges(binding.nearbyFilter.searchViewLayout.searchView)
|
||||||
.takeUntil(RxView.detaches(binding.nearbyFilter.searchViewLayout.searchView))
|
.takeUntil(RxView.detaches(binding.nearbyFilter.searchViewLayout.searchView))
|
||||||
.debounce(500, TimeUnit.MILLISECONDS)
|
.debounce(500, TimeUnit.MILLISECONDS)
|
||||||
|
|
@ -1234,7 +1234,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
*/
|
*/
|
||||||
private void emptyCache() {
|
private void emptyCache() {
|
||||||
// reload the map once the cache is cleared
|
// reload the map once the cache is cleared
|
||||||
compositeDisposable.add(
|
getCompositeDisposable().add(
|
||||||
placesRepository.clearCache()
|
placesRepository.clearCache()
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
|
@ -1269,7 +1269,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
final Observable<String> savePlacesObservable = Observable
|
final Observable<String> savePlacesObservable = Observable
|
||||||
.fromCallable(() -> nearbyController
|
.fromCallable(() -> nearbyController
|
||||||
.getPlacesAsKML(getMapFocus()));
|
.getPlacesAsKML(getMapFocus()));
|
||||||
compositeDisposable.add(savePlacesObservable
|
getCompositeDisposable().add(savePlacesObservable
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(kmlString -> {
|
.subscribe(kmlString -> {
|
||||||
|
|
@ -1303,7 +1303,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
final Observable<String> savePlacesObservable = Observable
|
final Observable<String> savePlacesObservable = Observable
|
||||||
.fromCallable(() -> nearbyController
|
.fromCallable(() -> nearbyController
|
||||||
.getPlacesAsGPX(getMapFocus()));
|
.getPlacesAsGPX(getMapFocus()));
|
||||||
compositeDisposable.add(savePlacesObservable
|
getCompositeDisposable().add(savePlacesObservable
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(gpxString -> {
|
.subscribe(gpxString -> {
|
||||||
|
|
@ -1405,7 +1405,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
final Observable<List<Place>> getPlaceObservable = Observable
|
final Observable<List<Place>> getPlaceObservable = Observable
|
||||||
.fromCallable(() -> nearbyController
|
.fromCallable(() -> nearbyController
|
||||||
.getPlaces(List.of(place)));
|
.getPlaces(List.of(place)));
|
||||||
compositeDisposable.add(getPlaceObservable
|
getCompositeDisposable().add(getPlaceObservable
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(placeList -> {
|
.subscribe(placeList -> {
|
||||||
|
|
@ -1449,7 +1449,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
searchLatLng,
|
searchLatLng,
|
||||||
false, true, Utils.isMonumentsEnabled(new Date()), customQuery));
|
false, true, Utils.isMonumentsEnabled(new Date()), customQuery));
|
||||||
|
|
||||||
compositeDisposable.add(nearbyPlacesInfoObservable
|
getCompositeDisposable().add(nearbyPlacesInfoObservable
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(nearbyPlacesInfo -> {
|
.subscribe(nearbyPlacesInfo -> {
|
||||||
|
|
@ -1486,7 +1486,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
searchLatLng,
|
searchLatLng,
|
||||||
false, true, Utils.isMonumentsEnabled(new Date()), customQuery));
|
false, true, Utils.isMonumentsEnabled(new Date()), customQuery));
|
||||||
|
|
||||||
compositeDisposable.add(nearbyPlacesInfoObservable
|
getCompositeDisposable().add(nearbyPlacesInfoObservable
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(nearbyPlacesInfo -> {
|
.subscribe(nearbyPlacesInfo -> {
|
||||||
|
|
@ -1518,7 +1518,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
public void savePlaceToDatabase(Place place) {
|
public void savePlaceToDatabase(Place place) {
|
||||||
compositeDisposable.add(placesRepository
|
getCompositeDisposable().add(placesRepository
|
||||||
.save(place)
|
.save(place)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.subscribe());
|
.subscribe());
|
||||||
|
|
@ -1531,7 +1531,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
@Override
|
@Override
|
||||||
public void stopQuery() {
|
public void stopQuery() {
|
||||||
stopQuery = true;
|
stopQuery = true;
|
||||||
compositeDisposable.clear();
|
getCompositeDisposable().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package fr.free.nrw.commons.upload.categories
|
package fr.free.nrw.commons.upload.categories
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.ProgressDialog
|
import android.app.ProgressDialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
|
@ -89,6 +90,7 @@ class UploadCategoriesFragment : UploadBaseFragment(), CategoriesContract.View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("StringFormatMatches")
|
||||||
private fun init() {
|
private fun init() {
|
||||||
if (binding == null) {
|
if (binding == null) {
|
||||||
return
|
return
|
||||||
|
|
@ -372,8 +374,9 @@ class UploadCategoriesFragment : UploadBaseFragment(), CategoriesContract.View {
|
||||||
|
|
||||||
(requireActivity() as AppCompatActivity).supportActionBar?.hide()
|
(requireActivity() as AppCompatActivity).supportActionBar?.hide()
|
||||||
|
|
||||||
|
|
||||||
if (parentFragment?.parentFragment?.parentFragment is ContributionsFragment) {
|
if (parentFragment?.parentFragment?.parentFragment is ContributionsFragment) {
|
||||||
((parentFragment?.parentFragment?.parentFragment) as ContributionsFragment).binding.cardViewNearby.visibility = View.GONE
|
((parentFragment?.parentFragment?.parentFragment) as ContributionsFragment).binding?.cardViewNearby?.visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue