public class WallpaperApplication extends Application {

    private static final String VERSION = "version";

    private static FiveHundredPxClient sApiClient;
    private static FiveHundredPxClient sNonLoggedInApiClient;
    private static ThreadBus sBus;

    @Override
    public void onCreate() {
        super.onCreate();

        migrate();
        MailableLog.init(this, BuildConfig.DEBUG);
        DebugUtils.setup(this);

        Realm.init(this);
        RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().build();
        Realm.setDefaultConfiguration(realmConfiguration);

        getBus().register(this);

        if (Settings.isEnabled(this) && !AlarmHelper.isAlarmSet(this)) {
            AlarmHelper.scheduleWallpaperAlarm(this);
        }
    }

    private void migrate() {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor editor = prefs.edit();
        int version = prefs.getInt(VERSION, 0);
        if (BuildConfig.VERSION_CODE > version) {
            String now = new Date().toString();
            if (version == 0) {
                editor.putString("install_date", now);
            }

            editor.putString("upgrade_date", now);
            editor.putInt(VERSION, BuildConfig.VERSION_CODE);
            editor.apply();

            MailableLog.clearLog(this);
        }
    }

    @Subscribe
    public void onUserUpdated(UserUpdatedEvent event) {
        sApiClient = null;
    }

    public static FiveHundredPxClient getApiClient() {
        if (sApiClient == null) {
            Realm realm = Realm.getDefaultInstance();
            OkHttpClient.Builder okHttpBuilder = new OkHttpClient.Builder();
            if (User.isUserLoggedIn(realm)) {
                AccessToken accessToken = User.getLoggedInUserAccessToken(realm);
                OkHttpOAuthConsumer consumer = new OkHttpOAuthConsumer(BuildConfig.CONSUMER_KEY,
                        BuildConfig.CONSUMER_SECRET);
                consumer.setTokenWithSecret(accessToken.getToken(), accessToken.getTokenSecret());
                okHttpBuilder.addInterceptor(new SigningInterceptor(consumer));
            } else {
                okHttpBuilder.addInterceptor(new ConsumerApiKeyInterceptor());
            }

            okHttpBuilder.addInterceptor(new UserAgentInterceptor());

            if (BuildConfig.DEBUG) {
                okHttpBuilder.addNetworkInterceptor(DebugUtils.getDebugNetworkInterceptor());
            }

            sApiClient = new Retrofit.Builder()
                    .baseUrl("https://api.500px.com/v1/")
                    .addConverterFactory(GsonConverterFactory.create(new GsonBuilder()
                            .excludeFieldsWithoutExposeAnnotation()
                            .create()))
                    .client(okHttpBuilder.build())
                    .addConverterFactory(GsonConverterFactory.create())
                    .build()
                    .create(FiveHundredPxClient.class);

            realm.close();
        }

        return sApiClient;
    }

    public static FiveHundredPxClient getNonLoggedInApiClient() {
        if (sNonLoggedInApiClient == null) {
            OkHttpClient.Builder okHttpBuilder = new OkHttpClient.Builder()
                    .addInterceptor(new ConsumerApiKeyInterceptor())
                    .addInterceptor(new UserAgentInterceptor());

            if (BuildConfig.DEBUG) {
                okHttpBuilder.addNetworkInterceptor(DebugUtils.getDebugNetworkInterceptor());
            }

            sNonLoggedInApiClient = new Retrofit.Builder()
                    .baseUrl("https://api.500px.com/v1/")
                    .addConverterFactory(GsonConverterFactory.create(new GsonBuilder()
                            .excludeFieldsWithoutExposeAnnotation()
                            .create()))
                    .client(okHttpBuilder.build())
                    .addConverterFactory(GsonConverterFactory.create())
                    .build()
                    .create(FiveHundredPxClient.class);
        }

        return sNonLoggedInApiClient;
    }

    public static Bus getBus() {
        if (sBus == null) {
            sBus = new ThreadBus();
        }
        return sBus;
    }
} public class PicassoHelper {

    public static Picasso getPicasso(Context context) {
        return new Picasso.Builder(context.getApplicationContext())
                .downloader(new OkHttp3Downloader(context.getApplicationContext(), 512000000)) // 512mb
                .indicatorsEnabled(BuildConfig.DEBUG)
                .build();
    }

    public static void clearCache(Context context) {
        PicassoTools.clearCache(PicassoHelper.getPicasso(context));
    }
} public class Settings {

    private static SharedPreferences getPrefs(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context);
    }

    public static String getFavoriteGallery(Context context) {
        return getPrefs(context).getString("favorite_gallery", null);
    }

    public static String getFavoriteGalleryId(Context context) {
        return getPrefs(context).getString("favorite_gallery_id", null);
    }

    public static void setFavoriteGallery(Context context, String gallery) {
        getPrefs(context).edit().putString("favorite_gallery", gallery).apply();
    }

    public static void setFavoriteGalleryId(Context context, String id) {
        getPrefs(context).edit().putString("favorite_gallery_id", id).apply();
    }

    public static String getFeature(Context context) {
        return getPrefs(context).getString("feature", "popular");
    }

    public static void setFeature(Context context, String feature) {
        getPrefs(context).edit().putString("feature", feature).apply();
    }

    public static String getSearchQuery(Context context) {
        return getPrefs(context).getString("search_query", "");
    }

    public static void setSearchQuery(Context context, String query) {
        getPrefs(context).edit().putString("search_query", query).apply();
    }

    public static int[] getCategories(Context context) {
        Set<String> defaultCategory = new HashSet<String>();
        defaultCategory.add("8");
        Set<String> prefCategories = getPrefs(context).getStringSet("categories", defaultCategory);

        int[] categories = new int[prefCategories.size()];
        int i = 0;
        for (String category : prefCategories) {
            categories[i] = Integer.parseInt(category);
            i++;
        }

        return categories;
    }

    public static void setCategories(Context context, Set<String> categories) {
        getPrefs(context).edit().putStringSet("categories", categories).apply();
    }

    public static boolean isEnabled(Context context) {
        return getPrefs(context).getBoolean("enable", false);
    }

    public static int getUpdateInterval(Context context) {
        return Integer.parseInt(getPrefs(context).getString("update_interval", "3600"));
    }

    public static void setUpdateInterval(Context context, String interval) {
        getPrefs(context).edit().putString("update_interval", interval).apply();
    }

    public static boolean useParallax(Context context) {
        return getPrefs(context).getBoolean("use_parallax", false);
    }

    public static boolean useOnlyWifi(Context context) {
        return getPrefs(context).getBoolean("use_only_wifi", true);
    }

    public static long getLastUpdated(Context context) {
        return getPrefs(context).getLong("last_updated", 0);
    }

    public static void setUpdated(Context context) {
        getPrefs(context).edit().putLong("last_updated", System.currentTimeMillis()).apply();
    }

    public static void clearUpdated(Context context) {
        getPrefs(context).edit().putLong("last_updated", 0).apply();
    }
} public class Utils {

    public static boolean shouldGetPhotos(Context context, Realm realm) {
        return Settings.isEnabled(context) && Utils.needMorePhotos(context, realm) &&
                isCurrentNetworkOk(context);
    }

    public static boolean shouldUpdateWallpaper(Context context) {
        return Settings.isEnabled(context) && (((Settings.getLastUpdated(context) +
                 (Settings.getUpdateInterval(context) * 1000)) < System.currentTimeMillis()));
    }

    public static boolean isCurrentNetworkOk(Context context) {
        return !Settings.useOnlyWifi(context) ||
                (Settings.useOnlyWifi(context) && Utils.isConnectedToWifi(context));
    }

    public static boolean needMorePhotos(Context context, Realm realm) {
        return Photos.unseenPhotoCount(context, realm) <= 10;
    }

    public static boolean isConnectedToWifi(Context context) {
        ConnectivityManager connectivityManager =
                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
        return (activeNetwork != null && activeNetwork.isConnectedOrConnecting() &&
                activeNetwork.getType() == ConnectivityManager.TYPE_WIFI);
    }

    public static int dpToPx(Context context, double dp) {
        return (int) Math.round(dp * (context.getResources().getDisplayMetrics().xdpi / DisplayMetrics.DENSITY_DEFAULT));
    }

    public static int getWallpaperHeight(Context context) {
        return WallpaperManager.getInstance(context).getDesiredMinimumHeight();
    }

    public static int getWallpaperWidth(Context context) {
        return WallpaperManager.getInstance(context).getDesiredMinimumWidth();
    }

    public static int getScreenHeight(Context context) {
        return getScreenResolution(context).y;
    }

    public static int getScreenWidth(Context context) {
        return getScreenResolution(context).x;
    }

    private static Point getScreenResolution(Context context) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Point point = new Point();
        windowManager.getDefaultDisplay().getSize(point);
        return point;
    }

    public static boolean supportsParallax(Context context) {
        return ((double) getWallpaperWidth(context) / getScreenWidth(context)) >= 2;
    }

    public static String getListSummary(Context context, int indexArrayId, int valueArrayId,
                                        String index, String defaultValue) {
        String[] indexArray = context.getResources().getStringArray(indexArrayId);
        String[] valueArray = context.getResources().getStringArray(valueArrayId);
        int i;
        for (i = 0; i < indexArray.length; i++) {
            if (indexArray[i].equals(index)) {
                return valueArray[i];
            }
        }
        return defaultValue;
    }
} public class GalleryResponse {

    @Expose public List<Gallery> galleries;

    public class Gallery {

        @Expose public String id;
        @Expose public String name;
    }
} public class PhotoResponse {

    @Expose public Photo photo;
} public class Photos extends RealmObject {

    public static final String BASE_URL_500PX = "http://500px.com";

    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");

    @Expose
    @SerializedName("id")
    @Required
    private String id;

    @Expose
    private String name;

    @Expose
    private String description;

    @Expose
    private String userName;

    @Expose
    private long createdAt;

    @Expose
    private String feature;

    @Expose
    private String search;

    @Expose
    private int category;

    @Expose
    @SerializedName("highest_rating")
    private double highestRating;

    @Expose
    @SerializedName("times_viewed")
    private int views;

    @Expose
    @SerializedName("image_url")
    public String imageUrl;

    @Expose
    @SerializedName("url")
    private String urlPath;

    @Expose
    private int palette;

    @Expose
    private boolean seen;

    @Expose
    private long seenAt;

    @Expose
    private int failedCount;

    @Expose
    private long addedAt;

    public String getPhotoId() {
        return id;
    }

    public void setPhotoId(String photoId) {
        this.id = photoId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public long getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(long createdAt) {
        this.createdAt = createdAt;
    }

    public String getFeature() {
        return feature;
    }

    public void setFeature(String feature) {
        this.feature = feature;
    }

    public String getSearch() {
        return search;
    }

    public void setSearch(String search) {
        this.search = search;
    }

    public int getCategory() {
        return category;
    }

    public void setCategory(int category) {
        this.category = category;
    }

    public double getHighestRating() {
        return highestRating;
    }

    public void setHighestRating(double highestRating) {
        this.highestRating = highestRating;
    }

    public int getViews() {
        return views;
    }

    public void setViews(int views) {
        this.views = views;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    public String getUrlPath() {
        return urlPath;
    }

    public void setUrlPath(String urlPath) {
        this.urlPath = urlPath;
    }

    public int getPalette() {
        return palette;
    }

    public void setPalette(int palette) {
        this.palette = palette;
    }

    public boolean isSeen() {
        return seen;
    }

    public void setSeen(boolean seen) {
        this.seen = seen;
    }

    public long getSeenAt() {
        return seenAt;
    }

    public void setSeenAt(long seenAt) {
        this.seenAt = seenAt;
    }

    public int getFailedCount() {
        return failedCount;
    }

    public void setFailedCount(int failedCount) {
        this.failedCount = failedCount;
    }

    public long getAddedAt() {
        return addedAt;
    }

    public void setAddedAt(long addedAt) {
        this.addedAt = addedAt;
    }

    public static Photos create(Realm realm, Photo photo, String feature, String search) {
        Logger logger = LoggerFactory.getLogger("Photos");

        if (photo.nsfw) {
            logger.debug("Photo was nsfw");
            return null;
        }

        if (realm.where(Photos.class).equalTo("id", photo.id).count() > 0) {
            logger.debug("Photo already exists");
            return null;
        }

        try {
            realm.beginTransaction();

            Photos photoModel = realm.createObject(Photos.class);
            photoModel.setPhotoId(photo.id);
            photoModel.setName(photo.name);
            photoModel.setDescription(photo.description);
            photoModel.setUserName(photo.user.getFullName());
            photoModel.setCreatedAt(DATE_FORMAT.parse(photo.createdAt.substring(0, photo.createdAt.length() - 6)).getTime());
            photoModel.setFeature(feature);
            photoModel.setSearch(search);
            photoModel.setCategory(photo.category);
            photoModel.setHighestRating(photo.highestRating);
            photoModel.setViews(photo.views);
            photoModel.setImageUrl(photo.imageUrl);
            photoModel.setUrlPath(photo.url);
            photoModel.setSeen(false);
            photoModel.setSeenAt(0);
            photoModel.setAddedAt(photoModel.addedAt = System.currentTimeMillis());

            realm.commitTransaction();

            return photoModel;
        } catch (ParseException e) {
            logger.error(e.getMessage());
        }

        return null;
    }

    public static Photos getPhoto(Realm realm, int id) {
        return realm.where(Photos.class)
                .equalTo("id", id)
                .findFirst();
    }

    public static Photos getNextPhoto(Context context, Realm realm) {
        RealmResults<Photos> photos = getQuery(context, realm);
        if (photos.isEmpty()) {
            return null;
        } else {
            return photos.first();
        }
    }

    public static Photos getCurrentPhoto(Realm realm) {
        RealmResults<Photos> photos = getRecentlySeenPhotos(realm);
        if (photos.isEmpty()) {
            return null;
        } else {
            return photos.first();
        }
    }

    public static RealmResults<Photos> getRecentlySeenPhotos(Realm realm) {
        return realm.where(Photos.class)
                .equalTo("seen", true)
                .greaterThan("seenAt", System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7))
                .findAllSorted("seenAt", Sort.DESCENDING);
    }

    public static List<Photos> getUnseenPhotos(Context context, Realm realm) {
        return getQuery(context, realm);
    }

    public static int unseenPhotoCount(Context context, Realm realm) {
        return getQuery(context, realm).size();
    }

    private static RealmResults<Photos> getQuery(Context context, Realm realm) {
        String feature = Settings.getFeature(context);
        RealmQuery<Photos> query = realm.where(Photos.class);
        if (feature.equals("search")) {
            query.equalTo("search", Settings.getSearchQuery(context));
        } else {
            query.equalTo("feature", feature);
        }

        query.beginGroup();
        int[] categories = Settings.getCategories(context);
        for (int i = 0; i < categories.length - 1; i++) {
            query.equalTo("category", categories[i])
                    .or();
        }
        query.equalTo("category", categories[categories.length - 1])
                .endGroup();

        return query.equalTo("seen", false)
                .findAllSorted(new String[] { "failedCount", "highestRating", "views", "createdAt" },
                        new Sort[] { Sort.ASCENDING, Sort.DESCENDING, Sort.DESCENDING, Sort.ASCENDING });
    }
} public class User extends RealmObject {

    @Expose
    private int id;

    @Expose
    @SerializedName("username")
    private String userName;

    @Expose
    @SerializedName("firstname")
    private String firstName;

    @Expose
    @SerializedName("lastname")
    private String lastName;

    @Expose
    @SerializedName("fullname")
    private String fullName;

    @Expose
    @SerializedName("userpic_url")
    private String photo;

    @Expose
    private String accessToken;

    @Expose
    private String accessTokenSecret;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public String getAccessTokenSecret() {
        return accessTokenSecret;
    }

    public void setAccessTokenSecret(String accessTokenSecret) {
        this.accessTokenSecret = accessTokenSecret;
    }

    public static User getUser(Realm realm) {
        return realm.where(User.class).findFirst();
    }

    public static boolean isUserLoggedIn(Realm realm) {
        return (realm.where(User.class).findFirst() != null);
    }

    public static void logout(Realm realm) {
        realm.beginTransaction();
        realm.where(User.class).findAll().deleteAllFromRealm();
        realm.commitTransaction();
    }

    public static void newUser(Context context, Realm realm, AccessToken accessToken) {
        User.logout(realm);

        realm.beginTransaction();
        User user = realm.createObject(User.class);
        user.setAccessToken(accessToken.getToken());
        user.setAccessTokenSecret(accessToken.getTokenSecret());
        realm.commitTransaction();

        context.startService(new Intent(context, UserInfoIntentService.class));
    }

    public static AccessToken getLoggedInUserAccessToken(Realm realm) {
        User user = getUser(realm);
        return (user != null ? new AccessToken(user.getAccessToken(), user.getAccessTokenSecret()) : null);
    }
} public class FavoriteButton extends Button implements View.OnClickListener {

    private int mUserId;
    private String mPhotoId;
    private boolean mFavorited;

    public FavoriteButton(Context context) {
        super(context);
    }

    public FavoriteButton(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public FavoriteButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public FavoriteButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public void setup(String photoId, boolean favorited) {
        Realm realm = Realm.getDefaultInstance();

        if (User.isUserLoggedIn(realm)) {
            mUserId = User.getUser(realm).getId();
            mPhotoId = photoId;
            mFavorited = favorited;

            setCompoundDrawablesWithIntrinsicBounds(R.drawable.button_action_favorite, 0, 0, 0);
            if (mFavorited) {
                setBackgroundResource(R.drawable.button_action_bg_favorited);
            } else {
                setBackgroundResource(R.drawable.button_action_bg);
            }

            setOnClickListener(this);
            setVisibility(View.VISIBLE);
        }

        realm.close();
    }

    @Override
    public void onClick(View v) {
        if (mFavorited) {
            setBackgroundResource(R.drawable.button_action_bg);

            WallpaperApplication.getApiClient()
                    .unfavorite(mUserId, Settings.getFavoriteGalleryId(getContext()), PhotoGalleryRequest.remove(mPhotoId))
                    .enqueue(new Callback<ApiResponse>() {
                        @Override
                        public void onResponse(Call<ApiResponse> call, Response<ApiResponse> response) {
                            if (response.isSuccessful()) {
                                setup(mPhotoId, false);
                                FirebaseAnalytics.getInstance(getContext()).logEvent("unfavorited", null);
                            } else {
                                onFailure(null, null);
                            }
                        }

                        @Override
                        public void onFailure(Call<ApiResponse> call, Throwable t) {
                            setBackgroundResource(R.drawable.button_action_bg_favorited);
                        }
                    });
        } else {
            setBackgroundResource(R.drawable.button_action_bg_favorited);

            WallpaperApplication.getApiClient()
                    .favorite(mUserId, Settings.getFavoriteGalleryId(getContext()), PhotoGalleryRequest.add(mPhotoId))
                    .enqueue(new Callback<ApiResponse>() {
                        @Override
                        public void onResponse(Call<ApiResponse> call, Response<ApiResponse> response) {
                            if (response.isSuccessful()) {
                                setup(mPhotoId, true);
                                FirebaseAnalytics.getInstance(getContext()).logEvent("favorited", null);
                            } else {
                                onFailure(null, null);
                            }
                        }

                        @Override
                        public void onFailure(Call<ApiResponse> call, Throwable t) {
                            setBackgroundResource(R.drawable.button_action_bg);
                        }
                    });
        }
    }

    @Override
    public void setBackgroundResource(int resid) {
        super.setBackgroundResource(resid);
        setPadding(dpToPx(getContext(), 4), dpToPx(getContext(), 4), dpToPx(getContext(), 4), dpToPx(getContext(), 4));
    }
} public class LikeButton extends Button implements View.OnClickListener {

    private Photo mPhoto;

    public LikeButton(Context context) {
        super(context);
    }

    public LikeButton(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public LikeButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public LikeButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public void setPhoto(Photo photo) {
        mPhoto = photo;

        setText(Integer.toString(mPhoto.votes));
        setCompoundDrawablesWithIntrinsicBounds(R.drawable.button_action_like, 0, 0, 0);
        if (mPhoto.voted) {
            setBackgroundResource(R.drawable.button_action_bg_liked);
        } else {
            setBackgroundResource(R.drawable.button_action_bg);
        }

        setOnClickListener(this);
        setVisibility(View.VISIBLE);
    }

    @Override
    public void onClick(View v) {
        if (mPhoto.voted) {
            setBackgroundResource(R.drawable.button_action_bg);
        } else {
            setBackgroundResource(R.drawable.button_action_bg_liked);
        }

        Callback<PhotoResponse> callback = new Callback<PhotoResponse>() {
            @Override
            public void onResponse(Call<PhotoResponse> call, Response<PhotoResponse> response) {
                if (response.isSuccessful()) {
                    Photo photo = response.body().photo;
                    photo.voted = !mPhoto.voted;
                    setPhoto(response.body().photo);

                    FirebaseAnalytics.getInstance(getContext()).logEvent((photo.voted ? "liked" : "unliked"), null);
                } else {
                    onFailure(null, null);
                }
            }

            @Override
            public void onFailure(Call<PhotoResponse> call, Throwable t) {
                if (mPhoto.voted) {
                    setBackgroundResource(R.drawable.button_action_bg_liked);
                } else {
                    setBackgroundResource(R.drawable.button_action_bg);
                }
            }
        };

        if (mPhoto.voted) {
            WallpaperApplication.getApiClient().unlike(mPhoto.id).enqueue(callback);
        } else {
            WallpaperApplication.getApiClient().like(mPhoto.id).enqueue(callback);
        };
    }

    @Override
    public void setBackgroundResource(int resid) {
        super.setBackgroundResource(resid);

        setPadding(dpToPx(getContext(), 2), dpToPx(getContext(), 4), dpToPx(getContext(), 8),
                dpToPx(getContext(), 4));
    }
}
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.lukekorth.photo_paper.R;
import com.lukekorth.photo_paper.WallpaperApplication;
import com.lukekorth.photo_paper.helpers.PicassoHelper;
import com.lukekorth.photo_paper.helpers.Settings;
import com.lukekorth.photo_paper.helpers.Utils;
import com.lukekorth.photo_paper.models.GalleryResponse;
import com.lukekorth.photo_paper.models.PhotoResponse;
import com.lukekorth.photo_paper.models.Photos;
import com.lukekorth.photo_paper.models.User;
import com.lukekorth.photo_paper.views.FavoriteButton;
import com.lukekorth.photo_paper.views.LikeButton;
import com.squareup.picasso.Picasso;
import io.realm.Realm;
import io.realm.RealmChangeListener;
import io.realm.RealmResults;
import it.sephiroth.android.library.imagezoom.ImageViewTouch;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
package com.lukekorth.photo_paper.adapters;




public class PhotoPagerAdapter extends PagerAdapter implements RealmChangeListener<RealmResults<Photos>> {

    private Context mContext;
    private ViewPager mViewPager;
    private LayoutInflater mInflater;
    private Picasso mPicasso;
    private Realm mRealm;
    private RealmResults<Photos> mPhotos;
    private int mNumberOfPhotos;
    private boolean mLoggedIn;

    public PhotoPagerAdapter(Context context, Realm realm, ViewPager viewPager,
                             RealmResults<Photos> photos) {
        mContext = context;
        mViewPager = viewPager;
        mInflater = LayoutInflater.from(context);
        mPicasso = PicassoHelper.getPicasso(mContext);
        mRealm = realm;
        mPhotos = photos;
        mNumberOfPhotos = photos.size();
        mLoggedIn = User.isUserLoggedIn(mRealm);