III-sonic

Untitled

Dec 3rd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.65 KB | None | 0 0
  1. adapte
  2.  
  3. package com.skmobile.cataloguemovieuiux;
  4.  
  5. import android.content.Context;
  6. import android.icu.text.DateFormat;
  7. import android.icu.text.SimpleDateFormat;
  8. import android.support.v7.widget.RecyclerView;
  9. import android.view.LayoutInflater;
  10. import android.view.View;
  11. import android.view.ViewGroup;
  12. import android.widget.ImageView;
  13. import android.widget.RelativeLayout;
  14. import android.widget.TextView;
  15.  
  16. import com.bumptech.glide.Glide;
  17.  
  18. import java.text.ParseException;
  19. import java.util.ArrayList;
  20. import java.util.Date;
  21.  
  22. import butterknife.BindView;
  23. import butterknife.ButterKnife;
  24.  
  25. /**
  26. * Created by ADMIN on 03/12/2017.
  27. */
  28.  
  29. public class MovieAdapter extends RecyclerView.Adapter<MovieAdapter.ViewHolder> {
  30.  
  31. ArrayList<MovieItems> movieItemses;
  32. Context context;
  33.  
  34. public MovieAdapter(Context context) {
  35. this.context = context;
  36.  
  37. }
  38.  
  39. private ArrayList<MovieItems> getMovieItemses() {
  40. return movieItemses;
  41. }
  42.  
  43. void setMovieItemses(ArrayList<MovieItems> movieItemses) {
  44. this.movieItemses = movieItemses;
  45. }
  46.  
  47. public void setData(ArrayList<MovieItems> items) {
  48. movieItemses = items;
  49. notifyDataSetChanged();
  50. }
  51. public void addItem(final MovieItems item){
  52. movieItemses.add(item);
  53. notifyDataSetChanged();
  54. }
  55. public void clearData(){
  56.  
  57. movieItemses.clear();
  58. }
  59. @Override
  60. public int getItemViewType(int position) {
  61. return 1;
  62. }
  63.  
  64. @Override
  65. public long getItemId(int position) {
  66. return position;
  67. }
  68.  
  69.  
  70. @Override
  71. public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  72. View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_list, parent, false);
  73. return new ViewHolder(view);
  74. }
  75.  
  76. @Override
  77. public void onBindViewHolder(ViewHolder holder, int position) {
  78.  
  79. MovieItems mv = getMovieItemses().get(position);
  80.  
  81. Glide.with(context).load
  82. ("http://image.tmdb.org/t/p/w185"+mv
  83. .getImage())
  84. .into(holder.ViewImage);
  85. holder.textViewTitle.setText(mv.getTitle());
  86. holder.textViewDescription.setText(mv.getDiscripsi());
  87. holder.textViewDate.setText(mv.getDate());
  88. DateFormat inputFormat = new SimpleDateFormat("yyyy-M-dd");
  89. DateFormat outputFormat = new SimpleDateFormat("EEEE, MMM dd, yyyy");
  90. Date date = null;
  91. try {
  92. date = inputFormat.parse(mv.getDate());
  93. holder.textViewDate.setText(outputFormat.format(date));
  94. } catch (ParseException e) {
  95. holder.textViewDate.setText(mv.getDate());
  96. }
  97.  
  98.  
  99. }
  100.  
  101. @Override
  102. public int getItemCount() {
  103. return getMovieItemses().size();
  104. }
  105.  
  106. class ViewHolder extends RecyclerView.ViewHolder {
  107. @BindView(R.id.tv_title)
  108. TextView textViewTitle;
  109.  
  110. @BindView(R.id.img_item_photo)
  111. ImageView ViewImage;
  112.  
  113. @BindView(R.id.tv_description)
  114. TextView textViewDescription;
  115.  
  116. @BindView(R.id.tv_date)
  117. TextView textViewDate;
  118.  
  119. @BindView(R.id.nowplaying)
  120. RelativeLayout relativeLayout;
  121. ViewHolder(View view){
  122. super(view);
  123.  
  124. ButterKnife.bind(this, view);
  125. }
  126.  
  127.  
  128.  
  129. }
  130. }
  131. ===============================================
  132. movieitems
  133. package com.skmobile.cataloguemovieuiux;
  134.  
  135. import android.os.Build;
  136. import android.support.annotation.RequiresApi;
  137.  
  138. import org.json.JSONException;
  139. import org.json.JSONObject;
  140.  
  141. /**
  142. * Created by ADMIN on 03/12/2017.
  143. */
  144.  
  145. public class MovieItems {
  146. private String title;
  147. private String image;
  148. private String discripsi;
  149. private String date;
  150. private String backdor;
  151.  
  152. @RequiresApi(api = Build.VERSION_CODES.N)
  153. public MovieItems(JSONObject object) {
  154. try {
  155.  
  156. String title = object.getString("original_title");
  157. String image = object.getString("poster_path");
  158. String description = object.getString("overview");
  159. String date = object.getString("release_date");
  160. String backdor = object.getString("backdrop_path");
  161.  
  162.  
  163. this.title = title;
  164. this.backdor = backdor;
  165. this.discripsi = description;
  166. this.image = image;
  167. this.date = date;
  168. } catch (JSONException e) {
  169. e.printStackTrace();
  170. }
  171. }
  172.  
  173. public String getTitle() {
  174. return title;
  175. }
  176.  
  177. public void setTitle(String title) {
  178. this.title = title;
  179. }
  180.  
  181. public String getImage() {
  182. return image;
  183. }
  184.  
  185. public void setImage(String image) {
  186. this.image = image;
  187. }
  188.  
  189. public String getDiscripsi() {
  190. return discripsi;
  191. }
  192.  
  193. public void setDiscripsi(String discripsi) {
  194. this.discripsi = discripsi;
  195. }
  196.  
  197. public String getDate() {
  198. return date;
  199. }
  200.  
  201. public void setDate(String date) {
  202. this.date = date;
  203. }
  204.  
  205. public String getBackdor() {
  206. return backdor;
  207. }
  208.  
  209. public void setBackdor(String backdor) {
  210. this.backdor = backdor;
  211. }
  212.  
  213.  
  214. }
  215. =========================================
  216. taskmovie
  217.  
  218. package com.skmobile.cataloguemovieuiux;
  219.  
  220. import android.support.v4.content.AsyncTaskLoader;
  221. import android.content.Context;
  222. import android.os.Build;
  223. import android.support.annotation.RequiresApi;
  224.  
  225. import com.loopj.android.http.AsyncHttpResponseHandler;
  226. import com.loopj.android.http.SyncHttpClient;
  227.  
  228. import org.json.JSONArray;
  229. import org.json.JSONObject;
  230.  
  231. import java.util.ArrayList;
  232. import cz.msebera.android.httpclient.Header;
  233.  
  234. import static com.skmobile.cataloguemovieuiux.BuildConfig.NOW_PLAYING_URL;
  235. import static com.skmobile.cataloguemovieuiux.BuildConfig.PHOTO_PROFILE_URL;
  236. import static com.skmobile.cataloguemovieuiux.BuildConfig.UPCOMING_URL;
  237. import static com.skmobile.cataloguemovieuiux.BuildConfig.PEOPLE_URL;
  238. import static com.skmobile.cataloguemovieuiux.BuildConfig.TVMOVIE_URL;
  239. import static com.skmobile.cataloguemovieuiux.BuildConfig.TOPRATE_URL;
  240. import static com.skmobile.cataloguemovieuiux.BuildConfig.SEARCH_URL;
  241.  
  242.  
  243.  
  244. /**
  245. * Created by ADMIN on 03/12/2017.
  246. */
  247.  
  248. public class MyTaskMovie extends AsyncTaskLoader<ArrayList<MovieItems>> {
  249.  
  250. private ArrayList<MovieItems> mMovieData;
  251. private boolean mResult;
  252. private String category;
  253. private String keyword;
  254.  
  255. public MyTaskMovie(final Context context, String category, String keyword) {
  256. super(context);
  257. this.category = category;
  258. this.keyword = keyword;
  259. onContentChanged();
  260.  
  261. }
  262.  
  263. @Override
  264. protected void onStartLoading() {
  265. if (takeContentChanged())
  266. forceLoad();
  267. else if (mResult)
  268. deliverResult(mMovieData);
  269. }
  270.  
  271. @Override
  272. public void deliverResult(final ArrayList<MovieItems> data) {
  273. mMovieData = data;
  274. mResult = true;
  275. super.deliverResult(data);
  276. }
  277.  
  278. @Override
  279. protected void onReset() {
  280. super.onReset();
  281. onStopLoading();
  282. if (mResult) {
  283. onReleaseResources(mMovieData);
  284. mMovieData = null;
  285. mResult = false;
  286. }
  287. }
  288.  
  289.  
  290.  
  291.  
  292. @Override
  293. public ArrayList<MovieItems> loadInBackground() {
  294. SyncHttpClient client = new SyncHttpClient();
  295.  
  296. final ArrayList<MovieItems> movieItemses = new ArrayList<>();
  297.  
  298. String url = null;
  299. switch (category){
  300. case "now_playing":
  301. url = NOW_PLAYING_URL;
  302. break;
  303. case "upcoming":
  304. url = UPCOMING_URL;
  305. break;
  306. case "search":
  307. url = SEARCH_URL+"&language=en-US&query="+keyword;
  308. break;
  309. case "toprate":
  310. url = TOPRATE_URL;
  311. break;
  312. case "people":
  313. url = PEOPLE_URL;
  314. break;
  315. case "tvmovie":
  316. url = TVMOVIE_URL;
  317. break;
  318. }
  319.  
  320. client.get(url, new AsyncHttpResponseHandler() {
  321. @Override
  322. public void onStart() {
  323. super.onStart();
  324. setUseSynchronousMode(true);
  325. }
  326.  
  327.  
  328. @RequiresApi(api = Build.VERSION_CODES.N)
  329. @Override
  330. public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
  331. try {
  332. String result = new String(responseBody);
  333. JSONObject responeseObject = new JSONObject(result);
  334. JSONArray list = responeseObject.getJSONArray("results");
  335.  
  336. for (int i = 0; i < list.length(); i++) {
  337. JSONObject movie = list.getJSONObject(i);
  338. MovieItems movieItems = new MovieItems(movie);
  339. movieItemses.add(movieItems);
  340. }
  341. } catch (Exception e) {
  342. e.printStackTrace();
  343. }
  344. }
  345.  
  346. @Override
  347. public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
  348.  
  349. }
  350.  
  351. });
  352. return movieItemses;
  353.  
  354. }
  355. protected void onReleaseResources(ArrayList<MovieItems> data) {
  356.  
  357. }
  358. }
  359.  
  360. ============================================================
  361. nowplaying
  362.  
  363. package com.skmobile.cataloguemovieuiux;
  364.  
  365.  
  366. import android.os.Build;
  367. import android.support.annotation.RequiresApi;
  368. import android.support.v4.app.LoaderManager;
  369. import android.support.v4.content.Loader;
  370. import android.os.Bundle;
  371. import android.support.v4.app.Fragment;
  372. import android.support.v7.widget.RecyclerView;
  373. import android.view.LayoutInflater;
  374. import android.view.View;
  375. import android.view.ViewGroup;
  376.  
  377. import java.util.ArrayList;
  378.  
  379. import butterknife.BindView;
  380.  
  381.  
  382. /**
  383. * A simple {@link Fragment} subclass.
  384. */
  385. public class NowPlaying extends Fragment implements LoaderManager.LoaderCallbacks<ArrayList<MovieItems>>{
  386. @BindView(R.id.rv_category)
  387. RecyclerView recyclerView;
  388. ArrayList<MovieItems> list = new ArrayList<>();
  389. MovieAdapter adapter;
  390.  
  391. public NowPlaying() {
  392. // Required empty public constructor
  393. }
  394.  
  395.  
  396. @Override
  397. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  398. Bundle savedInstanceState) {
  399. // Inflate the layout for this fragment
  400. View view = inflater.inflate(R.layout.fragment_list, container, false);
  401. recyclerView.setHasFixedSize(true);
  402.  
  403.  
  404. adapter.notifyDataSetChanged();
  405.  
  406.  
  407. recyclerView.setAdapter(adapter);
  408.  
  409.  
  410. return view;
  411. }
  412.  
  413. @Override
  414. public void onActivityCreated(Bundle savedInstanceState){
  415. super.onActivityCreated(savedInstanceState);
  416. Bundle bundle = new Bundle();
  417. getLoaderManager().initLoader(0, bundle, this);
  418.  
  419. }
  420.  
  421. @RequiresApi(api = Build.VERSION_CODES.KITKAT)
  422. @Override
  423. public Loader<ArrayList<MovieItems>> onCreateLoader(int id, Bundle args) {
  424. return new MyTaskMovie(getActivity(), "now_playing", null);
  425. }
  426.  
  427. @Override
  428. public void onLoadFinished(Loader<ArrayList<MovieItems>> loader, ArrayList<MovieItems> data) {
  429. adapter.setData(data);
  430. list = data;
  431.  
  432.  
  433. }
  434.  
  435. @Override
  436. public void onLoaderReset(Loader<ArrayList<MovieItems>> loader) {
  437. adapter.setData(null);
  438.  
  439. }
  440.  
  441.  
  442. }
  443.  
  444.  
  445. ==================================================
  446. upcoming
  447. package com.skmobile.cataloguemovieuiux;
  448.  
  449.  
  450. import android.os.Build;
  451. import android.os.Bundle;
  452. import android.support.annotation.RequiresApi;
  453. import android.support.v4.app.Fragment;
  454. import android.support.v4.app.LoaderManager;
  455. import android.support.v4.content.Loader;
  456. import android.support.v7.widget.RecyclerView;
  457. import android.view.LayoutInflater;
  458. import android.view.View;
  459. import android.view.ViewGroup;
  460.  
  461. import java.util.ArrayList;
  462.  
  463. import butterknife.BindView;
  464.  
  465.  
  466. /**
  467. * A simple {@link Fragment} subclass.
  468. */
  469. public class UpComing extends Fragment implements LoaderManager.LoaderCallbacks<ArrayList<MovieItems>>{
  470. @BindView(R.id.rv_category)
  471. RecyclerView recyclerView;
  472. ArrayList<MovieItems> list = new ArrayList<>();
  473. MovieAdapter adapter;
  474.  
  475. public UpComing() {
  476. // Required empty public constructor
  477. }
  478.  
  479.  
  480. @Override
  481. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  482. Bundle savedInstanceState) {
  483. // Inflate the layout for this fragment
  484. View view = inflater.inflate(R.layout.fragment_list, container, false);
  485. recyclerView.setHasFixedSize(true);
  486.  
  487. adapter.notifyDataSetChanged();
  488.  
  489.  
  490. recyclerView.setAdapter(adapter);
  491.  
  492.  
  493. return view;
  494. }
  495. @Override
  496. public void onActivityCreated(Bundle savedInstanceState){
  497. super.onActivityCreated(savedInstanceState);
  498. Bundle bundle = new Bundle();
  499. getLoaderManager().initLoader(0, bundle, this);
  500.  
  501. }
  502.  
  503. @RequiresApi(api = Build.VERSION_CODES.KITKAT)
  504. @Override
  505. public Loader<ArrayList<MovieItems>> onCreateLoader(int id, Bundle args) {
  506. return new MyTaskMovie(getActivity(), "upcoming", null);
  507. }
  508.  
  509. @Override
  510. public void onLoadFinished(Loader<ArrayList<MovieItems>> loader, ArrayList<MovieItems> data) {
  511. adapter.setData(data);
  512. list = data;
  513.  
  514.  
  515. }
  516.  
  517. @Override
  518. public void onLoaderReset(Loader<ArrayList<MovieItems>> loader) {
  519. adapter.setData(null);
  520.  
  521. }
  522.  
  523.  
  524. }
Add Comment
Please, Sign In to add comment