Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/video_quality
Browse files Browse the repository at this point in the history
  • Loading branch information
PavloNetrebchuk committed Oct 27, 2023
2 parents 90169af + 3170de0 commit 5532eaf
Show file tree
Hide file tree
Showing 44 changed files with 1,199 additions and 49 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ dependencies {
implementation project(path: ':discovery')
implementation project(path: ':profile')
implementation project(path: ':discussion')
implementation project(path: ':whatsnew')

kapt "androidx.room:room-compiler:$room_version"

Expand Down
47 changes: 32 additions & 15 deletions app/src/main/java/org/openedx/app/AppActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import org.openedx.core.presentation.global.WindowSizeHolder
import org.openedx.core.ui.WindowSize
import org.openedx.core.ui.WindowType
import org.openedx.profile.presentation.ProfileRouter
import org.openedx.whatsnew.WhatsNewFileManager
import org.openedx.whatsnew.data.storage.WhatsNewPreferences
import org.openedx.whatsnew.presentation.whatsnew.WhatsNewFragment

class AppActivity : AppCompatActivity(), InsetHolder, WindowSizeHolder, AppDataHolder {

Expand All @@ -41,8 +44,10 @@ class AppActivity : AppCompatActivity(), InsetHolder, WindowSizeHolder, AppDataH
get() = AppData(BuildConfig.VERSION_NAME)

private lateinit var binding: ActivityAppBinding
private val preferencesManager by inject<CorePreferences>()
private val viewModel by viewModel<AppViewModel>()
private val whatsNewFileManager by inject<WhatsNewFileManager>()
private val whatsNewPreferencesManager by inject<WhatsNewPreferences>()
private val corePreferencesManager by inject<CorePreferences>()
private val profileRouter by inject<ProfileRouter>()

private var _insetTop = 0
Expand Down Expand Up @@ -110,14 +115,22 @@ class AppActivity : AppCompatActivity(), InsetHolder, WindowSizeHolder, AppDataH
binding.root.requestApplyInsetsWhenAttached()

if (savedInstanceState == null) {
if (preferencesManager.user != null) {
supportFragmentManager.beginTransaction()
.add(R.id.container, MainFragment())
.commit()
} else {
supportFragmentManager.beginTransaction()
.add(R.id.container, SignInFragment())
.commit()
when {
corePreferencesManager.user == null -> {
supportFragmentManager.beginTransaction()
.add(R.id.container, SignInFragment())
.commit()
}
shouldShowWhatsNew() -> {
supportFragmentManager.beginTransaction()
.add(R.id.container, WhatsNewFragment())
.commit()
}
corePreferencesManager.user != null -> {
supportFragmentManager.beginTransaction()
.add(R.id.container, MainFragment())
.commit()
}
}
}

Expand All @@ -130,16 +143,14 @@ class AppActivity : AppCompatActivity(), InsetHolder, WindowSizeHolder, AppDataH
val metrics = WindowMetricsCalculator.getOrCreate()
.computeCurrentWindowMetrics(this)

val widthDp = metrics.bounds.width() /
resources.displayMetrics.density
val widthDp = metrics.bounds.width() / resources.displayMetrics.density
val widthWindowSize = when {
widthDp < 600f -> WindowType.Compact
widthDp < 840f -> WindowType.Medium
else -> WindowType.Expanded
}

val heightDp = metrics.bounds.height() /
resources.displayMetrics.density
val heightDp = metrics.bounds.height() / resources.displayMetrics.density
val heightWindowSize = when {
heightDp < 480f -> WindowType.Compact
heightDp < 900f -> WindowType.Medium
Expand All @@ -149,15 +160,21 @@ class AppActivity : AppCompatActivity(), InsetHolder, WindowSizeHolder, AppDataH
}

private fun isUsingNightModeResources(): Boolean {
return when (resources.configuration.uiMode and
Configuration.UI_MODE_NIGHT_MASK) {
return when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_YES -> true
Configuration.UI_MODE_NIGHT_NO -> false
Configuration.UI_MODE_NIGHT_UNDEFINED -> false
else -> false
}
}

override fun shouldShowWhatsNew(): Boolean {
val dataVersion = whatsNewFileManager.getNewestData().version
return BuildConfig.VERSION_NAME == dataVersion
&& whatsNewPreferencesManager.lastWhatsNewVersion != dataVersion
&& org.openedx.core.BuildConfig.SHOW_WHATS_NEW
}

companion object {
const val TOP_INSET = "topInset"
const val BOTTOM_INSET = "bottomInset"
Expand Down
17 changes: 13 additions & 4 deletions app/src/main/java/org/openedx/app/AppRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.openedx.auth.presentation.restore.RestorePasswordFragment
import org.openedx.auth.presentation.signin.SignInFragment
import org.openedx.auth.presentation.signup.SignUpFragment
import org.openedx.core.FragmentViewType
import org.openedx.profile.domain.model.Account
import org.openedx.core.domain.model.CoursewareAccess
import org.openedx.core.presentation.course.CourseViewMode
import org.openedx.course.presentation.CourseRouter
Expand All @@ -17,13 +16,13 @@ import org.openedx.course.presentation.container.NoAccessCourseContainerFragment
import org.openedx.course.presentation.detail.CourseDetailsFragment
import org.openedx.course.presentation.handouts.HandoutsType
import org.openedx.course.presentation.handouts.WebViewFragment
import org.openedx.discovery.presentation.search.CourseSearchFragment
import org.openedx.course.presentation.section.CourseSectionFragment
import org.openedx.course.presentation.unit.container.CourseUnitContainerFragment
import org.openedx.course.presentation.unit.video.VideoFullScreenFragment
import org.openedx.course.presentation.unit.video.YoutubeVideoFullScreenFragment
import org.openedx.dashboard.presentation.DashboardRouter
import org.openedx.discovery.presentation.DiscoveryRouter
import org.openedx.discovery.presentation.search.CourseSearchFragment
import org.openedx.discussion.domain.model.DiscussionComment
import org.openedx.discussion.domain.model.Thread
import org.openedx.discussion.presentation.DiscussionRouter
Expand All @@ -32,16 +31,19 @@ import org.openedx.discussion.presentation.responses.DiscussionResponsesFragment
import org.openedx.discussion.presentation.search.DiscussionSearchThreadFragment
import org.openedx.discussion.presentation.threads.DiscussionAddThreadFragment
import org.openedx.discussion.presentation.threads.DiscussionThreadsFragment
import org.openedx.profile.domain.model.Account
import org.openedx.profile.presentation.ProfileRouter
import org.openedx.profile.presentation.anothers_account.AnothersProfileFragment
import org.openedx.profile.presentation.delete.DeleteProfileFragment
import org.openedx.profile.presentation.edit.EditProfileFragment
import org.openedx.profile.presentation.settings.video.VideoQualityFragment
import org.openedx.profile.presentation.settings.video.VideoSettingsFragment
import java.util.*
import org.openedx.whatsnew.WhatsNewRouter
import org.openedx.whatsnew.presentation.whatsnew.WhatsNewFragment
import java.util.Date

class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, DiscussionRouter,
ProfileRouter {
ProfileRouter, WhatsNewRouter {

//region AuthRouter
override fun navigateToMain(fm: FragmentManager) {
Expand All @@ -58,6 +60,13 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
override fun navigateToRestorePassword(fm: FragmentManager) {
replaceFragmentWithBackStack(fm, RestorePasswordFragment())
}

override fun navigateToWhatsNew(fm: FragmentManager) {
fm.popBackStack()
fm.beginTransaction()
.replace(R.id.container, WhatsNewFragment())
.commit()
}
//endregion

//region DiscoveryRouter
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/org/openedx/app/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.viewModelScope
import androidx.room.RoomDatabase
import org.openedx.core.BaseViewModel
import org.openedx.core.SingleEventLiveData
import org.openedx.app.system.notifier.AppNotifier
import org.openedx.app.system.notifier.LogoutEvent
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.openedx.app.system.notifier.AppNotifier
import org.openedx.app.system.notifier.LogoutEvent
import org.openedx.core.BaseViewModel
import org.openedx.core.SingleEventLiveData
import org.openedx.core.data.storage.CorePreferences

class AppViewModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import org.openedx.profile.data.model.Account
import org.openedx.core.data.model.User
import org.openedx.core.domain.model.VideoSettings
import org.openedx.profile.data.storage.ProfilePreferences
import org.openedx.whatsnew.data.storage.WhatsNewPreferences

class PreferencesManager(context: Context) : CorePreferences, ProfilePreferences {
class PreferencesManager(context: Context) : CorePreferences, ProfilePreferences, WhatsNewPreferences {

private val sharedPreferences = context.getSharedPreferences(BuildConfig.APPLICATION_ID, Context.MODE_PRIVATE)

Expand Down Expand Up @@ -72,11 +73,18 @@ class PreferencesManager(context: Context) : CorePreferences, ProfilePreferences
?: VideoSettings.default
}

override var lastWhatsNewVersion: String
set(value) {
saveString(LAST_WHATS_NEW_VERSION, value)
}
get() = getString(LAST_WHATS_NEW_VERSION)

companion object {
private const val ACCESS_TOKEN = "access_token"
private const val REFRESH_TOKEN = "refresh_token"
private const val USER = "user"
private const val ACCOUNT = "account"
private const val VIDEO_SETTINGS = "video_settings"
private const val LAST_WHATS_NEW_VERSION = "last_whats_new_version"
}
}
6 changes: 6 additions & 0 deletions app/src/main/java/org/openedx/app/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ import org.koin.core.qualifier.named
import org.koin.dsl.module
import org.openedx.core.data.storage.CorePreferences
import org.openedx.profile.data.storage.ProfilePreferences
import org.openedx.whatsnew.WhatsNewFileManager
import org.openedx.whatsnew.WhatsNewRouter
import org.openedx.whatsnew.data.storage.WhatsNewPreferences

val appModule = module {

single { PreferencesManager(get()) }
single<CorePreferences> { get<PreferencesManager>() }
single<ProfilePreferences> { get<PreferencesManager>() }
single<WhatsNewPreferences> { get<PreferencesManager>() }

single { ResourceManager(get()) }

Expand All @@ -63,6 +67,7 @@ val appModule = module {
single<CourseRouter> { get<AppRouter>() }
single<DiscussionRouter> { get<AppRouter>() }
single<ProfileRouter> { get<AppRouter>() }
single<WhatsNewRouter> { get<AppRouter>() }


single { NetworkConnection(get()) }
Expand Down Expand Up @@ -114,6 +119,7 @@ val appModule = module {
}

single { TranscriptManager(get()) }
single { WhatsNewFileManager(get()) }

single { AnalyticsManager(get()) }
single<DashboardAnalytics> { get<AnalyticsManager>() }
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/org/openedx/app/di/ScreenModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import org.koin.dsl.module
import org.openedx.course.presentation.unit.video.EncodedVideoUnitViewModel
import org.openedx.course.presentation.unit.video.VideoUnitViewModel
import org.openedx.profile.presentation.anothers_account.AnothersProfileViewModel
import org.openedx.whatsnew.presentation.whatsnew.WhatsNewViewModel

val screenModule = module {

Expand Down Expand Up @@ -100,4 +101,6 @@ val screenModule = module {
viewModel { (comment: DiscussionComment) -> DiscussionResponsesViewModel(get(), get(), get(), comment) }
viewModel { (courseId: String) -> DiscussionAddThreadViewModel(get(), get(), get(), courseId) }
viewModel { (courseId: String) -> DiscussionSearchThreadViewModel(get(), get(), get(), courseId) }

viewModel { WhatsNewViewModel(get()) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ interface AuthRouter {
fun navigateToSignUp(fm: FragmentManager)

fun navigateToRestorePassword(fm: FragmentManager)

fun navigateToWhatsNew(fm : FragmentManager)
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import org.openedx.core.ui.theme.appShapes
import org.openedx.core.ui.theme.appTypography
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.openedx.core.presentation.global.AppDataHolder

class SignInFragment : Fragment() {

Expand Down Expand Up @@ -82,8 +83,13 @@ class SignInFragment : Fragment() {
)

LaunchedEffect(loginSuccess) {
val isNeedToShowWhatsNew = (requireActivity() as AppDataHolder).shouldShowWhatsNew()
if (loginSuccess) {
router.navigateToMain(parentFragmentManager)
if (isNeedToShowWhatsNew) {
router.navigateToWhatsNew(parentFragmentManager)
} else {
router.navigateToMain(parentFragmentManager)
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ platformName: "OpenEdX"
platformFullName: "OpenEdX"
#tokenType enum accepts JWT and BEARER only
tokenType: "JWT"
#feature flag for activating What’s New feature
showWhatsNew: false
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ android {
consumerProguardFiles "consumer-rules.pro"

buildConfigField "String", "ACCESS_TOKEN_TYPE", "\"${config.tokenType}\""
buildConfigField "Boolean", "SHOW_WHATS_NEW", "${config.showWhatsNew}"
}

namespace 'org.openedx.core'
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/openedx/core/module/DownloadWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class DownloadWorker(
return ForegroundInfo(
NOTIFICATION_ID,
notificationBuilder
.setSmallIcon(R.drawable.core_ic_check)
.setSmallIcon(R.drawable.core_ic_check_in_box)
.setProgress(100, 0, false)
.setPriority(NotificationManager.IMPORTANCE_LOW)
.setContentText(context.getString(R.string.core_downloading_in_progress))
Expand All @@ -80,7 +80,7 @@ class DownloadWorker(
notificationManager.notify(
NOTIFICATION_ID,
notificationBuilder
.setSmallIcon(R.drawable.core_ic_check)
.setSmallIcon(R.drawable.core_ic_check_in_box)
.setProgress(100, value.toInt(), false)
.setPriority(NotificationManager.IMPORTANCE_LOW)
.setContentText(context.getString(R.string.core_downloading_in_progress))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.openedx.core.presentation.global

interface AppDataHolder {
val appData: AppData
fun shouldShowWhatsNew(): Boolean
}

data class AppData(
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/org/openedx/core/ui/ComposeExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package org.openedx.core.ui
import android.content.res.Configuration
import android.graphics.Rect
import android.view.ViewTreeObserver
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.MutatePriority
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.pager.PagerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.MutableState
Expand Down Expand Up @@ -173,3 +175,7 @@ fun LazyListState.reEnableScrolling(scope: CoroutineScope) {
}
}

@OptIn(ExperimentalFoundationApi::class)
fun PagerState.calculateCurrentOffsetForPage(page: Int): Float {
return (currentPage - page) + currentPageOffsetFraction
}
6 changes: 3 additions & 3 deletions core/src/main/res/drawable/core_ic_back.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
android:strokeLineJoin="round"
android:strokeWidth="1.75"
android:fillColor="#00000000"
android:strokeColor="#19212F"
android:strokeColor="#ffffff"
android:strokeLineCap="round"/>
<path
android:pathData="M11,18L5,12"
android:strokeLineJoin="round"
android:strokeWidth="1.75"
android:fillColor="#00000000"
android:strokeColor="#19212F"
android:strokeColor="#ffffff"
android:strokeLineCap="round"/>
<path
android:pathData="M11,6L5,12"
android:strokeLineJoin="round"
android:strokeWidth="1.75"
android:fillColor="#00000000"
android:strokeColor="#19212F"
android:strokeColor="#ffffff"
android:strokeLineCap="round"/>
</group>
</vector>
Loading

0 comments on commit 5532eaf

Please sign in to comment.