This commit is contained in:
Sujal-Gupta-SG 2025-01-26 17:09:33 +05:30
parent d4d566b647
commit df37f48eff
3 changed files with 10 additions and 26 deletions

View file

@ -129,7 +129,7 @@ public class ContributionsListPresenter implements UserActionListener {
});
}
private String lastKnownIdentifier = null; // Declare and initialize
private long lastKnownIdentifier ; // Declare and initialize
/**
* Check for new contributions by comparing the latest contribution identifier.
@ -140,31 +140,14 @@ public class ContributionsListPresenter implements UserActionListener {
contributionsRemoteDataSource.setUserName(sessionManager.getUserName());
contributionsRemoteDataSource.fetchLatestContributionIdentifier(latestIdentifier -> {
Timber.d("Latest identifier: %s", latestIdentifier);
Timber.d("Last known identifier: %s", lastKnownIdentifier);
if (latestIdentifier != null && !latestIdentifier.equals(lastKnownIdentifier)) {
lastKnownIdentifier = latestIdentifier;
fetchAllContributions(); // Fetch the full list of contributions
contributionBoundaryCallback.refreshList(() -> Unit.INSTANCE);
}
return Unit.INSTANCE;
});
}
/**
* Fetch new contributions from the server and append them to the existing list.
*/
void fetchAllContributions() {
contributionsRemoteDataSource.fetchContributions(
new ContributionsRemoteDataSource.LoadCallback<>() {
@Override
public void onResult(List<Contribution> newContributions) {
if (newContributions != null && !newContributions.isEmpty()) {
existingContributions.clear();
existingContributions.addAll(newContributions);
liveData.postValue(
existingContributions); // Update liveData with the new list
}
}
});
}
}

View file

@ -76,7 +76,7 @@ constructor(
/**
* Fetches the latest contribution identifier only
*/
fun fetchLatestContributionIdentifier(callback: (String?) -> Unit) {
fun fetchLatestContributionIdentifier(callback: (Long?) -> Unit) {
if (userName.isNullOrEmpty()) {
Timber.e("Failed to fetch latest contribution: userName is null or empty")
return
@ -86,11 +86,13 @@ constructor(
compositeDisposable.add(
mediaClient.getMediaListForUser(userName!!)
.map { mediaList ->
mediaList.firstOrNull()?.pageId.toString() // Extract the first contribution's pageId
mediaList.firstOrNull()?.pageId // Extract the first contribution's pageId as Long
}
.subscribeOn(ioThreadScheduler)
.subscribe({ latestIdentifier ->
callback(latestIdentifier)
if (latestIdentifier != null) {
callback(latestIdentifier.toLong())
}
}) { error: Throwable ->
Timber.e("Failed to fetch latest contribution identifier: %s", error.message)
callback(null)

View file

@ -15,6 +15,7 @@ import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
@ -457,7 +458,6 @@ public class MainActivity extends BaseActivity
ImageView refreshIcon = actionView.findViewById(R.id.refresh_icon);
if (refreshIcon != null) {
refreshIcon.setOnClickListener(v -> {
// Clear previous animation and start new one
v.clearAnimation();
Animation rotateAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate);
v.startAnimation(rotateAnimation);
@ -472,7 +472,6 @@ public class MainActivity extends BaseActivity
return true;
}
public void centerMapToPlace(Place place) {
setSelectedItemId(NavTab.NEARBY.code());
nearbyParentFragment.setNearbyParentFragmentInstanceReadyCallback(