Commit f218282e authored by Mygod's avatar Mygod

Use require* in support library

parent 6d866633
...@@ -50,7 +50,7 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompatDividers() { ...@@ -50,7 +50,7 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompatDividers() {
boot.isChecked = BootReceiver.enabled boot.isChecked = BootReceiver.enabled
val dba = findPreference(Key.directBootAware) val dba = findPreference(Key.directBootAware)
if (Build.VERSION.SDK_INT >= 24 && context!!.getSystemService(DevicePolicyManager::class.java) if (Build.VERSION.SDK_INT >= 24 && requireContext().getSystemService(DevicePolicyManager::class.java)
.storageEncryptionStatus == DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE_PER_USER) .storageEncryptionStatus == DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE_PER_USER)
dba.onPreferenceChangeListener = directBootAwareListener else dba.parent!!.removePreference(dba) dba.onPreferenceChangeListener = directBootAwareListener else dba.parent!!.removePreference(dba)
...@@ -59,7 +59,7 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompatDividers() { ...@@ -59,7 +59,7 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompatDividers() {
tfo.setOnPreferenceChangeListener { _, value -> tfo.setOnPreferenceChangeListener { _, value ->
val result = TcpFastOpen.enabled(value as Boolean) val result = TcpFastOpen.enabled(value as Boolean)
if (result != null && result != "Success.") if (result != null && result != "Success.")
Snackbar.make(activity!!.findViewById(R.id.snackbar), result, Snackbar.LENGTH_LONG).show() Snackbar.make(requireActivity().findViewById(R.id.snackbar), result, Snackbar.LENGTH_LONG).show()
value == TcpFastOpen.sendEnabled value == TcpFastOpen.sendEnabled
} }
if (!TcpFastOpen.supported) { if (!TcpFastOpen.supported) {
......
...@@ -65,7 +65,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu ...@@ -65,7 +65,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu
override fun onCreatePreferencesFix(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferencesFix(savedInstanceState: Bundle?, rootKey: String?) {
preferenceManager.preferenceDataStore = DataStore.privateStore preferenceManager.preferenceDataStore = DataStore.privateStore
val activity = activity!! val activity = requireActivity()
val profile = ProfileManager.getProfile(activity.intent.getIntExtra(Action.EXTRA_PROFILE_ID, -1)) val profile = ProfileManager.getProfile(activity.intent.getIntExtra(Action.EXTRA_PROFILE_ID, -1))
if (profile == null) { if (profile == null) {
activity.finish() activity.finish()
...@@ -134,7 +134,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu ...@@ -134,7 +134,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu
ProfileManager.updateProfile(profile) ProfileManager.updateProfile(profile)
ProfilesFragment.instance?.profilesAdapter?.deepRefreshId(profile.id) ProfilesFragment.instance?.profilesAdapter?.deepRefreshId(profile.id)
if (DataStore.profileId == profile.id && DataStore.directBootAware) DirectBoot.update() if (DataStore.profileId == profile.id && DataStore.directBootAware) DirectBoot.update()
activity!!.finish() requireActivity().finish()
} }
override fun onResume() { override fun onResume() {
...@@ -161,7 +161,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu ...@@ -161,7 +161,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu
override fun onDisplayPreferenceDialog(preference: Preference) { override fun onDisplayPreferenceDialog(preference: Preference) {
if (preference.key == Key.pluginConfigure) { if (preference.key == Key.pluginConfigure) {
val intent = PluginManager.buildIntent(pluginConfiguration.selected, PluginContract.ACTION_CONFIGURE) val intent = PluginManager.buildIntent(pluginConfiguration.selected, PluginContract.ACTION_CONFIGURE)
if (intent.resolveActivity(activity!!.packageManager) != null) if (intent.resolveActivity(requireContext().packageManager) != null)
startActivityForResult(intent.putExtra(PluginContract.EXTRA_OPTIONS, startActivityForResult(intent.putExtra(PluginContract.EXTRA_OPTIONS,
pluginConfiguration.selectedOptions.toString()), REQUEST_CODE_PLUGIN_CONFIGURE) else { pluginConfiguration.selectedOptions.toString()), REQUEST_CODE_PLUGIN_CONFIGURE) else {
showPluginEditor() showPluginEditor()
...@@ -183,7 +183,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu ...@@ -183,7 +183,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu
override fun onMenuItemClick(item: MenuItem) = when (item.itemId) { override fun onMenuItemClick(item: MenuItem) = when (item.itemId) {
R.id.action_delete -> { R.id.action_delete -> {
val activity = activity!! val activity = requireActivity()
AlertDialog.Builder(activity) AlertDialog.Builder(activity)
.setTitle(R.string.delete_confirm_prompt) .setTitle(R.string.delete_confirm_prompt)
.setPositiveButton(R.string.yes, { _, _ -> .setPositiveButton(R.string.yes, { _, _ ->
......
...@@ -128,7 +128,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener { ...@@ -128,7 +128,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
itemView.setOnClickListener(this) itemView.setOnClickListener(this)
val share = itemView.findViewById<View>(R.id.share) val share = itemView.findViewById<View>(R.id.share)
share.setOnClickListener { share.setOnClickListener {
val popup = PopupMenu(activity!!, share) val popup = PopupMenu(requireContext(), share)
popup.menuInflater.inflate(R.menu.profile_share_popup, popup.menu) popup.menuInflater.inflate(R.menu.profile_share_popup, popup.menu)
popup.setOnMenuItemClickListener(this) popup.setOnMenuItemClickListener(this)
popup.show() popup.show()
...@@ -173,10 +173,10 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener { ...@@ -173,10 +173,10 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
var adView = adView var adView = adView
if (item.host == "198.199.101.152") { if (item.host == "198.199.101.152") {
if (adView == null) { if (adView == null) {
val params = val params = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) ViewGroup.LayoutParams.WRAP_CONTENT)
params.gravity = Gravity.CENTER_HORIZONTAL params.gravity = Gravity.CENTER_HORIZONTAL
val context = context!! val context = requireContext()
adView = AdView(context) adView = AdView(context)
adView.layoutParams = params adView.layoutParams = params
adView.adUnitId = "ca-app-pub-9097031975646651/7760346322" adView.adUnitId = "ca-app-pub-9097031975646651/7760346322"
...@@ -208,7 +208,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener { ...@@ -208,7 +208,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
override fun onMenuItemClick(item: MenuItem): Boolean = when (item.itemId) { override fun onMenuItemClick(item: MenuItem): Boolean = when (item.itemId) {
R.id.action_qr_code_nfc -> { R.id.action_qr_code_nfc -> {
fragmentManager!!.beginTransaction().add(QRCodeDialog(this.item.toString()), "") requireFragmentManager().beginTransaction().add(QRCodeDialog(this.item.toString()), "")
.commitAllowingStateLoss() .commitAllowingStateLoss()
true true
} }
...@@ -230,7 +230,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener { ...@@ -230,7 +230,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
override fun onBindViewHolder(holder: ProfileViewHolder, position: Int) = holder.bind(profiles[position]) override fun onBindViewHolder(holder: ProfileViewHolder, position: Int) = holder.bind(profiles[position])
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProfileViewHolder = ProfileViewHolder( override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProfileViewHolder = ProfileViewHolder(
LayoutInflater.from(parent!!.context).inflate(R.layout.layout_profile, parent, false)) LayoutInflater.from(parent.context).inflate(R.layout.layout_profile, parent, false))
override fun getItemCount(): Int = profiles.size override fun getItemCount(): Int = profiles.size
override fun getItemId(position: Int): Long = profiles[position].id.toLong() override fun getItemId(position: Int): Long = profiles[position].id.toLong()
...@@ -305,7 +305,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener { ...@@ -305,7 +305,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
private var txTotal: Long = 0L private var txTotal: Long = 0L
private var rxTotal: Long = 0L private var rxTotal: Long = 0L
private val clipboard by lazy { activity!!.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager } private val clipboard by lazy { requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager }
private fun startConfig(id: Int) = startActivity(Intent(context, ProfileConfigActivity::class.java) private fun startConfig(id: Int) = startActivity(Intent(context, ProfileConfigActivity::class.java)
.putExtra(Action.EXTRA_PROFILE_ID, id)) .putExtra(Action.EXTRA_PROFILE_ID, id))
...@@ -331,7 +331,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener { ...@@ -331,7 +331,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
profilesList.itemAnimator = animator profilesList.itemAnimator = animator
profilesList.adapter = profilesAdapter profilesList.adapter = profilesAdapter
instance = this instance = this
undoManager = UndoSnackbarManager(activity!!.findViewById(R.id.snackbar), undoManager = UndoSnackbarManager(requireActivity().findViewById(R.id.snackbar),
profilesAdapter::undo, profilesAdapter::commit) profilesAdapter::undo, profilesAdapter::commit)
ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP or ItemTouchHelper.DOWN, ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP or ItemTouchHelper.DOWN,
ItemTouchHelper.START or ItemTouchHelper.END) { ItemTouchHelper.START or ItemTouchHelper.END) {
...@@ -351,7 +351,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener { ...@@ -351,7 +351,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
profilesAdapter.move(viewHolder.adapterPosition, target.adapterPosition) profilesAdapter.move(viewHolder.adapterPosition, target.adapterPosition)
return true return true
} }
override fun clearView(recyclerView: RecyclerView?, viewHolder: RecyclerView.ViewHolder?) { override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) {
super.clearView(recyclerView, viewHolder) super.clearView(recyclerView, viewHolder)
profilesAdapter.commitMove() profilesAdapter.commitMove()
} }
...@@ -369,13 +369,13 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener { ...@@ -369,13 +369,13 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
val profiles = Profile.findAll(clipboard.primaryClip.getItemAt(0).text).toList() val profiles = Profile.findAll(clipboard.primaryClip.getItemAt(0).text).toList()
if (profiles.isNotEmpty()) { if (profiles.isNotEmpty()) {
profiles.forEach { ProfileManager.createProfile(it) } profiles.forEach { ProfileManager.createProfile(it) }
Snackbar.make(activity!!.findViewById(R.id.snackbar), R.string.action_import_msg, Snackbar.make(requireActivity().findViewById(R.id.snackbar), R.string.action_import_msg,
Snackbar.LENGTH_LONG).show() Snackbar.LENGTH_LONG).show()
return true return true
} }
} catch (_: IndexOutOfBoundsException) { } } catch (_: IndexOutOfBoundsException) { }
Snackbar.make(activity!!.findViewById(R.id.snackbar), R.string.action_import_err, Snackbar.LENGTH_LONG) Snackbar.make(requireActivity().findViewById(R.id.snackbar), R.string.action_import_err,
.show() Snackbar.LENGTH_LONG).show()
true true
} }
R.id.action_manual_settings -> { R.id.action_manual_settings -> {
...@@ -384,7 +384,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener { ...@@ -384,7 +384,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
} }
R.id.action_export -> { R.id.action_export -> {
val profiles = ProfileManager.getAllProfiles() val profiles = ProfileManager.getAllProfiles()
Snackbar.make(activity!!.findViewById(R.id.snackbar), if (profiles != null) { Snackbar.make(requireActivity().findViewById(R.id.snackbar), if (profiles != null) {
clipboard.primaryClip = ClipData.newPlainText(null, profiles.joinToString("\n")) clipboard.primaryClip = ClipData.newPlainText(null, profiles.joinToString("\n"))
R.string.action_export_msg R.string.action_export_msg
} else R.string.action_export_err, Snackbar.LENGTH_LONG).show() } else R.string.action_export_err, Snackbar.LENGTH_LONG).show()
......
...@@ -80,7 +80,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener, ...@@ -80,7 +80,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
private lateinit var positive: Button private lateinit var positive: Button
init { init {
val activity = activity!! val activity = requireActivity()
val view = activity.layoutInflater.inflate(R.layout.dialog_acl_rule, null) val view = activity.layoutInflater.inflate(R.layout.dialog_acl_rule, null)
templateSelector = view.findViewById(R.id.template_selector) templateSelector = view.findViewById(R.id.template_selector)
editText = view.findViewById(R.id.content) editText = view.findViewById(R.id.content)
...@@ -360,7 +360,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener, ...@@ -360,7 +360,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
private lateinit var list: RecyclerView private lateinit var list: RecyclerView
private var mode: ActionMode? = null private var mode: ActionMode? = null
private lateinit var undoManager: UndoSnackbarManager<Any> private lateinit var undoManager: UndoSnackbarManager<Any>
private val clipboard by lazy { activity!!.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager } private val clipboard by lazy { requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager }
private fun onSelectedItemsUpdated() { private fun onSelectedItemsUpdated() {
if (selectedItems.isEmpty()) mode?.finish() else if (mode == null) mode = toolbar.startActionMode(this) if (selectedItems.isEmpty()) mode?.finish() else if (mode == null) mode = toolbar.startActionMode(this)
...@@ -383,12 +383,13 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener, ...@@ -383,12 +383,13 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
toolbar.setTitle(R.string.custom_rules) toolbar.setTitle(R.string.custom_rules)
toolbar.inflateMenu(R.menu.custom_rules_menu) toolbar.inflateMenu(R.menu.custom_rules_menu)
toolbar.setOnMenuItemClickListener(this) toolbar.setOnMenuItemClickListener(this)
val activity = requireActivity()
list = view.findViewById(R.id.list) list = view.findViewById(R.id.list)
list.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) list.layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
list.itemAnimator = DefaultItemAnimator() list.itemAnimator = DefaultItemAnimator()
list.adapter = adapter list.adapter = adapter
view.findViewById<FastScroller>(R.id.fastscroller).setRecyclerView(list) view.findViewById<FastScroller>(R.id.fastscroller).setRecyclerView(list)
undoManager = UndoSnackbarManager(activity!!.findViewById(R.id.snackbar), adapter::undo) undoManager = UndoSnackbarManager(activity.findViewById(R.id.snackbar), adapter::undo)
ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.START or ItemTouchHelper.END) { ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.START or ItemTouchHelper.END) {
override fun getSwipeDirs(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int = override fun getSwipeDirs(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int =
if (isEnabled && selectedItems.isEmpty()) super.getSwipeDirs(recyclerView, viewHolder) else 0 if (isEnabled && selectedItems.isEmpty()) super.getSwipeDirs(recyclerView, viewHolder) else 0
...@@ -439,8 +440,8 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener, ...@@ -439,8 +440,8 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
try { try {
adapter.addToProxy(clipboard.primaryClip.getItemAt(0).text.toString()) != null adapter.addToProxy(clipboard.primaryClip.getItemAt(0).text.toString()) != null
} catch (exc: Exception) { } catch (exc: Exception) {
Snackbar.make(activity!!.findViewById(R.id.snackbar), R.string.action_import_err, Snackbar.LENGTH_LONG) Snackbar.make(requireActivity().findViewById(R.id.snackbar), R.string.action_import_err,
.show() Snackbar.LENGTH_LONG).show()
app.track(exc) app.track(exc)
} }
true true
...@@ -462,7 +463,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener, ...@@ -462,7 +463,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
} }
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
val activity = activity!! val activity = requireActivity()
val window = activity.window val window = activity.window
// In the end material_grey_100 is used for background, see AppCompatDrawableManager (very complicated) // In the end material_grey_100 is used for background, see AppCompatDrawableManager (very complicated)
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= 23) {
...@@ -495,7 +496,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener, ...@@ -495,7 +496,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
else -> false else -> false
} }
override fun onDestroyActionMode(mode: ActionMode) { override fun onDestroyActionMode(mode: ActionMode) {
val activity = activity!! val activity = requireActivity()
val window = activity.window val window = activity.window
window.statusBarColor = ContextCompat.getColor(activity, window.statusBarColor = ContextCompat.getColor(activity,
activity.theme.resolveResourceId(android.R.attr.statusBarColor)) activity.theme.resolveResourceId(android.R.attr.statusBarColor))
......
...@@ -101,8 +101,8 @@ class BottomSheetPreferenceDialogFragment : PreferenceDialogFragmentCompat() { ...@@ -101,8 +101,8 @@ class BottomSheetPreferenceDialogFragment : PreferenceDialogFragmentCompat() {
private var clickedIndex = -1 private var clickedIndex = -1
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val activity = activity val activity = requireActivity()
val dialog = BottomSheetDialog(activity!!, theme) val dialog = BottomSheetDialog(activity, theme)
val recycler = RecyclerView(activity) val recycler = RecyclerView(activity)
val padding = resources.getDimensionPixelOffset(R.dimen.bottom_sheet_padding) val padding = resources.getDimensionPixelOffset(R.dimen.bottom_sheet_padding)
recycler.setPadding(0, padding, 0, padding) recycler.setPadding(0, padding, 0, padding)
......
...@@ -40,8 +40,9 @@ class PluginConfigurationDialogFragment : EditTextPreferenceDialogFragmentCompat ...@@ -40,8 +40,9 @@ class PluginConfigurationDialogFragment : EditTextPreferenceDialogFragmentCompat
super.onPrepareDialogBuilder(builder) super.onPrepareDialogBuilder(builder)
val intent = PluginManager.buildIntent(arguments!!.getString(PLUGIN_ID_FRAGMENT_TAG), val intent = PluginManager.buildIntent(arguments!!.getString(PLUGIN_ID_FRAGMENT_TAG),
PluginContract.ACTION_HELP) PluginContract.ACTION_HELP)
if (intent.resolveActivity(activity!!.packageManager) != null) builder.setNeutralButton("?", { _, _ -> val activity = requireActivity()
activity!!.startActivityForResult(intent.putExtra(PluginContract.EXTRA_OPTIONS, editText.text.toString()), if (intent.resolveActivity(activity.packageManager) != null) builder.setNeutralButton("?", { _, _ ->
activity.startActivityForResult(intent.putExtra(PluginContract.EXTRA_OPTIONS, editText.text.toString()),
ProfileConfigActivity.REQUEST_CODE_PLUGIN_HELP) ProfileConfigActivity.REQUEST_CODE_PLUGIN_HELP)
}) })
} }
......
Markdown is supported
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