mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
fix: null context issue by removing context getter override (#6218)
Refactored related code to resolve build issues
This commit is contained in:
parent
d11439f85d
commit
32d485cc51
4 changed files with 23 additions and 25 deletions
|
|
@ -10,7 +10,7 @@ interface ContributionsContract {
|
||||||
|
|
||||||
interface View {
|
interface View {
|
||||||
fun showMessage(localizedMessage: String)
|
fun showMessage(localizedMessage: String)
|
||||||
fun getContext(): Context
|
fun getContext(): Context?
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UserActionListener : BasePresenter<View> {
|
interface UserActionListener : BasePresenter<View> {
|
||||||
|
|
|
||||||
|
|
@ -74,12 +74,9 @@ import java.util.Date
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Named
|
import javax.inject.Named
|
||||||
|
|
||||||
class ContributionsFragment
|
class ContributionsFragment : CommonsDaggerSupportFragment(), FragmentManager.OnBackStackChangedListener,
|
||||||
|
|
||||||
: CommonsDaggerSupportFragment(), FragmentManager.OnBackStackChangedListener,
|
|
||||||
LocationUpdateListener, MediaDetailProvider, SensorEventListener, ICampaignsView,
|
LocationUpdateListener, MediaDetailProvider, SensorEventListener, ICampaignsView,
|
||||||
ContributionsContract.View,
|
ContributionsContract.View, ContributionsListFragment.Callback {
|
||||||
ContributionsListFragment.Callback {
|
|
||||||
@JvmField
|
@JvmField
|
||||||
@Inject
|
@Inject
|
||||||
@Named("default_preferences")
|
@Named("default_preferences")
|
||||||
|
|
@ -307,11 +304,13 @@ class ContributionsFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
notification.setOnClickListener { view: View? ->
|
notification.setOnClickListener { view: View? ->
|
||||||
|
context?.let {
|
||||||
startYourself(
|
startYourself(
|
||||||
context, "unread"
|
it, "unread"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
fun setNotificationCount() {
|
fun setNotificationCount() {
|
||||||
|
|
@ -889,7 +888,8 @@ class ContributionsFragment
|
||||||
* this function updates the number of contributions
|
* this function updates the number of contributions
|
||||||
*/
|
*/
|
||||||
fun upDateUploadCount() {
|
fun upDateUploadCount() {
|
||||||
WorkManager.getInstance(context)
|
context?.let {
|
||||||
|
WorkManager.getInstance(it)
|
||||||
.getWorkInfosForUniqueWorkLiveData(UploadWorker::class.java.simpleName).observe(
|
.getWorkInfosForUniqueWorkLiveData(UploadWorker::class.java.simpleName).observe(
|
||||||
viewLifecycleOwner
|
viewLifecycleOwner
|
||||||
) { workInfos: List<WorkInfo?> ->
|
) { workInfos: List<WorkInfo?> ->
|
||||||
|
|
@ -898,6 +898,7 @@ class ContributionsFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -953,7 +954,7 @@ class ContributionsFragment
|
||||||
Timber.d("Skipping re-upload for non-failed %s", contribution.toString())
|
Timber.d("Skipping re-upload for non-failed %s", contribution.toString())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showLongToast(context, R.string.this_function_needs_network_connection)
|
context?.let { showLongToast(it, R.string.this_function_needs_network_connection) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,9 +80,11 @@ class ContributionsPresenter @Inject internal constructor(
|
||||||
.save(contribution)
|
.save(contribution)
|
||||||
.subscribeOn(ioThreadScheduler)
|
.subscribeOn(ioThreadScheduler)
|
||||||
.subscribe {
|
.subscribe {
|
||||||
|
view!!.getContext()?.applicationContext?.let {
|
||||||
makeOneTimeWorkRequest(
|
makeOneTimeWorkRequest(
|
||||||
view!!.getContext().applicationContext, ExistingWorkPolicy.KEEP
|
it, ExistingWorkPolicy.KEEP
|
||||||
)
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,9 +63,4 @@ abstract class CommonsDaggerSupportFragment : Fragment(), HasSupportFragmentInje
|
||||||
|
|
||||||
return getInstance(activity.applicationContext)
|
return getInstance(activity.applicationContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure getContext() returns a non-null Context
|
|
||||||
override fun getContext(): Context {
|
|
||||||
return super.getContext() ?: throw IllegalStateException("Context is null")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue