From 46b4dfafc5b48616b61c0d68a657904fc2cff3d0 Mon Sep 17 00:00:00 2001 From: takahirom Date: Fri, 29 Dec 2017 15:56:36 +0900 Subject: [PATCH 1/6] Change DetailFragment to SessionDetailFragment --- .../droidkaigi/confsched2018/di/FragmentBuildersModule.kt | 4 ++-- .../confsched2018/presentation/NavigationController.kt | 4 ++-- .../presentation/detail/SessionDetailActivity.kt | 4 ++-- .../detail/{DetailFragment.kt => SessionDetailFragment.kt} | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) rename app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/{DetailFragment.kt => SessionDetailFragment.kt} (93%) diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/FragmentBuildersModule.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/FragmentBuildersModule.kt index b8eb6960..14800e60 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/di/FragmentBuildersModule.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/FragmentBuildersModule.kt @@ -2,7 +2,7 @@ package io.github.droidkaigi.confsched2018.di import dagger.Module import dagger.android.ContributesAndroidInjector -import io.github.droidkaigi.confsched2018.presentation.detail.DetailFragment +import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailFragment import io.github.droidkaigi.confsched2018.presentation.favorite.FavoriteSessionsFragment import io.github.droidkaigi.confsched2018.presentation.feed.FeedFragment import io.github.droidkaigi.confsched2018.presentation.search.SearchFragment @@ -26,5 +26,5 @@ import io.github.droidkaigi.confsched2018.presentation.sessions.SessionsFragment @ContributesAndroidInjector abstract fun contributeFeedFragment(): FeedFragment - @ContributesAndroidInjector abstract fun contributeDetailFragment(): DetailFragment + @ContributesAndroidInjector abstract fun contributeDetailFragment(): SessionDetailFragment } 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 863240ff..67e97901 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 @@ -4,7 +4,7 @@ import android.support.v4.app.FragmentManager import android.support.v7.app.AppCompatActivity import io.github.droidkaigi.confsched2018.R import io.github.droidkaigi.confsched2018.model.Session -import io.github.droidkaigi.confsched2018.presentation.detail.DetailFragment +import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailFragment import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailActivity import io.github.droidkaigi.confsched2018.presentation.favorite.FavoriteSessionsFragment import io.github.droidkaigi.confsched2018.presentation.feed.FeedFragment @@ -47,7 +47,7 @@ class NavigationController @Inject constructor(private val activity: AppCompatAc fun navigateToDetail(sessionId: String) { fragmentManager .beginTransaction() - .replace(containerId, DetailFragment.newInstance(sessionId)) + .replace(containerId, SessionDetailFragment.newInstance(sessionId)) .commitAllowingStateLoss() } 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 cceeb986..cdf725e4 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 @@ -29,6 +29,8 @@ class SessionDetailActivity : AppCompatActivity(), HasSupportFragmentInjector { navigationController.navigateToDetail(intent.getStringExtra(EXTRA_SESSION_ID)) } + override fun supportFragmentInjector(): AndroidInjector = dispatchingAndroidInjector + companion object { val EXTRA_SESSION_ID = "EXTRA_SESSION_ID" fun start(context: Context, session: Session) { @@ -37,6 +39,4 @@ class SessionDetailActivity : AppCompatActivity(), HasSupportFragmentInjector { }) } } - - override fun supportFragmentInjector(): AndroidInjector = dispatchingAndroidInjector } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/DetailFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt similarity index 93% rename from app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/DetailFragment.kt rename to app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt index 652712e9..030b5c01 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/DetailFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailFragment.kt @@ -14,7 +14,7 @@ import io.github.droidkaigi.confsched2018.util.ext.observe import timber.log.Timber import javax.inject.Inject -class DetailFragment : Fragment(), Injectable { +class SessionDetailFragment : Fragment(), Injectable { // TODO create layout private lateinit var binding: ItemSessionBinding @@ -53,7 +53,7 @@ class DetailFragment : Fragment(), Injectable { companion object { val EXTRA_SESSION_ID = "EXTRA_SESSION_ID" - fun newInstance(sessionId: String): DetailFragment = DetailFragment().apply { + fun newInstance(sessionId: String): SessionDetailFragment = SessionDetailFragment().apply { arguments = Bundle().apply { putString(EXTRA_SESSION_ID, sessionId) } From db83d2efff8decdde403ee5d5f7829869aaf3045 Mon Sep 17 00:00:00 2001 From: takahirom Date: Fri, 29 Dec 2017 18:09:52 +0900 Subject: [PATCH 2/6] Create empty activities and fragments for each function --- app/build.gradle | 2 + app/src/main/AndroidManifest.xml | 44 +++++++++++ .../di/AboutThisAppActivityBuilder.kt | 12 +++ .../di/AboutThisAppActivityModule.kt | 13 ++++ .../confsched2018/di/AppComponent.kt | 4 + .../di/FragmentBuildersModule.kt | 12 +++ .../confsched2018/di/MapActivityBuilder.kt | 12 +++ .../confsched2018/di/MapActivityModule.kt | 13 ++++ .../di/SessionDetailActivityModule.kt | 2 +- .../di/SettingsActivityBuilder.kt | 12 +++ .../di/SettingsActivityModule.kt | 13 ++++ .../di/SponsorsActivityBuilder.kt | 12 +++ .../di/SponsorsActivityModule.kt | 13 ++++ .../presentation/MainActivity.kt | 10 +++ .../presentation/NavigationController.kt | 73 ++++++++++++++----- .../about/AboutThisAppActivity.kt | 41 +++++++++++ .../about/AboutThisAppFragment.kt | 26 +++++++ .../favorite/FavoriteSessionsFragment.kt | 2 +- .../presentation/map/MapActivity.kt | 41 +++++++++++ .../presentation/map/MapFragment.kt | 26 +++++++ .../search/SearchSessionFragment.kt | 2 +- .../sessions/AllSessionsFragment.kt | 2 +- .../sessions/RoomSessionsFragment.kt | 2 +- .../presentation/settings/SettingsActivity.kt | 42 +++++++++++ .../presentation/settings/SettingsFragment.kt | 26 +++++++ .../presentation/sponsors/SponsorsActivity.kt | 42 +++++++++++ .../presentation/sponsors/SponsorsFragment.kt | 26 +++++++ .../res/layout/activity_about_this_app.xml | 35 +++++++++ app/src/main/res/layout/activity_map.xml | 35 +++++++++ app/src/main/res/layout/activity_settings.xml | 35 +++++++++ app/src/main/res/layout/activity_sponsors.xml | 35 +++++++++ .../res/layout/fragment_about_this_app.xml | 14 ++++ app/src/main/res/layout/fragment_map.xml | 14 ++++ app/src/main/res/layout/fragment_settings.xml | 14 ++++ app/src/main/res/layout/fragment_sponsors.xml | 14 ++++ app/src/main/res/values/strings.xml | 12 +++ 36 files changed, 709 insertions(+), 24 deletions(-) create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/di/AboutThisAppActivityBuilder.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/di/AboutThisAppActivityModule.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/di/MapActivityBuilder.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/di/MapActivityModule.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/di/SettingsActivityBuilder.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/di/SettingsActivityModule.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/di/SponsorsActivityBuilder.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/di/SponsorsActivityModule.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/presentation/about/AboutThisAppActivity.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/presentation/about/AboutThisAppFragment.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/presentation/map/MapActivity.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/presentation/map/MapFragment.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/presentation/settings/SettingsActivity.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/presentation/settings/SettingsFragment.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sponsors/SponsorsActivity.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sponsors/SponsorsFragment.kt create mode 100644 app/src/main/res/layout/activity_about_this_app.xml create mode 100644 app/src/main/res/layout/activity_map.xml create mode 100644 app/src/main/res/layout/activity_settings.xml create mode 100644 app/src/main/res/layout/activity_sponsors.xml create mode 100644 app/src/main/res/layout/fragment_about_this_app.xml create mode 100644 app/src/main/res/layout/fragment_map.xml create mode 100644 app/src/main/res/layout/fragment_settings.xml create mode 100644 app/src/main/res/layout/fragment_sponsors.xml diff --git a/app/build.gradle b/app/build.gradle index d008cd63..ce4faa5d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -152,3 +152,5 @@ repositories { } apply plugin: 'com.google.gms.google-services' + + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 80190252..9eb6951a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -25,6 +25,50 @@ + + + + + + + + + + + + diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/AboutThisAppActivityBuilder.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/AboutThisAppActivityBuilder.kt new file mode 100644 index 00000000..801c8e01 --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/AboutThisAppActivityBuilder.kt @@ -0,0 +1,12 @@ +package io.github.droidkaigi.confsched2018.di + +import dagger.Module +import dagger.android.ContributesAndroidInjector +import io.github.droidkaigi.confsched2018.presentation.about.AboutThisAppActivity +import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailActivity + +@Module abstract class AboutThisAppActivityBuilder { + @ContributesAndroidInjector(modules = [FragmentBuildersModule::class, AboutThisAppActivityModule::class]) + abstract fun contributeAboutThisAppActivity(): AboutThisAppActivity + +} diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/AboutThisAppActivityModule.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/AboutThisAppActivityModule.kt new file mode 100644 index 00000000..02d8f01e --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/AboutThisAppActivityModule.kt @@ -0,0 +1,13 @@ +package io.github.droidkaigi.confsched2018.di + +import android.support.v7.app.AppCompatActivity +import dagger.Binds +import dagger.Module +import io.github.droidkaigi.confsched2018.presentation.about.AboutThisAppActivity +import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailActivity + +@Module +interface AboutThisAppActivityModule { + @Binds + fun providesAppCompatActivity(activity: AboutThisAppActivity): AppCompatActivity +} diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/AppComponent.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/AppComponent.kt index e2ab67b8..e16f1370 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/di/AppComponent.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/AppComponent.kt @@ -14,6 +14,10 @@ import javax.inject.Singleton NetworkModule::class, DatabaseModule::class, MainActivityBuilder::class, + MapActivityBuilder::class, + AboutThisAppActivityBuilder::class, + SettingsActivityBuilder::class, + SponsorsActivityBuilder::class, SessionDetailActivityBuilder::class ]) interface AppComponent { diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/FragmentBuildersModule.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/FragmentBuildersModule.kt index 14800e60..395ded30 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/di/FragmentBuildersModule.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/FragmentBuildersModule.kt @@ -2,14 +2,18 @@ package io.github.droidkaigi.confsched2018.di import dagger.Module import dagger.android.ContributesAndroidInjector +import io.github.droidkaigi.confsched2018.presentation.about.AboutThisAppFragment import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailFragment import io.github.droidkaigi.confsched2018.presentation.favorite.FavoriteSessionsFragment import io.github.droidkaigi.confsched2018.presentation.feed.FeedFragment +import io.github.droidkaigi.confsched2018.presentation.map.MapFragment import io.github.droidkaigi.confsched2018.presentation.search.SearchFragment import io.github.droidkaigi.confsched2018.presentation.search.SearchSessionFragment import io.github.droidkaigi.confsched2018.presentation.sessions.AllSessionsFragment import io.github.droidkaigi.confsched2018.presentation.sessions.RoomSessionsFragment import io.github.droidkaigi.confsched2018.presentation.sessions.SessionsFragment +import io.github.droidkaigi.confsched2018.presentation.settings.SettingsFragment +import io.github.droidkaigi.confsched2018.presentation.sponsors.SponsorsFragment @Module abstract class FragmentBuildersModule { @ContributesAndroidInjector abstract fun contributeSessionsFragment(): SessionsFragment @@ -27,4 +31,12 @@ import io.github.droidkaigi.confsched2018.presentation.sessions.SessionsFragment @ContributesAndroidInjector abstract fun contributeFeedFragment(): FeedFragment @ContributesAndroidInjector abstract fun contributeDetailFragment(): SessionDetailFragment + + @ContributesAndroidInjector abstract fun contributeMapFragment(): MapFragment + + @ContributesAndroidInjector abstract fun contributeAboutThisAppFragment(): AboutThisAppFragment + + @ContributesAndroidInjector abstract fun contributeSponsorsFragment(): SponsorsFragment + + @ContributesAndroidInjector abstract fun contributeSettingsFragment(): SettingsFragment } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/MapActivityBuilder.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/MapActivityBuilder.kt new file mode 100644 index 00000000..daa8150a --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/MapActivityBuilder.kt @@ -0,0 +1,12 @@ +package io.github.droidkaigi.confsched2018.di + +import dagger.Module +import dagger.android.ContributesAndroidInjector +import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailActivity +import io.github.droidkaigi.confsched2018.presentation.map.MapActivity + +@Module abstract class MapActivityBuilder { + @ContributesAndroidInjector(modules = [FragmentBuildersModule::class, MapActivityModule::class]) + abstract fun contributeMapActivity(): MapActivity + +} diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/MapActivityModule.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/MapActivityModule.kt new file mode 100644 index 00000000..6a327db4 --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/MapActivityModule.kt @@ -0,0 +1,13 @@ +package io.github.droidkaigi.confsched2018.di + +import android.support.v7.app.AppCompatActivity +import dagger.Binds +import dagger.Module +import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailActivity +import io.github.droidkaigi.confsched2018.presentation.map.MapActivity + +@Module +interface MapActivityModule { + @Binds + fun providesAppCompatActivity(activity: MapActivity): AppCompatActivity +} diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/SessionDetailActivityModule.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/SessionDetailActivityModule.kt index 32cf1600..54413c97 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/di/SessionDetailActivityModule.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/SessionDetailActivityModule.kt @@ -8,5 +8,5 @@ import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailActiv @Module interface SessionDetailActivityModule { @Binds - fun providesAppCompatActivity(sessionDetailActivity: SessionDetailActivity): AppCompatActivity + fun providesAppCompatActivity(activity: SessionDetailActivity): AppCompatActivity } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/SettingsActivityBuilder.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/SettingsActivityBuilder.kt new file mode 100644 index 00000000..96bac953 --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/SettingsActivityBuilder.kt @@ -0,0 +1,12 @@ +package io.github.droidkaigi.confsched2018.di + +import dagger.Module +import dagger.android.ContributesAndroidInjector +import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailActivity +import io.github.droidkaigi.confsched2018.presentation.settings.SettingsActivity + +@Module abstract class SettingsActivityBuilder { + @ContributesAndroidInjector(modules = [FragmentBuildersModule::class, SettingsActivityModule::class]) + abstract fun contributeSettingsActivity(): SettingsActivity + +} diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/SettingsActivityModule.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/SettingsActivityModule.kt new file mode 100644 index 00000000..5c3788e2 --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/SettingsActivityModule.kt @@ -0,0 +1,13 @@ +package io.github.droidkaigi.confsched2018.di + +import android.support.v7.app.AppCompatActivity +import dagger.Binds +import dagger.Module +import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailActivity +import io.github.droidkaigi.confsched2018.presentation.settings.SettingsActivity + +@Module +interface SettingsActivityModule { + @Binds + fun providesAppCompatActivity(activity: SettingsActivity): AppCompatActivity +} diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/SponsorsActivityBuilder.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/SponsorsActivityBuilder.kt new file mode 100644 index 00000000..505ba690 --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/SponsorsActivityBuilder.kt @@ -0,0 +1,12 @@ +package io.github.droidkaigi.confsched2018.di + +import dagger.Module +import dagger.android.ContributesAndroidInjector +import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailActivity +import io.github.droidkaigi.confsched2018.presentation.sponsors.SponsorsActivity + +@Module abstract class SponsorsActivityBuilder { + @ContributesAndroidInjector(modules = [FragmentBuildersModule::class, SponsorsActivityModule::class]) + abstract fun contributeSponsorsActivity(): SponsorsActivity + +} diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/SponsorsActivityModule.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/SponsorsActivityModule.kt new file mode 100644 index 00000000..f64a8ac4 --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/SponsorsActivityModule.kt @@ -0,0 +1,13 @@ +package io.github.droidkaigi.confsched2018.di + +import android.support.v7.app.AppCompatActivity +import dagger.Binds +import dagger.Module +import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailActivity +import io.github.droidkaigi.confsched2018.presentation.sponsors.SponsorsActivity + +@Module +interface SponsorsActivityModule { + @Binds + fun providesAppCompatActivity(activity: SponsorsActivity): AppCompatActivity +} diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/MainActivity.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/MainActivity.kt index 58795fb6..3d965820 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/MainActivity.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/MainActivity.kt @@ -78,7 +78,17 @@ class MainActivity : AppCompatActivity(), HasSupportFragmentInjector { actionBarDrawerToggle.syncState() binding.drawer.setNavigationItemSelectedListener { item -> when (item.itemId) { + R.id.nav_item_map -> { + navigationController.navigateToMapActivity() + } + R.id.nav_item_setting -> { + navigationController.navigateToSettingsActivity() + } + R.id.nav_item_sponsor -> { + navigationController.navigateToSponsorsActivity() + } R.id.nav_item_info -> { + navigationController.navigateToAboutThisAppActivity() } else -> { } 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 67e97901..260520cc 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 @@ -1,15 +1,24 @@ package io.github.droidkaigi.confsched2018.presentation +import android.support.v4.app.Fragment import android.support.v4.app.FragmentManager import android.support.v7.app.AppCompatActivity import io.github.droidkaigi.confsched2018.R import io.github.droidkaigi.confsched2018.model.Session -import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailFragment +import io.github.droidkaigi.confsched2018.presentation.about.AboutThisAppActivity +import io.github.droidkaigi.confsched2018.presentation.about.AboutThisAppFragment import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailActivity +import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailFragment import io.github.droidkaigi.confsched2018.presentation.favorite.FavoriteSessionsFragment import io.github.droidkaigi.confsched2018.presentation.feed.FeedFragment +import io.github.droidkaigi.confsched2018.presentation.map.MapActivity +import io.github.droidkaigi.confsched2018.presentation.map.MapFragment import io.github.droidkaigi.confsched2018.presentation.search.SearchFragment import io.github.droidkaigi.confsched2018.presentation.sessions.SessionsFragment +import io.github.droidkaigi.confsched2018.presentation.settings.SettingsActivity +import io.github.droidkaigi.confsched2018.presentation.settings.SettingsFragment +import io.github.droidkaigi.confsched2018.presentation.sponsors.SponsorsActivity +import io.github.droidkaigi.confsched2018.presentation.sponsors.SponsorsFragment import javax.inject.Inject class NavigationController @Inject constructor(private val activity: AppCompatActivity) { @@ -17,41 +26,67 @@ class NavigationController @Inject constructor(private val activity: AppCompatAc private val fragmentManager: FragmentManager = activity.supportFragmentManager fun navigateToSessions() { - fragmentManager - .beginTransaction() - .replace(containerId, SessionsFragment.newInstance()) - .commitAllowingStateLoss() + replaceFragment(SessionsFragment.newInstance()) } fun navigateToSearch() { - fragmentManager - .beginTransaction() - .replace(containerId, SearchFragment.newInstance()) - .commitAllowingStateLoss() + replaceFragment(SearchFragment.newInstance()) } fun navigateToFavoriteSessions() { - fragmentManager - .beginTransaction() - .replace(containerId, FavoriteSessionsFragment.newInstance()) - .commitAllowingStateLoss() + replaceFragment(FavoriteSessionsFragment.newInstance()) } fun navigateToFeed() { - fragmentManager - .beginTransaction() - .replace(containerId, FeedFragment.newInstance()) - .commitAllowingStateLoss() + replaceFragment(FeedFragment.newInstance()) } fun navigateToDetail(sessionId: String) { + replaceFragment(SessionDetailFragment.newInstance(sessionId)) + } + + fun navigateToMap() { + replaceFragment(MapFragment.newInstance()) + } + + fun navigateToSponsors() { + replaceFragment(SponsorsFragment.newInstance()) + } + + fun navigateToSettings() { + replaceFragment(SettingsFragment.newInstance()) + } + + fun navigateToAboutThisApp() { + replaceFragment(AboutThisAppFragment.newInstance()) + } + + private fun replaceFragment(fragment: Fragment) { fragmentManager .beginTransaction() - .replace(containerId, SessionDetailFragment.newInstance(sessionId)) + .replace(containerId, fragment) .commitAllowingStateLoss() } - fun navigateToDetailActivity(session: Session) { + + fun navigateToSessionDetailActivity(session: Session) { SessionDetailActivity.start(activity, session) } + + fun navigateToMapActivity() { + MapActivity.start(activity) + } + + fun navigateToSponsorsActivity() { + SponsorsActivity.start(activity) + } + + fun navigateToSettingsActivity() { + SettingsActivity.start(activity) + } + + fun navigateToAboutThisAppActivity() { + AboutThisAppActivity.start(activity) + } + } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/about/AboutThisAppActivity.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/about/AboutThisAppActivity.kt new file mode 100644 index 00000000..ae84a418 --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/about/AboutThisAppActivity.kt @@ -0,0 +1,41 @@ +package io.github.droidkaigi.confsched2018.presentation.about + +import android.content.Context +import android.content.Intent +import android.databinding.DataBindingUtil +import android.os.Bundle +import android.support.v4.app.Fragment +import android.support.v7.app.AppCompatActivity +import dagger.android.AndroidInjector +import dagger.android.DispatchingAndroidInjector +import dagger.android.support.HasSupportFragmentInjector +import io.github.droidkaigi.confsched2018.R +import io.github.droidkaigi.confsched2018.databinding.ActivityAboutThisAppBinding +import io.github.droidkaigi.confsched2018.presentation.NavigationController +import javax.inject.Inject + +class AboutThisAppActivity : AppCompatActivity(), HasSupportFragmentInjector { + @Inject lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector + @Inject lateinit var navigationController: NavigationController + + private val binding: ActivityAboutThisAppBinding by lazy { + DataBindingUtil.setContentView(this, R.layout.activity_about_this_app) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setSupportActionBar(binding.toolbar) + navigationController.navigateToAboutThisApp() + + supportActionBar?.setDisplayHomeAsUpEnabled(true) + } + + override fun supportFragmentInjector(): AndroidInjector = dispatchingAndroidInjector + + companion object { + fun start(context: Context) { + context.startActivity(Intent(context, AboutThisAppActivity::class.java)) + } + } +} diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/about/AboutThisAppFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/about/AboutThisAppFragment.kt new file mode 100644 index 00000000..a904423b --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/about/AboutThisAppFragment.kt @@ -0,0 +1,26 @@ +package io.github.droidkaigi.confsched2018.presentation.about + +import android.arch.lifecycle.ViewModelProvider +import android.os.Bundle +import android.support.v4.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import io.github.droidkaigi.confsched2018.databinding.FragmentAboutThisAppBinding +import io.github.droidkaigi.confsched2018.di.Injectable +import javax.inject.Inject + +class AboutThisAppFragment : Fragment(), Injectable { + private lateinit var binding: FragmentAboutThisAppBinding + @Inject lateinit var viewModelFactory: ViewModelProvider.Factory + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + binding = FragmentAboutThisAppBinding.inflate(inflater, container!!, false) + return binding.root + } + + companion object { + fun newInstance(): AboutThisAppFragment = AboutThisAppFragment() + } +} 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 39fded26..77606f49 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 @@ -94,7 +94,7 @@ class FavoriteSessionsFragment : Fragment(), Injectable { add(sessionsGroup) setOnItemClickListener({ item, _ -> val sessionItem = item as? SessionItem ?: return@setOnItemClickListener - navigationController.navigateToDetailActivity(sessionItem.session) + navigationController.navigateToSessionDetailActivity(sessionItem.session) }) } binding.sessionsRecycler.apply { diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/map/MapActivity.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/map/MapActivity.kt new file mode 100644 index 00000000..2b52ca1d --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/map/MapActivity.kt @@ -0,0 +1,41 @@ +package io.github.droidkaigi.confsched2018.presentation.map + +import android.content.Context +import android.content.Intent +import android.databinding.DataBindingUtil +import android.os.Bundle +import android.support.v4.app.Fragment +import android.support.v7.app.AppCompatActivity +import dagger.android.AndroidInjector +import dagger.android.DispatchingAndroidInjector +import dagger.android.support.HasSupportFragmentInjector +import io.github.droidkaigi.confsched2018.R +import io.github.droidkaigi.confsched2018.databinding.ActivityMapBinding +import io.github.droidkaigi.confsched2018.presentation.NavigationController +import javax.inject.Inject + +class MapActivity : AppCompatActivity(), HasSupportFragmentInjector { + @Inject lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector + @Inject lateinit var navigationController: NavigationController + + private val binding: ActivityMapBinding by lazy { + DataBindingUtil.setContentView(this, R.layout.activity_map) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setSupportActionBar(binding.toolbar) + navigationController.navigateToMap() + + supportActionBar?.setDisplayHomeAsUpEnabled(true) + } + + override fun supportFragmentInjector(): AndroidInjector = dispatchingAndroidInjector + + companion object { + fun start(context: Context) { + context.startActivity(Intent(context, MapActivity::class.java)) + } + } +} diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/map/MapFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/map/MapFragment.kt new file mode 100644 index 00000000..609183c0 --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/map/MapFragment.kt @@ -0,0 +1,26 @@ +package io.github.droidkaigi.confsched2018.presentation.map + +import android.arch.lifecycle.ViewModelProvider +import android.os.Bundle +import android.support.v4.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import io.github.droidkaigi.confsched2018.databinding.FragmentMapBinding +import io.github.droidkaigi.confsched2018.di.Injectable +import javax.inject.Inject + +class MapFragment : Fragment(), Injectable { + private lateinit var binding: FragmentMapBinding + @Inject lateinit var viewModelFactory: ViewModelProvider.Factory + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + binding = FragmentMapBinding.inflate(inflater, container!!, false) + return binding.root + } + + companion object { + fun newInstance(): MapFragment = MapFragment() + } +} diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionFragment.kt index 347bf1b8..b9490b43 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionFragment.kt @@ -77,7 +77,7 @@ class SearchSessionFragment : Fragment(), Injectable { add(sessionsGroup) setOnItemClickListener({ item, _ -> val sessionItem = (item as? HorizontalSessionItem) ?: return@setOnItemClickListener - navigationController.navigateToDetailActivity(sessionItem.session) + navigationController.navigateToSessionDetailActivity(sessionItem.session) }) } 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 c6a9d627..2171c064 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 @@ -96,7 +96,7 @@ class AllSessionsFragment : Fragment(), Injectable { add(sessionsGroup) setOnItemClickListener({ item, _ -> val sessionItem = item as? SessionItem ?: return@setOnItemClickListener - navigationController.navigateToDetailActivity(sessionItem.session) + navigationController.navigateToSessionDetailActivity(sessionItem.session) }) } 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 0c630ef1..6e7b5b77 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 @@ -104,7 +104,7 @@ class RoomSessionsFragment : Fragment(), Injectable { add(sessionsGroup) setOnItemClickListener({ item, _ -> val sessionItem = item as? SessionItem ?: return@setOnItemClickListener - navigationController.navigateToDetailActivity(sessionItem.session) + navigationController.navigateToSessionDetailActivity(sessionItem.session) }) } binding.sessionsRecycler.apply { diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/settings/SettingsActivity.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/settings/SettingsActivity.kt new file mode 100644 index 00000000..d212946f --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/settings/SettingsActivity.kt @@ -0,0 +1,42 @@ +package io.github.droidkaigi.confsched2018.presentation.settings + + +import android.content.Context +import android.content.Intent +import android.databinding.DataBindingUtil +import android.os.Bundle +import android.support.v4.app.Fragment +import android.support.v7.app.AppCompatActivity +import dagger.android.AndroidInjector +import dagger.android.DispatchingAndroidInjector +import dagger.android.support.HasSupportFragmentInjector +import io.github.droidkaigi.confsched2018.R +import io.github.droidkaigi.confsched2018.databinding.ActivitySettingsBinding +import io.github.droidkaigi.confsched2018.presentation.NavigationController +import javax.inject.Inject + +class SettingsActivity : AppCompatActivity(), HasSupportFragmentInjector { + @Inject lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector + @Inject lateinit var navigationController: NavigationController + + private val binding: ActivitySettingsBinding by lazy { + DataBindingUtil.setContentView(this, R.layout.activity_settings) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setSupportActionBar(binding.toolbar) + navigationController.navigateToSettings() + + supportActionBar?.setDisplayHomeAsUpEnabled(true) + } + + override fun supportFragmentInjector(): AndroidInjector = dispatchingAndroidInjector + + companion object { + fun start(context: Context) { + context.startActivity(Intent(context, SettingsActivity::class.java)) + } + } +} diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/settings/SettingsFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/settings/SettingsFragment.kt new file mode 100644 index 00000000..8ccf1b2e --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/settings/SettingsFragment.kt @@ -0,0 +1,26 @@ +package io.github.droidkaigi.confsched2018.presentation.settings + +import android.arch.lifecycle.ViewModelProvider +import android.os.Bundle +import android.support.v4.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import io.github.droidkaigi.confsched2018.databinding.FragmentSettingsBinding +import io.github.droidkaigi.confsched2018.di.Injectable +import javax.inject.Inject + +class SettingsFragment : Fragment(), Injectable { + private lateinit var binding: FragmentSettingsBinding + @Inject lateinit var viewModelFactory: ViewModelProvider.Factory + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + binding = FragmentSettingsBinding.inflate(inflater, container!!, false) + return binding.root + } + + companion object { + fun newInstance(): SettingsFragment = SettingsFragment() + } +} diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sponsors/SponsorsActivity.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sponsors/SponsorsActivity.kt new file mode 100644 index 00000000..ea852670 --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sponsors/SponsorsActivity.kt @@ -0,0 +1,42 @@ +package io.github.droidkaigi.confsched2018.presentation.sponsors + + +import android.content.Context +import android.content.Intent +import android.databinding.DataBindingUtil +import android.os.Bundle +import android.support.v4.app.Fragment +import android.support.v7.app.AppCompatActivity +import dagger.android.AndroidInjector +import dagger.android.DispatchingAndroidInjector +import dagger.android.support.HasSupportFragmentInjector +import io.github.droidkaigi.confsched2018.R +import io.github.droidkaigi.confsched2018.databinding.ActivitySponsorsBinding +import io.github.droidkaigi.confsched2018.presentation.NavigationController +import javax.inject.Inject + +class SponsorsActivity : AppCompatActivity(), HasSupportFragmentInjector { + @Inject lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector + @Inject lateinit var navigationController: NavigationController + + private val binding: ActivitySponsorsBinding by lazy { + DataBindingUtil.setContentView(this, R.layout.activity_sponsors) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setSupportActionBar(binding.toolbar) + navigationController.navigateToSponsors() + + supportActionBar?.setDisplayHomeAsUpEnabled(true) + } + + override fun supportFragmentInjector(): AndroidInjector = dispatchingAndroidInjector + + companion object { + fun start(context: Context) { + context.startActivity(Intent(context, SponsorsActivity::class.java)) + } + } +} diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sponsors/SponsorsFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sponsors/SponsorsFragment.kt new file mode 100644 index 00000000..f4bdd493 --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sponsors/SponsorsFragment.kt @@ -0,0 +1,26 @@ +package io.github.droidkaigi.confsched2018.presentation.sponsors + +import android.arch.lifecycle.ViewModelProvider +import android.os.Bundle +import android.support.v4.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import io.github.droidkaigi.confsched2018.databinding.FragmentSponsorsBinding +import io.github.droidkaigi.confsched2018.di.Injectable +import javax.inject.Inject + +class SponsorsFragment : Fragment(), Injectable { + private lateinit var binding: FragmentSponsorsBinding + @Inject lateinit var viewModelFactory: ViewModelProvider.Factory + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + binding = FragmentSponsorsBinding.inflate(inflater, container!!, false) + return binding.root + } + + companion object { + fun newInstance(): SponsorsFragment = SponsorsFragment() + } +} diff --git a/app/src/main/res/layout/activity_about_this_app.xml b/app/src/main/res/layout/activity_about_this_app.xml new file mode 100644 index 00000000..02923244 --- /dev/null +++ b/app/src/main/res/layout/activity_about_this_app.xml @@ -0,0 +1,35 @@ + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_map.xml b/app/src/main/res/layout/activity_map.xml new file mode 100644 index 00000000..990627fa --- /dev/null +++ b/app/src/main/res/layout/activity_map.xml @@ -0,0 +1,35 @@ + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml new file mode 100644 index 00000000..116bb50c --- /dev/null +++ b/app/src/main/res/layout/activity_settings.xml @@ -0,0 +1,35 @@ + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_sponsors.xml b/app/src/main/res/layout/activity_sponsors.xml new file mode 100644 index 00000000..57e2cef7 --- /dev/null +++ b/app/src/main/res/layout/activity_sponsors.xml @@ -0,0 +1,35 @@ + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_about_this_app.xml b/app/src/main/res/layout/fragment_about_this_app.xml new file mode 100644 index 00000000..d3bac263 --- /dev/null +++ b/app/src/main/res/layout/fragment_about_this_app.xml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/app/src/main/res/layout/fragment_map.xml b/app/src/main/res/layout/fragment_map.xml new file mode 100644 index 00000000..505e4b9b --- /dev/null +++ b/app/src/main/res/layout/fragment_map.xml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml new file mode 100644 index 00000000..c20dc979 --- /dev/null +++ b/app/src/main/res/layout/fragment_settings.xml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/app/src/main/res/layout/fragment_sponsors.xml b/app/src/main/res/layout/fragment_sponsors.xml new file mode 100644 index 00000000..4bcf4d30 --- /dev/null +++ b/app/src/main/res/layout/fragment_sponsors.xml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dc931674..80c92910 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -27,4 +27,16 @@ お知らせ + + + 地図 + + + スポンサー + + + このアプリについて + + + 設定 From 046ed511a3574b7f22300adce75fbb0597b12e77 Mon Sep 17 00:00:00 2001 From: takahirom Date: Fri, 29 Dec 2017 18:24:19 +0900 Subject: [PATCH 3/6] Refactor by own review --- app/build.gradle | 2 -- .../di/AboutThisAppActivityBuilder.kt | 1 - .../di/AboutThisAppActivityModule.kt | 6 ++---- .../confsched2018/di/MainActivityModule.kt | 3 +-- .../confsched2018/di/MapActivityModule.kt | 6 ++---- .../di/SessionDetailActivityModule.kt | 6 ++---- .../confsched2018/di/SettingsActivityModule.kt | 6 ++---- .../confsched2018/di/SponsorsActivityModule.kt | 6 ++---- .../confsched2018/presentation/MainActivity.kt | 18 ++++-------------- .../presentation/about/AboutThisAppActivity.kt | 4 ++-- .../presentation/map/MapActivity.kt | 4 ++-- .../presentation/settings/SettingsActivity.kt | 4 ++-- .../presentation/sponsors/SponsorsActivity.kt | 4 ++-- 13 files changed, 23 insertions(+), 47 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ce4faa5d..d008cd63 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -152,5 +152,3 @@ repositories { } apply plugin: 'com.google.gms.google-services' - - diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/AboutThisAppActivityBuilder.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/AboutThisAppActivityBuilder.kt index 801c8e01..231a7ec4 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/di/AboutThisAppActivityBuilder.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/AboutThisAppActivityBuilder.kt @@ -8,5 +8,4 @@ import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailActiv @Module abstract class AboutThisAppActivityBuilder { @ContributesAndroidInjector(modules = [FragmentBuildersModule::class, AboutThisAppActivityModule::class]) abstract fun contributeAboutThisAppActivity(): AboutThisAppActivity - } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/AboutThisAppActivityModule.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/AboutThisAppActivityModule.kt index 02d8f01e..a5889bfd 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/di/AboutThisAppActivityModule.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/AboutThisAppActivityModule.kt @@ -6,8 +6,6 @@ import dagger.Module import io.github.droidkaigi.confsched2018.presentation.about.AboutThisAppActivity import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailActivity -@Module -interface AboutThisAppActivityModule { - @Binds - fun providesAppCompatActivity(activity: AboutThisAppActivity): AppCompatActivity +@Module interface AboutThisAppActivityModule { + @Binds fun providesAppCompatActivity(activity: AboutThisAppActivity): AppCompatActivity } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/MainActivityModule.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/MainActivityModule.kt index a8932503..ccceacee 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/di/MainActivityModule.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/MainActivityModule.kt @@ -5,7 +5,6 @@ import dagger.Binds import dagger.Module import io.github.droidkaigi.confsched2018.presentation.MainActivity -@Module -interface MainActivityModule { +@Module interface MainActivityModule { @Binds fun providesAppCompatActivity(mainActivity: MainActivity): AppCompatActivity } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/MapActivityModule.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/MapActivityModule.kt index 6a327db4..b6b93ee0 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/di/MapActivityModule.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/MapActivityModule.kt @@ -6,8 +6,6 @@ import dagger.Module import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailActivity import io.github.droidkaigi.confsched2018.presentation.map.MapActivity -@Module -interface MapActivityModule { - @Binds - fun providesAppCompatActivity(activity: MapActivity): AppCompatActivity +@Module interface MapActivityModule { + @Binds fun providesAppCompatActivity(activity: MapActivity): AppCompatActivity } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/SessionDetailActivityModule.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/SessionDetailActivityModule.kt index 54413c97..be424737 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/di/SessionDetailActivityModule.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/SessionDetailActivityModule.kt @@ -5,8 +5,6 @@ import dagger.Binds import dagger.Module import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailActivity -@Module -interface SessionDetailActivityModule { - @Binds - fun providesAppCompatActivity(activity: SessionDetailActivity): AppCompatActivity +@Module interface SessionDetailActivityModule { + @Binds fun providesAppCompatActivity(activity: SessionDetailActivity): AppCompatActivity } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/SettingsActivityModule.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/SettingsActivityModule.kt index 5c3788e2..6c0996fd 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/di/SettingsActivityModule.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/SettingsActivityModule.kt @@ -6,8 +6,6 @@ import dagger.Module import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailActivity import io.github.droidkaigi.confsched2018.presentation.settings.SettingsActivity -@Module -interface SettingsActivityModule { - @Binds - fun providesAppCompatActivity(activity: SettingsActivity): AppCompatActivity +@Module interface SettingsActivityModule { + @Binds fun providesAppCompatActivity(activity: SettingsActivity): AppCompatActivity } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/SponsorsActivityModule.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/SponsorsActivityModule.kt index f64a8ac4..7983db0f 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/di/SponsorsActivityModule.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/SponsorsActivityModule.kt @@ -6,8 +6,6 @@ import dagger.Module import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailActivity import io.github.droidkaigi.confsched2018.presentation.sponsors.SponsorsActivity -@Module -interface SponsorsActivityModule { - @Binds - fun providesAppCompatActivity(activity: SponsorsActivity): AppCompatActivity +@Module interface SponsorsActivityModule { + @Binds fun providesAppCompatActivity(activity: SponsorsActivity): AppCompatActivity } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/MainActivity.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/MainActivity.kt index 3d965820..2988b624 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/MainActivity.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/MainActivity.kt @@ -78,20 +78,10 @@ class MainActivity : AppCompatActivity(), HasSupportFragmentInjector { actionBarDrawerToggle.syncState() binding.drawer.setNavigationItemSelectedListener { item -> when (item.itemId) { - R.id.nav_item_map -> { - navigationController.navigateToMapActivity() - } - R.id.nav_item_setting -> { - navigationController.navigateToSettingsActivity() - } - R.id.nav_item_sponsor -> { - navigationController.navigateToSponsorsActivity() - } - R.id.nav_item_info -> { - navigationController.navigateToAboutThisAppActivity() - } - else -> { - } + R.id.nav_item_map -> navigationController.navigateToMapActivity() + R.id.nav_item_setting -> navigationController.navigateToSettingsActivity() + R.id.nav_item_sponsor -> navigationController.navigateToSponsorsActivity() + R.id.nav_item_info -> navigationController.navigateToAboutThisAppActivity() } true } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/about/AboutThisAppActivity.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/about/AboutThisAppActivity.kt index ae84a418..4b3dbff3 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/about/AboutThisAppActivity.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/about/AboutThisAppActivity.kt @@ -26,9 +26,9 @@ class AboutThisAppActivity : AppCompatActivity(), HasSupportFragmentInjector { super.onCreate(savedInstanceState) setSupportActionBar(binding.toolbar) - navigationController.navigateToAboutThisApp() - supportActionBar?.setDisplayHomeAsUpEnabled(true) + + navigationController.navigateToAboutThisApp() } override fun supportFragmentInjector(): AndroidInjector = dispatchingAndroidInjector diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/map/MapActivity.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/map/MapActivity.kt index 2b52ca1d..4b933304 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/map/MapActivity.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/map/MapActivity.kt @@ -26,9 +26,9 @@ class MapActivity : AppCompatActivity(), HasSupportFragmentInjector { super.onCreate(savedInstanceState) setSupportActionBar(binding.toolbar) - navigationController.navigateToMap() - supportActionBar?.setDisplayHomeAsUpEnabled(true) + + navigationController.navigateToMap() } override fun supportFragmentInjector(): AndroidInjector = dispatchingAndroidInjector diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/settings/SettingsActivity.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/settings/SettingsActivity.kt index d212946f..e4ec3be9 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/settings/SettingsActivity.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/settings/SettingsActivity.kt @@ -27,9 +27,9 @@ class SettingsActivity : AppCompatActivity(), HasSupportFragmentInjector { super.onCreate(savedInstanceState) setSupportActionBar(binding.toolbar) - navigationController.navigateToSettings() - supportActionBar?.setDisplayHomeAsUpEnabled(true) + + navigationController.navigateToSettings() } override fun supportFragmentInjector(): AndroidInjector = dispatchingAndroidInjector diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sponsors/SponsorsActivity.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sponsors/SponsorsActivity.kt index ea852670..6e2707e3 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sponsors/SponsorsActivity.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/sponsors/SponsorsActivity.kt @@ -27,9 +27,9 @@ class SponsorsActivity : AppCompatActivity(), HasSupportFragmentInjector { super.onCreate(savedInstanceState) setSupportActionBar(binding.toolbar) - navigationController.navigateToSponsors() - supportActionBar?.setDisplayHomeAsUpEnabled(true) + + navigationController.navigateToSponsors() } override fun supportFragmentInjector(): AndroidInjector = dispatchingAndroidInjector From c9daa72cb1e2f193d292647b37230892053a103d Mon Sep 17 00:00:00 2001 From: takahirom Date: Fri, 29 Dec 2017 19:06:21 +0900 Subject: [PATCH 4/6] Add empty fragments for topics and speakers --- .../di/FragmentBuildersModule.kt | 10 ++- .../confsched2018/di/ViewModelModule.kt | 17 ++++- .../presentation/search/SearchFragment.kt | 9 +-- ...nFragment.kt => SearchSessionsFragment.kt} | 25 +++---- ...iewModel.kt => SearchSessionsViewModel.kt} | 2 +- .../search/SearchSpeakersFragment.kt | 73 +++++++++++++++++++ .../search/SearchSpeakersViewModel.kt | 38 ++++++++++ .../search/SearchTopicsFragment.kt | 73 +++++++++++++++++++ .../search/SearchTopicsViewModel.kt | 38 ++++++++++ ...ssion.xml => fragment_search_sessions.xml} | 0 .../res/layout/fragment_search_speakers.xml | 27 +++++++ .../res/layout/fragment_search_topics.xml | 27 +++++++ app/src/main/res/values/strings.xml | 4 +- 13 files changed, 315 insertions(+), 28 deletions(-) rename app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/{SearchSessionFragment.kt => SearchSessionsFragment.kt} (81%) rename app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/{SearchSessionViewModel.kt => SearchSessionsViewModel.kt} (97%) create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSpeakersFragment.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSpeakersViewModel.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchTopicsFragment.kt create mode 100644 app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchTopicsViewModel.kt rename app/src/main/res/layout/{fragment_search_session.xml => fragment_search_sessions.xml} (100%) create mode 100644 app/src/main/res/layout/fragment_search_speakers.xml create mode 100644 app/src/main/res/layout/fragment_search_topics.xml diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/FragmentBuildersModule.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/FragmentBuildersModule.kt index 395ded30..6418e29e 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/di/FragmentBuildersModule.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/FragmentBuildersModule.kt @@ -8,7 +8,9 @@ import io.github.droidkaigi.confsched2018.presentation.favorite.FavoriteSessions import io.github.droidkaigi.confsched2018.presentation.feed.FeedFragment import io.github.droidkaigi.confsched2018.presentation.map.MapFragment import io.github.droidkaigi.confsched2018.presentation.search.SearchFragment -import io.github.droidkaigi.confsched2018.presentation.search.SearchSessionFragment +import io.github.droidkaigi.confsched2018.presentation.search.SearchSessionsFragment +import io.github.droidkaigi.confsched2018.presentation.search.SearchSpeakersFragment +import io.github.droidkaigi.confsched2018.presentation.search.SearchTopicsFragment import io.github.droidkaigi.confsched2018.presentation.sessions.AllSessionsFragment import io.github.droidkaigi.confsched2018.presentation.sessions.RoomSessionsFragment import io.github.droidkaigi.confsched2018.presentation.sessions.SessionsFragment @@ -24,7 +26,11 @@ import io.github.droidkaigi.confsched2018.presentation.sponsors.SponsorsFragment @ContributesAndroidInjector abstract fun contributeSearchFragment(): SearchFragment - @ContributesAndroidInjector abstract fun contributeSearchSessionFragment(): SearchSessionFragment + @ContributesAndroidInjector abstract fun contributeSearchSessionsFragment(): SearchSessionsFragment + + @ContributesAndroidInjector abstract fun contributeSearchTopicsFragment(): SearchTopicsFragment + + @ContributesAndroidInjector abstract fun contributeSearchSpeakersFragment(): SearchSpeakersFragment @ContributesAndroidInjector abstract fun contributeFavoriteSessionsFragment(): FavoriteSessionsFragment diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/di/ViewModelModule.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/di/ViewModelModule.kt index 5d9d7b80..ec6584d3 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/di/ViewModelModule.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/di/ViewModelModule.kt @@ -8,7 +8,9 @@ import dagger.multibindings.IntoMap import io.github.droidkaigi.confsched2018.presentation.detail.SessionDetailViewModel import io.github.droidkaigi.confsched2018.presentation.favorite.FavoriteSessionsViewModel import io.github.droidkaigi.confsched2018.presentation.feed.FeedViewModel -import io.github.droidkaigi.confsched2018.presentation.search.SearchSessionViewModel +import io.github.droidkaigi.confsched2018.presentation.search.SearchSessionsViewModel +import io.github.droidkaigi.confsched2018.presentation.search.SearchSpeakersViewModel +import io.github.droidkaigi.confsched2018.presentation.search.SearchTopicsViewModel import io.github.droidkaigi.confsched2018.presentation.search.SearchViewModel import io.github.droidkaigi.confsched2018.presentation.sessions.AllSessionsViewModel import io.github.droidkaigi.confsched2018.presentation.sessions.RoomSessionsViewModel @@ -32,8 +34,8 @@ import io.github.droidkaigi.confsched2018.presentation.sessions.SessionsViewMode abstract fun bindRoomSessionsViewModel(roomSessionsViewModel: RoomSessionsViewModel): ViewModel @Binds @IntoMap - @ViewModelKey(SearchSessionViewModel::class) - abstract fun bindSearchSessionViewModel(searchSessionViewModel: SearchSessionViewModel): ViewModel + @ViewModelKey(SearchSessionsViewModel::class) + abstract fun bindSearchSessionViewModel(searchSessionsViewModel: SearchSessionsViewModel): ViewModel @Binds @IntoMap @@ -48,5 +50,14 @@ import io.github.droidkaigi.confsched2018.presentation.sessions.SessionsViewMode @ViewModelKey(SessionDetailViewModel::class) abstract fun bindSessionDetailViewModel(sessionDetailViewModel: SessionDetailViewModel): ViewModel + @Binds @IntoMap + @ViewModelKey(SearchTopicsViewModel::class) + abstract fun bindSearchTopicsViewModel(sessionDetailViewModel: SearchTopicsViewModel): ViewModel + + @Binds @IntoMap + @ViewModelKey(SearchSpeakersViewModel::class) + abstract fun bindSearchSpeakersViewModel(sessionDetailViewModel: SearchSpeakersViewModel): ViewModel + + @Binds abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchFragment.kt index f3c01799..b0559b38 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchFragment.kt @@ -23,7 +23,6 @@ import io.github.droidkaigi.confsched2018.databinding.FragmentSearchBinding import io.github.droidkaigi.confsched2018.di.Injectable import io.github.droidkaigi.confsched2018.model.Session import io.github.droidkaigi.confsched2018.presentation.Result -import io.github.droidkaigi.confsched2018.presentation.sessions.AllSessionsFragment import io.github.droidkaigi.confsched2018.presentation.sessions.item.DateSessionsGroup import io.github.droidkaigi.confsched2018.util.ext.* import timber.log.Timber @@ -163,7 +162,7 @@ class SearchBeforeViewPagerAdapter(val context: Context, fragmentManager: Fragme enum class Tab(@StringRes val title: Int) { Session(R.string.search_before_tab_session), Topic(R.string.search_before_tab_topic), - User(R.string.search_before_tab_user); + Speakers(R.string.search_before_tab_speaker); } override fun getPageTitle(position: Int): CharSequence = context.getString(Tab.values()[position].title) @@ -171,9 +170,9 @@ class SearchBeforeViewPagerAdapter(val context: Context, fragmentManager: Fragme override fun getItem(position: Int): Fragment { val tab = Tab.values()[position] return when (tab) { - Tab.Session -> SearchSessionFragment.newInstance() - Tab.Topic -> AllSessionsFragment.newInstance() - Tab.User -> AllSessionsFragment.newInstance() + Tab.Session -> SearchSessionsFragment.newInstance() + Tab.Topic -> SearchTopicsFragment.newInstance() + Tab.Speakers -> SearchSpeakersFragment.newInstance() } } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionsFragment.kt similarity index 81% rename from app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionFragment.kt rename to app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionsFragment.kt index b9490b43..734d1a23 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionsFragment.kt @@ -9,7 +9,7 @@ import android.view.View import android.view.ViewGroup import com.xwray.groupie.GroupAdapter import com.xwray.groupie.ViewHolder -import io.github.droidkaigi.confsched2018.databinding.FragmentSearchSessionBinding +import io.github.droidkaigi.confsched2018.databinding.FragmentSearchSessionsBinding import io.github.droidkaigi.confsched2018.di.Injectable import io.github.droidkaigi.confsched2018.model.Session import io.github.droidkaigi.confsched2018.presentation.NavigationController @@ -20,15 +20,15 @@ import io.github.droidkaigi.confsched2018.util.ext.observe import timber.log.Timber import javax.inject.Inject -class SearchSessionFragment : Fragment(), Injectable { - private lateinit var binding: FragmentSearchSessionBinding +class SearchSessionsFragment : Fragment(), Injectable { + private lateinit var binding: FragmentSearchSessionsBinding @Inject lateinit var viewModelFactory: ViewModelProvider.Factory private val sessionsGroup = LevelSessionsGroup(this) @Inject lateinit var navigationController: NavigationController - private val searchSessionViewModel: SearchSessionViewModel by lazy { - ViewModelProviders.of(this, viewModelFactory).get(SearchSessionViewModel::class.java) + private val searchSessionsViewModel: SearchSessionsViewModel by lazy { + ViewModelProviders.of(this, viewModelFactory).get(SearchSessionsViewModel::class.java) } private val onFavoriteClickListener = { session: Session -> @@ -36,7 +36,7 @@ class SearchSessionFragment : Fragment(), Injectable { session.isFavorited = !session.isFavorited binding.searchSessionRecycler.adapter.notifyDataSetChanged() - searchSessionViewModel.onFavoriteClick(session) + searchSessionsViewModel.onFavoriteClick(session) } override fun onCreate(savedInstanceState: Bundle?) { @@ -46,19 +46,14 @@ class SearchSessionFragment : Fragment(), Injectable { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - binding = FragmentSearchSessionBinding.inflate(layoutInflater, container, false) + binding = FragmentSearchSessionsBinding.inflate(layoutInflater, container, false) return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - - setupSearch() - } - - private fun setupSearch() { setupRecyclerView() - searchSessionViewModel.levelSessions.observe(this, { result -> + searchSessionsViewModel.levelSessions.observe(this, { result -> when (result) { is Result.Success -> { val levelSessions = result.data @@ -69,7 +64,7 @@ class SearchSessionFragment : Fragment(), Injectable { } } }) - lifecycle.addObserver(searchSessionViewModel) + lifecycle.addObserver(searchSessionsViewModel) } private fun setupRecyclerView() { @@ -87,7 +82,7 @@ class SearchSessionFragment : Fragment(), Injectable { } companion object { - fun newInstance(): SearchSessionFragment = SearchSessionFragment() + fun newInstance(): SearchSessionsFragment = SearchSessionsFragment() } } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionViewModel.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionsViewModel.kt similarity index 97% rename from app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionViewModel.kt rename to app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionsViewModel.kt index d3bc92c9..02552741 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionViewModel.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSessionsViewModel.kt @@ -17,7 +17,7 @@ import io.reactivex.rxkotlin.addTo import io.reactivex.rxkotlin.subscribeBy import javax.inject.Inject -class SearchSessionViewModel @Inject constructor( +class SearchSessionsViewModel @Inject constructor( private val repository: SessionRepository, private val schedulerProvider: SchedulerProvider ) : ViewModel(), LifecycleObserver { diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSpeakersFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSpeakersFragment.kt new file mode 100644 index 00000000..676b4a8b --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSpeakersFragment.kt @@ -0,0 +1,73 @@ +package io.github.droidkaigi.confsched2018.presentation.search + +import android.arch.lifecycle.ViewModelProvider +import android.arch.lifecycle.ViewModelProviders +import android.os.Bundle +import android.support.v4.app.Fragment +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.databinding.FragmentSearchSpeakersBinding +import io.github.droidkaigi.confsched2018.di.Injectable +import io.github.droidkaigi.confsched2018.model.Session +import io.github.droidkaigi.confsched2018.presentation.NavigationController +import io.github.droidkaigi.confsched2018.presentation.search.item.HorizontalSessionItem +import javax.inject.Inject + +class SearchSpeakersFragment : Fragment(), Injectable { + private lateinit var binding: FragmentSearchSpeakersBinding + @Inject lateinit var viewModelFactory: ViewModelProvider.Factory + + @Inject lateinit var navigationController: NavigationController + private val searchTopicsViewModel: SearchTopicsViewModel by lazy { + ViewModelProviders.of(this, viewModelFactory).get(SearchTopicsViewModel::class.java) + } + + private val onFavoriteClickListener = { session: Session -> + // Since it takes time to change the favorite state, change only the state of View first + session.isFavorited = !session.isFavorited + binding.searchSessionRecycler.adapter.notifyDataSetChanged() + + searchTopicsViewModel.onFavoriteClick(session) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setHasOptionsMenu(true) + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + binding = FragmentSearchSpeakersBinding.inflate(layoutInflater, container, false) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setupRecyclerView() + // TODO: searchTopicsViewModel.sessions fetch data here + lifecycle.addObserver(searchTopicsViewModel) + } + + private fun setupRecyclerView() { + val groupAdapter = GroupAdapter().apply { + // TODO: Add group +// add(sessionsGroup) + setOnItemClickListener({ item, _ -> + val sessionItem = (item as? HorizontalSessionItem) ?: return@setOnItemClickListener + navigationController.navigateToSessionDetailActivity(sessionItem.session) + }) + } + binding.searchSessionRecycler.apply { + adapter = groupAdapter + } + + } + + companion object { + fun newInstance(): SearchSpeakersFragment = SearchSpeakersFragment() + } +} + diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSpeakersViewModel.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSpeakersViewModel.kt new file mode 100644 index 00000000..03a02aba --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSpeakersViewModel.kt @@ -0,0 +1,38 @@ +package io.github.droidkaigi.confsched2018.presentation.search + +import android.arch.lifecycle.LifecycleObserver +import android.arch.lifecycle.LiveData +import android.arch.lifecycle.ViewModel +import io.github.droidkaigi.confsched2018.data.repository.SessionRepository +import io.github.droidkaigi.confsched2018.model.Session +import io.github.droidkaigi.confsched2018.model.Topic +import io.github.droidkaigi.confsched2018.presentation.Result +import io.github.droidkaigi.confsched2018.util.defaultErrorHandler +import io.github.droidkaigi.confsched2018.util.rx.SchedulerProvider +import io.reactivex.Single +import io.reactivex.disposables.CompositeDisposable +import io.reactivex.rxkotlin.addTo +import io.reactivex.rxkotlin.subscribeBy +import javax.inject.Inject + +class SearchSpeakersViewModel @Inject constructor( + private val repository: SessionRepository, + private val schedulerProvider: SchedulerProvider +) : ViewModel(), LifecycleObserver { + val sessions: LiveData>>> by lazy { + TODO() + } + private val compositeDisposable: CompositeDisposable = CompositeDisposable() + + fun onFavoriteClick(session: Session) { + val favoriteSingle: Single = repository.favorite(session) + favoriteSingle + .subscribeBy(onError = defaultErrorHandler()) + .addTo(compositeDisposable) + } + + override fun onCleared() { + super.onCleared() + compositeDisposable.clear() + } +} diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchTopicsFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchTopicsFragment.kt new file mode 100644 index 00000000..5e9ee72f --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchTopicsFragment.kt @@ -0,0 +1,73 @@ +package io.github.droidkaigi.confsched2018.presentation.search + +import android.arch.lifecycle.ViewModelProvider +import android.arch.lifecycle.ViewModelProviders +import android.os.Bundle +import android.support.v4.app.Fragment +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.databinding.FragmentSearchTopicsBinding +import io.github.droidkaigi.confsched2018.di.Injectable +import io.github.droidkaigi.confsched2018.model.Session +import io.github.droidkaigi.confsched2018.presentation.NavigationController +import io.github.droidkaigi.confsched2018.presentation.search.item.HorizontalSessionItem +import javax.inject.Inject + +class SearchTopicsFragment : Fragment(), Injectable { + private lateinit var binding: FragmentSearchTopicsBinding + @Inject lateinit var viewModelFactory: ViewModelProvider.Factory + + @Inject lateinit var navigationController: NavigationController + private val searchTopicsViewModel: SearchTopicsViewModel by lazy { + ViewModelProviders.of(this, viewModelFactory).get(SearchTopicsViewModel::class.java) + } + + private val onFavoriteClickListener = { session: Session -> + // Since it takes time to change the favorite state, change only the state of View first + session.isFavorited = !session.isFavorited + binding.searchSessionRecycler.adapter.notifyDataSetChanged() + + searchTopicsViewModel.onFavoriteClick(session) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setHasOptionsMenu(true) + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + binding = FragmentSearchTopicsBinding.inflate(layoutInflater, container, false) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setupRecyclerView() + // TODO: searchTopicsViewModel.sessions fetch data here + lifecycle.addObserver(searchTopicsViewModel) + } + + private fun setupRecyclerView() { + val groupAdapter = GroupAdapter().apply { + // TODO: Add group +// add(sessionsGroup) + setOnItemClickListener({ item, _ -> + val sessionItem = (item as? HorizontalSessionItem) ?: return@setOnItemClickListener + navigationController.navigateToSessionDetailActivity(sessionItem.session) + }) + } + binding.searchSessionRecycler.apply { + adapter = groupAdapter + } + + } + + companion object { + fun newInstance(): SearchTopicsFragment = SearchTopicsFragment() + } +} + diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchTopicsViewModel.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchTopicsViewModel.kt new file mode 100644 index 00000000..9ab0caaa --- /dev/null +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchTopicsViewModel.kt @@ -0,0 +1,38 @@ +package io.github.droidkaigi.confsched2018.presentation.search + +import android.arch.lifecycle.LifecycleObserver +import android.arch.lifecycle.LiveData +import android.arch.lifecycle.ViewModel +import io.github.droidkaigi.confsched2018.data.repository.SessionRepository +import io.github.droidkaigi.confsched2018.model.Session +import io.github.droidkaigi.confsched2018.model.Topic +import io.github.droidkaigi.confsched2018.presentation.Result +import io.github.droidkaigi.confsched2018.util.defaultErrorHandler +import io.github.droidkaigi.confsched2018.util.rx.SchedulerProvider +import io.reactivex.Single +import io.reactivex.disposables.CompositeDisposable +import io.reactivex.rxkotlin.addTo +import io.reactivex.rxkotlin.subscribeBy +import javax.inject.Inject + +class SearchTopicsViewModel @Inject constructor( + private val repository: SessionRepository, + private val schedulerProvider: SchedulerProvider +) : ViewModel(), LifecycleObserver { + val sessions: LiveData>>> by lazy { + TODO() + } + private val compositeDisposable: CompositeDisposable = CompositeDisposable() + + fun onFavoriteClick(session: Session) { + val favoriteSingle: Single = repository.favorite(session) + favoriteSingle + .subscribeBy(onError = defaultErrorHandler()) + .addTo(compositeDisposable) + } + + override fun onCleared() { + super.onCleared() + compositeDisposable.clear() + } +} diff --git a/app/src/main/res/layout/fragment_search_session.xml b/app/src/main/res/layout/fragment_search_sessions.xml similarity index 100% rename from app/src/main/res/layout/fragment_search_session.xml rename to app/src/main/res/layout/fragment_search_sessions.xml diff --git a/app/src/main/res/layout/fragment_search_speakers.xml b/app/src/main/res/layout/fragment_search_speakers.xml new file mode 100644 index 00000000..2f4a7f58 --- /dev/null +++ b/app/src/main/res/layout/fragment_search_speakers.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_search_topics.xml b/app/src/main/res/layout/fragment_search_topics.xml new file mode 100644 index 00000000..2f4a7f58 --- /dev/null +++ b/app/src/main/res/layout/fragment_search_topics.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 80c92910..fc5f6578 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -19,8 +19,8 @@ 検索 セッション トピック - ユーザー - expand button + スピーカー + Expand button マイセッション From e3581eaceb3f1080c843eb8a2dcc1b1a64e42f12 Mon Sep 17 00:00:00 2001 From: takahirom Date: Fri, 29 Dec 2017 19:24:43 +0900 Subject: [PATCH 5/6] Delete unnecessary codes and refactor small things --- .../search/SearchSpeakersFragment.kt | 21 +++---------------- .../search/SearchSpeakersViewModel.kt | 2 +- .../search/SearchTopicsFragment.kt | 8 +------ app/src/main/res/values/strings.xml | 2 +- 4 files changed, 6 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSpeakersFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSpeakersFragment.kt index 676b4a8b..2427a0bd 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSpeakersFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSpeakersFragment.kt @@ -11,9 +11,7 @@ import com.xwray.groupie.GroupAdapter import com.xwray.groupie.ViewHolder import io.github.droidkaigi.confsched2018.databinding.FragmentSearchSpeakersBinding import io.github.droidkaigi.confsched2018.di.Injectable -import io.github.droidkaigi.confsched2018.model.Session import io.github.droidkaigi.confsched2018.presentation.NavigationController -import io.github.droidkaigi.confsched2018.presentation.search.item.HorizontalSessionItem import javax.inject.Inject class SearchSpeakersFragment : Fragment(), Injectable { @@ -25,14 +23,6 @@ class SearchSpeakersFragment : Fragment(), Injectable { ViewModelProviders.of(this, viewModelFactory).get(SearchTopicsViewModel::class.java) } - private val onFavoriteClickListener = { session: Session -> - // Since it takes time to change the favorite state, change only the state of View first - session.isFavorited = !session.isFavorited - binding.searchSessionRecycler.adapter.notifyDataSetChanged() - - searchTopicsViewModel.onFavoriteClick(session) - } - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setHasOptionsMenu(true) @@ -47,23 +37,18 @@ class SearchSpeakersFragment : Fragment(), Injectable { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setupRecyclerView() - // TODO: searchTopicsViewModel.sessions fetch data here + // TODO: searchTopicsViewModel.speakers fetch data here lifecycle.addObserver(searchTopicsViewModel) } private fun setupRecyclerView() { val groupAdapter = GroupAdapter().apply { - // TODO: Add group -// add(sessionsGroup) - setOnItemClickListener({ item, _ -> - val sessionItem = (item as? HorizontalSessionItem) ?: return@setOnItemClickListener - navigationController.navigateToSessionDetailActivity(sessionItem.session) - }) + // TODO: Add group and click listener +// add(speakersGroup) } binding.searchSessionRecycler.apply { adapter = groupAdapter } - } companion object { diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSpeakersViewModel.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSpeakersViewModel.kt index 03a02aba..e6610730 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSpeakersViewModel.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchSpeakersViewModel.kt @@ -19,7 +19,7 @@ class SearchSpeakersViewModel @Inject constructor( private val repository: SessionRepository, private val schedulerProvider: SchedulerProvider ) : ViewModel(), LifecycleObserver { - val sessions: LiveData>>> by lazy { + val speakers: LiveData>>> by lazy { TODO() } private val compositeDisposable: CompositeDisposable = CompositeDisposable() diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchTopicsFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchTopicsFragment.kt index 5e9ee72f..2a1112be 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchTopicsFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchTopicsFragment.kt @@ -13,7 +13,6 @@ import io.github.droidkaigi.confsched2018.databinding.FragmentSearchTopicsBindin import io.github.droidkaigi.confsched2018.di.Injectable import io.github.droidkaigi.confsched2018.model.Session import io.github.droidkaigi.confsched2018.presentation.NavigationController -import io.github.droidkaigi.confsched2018.presentation.search.item.HorizontalSessionItem import javax.inject.Inject class SearchTopicsFragment : Fragment(), Injectable { @@ -53,17 +52,12 @@ class SearchTopicsFragment : Fragment(), Injectable { private fun setupRecyclerView() { val groupAdapter = GroupAdapter().apply { - // TODO: Add group + // TODO: Add group and click listener // add(sessionsGroup) - setOnItemClickListener({ item, _ -> - val sessionItem = (item as? HorizontalSessionItem) ?: return@setOnItemClickListener - navigationController.navigateToSessionDetailActivity(sessionItem.session) - }) } binding.searchSessionRecycler.apply { adapter = groupAdapter } - } companion object { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fc5f6578..2917b9b1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,7 +3,7 @@ %1$s - %2$s - 会場マップ + 地図 スポンサー このアプリについて 設定 From 65949f1b70eaa6970e45cd196c362923c982073e Mon Sep 17 00:00:00 2001 From: takahirom Date: Fri, 29 Dec 2017 23:25:27 +0900 Subject: [PATCH 6/6] Refactor around search --- .../data/repository/SessionDataRepository.kt | 14 ++- .../data/repository/SessionRepository.kt | 1 + .../common/mapper/ResultMapperExt.kt | 7 +- .../presentation/search/SearchFragment.kt | 4 +- .../search/SearchTopicsFragment.kt | 2 +- .../presentation/search/SearchViewModel.kt | 19 +--- .../confsched2018/DummyDataCreator.kt | 104 ++++++++++++++---- .../repository/SessionsDataRepositoryTest.kt | 63 +++++------ .../detail/SessionDetailViewModelTest.kt | 6 +- .../search/SearchViewModelTest.kt | 82 ++++++++++++++ common-jvm/src/main/kotlin/JvmDate.kt | 4 + common/src/main/kotlin/SearchResult.kt | 6 + 12 files changed, 226 insertions(+), 86 deletions(-) create mode 100644 app/src/test/java/io/github/droidkaigi/confsched2018/presentation/search/SearchViewModelTest.kt create mode 100644 common/src/main/kotlin/SearchResult.kt diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/data/repository/SessionDataRepository.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/data/repository/SessionDataRepository.kt index 8b3d8008..cec1fba3 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/data/repository/SessionDataRepository.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/data/repository/SessionDataRepository.kt @@ -12,6 +12,7 @@ import io.reactivex.Completable import io.reactivex.Flowable import io.reactivex.Single import io.reactivex.rxkotlin.Flowables +import io.reactivex.rxkotlin.Singles import timber.log.Timber import javax.inject.Inject @@ -47,8 +48,8 @@ class SessionDataRepository @Inject constructor( override val speakers: Flowable> = sessionDatabase.getAllSpeaker() .map { speakers -> - speakers.map { speaker -> speaker.toSpeaker() } - } + speakers.map { speaker -> speaker.toSpeaker() } + } override val roomSessions: Flowable>> = sessions.map { sessionList -> sessionList.groupBy { it.room } } @@ -70,6 +71,15 @@ class SessionDataRepository @Inject constructor( .toCompletable() } + override fun search(query: String): Single = Singles.zip( + sessions.map { + it.filter { it.title.contains(query) || it.desc.contains(query) } + }.firstOrError(), + speakers.map { + it.filter { it.name.contains(query) } + }.firstOrError(), + { sessions: List, speakers: List -> SearchResult(sessions, speakers) }) + companion object { const val DEBUG = false } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/data/repository/SessionRepository.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/data/repository/SessionRepository.kt index 1dded07e..5cdaaf07 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/data/repository/SessionRepository.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/data/repository/SessionRepository.kt @@ -16,5 +16,6 @@ interface SessionRepository { @CheckResult fun refreshSessions(): Completable @CheckResult fun favorite(session: Session): Single + @CheckResult fun search(query: String): Single } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/common/mapper/ResultMapperExt.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/common/mapper/ResultMapperExt.kt index efd09141..79da42c5 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/common/mapper/ResultMapperExt.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/common/mapper/ResultMapperExt.kt @@ -25,9 +25,4 @@ fun Observable.toResult(schedulerProvider: SchedulerProvider): Observable } fun Single.toResult(schedulerProvider: SchedulerProvider): Observable> = - compose { item -> - item - .map { Result.success(it) } - .onErrorReturn { e -> Result.failure(e.message ?: "unknown", e) } - .observeOn(schedulerProvider.ui()) - }.toObservable().startWith(Result.inProgress()) + toObservable().toResult(schedulerProvider) diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchFragment.kt index b0559b38..e01aa3ff 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchFragment.kt @@ -71,10 +71,10 @@ class SearchFragment : Fragment(), Injectable { private fun setupSearch() { setupRecyclerView() - searchViewModel.sessions.observe(this, { result -> + searchViewModel.result.observe(this, { result -> when (result) { is Result.Success -> { - val sessions = result.data + val sessions = result.data.sessions sessionsGroup.updateSessions(sessions, onFavoriteClickListener) binding.sessionsRecycler.scrollToPosition(0) } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchTopicsFragment.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchTopicsFragment.kt index 2a1112be..66f26d6f 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchTopicsFragment.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchTopicsFragment.kt @@ -46,7 +46,7 @@ class SearchTopicsFragment : Fragment(), Injectable { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setupRecyclerView() - // TODO: searchTopicsViewModel.sessions fetch data here + // TODO: searchTopicsViewModel.result fetch data here lifecycle.addObserver(searchTopicsViewModel) } diff --git a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchViewModel.kt b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchViewModel.kt index 78740ed3..95f9a0e3 100644 --- a/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchViewModel.kt +++ b/app/src/main/java/io/github/droidkaigi/confsched2018/presentation/search/SearchViewModel.kt @@ -4,8 +4,8 @@ import android.arch.lifecycle.LifecycleObserver import android.arch.lifecycle.MutableLiveData import android.arch.lifecycle.ViewModel import io.github.droidkaigi.confsched2018.data.repository.SessionRepository +import io.github.droidkaigi.confsched2018.model.SearchResult import io.github.droidkaigi.confsched2018.model.Session -import io.github.droidkaigi.confsched2018.model.Speaker import io.github.droidkaigi.confsched2018.presentation.Result import io.github.droidkaigi.confsched2018.presentation.common.mapper.toResult import io.github.droidkaigi.confsched2018.util.defaultErrorHandler @@ -20,24 +20,15 @@ class SearchViewModel @Inject constructor( private val repository: SessionRepository, private val schedulerProvider: SchedulerProvider ) : ViewModel(), LifecycleObserver { - val sessions: MutableLiveData>> = MutableLiveData() - val speakers: MutableLiveData>> = MutableLiveData() + val result: MutableLiveData> = MutableLiveData() private val compositeDisposable: CompositeDisposable = CompositeDisposable() fun onQuery(query: String) { - repository.sessions - .map { - it.filter { it.title.contains(query) || it.desc.contains(query) } - } + repository.search(query) .toResult(schedulerProvider) - .subscribe { sessions.value = it } - .addTo(compositeDisposable) - repository.speakers - .map { - it.filter { it.name.contains(query) } + .subscribe { + result.value = it } - .toResult(schedulerProvider) - .subscribe { speakers.value = it } .addTo(compositeDisposable) } diff --git a/app/src/test/java/io/github/droidkaigi/confsched2018/DummyDataCreator.kt b/app/src/test/java/io/github/droidkaigi/confsched2018/DummyDataCreator.kt index 3f86212c..3825e599 100644 --- a/app/src/test/java/io/github/droidkaigi/confsched2018/DummyDataCreator.kt +++ b/app/src/test/java/io/github/droidkaigi/confsched2018/DummyDataCreator.kt @@ -1,32 +1,41 @@ package io.github.droidkaigi.confsched2018 +import io.github.droidkaigi.confsched2018.data.db.entity.* import io.github.droidkaigi.confsched2018.model.* +import org.threeten.bp.LocalDateTime -val DUMMY_SESSION_ID_1 = "test1" -val DUMMY_SESSION_ID_2 = "test2" +const val DUMMY_SESSION_ID1 = "test1" +const val DUMMY_SESSION_ID2 = "test2" +const val DUMMY_SESSION_TITLE1 = "DroidKaigi" +const val DUMMY_SESSION_TITLE2 = "RejectKaigi" fun createDummySessions(): List = - listOf(createDummySession(DUMMY_SESSION_ID_1), createDummySession(DUMMY_SESSION_ID_2)) - -fun createDummySession(sessionId: String): Session = Session( - id = sessionId, - title = "DroidKaigi", - desc = "How to create DroidKaigi app", - startTime = parseDate(10000), - endTime = parseDate(10000), - format = "30分", - room = Room(1, "Hall"), - topic = Topic(2, "Development tool"), - language = "JA", - level = Level(1, "Beginner"), - speakers = listOf( - createSpeaker(), - createSpeaker() - ), - isFavorited = true -) - -private fun createSpeaker(): Speaker { + listOf( + createDummySession(DUMMY_SESSION_ID1, DUMMY_SESSION_TITLE1), + createDummySession(DUMMY_SESSION_ID2, DUMMY_SESSION_TITLE2) + ) + +fun createDummySession(sessionId: String = DUMMY_SESSION_ID1, title: String = DUMMY_SESSION_TITLE1): Session { + return Session( + id = sessionId, + title = title, + desc = "How to create DroidKaigi app", + startTime = parseDate(10000), + endTime = parseDate(10000), + format = "30分", + room = Room(1, "Hall"), + topic = Topic(2, "Development tool"), + language = "JA", + level = Level(1, "Beginner"), + speakers = listOf( + createDummySpeaker(), + createDummySpeaker() + ), + isFavorited = true + ) +} + +fun createDummySpeaker(): Speaker { return Speaker( name = "tm", imageUrl = "http://example.com", @@ -36,3 +45,52 @@ private fun createSpeaker(): Speaker { companyUrl = null ) } + + +fun createDummySpeakerEntities(): List { + return listOf( + SpeakerEntity( + "aaaa" + , "hogehoge" + , "https://example.com" + , "http://example.com/hoge" + , null + , null + , "http://example.github.com/hoge" + ), + SpeakerEntity( + "bbbb" + , "hogehuga" + , "https://example.com" + , "http://example.com/hoge" + , null + , null + , "http://example.github.com/hoge" + )) +} + +fun createDummySessionWithSpeakersEntities(): List { + return listOf(SessionWithSpeakers(SessionEntity(DUMMY_SESSION_ID1, + DUMMY_SESSION_TITLE1, + "Endless battle", + LocalDateTime.of(1, 1, 1, 1, 1), + LocalDateTime.of(1, 1, 1, 1, 1), + "30分", + "日本語", + LevelEntity(1, "ニッチ / Niche"), + TopicEntity(1, "開発環境 / Development"), + RoomEntity(1, "ホール")), + listOf("aaaa", "bbbb")), + SessionWithSpeakers(SessionEntity(DUMMY_SESSION_ID2, + DUMMY_SESSION_TITLE2, + "Endless battle", + LocalDateTime.of(1, 1, 1, 1, 1), + LocalDateTime.of(1, 1, 1, 1, 1), + "30分", + "日本語", + LevelEntity(1, "ニッチ / Niche"), + TopicEntity(1, "開発環境 / Development"), + RoomEntity(1, "ホール")), + listOf("aaaa", "bbbb")) + ) +} diff --git a/app/src/test/java/io/github/droidkaigi/confsched2018/data/repository/SessionsDataRepositoryTest.kt b/app/src/test/java/io/github/droidkaigi/confsched2018/data/repository/SessionsDataRepositoryTest.kt index 439f0f44..da0ba176 100644 --- a/app/src/test/java/io/github/droidkaigi/confsched2018/data/repository/SessionsDataRepositoryTest.kt +++ b/app/src/test/java/io/github/droidkaigi/confsched2018/data/repository/SessionsDataRepositoryTest.kt @@ -4,11 +4,15 @@ import com.nhaarman.mockito_kotlin.doReturn import com.nhaarman.mockito_kotlin.mock import com.nhaarman.mockito_kotlin.verify import com.nhaarman.mockito_kotlin.whenever +import io.github.droidkaigi.confsched2018.DUMMY_SESSION_TITLE1 +import io.github.droidkaigi.confsched2018.createDummySessionWithSpeakersEntities +import io.github.droidkaigi.confsched2018.createDummySpeakerEntities import io.github.droidkaigi.confsched2018.data.db.FavoriteDatabase import io.github.droidkaigi.confsched2018.data.db.SessionDatabase -import io.github.droidkaigi.confsched2018.data.db.entity.* +import io.github.droidkaigi.confsched2018.data.db.entity.RoomEntity import io.github.droidkaigi.confsched2018.data.db.entity.mapper.toRooms import io.github.droidkaigi.confsched2018.data.db.entity.mapper.toSession +import io.github.droidkaigi.confsched2018.model.SearchResult import io.github.droidkaigi.confsched2018.util.rx.TestSchedulerProvider import io.reactivex.Flowable import org.junit.Before @@ -16,7 +20,6 @@ import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock import org.robolectric.RobolectricTestRunner -import org.threeten.bp.LocalDateTime @RunWith(RobolectricTestRunner::class) class SessionsDataRepositoryTest { @@ -47,39 +50,8 @@ class SessionsDataRepositoryTest { } @Test fun sessions() { - val sessions = listOf(SessionWithSpeakers(SessionEntity("10" - , "DroidKaigi app" - , "Endless battle" - , LocalDateTime.of(1, 1, 1, 1, 1) - , LocalDateTime.of(1, 1, 1, 1, 1) - , "30分" - , "日本語" - , LevelEntity(1, "ニッチ / Niche") - , TopicEntity(1, "開発環境 / Development") - , RoomEntity(1, "ホール")), - listOf( - "aaaa", "bbbb" - ))) - val speakers = listOf( - SpeakerEntity( - "aaaa" - , "hogehoge" - , "https://example.com" - , "http://example.com/hoge" - , null - , null - , "http://example.github.com/hoge" - ), - SpeakerEntity( - "bbbb" - , "hogehuga" - , "https://example.com" - , "http://example.com/hoge" - , null - , null - , "http://example.github.com/hoge" - )) - + val sessions = createDummySessionWithSpeakersEntities() + val speakers = createDummySpeakerEntities() whenever(sessionDatabase.getAllSessions()).doReturn(Flowable.just(sessions)) whenever(sessionDatabase.getAllSpeaker()).doReturn(Flowable.just(speakers)) @@ -96,4 +68,25 @@ class SessionsDataRepositoryTest { verify(sessionDatabase).getAllSessions() } + @Test fun search() { + val sessions = createDummySessionWithSpeakersEntities() + val speakers = createDummySpeakerEntities() + whenever(sessionDatabase.getAllSessions()).doReturn(Flowable.just(sessions)) + whenever(sessionDatabase.getAllSpeaker()).doReturn(Flowable.just(speakers)) + val sessionDataRepository = SessionDataRepository(mock(), + sessionDatabase, + favoriteDatabase, + TestSchedulerProvider()) + + sessionDataRepository.search(DUMMY_SESSION_TITLE1) + .doOnSuccess { + println(it) + } + .test() + .assertValue(SearchResult(listOf(sessions[0].toSession(speakers, emptyList())), + listOf())) + + verify(sessionDatabase).getAllSessions() + } + } diff --git a/app/src/test/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailViewModelTest.kt b/app/src/test/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailViewModelTest.kt index ae305ab3..7f6b6ed1 100644 --- a/app/src/test/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailViewModelTest.kt +++ b/app/src/test/java/io/github/droidkaigi/confsched2018/presentation/detail/SessionDetailViewModelTest.kt @@ -2,7 +2,7 @@ package io.github.droidkaigi.confsched2018.presentation.detail import android.arch.lifecycle.Observer import com.nhaarman.mockito_kotlin.* -import io.github.droidkaigi.confsched2018.DUMMY_SESSION_ID_1 +import io.github.droidkaigi.confsched2018.DUMMY_SESSION_ID1 import io.github.droidkaigi.confsched2018.createDummySession import io.github.droidkaigi.confsched2018.createDummySessions import io.github.droidkaigi.confsched2018.data.repository.SessionRepository @@ -43,13 +43,13 @@ class SessionDetailViewModelTest { val sessions = createDummySessions() whenever(repository.sessions).doReturn(Flowable.just(sessions)) viewModel = SessionDetailViewModel(repository, TestSchedulerProvider()) - viewModel.sessionId = DUMMY_SESSION_ID_1 + viewModel.sessionId = DUMMY_SESSION_ID1 val result: Observer> = mock() viewModel.session.observeForever(result) verify(repository).sessions - verify(result).onChanged(Result.success(createDummySession(DUMMY_SESSION_ID_1))) + verify(result).onChanged(Result.success(createDummySession(DUMMY_SESSION_ID1))) } @Test fun sessions_Error() { diff --git a/app/src/test/java/io/github/droidkaigi/confsched2018/presentation/search/SearchViewModelTest.kt b/app/src/test/java/io/github/droidkaigi/confsched2018/presentation/search/SearchViewModelTest.kt new file mode 100644 index 00000000..2ac07e49 --- /dev/null +++ b/app/src/test/java/io/github/droidkaigi/confsched2018/presentation/search/SearchViewModelTest.kt @@ -0,0 +1,82 @@ +package io.github.droidkaigi.confsched2018.presentation.search + +import android.arch.lifecycle.Observer +import com.nhaarman.mockito_kotlin.* +import io.github.droidkaigi.confsched2018.createDummySessions +import io.github.droidkaigi.confsched2018.createDummySpeaker +import io.github.droidkaigi.confsched2018.data.repository.SessionRepository +import io.github.droidkaigi.confsched2018.model.SearchResult +import io.github.droidkaigi.confsched2018.model.Session +import io.github.droidkaigi.confsched2018.presentation.Result +import io.github.droidkaigi.confsched2018.util.rx.TestSchedulerProvider +import io.reactivex.Completable +import io.reactivex.Single +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.robolectric.RobolectricTestRunner + +@RunWith(RobolectricTestRunner::class) +class SearchViewModelTest { + @Mock private val repository: SessionRepository = mock() + + private lateinit var viewModel: SearchViewModel + + @Before fun init() { + whenever(repository.refreshSessions()).doReturn(Completable.complete()) + } + + @Test fun search_Empty() { + whenever(repository.search("query")).doReturn(Single.just(SearchResult(listOf(), listOf()))) + viewModel = SearchViewModel(repository, TestSchedulerProvider()) + val result: Observer> = mock() + viewModel.result.observeForever(result) + + viewModel.onQuery("query") + + + verify(repository).search("query") + verify(result).onChanged(Result.inProgress()) + verify(result).onChanged(Result.success(SearchResult(listOf(), listOf()))) + + } + + @Test fun search_Basic() { + val searchResult = SearchResult(createDummySessions(), listOf(createDummySpeaker())) + whenever(repository.search("query")).doReturn(Single.just(searchResult)) + viewModel = SearchViewModel(repository, TestSchedulerProvider()) + val result: Observer> = mock() + viewModel.result.observeForever(result) + + viewModel.onQuery("query") + + verify(repository).search("query") + verify(result).onChanged(Result.success(searchResult)) + } + + @Test fun search_Error() { + val runtimeException = RuntimeException("test") + whenever(repository.search("query")).doReturn(Single.error(runtimeException)) + viewModel = SearchViewModel(repository, TestSchedulerProvider()) + val result: Observer> = mock() + viewModel.result.observeForever(result) + + viewModel.onQuery("query") + + verify(repository).search("query") + verify(result).onChanged(Result.failure(runtimeException.message!!, runtimeException)) + } + + + @Test fun favorite() { + whenever(repository.favorite(any())).doReturn(Single.just(true)) + viewModel = SearchViewModel(repository, TestSchedulerProvider()) + val session = mock() + + viewModel.onFavoriteClick(session) + + verify(repository).favorite(session) + } + +} diff --git a/common-jvm/src/main/kotlin/JvmDate.kt b/common-jvm/src/main/kotlin/JvmDate.kt index 88af77f2..5ae7ce01 100644 --- a/common-jvm/src/main/kotlin/JvmDate.kt +++ b/common-jvm/src/main/kotlin/JvmDate.kt @@ -32,6 +32,10 @@ actual class Date { actual fun getTime(): Number = calendar.timeInMillis + override fun hashCode(): Int { + return date.time.toInt() + } + override fun equals(other: Any?): Boolean = other is Date && other.calendar.time == calendar.time } diff --git a/common/src/main/kotlin/SearchResult.kt b/common/src/main/kotlin/SearchResult.kt new file mode 100644 index 00000000..b557ace1 --- /dev/null +++ b/common/src/main/kotlin/SearchResult.kt @@ -0,0 +1,6 @@ +package io.github.droidkaigi.confsched2018.model + +data class SearchResult ( + val sessions:List, + val speakers:List +)