Exemplo n.º 1
0
  public void setVenueData(String venueID) {
    final Venue venue = myRealm.where(Venue.class).equalTo("id", venueID).findFirst();
    Log.d("Full venue", venue.toString());

    // update the remaining fields with the new volley data
    _venue_title.setText(venue.getName());
    try {
      _venue_website_official.setText(venue.getWebsite());
    } catch (Exception e) {
      _venue_website_official.setText("NA");
    }
    try {
      _venue_website_sw.setText(venue.getSw_website());
    } catch (Exception e) {
      _venue_website_sw.setText("NA");
    }

    String address, address1, address2, city, post_code;
    address = address1 = address2 = city = post_code = "";
    try {
      address1 = venue.getLocation().getAddress_1() + "\n";
    } catch (Exception e) {
      Log.d(TAG, "No address1");
    }
    try {
      address2 = venue.getLocation().getAddress_2() + "\n";
    } catch (Exception e) {
      Log.d(TAG, "No address2");
    }
    try {
      city = venue.getLocation().getCity() + "\n";
    } catch (Exception e) {
      Log.d(TAG, "No city");
    }
    try {
      post_code = venue.getLocation().getPost_code();
    } catch (Exception e) {
      Log.d(TAG, "No post code");
    }

    address = address1 + address2 + city + post_code;

    _venue_address.setText("Address: " + address);
    Log.d("Venue", "" + venue.getLocation().getAddress_1());

    try {
      if (venue.getImage_URL() != null) {
        IMAGE_URL_VENUE = venue.getImage_URL();
      }
    } catch (Exception e) {
      Log.d(TAG, "No venue image");
    }
  }
Exemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_event_detail);
    sharedPref =
        getApplicationContext().getSharedPreferences("PREFERENCE_FILE_KEY", Context.MODE_PRIVATE);

    ButterKnife.bind(this);

    Bundle extras = getIntent().getExtras();

    _container_summary.setVisibility(View.VISIBLE);
    _container_artist.setVisibility(View.GONE);
    _container_venue.setVisibility(View.GONE);

    _summary_description.setVisibility(View.GONE);
    _summary_tickets_buy.setVisibility(View.GONE);
    _artist_websites.setVisibility(View.GONE);
    _artist_description.setVisibility(View.GONE);
    _venue_address.setVisibility(View.GONE);

    String eventID = "1038341"; // default should return 'Katie Melua' event
    String artistID = "";
    String venueID = "";
    if (extras != null) {
      eventID = extras.getString("EventID");
    }

    //        _baseLayout.setOnTouchListener(this);

    //        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams)
    // _baseLayout.getLayoutParams();
    //        anchorLeft = _baseLayout.getLeft() + lp.leftMargin;

    myRealm = Realm.getDefaultInstance();
    final Event event = myRealm.where(Event.class).equalTo("id", eventID).findFirst();

    final Artist artist =
        myRealm.where(Artist.class).equalTo("id", event.getArtist().getId()).findFirst();
    Log.d("Artist", artist.toString());
    final Venue venue =
        myRealm.where(Venue.class).equalTo("id", event.getVenue().getId()).findFirst();
    Log.d("Venue", venue.toString());

    artistID = artist.getId();
    venueID = venue.getId();

    setEventData(eventID);
    setArtistData(artistID);
    setVenueData(venueID);

    Log.d("Event", event.getArtist().getName());
    Log.d("Partial Data", event.toString());

    _summary_tickets_buy.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            try {
              if (event.getUrl() != null) {
                Toast.makeText(getApplicationContext(), "Show me dem tickets!", Toast.LENGTH_SHORT)
                    .show();
                Log.d("Buying", event.getUrl());
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(event.getUrl()));
                startActivity(browserIntent);
              } else {
                Toast.makeText(getApplicationContext(), "No ticket link :(", Toast.LENGTH_SHORT)
                    .show();
                Log.d("Else", event.getUrl());
              }
            } catch (Exception e) {
              Log.d("Catch", e.toString());
            }
          }
        });

    // Check if realm already has full event data (via EventURL), if not, make volley request
    try {
      if (event.getUrl()
          == null) { // TODO: needs to update to get latest ticket info, maybe a timestamp check to
        // be added/separate api route for ticket info
        requestFullData(eventID, "Event");
        Log.d(TAG, "Requesting full data...");
      } else {
        Log.d(TAG, "Already has full data");
      }
    } catch (Exception e) {
      Log.d(TAG, e.toString());
    }

    try {
      if (event.getArtist().getDescription()
          == null) { // check if full artist data already in realm
        requestFullData(artistID, "Artist");
        Log.d(TAG, "Requesting full artist data...");
      } else {
        Log.d(TAG, "Already has full artist data");
      }
    } catch (Exception e) {
      Log.d(TAG, e.toString());
    }

    try {
      if (event.getVenue().getSw_website() == null) { // check if full venue data already in realm
        requestFullData(venueID, "Venue");
        Log.d(TAG, "Requesting full venue data...");
      } else {
        Log.d(TAG, "Already has full venue data");
      }
    } catch (Exception e) {
      Log.d(TAG, e.toString());
    }

    _close.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            finish();
          }
        });
  }