Skip to content

Commit

Permalink
Fixes part of oppia#59: Build app module views + view models with Baz…
Browse files Browse the repository at this point in the history
…el (oppia#1581)

* Fixed typo

* Added Firebase dependencies

* Removed AsyncResultTest example

* Removed AsynchResultTest example

* Firebase dependencies added

* Removed unnecessary comments in WORKSPACE and moved rules_kotlin

* Added re-naming TODOs

* Renamed java_proto rules java_proto_lite

* Added doc comments to model/BUILD.bazel and format_import_proto_library

* Added comments to WORKSPACE file

* Fixed nits

* Added comment to kt_android_library() rule

* Fixed more nits

* Added Firebase comment

* Fixed merge conflicts and nits

* Deleted unused dependencies from testing_main_lib

* Fixed nits and error with testing lib dependencies

* Removed printStackTrace()

* Removed addressed TODOs, all tests pass

* Removed redundant public modifier

* Changed library name to model

* Formatted WORKSPACE comment

* Formatted TODO statement

* Changed format_import_proto_library comment

* Added EOF newline

* Created Issue and linked TODO in WORKSPACE

* Edited model BUILD file top comment

* Addressed nits

* Fixed nits and added comments

* Fixing nits

* Deleted unnecessary dependencies and testing example file

* Fixed manifest issues

* Move google json file

* Restore app version of json

* Edit TODO

* Deleted TODO

* Changed Firebase comment

* Added testing functionality from later PR

* Added comments to bzl files

* Added targetSDK to manifests

* Changed crashlytics_lib to crashlytics

* Changed testing_tests visibility

* Added comment to utility_test.bzl

* Changed type of comment ticks

* Fixed typos and all tests pass

* Removed empty line

* Fixed errors from merge

* Added comments to data and domain BUILD files

* Fixed indentation in domain_test

* Removed commented-out dependencies

* Fixed nits and added TODOs

* Added Args to document comment

* Changed targetSDK to 29

* Formatted TODO

* Added root BUILD file

* Moved google-services.json

* Added gogle-services.json back to app

* Trying to remove combined testing library

* Changed targetSDK to 29

* Tests pass now with deps passed in.

* Created TEST_DEPS list to avoid duplicate list of dependencies

* Removed unused resources and manifest

* Updated comments to reflect changes

* Changed deps to be a parameter, changed targetSDK back to 28 because tests do not pass at 29

* Fixed indentation in utility/BUILD

* Updated comment for utility_test.bzl

* Updated comment for testing_test

* Formatted dependencies and removed unused dependency

* Updated dependency list

* Header for oppia_android_test now fits on one line

* Simplifies comment on domain/BUILD file

* Changed cache_store to persistent_cache_store

* Removed glob() from data BUILD file

* Edited documentation for oppia_android_test

* Updated documentation for utility and testing BUILD files

* Changed src to srcs

* Changed src to srcs

* All dragAndDrop tests now pass, stateRetreiverTest fails

* Created java files for binding adapters

* Translated DrawableDinsingAdapter

* Traslated EditTextBindingAdapter

* Translated ImageViewBindingAdapters

* Translated MarginBindingAdapters

* Translated TextViewBindingAdapters

* Translated RecyclerViewBindingAdapter

* Deleted kotlin binding adapters

* Translated GuidelineBindingAdapter

* Translated StateAssemblerMarginBindingAdapters

* Translated StateAssemblerPaddingBindingAdapters

* Almost finished translating ViewBindingAdapter

* Fixed the duplicate google-services.json issue

* Created Issue and added TODO

* Translated ViewBindingAdapter

* Added minSDK back

* Alphabetized dependencies

* Fixed firebase target

* Trying to fix StateRetreiverTest

* Binding Adapter files are building with Gradle!

* Fixed ktlint violation

* Revert "Deleted kotlin binding adapters"

This reverts commit 84037cb.

* Revert "Translated GuidelineBindingAdapter"

This reverts commit ce92d0a.

* Revert "Translated StateAssemblerMarginBindingAdapters"

This reverts commit 88c9492.

* Revert "Translated StateAssemblerPaddingBindingAdapters"

This reverts commit d66af07.

* Git mv on DrawableBindingAdapters

* Translated DrawableBindingAdapters

* Deleted java files

* Translated EditTextBA and GuidelineBA

* Translated ImageViewBA

* Added missing semicolon

* Translated MarginBindingAdapters

* Translated State AssemblerMarginBA

* Translated StateAssemblerPaddingBA

* Translated TextViewBA

* Revert "Translated TextViewBA"

This reverts commit 849549d.

* Changed targetSdk to 28

* Revert "Revert "Translated TextViewBA""

This reverts commit 6cfa75d.

* Fixed formatting issues and changed NotNull to NonNull

* Refactored GuidelineBindingAdapter to be GuidelineBindingAdapters

* Fixed some double space errors and other typos

* Added missing ViewBindingAdapter

* Deleted extra spaces and fixed more nit issues

* Made all classes final

* Added top level documentation

* Reformatted some comments to fit java style

* Reformatted imports

* Created Issue and added TODOs for re-restricitng access

* Added min and target SDK to domain manifest

* Added documentation comment

* Deleted unused domain_tests library

* Revert "Deleted unused domain_tests library"

This reverts commit 65e71cc.

* Removed unused domain)tests library

* Annotations and helpers library builds

* Listeners library builds

* View models build

* Views now build

* Added documentation comments

* Started removing binding dependencies from views

* Removed fragment imports used only for comments in order to build view files

* Pulled binding dependenvy out of ConceptCardViewModel

* Edited R import statements for Bazel to build

* Fixed more errors, view_model builds

* Worked through more errors

* Added a dependency

* View library builds

* Ordered BUILD file for better merging

* Removed unused listeners

* Added missing comments

* Formatted files and added missing @nonnull annotations

* Fixed ktlint errors

* Revert "Formatted files and added missing @nonnull annotations"

This reverts commit 84b6125.

* Added genrule for viewmodel files

* Added view genrule

* Both Bazel and Gradle are building

* Fixed ktlint errors

* Delete vcs.xml

* Renamed files, deleted unused files, and added some documentation

* Improved implementation of some functions in ViewBindingShimImpl and added documentation

* Fixed ktlint errors

* Put genrules in a loop, created issue to remove genrules post-gradle and added TODO

* Added more documentation, created an issue to remove shim files, added TODO

* Fixed Gradle build error

* Added documentation, created an issue, added a TODO

* Formatted single line comments

* Fixing more nits

* Fixed more nits.

* Fixed getTimeAgo() function

* Suppressed warning in bindToRecyclerViewAdapter

* Simplified genrule

* Alphabetized lists in app module BUILD

* Added genrule comments, simplified gnerule targets in lists

* Fixed QuestionPlayerFragmentPresenter and StateFragmentPresenter

* Fixed QuestionPlayerViewModel & FRagmentPresenter as well as StateViewModel & FragmentPresenter

* Fixed some nits

* Fixed ktlint errors

* Added assets

* Fixed DragDrop ViewBinding implementations, added modules to TestComponent

* Fix ktlint errors

* Fixed nits in TextViewBA

* Testing module tests now pass, all domain tests pass except StateRetreiver

* Removed unused dependencies, aplhabetized dependencies

* Fixed merge errors

* Fixed nits

* Removed unnecessary field in StateFragmentAccessibilityTest

* Fixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTestFixed StateFragmentAccessibilityTest

* Injected context in AppVersionViewModel

* Used lambda function to resolve issues with QuestionPlayerVM and QuestionPlayerFragmentPresenter

* Fixed small errors

* Fixed ktlint error

* Fixed StateFragmentPresenter and view model, fixed some nits

* Fixed ktlint errors

* Fixed nits

* Fixed ktlint error
  • Loading branch information
miaboloix committed Aug 19, 2020
1 parent a084396 commit 71def98
Show file tree
Hide file tree
Showing 62 changed files with 1,313 additions and 263 deletions.
6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

33 changes: 32 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ git_repository(
load("@tools_android//tools/googleservices:defs.bzl", "google_services_workspace_dependencies")
google_services_workspace_dependencies()

git_repository(
name = "circularimageview",
commit = "6098dec76713b34eb8b10883cbe54189ddc08566",
remote = "https://github.com/oppia/CircularImageview",
)

bind(
name = "databinding_annotation_processor",
actual = "//tools/android:compiler_annotation_processor",
)

load("@rules_jvm_external//:defs.bzl", "maven_install")

maven_install(
Expand All @@ -112,27 +123,47 @@ maven_install(
"androidx.annotation:annotation:1.1.0",
"androidx.appcompat:appcompat:1.0.2",
"androidx.arch.core:core-testing:2.1.0",
"androidx.constraintlayout:constraintlayout:1.1.3",
"androidx.core:core-ktx:1.0.1",
"androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha03",
"androidx.core:core:1.0.1",
"androidx.databinding:databinding-adapters:3.4.2",
"androidx.databinding:databinding-common:3.4.2",
"androidx.databinding:databinding-runtime:3.4.2",
"androidx.lifecycle:lifecycle-extensions:2.2.0",
"androidx.lifecycle:lifecycle-livedata-core:2.2.0",
"androidx.lifecycle:lifecycle-livedata-ktx:2.2.0",
"androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0",
"androidx.multidex:multidex-instrumentation:2.0.0",
"androidx.multidex:multidex:2.0.1",
"androidx.recyclerview:recyclerview:1.0.0",
"androidx.test.espresso:espresso-contrib:3.1.0",
"androidx.test.espresso:espresso-core:3.2.0",
"androidx.test.espresso:espresso-intents:3.1.0",
"androidx.test.ext:junit:1.1.1",
"androidx.test:runner:1.2.0",
"androidx.viewpager:viewpager:1.0.0",
"com.android.support:support-annotations:28.0.0",
"com.caverock:androidsvg-aar:1.4",
"com.chaos.view:pinview:1.4.3",
"com.crashlytics.sdk.android:crashlytics:2.9.8",
"com.github.bumptech.glide:glide:4.11.0",
"com.google.android.material:material:1.2.0-alpha02",
"com.google.firebase:firebase-analytics:17.4.4",
"com.google.firebase:firebase-crashlytics:17.1.1",
"com.google.gms:google-services:4.3.3",
"com.google.truth:truth:0.43",
"com.squareup.retrofit2:converter-gson:2.5.0",
"com.squareup.retrofit2:retrofit:2.9.0",
"de.hdodenhof:circleimageview:3.0.1",
"io.fabric.sdk.android:fabric:1.4.7",
"javax.annotation:javax.annotation-api:jar:1.3.2",
"junit:junit:4.12",
"org.jetbrains.kotlin:kotlin-reflect:1.3.41",
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:jar:1.3.72",
"org.jetbrains.kotlin:kotlin-test-junit:1.3.72",
"org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2",
"org.jetbrains.kotlinx:kotlinx-coroutines-test:1.2.2",
"org.jetbrains:annotations:jar:13.0",
"org.mockito:mockito-core:2.19.0",
"org.robolectric:annotations:4.3",
"org.robolectric:robolectric:4.3",
Expand Down
338 changes: 334 additions & 4 deletions app/BUILD.bazel

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<!-- TODO(#56): Reenable landscape support. -->
<uses-sdk android:minSdkVersion="19"
android:maxSdkVersion="28" />
<application
android:name=".application.OppiaApplication"
android:allowBackup="true"
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/ViewModelManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- TODO(#1632): Remove manifest post-Gradle -->
<manifest xmlns:android="http:https://schemas.android.com/apk/res/android"
package="org.oppia.app.vm">
<uses-sdk android:minSdkVersion="19"
android:targetSdkVersion="28" />
</manifest>
7 changes: 7 additions & 0 deletions app/src/main/ViewsManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- TODO(#1632): Remove manifest post-Gradle -->
<manifest xmlns:android="http:https://schemas.android.com/apk/res/android"
package="org.oppia.app.views">
<uses-sdk android:minSdkVersion="19"
android:targetSdkVersion="28" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.oppia.app.administratorcontrols.administratorcontrolsitemviewmodel.Ad
import org.oppia.app.fragment.FragmentScope
import org.oppia.app.model.DeviceSettings
import org.oppia.app.model.ProfileId
import org.oppia.app.shim.IntentFactoryShim
import org.oppia.app.viewmodel.ObservableViewModel
import org.oppia.domain.profile.ProfileManagementController
import org.oppia.util.data.AsyncResult
Expand All @@ -26,7 +27,8 @@ class AdministratorControlsViewModel @Inject constructor(
private val activity: AppCompatActivity,
private val fragment: Fragment,
private val logger: ConsoleLogger,
private val profileManagementController: ProfileManagementController
private val profileManagementController: ProfileManagementController,
private val IntentFactoryShim: IntentFactoryShim
) : ObservableViewModel() {
private val routeToProfileListListener = activity as RouteToProfileListListener
private lateinit var userProfileId: ProfileId
Expand Down Expand Up @@ -72,7 +74,12 @@ class AdministratorControlsViewModel @Inject constructor(
)
)
itemViewModelList.add(AdministratorControlsAppInformationViewModel(activity))
itemViewModelList.add(AdministratorControlsAccountActionsViewModel(fragment))
itemViewModelList.add(
AdministratorControlsAccountActionsViewModel(
fragment,
IntentFactoryShim
)
)

return itemViewModelList
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import android.content.Intent
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import org.oppia.app.R
import org.oppia.app.profile.ProfileActivity
import org.oppia.app.shim.IntentFactoryShim

/** [ViewModel] for the recycler view in [AdministratorControlsFragment]. */
class AdministratorControlsAccountActionsViewModel(
private val fragment: Fragment
private val fragment: Fragment,
private val intentFactoryShim: IntentFactoryShim
) : AdministratorControlsItemViewModel() {

fun onLogOutClicked() {
Expand All @@ -19,7 +20,7 @@ class AdministratorControlsAccountActionsViewModel(
}
.setPositiveButton(R.string.log_out_dialog_okay_button) { _, _ ->
// TODO(#762): Replace [ProfileChooserActivity] to [LoginActivity] once it is added.
val intent = Intent(fragment.activity, ProfileActivity::class.java)
val intent = intentFactoryShim.createProfileActivityIntent(fragment.activity!!)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
fragment.activity!!.startActivity(intent)
fragment.activity!!.finish()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.oppia.app.administratorcontrols.appversion

import android.content.Context
import androidx.databinding.ObservableField
import androidx.fragment.app.Fragment
import org.oppia.app.BuildConfig
import androidx.lifecycle.ViewModel
import org.oppia.app.fragment.FragmentScope
import org.oppia.app.viewmodel.ObservableViewModel
import org.oppia.util.system.OppiaDateTimeFormatter
Expand All @@ -13,10 +14,12 @@ import javax.inject.Inject
@FragmentScope
class AppVersionViewModel @Inject constructor(
fragment: Fragment,
private val oppiaDateTimeFormatter: OppiaDateTimeFormatter
private val oppiaDateTimeFormatter: OppiaDateTimeFormatter,
context: Context
) : ObservableViewModel() {

val versionName = ObservableField<String>(BuildConfig.VERSION_NAME)
val versionName: String = context.packageManager
.getPackageInfo(context.packageName, 0).versionName

private val lastUpdateDateTime =
fragment.activity!!.packageManager.getPackageInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.app.Application
import dagger.BindsInstance
import dagger.Component
import org.oppia.app.activity.ActivityComponent
import org.oppia.app.shim.IntentFactoryShimModule
import org.oppia.app.shim.ViewBindingShimModule
import org.oppia.data.backends.gae.NetworkModule
import org.oppia.domain.classify.InteractionsModule
import org.oppia.domain.classify.rules.continueinteraction.ContinueModule
Expand Down Expand Up @@ -45,7 +47,8 @@ import javax.inject.Singleton
InteractionsModule::class, GcsResourceModule::class, GlideImageLoaderModule::class,
ImageParsingModule::class, HtmlParserEntityTypeModule::class, CachingModule::class,
QuestionModule::class, LogReportingModule::class, AccessibilityModule::class,
ImageClickInputModule::class, LogStorageModule::class, PrimeTopicAssetsControllerModule::class,
ImageClickInputModule::class, LogStorageModule::class, IntentFactoryShimModule::class,
ViewBindingShimModule::class, PrimeTopicAssetsControllerModule::class,
ExpirationMetaDataRetrieverModule::class
]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package org.oppia.app.customview
import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import org.oppia.app.R
import org.oppia.app.fragment.InjectableFragment
import org.oppia.app.model.LessonThumbnail
import org.oppia.app.model.LessonThumbnailGraphic
import org.oppia.app.shim.ViewComponentFactory
import org.oppia.util.gcsresource.DefaultResourceBucketName
import org.oppia.util.parser.DefaultGcsPrefix
import org.oppia.util.parser.ImageLoader
Expand Down Expand Up @@ -98,9 +99,8 @@ class LessonThumbnailImageView @JvmOverloads constructor(

override fun onAttachedToWindow() {
super.onAttachedToWindow()
FragmentManager.findFragment<InjectableFragment>(this)
.createViewComponent(this)
.inject(this)
(FragmentManager.findFragment<Fragment>(this) as ViewComponentFactory)
.createViewComponent(this).inject(this)
}

private fun getLessonDrawableResource(lessonThumbnail: LessonThumbnail): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
/** Holds all custom binding adapters that bind to [TextView]. */
public final class TextViewBindingAdapters {

private static int MINUTE_MILLIS = (int) TimeUnit.MINUTES.toMillis(1);

/** Binds date text with relative time. */
@BindingAdapter("profile:created")
public static void setProfileDataText(@NonNull TextView textView, long timestamp) {
Expand Down Expand Up @@ -57,7 +55,7 @@ private static String getTimeAgo(long lastVisitedTimeStamp, Context context) {
Resources res = context.getResources();
long timeDifferenceMillis = currentTimeMillis - timeStampMillis;

if (timeDifferenceMillis < MINUTE_MILLIS) {
if (timeDifferenceMillis < (int) TimeUnit.MINUTES.toMillis(1)) {
return context.getString(R.string.just_now);
} else if (timeDifferenceMillis < TimeUnit.MINUTES.toMillis(50)) {
return getPluralString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import org.oppia.app.profile.AdminSettingsDialogFragment
import org.oppia.app.profile.ProfileChooserFragment
import org.oppia.app.profile.ResetPinDialogFragment
import org.oppia.app.profileprogress.ProfileProgressFragment
import org.oppia.app.shim.IntentFactoryShimModule
import org.oppia.app.shim.ViewBindingShimModule
import org.oppia.app.story.StoryFragment
import org.oppia.app.testing.BindableAdapterTestFragment
import org.oppia.app.testing.ImageRegionSelectionTestFragment
Expand All @@ -51,7 +53,12 @@ import org.oppia.app.walkthrough.welcome.WalkthroughWelcomeFragment
import javax.inject.Provider

/** Root subcomponent for all fragments. */
@Subcomponent(modules = [FragmentModule::class, InteractionViewModelModule::class])
@Subcomponent(
modules = [
FragmentModule::class, InteractionViewModelModule::class, IntentFactoryShimModule::class,
ViewBindingShimModule::class
]
)
@FragmentScope
interface FragmentComponent {
@Subcomponent.Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import android.content.Context
import android.view.View
import androidx.fragment.app.Fragment
import org.oppia.app.activity.InjectableAppCompatActivity
import org.oppia.app.shim.ViewComponentFactory
import org.oppia.app.view.ViewComponent

/**
* A fragment that facilitates field injection to children. This fragment can only be used with
* [InjectableAppCompatActivity] contexts.
*/
abstract class InjectableFragment : Fragment() {
abstract class InjectableFragment : Fragment(), ViewComponentFactory {
/**
* The [FragmentComponent] corresponding to this fragment. This cannot be used before [onAttach] is called, and can be
* used to inject lateinit fields in child fragments during fragment attachment (which is recommended to be done in an
Expand All @@ -24,7 +25,7 @@ abstract class InjectableFragment : Fragment() {
(requireActivity() as InjectableAppCompatActivity).createFragmentComponent(this)
}

fun createViewComponent(view: View): ViewComponent {
override fun createViewComponent(view: View): ViewComponent {
return fragmentComponent.getViewComponentBuilderProvider().get().setView(view).build()
}
}
22 changes: 19 additions & 3 deletions app/src/main/java/org/oppia/app/home/HomeFragmentPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.oppia.app.model.Profile
import org.oppia.app.model.ProfileId
import org.oppia.app.model.TopicList
import org.oppia.app.model.TopicSummary
import org.oppia.app.shim.IntentFactoryShim
import org.oppia.domain.oppialogger.OppiaLogger
import org.oppia.domain.profile.ProfileManagementController
import org.oppia.domain.topic.TopicListController
Expand All @@ -46,6 +47,7 @@ class HomeFragmentPresenter @Inject constructor(
private val oppiaClock: OppiaClock,
private val logger: ConsoleLogger,
private val oppiaLogger: OppiaLogger,
private val intentFactoryShim: IntentFactoryShim,
@TopicHtmlParserEntityType private val topicEntityType: String,
@StoryHtmlParserEntityType private val storyEntityType: String
) {
Expand All @@ -71,7 +73,11 @@ class HomeFragmentPresenter @Inject constructor(
logHomeActivityEvent()

welcomeViewModel = WelcomeViewModel()
promotedStoryListViewModel = PromotedStoryListViewModel(activity, internalProfileId)
promotedStoryListViewModel = PromotedStoryListViewModel(
activity,
internalProfileId,
intentFactoryShim
)
allTopicsViewModel = AllTopicsViewModel()
itemList.add(welcomeViewModel)
itemList.add(promotedStoryListViewModel)
Expand Down Expand Up @@ -191,14 +197,24 @@ class HomeFragmentPresenter @Inject constructor(
promotedStoryList.clear()
if (it.recentStoryCount != 0) {
it.recentStoryList.take(limit).forEach { promotedStory ->
val recentStory = PromotedStoryViewModel(activity, internalProfileId, storyEntityType)
val recentStory = PromotedStoryViewModel(
activity,
internalProfileId,
storyEntityType,
intentFactoryShim
)
recentStory.setPromotedStory(promotedStory)
promotedStoryList.add(recentStory)
}
} else {
// TODO(#936): Optimise this as part of recommended stories.
it.olderStoryList.take(limit).forEach { promotedStory ->
val oldStory = PromotedStoryViewModel(activity, internalProfileId, storyEntityType)
val oldStory = PromotedStoryViewModel(
activity,
internalProfileId,
storyEntityType,
intentFactoryShim
)
oldStory.setPromotedStory(promotedStory)
promotedStoryList.add(oldStory)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModel
import org.oppia.app.home.HomeItemViewModel
import org.oppia.app.home.RouteToRecentlyPlayedListener
import org.oppia.app.home.recentlyplayed.RecentlyPlayedActivity
import org.oppia.app.shim.IntentFactoryShim

/** [ViewModel] promoted story list in [HomeFragment]. */
class PromotedStoryListViewModel(
private val activity: AppCompatActivity,
private val internalProfileId: Int
private val internalProfileId: Int,
private val IntentFactoryShim: IntentFactoryShim
) :
HomeItemViewModel(),
RouteToRecentlyPlayedListener {
Expand All @@ -19,11 +20,10 @@ class PromotedStoryListViewModel(
}

override fun routeToRecentlyPlayed() {
activity.startActivity(
RecentlyPlayedActivity.createRecentlyPlayedActivityIntent(
activity.applicationContext,
internalProfileId
)
val intent = IntentFactoryShim.createRecentlyPlayedActivityIntent(
activity.applicationContext,
internalProfileId
)
activity.startActivity(intent)
}
}
Loading

0 comments on commit 71def98

Please sign in to comment.