Commit a26d180d authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Replaced null-asserted usages of context and activity with their requireXX counterparts

parent faf68284
......@@ -45,15 +45,15 @@ class AboutFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
view.credits.setOnClickListener {
showInfoTextDialog(
context!!,
requireContext(),
getString(R.string.dialog_credits_title),
getString(R.string.dialog_credits_message)
)
}
view.privacyPolicy.setOnClickListener {
showPrivacyPolicyDialog(context!!)
showPrivacyPolicyDialog(requireContext())
}
if(isPackageInstalled(context!!, "org.telegram.messenger")) {
if(isPackageInstalled(requireContext(), "org.telegram.messenger")) {
view.group.setOnClickListener {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("tg://join?invite=I54nRleveRGP8IPmcIdySg"))
startActivity(intent)
......@@ -62,7 +62,7 @@ class AboutFragment : Fragment() {
view.group.visibility = View.GONE
}
view.contact.setOnClickListener {
context!!.showEmailChooser(
requireContext().showEmailChooser(
getString(R.string.about_contact_developer),
getString(R.string.app_name),
getString(R.string.support_contact_mail),
......@@ -78,21 +78,21 @@ class AboutFragment : Fragment() {
startActivity(Intent.createChooser(intent, getString(R.string.about_share)))
}
view.changelog.setOnClickListener {
ChangelogDialog(context!!, 22, showOptOut = false, showInfoText = false).show()
ChangelogDialog(requireContext(), 22, showOptOut = false, showInfoText = false).show()
}
view.licenses.setOnClickListener {
LicensesDialog(context!!).show()
LicensesDialog(requireContext()).show()
}
view.about.setOnClickListener {
showInfoTextDialog(
context!!,
requireContext(),
getString(R.string.menu_about),
getString(
R.string.about_app,
BuildConfig.VERSION_NAME + (if (BuildConfig.DEBUG) " DEBUG" else "") + " (Commit ${BuildConfig.COMMIT_HASH})",
BuildConfig.VERSION_CODE,
AppDatabase.currentVersion,
if (context!!.getPreferences().crashreportingType == Crashreporting.FULL) context!!.getPreferences().crashReportingUUID else "---"
if (requireContext().getPreferences().crashreportingType == Crashreporting.FULL) requireContext().getPreferences().crashReportingUUID else "---"
)
)
}
......@@ -101,7 +101,7 @@ class AboutFragment : Fragment() {
languageCode.startsWith(it)
}) view.translating.visibility = View.GONE
else view.translating.setOnClickListener {
showInfoTextDialog(context!!, getString(R.string.about_help_translating),
showInfoTextDialog(requireContext(), getString(R.string.about_help_translating),
getString(R.string.dialog_help_translating_message),
neutralButton = getString(R.string.all_close) to null)
}
......
......@@ -99,7 +99,7 @@ class DnsRuleFragment : Fragment() {
}
}
addSource.setOnClickListener {
NewHostSourceDialog(context!!, onSourceCreated = { newSource ->
NewHostSourceDialog(requireContext(), onSourceCreated = { newSource ->
if (!sourceAdapterList.contains(newSource)) {
val insertPos = sourceAdapterList.indexOfFirst {
it.name > newSource.name
......@@ -124,17 +124,17 @@ class DnsRuleFragment : Fragment() {
}).show()
}
refresh.setOnClickListener {
HostSourceRefreshDialog(context!!,runRefresh = {
if(context!!.isServiceRunning(RuleImportService::class.java)) {
context!!.startService(Intent(context!!, RuleImportService::class.java).putExtra("abort", true))
HostSourceRefreshDialog(requireContext(),runRefresh = {
if(requireContext().isServiceRunning(RuleImportService::class.java)) {
requireContext().startService(Intent(requireContext(), RuleImportService::class.java).putExtra("abort", true))
} else {
context!!.startService(Intent(context!!, RuleImportService::class.java))
requireContext().startService(Intent(requireContext(), RuleImportService::class.java))
refreshProgress.show()
refreshProgressShown = true
}
}, refreshConfigChanged = {
getPreferences().apply {
val workManager = WorkManager.getInstance(context!!)
val workManager = WorkManager.getInstance(requireContext())
workManager.cancelAllWorkByTag("hostSourceRefresh")
if(automaticHostRefresh) {
val constraints = Constraints.Builder()
......@@ -167,18 +167,18 @@ class DnsRuleFragment : Fragment() {
}).show()
}
export.setOnClickListener {
if (context!!.isServiceRunning(RuleExportService::class.java)) {
context!!.startService(Intent(context!!, RuleExportService::class.java).putExtra("abort", true))
if (requireContext().isServiceRunning(RuleExportService::class.java)) {
requireContext().startService(Intent(requireContext(), RuleExportService::class.java).putExtra("abort", true))
} else {
ExportDnsRulesDialog(context!!) { exportFromSources, exportUserRules, exportType ->
ExportDnsRulesDialog(requireContext()) { exportFromSources, exportUserRules, exportType ->
fileChosenCallback = {
val intent = Intent(context!!, RuleExportService::class.java).apply {
val intent = Intent(requireContext(), RuleExportService::class.java).apply {
putExtra(
"params",
RuleExportService.Params(exportFromSources, exportUserRules, exportType, it.toString())
)
}
context!!.startService(intent)
requireContext().startService(intent)
exportProgress.show()
exportProgressShown = true
}
......@@ -200,7 +200,7 @@ class DnsRuleFragment : Fragment() {
sourceAdapter = ModelAdapterBuilder.withModelAndViewHolder({ view, type ->
when (type) {
0 -> SourceViewHolder(view, deleteSource = {
showInfoTextDialog(context!!,
showInfoTextDialog(requireContext(),
getString(R.string.dialog_deletehostsource_title, it.name),
getString(R.string.dialog_deletehostsource_message, it.name),
getString(R.string.all_yes) to { dialog, _ ->
......@@ -224,7 +224,7 @@ class DnsRuleFragment : Fragment() {
getDatabase().hostSourceDao().setSourceEnabled(hostSource.id, enabled)
notifyRulesChanged()
}, editSource = { hostSource ->
NewHostSourceDialog(context!!, onSourceCreated = { newSource ->
NewHostSourceDialog(requireContext(), onSourceCreated = { newSource ->
getDatabase().hostSourceDao().findById(hostSource.id)?.apply {
this.name = newSource.name
this.source = newSource.source
......@@ -252,7 +252,7 @@ class DnsRuleFragment : Fragment() {
getPreferences().customHostsEnabled = it
},
clearRules = {
showInfoTextDialog(context!!,
showInfoTextDialog(requireContext(),
getString(R.string.dialog_clearuserrules_title),
getString(R.string.dialog_clearuserrules_message),
getString(R.string.all_yes) to { dialog, _ ->
......@@ -292,7 +292,7 @@ class DnsRuleFragment : Fragment() {
}
},
createRule = {
DnsRuleDialog(context!!, onRuleCreated = { newRule ->
DnsRuleDialog(requireContext(), onRuleCreated = { newRule ->
val insert = {
val insertPos = userDnsRules.indexOfFirst {
it.host > newRule.host
......@@ -330,7 +330,7 @@ class DnsRuleFragment : Fragment() {
notifyRulesChanged()
} else {
Snackbar.make(
activity!!.findViewById(android.R.id.content),
requireActivity().findViewById(android.R.id.content),
R.string.window_dnsrules_hostalreadyexists,
Snackbar.LENGTH_LONG
).show()
......@@ -355,7 +355,7 @@ class DnsRuleFragment : Fragment() {
}
notifyRulesChanged()
}, editRule = {
DnsRuleDialog(context!!, it) { newRule ->
DnsRuleDialog(requireContext(), it) { newRule ->
val rows = getDatabase().dnsRuleDao().updateIgnore(newRule)
if (rows > 0) {
val index = userDnsRules.indexOf(it)
......@@ -363,7 +363,7 @@ class DnsRuleFragment : Fragment() {
sourceAdapter.notifyItemChanged(sourceAdapterList.size + 1 + index)
} else {
Snackbar.make(
activity!!.findViewById(android.R.id.content),
requireActivity().findViewById(android.R.id.content),
R.string.window_dnsrules_hostalreadyexists,
Snackbar.LENGTH_LONG
).show()
......@@ -433,17 +433,17 @@ class DnsRuleFragment : Fragment() {
}
}.build()
list.layoutManager = LinearLayoutManager(context!!)
list.layoutManager = LinearLayoutManager(requireContext())
list.recycledViewPool.setMaxRecycledViews(1, 1)
list.addItemDecoration(SpaceItemDecorator(context!!))
list.addItemDecoration(SpaceItemDecorator(requireContext()))
list.adapter = sourceAdapter
if(context!!.isServiceRunning(RuleImportService::class.java)) {
if(requireContext().isServiceRunning(RuleImportService::class.java)) {
refreshProgress.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
refreshProgress.show()
refreshProgressShown = true
}
}
if(context!!.isServiceRunning(RuleExportService::class.java)) {
if(requireContext().isServiceRunning(RuleExportService::class.java)) {
exportProgress.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
exportProgressShown = true
exportProgress.show()
......@@ -452,7 +452,7 @@ class DnsRuleFragment : Fragment() {
}
private fun notifyRulesChanged() {
LocalBroadcastManager.getInstance(context!!).sendBroadcast(Intent(DnsVpnService.BROADCAST_DNSRULES_REFRESHED))
LocalBroadcastManager.getInstance(requireContext()).sendBroadcast(Intent(DnsVpnService.BROADCAST_DNSRULES_REFRESHED))
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
......@@ -465,7 +465,7 @@ class DnsRuleFragment : Fragment() {
override fun onResume() {
super.onResume()
importDoneReceiver = context!!.registerLocalReceiver(IntentFilter(RuleImportService.BROADCAST_IMPORT_DONE)) {
importDoneReceiver = requireContext().registerLocalReceiver(IntentFilter(RuleImportService.BROADCAST_IMPORT_DONE)) {
refreshProgress.hide()
refreshProgressShown = false
......@@ -484,15 +484,15 @@ class DnsRuleFragment : Fragment() {
updateRuleCountTitle()
}
}
exportDoneReceiver = context!!.registerLocalReceiver(IntentFilter(RuleExportService.BROADCAST_EXPORT_DONE)) {
exportDoneReceiver = requireContext().registerLocalReceiver(IntentFilter(RuleExportService.BROADCAST_EXPORT_DONE)) {
exportProgress.hide()
exportProgressShown = false
}
if(!context!!.isServiceRunning(RuleImportService::class.java) && refreshProgressShown) {
if(!requireContext().isServiceRunning(RuleImportService::class.java) && refreshProgressShown) {
refreshProgress.hide()
refreshProgressShown = false
}
if(!context!!.isServiceRunning(RuleExportService::class.java) && exportProgressShown) {
if(!requireContext().isServiceRunning(RuleExportService::class.java) && exportProgressShown) {
exportProgress.show()
exportProgressShown = false
}
......@@ -506,8 +506,8 @@ class DnsRuleFragment : Fragment() {
override fun onPause() {
super.onPause()
context!!.unregisterLocalReceiver(importDoneReceiver)
context!!.unregisterLocalReceiver(exportDoneReceiver)
requireContext().unregisterLocalReceiver(importDoneReceiver)
requireContext().unregisterLocalReceiver(exportDoneReceiver)
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
......
......@@ -96,8 +96,8 @@ class MainFragment : Fragment() {
} else {
if (event.flags and MotionEvent.FLAG_WINDOW_IS_OBSCURED != 0) {
if (event.action == MotionEvent.ACTION_UP) {
if (VpnService.prepare(context!!) != null) {
showInfoTextDialog(context!!,
if (VpnService.prepare(requireContext()) != null) {
showInfoTextDialog(requireContext(),
getString(R.string.dialog_overlaydetected_title),
getString(R.string.dialog_overlaydetected_message),
positiveButton = null,
......@@ -115,7 +115,7 @@ class MainFragment : Fragment() {
}
}
speedTest.setOnClickListener {
startActivity(Intent(context!!, SpeedTestActivity::class.java))
startActivity(Intent(requireContext(), SpeedTestActivity::class.java))
}
vpnStateReceiver = requireContext().registerLocalReceiver(
listOf(
......@@ -158,7 +158,7 @@ class MainFragment : Fragment() {
startActivity(i)
} catch (e: ActivityNotFoundException) {
Toast.makeText(
context!!,
requireContext(),
R.string.error_no_webbrowser_installed,
Toast.LENGTH_LONG
).show()
......@@ -218,7 +218,7 @@ class MainFragment : Fragment() {
val privateDnsActive = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
false
} else {
(context!!.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).let {
(requireContext().getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).let {
if (it.activeNetwork == null) false
else it.getLinkProperties(it.activeNetwork)?.isPrivateDnsActive ?: false
}
......
......@@ -63,9 +63,9 @@ class QueryLogFragment : Fragment(), BackpressFragment {
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.menu_queryloglist, menu)
val searchManager = context!!.getSystemService(Context.SEARCH_SERVICE) as SearchManager
val searchManager = requireContext().getSystemService(Context.SEARCH_SERVICE) as SearchManager
val searchView: SearchView = menu.findItem(R.id.search)!!.actionView as SearchView
searchView.setSearchableInfo(searchManager.getSearchableInfo(activity!!.componentName))
searchView.setSearchableInfo(searchManager.getSearchableInfo(requireActivity().componentName))
searchView.setOnQueryTextListener(listFragment)
}
......
......@@ -379,14 +379,14 @@ class SettingsFragment : PreferenceFragmentCompat() {
}
}
clearCache.setOnPreferenceClickListener {
showInfoTextDialog(context!!,
showInfoTextDialog(requireContext(),
getString(R.string.title_clear_dnscache),
getString(R.string.dialog_cleardnscache_message),
getString(R.string.all_yes) to { dialog, _ ->
GlobalScope.launch(Dispatchers.IO) {
context?.also {
getDatabase().cachedResponseDao().deleteAll()
DnsVpnService.invalidateDNSCache(context!!)
DnsVpnService.invalidateDNSCache(requireContext())
}
}
dialog.dismiss()
......@@ -462,7 +462,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
@RequiresApi(Build.VERSION_CODES.M)
private fun showBatteryOptimizationDialog(enablePreference: () -> Unit) {
val intent = Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)
if(intent.resolveActivity(context!!.packageManager) == null) {
if(intent.resolveActivity(requireContext().packageManager) == null) {
enablePreference()
} else {
AlertDialog.Builder(requireContext(), requireContext().getPreferences().theme.dialogStyle)
......
......@@ -36,28 +36,28 @@ class SettingsOverviewFragment: Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
general.setOnClickListener {
SettingsActivity.showCategory(context!!, SettingsActivity.Category.GENERAL)
SettingsActivity.showCategory(requireContext(), SettingsActivity.Category.GENERAL)
}
notification.setOnClickListener {
SettingsActivity.showCategory(context!!, SettingsActivity.Category.NOTIFICATION)
SettingsActivity.showCategory(requireContext(), SettingsActivity.Category.NOTIFICATION)
}
pin.setOnClickListener {
SettingsActivity.showCategory(context!!, SettingsActivity.Category.PIN)
SettingsActivity.showCategory(requireContext(), SettingsActivity.Category.PIN)
}
cache.setOnClickListener {
SettingsActivity.showCategory(context!!, SettingsActivity.Category.CACHE)
SettingsActivity.showCategory(requireContext(), SettingsActivity.Category.CACHE)
}
logging.setOnClickListener {
SettingsActivity.showCategory(context!!, SettingsActivity.Category.LOGGING)
SettingsActivity.showCategory(requireContext(), SettingsActivity.Category.LOGGING)
}
ip.setOnClickListener {
SettingsActivity.showCategory(context!!, SettingsActivity.Category.IP)
SettingsActivity.showCategory(requireContext(), SettingsActivity.Category.IP)
}
network.setOnClickListener {
SettingsActivity.showCategory(context!!, SettingsActivity.Category.NETWORK)
SettingsActivity.showCategory(requireContext(), SettingsActivity.Category.NETWORK)
}
queryLogging.setOnClickListener {
SettingsActivity.showCategory(context!!, SettingsActivity.Category.QUERIES)
SettingsActivity.showCategory(requireContext(), SettingsActivity.Category.QUERIES)
}
}
}
\ No newline at end of file
......@@ -95,19 +95,19 @@ class QueryLogDetailFragment : Fragment() {
val answerIP = query.getParsedResponses().firstOrNull {
it.type == query.type
}?.payload?.toString() ?: if(query.type == Record.TYPE.A) "0.0.0.0" else "::1"
DnsRuleDialog(context!!, DnsRule(query.type, query.name, target = answerIP), onRuleCreated = { newRule ->
DnsRuleDialog(requireContext(), DnsRule(query.type, query.name, target = answerIP), onRuleCreated = { newRule ->
val id = if (newRule.isWhitelistRule()) {
getDatabase().dnsRuleDao().insertWhitelist(newRule)
} else getDatabase().dnsRuleDao().insertIgnore(newRule)
if (id != -1L) {
Snackbar.make(
activity!!.findViewById(android.R.id.content),
requireActivity().findViewById(android.R.id.content),
R.string.windows_querylogging_dnsrule_created,
Snackbar.LENGTH_LONG
).show()
} else {
Snackbar.make(
activity!!.findViewById(android.R.id.content),
requireActivity().findViewById(android.R.id.content),
R.string.window_dnsrules_hostalreadyexists,
Snackbar.LENGTH_LONG
).show()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment