Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/app_update
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/src/main/java/org/openedx/app/AppRouter.kt
#	app/src/main/java/org/openedx/app/di/AppModule.kt
#	app/src/main/java/org/openedx/app/di/ScreenModule.kt
#	auth/src/main/java/org/openedx/auth/presentation/signin/SignInFragment.kt
  • Loading branch information
PavloNetrebchuk committed Oct 27, 2023
2 parents 3ac8dd0 + 3170de0 commit 5405108
Show file tree
Hide file tree
Showing 43 changed files with 1,198 additions and 44 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
44 changes: 31 additions & 13 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 @@ -157,6 +168,13 @@ class AppActivity : AppCompatActivity(), InsetHolder, WindowSizeHolder, AppDataH
}
}

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.core.presentation.global.app_upgrade.AppUpgradeRouter
Expand All @@ -19,13 +18,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 @@ -34,17 +33,20 @@ 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.profile.ProfileFragment
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, AppUpgradeRouter {
ProfileRouter, AppUpgradeRouter, WhatsNewRouter {

//region AuthRouter
override fun navigateToMain(fm: FragmentManager) {
Expand All @@ -61,6 +63,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
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 @@ -71,11 +72,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 @@ -40,12 +40,16 @@ import org.openedx.core.data.storage.CorePreferences
import org.openedx.core.presentation.global.app_upgrade.AppUpgradeRouter
import org.openedx.core.system.notifier.AppUpgradeNotifier
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 @@ -66,6 +70,7 @@ val appModule = module {
single<CourseRouter> { get<AppRouter>() }
single<DiscussionRouter> { get<AppRouter>() }
single<ProfileRouter> { get<AppRouter>() }
single<WhatsNewRouter> { get<AppRouter>() }
single<AppUpgradeRouter> { get<AppRouter>() }


Expand Down Expand Up @@ -118,6 +123,7 @@ val appModule = module {
}

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

single { AnalyticsManager(get()) }
single<DashboardAnalytics> { get<AnalyticsManager>() }
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/org/openedx/app/di/ScreenModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ import org.openedx.discussion.presentation.topics.DiscussionTopicsViewModel
import org.openedx.profile.data.repository.ProfileRepository
import org.openedx.profile.domain.interactor.ProfileInteractor
import org.openedx.profile.domain.model.Account
import org.openedx.profile.presentation.anothers_account.AnothersProfileViewModel
import org.openedx.profile.presentation.delete.DeleteProfileViewModel
import org.openedx.profile.presentation.edit.EditProfileViewModel
import org.openedx.profile.presentation.profile.ProfileViewModel
import org.openedx.profile.presentation.settings.video.VideoQualityViewModel
import org.openedx.profile.presentation.settings.video.VideoSettingsViewModel
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 @@ -76,6 +76,9 @@ import org.openedx.core.ui.theme.appShapes
import org.openedx.core.ui.theme.appTypography
import org.openedx.core.ui.windowSizeValue
import org.openedx.core.AppUpdateState
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 @@ -116,10 +119,16 @@ 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)
}
}
}

} else {
AppUpgradeRequiredScreen(
onUpdateClick = {
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>
26 changes: 11 additions & 15 deletions core/src/main/res/drawable/core_ic_check.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<group>
<clip-path
android:pathData="M0,0h24v24h-24z"/>
<path
android:pathData="M9,11L12,14L20,6M20,12V18C20,18.53 19.789,19.039 19.414,19.414C19.039,19.789 18.53,20 18,20H6C5.47,20 4.961,19.789 4.586,19.414C4.211,19.039 4,18.53 4,18V6C4,5.47 4.211,4.961 4.586,4.586C4.961,4.211 5.47,4 6,4H15"
android:strokeLineJoin="round"
android:strokeWidth="1.75"
android:fillColor="#00000000"
android:strokeColor="#ffffff"
android:strokeLineCap="round"/>
</group>
android:width="18dp"
android:height="12dp"
android:viewportWidth="18"
android:viewportHeight="12">
<path
android:pathData="M1.5,6L6.5,11L16.5,1"
android:strokeLineJoin="round"
android:strokeWidth="1.75"
android:fillColor="#00000000"
android:strokeColor="#ffffff"
android:strokeLineCap="round"/>
</vector>
Loading

0 comments on commit 5405108

Please sign in to comment.