public class Constants {

    public static final String ALBUM_NAME = "Rando";

    public static final String FILEPATH = "FILEPATH";
    public static final String TOTAL_RANDOS_NUMBER = "TOTAL_RANDOS_NUMBER";
    public static final String UPDATE_STATUS = "UPDATE_STATUS";
    public static final String UPDATED = "UPDATED";
    public static final String NOT_UPDATED = "NOT_UPDATED";

    /**
     * Default on-disk cache directory.
     */
    public static final String DEFAULT_CACHE_DIR = "volley";
    public static final int DEFAULT_CACHE_SIZE = 20 * 1024 * 1024;

    public static final String CAMERA_BROADCAST_EVENT = "RANDO_CAMERA_EVENT";
    public static final String SYNC_BROADCAST_EVENT = "Rando4MeSyncEvent";
    public static final String SYNC_STATISTICS_EVENT = "Rando4MeSyncStatEvent";
    public static final String UPLOAD_SERVICE_BROADCAST_EVENT = "Rando4MeUploadDoneEvent";
    public static final String AUTH_FAILURE_BROADCAST_EVENT = "Rando4MeAuthFailureEvent";
    public static final String LOGOUT_BROADCAST_EVENT = "Rando4MeLogoutEvent";
    public static final String AUTH_SUCCCESS_BROADCAST_EVENT = "Rando4MeAuthSuccessEvent";
    public static final String PUSH_NOTIFICATION_BROADCAST_EVENT = "Rando4MePushNotificationEvent";

    public static final String RANDO_PHOTO_PATH = "RANDO_PHOTO_PATH";

    public static final String IMAGE_PREFIX = "IMG_";
    public static final String IMAGE_POSTFIX = ".jpg";

    public static final long LOCATION_DETECT_TIMEOUT = 5 * 60 * 1000; //in milliseconds

    public static final int UNAUTHORIZED_CODE = 400;
    public static final int FORBIDDEN_CODE = 411;


    public static final int DESIRED_PICTURE_SIZE = 1200;
    public static final int SIZE_SMALL = 480;
    public static final int SIZE_MEDIUM = 800;
    public static final int SIZE_LARGE = 1200;

    public static final String SERVER_API_HOST = BuildConfig.RANDO_API_HOST;
    public static final String SERVER_HOST = BuildConfig.RANDO_HOST;
    public static final String SERVER_API_URL = "https://" + SERVER_API_HOST;
    public static final String SERVER_URL = "https://" + SERVER_HOST;
    public static final String PRIVACY_POLICY_URL = "https://github.com/RandoApp/Rando/wiki/Privacy-Policy";
    public static final int UPLOAD_CONNECTION_TIMEOUT = (int) TimeUnit.MINUTES.toMillis(10);
    public static final int API_CONNECTION_TIMEOUT = (int) TimeUnit.MINUTES.toMillis(2);

    public static final int UPLOAD_RETRY_TIMEOUT = 5 * 60 * 1000;

    //Shared Preferences
    public static final String PREFERENCES_FILE_NAME = "rando.prefs";
    public static final String AUTH_TOKEN = "auth.token";
    public static final String FIREBASE_INSTANCE_ID = "firebase.instance.id";
    public static final String UPDATE_PLAY_SETVICES_DIALOG_SHOWN_DATE = "play.services.update.dialog.shown.date";
    public static final String CAMERA_FACING_STRING = "camera.facing.string";
    public static final String CAMERA_GRID_STRING = "camera.grid.string";
    public static final String ENABLE_VIBRATE = "enable.vibrate";
    public static final String CAMERA_FLASH_MODE = "camera.flash.mode";
    public static final String USER_STATISTICS_LIKES = "likes";
    public static final String USER_STATISTICS_DISLIKES = "dislikes";
    public static final String ACCOUNT = "account";
    public static final String TRAINING_FRAGMENT_SHOWN = "training.fragment.shown";
    public static final String BAN_RESET_AT = "main.ban.reset.at";

    public static final String AUTH_TOKEN_PARAM = "token";
    public static final String SIGNUP_EMAIL_PARAM = "email";
    public static final String SIGNUP_PASSWORD_PARAM = "password";
    public static final String GOOGLE_EMAIL_PARAM = "email";
    public static final String GOOGLE_TOKEN_PARAM = "token";
    public static final String ANONYMOUS_ID_PARAM = "id";
    public static final String IMAGE_URL_PARAM = "imageURL";
    public static final String IMAGE_URL_SIZES_PARAM = "imageSizeURL";
    public static final String MAP_URL_SIZES_PARAM = "mapSizeURL";
    public static final String SMALL_PARAM = "small";
    public static final String MEDIUM_PARAM = "medium";
    public static final String LARGE_PARAM = "large";
    public static final String RANDO_ID_PARAM = "randoId";
    public static final String MAP_URL_PARAM = "mapURL";
    public static final String CREATION_PARAM = "creation";
    public static final String DETECTED_PARAM = "detected";
    public static final String RATING_PARAM = "rating";
    public static final String RANDO_PARAM = "rando";
    public static final String STATISTICS_PARAM = "statistics";
    public static final String NOTIFICATION_TYPE_PARAM = "notificationType";
    public static final String IN_RANDOS_PARAM = "in";
    public static final String OUT_RANDOS_PARAM = "out";
    public static final String EMAIL_PARAM = "email";
    public static final String LOCATION = "location";
    public static final String LATITUDE_PARAM = "latitude";
    public static final String LONGITUDE_PARAM = "longitude";
    public static final String FIREBASE_INSTANCE_ID_PARAM = "firebaseInstanceId";
    public static final String FIREBASE_INSTANCE_ID_HEADER = "FirebaseInstanceId";
    public static final String AUTHORIZATION_HEADER = "Authorization";

    public static final String PAGE = "page";

    public static final String ERROR_MESSAGE_PARAM = "message";
    public static final String ERROR_CODE_PARAM = "code";
    public static final String ERROR_STATUS_PARAM = "status";

    public static final String IMAGE_PARAM = "image";

    public static final String IMAGE_MIME_TYPE = "image/jpeg";
    public static final String SIGNUP_URL = SERVER_API_URL + "/user";
    public static final String STATISTICS_URL = SERVER_API_URL + "/user/statistics";
    public static final String GOOGLE_URL = SERVER_API_URL + "/google";
    public static final String ANONYMOUS_URL = SERVER_API_URL + "/anonymous";
    public static final String LOGOUT_URL = SERVER_API_URL + "/logout";
    public static final String FETCH_USER_URL = SERVER_API_URL + "/user";
    public static final String UPLOAD_RANDO_URL = SERVER_API_URL + "/image";
    public static final String DELETE_URL = SERVER_API_URL + "/delete/";
    public static final String REPORT_URL = SERVER_API_URL + "/report/";
    public static final String SHARE_URL = SERVER_URL + "/s/%s";
    public static final String RATE_URL = SERVER_API_URL + "/rate/";

    public static final String GOOGLE_AUTH_SCOPE = "oauth2:https://www.googleapis.com/auth/userinfo.profile";
    public static final String GOOGLE_USER_INFO_URL = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=";

    private static final int NUMBER_OF_IMAGES_IN_ONE_SET = 4; //stranger's + user's images and maps
    public static final int NUMBER_OF_IMAGES_FOR_CACHING = NUMBER_OF_IMAGES_IN_ONE_SET * 2; //2 visible image sets per screen

    public static final int GOOGLE_ACTIVITIES_AUTH_REQUEST_CODE = 483; //value is not matter

    public static final int CAMERA_ACTIVITY_UPLOAD_PRESSED_RESULT_CODE = 628;
    public static final int CAMERA_ACTIVITY_UPLOAD_PRESSED_REQUEST_CODE = 623;
    public static final int UPDATE_PLAY_SERVICES_REQUEST_CODE = 2404;
    public static final int CAMERA_ACTIVITY_CAMERA_PERMISSION_REQUIRED = 629;


    public static final int ALL_PERMISSIONS_REQUEST_CODE = 701;
    public static final int CAMERA_PERMISSION_REQUEST_CODE = 702;
    public static final int LOCATION_PERMISSION_REQUEST_CODE = 703;
    public static final int CONTACTS_PERMISSION_REQUEST_CODE = 704;
    public static final int STORAGE_PERMISSION_REQUEST_CODE = 705;

    public static final int GOOGLE_SIGN_IN = 801;

    public static final String LOGOUT_ACTIVITY = "LOGOUT";
    public static final int LOGOUT_ACTIVITY_RESULT = 901;

    public static final String PUSH_NOTIFICATION_LANDED = "landed";
    public static final String PUSH_NOTIFICATION_RECEIVED = "received";
    public static final String PUSH_NOTIFICATION_RATED = "rated";

    public static final String TO_UPLOAD_RANDO_ID = "randoIdToUpload";


} public class Log {

    public static void i(Class clazz, String... msgs) {
        android.util.Log.i(clazz.getName(), concatenate(msgs));
    }

    public static void d(Class clazz, String... msgs) {
        android.util.Log.d(clazz.getName(), concatenate(msgs));
    }

    public static void w(Class clazz, String... msgs) {
        android.util.Log.w(clazz.getName(), concatenate(msgs));
    }

    public static void e(Class clazz, String... msgs) {
        android.util.Log.e(clazz.getName(), concatenate(msgs));
    }

    public static void e(Class clazz, String comment, Throwable throwable) {
        android.util.Log.e(clazz.getName(), comment + " error:", throwable);
    }

    public static void v(Class clazz, String... msgs) {
        android.util.Log.v(clazz.getName(), concatenate(msgs));
    }

    private static String concatenate(String[] msgs) {
        if (msgs == null) {
            return "";
        }

        StringBuilder sb = new StringBuilder();
        for (String msg : msgs) {
            sb.append(msg).append(" ");
        }
        return sb.toString();
    }

} public static final String CREATION_PARAM = "creation"; public static final String DETECTED_PARAM = "detected"; public static final String IMAGE_URL_PARAM = "imageURL"; public static final String IMAGE_URL_SIZES_PARAM = "imageSizeURL"; public static final String LARGE_PARAM = "large"; public static final String MAP_URL_PARAM = "mapURL"; public static final String MAP_URL_SIZES_PARAM = "mapSizeURL"; public static final String MEDIUM_PARAM = "medium"; public static final String RANDO_ID_PARAM = "randoId"; public static final String RATING_PARAM = "rating"; public static final String SMALL_PARAM = "small";
import android.text.TextUtils;
import com.github.randoapp.Constants;
import com.github.randoapp.log.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.util.Comparator;
import java.util.Date;
import static com.github.randoapp.Constants.CREATION_PARAM;
import static com.github.randoapp.Constants.DETECTED_PARAM;
import static com.github.randoapp.Constants.IMAGE_URL_PARAM;
import static com.github.randoapp.Constants.IMAGE_URL_SIZES_PARAM;
import static com.github.randoapp.Constants.LARGE_PARAM;
import static com.github.randoapp.Constants.MAP_URL_PARAM;
import static com.github.randoapp.Constants.MAP_URL_SIZES_PARAM;
import static com.github.randoapp.Constants.MEDIUM_PARAM;
import static com.github.randoapp.Constants.RANDO_ID_PARAM;
import static com.github.randoapp.Constants.RATING_PARAM;
import static com.github.randoapp.Constants.SMALL_PARAM;
package com.github.randoapp.db.model;






public class Rando implements Serializable {

    public enum Status {
        IN, OUT
    }

    public int id;
    public String randoId;
    public String imageURL;
    public UrlSize imageURLSize = new UrlSize();
    public Date date;
    public String mapURL;
    public UrlSize mapURLSize = new UrlSize();
    public Status status;
    public String detected;
    public Integer rating;

    public boolean isToUpload() {
        return Constants.TO_UPLOAD_RANDO_ID.equals(randoId);
    }

    public boolean isUnwanted() {
        return detected != null && detected.contains("\"unwanted\"");
    }

    public static Rando fromJSON(String jsonRandoString, Rando.Status status) {
        try {
            return fromJSON(new JSONObject(jsonRandoString), status);
        } catch (JSONException e){
            return null;
        }
    }

    public static Rando fromJSON(JSONObject jsonRando, Rando.Status status) throws JSONException {
        Rando rando = new Rando();
        JSONObject userRandoUrlSizes = jsonRando.getJSONObject(IMAGE_URL_SIZES_PARAM);