From 2b78515d41c83c691710dd5677c4a0681b6ef4b6 Mon Sep 17 00:00:00 2001 From: e10dokup <2edokup@gmail.com> Date: Wed, 31 Jan 2018 09:09:38 +0900 Subject: [PATCH 1/6] Create transition --- .../presentation/NavigationController.kt | 4 ++ .../detail/SessionDetailActivity.kt | 66 ++++++++++++++++++- .../detail/SessionDetailFragment.kt | 24 +++++++ .../sessions/AllSessionsFragment.kt | 7 +- .../res/layout/fragment_session_detail.xml | 1 + 5 files changed, 99 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/NavigationController.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/NavigationController.kt index 780e82cb..51984810 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/NavigationController.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/NavigationController.kt @@ -123,6 +123,10 @@ class NavigationController @Inject constructor(private val activity: AppCompatAc SessionDetailActivity.start(activity, session) } + fun navigateToSessionDetailActivity(session: Session, sharedElement: Pair) { + SessionDetailActivity.start(activity, session, sharedElement) + } + fun navigateToSessionsFeedbackActivity(session: Session.SpeechSession) { SessionsFeedbackActivity.start(activity, session) } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailActivity.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailActivity.kt index 05e4ab30..6fa3a1fc 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailActivity.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailActivity.kt @@ -1,14 +1,22 @@ package io.github.droidkaigi.confsched2018.presentation.detail +import android.annotation.TargetApi +import android.app.Activity +import android.app.SharedElementCallback import android.arch.lifecycle.ViewModelProvider import android.arch.lifecycle.ViewModelProviders import android.content.Context import android.content.Intent import android.databinding.DataBindingUtil +import android.os.Build import android.os.Bundle +import android.support.v4.app.ActivityOptionsCompat import android.support.v4.app.Fragment import android.support.v4.app.FragmentManager import android.support.v4.app.FragmentStatePagerAdapter +import android.support.v4.util.Pair +import android.support.v4.view.ViewPager +import android.view.View import dagger.android.AndroidInjector import dagger.android.DispatchingAndroidInjector import dagger.android.support.HasSupportFragmentInjector @@ -32,6 +40,8 @@ class SessionDetailActivity : @Inject lateinit var viewModelFactory: ViewModelProvider.Factory @Inject lateinit var drawerMenu: DrawerMenu + private var backPressed = false + private val binding: ActivitySessionDetailBinding by lazy { DataBindingUtil .setContentView( @@ -46,8 +56,33 @@ class SessionDetailActivity : private val pagerAdapter = SessionDetailFragmentPagerAdapter(supportFragmentManager) + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + private val sharedElementCallback = object : SharedElementCallback() { + override fun onMapSharedElements( + names: MutableList?, + sharedElements: MutableMap?) { + super.onMapSharedElements(names, sharedElements) + + if (backPressed) { + val currentFragment = pagerAdapter.findFragmentByPosition( + binding.detailSessionsPager, + binding.detailSessionsPager.currentItem) + sharedElements?.clear() + + sharedElements?.put( + intent.getStringExtra(EXTRA_TRANSITION_NAME), + currentFragment.speakerSummary) + } + } + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + + pagerAdapter.transitionName = intent.getStringExtra(EXTRA_TRANSITION_NAME) + + supportPostponeEnterTransition() + supportActionBar?.let { it.setDisplayHomeAsUpEnabled(true) it.setDisplayShowTitleEnabled(false) @@ -57,6 +92,10 @@ class SessionDetailActivity : is Result.Success -> { val sessions = result.data bindSessions(sessions) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + setEnterSharedElementCallback(sharedElementCallback) + } + } is Result.Failure -> { Timber.e(result.e) @@ -83,9 +122,11 @@ class SessionDetailActivity : } } + override fun supportFragmentInjector(): AndroidInjector = dispatchingAndroidInjector override fun onBackPressed() { + backPressed = true if (drawerMenu.closeDrawerIfNeeded()) { super.onBackPressed() } @@ -102,6 +143,8 @@ class SessionDetailActivity : class SessionDetailFragmentPagerAdapter( fragmentManager: FragmentManager ) : FragmentStatePagerAdapter(fragmentManager) { + var transitionName: String? = null + var sessions: List = listOf() set(value) { field = value @@ -109,22 +152,43 @@ class SessionDetailActivity : } override fun getItem(position: Int): Fragment { - return SessionDetailFragment.newInstance(sessions[position].id) + return SessionDetailFragment.newInstance(sessions[position].id, transitionName!!) } override fun getCount(): Int = sessions.size + + fun findFragmentByPosition(viewPager: ViewPager, position: Int): SessionDetailFragment { + return instantiateItem(viewPager, position) as SessionDetailFragment + } + } companion object { const val EXTRA_SESSION_ID = "EXTRA_SESSION_ID" + const val EXTRA_TRANSITION_NAME = "EXTRA_TRANSITION_NAME" + fun start(context: Context, session: Session) { context.startActivity(createIntent(context, session.id)) } + fun start(activity: Activity, session: Session, sharedElement: Pair) { + val options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElement) + activity.startActivity(createIntent(activity, session.id, sharedElement), options.toBundle()) + } + fun createIntent(context: Context, sessionId: String): Intent { return Intent(context, SessionDetailActivity::class.java).apply { putExtra(EXTRA_SESSION_ID, sessionId) } } + + fun createIntent(context: Context, sessionId: String, sharedElement: Pair): + Intent { + return Intent(context, SessionDetailActivity::class.java).apply { + putExtra(EXTRA_SESSION_ID, sessionId) + putExtra(EXTRA_TRANSITION_NAME, sharedElement.second) + } + } + } } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt index 6b2126a2..8edb8995 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt @@ -3,8 +3,11 @@ package io.github.droidkaigi.confsched2018.presentation.detail import android.arch.lifecycle.ViewModelProvider import android.arch.lifecycle.ViewModelProviders import android.graphics.drawable.Animatable +import android.os.Build import android.os.Bundle import android.support.v4.app.Fragment +import android.support.v4.view.ViewCompat +import android.text.TextUtils import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -15,6 +18,7 @@ import io.github.droidkaigi.confsched2018.model.Level import io.github.droidkaigi.confsched2018.model.Session import io.github.droidkaigi.confsched2018.presentation.NavigationController import io.github.droidkaigi.confsched2018.presentation.Result +import io.github.droidkaigi.confsched2018.presentation.common.view.SpeakersSummaryLayout import io.github.droidkaigi.confsched2018.util.SessionAlarm import io.github.droidkaigi.confsched2018.util.ext.context import io.github.droidkaigi.confsched2018.util.ext.drawable @@ -34,6 +38,9 @@ class SessionDetailFragment : Fragment(), Injectable { ViewModelProviders.of(activity!!, viewModelFactory).get(SessionDetailViewModel::class.java) } + val speakerSummary: SpeakersSummaryLayout + get() = binding.speakerSummary + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -55,6 +62,13 @@ class SessionDetailFragment : Fragment(), Injectable { bindSession(sessions[position]) setSessionIndicator(sessions.getOrNull(position - 1), sessions.getOrNull(position + 1)) + if (!TextUtils.isEmpty(arguments!!.getString(EXTRA_TRANSITION_NAME)) + && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + ViewCompat.setTransitionName( + view.findViewById(R.id.speaker_summary), + arguments!!.getString(EXTRA_TRANSITION_NAME)) + activity?.supportStartPostponedEnterTransition() + } } is Result.Failure -> { Timber.e(result.e) @@ -117,10 +131,20 @@ class SessionDetailFragment : Fragment(), Injectable { companion object { const val EXTRA_SESSION_ID = "EXTRA_SESSION_ID" + const val EXTRA_TRANSITION_NAME = "EXTRA_TRANSITION_NAME" + fun newInstance(sessionId: String): SessionDetailFragment = SessionDetailFragment().apply { arguments = Bundle().apply { putString(EXTRA_SESSION_ID, sessionId) } } + + fun newInstance(sessionId: String, transitionName: String): SessionDetailFragment = + SessionDetailFragment().apply { + arguments = Bundle().apply { + putString(EXTRA_SESSION_ID, sessionId) + putString(EXTRA_TRANSITION_NAME, transitionName) + } + } } } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/AllSessionsFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/AllSessionsFragment.kt index 082d0075..872a6664 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/AllSessionsFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/AllSessionsFragment.kt @@ -6,6 +6,7 @@ import android.os.Bundle import android.support.transition.TransitionInflater import android.support.transition.TransitionManager import android.support.v4.app.Fragment +import android.support.v4.util.Pair import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView import android.support.v7.widget.SimpleItemAnimator @@ -112,9 +113,11 @@ class AllSessionsFragment : Fragment(), Injectable, CurrentSessionScroller, TabL private fun setupRecyclerView() { val groupAdapter = GroupAdapter().apply { add(sessionsSection) - setOnItemClickListener({ item, _ -> + setOnItemClickListener({ item, v -> val sessionItem = item as? SpeechSessionItem ?: return@setOnItemClickListener - navigationController.navigateToSessionDetailActivity(sessionItem.session) + val sharedElement = Pair(v.findViewById(R.id.speaker_summary), + sessionItem.session.id) + navigationController.navigateToSessionDetailActivity(sessionItem.session, sharedElement) }) } binding.sessionsRecycler.apply { diff --git a/app/src/main/res/layout/fragment_session_detail.xml b/app/src/main/res/layout/fragment_session_detail.xml index b82ad23b..5b95e3fe 100644 --- a/app/src/main/res/layout/fragment_session_detail.xml +++ b/app/src/main/res/layout/fragment_session_detail.xml @@ -121,6 +121,7 @@ tools:text="初心者向け" /> Date: Thu, 1 Feb 2018 09:07:13 +0900 Subject: [PATCH 2/6] Fix missing transition --- .../detail/SessionDetailActivity.kt | 31 ++++++++++++----- .../detail/SessionDetailFragment.kt | 34 ++++++++++++++----- .../sessions/AllSessionsFragment.kt | 5 +-- 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailActivity.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailActivity.kt index 6fa3a1fc..7b492466 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailActivity.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailActivity.kt @@ -56,6 +56,12 @@ class SessionDetailActivity : private val pagerAdapter = SessionDetailFragmentPagerAdapter(supportFragmentManager) + private lateinit var sessions: List + + val firstSessionId: String by lazy { + intent.getStringExtra(EXTRA_SESSION_ID) + } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) private val sharedElementCallback = object : SharedElementCallback() { override fun onMapSharedElements( @@ -72,15 +78,20 @@ class SessionDetailActivity : sharedElements?.put( intent.getStringExtra(EXTRA_TRANSITION_NAME), currentFragment.speakerSummary) + currentFragment.hideButton() + + val data = Intent() + val bundle = Bundle() + bundle.putString("position", sessions[binding.detailSessionsPager.currentItem].id) + data.putExtras(bundle) + + setResult(Activity.RESULT_OK, data) } } } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - - pagerAdapter.transitionName = intent.getStringExtra(EXTRA_TRANSITION_NAME) - supportPostponeEnterTransition() supportActionBar?.let { @@ -90,7 +101,7 @@ class SessionDetailActivity : sessionDetailViewModel.sessions.observe(this) { result -> when (result) { is Result.Success -> { - val sessions = result.data + sessions = result.data bindSessions(sessions) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setEnterSharedElementCallback(sharedElementCallback) @@ -111,8 +122,7 @@ class SessionDetailActivity : val firstAssign = pagerAdapter.sessions.isEmpty() && sessions.isNotEmpty() pagerAdapter.sessions = sessions if (firstAssign) { - val sessionId = intent.getStringExtra(EXTRA_SESSION_ID) - val position = sessions.indexOfFirst { it.id == sessionId } + val position = sessions.indexOfFirst { it.id == firstSessionId } binding .detailSessionsPager .setCurrentItem( @@ -143,7 +153,6 @@ class SessionDetailActivity : class SessionDetailFragmentPagerAdapter( fragmentManager: FragmentManager ) : FragmentStatePagerAdapter(fragmentManager) { - var transitionName: String? = null var sessions: List = listOf() set(value) { @@ -152,7 +161,7 @@ class SessionDetailActivity : } override fun getItem(position: Int): Fragment { - return SessionDetailFragment.newInstance(sessions[position].id, transitionName!!) + return SessionDetailFragment.newInstance(sessions[position].id, sessions[position].id) } override fun getCount(): Int = sessions.size @@ -166,6 +175,7 @@ class SessionDetailActivity : companion object { const val EXTRA_SESSION_ID = "EXTRA_SESSION_ID" const val EXTRA_TRANSITION_NAME = "EXTRA_TRANSITION_NAME" + const val REQUEST_POSITION = 1 fun start(context: Context, session: Session) { context.startActivity(createIntent(context, session.id)) @@ -173,7 +183,10 @@ class SessionDetailActivity : fun start(activity: Activity, session: Session, sharedElement: Pair) { val options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElement) - activity.startActivity(createIntent(activity, session.id, sharedElement), options.toBundle()) + activity.startActivityForResult( + createIntent(activity, session.id, sharedElement), + REQUEST_POSITION, + options.toBundle()) } fun createIntent(context: Context, sessionId: String): Intent { diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt index 8edb8995..74d6210f 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt @@ -11,6 +11,7 @@ import android.text.TextUtils import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.view.ViewTreeObserver import io.github.droidkaigi.confsched2018.R import io.github.droidkaigi.confsched2018.databinding.FragmentSessionDetailBinding import io.github.droidkaigi.confsched2018.di.Injectable @@ -39,7 +40,7 @@ class SessionDetailFragment : Fragment(), Injectable { } val speakerSummary: SpeakersSummaryLayout - get() = binding.speakerSummary + get() = binding.speakerSummary override fun onCreateView( inflater: LayoutInflater, @@ -62,13 +63,6 @@ class SessionDetailFragment : Fragment(), Injectable { bindSession(sessions[position]) setSessionIndicator(sessions.getOrNull(position - 1), sessions.getOrNull(position + 1)) - if (!TextUtils.isEmpty(arguments!!.getString(EXTRA_TRANSITION_NAME)) - && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - ViewCompat.setTransitionName( - view.findViewById(R.id.speaker_summary), - arguments!!.getString(EXTRA_TRANSITION_NAME)) - activity?.supportStartPostponedEnterTransition() - } } is Result.Failure -> { Timber.e(result.e) @@ -89,6 +83,26 @@ class SessionDetailFragment : Fragment(), Injectable { } binding.toolbar.setNavigationOnClickListener { activity?.finish() } + + binding.speakerSummary.viewTreeObserver.addOnPreDrawListener( + object : ViewTreeObserver.OnPreDrawListener { + override fun onPreDraw(): Boolean { + binding.speakerSummary.viewTreeObserver.removeOnPreDrawListener(this) + + val firstSessionId = (activity as? SessionDetailActivity)?.firstSessionId + ?: return true + val transitionName = arguments!!.getString(EXTRA_TRANSITION_NAME) + if (!TextUtils.isEmpty(arguments!!.getString(EXTRA_TRANSITION_NAME)) + && firstSessionId == transitionName + && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + ViewCompat.setTransitionName( + view.findViewById(R.id.speaker_summary), + transitionName) + activity?.supportStartPostponedEnterTransition() + } + return true + } + }) } private fun bindSession(session: Session.SpeechSession) { @@ -124,6 +138,10 @@ class SessionDetailFragment : Fragment(), Injectable { binding.nextSession = nextSession } + fun hideButton() { + binding.fab.visibility = View.INVISIBLE + } + interface OnClickBottomAreaListener { fun onClickPrevSession() fun onClickNextSession() diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/AllSessionsFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/AllSessionsFragment.kt index 872a6664..7ec171f4 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/AllSessionsFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/AllSessionsFragment.kt @@ -22,8 +22,8 @@ import io.github.droidkaigi.confsched2018.model.Session import io.github.droidkaigi.confsched2018.presentation.NavigationController import io.github.droidkaigi.confsched2018.presentation.Result import io.github.droidkaigi.confsched2018.presentation.common.view.TabLayoutItem -import io.github.droidkaigi.confsched2018.presentation.sessions.SessionsFragment.CurrentSessionScroller import io.github.droidkaigi.confsched2018.presentation.sessions.item.DateSessionsSection +import io.github.droidkaigi.confsched2018.presentation.sessions.SessionsFragment.CurrentSessionScroller import io.github.droidkaigi.confsched2018.presentation.sessions.item.SpeechSessionItem import io.github.droidkaigi.confsched2018.util.ProgressTimeLatch import io.github.droidkaigi.confsched2018.util.SessionAlarm @@ -115,7 +115,8 @@ class AllSessionsFragment : Fragment(), Injectable, CurrentSessionScroller, TabL add(sessionsSection) setOnItemClickListener({ item, v -> val sessionItem = item as? SpeechSessionItem ?: return@setOnItemClickListener - val sharedElement = Pair(v.findViewById(R.id.speaker_summary), + val sharedElement = Pair( + v.findViewById(R.id.speaker_summary), sessionItem.session.id) navigationController.navigateToSessionDetailActivity(sessionItem.session, sharedElement) }) From dfe03a68eb8aa59397e6f5c038013b3714f1d6fc Mon Sep 17 00:00:00 2001 From: e10dokup <2edokup@gmail.com> Date: Fri, 2 Feb 2018 00:59:27 +0900 Subject: [PATCH 3/6] Set Shared element on other sessions fragments --- .../detail/SessionDetailActivity.kt | 21 ++++--------------- .../favorite/FavoriteSessionsFragment.kt | 8 +++++-- .../search/SearchSessionsFragment.kt | 9 ++++++-- .../sessions/AllSessionsFragment.kt | 3 +++ .../sessions/RoomSessionsFragment.kt | 8 +++++-- .../speaker/SpeakerDetailFragment.kt | 8 +++++-- .../presentation/topic/TopicDetailFragment.kt | 8 +++++-- 7 files changed, 38 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailActivity.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailActivity.kt index 7b492466..df58ed5f 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailActivity.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailActivity.kt @@ -74,18 +74,7 @@ class SessionDetailActivity : binding.detailSessionsPager, binding.detailSessionsPager.currentItem) sharedElements?.clear() - - sharedElements?.put( - intent.getStringExtra(EXTRA_TRANSITION_NAME), - currentFragment.speakerSummary) currentFragment.hideButton() - - val data = Intent() - val bundle = Bundle() - bundle.putString("position", sessions[binding.detailSessionsPager.currentItem].id) - data.putExtras(bundle) - - setResult(Activity.RESULT_OK, data) } } } @@ -174,8 +163,7 @@ class SessionDetailActivity : companion object { const val EXTRA_SESSION_ID = "EXTRA_SESSION_ID" - const val EXTRA_TRANSITION_NAME = "EXTRA_TRANSITION_NAME" - const val REQUEST_POSITION = 1 + private const val EXTRA_TRANSITION_NAME = "EXTRA_TRANSITION_NAME" fun start(context: Context, session: Session) { context.startActivity(createIntent(context, session.id)) @@ -183,9 +171,7 @@ class SessionDetailActivity : fun start(activity: Activity, session: Session, sharedElement: Pair) { val options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElement) - activity.startActivityForResult( - createIntent(activity, session.id, sharedElement), - REQUEST_POSITION, + activity.startActivity(createIntent(activity, session.id, sharedElement), options.toBundle()) } @@ -195,7 +181,8 @@ class SessionDetailActivity : } } - fun createIntent(context: Context, sessionId: String, sharedElement: Pair): + private fun createIntent(context: Context, sessionId: String, sharedElement: Pair): Intent { return Intent(context, SessionDetailActivity::class.java).apply { putExtra(EXTRA_SESSION_ID, sessionId) diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/favorite/FavoriteSessionsFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/favorite/FavoriteSessionsFragment.kt index c4a5714b..5a358148 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/favorite/FavoriteSessionsFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/favorite/FavoriteSessionsFragment.kt @@ -6,6 +6,7 @@ import android.os.Bundle import android.support.transition.TransitionInflater import android.support.transition.TransitionManager import android.support.v4.app.Fragment +import android.support.v4.util.Pair import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView import android.support.v7.widget.SimpleItemAnimator @@ -91,9 +92,12 @@ class FavoriteSessionsFragment : Fragment(), Injectable { private fun setupRecyclerView() { val groupAdapter = GroupAdapter().apply { add(sessionsSection) - setOnItemClickListener({ item, _ -> + setOnItemClickListener({ item, v -> val sessionItem = item as? SpeechSessionItem ?: return@setOnItemClickListener - navigationController.navigateToSessionDetailActivity(sessionItem.session) + val sharedElement = Pair( + v.findViewById(R.id.speaker_summary), + sessionItem.session.id) + navigationController.navigateToSessionDetailActivity(sessionItem.session, sharedElement) }) } binding.sessionsRecycler.apply { diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionsFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionsFragment.kt index 6edb2225..90401188 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionsFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionsFragment.kt @@ -4,11 +4,13 @@ import android.arch.lifecycle.ViewModelProvider import android.arch.lifecycle.ViewModelProviders import android.os.Bundle import android.support.v4.app.Fragment +import android.support.v4.util.Pair import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.xwray.groupie.GroupAdapter import com.xwray.groupie.ViewHolder +import io.github.droidkaigi.confsched2018.R import io.github.droidkaigi.confsched2018.databinding.FragmentSearchSessionsBinding import io.github.droidkaigi.confsched2018.di.Injectable import io.github.droidkaigi.confsched2018.model.Session @@ -70,9 +72,12 @@ class SearchSessionsFragment : Fragment(), Injectable, TabLayoutItem { private fun setupRecyclerView() { val groupAdapter = GroupAdapter().apply { add(sessionsSection) - setOnItemClickListener({ item, _ -> + setOnItemClickListener({ item, v -> val sessionItem = (item as? HorizontalSessionItem) ?: return@setOnItemClickListener - navigationController.navigateToSessionDetailActivity(sessionItem.session) + val sharedElement = Pair( + v.findViewById(R.id.speaker_summary), + sessionItem.session.id) + navigationController.navigateToSessionDetailActivity(sessionItem.session, sharedElement) }) } binding.searchSessionRecycler.apply { diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/AllSessionsFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/AllSessionsFragment.kt index 7ec171f4..eb45da2a 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/AllSessionsFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/AllSessionsFragment.kt @@ -106,10 +106,13 @@ class AllSessionsFragment : Fragment(), Injectable, CurrentSessionScroller, TabL binding.sessionsRecycler.scrollToPosition(currentSessionPosition) } +<<<<<<< HEAD override fun scrollToTop() { binding.sessionsRecycler.smoothScrollToPosition(0) } +======= +>>>>>>> Set Shared element on other sessions fragments private fun setupRecyclerView() { val groupAdapter = GroupAdapter().apply { add(sessionsSection) diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/RoomSessionsFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/RoomSessionsFragment.kt index d81ee826..ac900ca7 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/RoomSessionsFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/RoomSessionsFragment.kt @@ -6,6 +6,7 @@ import android.os.Bundle import android.support.transition.TransitionInflater import android.support.transition.TransitionManager import android.support.v4.app.Fragment +import android.support.v4.util.Pair import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView import android.support.v7.widget.SimpleItemAnimator @@ -120,9 +121,12 @@ class RoomSessionsFragment : Fragment(), Injectable, CurrentSessionScroller, Tab private fun setupRecyclerView() { val groupAdapter = GroupAdapter().apply { add(sessionsSection) - setOnItemClickListener({ item, _ -> + setOnItemClickListener({ item, v -> val sessionItem = item as? SpeechSessionItem ?: return@setOnItemClickListener - navigationController.navigateToSessionDetailActivity(sessionItem.session) + val sharedElement = Pair( + v.findViewById(R.id.speaker_summary), + sessionItem.session.id) + navigationController.navigateToSessionDetailActivity(sessionItem.session, sharedElement) }) } binding.sessionsRecycler.apply { diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/speaker/SpeakerDetailFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/speaker/SpeakerDetailFragment.kt index 0e4819f7..b7dab397 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/speaker/SpeakerDetailFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/speaker/SpeakerDetailFragment.kt @@ -9,6 +9,7 @@ import android.os.Build import android.os.Bundle import android.support.design.widget.BottomSheetDialog import android.support.v4.app.Fragment +import android.support.v4.util.Pair import android.support.v4.view.ViewCompat import android.support.v7.widget.LinearLayoutManager import android.text.TextUtils @@ -214,9 +215,12 @@ class SpeakerDetailFragment : Fragment(), Injectable { private fun setupRecyclerView() { val groupAdapter = GroupAdapter().apply { add(sessionsSection) - setOnItemClickListener({ item, _ -> + setOnItemClickListener({ item, v -> val sessionItem = item as? SpeechSessionItem ?: return@setOnItemClickListener - navigationController.navigateToSessionDetailActivity(sessionItem.session) + val sharedElement = Pair( + v.findViewById(R.id.speaker_summary), + sessionItem.session.id) + navigationController.navigateToSessionDetailActivity(sessionItem.session, sharedElement) }) } val linearLayoutManager = LinearLayoutManager(context) diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/topic/TopicDetailFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/topic/TopicDetailFragment.kt index 61230d03..a8a24a49 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/topic/TopicDetailFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/topic/TopicDetailFragment.kt @@ -4,6 +4,7 @@ import android.arch.lifecycle.ViewModelProvider import android.arch.lifecycle.ViewModelProviders import android.os.Bundle import android.support.v4.app.Fragment +import android.support.v4.util.Pair import android.support.v7.widget.LinearLayoutManager import android.view.LayoutInflater import android.view.View @@ -78,9 +79,12 @@ class TopicDetailFragment : Fragment(), Injectable { private fun setupRecyclerView() { val groupAdapter = GroupAdapter().apply { add(sessionsSection) - setOnItemClickListener { item, _ -> + setOnItemClickListener { item, v -> val sessionItem = item as? SpeechSessionItem ?: return@setOnItemClickListener - navigationController.navigateToSessionDetailActivity(sessionItem.session) + val sharedElement = Pair( + v.findViewById(R.id.speaker_summary), + sessionItem.session.id) + navigationController.navigateToSessionDetailActivity(sessionItem.session, sharedElement) } } val linearLayoutManager = LinearLayoutManager(context) From 17d0220d16de1e00538d33d8fb6d4088e86028b4 Mon Sep 17 00:00:00 2001 From: Yoshihiro WADA <2edokup@gmail.com> Date: Sun, 4 Feb 2018 13:22:07 +0900 Subject: [PATCH 4/6] Remove unnecessary properties / move SharedElementCallback to anonymous object --- .../detail/SessionDetailActivity.kt | 49 +++++++++---------- .../detail/SessionDetailFragment.kt | 45 ++++++++--------- .../favorite/FavoriteSessionsFragment.kt | 4 +- .../search/SearchSessionsFragment.kt | 4 +- .../sessions/AllSessionsFragment.kt | 9 ++-- .../sessions/RoomSessionsFragment.kt | 4 +- .../speaker/SpeakerDetailFragment.kt | 4 +- .../presentation/topic/TopicDetailFragment.kt | 4 +- .../confsched2018/util/ext/ViewExt.kt | 12 +++++ 9 files changed, 74 insertions(+), 61 deletions(-) diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailActivity.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailActivity.kt index df58ed5f..3b27ba67 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailActivity.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailActivity.kt @@ -40,8 +40,6 @@ class SessionDetailActivity : @Inject lateinit var viewModelFactory: ViewModelProvider.Factory @Inject lateinit var drawerMenu: DrawerMenu - private var backPressed = false - private val binding: ActivitySessionDetailBinding by lazy { DataBindingUtil .setContentView( @@ -62,23 +60,6 @@ class SessionDetailActivity : intent.getStringExtra(EXTRA_SESSION_ID) } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - private val sharedElementCallback = object : SharedElementCallback() { - override fun onMapSharedElements( - names: MutableList?, - sharedElements: MutableMap?) { - super.onMapSharedElements(names, sharedElements) - - if (backPressed) { - val currentFragment = pagerAdapter.findFragmentByPosition( - binding.detailSessionsPager, - binding.detailSessionsPager.currentItem) - sharedElements?.clear() - currentFragment.hideButton() - } - } - } - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) supportPostponeEnterTransition() @@ -93,9 +74,8 @@ class SessionDetailActivity : sessions = result.data bindSessions(sessions) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - setEnterSharedElementCallback(sharedElementCallback) + removeSharedElements() } - } is Result.Failure -> { Timber.e(result.e) @@ -121,11 +101,26 @@ class SessionDetailActivity : } } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + private fun removeSharedElements() { + setEnterSharedElementCallback(object : SharedElementCallback() { + override fun onMapSharedElements( + names: MutableList?, + sharedElements: MutableMap?) { + super.onMapSharedElements(names, sharedElements) + + val currentFragment = pagerAdapter.findFragmentByPosition( + binding.detailSessionsPager, + binding.detailSessionsPager.currentItem) + sharedElements?.clear() + currentFragment.hideButton() + } + }) + } override fun supportFragmentInjector(): AndroidInjector = dispatchingAndroidInjector override fun onBackPressed() { - backPressed = true if (drawerMenu.closeDrawerIfNeeded()) { super.onBackPressed() } @@ -158,7 +153,6 @@ class SessionDetailActivity : fun findFragmentByPosition(viewPager: ViewPager, position: Int): SessionDetailFragment { return instantiateItem(viewPager, position) as SessionDetailFragment } - } companion object { @@ -170,9 +164,11 @@ class SessionDetailActivity : } fun start(activity: Activity, session: Session, sharedElement: Pair) { - val options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElement) - activity.startActivity(createIntent(activity, session.id, sharedElement), - options.toBundle()) + val options = ActivityOptionsCompat.makeSceneTransitionAnimation( + activity, + sharedElement) + val intent = createIntent(activity, session.id, sharedElement) + activity.startActivity(intent, options.toBundle()) } fun createIntent(context: Context, sessionId: String): Intent { @@ -189,6 +185,5 @@ class SessionDetailActivity : putExtra(EXTRA_TRANSITION_NAME, sharedElement.second) } } - } } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt index 74d6210f..658606bc 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt @@ -1,5 +1,6 @@ package io.github.droidkaigi.confsched2018.presentation.detail +import android.annotation.TargetApi import android.arch.lifecycle.ViewModelProvider import android.arch.lifecycle.ViewModelProviders import android.graphics.drawable.Animatable @@ -11,7 +12,6 @@ import android.text.TextUtils import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.view.ViewTreeObserver import io.github.droidkaigi.confsched2018.R import io.github.droidkaigi.confsched2018.databinding.FragmentSessionDetailBinding import io.github.droidkaigi.confsched2018.di.Injectable @@ -19,8 +19,8 @@ import io.github.droidkaigi.confsched2018.model.Level import io.github.droidkaigi.confsched2018.model.Session import io.github.droidkaigi.confsched2018.presentation.NavigationController import io.github.droidkaigi.confsched2018.presentation.Result -import io.github.droidkaigi.confsched2018.presentation.common.view.SpeakersSummaryLayout import io.github.droidkaigi.confsched2018.util.SessionAlarm +import io.github.droidkaigi.confsched2018.util.ext.addOnetimeOnPreDrawListener import io.github.droidkaigi.confsched2018.util.ext.context import io.github.droidkaigi.confsched2018.util.ext.drawable import io.github.droidkaigi.confsched2018.util.ext.observe @@ -39,9 +39,6 @@ class SessionDetailFragment : Fragment(), Injectable { ViewModelProviders.of(activity!!, viewModelFactory).get(SessionDetailViewModel::class.java) } - val speakerSummary: SpeakersSummaryLayout - get() = binding.speakerSummary - override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -84,25 +81,15 @@ class SessionDetailFragment : Fragment(), Injectable { binding.toolbar.setNavigationOnClickListener { activity?.finish() } - binding.speakerSummary.viewTreeObserver.addOnPreDrawListener( - object : ViewTreeObserver.OnPreDrawListener { - override fun onPreDraw(): Boolean { - binding.speakerSummary.viewTreeObserver.removeOnPreDrawListener(this) - - val firstSessionId = (activity as? SessionDetailActivity)?.firstSessionId - ?: return true - val transitionName = arguments!!.getString(EXTRA_TRANSITION_NAME) - if (!TextUtils.isEmpty(arguments!!.getString(EXTRA_TRANSITION_NAME)) - && firstSessionId == transitionName - && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - ViewCompat.setTransitionName( - view.findViewById(R.id.speaker_summary), - transitionName) - activity?.supportStartPostponedEnterTransition() - } - return true - } - }) + val firstSessionId = (activity as? SessionDetailActivity)?.firstSessionId ?: return + val transitionName = arguments!!.getString(EXTRA_TRANSITION_NAME) + + if (!TextUtils.isEmpty(transitionName) + && firstSessionId == transitionName + && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + initViewTransitions(view) + } + } private fun bindSession(session: Session.SpeechSession) { @@ -142,6 +129,16 @@ class SessionDetailFragment : Fragment(), Injectable { binding.fab.visibility = View.INVISIBLE } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + private fun initViewTransitions(view: View) { + binding.speakerSummary.addOnetimeOnPreDrawListener { + ViewCompat.setTransitionName( + view.findViewById(R.id.speaker_summary), + arguments!!.getString(EXTRA_TRANSITION_NAME)) + activity?.supportStartPostponedEnterTransition() + } + } + interface OnClickBottomAreaListener { fun onClickPrevSession() fun onClickNextSession() diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/favorite/FavoriteSessionsFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/favorite/FavoriteSessionsFragment.kt index 5a358148..b55503b2 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/favorite/FavoriteSessionsFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/favorite/FavoriteSessionsFragment.kt @@ -97,7 +97,9 @@ class FavoriteSessionsFragment : Fragment(), Injectable { val sharedElement = Pair( v.findViewById(R.id.speaker_summary), sessionItem.session.id) - navigationController.navigateToSessionDetailActivity(sessionItem.session, sharedElement) + navigationController.navigateToSessionDetailActivity( + sessionItem.session, + sharedElement) }) } binding.sessionsRecycler.apply { diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionsFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionsFragment.kt index 90401188..4babe8e6 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionsFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionsFragment.kt @@ -77,7 +77,9 @@ class SearchSessionsFragment : Fragment(), Injectable, TabLayoutItem { val sharedElement = Pair( v.findViewById(R.id.speaker_summary), sessionItem.session.id) - navigationController.navigateToSessionDetailActivity(sessionItem.session, sharedElement) + navigationController.navigateToSessionDetailActivity( + sessionItem.session, + sharedElement) }) } binding.searchSessionRecycler.apply { diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/AllSessionsFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/AllSessionsFragment.kt index eb45da2a..e85c700d 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/AllSessionsFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/AllSessionsFragment.kt @@ -22,8 +22,8 @@ import io.github.droidkaigi.confsched2018.model.Session import io.github.droidkaigi.confsched2018.presentation.NavigationController import io.github.droidkaigi.confsched2018.presentation.Result import io.github.droidkaigi.confsched2018.presentation.common.view.TabLayoutItem -import io.github.droidkaigi.confsched2018.presentation.sessions.item.DateSessionsSection import io.github.droidkaigi.confsched2018.presentation.sessions.SessionsFragment.CurrentSessionScroller +import io.github.droidkaigi.confsched2018.presentation.sessions.item.DateSessionsSection import io.github.droidkaigi.confsched2018.presentation.sessions.item.SpeechSessionItem import io.github.droidkaigi.confsched2018.util.ProgressTimeLatch import io.github.droidkaigi.confsched2018.util.SessionAlarm @@ -106,13 +106,10 @@ class AllSessionsFragment : Fragment(), Injectable, CurrentSessionScroller, TabL binding.sessionsRecycler.scrollToPosition(currentSessionPosition) } -<<<<<<< HEAD override fun scrollToTop() { binding.sessionsRecycler.smoothScrollToPosition(0) } -======= ->>>>>>> Set Shared element on other sessions fragments private fun setupRecyclerView() { val groupAdapter = GroupAdapter().apply { add(sessionsSection) @@ -121,7 +118,9 @@ class AllSessionsFragment : Fragment(), Injectable, CurrentSessionScroller, TabL val sharedElement = Pair( v.findViewById(R.id.speaker_summary), sessionItem.session.id) - navigationController.navigateToSessionDetailActivity(sessionItem.session, sharedElement) + navigationController.navigateToSessionDetailActivity( + sessionItem.session, + sharedElement) }) } binding.sessionsRecycler.apply { diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/RoomSessionsFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/RoomSessionsFragment.kt index ac900ca7..f1f023fd 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/RoomSessionsFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sessions/RoomSessionsFragment.kt @@ -126,7 +126,9 @@ class RoomSessionsFragment : Fragment(), Injectable, CurrentSessionScroller, Tab val sharedElement = Pair( v.findViewById(R.id.speaker_summary), sessionItem.session.id) - navigationController.navigateToSessionDetailActivity(sessionItem.session, sharedElement) + navigationController.navigateToSessionDetailActivity( + sessionItem.session, + sharedElement) }) } binding.sessionsRecycler.apply { diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/speaker/SpeakerDetailFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/speaker/SpeakerDetailFragment.kt index b7dab397..87da30d2 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/speaker/SpeakerDetailFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/speaker/SpeakerDetailFragment.kt @@ -220,7 +220,9 @@ class SpeakerDetailFragment : Fragment(), Injectable { val sharedElement = Pair( v.findViewById(R.id.speaker_summary), sessionItem.session.id) - navigationController.navigateToSessionDetailActivity(sessionItem.session, sharedElement) + navigationController.navigateToSessionDetailActivity( + sessionItem.session, + sharedElement) }) } val linearLayoutManager = LinearLayoutManager(context) diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/topic/TopicDetailFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/topic/TopicDetailFragment.kt index a8a24a49..66917b71 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/topic/TopicDetailFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/topic/TopicDetailFragment.kt @@ -84,7 +84,9 @@ class TopicDetailFragment : Fragment(), Injectable { val sharedElement = Pair( v.findViewById(R.id.speaker_summary), sessionItem.session.id) - navigationController.navigateToSessionDetailActivity(sessionItem.session, sharedElement) + navigationController.navigateToSessionDetailActivity( + sessionItem.session, + sharedElement) } } val linearLayoutManager = LinearLayoutManager(context) diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/util/ext/ViewExt.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/util/ext/ViewExt.kt index 627b5f1b..c3b3a71b 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/util/ext/ViewExt.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/util/ext/ViewExt.kt @@ -2,6 +2,7 @@ package io.github.droidkaigi.confsched2018.util.ext import android.os.Build import android.view.View +import android.view.ViewTreeObserver fun View.setVisible(visible: Boolean) { if (visible) { @@ -23,6 +24,17 @@ fun View.isGone() = visibility == View.GONE fun View.isVisible() = visibility == View.VISIBLE +fun View.addOnetimeOnPreDrawListener(listener: () -> Unit) { + viewTreeObserver.addOnPreDrawListener(object : ViewTreeObserver.OnPreDrawListener { + override fun onPreDraw(): Boolean { + viewTreeObserver.removeOnPreDrawListener(this) + listener.invoke() + + return true + } + }) +} + var View.elevationForPostLollipop: Float get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { elevation From 3109dca346a6fe9febbf561eb32e5da2a201c7d2 Mon Sep 17 00:00:00 2001 From: Yoshihiro WADA <2edokup@gmail.com> Date: Sun, 4 Feb 2018 13:42:11 +0900 Subject: [PATCH 5/6] Add id to SpeakersSummaryLayout on item_horizontal_session for avoid crash --- app/src/main/res/layout/item_horizontal_session.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/item_horizontal_session.xml b/app/src/main/res/layout/item_horizontal_session.xml index 8e032b85..d109582f 100644 --- a/app/src/main/res/layout/item_horizontal_session.xml +++ b/app/src/main/res/layout/item_horizontal_session.xml @@ -98,6 +98,7 @@ /> Date: Sun, 4 Feb 2018 16:00:03 +0900 Subject: [PATCH 6/6] Fix danger issue --- .../confsched2018/presentation/detail/SessionDetailFragment.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt index 658606bc..2c88ae8b 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt @@ -89,7 +89,6 @@ class SessionDetailFragment : Fragment(), Injectable { && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { initViewTransitions(view) } - } private fun bindSession(session: Session.SpeechSession) {