mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +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 {
|
||||
fun showMessage(localizedMessage: String)
|
||||
fun getContext(): Context
|
||||
fun getContext(): Context?
|
||||
}
|
||||
|
||||
interface UserActionListener : BasePresenter<View> {
|
||||
|
|
|
|||
|
|
@ -74,12 +74,9 @@ import java.util.Date
|
|||
import javax.inject.Inject
|
||||
import javax.inject.Named
|
||||
|
||||
class ContributionsFragment
|
||||
|
||||
: CommonsDaggerSupportFragment(), FragmentManager.OnBackStackChangedListener,
|
||||
class ContributionsFragment : CommonsDaggerSupportFragment(), FragmentManager.OnBackStackChangedListener,
|
||||
LocationUpdateListener, MediaDetailProvider, SensorEventListener, ICampaignsView,
|
||||
ContributionsContract.View,
|
||||
ContributionsListFragment.Callback {
|
||||
ContributionsContract.View, ContributionsListFragment.Callback {
|
||||
@JvmField
|
||||
@Inject
|
||||
@Named("default_preferences")
|
||||
|
|
@ -307,11 +304,13 @@ class ContributionsFragment
|
|||
}
|
||||
}
|
||||
notification.setOnClickListener { view: View? ->
|
||||
context?.let {
|
||||
startYourself(
|
||||
context, "unread"
|
||||
it, "unread"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
fun setNotificationCount() {
|
||||
|
|
@ -889,7 +888,8 @@ class ContributionsFragment
|
|||
* this function updates the number of contributions
|
||||
*/
|
||||
fun upDateUploadCount() {
|
||||
WorkManager.getInstance(context)
|
||||
context?.let {
|
||||
WorkManager.getInstance(it)
|
||||
.getWorkInfosForUniqueWorkLiveData(UploadWorker::class.java.simpleName).observe(
|
||||
viewLifecycleOwner
|
||||
) { 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())
|
||||
}
|
||||
} 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)
|
||||
.subscribeOn(ioThreadScheduler)
|
||||
.subscribe {
|
||||
view!!.getContext()?.applicationContext?.let {
|
||||
makeOneTimeWorkRequest(
|
||||
view!!.getContext().applicationContext, ExistingWorkPolicy.KEEP
|
||||
it, ExistingWorkPolicy.KEEP
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,9 +63,4 @@ abstract class CommonsDaggerSupportFragment : Fragment(), HasSupportFragmentInje
|
|||
|
||||
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