Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NTV-223: overview & faq fragments & tabNavigation (#1410)
- Loading branch information
Showing
16 changed files
with
398 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.kickstarter.libs | ||
|
||
import com.kickstarter.ui.data.ProjectData | ||
|
||
interface Configure { | ||
fun configureWith(projectData: ProjectData) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/kickstarter/mock/factories/ProjectFaqFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.kickstarter.mock.factories | ||
|
||
import com.kickstarter.models.ProjectFaq | ||
import org.joda.time.DateTime | ||
|
||
class ProjectFaqFactory private constructor() { | ||
companion object { | ||
fun getFaqs(): List<ProjectFaq> { | ||
return listOf(getFaq(), getFaq(), getFaq()) | ||
} | ||
|
||
private fun getFaq() = ProjectFaq.builder() | ||
.id(7L) | ||
.answer("No, there is no extra VAT or taxes for backers.\\r\\n\\r\\nWe will export the tables to local countries first and forward to respective shipping addresses through local couriers. We will clear the customs for all the desks. \\r\\n\\r\\nVAT and taxes are already included in the reward price and no extra payment will be required from backers.") | ||
.question("Is there any extra VAT and taxes on top of shipping cost?") | ||
.createdAt(DateTime.now()) | ||
.build() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
app/src/main/java/com/kickstarter/ui/adapters/ProjectPagerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.kickstarter.ui.adapters | ||
|
||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.FragmentManager | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.viewpager2.adapter.FragmentStateAdapter | ||
import com.kickstarter.libs.Configure | ||
import com.kickstarter.ui.data.ProjectData | ||
import com.kickstarter.ui.fragments.ProjectFaqFragment | ||
import com.kickstarter.ui.fragments.ProjectOverviewFragment | ||
|
||
class ProjectPagerAdapter( | ||
private val fragmentManager: FragmentManager, | ||
lifecycle: Lifecycle | ||
) : | ||
FragmentStateAdapter(fragmentManager, lifecycle) { | ||
|
||
override fun getItemCount(): Int = 2 | ||
|
||
// TODO: improve when with an enum type | ||
override fun createFragment(position: Int): Fragment { | ||
return when (position) { | ||
0 -> return ProjectOverviewFragment.newInstance(position) | ||
1 -> return ProjectFaqFragment.newInstance(position) | ||
else -> ProjectOverviewFragment.newInstance(position) | ||
} | ||
} | ||
|
||
fun updatedWithProjectData(projectData: ProjectData) { | ||
fragmentManager.fragments.forEach { fragment -> | ||
// - fragmentManager.fragments will iterate over all fragments added, but only the ones on the | ||
// - projectTabLayout implement the Configure interface | ||
if (fragment is Configure) fragment.configureWith(projectData) | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/kickstarter/ui/fragments/ProjectFaqFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.kickstarter.ui.fragments | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import com.kickstarter.databinding.FragmentProjectFaqBinding | ||
import com.kickstarter.libs.BaseFragment | ||
import com.kickstarter.libs.Configure | ||
import com.kickstarter.libs.qualifiers.RequiresFragmentViewModel | ||
import com.kickstarter.libs.rx.transformers.Transformers | ||
import com.kickstarter.ui.ArgumentsKey | ||
import com.kickstarter.ui.data.ProjectData | ||
import com.kickstarter.viewmodels.ProjectFaqViewModel | ||
|
||
@RequiresFragmentViewModel(ProjectFaqViewModel.ViewModel::class) | ||
class ProjectFaqFragment : BaseFragment<ProjectFaqViewModel.ViewModel>(), Configure { | ||
private var binding: FragmentProjectFaqBinding? = null | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
super.onCreateView(inflater, container, savedInstanceState) | ||
binding = FragmentProjectFaqBinding.inflate(inflater, container, false) | ||
return binding?.root | ||
} | ||
|
||
override fun configureWith(projectData: ProjectData) { | ||
this.viewModel?.inputs?.configureWith(projectData) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
// TODO: FAQ's ready for complete https://kickstarter.atlassian.net/browse/NTV-209 | ||
this.viewModel.outputs.projectFaqs() | ||
.compose(bindToLifecycle()) | ||
.compose(Transformers.observeForUI()) | ||
.subscribe { | ||
var faq = "" | ||
it.map { faq += "***QUESTION: ${it.question} \n ***ANSWER:${it.answer} \n" } | ||
binding?.placeholder?.text = faq | ||
} | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
fun newInstance(position: Int): ProjectFaqFragment { | ||
val fragment = ProjectFaqFragment() | ||
val bundle = Bundle() | ||
bundle.putInt(ArgumentsKey.PROJECT_PAGER_POSITION, position) | ||
fragment.arguments = bundle | ||
return fragment | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/kickstarter/ui/fragments/ProjectOverviewFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.kickstarter.ui.fragments | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import com.kickstarter.databinding.FragmentProjectOverviewBinding | ||
import com.kickstarter.libs.BaseFragment | ||
import com.kickstarter.libs.Configure | ||
import com.kickstarter.libs.qualifiers.RequiresFragmentViewModel | ||
import com.kickstarter.ui.ArgumentsKey | ||
import com.kickstarter.ui.data.ProjectData | ||
import com.kickstarter.viewmodels.ProjectOverviewViewModel | ||
|
||
@RequiresFragmentViewModel(ProjectOverviewViewModel.ViewModel::class) | ||
class ProjectOverviewFragment : BaseFragment<ProjectOverviewViewModel.ViewModel>(), Configure { | ||
|
||
private var binding: FragmentProjectOverviewBinding? = null | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
super.onCreateView(inflater, container, savedInstanceState) | ||
binding = FragmentProjectOverviewBinding.inflate(inflater, container, false) | ||
return binding?.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
} | ||
|
||
override fun configureWith(projectData: ProjectData) { | ||
this.viewModel?.inputs?.configureWith(projectData) | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
fun newInstance(position: Int): ProjectOverviewFragment { | ||
val fragment = ProjectOverviewFragment() | ||
val bundle = Bundle() | ||
bundle.putInt(ArgumentsKey.PROJECT_PAGER_POSITION, position) | ||
fragment.arguments = bundle | ||
return fragment | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/kickstarter/viewmodels/ProjectFaqViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.kickstarter.viewmodels | ||
|
||
import androidx.annotation.NonNull | ||
import com.kickstarter.libs.Environment | ||
import com.kickstarter.libs.FragmentViewModel | ||
import com.kickstarter.libs.utils.ObjectUtils | ||
import com.kickstarter.models.ProjectFaq | ||
import com.kickstarter.ui.data.ProjectData | ||
import com.kickstarter.ui.fragments.ProjectFaqFragment | ||
import rx.Observable | ||
import rx.subjects.BehaviorSubject | ||
import rx.subjects.PublishSubject | ||
|
||
class ProjectFaqViewModel { | ||
interface Inputs { | ||
/** Configure with current [ProjectData]. */ | ||
fun configureWith(projectData: ProjectData) | ||
} | ||
|
||
interface Outputs { | ||
fun projectFaqs(): Observable<List<ProjectFaq>> | ||
} | ||
|
||
class ViewModel(@NonNull val environment: Environment) : FragmentViewModel<ProjectFaqFragment>(environment), Inputs, Outputs { | ||
val inputs: Inputs = this | ||
val outputs: Outputs = this | ||
|
||
// - Inputs | ||
private val projectDataInput = BehaviorSubject.create<ProjectData>() | ||
|
||
// - Outputs | ||
private val listFaqs = PublishSubject.create<List<ProjectFaq>>() | ||
|
||
init { | ||
// TODO: FAQ's ready for complete https://kickstarter.atlassian.net/browse/NTV-209 | ||
projectDataInput | ||
.map { it?.project()?.projectFaqs() } | ||
.filter { ObjectUtils.isNotNull(it) } | ||
.map { requireNotNull(it) } | ||
.compose(bindToLifecycle()) | ||
.subscribe { | ||
this.listFaqs.onNext(it.toList()) | ||
} | ||
} | ||
|
||
// - Inputs | ||
override fun configureWith(projectData: ProjectData) = this.projectDataInput.onNext(projectData) | ||
|
||
override fun projectFaqs(): Observable<List<ProjectFaq>> = this.listFaqs | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/kickstarter/viewmodels/ProjectOverviewViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.kickstarter.viewmodels | ||
|
||
import androidx.annotation.NonNull | ||
import com.kickstarter.libs.Environment | ||
import com.kickstarter.libs.FragmentViewModel | ||
import com.kickstarter.libs.utils.ObjectUtils | ||
import com.kickstarter.ui.data.ProjectData | ||
import com.kickstarter.ui.fragments.ProjectOverviewFragment | ||
import rx.subjects.BehaviorSubject | ||
|
||
class ProjectOverviewViewModel { | ||
interface Inputs { | ||
/** Configure with current [ProjectData]. */ | ||
fun configureWith(projectData: ProjectData) | ||
} | ||
|
||
interface Outputs | ||
|
||
class ViewModel(@NonNull val environment: Environment) : FragmentViewModel<ProjectOverviewFragment>(environment), Inputs, Outputs { | ||
val inputs: Inputs = this | ||
val outputs: Outputs = this | ||
|
||
private val projectDataInput = BehaviorSubject.create<ProjectData>() | ||
|
||
init { | ||
val project = projectDataInput | ||
.map { it.project() } | ||
.filter { ObjectUtils.isNotNull(it) } | ||
.map { requireNotNull(it) } | ||
} | ||
|
||
override fun configureWith(projectData: ProjectData) = this.projectDataInput.onNext(projectData) | ||
} | ||
} |
Oops, something went wrong.