Advertisement
Guest User

Untitled

a guest
Jan 28th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. package bezkol.samarama.aplikacjafilmowa;
  2.  
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.media.Image;
  6. import android.net.Uri;
  7. import android.os.Bundle;
  8. import android.support.v4.app.Fragment;
  9. import android.util.Log;
  10. import android.view.LayoutInflater;
  11. import android.view.View;
  12. import android.view.ViewGroup;
  13. import android.widget.CheckBox;
  14. import android.widget.ImageView;
  15. import android.widget.TextView;
  16. import android.widget.Toast;
  17.  
  18. import com.squareup.picasso.Picasso;
  19.  
  20. import static java.lang.String.valueOf;
  21.  
  22.  
  23. public class tab1 extends Fragment {
  24. @Override
  25. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  26. Bundle savedInstanceState) {
  27. View rootView = inflater.inflate(R.layout.tab1, container, false);
  28.  
  29. ImageView plakat = (ImageView) rootView.findViewById(R.id.zdjecie);
  30. TextView nazwa = (TextView) rootView.findViewById(R.id.nazwa);
  31. TextView opis = (TextView) rootView.findViewById(R.id.opis);
  32. ImageView filmweb_link = (ImageView) rootView.findViewById(R.id.filmweb);
  33. CheckBox ulubiony = (CheckBox) rootView.findViewById(R.id.ulubione);
  34. LikesDatabaseHelper db = LikesDatabaseHelper.getInstance(getContext());
  35. DatabaseHelper db2 = DatabaseHelper.getInstance(getContext());
  36. Context context = getActivity().getApplicationContext();
  37.  
  38. String link = "pusto";
  39. String name = (String) getActivity().getIntent().getExtras().get("tytul");
  40. String co = (String) getActivity().getIntent().getExtras().get("co");
  41. String ktozalogowany = db2.KtoZalogowany();
  42. nazwa.setText(name);
  43. opis.setText((String) getActivity().getIntent().getExtras().get("opis"));
  44. Picasso.with(getContext()).load((String) getActivity().getIntent().getExtras().get("img_url")).resize(500,739).into(plakat);
  45.  
  46. filmweb_link.setOnClickListener(new View.OnClickListener() {
  47. @Override
  48. public void onClick(View view) {
  49. Intent browserIntent = new Intent(Intent.ACTION_VIEW,
  50. Uri.parse((String) getActivity().getIntent().getExtras().get("filmweb_url")));
  51. startActivity(browserIntent);
  52. }
  53. });
  54.  
  55. if(db.isAdded(name,ktozalogowany)){
  56. ulubiony.setChecked(true);
  57. }
  58. ulubiony.setOnClickListener(new View.OnClickListener() {
  59. @Override
  60. public void onClick(View view) {
  61. if (!ktozalogowany.equals("")) {
  62. if (db.isAdded(name, ktozalogowany)) {
  63. db.deleteRecord(name, ktozalogowany);
  64. ulubiony.setChecked(false);
  65. new LikesDatabaseOnline(context).execute(name, ktozalogowany, "delete", "", "");
  66. } else {
  67. db.addRecord(name, link, co, ktozalogowany);
  68. ulubiony.setChecked(true);
  69. new LikesDatabaseOnline(context).execute(name, "pusto", co, ktozalogowany, "");
  70. }
  71. db.close();
  72. } else {
  73. Toast.makeText(context, "Najpierw należy się zalogować", Toast.LENGTH_LONG).show();
  74. ulubiony.setChecked(false);
  75. }
  76.  
  77. }});
  78. db2.close();
  79. return rootView;
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement