diff options
| author | Harsh Shandilya <msfjarvis@gmail.com> | 2020-04-11 01:07:49 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-11 01:07:49 +0530 |
| commit | f21b6426af0182691d9df697768cdcf16a368652 (patch) | |
| tree | e8e5d496a6d1b4c6c730ad4a485096d3a0c9349f /app/src/main/java/com/zeapo/pwdstore/autofill | |
| parent | 575ef8472654f49dd60f0e6909164dd8dbd098fb (diff) | |
| download | HardenedPass-f21b6426af0182691d9df697768cdcf16a368652.tar.gz HardenedPass-f21b6426af0182691d9df697768cdcf16a368652.zip | |
Switch refactored entities to ViewBinding (#695)
* build: Enable ViewBinding
* autofill: oreo: Switch to ViewBinding
* PasswordFragment: switch to ViewBinding
* AutofillPublisherChangedActivity: use with(binding) { } syntax
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/autofill')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillFilterActivity.kt | 24 | ||||
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillPublisherChangedActivity.kt | 57 |
2 files changed, 44 insertions, 37 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillFilterActivity.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillFilterActivity.kt index e1cbc496..aee7f1a9 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillFilterActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillFilterActivity.kt @@ -33,8 +33,8 @@ import com.zeapo.pwdstore.autofill.oreo.AutofillMatcher import com.zeapo.pwdstore.autofill.oreo.AutofillPreferences import com.zeapo.pwdstore.autofill.oreo.DirectoryStructure import com.zeapo.pwdstore.autofill.oreo.FormOrigin +import com.zeapo.pwdstore.databinding.ActivityOreoAutofillFilterBinding import com.zeapo.pwdstore.utils.PasswordItem -import kotlinx.android.synthetic.main.activity_oreo_autofill_filter.* @TargetApi(Build.VERSION_CODES.O) class AutofillFilterView : AppCompatActivity() { @@ -71,6 +71,7 @@ class AutofillFilterView : AppCompatActivity() { private lateinit var formOrigin: FormOrigin private lateinit var directoryStructure: DirectoryStructure + private lateinit var binding: ActivityOreoAutofillFilterBinding private val model: SearchableRepositoryViewModel by viewModels { ViewModelProvider.AndroidViewModelFactory(application) @@ -78,7 +79,8 @@ class AutofillFilterView : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_oreo_autofill_filter) + binding = ActivityOreoAutofillFilterBinding.inflate(layoutInflater) + setContentView(binding.root) setFinishOnTouchOutside(true) val params = window.attributes @@ -127,13 +129,13 @@ class AutofillFilterView : AppCompatActivity() { }.onItemClicked { _, item -> decryptAndFill(item) } - rvPassword.apply { + binding.rvPassword.apply { adapter = recyclerAdapter layoutManager = LinearLayoutManager(context) } val initialFilter = formOrigin.getPrettyIdentifier(applicationContext, untrusted = false) - search.setText(initialFilter, TextView.BufferType.EDITABLE) + binding.search.setText(initialFilter, TextView.BufferType.EDITABLE) val filterMode = if (formOrigin is FormOrigin.Web) FilterMode.StrictDomain else FilterMode.Fuzzy model.search( @@ -142,7 +144,7 @@ class AutofillFilterView : AppCompatActivity() { searchMode = SearchMode.RecursivelyInSubdirectories, listMode = ListMode.FilesOnly ) - search.addTextChangedListener { + binding.search.addTextChangedListener { model.search( it.toString().trim(), filterMode = FilterMode.Fuzzy, @@ -155,21 +157,21 @@ class AutofillFilterView : AppCompatActivity() { recyclerAdapter.submitList(list) // Switch RecyclerView out for a "no results" message if the new list is empty and // the message is not yet shown (and vice versa). - if ((list.isEmpty() && rvPasswordSwitcher.nextView.id == rvPasswordEmpty.id) || - (list.isNotEmpty() && rvPasswordSwitcher.nextView.id == rvPassword.id) + if ((list.isEmpty() && binding.rvPasswordSwitcher.nextView.id == binding.rvPasswordEmpty.id) || + (list.isNotEmpty() && binding.rvPasswordSwitcher.nextView.id == binding.rvPassword.id) ) - rvPasswordSwitcher.showNext() + binding.rvPasswordSwitcher.showNext() } - shouldMatch.text = getString( + binding.shouldMatch.text = getString( R.string.oreo_autofill_match_with, formOrigin.getPrettyIdentifier(applicationContext) ) } private fun decryptAndFill(item: PasswordItem) { - if (shouldClear.isChecked) AutofillMatcher.clearMatchesFor(applicationContext, formOrigin) - if (shouldMatch.isChecked) AutofillMatcher.addMatchFor( + if (binding.shouldClear.isChecked) AutofillMatcher.clearMatchesFor(applicationContext, formOrigin) + if (binding.shouldMatch.isChecked) AutofillMatcher.addMatchFor( applicationContext, formOrigin, item.file diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillPublisherChangedActivity.kt b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillPublisherChangedActivity.kt index bef0e536..cd954667 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillPublisherChangedActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillPublisherChangedActivity.kt @@ -21,7 +21,7 @@ import com.zeapo.pwdstore.autofill.oreo.AutofillMatcher import com.zeapo.pwdstore.autofill.oreo.AutofillPublisherChangedException import com.zeapo.pwdstore.autofill.oreo.FormOrigin import com.zeapo.pwdstore.autofill.oreo.computeCertificatesHash -import kotlinx.android.synthetic.main.activity_oreo_autofill_publisher_changed.* +import com.zeapo.pwdstore.databinding.ActivityOreoAutofillPublisherChangedBinding @TargetApi(Build.VERSION_CODES.O) class AutofillPublisherChangedActivity : AppCompatActivity() { @@ -45,10 +45,12 @@ class AutofillPublisherChangedActivity : AppCompatActivity() { } private lateinit var appPackage: String + private lateinit var binding: ActivityOreoAutofillPublisherChangedBinding override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_oreo_autofill_publisher_changed) + binding = ActivityOreoAutofillPublisherChangedBinding.inflate(layoutInflater) + setContentView(binding.root) setFinishOnTouchOutside(true) appPackage = intent.getStringExtra(EXTRA_APP_PACKAGE) ?: run { @@ -58,36 +60,39 @@ class AutofillPublisherChangedActivity : AppCompatActivity() { } supportActionBar?.hide() showPackageInfo() - - okButton.setOnClickListener { finish() } - advancedButton.setOnClickListener { - advancedButton.visibility = View.INVISIBLE - warningAppAdvancedInfo.visibility = View.VISIBLE - resetButton.visibility = View.VISIBLE - } - resetButton.setOnClickListener { - AutofillMatcher.clearMatchesFor(this, FormOrigin.App(appPackage)) - finish() + with(binding) { + okButton.setOnClickListener { finish() } + advancedButton.setOnClickListener { + advancedButton.visibility = View.INVISIBLE + warningAppAdvancedInfo.visibility = View.VISIBLE + resetButton.visibility = View.VISIBLE + } + resetButton.setOnClickListener { + AutofillMatcher.clearMatchesFor(this@AutofillPublisherChangedActivity, FormOrigin.App(appPackage)) + finish() + } } } private fun showPackageInfo() { try { - val packageInfo = - packageManager.getPackageInfo(appPackage, PackageManager.GET_META_DATA) - val installTime = DateUtils.getRelativeTimeSpanString(packageInfo.firstInstallTime) - warningAppInstallDate.text = - getString(R.string.oreo_autofill_warning_publisher_install_time, installTime) - val appInfo = - packageManager.getApplicationInfo(appPackage, PackageManager.GET_META_DATA) - warningAppName.text = "“${packageManager.getApplicationLabel(appInfo)}”" + with(binding) { + val packageInfo = + packageManager.getPackageInfo(appPackage, PackageManager.GET_META_DATA) + val installTime = DateUtils.getRelativeTimeSpanString(packageInfo.firstInstallTime) + warningAppInstallDate.text = + getString(R.string.oreo_autofill_warning_publisher_install_time, installTime) + val appInfo = + packageManager.getApplicationInfo(appPackage, PackageManager.GET_META_DATA) + warningAppName.text = "“${packageManager.getApplicationLabel(appInfo)}”" - val currentHash = computeCertificatesHash(this, appPackage) - warningAppAdvancedInfo.text = getString( - R.string.oreo_autofill_warning_publisher_advanced_info_template, - appPackage, - currentHash - ) + val currentHash = computeCertificatesHash(this@AutofillPublisherChangedActivity, appPackage) + warningAppAdvancedInfo.text = getString( + R.string.oreo_autofill_warning_publisher_advanced_info_template, + appPackage, + currentHash + ) + } } catch (exception: Exception) { e(exception) { "Failed to retrieve package info for $appPackage" } finish() |
