mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-30 14:23:55 +01:00
updated
This commit is contained in:
parent
d4d566b647
commit
df37f48eff
3 changed files with 10 additions and 26 deletions
|
|
@ -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.
|
* Check for new contributions by comparing the latest contribution identifier.
|
||||||
|
|
@ -140,31 +140,14 @@ public class ContributionsListPresenter implements UserActionListener {
|
||||||
contributionsRemoteDataSource.setUserName(sessionManager.getUserName());
|
contributionsRemoteDataSource.setUserName(sessionManager.getUserName());
|
||||||
|
|
||||||
contributionsRemoteDataSource.fetchLatestContributionIdentifier(latestIdentifier -> {
|
contributionsRemoteDataSource.fetchLatestContributionIdentifier(latestIdentifier -> {
|
||||||
|
Timber.d("Latest identifier: %s", latestIdentifier);
|
||||||
|
Timber.d("Last known identifier: %s", lastKnownIdentifier);
|
||||||
if (latestIdentifier != null && !latestIdentifier.equals(lastKnownIdentifier)) {
|
if (latestIdentifier != null && !latestIdentifier.equals(lastKnownIdentifier)) {
|
||||||
lastKnownIdentifier = latestIdentifier;
|
lastKnownIdentifier = latestIdentifier;
|
||||||
fetchAllContributions(); // Fetch the full list of contributions
|
contributionBoundaryCallback.refreshList(() -> Unit.INSTANCE);
|
||||||
}
|
}
|
||||||
return 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -76,7 +76,7 @@ constructor(
|
||||||
/**
|
/**
|
||||||
* Fetches the latest contribution identifier only
|
* Fetches the latest contribution identifier only
|
||||||
*/
|
*/
|
||||||
fun fetchLatestContributionIdentifier(callback: (String?) -> Unit) {
|
fun fetchLatestContributionIdentifier(callback: (Long?) -> Unit) {
|
||||||
if (userName.isNullOrEmpty()) {
|
if (userName.isNullOrEmpty()) {
|
||||||
Timber.e("Failed to fetch latest contribution: userName is null or empty")
|
Timber.e("Failed to fetch latest contribution: userName is null or empty")
|
||||||
return
|
return
|
||||||
|
|
@ -86,11 +86,13 @@ constructor(
|
||||||
compositeDisposable.add(
|
compositeDisposable.add(
|
||||||
mediaClient.getMediaListForUser(userName!!)
|
mediaClient.getMediaListForUser(userName!!)
|
||||||
.map { mediaList ->
|
.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)
|
.subscribeOn(ioThreadScheduler)
|
||||||
.subscribe({ latestIdentifier ->
|
.subscribe({ latestIdentifier ->
|
||||||
callback(latestIdentifier)
|
if (latestIdentifier != null) {
|
||||||
|
callback(latestIdentifier.toLong())
|
||||||
|
}
|
||||||
}) { error: Throwable ->
|
}) { error: Throwable ->
|
||||||
Timber.e("Failed to fetch latest contribution identifier: %s", error.message)
|
Timber.e("Failed to fetch latest contribution identifier: %s", error.message)
|
||||||
callback(null)
|
callback(null)
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import android.view.View;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.animation.AnimationUtils;
|
import android.view.animation.AnimationUtils;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.Toast;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
@ -457,7 +458,6 @@ public class MainActivity extends BaseActivity
|
||||||
ImageView refreshIcon = actionView.findViewById(R.id.refresh_icon);
|
ImageView refreshIcon = actionView.findViewById(R.id.refresh_icon);
|
||||||
if (refreshIcon != null) {
|
if (refreshIcon != null) {
|
||||||
refreshIcon.setOnClickListener(v -> {
|
refreshIcon.setOnClickListener(v -> {
|
||||||
// Clear previous animation and start new one
|
|
||||||
v.clearAnimation();
|
v.clearAnimation();
|
||||||
Animation rotateAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate);
|
Animation rotateAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate);
|
||||||
v.startAnimation(rotateAnimation);
|
v.startAnimation(rotateAnimation);
|
||||||
|
|
@ -472,7 +472,6 @@ public class MainActivity extends BaseActivity
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void centerMapToPlace(Place place) {
|
public void centerMapToPlace(Place place) {
|
||||||
setSelectedItemId(NavTab.NEARBY.code());
|
setSelectedItemId(NavTab.NEARBY.code());
|
||||||
nearbyParentFragment.setNearbyParentFragmentInstanceReadyCallback(
|
nearbyParentFragment.setNearbyParentFragmentInstanceReadyCallback(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue