Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.34 KB | None | 0 0
  1. package powercom.androidcustomerapp
  2.  
  3. import android.content.Intent
  4. import android.os.Bundle
  5. import android.support.v7.app.AppCompatActivity
  6. import android.view.View
  7. import android.widget.Toast
  8. import com.google.gson.Gson
  9. import kotlinx.android.synthetic.main.activity_startup.*
  10. import powercom.androidcustomerapp.controllers.StartupController
  11. import powercom.androidcustomerapp.interfaces.IControllers
  12. import powercom.androidcustomerapp.network.entities.Language
  13. import powercom.androidcustomerapp.network.entities.ServerRegion
  14. import powercom.androidcustomerapp.interfaces.IViews
  15.  
  16. class StartupActivity : AppCompatActivity(), IViews.Startup{
  17.  
  18.     private var nextActivityBundle: Bundle = Bundle()
  19.     private val controller: IControllers.Startup = StartupController(this)
  20.     private val gson = Gson()
  21.  
  22.     override fun onCreate(savedInstanceState: Bundle?) {
  23.         super.onCreate(savedInstanceState)
  24.         setContentView(R.layout.activity_startup)
  25.  
  26.         if (hasRegion())
  27.             toMain()
  28.         else
  29.             controller.getStartupData()
  30.     }
  31.  
  32.     override fun toRegions() {
  33.         var intent = Intent(this, RegionActivity::class.java)
  34.  
  35.         intent.putExtras(nextActivityBundle)
  36.         intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
  37.         startActivity(intent)
  38.         finish()
  39.     }
  40.  
  41.     private fun toMain() {
  42.         var intent = Intent(this, MainActivity::class.java)
  43.  
  44.         intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
  45.         startActivity(intent)
  46.         finish()
  47.     }
  48.  
  49.     override fun showProgress(isShowing: Boolean) {
  50.         if (isShowing) {
  51.             this.progress_layout.visibility = View.VISIBLE
  52.         }
  53.         else {
  54.             this.progress_layout.visibility = View.GONE
  55.         }
  56.     }
  57.  
  58.     override fun showToast(msg: String) {
  59.         Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
  60.     }
  61.  
  62.     override fun updateLanguages(languages: List<Language>) {
  63.         nextActivityBundle.putString("languages", this.gson.toJson(languages))
  64.     }
  65.  
  66.     override fun updateRegions(regions: List<ServerRegion>) {
  67.         nextActivityBundle.putString("regions", this.gson.toJson(regions))
  68.     }
  69.  
  70.     override fun updateStatusText(text: String) {
  71.         this.progress_text.text = text
  72.     }
  73.  
  74.     private fun hasRegion(): Boolean {
  75.         return prefs.region.id != -1
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement