Made changes to visibility implementation

This commit is contained in:
Kanahia 2024-07-26 18:04:46 +05:30
parent aeb49cd7de
commit ae00a9d19f
4 changed files with 79 additions and 69 deletions

View file

@ -9,6 +9,10 @@ import android.content.Intent;
import android.widget.Toast; import android.widget.Toast;
import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.ActivityResultLauncher;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.paging.DataSource.Factory;
import androidx.paging.LivePagedListBuilder;
import androidx.paging.PagedList;
import fr.free.nrw.commons.R; import fr.free.nrw.commons.R;
import fr.free.nrw.commons.filepicker.DefaultCallback; import fr.free.nrw.commons.filepicker.DefaultCallback;
import fr.free.nrw.commons.filepicker.FilePicker; import fr.free.nrw.commons.filepicker.FilePicker;
@ -25,6 +29,8 @@ import fr.free.nrw.commons.utils.DialogUtil;
import fr.free.nrw.commons.utils.PermissionUtils; import fr.free.nrw.commons.utils.PermissionUtils;
import fr.free.nrw.commons.utils.ViewUtil; import fr.free.nrw.commons.utils.ViewUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -39,10 +45,16 @@ public class ContributionController {
private boolean isInAppCameraUpload; private boolean isInAppCameraUpload;
public LocationPermissionCallback locationPermissionCallback; public LocationPermissionCallback locationPermissionCallback;
private LocationPermissionsHelper locationPermissionsHelper; private LocationPermissionsHelper locationPermissionsHelper;
LiveData<PagedList<Contribution>> failedAndPendingContributionList;
LiveData<PagedList<Contribution>> pendingContributionList;
LiveData<PagedList<Contribution>> failedContributionList;
@Inject @Inject
LocationServiceManager locationManager; LocationServiceManager locationManager;
@Inject
ContributionsRepository repository;
@Inject @Inject
public ContributionController(@Named("default_preferences") JsonKvStore defaultKvStore) { public ContributionController(@Named("default_preferences") JsonKvStore defaultKvStore) {
this.defaultKvStore = defaultKvStore; this.defaultKvStore = defaultKvStore;
@ -307,4 +319,48 @@ public class ContributionController {
isInAppCameraUpload = false; // reset the flag for next use isInAppCameraUpload = false; // reset the flag for next use
return shareIntent; return shareIntent;
} }
void getPendingContributions() {
final PagedList.Config pagedListConfig =
(new PagedList.Config.Builder())
.setPrefetchDistance(50)
.setPageSize(10).build();
Factory<Integer, Contribution> factory;
factory = repository.fetchContributionsWithStates(
Arrays.asList(Contribution.STATE_IN_PROGRESS, Contribution.STATE_QUEUED,
Contribution.STATE_PAUSED));
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
pagedListConfig);
pendingContributionList = livePagedListBuilder.build();
}
void getFailedContributions() {
final PagedList.Config pagedListConfig =
(new PagedList.Config.Builder())
.setPrefetchDistance(50)
.setPageSize(10).build();
Factory<Integer, Contribution> factory;
factory = repository.fetchContributionsWithStates(
Collections.singletonList(Contribution.STATE_FAILED));
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
pagedListConfig);
failedContributionList = livePagedListBuilder.build();
}
void getFailedAndPendingContributions() {
final PagedList.Config pagedListConfig =
(new PagedList.Config.Builder())
.setPrefetchDistance(50)
.setPageSize(10).build();
Factory<Integer, Contribution> factory;
factory = repository.fetchContributionsWithStates(
Arrays.asList(Contribution.STATE_IN_PROGRESS, Contribution.STATE_QUEUED,
Contribution.STATE_PAUSED, Contribution.STATE_FAILED));
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
pagedListConfig);
failedAndPendingContributionList = livePagedListBuilder.build();
}
} }

View file

@ -108,6 +108,8 @@ public class ContributionsFragment
LocationServiceManager locationManager; LocationServiceManager locationManager;
@Inject @Inject
NotificationController notificationController; NotificationController notificationController;
@Inject
ContributionController contributionController;
private CompositeDisposable compositeDisposable = new CompositeDisposable(); private CompositeDisposable compositeDisposable = new CompositeDisposable();
@ -298,6 +300,25 @@ public class ContributionsFragment
throwable -> Timber.e(throwable, "Error occurred while loading notifications"))); throwable -> Timber.e(throwable, "Error occurred while loading notifications")));
} }
public void setUploadIconVisibility() {
contributionController.getFailedAndPendingContributions();
contributionController.failedAndPendingContributionList.observe(getViewLifecycleOwner(), list -> {
updateUploadIcon(list.size());
});
}
public void setUploadIconCount() {
contributionController.getPendingContributions();
contributionController.pendingContributionList.observe(getViewLifecycleOwner(),
list -> {
updatePendingIcon(list.size());
});
contributionController.getFailedContributions();
contributionController.failedContributionList.observe(getViewLifecycleOwner(), list -> {
updateErrorIcon(list.size());
});
}
public void scrollToTop() { public void scrollToTop() {
if (contributionsListFragment != null) { if (contributionsListFragment != null) {
contributionsListFragment.scrollToTop(); contributionsListFragment.scrollToTop();
@ -499,6 +520,8 @@ public class ContributionsFragment
if(!isUserProfile) { if(!isUserProfile) {
setNotificationCount(); setNotificationCount();
fetchCampaigns(); fetchCampaigns();
setUploadIconVisibility();
setUploadIconCount();
} }
} }
mSensorManager.registerListener(this, mLight, SensorManager.SENSOR_DELAY_UI); mSensorManager.registerListener(this, mLight, SensorManager.SENSOR_DELAY_UI);
@ -688,7 +711,6 @@ public class ContributionsFragment
} }
} }
@Override
public void updatePendingIcon(int pendingCount) { public void updatePendingIcon(int pendingCount) {
if (pendingUploadsCountTextView != null){ if (pendingUploadsCountTextView != null){
if (pendingCount != 0){ if (pendingCount != 0){
@ -700,7 +722,6 @@ public class ContributionsFragment
} }
} }
@Override
public void updateErrorIcon(int errorCount) { public void updateErrorIcon(int errorCount) {
if (uploadsErrorTextView != null){ if (uploadsErrorTextView != null){
if (errorCount != 0){ if (errorCount != 0){
@ -712,7 +733,6 @@ public class ContributionsFragment
} }
} }
@Override
public void updateUploadIcon(int count) { public void updateUploadIcon(int count) {
if (pendingUploadsImageView != null){ if (pendingUploadsImageView != null){
if (count != 0){ if (count != 0){

View file

@ -214,20 +214,6 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
contributionsListPresenter.setup(userName, contributionsListPresenter.setup(userName,
Objects.equals(sessionManager.getUserName(), userName)); Objects.equals(sessionManager.getUserName(), userName));
contributionsListPresenter.getPendingContributions();
contributionsListPresenter.pendingContributionList.observe(getViewLifecycleOwner(), list -> {
pendingUploadsCount = list.size();
callback.updatePendingIcon(pendingUploadsCount);
});
contributionsListPresenter.getFailedContributions();
contributionsListPresenter.failedContributionList.observe(getViewLifecycleOwner(), list -> {
uploadErrorCount = list.size();
callback.updateErrorIcon(uploadErrorCount);
});
contributionsListPresenter.getFailedAndPendingContributions();
contributionsListPresenter.failedAndPendingContributionList.observe(getViewLifecycleOwner(), list -> {
callback.updateUploadIcon(list.size());
});
contributionsListPresenter.contributionList.observe(getViewLifecycleOwner(), list -> { contributionsListPresenter.contributionList.observe(getViewLifecycleOwner(), list -> {
contributionsSize = list.size(); contributionsSize = list.size();
adapter.submitList(list); adapter.submitList(list);
@ -509,10 +495,5 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
// Notify the viewpager that number of items have changed. // Notify the viewpager that number of items have changed.
void viewPagerNotifyDataSetChanged(); void viewPagerNotifyDataSetChanged();
void updatePendingIcon(int pendingCount);
void updateErrorIcon(int errorCount);
void updateUploadIcon(int count);
} }
} }

View file

@ -28,9 +28,6 @@ public class ContributionsListPresenter implements UserActionListener {
private final ContributionsRemoteDataSource contributionsRemoteDataSource; private final ContributionsRemoteDataSource contributionsRemoteDataSource;
LiveData<PagedList<Contribution>> contributionList; LiveData<PagedList<Contribution>> contributionList;
LiveData<PagedList<Contribution>> pendingContributionList;
LiveData<PagedList<Contribution>> failedContributionList;
LiveData<PagedList<Contribution>> failedAndPendingContributionList;
@Inject @Inject
ContributionsListPresenter( ContributionsListPresenter(
@ -96,48 +93,4 @@ public class ContributionsListPresenter implements UserActionListener {
contributionBoundaryCallback.dispose(); contributionBoundaryCallback.dispose();
} }
void getPendingContributions() {
final PagedList.Config pagedListConfig =
(new PagedList.Config.Builder())
.setPrefetchDistance(50)
.setPageSize(10).build();
Factory<Integer, Contribution> factory;
factory = repository.fetchContributionsWithStates(
Arrays.asList(Contribution.STATE_IN_PROGRESS, Contribution.STATE_QUEUED,
Contribution.STATE_PAUSED));
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
pagedListConfig);
pendingContributionList = livePagedListBuilder.build();
}
void getFailedContributions() {
final PagedList.Config pagedListConfig =
(new PagedList.Config.Builder())
.setPrefetchDistance(50)
.setPageSize(10).build();
Factory<Integer, Contribution> factory;
factory = repository.fetchContributionsWithStates(
Collections.singletonList(Contribution.STATE_FAILED));
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
pagedListConfig);
failedContributionList = livePagedListBuilder.build();
}
void getFailedAndPendingContributions() {
final PagedList.Config pagedListConfig =
(new PagedList.Config.Builder())
.setPrefetchDistance(50)
.setPageSize(10).build();
Factory<Integer, Contribution> factory;
factory = repository.fetchContributionsWithStates(
Arrays.asList(Contribution.STATE_IN_PROGRESS, Contribution.STATE_QUEUED,
Contribution.STATE_PAUSED, Contribution.STATE_FAILED));
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
pagedListConfig);
failedAndPendingContributionList = livePagedListBuilder.build();
}
} }