public static Result download(long id){
  ContentResolver cr=cr();
  Uri uri=ContentUris.withAppendedId(Restaurants.CONTENT_URI,id);
  String[] proj={Restaurants.GLOBAL_ID,Restaurants.PLACE_ID};
  EasyCursor c=new EasyCursor(cr.query(uri,proj,null,null,null));
  Restaurant restaurant=new Restaurant();
  restaurant.localId=id;
  if (c.moveToFirst()) {
    restaurant.globalId=c.getLong(Restaurants.GLOBAL_ID);
    restaurant.placeId=c.getString(Restaurants.PLACE_ID);
  }
  c.close();
  if (restaurant.globalId > 0 && TextUtils.isEmpty(restaurant.placeId)) {
    restaurant=Server.restaurant(restaurant);
  }
  Result result=null;
  if (restaurant != null && !TextUtils.isEmpty(restaurant.placeId)) {
    try {
      ContentValues vals=new ContentValues(14);
      vals.put(Restaurants.PLACE_ID,restaurant.placeId);
      result=details(id,vals);
      if (STATUS_NOT_FOUND.equals(result.status)) {
        return result;
      }
      if (result.place != null) {
        photo(result.photoId,id,result.place);
      }
    }
 catch (    IOException e) {
      Log.e(TAG,"getting place details or downloading restaurant photo",e);
      exception(e);
    }
  }
  if (restaurant != null && restaurant.status == null) {
    restaurant=Server.restaurant(restaurant);
  }
  if (restaurant != null) {
    restaurant.status=ACTIVE;
    ContentValues vals=Restaurants.values(restaurant);
    Restaurants.deleteConflict(restaurant.localId,restaurant.globalId);
    try {
      cr.update(uri,vals,null,null);
    }
 catch (    SQLiteConstraintException e) {
      Log.e(TAG,"updating restaurant from server",e);
      exception(e);
    }
    try {
      photo(id,vals);
    }
 catch (    IOException e) {
      Log.e(TAG,"downloading Street View image",e);
      exception(e);
    }
    List<Review> reviews=Server.reviews(restaurant);
    if (reviews != null) {
      boolean hasOwn=false;
      int size=reviews.size();
      for (int i=0; i < size; i++) {
        Review review=reviews.get(i);
        vals=Reviews.values(review);
        String sel=Reviews.GLOBAL_ID + " = ?";
        String[] args={String.valueOf(review.globalId)};
        if (cr.update(Reviews.CONTENT_URI,vals,sel,args) == 0) {
          review.localId=ContentUris.parseId(cr.insert(Reviews.CONTENT_URI,vals));
          if (review.localId > 0 && review.userId == 0) {
            hasOwn=true;
          }
        }
      }
      String restaurantId=String.valueOf(id);
      cr.call(AUTHORITY_URI,CALL_UPDATE_RESTAURANT_RATING,restaurantId,null);
      if (hasOwn) {
        cr.call(AUTHORITY_URI,CALL_UPDATE_RESTAURANT_LAST_VISIT,restaurantId,null);
      }
    }
  }
  return result;
}

public static Result download ( long id ) { ContentResolver cr = cr ( ) ; Uri uri = ContentUris . withAppendedId ( Restaurants . CONTENT_URI , id ) ; String [ ] proj = { Restaurants . GLOBAL_ID , Restaurants . PLACE_ID } ; EasyCursor c = new EasyCursor ( cr . query ( uri , proj , null , null , null ) ) ; Restaurant restaurant = new Restaurant ( ) ; restaurant . localId = id ; if ( c . moveToFirst ( ) ) { restaurant . globalId = c . getLong ( Restaurants . GLOBAL_ID ) ; restaurant . placeId = c . getString ( Restaurants . PLACE_ID ) ; } c . close ( ) ; if ( restaurant . globalId > 0 && TextUtils . isEmpty ( restaurant . placeId ) ) { restaurant = Server . restaurant ( restaurant ) ; } Result result = null ; if ( restaurant != null && ! TextUtils . isEmpty ( restaurant . placeId ) ) { try { ContentValues vals = new ContentValues ( 14 ) ; vals . put ( Restaurants . PLACE_ID , restaurant . placeId ) ; result = details ( id , vals ) ; if ( STATUS_NOT_FOUND . equals ( result . status ) ) { return result ; } if ( result . place != null ) { photo ( result . photoId , id , result . place ) ; } } catch ( IOException e ) { Log . e ( TAG , "getting place details or downloading restaurant photo" , e ) ; exception ( e ) ; } } if ( restaurant != null && restaurant . status == null ) { restaurant = Server . restaurant ( restaurant ) ; } if ( restaurant != null ) { restaurant . status = ACTIVE ; ContentValues vals = Restaurants . values ( restaurant ) ; Restaurants . deleteConflict ( restaurant . localId , restaurant . globalId ) ; try { cr . update ( uri , vals , null , null ) ; } catch ( SQLiteConstraintException e ) { Log . e ( TAG , "updating restaurant from server" , e ) ; exception ( e ) ; } try { photo ( id , vals ) ; } catch ( IOException e ) { Log . e ( TAG , "downloading Street View image" , e ) ; exception ( e ) ; } List < Review > reviews = Server . reviews ( restaurant ) ; if ( reviews != null ) { boolean hasOwn = false ; int size = reviews . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { Review review = reviews . get ( i ) ; vals = Reviews . values ( review ) ; String sel = Reviews . GLOBAL_ID + " = ?" ; String [ ] args = { String . valueOf ( review . globalId ) } ; if ( cr . update ( Reviews . CONTENT_URI , vals , sel , args ) == 0 ) { review . localId = ContentUris . parseId ( cr . insert ( Reviews . CONTENT_URI , vals ) ) ; if ( review . localId > 0 && review . userId == 0 ) { hasOwn = true ; } } } String restaurantId = String . valueOf ( id ) ; cr . call ( AUTHORITY_URI , CALL_UPDATE_RESTAURANT_RATING , restaurantId , null ) ; if ( hasOwn ) { cr . call ( AUTHORITY_URI , CALL_UPDATE_RESTAURANT_LAST_VISIT , restaurantId , null ) ; } } } return result ; }
download details , reviews , and photos for the restaurant .
