muhamad_lukman

DetailActivty

Jul 7th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.64 KB | None | 0 0
  1. package com.example.subsmission3.activity;
  2.  
  3. import android.arch.lifecycle.Observer;
  4. import android.arch.lifecycle.ViewModelProviders;
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.support.annotation.Nullable;
  8. import android.support.v7.app.AppCompatActivity;
  9. import android.view.View;
  10. import android.widget.ImageView;
  11. import android.widget.ProgressBar;
  12. import android.widget.TextView;
  13.  
  14. import com.bumptech.glide.Glide;
  15. import com.example.subsmission3.R;
  16. import com.example.subsmission3.model.ModelMovie;
  17. import com.example.subsmission3.viewmodel.MainViewModel;
  18.  
  19.  
  20.  
  21. public class DetailActivity extends AppCompatActivity {
  22.     ProgressBar progressBar;
  23.     TextView title,date,desc;
  24.     private MainViewModel mainViewModel;
  25.     ImageView image;
  26.     private static int idMovie = 0;
  27.     private static String jenis;
  28.     private static final String file_path = "https://image.tmdb.org/t/p/w342";
  29.  
  30.     @Override
  31.     protected void onCreate(@Nullable Bundle savedInstanceState) {
  32.         super.onCreate(savedInstanceState);
  33.         setContentView(R.layout.activity_detail);
  34.         image = findViewById(R.id.img_d);
  35.         title = findViewById(R.id.judul);
  36.         progressBar = findViewById(R.id.progressBar1);
  37.         date = findViewById(R.id.tangggal);
  38.         desc = findViewById(R.id.desc);
  39.         mainViewModel = ViewModelProviders.of(this).get(MainViewModel.class);
  40.         mainViewModel.getMovie().observe(this, new Observer<ModelMovie>() {
  41.             @Override
  42.             public void onChanged(@Nullable ModelMovie modelMovie) {
  43.             if (modelMovie != null){
  44.                 title.setText(modelMovie.getName());
  45.                 date.setText(modelMovie.getTnggal());
  46.                 desc.setText(modelMovie.getDeskripsi());
  47.                 Glide.with(image.getContext()).load(file_path+modelMovie.getPhoto()).into(image);
  48.                 showLoading(false);
  49.  
  50.             }
  51.  
  52.             }
  53.         });
  54.  
  55.         idMovie = getIntent().getIntExtra("data",0);
  56.         jenis = getIntent().getStringExtra("jenis");
  57.         setData();
  58.  
  59.     }
  60.  
  61.     private void setData() {
  62.         try {
  63.             if (jenis == "isMovie"){
  64.                 mainViewModel.setMovie(true,idMovie);
  65.             }else{
  66.             mainViewModel.setMovie(false,idMovie);
  67.             }
  68.             showLoading(true);
  69.         }catch (Exception e){
  70.             e.printStackTrace();
  71.  
  72.         }
  73.  
  74.     }
  75.     private void showLoading(Boolean loading){
  76.         if (loading == true){
  77.             progressBar.setVisibility(View.VISIBLE);
  78.         }else{
  79.             progressBar.setVisibility(View.GONE);
  80.         }
  81.  
  82.     }
  83.  
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment