ipdan4ik

[lb7] ItemActivity.kt

Apr 16th, 2021
729
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.lb7
  2.  
  3. import android.app.Activity
  4. import android.content.Intent
  5. import android.graphics.BitmapFactory
  6. import android.location.Location
  7. import androidx.appcompat.app.AppCompatActivity
  8. import android.os.Bundle
  9. import android.os.Environment
  10. import android.provider.MediaStore
  11. import android.view.Menu
  12. import android.view.MenuItem
  13. import android.view.View
  14. import android.widget.EditText
  15. import android.widget.ImageView
  16. import androidx.core.content.FileProvider
  17. import java.io.File
  18.  
  19. class ItemActivity : AppCompatActivity() {
  20.     private var index = 0
  21.     private lateinit var item: Item
  22.     override fun onCreate(savedInstanceState: Bundle?) {
  23.         super.onCreate(savedInstanceState)
  24.         setContentView(R.layout.activity_item)
  25.  
  26.         val intent = intent
  27.         index = intent?.getIntExtra("index", -1) ?: -1
  28.         item = intent?.getParcelableExtra("item") ?: Item()
  29.         val editTitle = findViewById<EditText>(R.id.title)
  30.         editTitle.setText(item.title)
  31.         val editLatitude = findViewById<EditText>(R.id.latitude)
  32.         editLatitude.setText(item.latitude.toString())
  33.         val editLongitude = findViewById<EditText>(R.id.longitude)
  34.         editLongitude.setText(item.longitude.toString())
  35.  
  36.         supportActionBar?.setDisplayHomeAsUpEnabled(true)
  37.     }
  38.     override fun onCreateOptionsMenu(menu: Menu?): Boolean {
  39.         menuInflater.inflate(R.menu.add_item, menu)
  40.         return super.onCreateOptionsMenu(menu)
  41.     }
  42.     override fun onOptionsItemSelected(item: MenuItem): Boolean {
  43.         if (item.itemId == android.R.id.home) {
  44.             finish()
  45.             return true
  46.         }
  47.         if (item.itemId == R.id.action_save) {
  48.             this.item.title = findViewById<EditText>(R.id.title).text.toString()
  49.             this.item.latitude = findViewById<EditText>(R.id.latitude).text.toString().toDouble()
  50.             this.item.longitude = findViewById<EditText>(R.id.longitude).text.toString().toDouble()
  51.             val intent = Intent()
  52.             intent.putExtra("index", index)
  53.             intent.putExtra("item", this.item)
  54.             setResult(Activity.RESULT_OK, intent)
  55.  
  56.             finish()
  57.             return true
  58.         }
  59.         if (item.itemId == R.id.action_delete) {
  60.             val intent = Intent()
  61.             intent.putExtra("index", index)
  62.             intent.putExtra("item", this.item)
  63.             setResult(111 , intent)
  64.  
  65.             finish()
  66.             return true
  67.         }
  68.  
  69.         return super.onOptionsItemSelected(item)
  70.     }
  71.  
  72.  
  73. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×