treewide: use getSystemService extension everywhere

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-04-21 13:15:41 +05:30
parent d505151662
commit 72166c6912
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
4 changed files with 11 additions and 7 deletions

View file

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

View file

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

View file

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

View file

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