package com.example.fragmenttransitions;

import android.support.annotation.IntRange;
import android.support.annotation.Nullable;
import android.support.v4.util.Pair;
import android.support.v4.view.ViewCompat;
import android.view.View;

import com.google.auto.value.AutoValue;

/**
 * Created by Owner on 2017. 08. 08..
 */
@AutoValue
public abstract class DetailsKey
        extends BaseKey
        implements HasSharedElement {
    private transient Pair<View, String> sharedElement;

    @Override
    @Nullable
    public Pair<View, String> sharedElement() {
        return sharedElement;
    }

    @Override
    public abstract String transitionName();

    public abstract int kittenNumber();

    public static DetailsKey create(Pair<View, String> sharedElement, @IntRange(from = 1, to = 6) int kittenNumber) {
        DetailsKey detailsKey = new AutoValue_DetailsKey(ViewCompat.getTransitionName(sharedElement.first), kittenNumber);
        detailsKey.sharedElement = sharedElement; // see https://github.com/google/auto/blob/4016d8dbbe4de668a1849e95223d1f2447b647bc/value/userguide/howto.md#ignore
        return detailsKey;
    }

    @Override
    protected BaseFragment createFragment() {
        return new DetailsFragment();
    }
}

@@ -271,16 +271,53 @@
 Value;%0A%0A
+import java.lang.ref.WeakReference;%0A%0A
 /**%0A * C
@@ -483,28 +483,43 @@
 nsient Pair%3C
+WeakReference%3C
 View
+%3E
 , String%3E sh
@@ -616,22 +616,149 @@
         
-return
+View view = sharedElement.first.get();%0A        if(view == null) %7B%0A            return null;%0A        %7D%0A        return Pair.create(view,
  sharedE
@@ -763,16 +763,24 @@
 dElement
+.second)
 ;%0A    %7D%0A
@@ -1157,29 +1157,107 @@
 ement = 
-sharedElement
+Pair.create(new WeakReference%3C%3E(sharedElement.first),%0A                sharedElement.second)
 ; // see

fix memory leak in shared element transition example