fix: null context issue by removing context getter override (#6218)

Refactored related code to resolve build issues
This commit is contained in:
Rohit Verma 2025-03-08 18:32:28 +05:30 committed by GitHub
parent d11439f85d
commit 32d485cc51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 25 deletions

View file

@ -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> {

View file

@ -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) }
} }
} }

View file

@ -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
) )
}
}) })
} }
} }

View file

@ -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")
}
} }