This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import toothpick.Scope | |
import toothpick.Toothpick | |
import kotlin.properties.ReadOnlyProperty | |
import kotlin.reflect.KProperty | |
annotation class ActivityScope | |
annotation class FreeScope | |
//------------------------- | |
// case: Entry point |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HeadLineFragment extends ListFragment { | |
@Override | |
public void onListItemClick(ListView l, View v, int p, long i) { | |
// Send the event to the host activity | |
// we should probably check if the activity is finishing|destroyed|rotating | |
mCallback.onArticleSelected(getActivity(), p); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HeadLineFragment extends Fragment { | |
public <T> void setHeadlineListener(HeadlineListener<T> listener) { | |
... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class MainActivity extends Activity { | |
public void onArticleSelected(int position) { | |
} | |
public static void onArticleSelected(MainActivity activity, int position) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
just(0) | |
.map(this::onArticleSelected) | |
.subscribe(...); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class MainActivity extends Activity { | |
public void bindFragment(HeadlinesFragment fragment) { | |
fragment.setHeadlineListener(MainActivity::onArticleSelected); | |
} | |
public void onArticleSelected(int position) { | |
... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HeadlinesFragment extends ListFragment { | |
HeadlineListener mCallback; | |
public <T> void setHeadlineListener(HeadlineListener<T> listener) { | |
this.mCallBack = listener; | |
} | |
@Override | |
public void onListItemClick(ListView l, View v, int p, long i) { | |
// Send the event to the host activity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface HeadlineListener<T extends Activity> extends Serializable { | |
public void onArticleSelected(T activity, int position); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class MainActivity extends Activity { | |
public void onArticleSelected(int position) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HeadlinesFragment extends ListFragment { | |
HeadlineListener mCallback; | |
// Container Activity must implement this interface | |
public interface HeadlineListener { | |
public void onArticleSelected(int position); | |
} | |
@Override | |
public void onAttach(Activity activity) { |
NewerOlder