treewide: use getSystemService extension everywhere
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
d505151662
commit
72166c6912
4 changed files with 11 additions and 7 deletions
|
@ -30,6 +30,7 @@ import androidx.appcompat.widget.SearchView.OnQueryTextListener
|
|||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.edit
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.observe
|
||||
|
@ -102,7 +103,7 @@ class PasswordStore : AppCompatActivity() {
|
|||
activity = this
|
||||
settings = PreferenceManager.getDefaultSharedPreferences(this.applicationContext)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
shortcutManager = getSystemService(ShortcutManager::class.java)
|
||||
shortcutManager = getSystemService()
|
||||
}
|
||||
|
||||
// If user opens app with permission granted then revokes and returns,
|
||||
|
|
|
@ -578,7 +578,7 @@ class UserPreference : AppCompatActivity() {
|
|||
|
||||
private val isAccessibilityServiceEnabled: Boolean
|
||||
get() {
|
||||
val am = getSystemService(AccessibilityManager::class.java) ?: return false
|
||||
val am = getSystemService<AccessibilityManager>() ?: return false
|
||||
val runningServices = am
|
||||
.getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_GENERIC)
|
||||
return runningServices
|
||||
|
|
|
@ -33,6 +33,7 @@ import android.widget.TextView
|
|||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.edit
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.widget.doOnTextChanged
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
|
@ -73,9 +74,7 @@ import org.openintents.openpgp.OpenPgpError
|
|||
import timber.log.Timber
|
||||
|
||||
class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
||||
private val clipboard: ClipboardManager by lazy {
|
||||
getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
}
|
||||
private val clipboard by lazy { getSystemService<ClipboardManager>() }
|
||||
private var passwordEntry: PasswordEntry? = null
|
||||
private var api: OpenPgpApi? = null
|
||||
|
||||
|
@ -140,6 +139,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
|||
crypto_password_category_decrypt.text = relativeParentPath
|
||||
crypto_password_file.text = name
|
||||
crypto_password_file.setOnLongClickListener {
|
||||
val clipboard = clipboard ?: return@setOnLongClickListener false
|
||||
val clip = ClipData.newPlainText("pgp_handler_result_pm", name)
|
||||
clipboard.setPrimaryClip(clip)
|
||||
showSnackbar(this.resources.getString(R.string.clipboard_username_toast_text))
|
||||
|
@ -808,6 +808,7 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
|||
}
|
||||
|
||||
private fun copyPasswordToClipBoard() {
|
||||
val clipboard = clipboard ?: return
|
||||
var pass = passwordEntry?.password
|
||||
|
||||
if (findViewById<TextView>(R.id.crypto_password_show) == null) {
|
||||
|
@ -837,12 +838,14 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound {
|
|||
}
|
||||
|
||||
private fun copyUsernameToClipBoard(username: String) {
|
||||
val clipboard = clipboard ?: return
|
||||
val clip = ClipData.newPlainText("pgp_handler_result_pm", username)
|
||||
clipboard.setPrimaryClip(clip)
|
||||
showSnackbar(resources.getString(R.string.clipboard_username_toast_text))
|
||||
}
|
||||
|
||||
private fun copyOtpToClipBoard(code: String) {
|
||||
val clipboard = clipboard ?: return
|
||||
val clip = ClipData.newPlainText("pgp_handler_result_pm", code)
|
||||
clipboard.setPrimaryClip(clip)
|
||||
showSnackbar(resources.getString(R.string.clipboard_otp_toast_text))
|
||||
|
|
|
@ -8,11 +8,11 @@ import android.annotation.SuppressLint
|
|||
import android.app.Dialog
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.zeapo.pwdstore.R
|
||||
|
@ -41,7 +41,7 @@ class ShowSshKeyFragment : DialogFragment() {
|
|||
ad.setOnShowListener {
|
||||
val b = ad.getButton(AlertDialog.BUTTON_NEUTRAL)
|
||||
b.setOnClickListener {
|
||||
val clipboard = activity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clipboard = activity.getSystemService<ClipboardManager>() ?: return@setOnClickListener
|
||||
val clip = ClipData.newPlainText("public key", publicKey.text.toString())
|
||||
clipboard.setPrimaryClip(clip)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue