mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
done
This commit is contained in:
parent
6ba3c60efc
commit
065eb0fc3c
2 changed files with 92 additions and 0 deletions
|
|
@ -1,16 +1,20 @@
|
||||||
package fr.free.nrw.commons.contributions
|
package fr.free.nrw.commons.contributions
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
import androidx.paging.DataSource
|
import androidx.paging.DataSource
|
||||||
import androidx.paging.LivePagedListBuilder
|
import androidx.paging.LivePagedListBuilder
|
||||||
import androidx.paging.PagedList
|
import androidx.paging.PagedList
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
import fr.free.nrw.commons.auth.SessionManager
|
||||||
import fr.free.nrw.commons.di.CommonsApplicationModule
|
import fr.free.nrw.commons.di.CommonsApplicationModule
|
||||||
import io.reactivex.Scheduler
|
import io.reactivex.Scheduler
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Named
|
import javax.inject.Named
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The presenter class for Contributions
|
* The presenter class for Contributions
|
||||||
*/
|
*/
|
||||||
|
|
@ -22,8 +26,15 @@ class ContributionsListPresenter @Inject internal constructor(
|
||||||
) : ContributionsListContract.UserActionListener {
|
) : ContributionsListContract.UserActionListener {
|
||||||
private val compositeDisposable = CompositeDisposable()
|
private val compositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var sessionManager: SessionManager
|
||||||
|
|
||||||
var contributionList: LiveData<PagedList<Contribution>>? = null
|
var contributionList: LiveData<PagedList<Contribution>>? = null
|
||||||
|
|
||||||
|
private val liveData = MutableLiveData<List<Contribution>>()
|
||||||
|
|
||||||
|
private val existingContributions: MutableList<Contribution> = ArrayList()
|
||||||
|
|
||||||
override fun onAttachView(view: ContributionsListContract.View) {
|
override fun onAttachView(view: ContributionsListContract.View) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,6 +77,13 @@ class ContributionsListPresenter @Inject internal constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
contributionList = livePagedListBuilder.build()
|
contributionList = livePagedListBuilder.build()
|
||||||
|
contributionList!!.observeForever { pagedList ->
|
||||||
|
pagedList?.let {
|
||||||
|
existingContributions.clear()
|
||||||
|
existingContributions.addAll(it)
|
||||||
|
liveData.value = existingContributions // Update liveData with the latest list
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDetachView() {
|
override fun onDetachView() {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.animation.AnimationUtils
|
||||||
|
import android.widget.ImageView
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.work.ExistingWorkPolicy
|
import androidx.work.ExistingWorkPolicy
|
||||||
|
|
@ -16,6 +18,7 @@ import fr.free.nrw.commons.WelcomeActivity
|
||||||
import fr.free.nrw.commons.auth.SessionManager
|
import fr.free.nrw.commons.auth.SessionManager
|
||||||
import fr.free.nrw.commons.bookmarks.BookmarkFragment
|
import fr.free.nrw.commons.bookmarks.BookmarkFragment
|
||||||
import fr.free.nrw.commons.contributions.ContributionsFragment.Companion.newInstance
|
import fr.free.nrw.commons.contributions.ContributionsFragment.Companion.newInstance
|
||||||
|
import fr.free.nrw.commons.databinding.FragmentContributionsListBinding
|
||||||
import fr.free.nrw.commons.databinding.MainBinding
|
import fr.free.nrw.commons.databinding.MainBinding
|
||||||
import fr.free.nrw.commons.explore.ExploreFragment
|
import fr.free.nrw.commons.explore.ExploreFragment
|
||||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||||
|
|
@ -31,6 +34,7 @@ import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment
|
||||||
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment.NearbyParentFragmentInstanceReadyCallback
|
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment.NearbyParentFragmentInstanceReadyCallback
|
||||||
import fr.free.nrw.commons.notification.NotificationActivity.Companion.startYourself
|
import fr.free.nrw.commons.notification.NotificationActivity.Companion.startYourself
|
||||||
import fr.free.nrw.commons.notification.NotificationController
|
import fr.free.nrw.commons.notification.NotificationController
|
||||||
|
import fr.free.nrw.commons.profile.ProfileActivity
|
||||||
import fr.free.nrw.commons.quiz.QuizChecker
|
import fr.free.nrw.commons.quiz.QuizChecker
|
||||||
import fr.free.nrw.commons.settings.SettingsFragment
|
import fr.free.nrw.commons.settings.SettingsFragment
|
||||||
import fr.free.nrw.commons.theme.BaseActivity
|
import fr.free.nrw.commons.theme.BaseActivity
|
||||||
|
|
@ -39,8 +43,10 @@ import fr.free.nrw.commons.upload.worker.WorkRequestHelper.Companion.makeOneTime
|
||||||
import fr.free.nrw.commons.utils.ViewUtilWrapper
|
import fr.free.nrw.commons.utils.ViewUtilWrapper
|
||||||
import io.reactivex.Completable
|
import io.reactivex.Completable
|
||||||
import io.reactivex.schedulers.Schedulers
|
import io.reactivex.schedulers.Schedulers
|
||||||
|
import org.apache.commons.codec.binary.StringUtils
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
|
import java.util.Objects
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Named
|
import javax.inject.Named
|
||||||
|
|
||||||
|
|
@ -58,6 +64,12 @@ class MainActivity : BaseActivity(), FragmentManager.OnBackStackChangedListener
|
||||||
@Inject
|
@Inject
|
||||||
var contributionDao: ContributionDao? = null
|
var contributionDao: ContributionDao? = null
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var contributionsListPresenter: ContributionsListPresenter
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var dataSource: ContributionsRemoteDataSource
|
||||||
|
|
||||||
private var contributionsFragment: ContributionsFragment? = null
|
private var contributionsFragment: ContributionsFragment? = null
|
||||||
private var nearbyParentFragment: NearbyParentFragment? = null
|
private var nearbyParentFragment: NearbyParentFragment? = null
|
||||||
private var exploreFragment: ExploreFragment? = null
|
private var exploreFragment: ExploreFragment? = null
|
||||||
|
|
@ -96,6 +108,9 @@ class MainActivity : BaseActivity(), FragmentManager.OnBackStackChangedListener
|
||||||
|
|
||||||
var tabLayout: NavTabLayout? = null
|
var tabLayout: NavTabLayout? = null
|
||||||
|
|
||||||
|
private var refresh: FragmentContributionsListBinding? = null
|
||||||
|
|
||||||
|
private var userName: String? = null
|
||||||
|
|
||||||
override fun onSupportNavigateUp(): Boolean {
|
override fun onSupportNavigateUp(): Boolean {
|
||||||
if (activeFragment == ActiveFragment.CONTRIBUTIONS) {
|
if (activeFragment == ActiveFragment.CONTRIBUTIONS) {
|
||||||
|
|
@ -150,6 +165,14 @@ after opening the app.
|
||||||
loadFragment(newInstance(), false)
|
loadFragment(newInstance(), false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
refresh = FragmentContributionsListBinding.inflate(getLayoutInflater());
|
||||||
|
if (getIntent().getExtras() != null) {
|
||||||
|
userName = getIntent().getExtras()?.getString(ProfileActivity.KEY_USERNAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userName.isNullOrEmpty()) {
|
||||||
|
userName = sessionManager?.userName
|
||||||
|
}
|
||||||
setUpPager()
|
setUpPager()
|
||||||
/**
|
/**
|
||||||
* Ask the user for media location access just after login
|
* Ask the user for media location access just after login
|
||||||
|
|
@ -455,10 +478,44 @@ after opening the app.
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
R.id.menu_refresh-> {
|
||||||
|
return true
|
||||||
|
}
|
||||||
else -> return super.onOptionsItemSelected(item)
|
else -> return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
|
val inflater = menuInflater
|
||||||
|
inflater.inflate(R.menu.contribution_activity_notification_menu, menu)
|
||||||
|
|
||||||
|
val refreshItem = menu.findItem(R.id.menu_refresh)
|
||||||
|
refreshItem?.actionView?.let { actionView ->
|
||||||
|
val refreshIcon = actionView.findViewById<ImageView>(R.id.refresh_icon)
|
||||||
|
refreshIcon?.setOnClickListener { v ->
|
||||||
|
v.clearAnimation()
|
||||||
|
val rotateAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate)
|
||||||
|
v.startAnimation(rotateAnimation)
|
||||||
|
|
||||||
|
// Initialize userName if it's null
|
||||||
|
val localUserName = userName ?: sessionManager?.userName
|
||||||
|
|
||||||
|
if (sessionManager?.userName == localUserName) {
|
||||||
|
refresh?.swipeRefreshLayout?.let { swipeRefresh ->
|
||||||
|
swipeRefresh.isRefreshing = true
|
||||||
|
swipeRefresh.isEnabled = true
|
||||||
|
contributionsListPresenter?.refreshList(swipeRefresh)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
refresh?.swipeRefreshLayout?.isEnabled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fun centerMapToPlace(place: Place?) {
|
fun centerMapToPlace(place: Place?) {
|
||||||
setSelectedItemId(NavTab.NEARBY.code())
|
setSelectedItemId(NavTab.NEARBY.code())
|
||||||
nearbyParentFragment!!.setNearbyParentFragmentInstanceReadyCallback(
|
nearbyParentFragment!!.setNearbyParentFragmentInstanceReadyCallback(
|
||||||
|
|
@ -516,6 +573,23 @@ after opening the app.
|
||||||
}
|
}
|
||||||
|
|
||||||
retryAllFailedUploads()
|
retryAllFailedUploads()
|
||||||
|
//check for new contributions
|
||||||
|
// Initialize userName if it's null
|
||||||
|
if (userName == null) {
|
||||||
|
userName = sessionManager?.userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Objects.equals(sessionManager?.userName, userName)) {
|
||||||
|
if (refresh != null && refresh!!.swipeRefreshLayout != null) {
|
||||||
|
refresh!!.swipeRefreshLayout.setRefreshing(true);
|
||||||
|
refresh!!.swipeRefreshLayout.setEnabled(true);
|
||||||
|
contributionsListPresenter?.refreshList(refresh!!.swipeRefreshLayout);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (refresh != null && refresh!!.swipeRefreshLayout != null) {
|
||||||
|
refresh!!.swipeRefreshLayout.setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue