-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Update selection_interaction_item.xml * Update selection_interaction_item.xml * Update return_to_topic_button_item.xml * Update return_to_topic_button_item.xml * fix rtl support in ongoing story card * Update ongoing_story_card.xml * Update MarginBindingAdapters.java * Update OngoingStoryViewModel.kt * Update MarginBindingAdapters.java * Update OngoingListAdapter.kt * Update OngoingListAdapter.kt * added testcases * Fixed testcases * Update RecentlyPlayedFragmentTest.kt * Update app/src/sharedTest/java/org/oppia/android/app/home/RecentlyPlayedFragmentTest.kt Co-authored-by: Ben Henning <[email protected]> * Update RecentlyPlayedFragmentTest.kt * fixed nits * Update BUILD.bazel * Update BUILD.bazel * Update RecentlyPlayedFragmentTest.kt Co-authored-by: Ben Henning <[email protected]>
- Loading branch information
1 parent
77ff836
commit 86d0d1f
Showing
9 changed files
with
383 additions
and
111 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
84 changes: 83 additions & 1 deletion
84
app/src/main/java/org/oppia/android/app/home/recentlyplayed/OngoingStoryViewModel.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 |
---|---|---|
@@ -1,18 +1,100 @@ | ||
package org.oppia.android.app.home.recentlyplayed | ||
|
||
import android.view.View | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.lifecycle.ViewModel | ||
import org.oppia.android.R | ||
import org.oppia.android.app.model.PromotedStory | ||
|
||
// TODO(#297): Add download status information to promoted-story-card. | ||
|
||
/** [ViewModel] for displaying a promoted story. */ | ||
class OngoingStoryViewModel( | ||
private val activity: AppCompatActivity, | ||
val ongoingStory: PromotedStory, | ||
val entityType: String, | ||
private val ongoingStoryClickListener: OngoingStoryClickListener | ||
private val ongoingStoryClickListener: OngoingStoryClickListener, | ||
private val position: Int | ||
) : RecentlyPlayedItemViewModel() { | ||
fun clickOnOngoingStoryTile(@Suppress("UNUSED_PARAMETER") v: View) { | ||
ongoingStoryClickListener.onOngoingStoryClicked(ongoingStory) | ||
} | ||
|
||
private val outerMargin by lazy { | ||
activity.resources.getDimensionPixelSize(R.dimen.recently_played_margin_max) | ||
} | ||
private val innerMargin by lazy { | ||
activity.resources.getDimensionPixelSize(R.dimen.recently_played_margin_min) | ||
} | ||
private val spanCount by lazy { | ||
activity.resources.getInteger(R.integer.recently_played_span_count) | ||
} | ||
|
||
/** | ||
* Determines the start margin for an individual TopicSummary relative to the grid columns laid out on the | ||
* HomeActivity. GridLayout columns are evenly spread out across the entire activity screen but the | ||
* Topic Summaries are positioned towards the center, so start margins are calculated to stagger inside each | ||
* fixed column but centered on the activity's layout, as shown below. | ||
* | ||
* | _____| _____ | _____ |_____ | | ||
* | | | | | | | | | | | | ||
* | | | | | | | | | | | | ||
* | |_____| |_____| | |_____| |_____| | | ||
* | | | | | | ||
* | _____ _____ _____ _____ | | ||
* | | | | | | | | | | | ||
* | | | | | | | | | | | ||
* | |_____| |_____| |_____| |_____| | | ||
* | | | ||
*/ | ||
fun computeStartMargin(): Int { | ||
return when (spanCount) { | ||
2 -> when (position % spanCount) { | ||
0 -> outerMargin | ||
else -> innerMargin | ||
} | ||
3 -> when (position % spanCount) { | ||
0 -> outerMargin | ||
1 -> innerMargin | ||
2 -> 0 | ||
else -> 0 | ||
} | ||
4 -> when (position % spanCount) { | ||
0 -> outerMargin | ||
1 -> innerMargin | ||
2 -> innerMargin / 2 | ||
3 -> 0 | ||
else -> 0 | ||
} | ||
else -> 0 | ||
} | ||
} | ||
|
||
/** | ||
* Determines the end margin for an individual TopicSummary relative to the grid columns laid out on the | ||
* HomeActivity. The end margins are calculated to stagger inside each fixed column but centered on the | ||
* activity's layout (see [computeStartMargin]). | ||
*/ | ||
fun computeEndMargin(): Int { | ||
return when (spanCount) { | ||
2 -> when (position % spanCount) { | ||
0 -> innerMargin | ||
else -> outerMargin | ||
} | ||
3 -> when (position % spanCount) { | ||
0 -> 0 | ||
1 -> innerMargin | ||
2 -> outerMargin | ||
else -> 0 | ||
} | ||
4 -> when (position % spanCount) { | ||
0 -> 0 | ||
1 -> innerMargin / 2 | ||
2 -> innerMargin | ||
3 -> outerMargin | ||
else -> 0 | ||
} | ||
else -> 0 | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.