Advertisement
III-sonic

Untitled

Dec 6th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. package com.skmobile.cataloguemovieuiux;
  2.  
  3.  
  4. import android.app.PendingIntent;
  5. import android.content.Intent;
  6. import android.os.Build;
  7. import android.support.annotation.RequiresApi;
  8. import android.support.v4.app.LoaderManager;
  9. import android.support.v4.app.TaskStackBuilder;
  10. import android.support.v4.content.Loader;
  11. import android.os.Bundle;
  12. import android.support.v4.app.Fragment;
  13. import android.support.v7.widget.LinearLayoutManager;
  14. import android.support.v7.widget.RecyclerView;
  15. import android.text.TextUtils;
  16. import android.view.LayoutInflater;
  17. import android.view.View;
  18. import android.view.ViewGroup;
  19. import android.widget.Button;
  20. import android.widget.Toast;
  21.  
  22. import java.util.ArrayList;
  23.  
  24. import butterknife.BindView;
  25. import butterknife.OnClick;
  26. import butterknife.OnItemClick;
  27.  
  28.  
  29. /**
  30. * A simple {@link Fragment} subclass.
  31. */
  32. public class NowPlaying extends Fragment implements LoaderManager.LoaderCallbacks<ArrayList<MovieItems>>{
  33.  
  34. RecyclerView recyclerView;
  35. RecyclerView.LayoutManager layoutManager;
  36. Button detail;
  37. private final int LOAD_ID =110;
  38.  
  39. ArrayList<MovieItems> list = new ArrayList<>();
  40. MovieAdapter adapter;
  41.  
  42.  
  43. public NowPlaying() {
  44. // Required empty public constructor
  45. }
  46.  
  47.  
  48. @Override
  49. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  50. Bundle savedInstanceState) {
  51. // Inflate the layout for this fragment
  52. View view = inflater.inflate(R.layout.content, container, false);
  53. detail = (Button)view.findViewById(R.id.btn_set_detail);
  54. detail.setOnClickListener(myListener);
  55. recyclerView = (RecyclerView)view.findViewById(R.id.rv_category);
  56. recyclerView.setHasFixedSize(true);
  57. adapter = new MovieAdapter(getActivity());
  58.  
  59. adapter.notifyDataSetChanged();
  60. recyclerView.setAdapter(adapter);
  61. layoutManager = new LinearLayoutManager(getActivity());
  62.  
  63. detail.getText().toString();
  64.  
  65. recyclerView.setLayoutManager(layoutManager);
  66.  
  67. return view;
  68. }
  69.  
  70. @Override
  71. public void onActivityCreated(Bundle savedInstanceState){
  72. super.onActivityCreated(savedInstanceState);
  73. Bundle bundle = new Bundle();
  74. getLoaderManager().initLoader(0, bundle, this);
  75.  
  76. }
  77.  
  78.  
  79.  
  80. @RequiresApi(api = Build.VERSION_CODES.KITKAT)
  81. @Override
  82. public Loader<ArrayList<MovieItems>> onCreateLoader(int id, Bundle args) {
  83. return new MyTaskMovie(getActivity(), "now_playing" , null);
  84. }
  85.  
  86. @Override
  87. public void onLoadFinished(Loader<ArrayList<MovieItems>> loader, ArrayList<MovieItems> data) {
  88. adapter.setData(data);
  89. list = new ArrayList<>();
  90. list = data;
  91.  
  92. list.addAll(data);
  93.  
  94.  
  95. }
  96.  
  97. @Override
  98. public void onLoaderReset(Loader<ArrayList<MovieItems>> loader) {
  99.  
  100. adapter.setData(null);
  101.  
  102.  
  103. }
  104. View.OnClickListener myListener = new View.OnClickListener() {
  105. @Override
  106. public void onClick(View v) {
  107. detail.getText().toString();
  108. Bundle bundle = new Bundle();
  109. showList();
  110.  
  111. }
  112. };
  113. private void showList(MovieItems movieItems){
  114. Intent intent = new Intent(getActivity(), DetailActivity.class);
  115. intent.putExtra(DetailActivity.EXTRA_TITLE, movieItems.getTitle());
  116. intent.putExtra(DetailActivity.EXTRA_DISCRIPTION, movieItems.getDiscripsi());
  117. intent.putExtra(DetailActivity.EXTRA_DATE, movieItems.getDate());
  118. intent.putExtra(DetailActivity.EXTRA_BACKDOR, movieItems.getBackdor());
  119. Toast.makeText(getActivity(), movieItems.getTitle(), Toast.LENGTH_LONG).show();
  120. PendingIntent pendingIntent = TaskStackBuilder.create(this)
  121. .addParentStack(DetailActivity.class)
  122. .addNextIntent(intent)
  123. .getPendingIntent(LOAD_ID, PendingIntent.FLAG_UPDATE_CURRENT);
  124. startActivity(intent);
  125. }
  126.  
  127.  
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement