davhilmawan

DetailActivity.kt

Nov 22nd, 2020
612
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.muhammaddavidhilmawan_18102023.praktikum6
  2.  
  3. import android.app.Activity
  4. import android.content.Intent
  5. import android.os.Bundle
  6. import android.os.Parcelable
  7. import com.google.android.material.appbar.CollapsingToolbarLayout
  8. import com.google.android.material.floatingactionbutton.FloatingActionButton
  9. import com.google.android.material.snackbar.Snackbar
  10. import androidx.appcompat.app.AppCompatActivity
  11. import com.bumptech.glide.Glide
  12. import com.bumptech.glide.request.RequestOptions
  13. import kotlinx.android.synthetic.main.activity_detail.*
  14. import kotlinx.android.synthetic.main.content_scrolling.*
  15.  
  16. class DetailActivity : AppCompatActivity() {
  17.  
  18.     override fun onCreate(savedInstanceState: Bundle?) {
  19.         val myData by getParcelableExtra<MyData>(DetailActivity.EXTRA_MYDATA)
  20.         super.onCreate(savedInstanceState)
  21.         setContentView(R.layout.activity_detail)
  22.         setSupportActionBar(findViewById(R.id.toolbar))
  23.         findViewById<FloatingActionButton>(R.id.fab).setOnClickListener { view ->
  24.             Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
  25.                 .setAction("Action", null).show()
  26.             val moveWithObjectIntent = Intent(this, MapsActivity::class.java)
  27.             moveWithObjectIntent.putExtra(MapsActivity.EXTRA_MYDATA, myData)
  28.             startActivity(moveWithObjectIntent)
  29.         }
  30.         supportActionBar?.title = myData.name.toString()
  31.         supportActionBar?.setDisplayHomeAsUpEnabled(true)
  32.         tv_detail_description.text = myData.description.toString()
  33.         Glide.with(this)
  34.             .load(myData.photo.toString())
  35.             .apply(RequestOptions().override(700, 700))
  36.             .into(iv_detail_photo)
  37.     }
  38.     companion object {
  39.         const val EXTRA_MYDATA = "extra_mydata"
  40.     }
  41.     inline fun <reified T : Parcelable> Activity.getParcelableExtra(key: String) = lazy {
  42.         intent.getParcelableExtra<T>(key)
  43.     }
  44.     override fun onSupportNavigateUp(): Boolean {
  45.         onBackPressed()
  46.         return true
  47.     }
  48. }
RAW Paste Data