Skip to content

Commit

Permalink
Add ViewBinding to QrCodeSignInFragment, SettingsActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgCantor committed Apr 8, 2021
1 parent a06b8f7 commit 5c39010
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
4 changes: 4 additions & 0 deletions automotive/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
viewBinding true
}

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ import androidx.core.content.ContextCompat.getDrawable
import androidx.core.text.HtmlCompat
import androidx.fragment.app.Fragment
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.qr_sign_in.app_icon
import kotlinx.android.synthetic.main.qr_sign_in.footer
import kotlinx.android.synthetic.main.qr_sign_in.primary_message
import kotlinx.android.synthetic.main.qr_sign_in.qr_code
import kotlinx.android.synthetic.main.qr_sign_in.secondary_message
import kotlinx.android.synthetic.main.qr_sign_in.toolbar
import com.example.android.uamp.automotive.databinding.QrSignInBinding

/**
* Fragment that is used to facilitate QR code sign-in. Users scan a QR code rendered by this
Expand All @@ -39,34 +34,43 @@ import kotlinx.android.synthetic.main.qr_sign_in.toolbar
*/
class QrCodeSignInFragment : Fragment(R.layout.qr_sign_in) {

private var binding: QrSignInBinding? = null

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding = QrSignInBinding.bind(view)

val context = requireContext()

toolbar.setNavigationOnClickListener {
binding?.toolbar?.setNavigationOnClickListener {
requireActivity().supportFragmentManager.popBackStack()
}

app_icon.setImageDrawable(getDrawable(requireContext(), R.drawable.aural_logo))
primary_message.text = getString(R.string.qr_sign_in_primary_text)
secondary_message.text = getString(R.string.qr_sign_in_secondary_text)
binding?.appIcon?.setImageDrawable(getDrawable(requireContext(), R.drawable.aural_logo))
binding?.primaryMessage?.text = getString(R.string.qr_sign_in_primary_text)
binding?.secondaryMessage?.text = getString(R.string.qr_sign_in_secondary_text)

// Links in footer text should be clickable.
footer.text = HtmlCompat.fromHtml(
binding?.footer?.text = HtmlCompat.fromHtml(
context.getString(R.string.sign_in_footer),
HtmlCompat.FROM_HTML_MODE_LEGACY
)
footer.movementMethod = LinkMovementMethod.getInstance()
binding?.footer?.movementMethod = LinkMovementMethod.getInstance()

setQrCode(getString(R.string.qr_code_url))
}

override fun onDestroy() {
super.onDestroy()
binding = null
}

/**
* Sets the QR code rendered on this sign in screen.
*
* @param code The QR code to display.
*/
private fun setQrCode(url: String) {
Glide.with(this).load(url).into(qr_code)
binding?.qrCode?.let { Glide.with(this).load(url).into(it) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@ package com.example.android.uamp.automotive

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_settings.toolbar
import com.example.android.uamp.automotive.databinding.ActivitySettingsBinding

/**
* This class exposes application settings
* for integration with MediaCenter in Android Automotive.
*/
class SettingsActivity : AppCompatActivity() {

private lateinit var binding: ActivitySettingsBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
binding = ActivitySettingsBinding.inflate(layoutInflater)
setContentView(binding.root)

setSupportActionBar(toolbar)
setSupportActionBar(binding.toolbar)
supportActionBar?.setHomeButtonEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)

Expand Down

0 comments on commit 5c39010

Please sign in to comment.