Skip to content
Permalink
Browse files

Extract search to new module

  • Loading branch information...
chrisbanes committed Oct 3, 2019
1 parent bbfca3d commit 54572858d0618de0ad3de187b932a04aaca7ca3d
@@ -31,6 +31,7 @@
<option value="$PROJECT_DIR$/ui-followed" />
<option value="$PROJECT_DIR$/ui-popular" />
<option value="$PROJECT_DIR$/ui-recommended" />
<option value="$PROJECT_DIR$/ui-search" />
<option value="$PROJECT_DIR$/ui-showdetails" />
<option value="$PROJECT_DIR$/ui-trending" />
<option value="$PROJECT_DIR$/ui-watched" />
@@ -25,6 +25,7 @@
<module fileurl="file://$PROJECT_DIR$/ui-followed/ui-followed.iml" filepath="$PROJECT_DIR$/ui-followed/ui-followed.iml" />
<module fileurl="file://$PROJECT_DIR$/ui-popular/ui-popular.iml" filepath="$PROJECT_DIR$/ui-popular/ui-popular.iml" />
<module fileurl="file://$PROJECT_DIR$/ui-recommended/ui-recommended.iml" filepath="$PROJECT_DIR$/ui-recommended/ui-recommended.iml" />
<module fileurl="file://$PROJECT_DIR$/ui-search/ui-search.iml" filepath="$PROJECT_DIR$/ui-search/ui-search.iml" />
<module fileurl="file://$PROJECT_DIR$/ui-showdetails/ui-showdetails.iml" filepath="$PROJECT_DIR$/ui-showdetails/ui-showdetails.iml" />
<module fileurl="file://$PROJECT_DIR$/ui-trending/ui-trending.iml" filepath="$PROJECT_DIR$/ui-trending/ui-trending.iml" />
<module fileurl="file://$PROJECT_DIR$/ui-watched/ui-watched.iml" filepath="$PROJECT_DIR$/ui-watched/ui-watched.iml" />
@@ -183,6 +183,7 @@ dependencies {
implementation project(":ui-popular")
implementation project(":ui-trending")
implementation project(":ui-recommended")
implementation project(":ui-search")

implementation Libs.AndroidX.Lifecycle.extensions
implementation Libs.AndroidX.Lifecycle.viewmodel
@@ -18,13 +18,10 @@ package app.tivi.home

import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import android.view.View
import androidx.appcompat.widget.SearchView
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
@@ -35,11 +32,8 @@ import app.tivi.databinding.ActivityHomeBinding
import app.tivi.extensions.hideSoftInput
import app.tivi.home.main.HomeNavigationItemDiffAdapter
import app.tivi.home.main.HomeNavigationItemDiffCallback
import app.tivi.home.search.SearchFragment
import app.tivi.home.search.SearchViewModel
import app.tivi.trakt.TraktConstants
import app.tivi.util.AppCoroutineDispatchers
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.viewModel
import com.airbnb.mvrx.withState
import net.openid.appauth.AuthorizationException
@@ -66,9 +60,6 @@ class HomeActivity : TiviActivityMvRxView() {
private val navController: NavController
get() = navHostFragment.navController

private val primaryNavigationFragment: Fragment?
get() = navHostFragment.childFragmentManager.primaryNavigationFragment

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

@@ -77,9 +68,6 @@ class HomeActivity : TiviActivityMvRxView() {
binding.homeRoot.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION

// val searchMenuItem = binding.homeToolbar.menu.findItem(R.id.home_menu_search)
// searchMenuItem.setOnActionExpandListener(SearchViewListeners())

binding.homeBottomNavigation.setupWithNavController(navController)

navController.addOnDestinationChangedListener { _, destination, _ ->
@@ -128,56 +116,4 @@ class HomeActivity : TiviActivityMvRxView() {
internal fun startLogin() {
viewModel.onLoginItemClicked(authService)
}

private inner class SearchViewListeners : SearchView.OnQueryTextListener, MenuItem.OnActionExpandListener {
private var expandedMenuItem: MenuItem? = null

override fun onQueryTextSubmit(query: String): Boolean {
(primaryNavigationFragment as? SearchFragment)?.run {
val searchViewModel: SearchViewModel by fragmentViewModel()
searchViewModel.setSearchQuery(query)
}
hideSoftInput()
return true
}

override fun onQueryTextChange(newText: String): Boolean {
(primaryNavigationFragment as? SearchFragment)?.run {
val searchViewModel: SearchViewModel by fragmentViewModel()
searchViewModel.setSearchQuery(newText)
}
return true
}

override fun onMenuItemActionExpand(item: MenuItem): Boolean {
expandedMenuItem = item

val searchView = item.actionView as SearchView
searchView.setOnQueryTextListener(this)

// Open the search fragment
navController.navigate(R.id.navigation_search)

return true
}

override fun onMenuItemActionCollapse(item: MenuItem): Boolean {
expandedMenuItem = null

val searchView = item.actionView as SearchView
searchView.setOnQueryTextListener(null)

(primaryNavigationFragment as? SearchFragment)?.run {
val searchViewModel: SearchViewModel by fragmentViewModel()
searchViewModel.clearQuery()
}

// Pop the search fragment off
if (navController.currentDestination?.id == R.id.navigation_search) {
navController.popBackStack()
}

return true
}
}
}

This file was deleted.

@@ -48,6 +48,8 @@ fun Activity.hideSoftInput() {
}
}

fun Fragment.hideSoftInput() = requireActivity().hideSoftInput()

fun Fragment.toDp(px: Int) = resources.toDp(px)
fun Activity.toDp(px: Int) = resources.toDp(px)
fun Resources.toDp(px: Int) = (displayMetrics.density * px).roundToInt()
@@ -38,4 +38,5 @@ include ':ui-watched'
include ':ui-trending'
include ':ui-popular'
include ':ui-recommended'
include ':ui-search'
include ':app'
@@ -0,0 +1,101 @@
/*
* Copyright 2018 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import app.tivi.buildsrc.Libs

apply plugin: 'com.android.library'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-kapt'
kapt {
correctErrorTypes = true
useBuildCache = true
}

apply plugin: 'kotlin-android-extensions'
androidExtensions {
experimental = true
}

android {
compileSdkVersion buildConfig.compileSdk

defaultConfig {
minSdkVersion buildConfig.minSdk
manifestPlaceholders += ['appAuthRedirectScheme': 'empty']
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

dataBinding {
enabled = true
}
}

dependencies {
implementation project(":base")
implementation project(":base-android")
implementation project(':domain')
implementation project(":trakt-auth")
implementation project(":common-ui")
implementation project(":common-epoxy")
implementation project(":common-layouts")
implementation project(':common-imageloading')
implementation project(":common-databinding")

implementation Libs.AndroidX.Lifecycle.extensions
implementation Libs.AndroidX.Lifecycle.viewmodel
kapt Libs.AndroidX.Lifecycle.compiler

implementation Libs.AndroidX.Paging.runtime

implementation Libs.AndroidX.appcompat
implementation Libs.AndroidX.browser
implementation Libs.AndroidX.palette
implementation Libs.AndroidX.recyclerview
implementation Libs.AndroidX.emoji
implementation Libs.AndroidX.preference
implementation Libs.AndroidX.constraintlayout
implementation Libs.AndroidX.coreKtx
implementation Libs.AndroidX.Fragment.fragment
implementation Libs.AndroidX.Fragment.fragmentKtx
implementation Libs.AndroidX.Navigation.fragment
implementation Libs.AndroidX.Navigation.ui

implementation Libs.Google.material

implementation Libs.Kotlin.stdlib
implementation Libs.Kotlin.reflect

implementation Libs.Dagger.androidSupport
kapt Libs.Dagger.compiler
kapt Libs.Dagger.androidProcessor

compileOnly Libs.AssistedInject.annotationDagger2
kapt Libs.AssistedInject.processorDagger2

implementation Libs.mvRx

implementation Libs.Epoxy.epoxy
implementation Libs.Epoxy.paging
implementation Libs.Epoxy.dataBinding
kapt Libs.Epoxy.processor
}
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2018 Google, Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.tivi.home.search">

</manifest>
@@ -18,7 +18,6 @@ package app.tivi.home.search

import app.tivi.data.entities.TiviShow
import app.tivi.home.HomeTextCreator
import app.tivi.searchItemShow
import app.tivi.common.epoxy.EpoxyModelProperty
import com.airbnb.epoxy.EpoxyController
import javax.inject.Inject

0 comments on commit 5457285

Please sign in to comment.
You can’t perform that action at this time.