-
Notifications
You must be signed in to change notification settings - Fork 16
map implementation #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
map implementation #175
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.futurice.freesound.feature.search | ||
|
|
||
| import android.os.Bundle | ||
| import com.futurice.freesound.inject.fragment.BaseFragmentModule | ||
| import com.futurice.freesound.map.BindingBaseMapViewFragment | ||
| import com.futurice.freesound.viewmodel.DataBinder | ||
| import com.futurice.freesound.viewmodel.SimpleDataBinder | ||
| import com.futurice.freesound.viewmodel.ViewModel | ||
| import javax.inject.Inject | ||
|
|
||
| class MapFragment : BindingBaseMapViewFragment<MapFragmentComponent>() { | ||
|
|
||
| @Inject | ||
| internal lateinit var simpleMapViewViewModel: MapViewModel | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| private val dataBinder = SimpleDataBinder() | ||
|
|
||
| override fun inject() { | ||
| component().inject(this) | ||
| } | ||
|
|
||
| override fun createComponent(): MapFragmentComponent = | ||
| (activity as SearchActivity).component() | ||
| .plusMapFragmentComponent(BaseFragmentModule(this)) | ||
|
|
||
| override fun viewModel(): ViewModel = simpleMapViewViewModel | ||
|
|
||
| override fun dataBinder(): DataBinder = dataBinder | ||
|
|
||
| override fun onActivityCreated(savedInstanceState: Bundle?) { | ||
| super.onActivityCreated(savedInstanceState) | ||
| this.getMapAsync(simpleMapViewViewModel) | ||
| } | ||
|
|
||
| companion object { | ||
| internal fun create(): MapFragment = MapFragment() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Copyright 2016 Futurice GmbH | ||
| * | ||
| * 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. | ||
| */ | ||
|
|
||
| package com.futurice.freesound.feature.search; | ||
|
|
||
| import com.futurice.freesound.inject.fragment.BaseFragmentComponent; | ||
| import com.futurice.freesound.inject.fragment.FragmentScope; | ||
|
|
||
| import dagger.Subcomponent; | ||
|
|
||
| @FragmentScope | ||
| @Subcomponent(modules = MapFragmentModule.class) | ||
| public interface MapFragmentComponent extends BaseFragmentComponent { | ||
|
|
||
| void inject(final MapFragment mapFragment); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Copyright 2016 Futurice GmbH | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also update your template for the copyright - 2018. |
||
| * | ||
| * 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. | ||
| */ | ||
|
|
||
| package com.futurice.freesound.feature.search; | ||
|
|
||
| import com.futurice.freesound.feature.common.scheduling.SchedulerProvider; | ||
| import com.futurice.freesound.inject.fragment.BaseFragmentModule; | ||
| import com.futurice.freesound.inject.fragment.FragmentScope; | ||
|
|
||
| import dagger.Module; | ||
| import dagger.Provides; | ||
|
|
||
| @Module(includes = BaseFragmentModule.class) | ||
| public class MapFragmentModule { | ||
|
|
||
| @Provides | ||
| @FragmentScope | ||
| static MapViewModel provideMapFragmentViewModel(TabController tabController, | ||
| SearchDataModel searchDataModel, | ||
| SchedulerProvider schedulerProvider) { | ||
| return new MapViewModel(tabController, searchDataModel, schedulerProvider); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.futurice.freesound.feature.search | ||
|
|
||
| import com.futurice.freesound.common.rx.plusAssign | ||
| import com.futurice.freesound.feature.common.scheduling.SchedulerProvider | ||
| import com.futurice.freesound.map.SimpleMapViewViewModel | ||
| import com.futurice.freesound.network.api.model.Sound | ||
| import io.reactivex.disposables.CompositeDisposable | ||
| import polanski.option.Option | ||
| import timber.log.Timber | ||
|
|
||
| internal class MapViewModel(private val tabController: TabController, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expose Also move Map related classes such as this to a subpackage: |
||
| private val searchDataModel: SearchDataModel, | ||
| private val schedulerProvider: SchedulerProvider) : SimpleMapViewViewModel() { | ||
|
|
||
| override fun bind(d: CompositeDisposable) { | ||
| d += tabController.tabRequestStream | ||
| .observeOn(schedulerProvider.ui()) | ||
| .subscribe( | ||
| { soundItem -> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this action a named method. |
||
| soundItem.sound.ifSome { sound -> | ||
| sound.geotag?.let { zoomToMarker(it) } | ||
| } | ||
| }, | ||
| Timber::e) | ||
|
|
||
| d += searchDataModel.searchStateOnceAndStream | ||
| .map(SearchState::results) | ||
| .observeOn(schedulerProvider.ui()) | ||
| .subscribe(::displayMarkers, | ||
| Timber::e) | ||
| } | ||
|
|
||
| override fun unbind() { | ||
| //nothing to do | ||
| } | ||
|
|
||
| private fun displayMarkers(optionalList: Option<List<Sound>>) { | ||
| wipeMarkers() | ||
| optionalList.ifSome { list -> | ||
| list.forEach { sound -> | ||
| sound.geotag?.let { addMarker(it, sound.name) } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,10 +19,12 @@ package com.futurice.freesound.feature.search | |
| import android.content.Context | ||
| import android.content.Intent | ||
| import android.os.Bundle | ||
| import android.support.v4.app.Fragment | ||
| import android.support.v4.app.FragmentManager | ||
| import android.support.v4.app.FragmentPagerAdapter | ||
| import android.support.v7.widget.SearchView | ||
| import android.support.v7.widget.SearchView.OnQueryTextListener | ||
| import android.view.View | ||
| import android.widget.Button | ||
| import com.futurice.freesound.R | ||
| import com.futurice.freesound.app.FreesoundApplication | ||
| import com.futurice.freesound.common.rx.plusAssign | ||
|
|
@@ -53,6 +55,11 @@ class SearchActivity : BindingBaseActivity<SearchActivityComponent>() { | |
| @Inject | ||
| internal lateinit var schedulerProvider: SchedulerProvider | ||
|
|
||
| @Inject | ||
| internal lateinit var tabController: TabController | ||
|
|
||
| private lateinit var searchPagerAdapter: SearchPagerAdapter | ||
|
|
||
| private val dataBinder = object : SimpleDataBinder() { | ||
|
|
||
| private fun SearchView.getTextChangeStream(uiScheduler: Scheduler): Observable<String> = | ||
|
|
@@ -74,6 +81,12 @@ class SearchActivity : BindingBaseActivity<SearchActivityComponent>() { | |
| .observeOn(schedulerProvider.ui()) | ||
| .subscribe({ handleErrorState(it) }) | ||
| { e(it, "Error receiving Errors") } | ||
|
|
||
| d += tabController.tabRequestStream | ||
| .observeOn(schedulerProvider.ui()) | ||
| .subscribe({ switchTab(it) }) | ||
| { e(it, "Error receiving Errors") } | ||
|
|
||
| } | ||
|
|
||
| private fun SearchView.subscribeToSearchView(emitter: ObservableEmitter<String>) { | ||
|
|
@@ -88,11 +101,14 @@ class SearchActivity : BindingBaseActivity<SearchActivityComponent>() { | |
| } | ||
| } | ||
|
|
||
| private fun switchTab(soundInfo: SoundInfo) { | ||
| container.currentItem = if (soundInfo.tabType == TabType.RESULTS) 0 else 1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There ought to be a better way to couple/define the TabType and its corresponding position. |
||
| } | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_search) | ||
| savedInstanceState.ifNull { addSearchFragment() } | ||
|
|
||
| toolbar_search.apply { setSupportActionBar(this) } | ||
| supportActionBar?.setDisplayHomeAsUpEnabled(true) | ||
|
|
||
|
|
@@ -123,9 +139,8 @@ class SearchActivity : BindingBaseActivity<SearchActivityComponent>() { | |
| } | ||
|
|
||
| private fun addSearchFragment() { | ||
| supportFragmentManager.beginTransaction() | ||
| .add(R.id.container, SearchFragment.create()) | ||
| .commit() | ||
| searchPagerAdapter = SearchPagerAdapter(supportFragmentManager) | ||
| container.adapter = searchPagerAdapter | ||
| } | ||
|
|
||
| private fun handleErrorState(searchState: SearchState) { | ||
|
|
@@ -135,7 +150,7 @@ class SearchActivity : BindingBaseActivity<SearchActivityComponent>() { | |
| } | ||
|
|
||
| private fun setClearSearchVisible(isClearButtonVisible: Boolean) { | ||
| val closeButton : View = search_view.findViewById(R.id.search_close_btn) | ||
| val closeButton: View = search_view.findViewById(R.id.search_close_btn) | ||
| closeButton.visibility = if (isClearButtonVisible) View.VISIBLE else View.GONE | ||
| } | ||
|
|
||
|
|
@@ -149,9 +164,24 @@ class SearchActivity : BindingBaseActivity<SearchActivityComponent>() { | |
|
|
||
| companion object { | ||
|
|
||
| @JvmStatic fun open(context: Context) { | ||
| @JvmStatic | ||
| fun open(context: Context) { | ||
| Intent(context, SearchActivity::class.java) | ||
| .apply { context.startActivity(this) } | ||
| } | ||
| } | ||
|
|
||
| private inner class SearchPagerAdapter(fm: FragmentManager?) : FragmentPagerAdapter(fm) { | ||
| override fun getItem(position: Int): Fragment = if (position == 0) SearchFragment.create() else MapFragment.create() | ||
|
|
||
| override fun getCount(): Int = 2 | ||
|
|
||
| override fun getPageTitle(position: Int): CharSequence = | ||
| when (position) { | ||
| 0 -> getString(R.string.search_tab_results) | ||
| 1 -> getString(R.string.search_tab_map) | ||
| else -> "" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A position other than 0 or 1 is a error condition, correct? If so then throw an |
||
| } | ||
|
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look up how to include this secret so that Travis builds.