mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Fixed large uploads issue
This commit is contained in:
parent
0b5fb6d7b0
commit
1e032e6bdf
9 changed files with 94 additions and 47 deletions
|
|
@ -23,6 +23,11 @@ public abstract class ContributionDao {
|
|||
@Query("SELECT * FROM contribution WHERE state = -1 ORDER BY media_dateUploaded DESC")
|
||||
abstract DataSource.Factory<Integer, Contribution> fetchContributionsWithStateCompleted();
|
||||
|
||||
@Query("SELECT * FROM contribution WHERE state IN (2, 3, 4) ORDER BY media_dateUploaded DESC")
|
||||
abstract DataSource.Factory<Integer, Contribution> fetchContributionsWithStateInProgress();
|
||||
|
||||
@Query("SELECT * FROM contribution WHERE state = 1 ORDER BY media_dateUploaded DESC")
|
||||
abstract DataSource.Factory<Integer, Contribution> fetchContributionsWithStateFailed();
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
public abstract void saveSynchronous(Contribution contribution);
|
||||
|
|
|
|||
|
|
@ -686,7 +686,7 @@ public class ContributionsFragment
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateUploadsIcon(int pendingCount, int errorCount) {
|
||||
public void updatePendingIcon(int pendingCount) {
|
||||
if (pendingUploadsCountTextView != null){
|
||||
if (pendingCount != 0){
|
||||
pendingUploadsCountTextView.setVisibility(View.VISIBLE);
|
||||
|
|
@ -694,14 +694,18 @@ public class ContributionsFragment
|
|||
}else {
|
||||
pendingUploadsCountTextView.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateErrorIcon(int errorCount) {
|
||||
if (uploadsErrorTextView != null){
|
||||
if (errorCount != 0){
|
||||
uploadsErrorTextView.setVisibility(View.VISIBLE);
|
||||
uploadsErrorTextView.setText(String.valueOf(errorCount));
|
||||
}else {
|
||||
uploadsErrorTextView.setVisibility(View.GONE);
|
||||
uploadsErrorTextView.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver;
|
|||
import androidx.recyclerview.widget.RecyclerView.ItemAnimator;
|
||||
import androidx.recyclerview.widget.RecyclerView.OnItemTouchListener;
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator;
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.Media;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
|
|
@ -43,14 +42,12 @@ import fr.free.nrw.commons.profile.ProfileActivity;
|
|||
import fr.free.nrw.commons.utils.DialogUtil;
|
||||
import fr.free.nrw.commons.utils.SystemThemeUtils;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import fr.free.nrw.commons.wikidata.model.WikiSite;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -217,22 +214,15 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
|
||||
contributionsListPresenter.setup(userName,
|
||||
Objects.equals(sessionManager.getUserName(), userName));
|
||||
contributionsListPresenter.getTotalContribution(userName);
|
||||
contributionsListPresenter.totalContributionList.observe(getViewLifecycleOwner(), list -> {
|
||||
uploadErrorCount = 0;
|
||||
pendingUploadsCount = 0;
|
||||
for (int i = 0; i< list.size(); i++){
|
||||
if (list.get(i) != null){
|
||||
if (list.get(i).getState() != Contribution.STATE_COMPLETED){
|
||||
if (list.get(i).getState() == Contribution.STATE_FAILED){
|
||||
uploadErrorCount++;
|
||||
}else {
|
||||
pendingUploadsCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
callback.updateUploadsIcon(pendingUploadsCount, uploadErrorCount);
|
||||
contributionsListPresenter.getPendingContributions(userName);
|
||||
contributionsListPresenter.pendingContributionList.observe(getViewLifecycleOwner(), list -> {
|
||||
pendingUploadsCount = list.size();
|
||||
callback.updatePendingIcon(pendingUploadsCount);
|
||||
});
|
||||
contributionsListPresenter.getFailedContributions(userName);
|
||||
contributionsListPresenter.failedContributionList.observe(getViewLifecycleOwner(), list -> {
|
||||
uploadErrorCount = list.size();
|
||||
callback.updateErrorIcon(uploadErrorCount);
|
||||
});
|
||||
contributionsListPresenter.contributionList.observe(getViewLifecycleOwner(), list -> {
|
||||
contributionsSize = list.size();
|
||||
|
|
@ -515,6 +505,8 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
|||
// Notify the viewpager that number of items have changed.
|
||||
void viewPagerNotifyDataSetChanged();
|
||||
|
||||
void updateUploadsIcon(int pendingCount, int errorCount);
|
||||
void updatePendingIcon(int pendingCount);
|
||||
|
||||
void updateErrorIcon(int errorCount);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ public class ContributionsListPresenter implements UserActionListener {
|
|||
private final ContributionsRemoteDataSource contributionsRemoteDataSource;
|
||||
|
||||
LiveData<PagedList<Contribution>> contributionList;
|
||||
LiveData<PagedList<Contribution>> totalContributionList;
|
||||
LiveData<PagedList<Contribution>> pendingContributionList;
|
||||
LiveData<PagedList<Contribution>> failedContributionList;
|
||||
|
||||
@Inject
|
||||
ContributionsListPresenter(
|
||||
|
|
@ -90,7 +91,7 @@ public class ContributionsListPresenter implements UserActionListener {
|
|||
contributionBoundaryCallback.dispose();
|
||||
}
|
||||
|
||||
void getTotalContribution(String userName) {
|
||||
void getPendingContributions(String userName) {
|
||||
final PagedList.Config pagedListConfig =
|
||||
(new PagedList.Config.Builder())
|
||||
.setPrefetchDistance(50)
|
||||
|
|
@ -99,13 +100,31 @@ public class ContributionsListPresenter implements UserActionListener {
|
|||
boolean shouldSetBoundaryCallback;
|
||||
contributionBoundaryCallback.setUserName(userName);
|
||||
shouldSetBoundaryCallback = true;
|
||||
factory = repository.fetchContributions();
|
||||
factory = repository.fetchInProgressContributions();
|
||||
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
|
||||
pagedListConfig);
|
||||
if (shouldSetBoundaryCallback) {
|
||||
livePagedListBuilder.setBoundaryCallback(contributionBoundaryCallback);
|
||||
}
|
||||
totalContributionList = livePagedListBuilder.build();
|
||||
pendingContributionList = livePagedListBuilder.build();
|
||||
}
|
||||
|
||||
void getFailedContributions(String userName) {
|
||||
final PagedList.Config pagedListConfig =
|
||||
(new PagedList.Config.Builder())
|
||||
.setPrefetchDistance(50)
|
||||
.setPageSize(10).build();
|
||||
Factory<Integer, Contribution> factory;
|
||||
boolean shouldSetBoundaryCallback;
|
||||
contributionBoundaryCallback.setUserName(userName);
|
||||
shouldSetBoundaryCallback = true;
|
||||
factory = repository.fetchFailedContributions();
|
||||
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
|
||||
pagedListConfig);
|
||||
if (shouldSetBoundaryCallback) {
|
||||
livePagedListBuilder.setBoundaryCallback(contributionBoundaryCallback);
|
||||
}
|
||||
failedContributionList = livePagedListBuilder.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,14 @@ class ContributionsLocalDataSource {
|
|||
return contributionDao.fetchContributionsWithStateCompleted();
|
||||
}
|
||||
|
||||
public Factory<Integer, Contribution> getInProgressContributions() {
|
||||
return contributionDao.fetchContributionsWithStateInProgress();
|
||||
}
|
||||
|
||||
public Factory<Integer, Contribution> getFailedContributions() {
|
||||
return contributionDao.fetchContributionsWithStateFailed();
|
||||
}
|
||||
|
||||
public Single<List<Long>> saveContributions(final List<Contribution> contributions) {
|
||||
final List<Contribution> contributionList = new ArrayList<>();
|
||||
for(final Contribution contribution: contributions) {
|
||||
|
|
|
|||
|
|
@ -53,6 +53,14 @@ public class ContributionsRepository {
|
|||
return localDataSource.getCompletedContributions();
|
||||
}
|
||||
|
||||
public Factory<Integer, Contribution> fetchInProgressContributions() {
|
||||
return localDataSource.getInProgressContributions();
|
||||
}
|
||||
|
||||
public Factory<Integer, Contribution> fetchFailedContributions() {
|
||||
return localDataSource.getFailedContributions();
|
||||
}
|
||||
|
||||
public Single<List<Long>> save(List<Contribution> contributions) {
|
||||
return localDataSource.saveContributions(contributions);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,25 +87,22 @@ class FailedUploadsFragment : CommonsDaggerSupportFragment(),PendingUploadsContr
|
|||
|
||||
fun initRecyclerView() {
|
||||
binding.failedUploadsRecyclerView.setLayoutManager(LinearLayoutManager(this.context))
|
||||
pendingUploadsPresenter!!.setup(
|
||||
userName,
|
||||
sessionManager!!.userName == userName
|
||||
)
|
||||
pendingUploadsPresenter!!.totalContributionList.observe(
|
||||
pendingUploadsPresenter!!.getFailedContributions(userName)
|
||||
pendingUploadsPresenter!!.failedContributionList.observe(
|
||||
viewLifecycleOwner
|
||||
) { list: PagedList<Contribution?> ->
|
||||
contributionsList = ArrayList()
|
||||
list.forEach {
|
||||
if (it != null) {
|
||||
if (it.state == Contribution.STATE_FAILED) {
|
||||
contributionsList.add(it)
|
||||
}
|
||||
contributionsList.add(it)
|
||||
}
|
||||
}
|
||||
if (contributionsList.size == 0) {
|
||||
if (list.size == 0) {
|
||||
uploadProgressActivity.setErrorIconsVisibility(false)
|
||||
binding.nofailedTextView.visibility = View.VISIBLE
|
||||
binding.failedUplaodsLl.visibility = View.GONE
|
||||
} else {
|
||||
uploadProgressActivity.setErrorIconsVisibility(true)
|
||||
binding.nofailedTextView.visibility = View.GONE
|
||||
binding.failedUplaodsLl.visibility = View.VISIBLE
|
||||
val adapter = FailedUploadsAdapter(contributionsList, this)
|
||||
|
|
|
|||
|
|
@ -131,18 +131,13 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
|||
}
|
||||
}
|
||||
}
|
||||
if (failedUploads == 0){
|
||||
uploadProgressActivity.setErrorIconsVisibility(false)
|
||||
}else{
|
||||
uploadProgressActivity.setErrorIconsVisibility(true)
|
||||
}
|
||||
if (contributionsList.size == 0) {
|
||||
if (contributionsSize == 0) {
|
||||
binding.nopendingTextView.visibility = View.VISIBLE
|
||||
binding.pendingUplaodsLl.visibility = View.GONE
|
||||
uploadProgressActivity.hidePendingIcons()
|
||||
} else {
|
||||
if (totalUploads == 0){
|
||||
totalUploads = contributionsList.size
|
||||
totalUploads = contributionsSize
|
||||
binding.progressBarPending.max = totalUploads
|
||||
}
|
||||
binding.nopendingTextView.visibility = View.GONE
|
||||
|
|
@ -167,9 +162,9 @@ class PendingUploadsFragment : CommonsDaggerSupportFragment(), PendingUploadsCon
|
|||
newContributionList.addAll(listOfRemoved)
|
||||
val adapter = PendingUploadsAdapter(newContributionList, this)
|
||||
binding.pendingUploadsRecyclerView.setAdapter(adapter)
|
||||
binding.progressTextView.setText((totalUploads-contributionsList.size).toString() + "/" + totalUploads + " uploaded")
|
||||
binding.progressBarPending.progress = totalUploads-contributionsList.size
|
||||
if (pausedOrQueuedUploads == contributionsList.size) {
|
||||
binding.progressTextView.setText((totalUploads-contributionsSize).toString() + "/" + totalUploads + " uploaded")
|
||||
binding.progressBarPending.progress = totalUploads-contributionsSize
|
||||
if (pausedOrQueuedUploads == contributionsSize) {
|
||||
uploadProgressActivity.setPausedIcon(true)
|
||||
}else{
|
||||
uploadProgressActivity.setPausedIcon(false)
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ public class PendingUploadsPresenter implements UserActionListener {
|
|||
private final ContributionsRemoteDataSource contributionsRemoteDataSource;
|
||||
|
||||
LiveData<PagedList<Contribution>> totalContributionList;
|
||||
LiveData<PagedList<Contribution>> failedContributionList;
|
||||
|
||||
@Inject
|
||||
PendingUploadsPresenter(
|
||||
|
|
@ -81,7 +82,7 @@ public class PendingUploadsPresenter implements UserActionListener {
|
|||
} else {
|
||||
contributionBoundaryCallback.setUserName(userName);
|
||||
shouldSetBoundaryCallback = true;
|
||||
factory = repository.fetchContributions();
|
||||
factory = repository.fetchInProgressContributions();
|
||||
}
|
||||
|
||||
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory, pagedListConfig);
|
||||
|
|
@ -92,6 +93,24 @@ public class PendingUploadsPresenter implements UserActionListener {
|
|||
totalContributionList = livePagedListBuilder.build();
|
||||
}
|
||||
|
||||
void getFailedContributions(String userName) {
|
||||
final PagedList.Config pagedListConfig =
|
||||
(new PagedList.Config.Builder())
|
||||
.setPrefetchDistance(50)
|
||||
.setPageSize(10).build();
|
||||
Factory<Integer, Contribution> factory;
|
||||
boolean shouldSetBoundaryCallback;
|
||||
contributionBoundaryCallback.setUserName(userName);
|
||||
shouldSetBoundaryCallback = true;
|
||||
factory = repository.fetchFailedContributions();
|
||||
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory,
|
||||
pagedListConfig);
|
||||
if (shouldSetBoundaryCallback) {
|
||||
livePagedListBuilder.setBoundaryCallback(contributionBoundaryCallback);
|
||||
}
|
||||
failedContributionList = livePagedListBuilder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachView(@NonNull View view) {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue