/*
 * Copyright 2014-present Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.facebook.litho.reference;

import android.content.Context;
import android.graphics.drawable.Drawable;
import com.facebook.litho.drawable.ComparableDrawable;

/**
 * A very simple Reference for {@link Drawable} used in all the cases where it's not
 * possible/desirable to use a real Reference. This will simply keep a reference to the Drawable in
 * the Props and return it. Please take care when using this. It keeps the drawable in memory all
 * the time and should only be used when the other built in specs are not applicable and it's not
 * possible to write a custom ReferenceSpec
 */
final class DrawableReferenceLifecycle extends ReferenceLifecycle<ComparableDrawable> {

  private static DrawableReferenceLifecycle sInstance;

  private DrawableReferenceLifecycle() {}

  public static synchronized DrawableReferenceLifecycle get() {
    if (sInstance == null) {
      sInstance = new DrawableReferenceLifecycle();
    }
    return sInstance;
  }

  @Override
  protected ComparableDrawable onAcquire(Context context, Reference<ComparableDrawable> reference) {
    return ((DrawableReference) reference).mDrawable;
  }

  @Override
  protected boolean shouldUpdate(
      Reference<ComparableDrawable> previous, Reference<ComparableDrawable> next) {
    ComparableDrawable previousDrawable = ((DrawableReference) previous).mDrawable;
    ComparableDrawable nextDrawable = ((DrawableReference) next).mDrawable;
    return !previousDrawable.isEquivalentTo(nextDrawable);
  }
}

@@ -1307,16 +1307,22 @@
  static 
+final 
 Drawable
@@ -1353,20 +1353,14 @@
 ance
-;%0A%0A  private
+ = new
  Dra
@@ -1388,41 +1388,20 @@
 le()
- %7B%7D
+;
 %0A%0A  p
-ublic static synchronized
+rivate
  Dra
@@ -1427,67 +1427,30 @@
 ycle
- get
 () %7B
+%7D%0A
 %0A  
-  if (sInstance == null) %7B%0A      sInstance = new
+public static
  Dra
@@ -1476,17 +1476,16 @@
 ycle
-();%0A    %7D
+ get() %7B
 %0A   

Remove synchronized in DrawableReferenceLifecycle#get