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