mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
fix :Upload count or number of contribution does not get updated when media is successful uploaded (#4399)
* * fix:Number of Contributions not updated * Add javadocs * minor changes * made minor changes
This commit is contained in:
parent
2a2d2879a9
commit
13528bcabd
2 changed files with 26 additions and 2 deletions
|
|
@ -9,6 +9,7 @@ import android.annotation.SuppressLint;
|
|||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
|
|
@ -33,6 +34,8 @@ import fr.free.nrw.commons.theme.BaseActivity;
|
|||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import androidx.work.WorkInfo;
|
||||
import androidx.work.WorkManager;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
|
|
@ -60,6 +63,7 @@ import fr.free.nrw.commons.notification.Notification;
|
|||
import fr.free.nrw.commons.notification.NotificationActivity;
|
||||
import fr.free.nrw.commons.notification.NotificationController;
|
||||
import fr.free.nrw.commons.theme.BaseActivity;
|
||||
import fr.free.nrw.commons.upload.worker.UploadWorker;
|
||||
import fr.free.nrw.commons.utils.ConfigUtils;
|
||||
import fr.free.nrw.commons.utils.DialogUtil;
|
||||
import fr.free.nrw.commons.utils.NetworkUtils;
|
||||
|
|
@ -154,7 +158,7 @@ public class ContributionsFragment
|
|||
}
|
||||
|
||||
initFragments();
|
||||
|
||||
upDateUploadCount();
|
||||
if(shouldShowMediaDetailsFragment){
|
||||
showMediaDetailPagerFragment();
|
||||
}else{
|
||||
|
|
@ -644,6 +648,21 @@ public class ContributionsFragment
|
|||
return mediaDetailPagerFragment;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* this function updates the number of contributions
|
||||
*/
|
||||
void upDateUploadCount() {
|
||||
WorkManager.getInstance(getContext())
|
||||
.getWorkInfosForUniqueWorkLiveData(UploadWorker.class.getSimpleName()).observe(
|
||||
getViewLifecycleOwner(), workInfos -> {
|
||||
if (workInfos.size() > 0) {
|
||||
setUploadCount();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reload media detail fragment once media is nominated
|
||||
*
|
||||
|
|
@ -658,7 +677,7 @@ public class ContributionsFragment
|
|||
showMediaDetailPagerFragment();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// click listener to toggle description that means uses can press the limited connection
|
||||
// banner and description will hide. Tap again to show description.
|
||||
private View.OnClickListener toggleDescriptionListener = new View.OnClickListener() {
|
||||
|
|
@ -674,5 +693,6 @@ public class ContributionsFragment
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import android.graphics.BitmapFactory
|
|||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.work.CoroutineWorker
|
||||
import androidx.work.Data
|
||||
import androidx.work.WorkerParameters
|
||||
import com.google.gson.Gson
|
||||
import com.mapbox.mapboxsdk.plugins.localization.BuildConfig
|
||||
|
|
@ -142,6 +143,7 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
|||
}
|
||||
|
||||
override suspend fun doWork(): Result {
|
||||
var countUpload = 0
|
||||
notificationManager = NotificationManagerCompat.from(appContext)
|
||||
val processingUploads = getNotificationBuilder(
|
||||
CommonsApplication.NOTIFICATION_CHANNEL_ID_ALL
|
||||
|
|
@ -192,6 +194,8 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
|
|||
contribution.transferred = 0
|
||||
contribution.state = Contribution.STATE_IN_PROGRESS
|
||||
contributionDao.saveSynchronous(contribution)
|
||||
setProgressAsync(Data.Builder().putInt("progress", countUpload).build())
|
||||
countUpload++
|
||||
uploadContribution(contribution = contribution)
|
||||
}
|
||||
}.collect()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue