Skip to content

Commit

Permalink
Fix part of #1287: Fix lint issues in app module in the kotlin files …
Browse files Browse the repository at this point in the history
…(walkthrough) (#1310)

* fin ktlint issue in walkthrough package

* [skip ci] nit changes
  • Loading branch information
anandwana001 authored Jun 16, 2020
1 parent 1f50019 commit fa9e9bf
Show file tree
Hide file tree
Showing 13 changed files with 227 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import javax.inject.Inject

/** Activity that contains the walkthrough flow for users. */
class WalkthroughActivity : InjectableAppCompatActivity(), WalkthroughFragmentChangeListener {
@Inject lateinit var walkthroughActivityPresenter: WalkthroughActivityPresenter

@Inject
lateinit var walkthroughActivityPresenter: WalkthroughActivityPresenter

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -31,7 +31,8 @@ class WalkthroughActivity : InjectableAppCompatActivity(), WalkthroughFragmentCh
}

companion object {
internal const val WALKTHROUGH_ACTIVITY_INTERNAL_PROFILE_ID_KEY = "WalkthroughActivity.internal_profile_id"
internal const val WALKTHROUGH_ACTIVITY_INTERNAL_PROFILE_ID_KEY =
"WalkthroughActivity.internal_profile_id"

fun createWalkthroughActivityIntent(context: Context, internalProfileId: Int): Intent {
val intent = Intent(context, WalkthroughActivity::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,27 @@ class WalkthroughActivityPresenter @Inject constructor(
}
} else if (currentFragmentIndex != null) {
when (currentFragmentIndex) {
0 -> activity.supportFragmentManager.beginTransaction().replace(
R.id.walkthrough_fragment_placeholder,
getWalkthroughWelcomeFragment() ?: WalkthroughWelcomeFragment()
).commitNow().also {
getWalkthroughViewModel().currentProgress.set(1)
}
1 -> activity.supportFragmentManager.beginTransaction().replace(
R.id.walkthrough_fragment_placeholder,
getWalkthroughTopicListFragment() ?: WalkthroughTopicListFragment()
).commitNow().also {
getWalkthroughViewModel().currentProgress.set(2)
}
2 -> activity.supportFragmentManager.beginTransaction().replace(
R.id.walkthrough_fragment_placeholder,
getWalkthroughFinalFragment() ?: WalkthroughFinalFragment()
).commitNow().also {
getWalkthroughViewModel().currentProgress.set(3)
}
0 ->
activity.supportFragmentManager.beginTransaction().replace(
R.id.walkthrough_fragment_placeholder,
getWalkthroughWelcomeFragment() ?: WalkthroughWelcomeFragment()
).commitNow().also {
getWalkthroughViewModel().currentProgress.set(1)
}
1 ->
activity.supportFragmentManager.beginTransaction().replace(
R.id.walkthrough_fragment_placeholder,
getWalkthroughTopicListFragment() ?: WalkthroughTopicListFragment()
).commitNow().also {
getWalkthroughViewModel().currentProgress.set(2)
}
2 ->
activity.supportFragmentManager.beginTransaction().replace(
R.id.walkthrough_fragment_placeholder,
getWalkthroughFinalFragment() ?: WalkthroughFinalFragment()
).commitNow().also {
getWalkthroughViewModel().currentProgress.set(3)
}
}
}
}
Expand All @@ -76,15 +79,27 @@ class WalkthroughActivityPresenter @Inject constructor(
}

private fun getWalkthroughWelcomeFragment(): WalkthroughWelcomeFragment? {
return activity.supportFragmentManager.findFragmentById(R.id.walkthrough_fragment_placeholder) as WalkthroughWelcomeFragment?
return activity
.supportFragmentManager
.findFragmentById(
R.id.walkthrough_fragment_placeholder
) as WalkthroughWelcomeFragment?
}

private fun getWalkthroughTopicListFragment(): WalkthroughTopicListFragment? {
return activity.supportFragmentManager.findFragmentById(R.id.walkthrough_fragment_placeholder) as WalkthroughTopicListFragment?
return activity
.supportFragmentManager
.findFragmentById(
R.id.walkthrough_fragment_placeholder
) as WalkthroughTopicListFragment?
}

private fun getWalkthroughFinalFragment(): WalkthroughFinalFragment? {
return activity.supportFragmentManager.findFragmentById(R.id.walkthrough_fragment_placeholder) as WalkthroughFinalFragment?
return activity
.supportFragmentManager
.findFragmentById(
R.id.walkthrough_fragment_placeholder
) as WalkthroughFinalFragment?
}

fun changePage(pageNumber: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,28 @@ class WalkthroughFinalFragment : InjectableFragment() {
return storyFragment
}
}
@Inject lateinit var walkthroughFinalFragmentPresenter: WalkthroughFinalFragmentPresenter

@Inject
lateinit var walkthroughFinalFragmentPresenter: WalkthroughFinalFragmentPresenter

override fun onAttach(context: Context) {
super.onAttach(context)
fragmentComponent.inject(this)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val args = checkNotNull(arguments) { "Expected arguments to be passed to WalkthroughFinalFragment" }
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val args =
checkNotNull(arguments) {
"Expected arguments to be passed to WalkthroughFinalFragment"
}
val topicId =
checkNotNull(args.getString(KEY_TOPIC_ID_ARGUMENT)) { "Expected topicId to be passed to WalkthroughFinalFragment" }
return walkthroughFinalFragmentPresenter.handleCreateView(inflater, container,topicId)
checkNotNull(args.getString(KEY_TOPIC_ID_ARGUMENT)) {
"Expected topicId to be passed to WalkthroughFinalFragment"
}
return walkthroughFinalFragmentPresenter.handleCreateView(inflater, container, topicId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ class WalkthroughFinalFragmentPresenter @Inject constructor(
private lateinit var topicName: String

fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?, topicId: String): View? {
binding = WalkthroughFinalFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false)
binding =
WalkthroughFinalFragmentBinding.inflate(
inflater,
container,
/* attachToRoot= */ false
)
this.topicId = topicId
val internalProfileId = activity.intent.getIntExtra(WalkthroughActivity.WALKTHROUGH_ACTIVITY_INTERNAL_PROFILE_ID_KEY, -1)
val internalProfileId = activity.intent.getIntExtra(
WalkthroughActivity.WALKTHROUGH_ACTIVITY_INTERNAL_PROFILE_ID_KEY,
-1
)
profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()

walkthroughFinalViewModel = WalkthroughFinalViewModel()
Expand All @@ -53,15 +61,23 @@ class WalkthroughFinalFragmentPresenter @Inject constructor(
private val topicLiveData: LiveData<Topic> by lazy { getTopic() }

private fun subscribeToTopicLiveData() {
topicLiveData.observe(activity, Observer { result ->
topicName = result.name
setTopicName()
})
topicLiveData.observe(
activity,
Observer { result ->
topicName = result.name
setTopicName()
}
)
}

private fun setTopicName() {
if (::walkthroughFinalViewModel.isInitialized && ::topicName.isInitialized) {
walkthroughFinalViewModel.topicTitle.set(activity.getString(R.string.are_you_interested,topicName))
walkthroughFinalViewModel.topicTitle.set(
activity.getString(
R.string.are_you_interested,
topicName
)
)
}
}

Expand All @@ -75,7 +91,11 @@ class WalkthroughFinalFragmentPresenter @Inject constructor(

private fun processTopicResult(topic: AsyncResult<Topic>): Topic {
if (topic.isFailure()) {
logger.e("WalkthroughFinalFragment", "Failed to retrieve topic", topic.getErrorOrNull()!!)
logger.e(
"WalkthroughFinalFragment",
"Failed to retrieve topic",
topic.getErrorOrNull()!!
)
}
return topic.getOrDefault(Topic.getDefaultInstance())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ import javax.inject.Inject

/** The second slide for [WalkthroughActivity]. */
class WalkthroughTopicListFragment : InjectableFragment(), TopicSummaryClickListener {
@Inject lateinit var walkthroughTopicListFragmentPresenter: WalkthroughTopicListFragmentPresenter
@Inject
lateinit var walkthroughTopicListFragmentPresenter: WalkthroughTopicListFragmentPresenter

override fun onAttach(context: Context) {
super.onAttach(context)
fragmentComponent.inject(this)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return walkthroughTopicListFragmentPresenter.handleCreateView(inflater, container)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ class WalkthroughTopicListFragmentPresenter @Inject constructor(
fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? {
val viewModel = getWalkthroughTopicViewModel()

binding = WalkthroughTopicListFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false)
binding =
WalkthroughTopicListFragmentBinding.inflate(
inflater,
container,
/* attachToRoot= */ false
)

binding.let {
it.lifecycleOwner = fragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ class WalkthroughTopicViewModel @Inject constructor(
)

// Add the rest of the list
itemViewModelList.addAll(topicList.topicSummaryList.map { topic ->
WalkthroughTopicSummaryViewModel(
topic,
fragment as TopicSummaryClickListener
)
})
itemViewModelList.addAll(
topicList.topicSummaryList.map { topic ->
WalkthroughTopicSummaryViewModel(
topic,
fragment as TopicSummaryClickListener
)
}
)
return itemViewModelList
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ import javax.inject.Inject

/** The first slide for [WalkthroughActivity]. */
class WalkthroughWelcomeFragment : InjectableFragment() {
@Inject lateinit var walkthroughWelcomeFragmentPresenter: WalkthroughWelcomeFragmentPresenter
@Inject
lateinit var walkthroughWelcomeFragmentPresenter: WalkthroughWelcomeFragmentPresenter

override fun onAttach(context: Context) {
super.onAttach(context)
fragmentComponent.inject(this)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return walkthroughWelcomeFragmentPresenter.handleCreateView(inflater, container)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,17 @@ class WalkthroughWelcomeFragmentPresenter @Inject constructor(
private lateinit var profileName: String

fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? {
binding = WalkthroughWelcomeFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false)
binding =
WalkthroughWelcomeFragmentBinding.inflate(
inflater,
container,
/* attachToRoot= */ false
)

internalProfileId = activity.intent.getIntExtra(WalkthroughActivity.WALKTHROUGH_ACTIVITY_INTERNAL_PROFILE_ID_KEY, -1)
internalProfileId = activity.intent.getIntExtra(
WalkthroughActivity.WALKTHROUGH_ACTIVITY_INTERNAL_PROFILE_ID_KEY,
-1
)
profileId = ProfileId.newBuilder().setInternalId(internalProfileId).build()
walkthroughWelcomeViewModel = WalkthroughWelcomeViewModel()

Expand All @@ -58,26 +66,36 @@ class WalkthroughWelcomeFragmentPresenter @Inject constructor(
}

private fun getProfileData(): LiveData<Profile> {
return Transformations.map(profileManagementController.getProfile(profileId), ::processGetProfileResult)
return Transformations.map(
profileManagementController.getProfile(profileId),
::processGetProfileResult
)
}

private fun subscribeToProfileLiveData() {
profileLiveData.observe(activity, Observer<Profile> { result ->
profileName = result.name
setProfileName()
})
profileLiveData.observe(
activity,
Observer<Profile> { result ->
profileName = result.name
setProfileName()
}
)
}

private fun processGetProfileResult(profileResult: AsyncResult<Profile>): Profile {
if (profileResult.isFailure()) {
logger.e("WalkthroughWelcomeFragment", "Failed to retrieve profile", profileResult.getErrorOrNull()!!)
logger.e(
"WalkthroughWelcomeFragment",
"Failed to retrieve profile",
profileResult.getErrorOrNull()!!
)
}
return profileResult.getOrDefault(Profile.getDefaultInstance())
}

private fun setProfileName() {
if (::walkthroughWelcomeViewModel.isInitialized && ::profileName.isInitialized) {
walkthroughWelcomeViewModel.profileName.set(activity.getString(R.string.welcome,profileName))
walkthroughWelcomeViewModel.profileName.set(activity.getString(R.string.welcome, profileName))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class WalkthroughActivityTest {
}

@Test
fun testWalkthroughFragment_increaseProgress_onBackPressed_decreaseProgress_progressWorksCorrectly() {
fun testWalkthroughFragment_increaseProgress_onBackPressed_decreaseProgress_progressWorksCorrectly() { // ktlint-disable max-line-length
launch(WalkthroughActivity::class.java).use {
onView(withId(R.id.walkthrough_welcome_next_button)).perform(scrollTo(), click())
onView(withId(R.id.walkthrough_progress_bar)).check(matches(withProgress(2)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class WalkthroughFinalFragmentTest {
}

@Test
fun testWalkthroughWelcomeFragment_recyclerViewIndex2_topicSelected_configurationChanged_topicTitleIsCorrect() {
fun testWalkthroughWelcomeFragment_recyclerViewIndex2_topicSelected_configurationChanged_topicTitleIsCorrect() { // ktlint-disable max-line-length
launch<WalkthroughActivity>(createWalkthroughActivityIntent(0)).use {
onView(withId(R.id.walkthrough_welcome_next_button))
.perform(scrollTo(), click())
Expand Down Expand Up @@ -121,7 +121,7 @@ class WalkthroughFinalFragmentTest {
}

@Test
fun testWalkthroughWelcomeFragment_recyclerViewIndex1_topicSelected_yesNoButton_isDisplayedCorrectly() {
fun testWalkthroughWelcomeFragment_recyclerViewIndex1_topicSelected_yesNoButton_isDisplayedCorrectly() { // ktlint-disable max-line-length
launch<WalkthroughActivity>(createWalkthroughActivityIntent(0)).use {
onView(withId(R.id.walkthrough_welcome_next_button))
.perform(scrollTo(), click())
Expand All @@ -142,7 +142,7 @@ class WalkthroughFinalFragmentTest {
}

@Test
fun testWalkthroughWelcomeFragment_recyclerViewIndex1_topicSelected_clickNoButton_worksCorrectly() {
fun testWalkthroughWelcomeFragment_recyclerViewIndex1_topicSelected_clickNoButton_worksCorrectly() { // ktlint-disable max-line-length
launch<WalkthroughActivity>(createWalkthroughActivityIntent(0)).use {
onView(withId(R.id.walkthrough_welcome_next_button))
.perform(scrollTo(), click())
Expand Down
Loading

0 comments on commit fa9e9bf

Please sign in to comment.