Skip to content

Commit

Permalink
Minor review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PavloNetrebchuk committed Nov 1, 2023
1 parent 5405108 commit 0777de9
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 60 deletions.
14 changes: 7 additions & 7 deletions app/src/main/java/org/openedx/app/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.setFragmentResultListener
import androidx.viewpager2.widget.ViewPager2
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.openedx.app.adapter.MainNavigationFragmentAdapter
import org.openedx.app.databinding.FragmentMainBinding
import org.openedx.core.presentation.global.app_upgrade.UpgradeRequiredFragment
Expand All @@ -18,23 +19,18 @@ class MainFragment : Fragment(R.layout.fragment_main) {

private val binding by viewBinding(FragmentMainBinding::bind)
private val analytics by inject<AppAnalytics>()
private val viewModel by viewModel<MainViewModel>()

private lateinit var adapter: MainNavigationFragmentAdapter
private var isBottomBarEnabled = true

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setFragmentResultListener(UpgradeRequiredFragment.REQUEST_KEY) { _, _ ->
binding.bottomNavView.selectedItemId = R.id.fragmentProfile
isBottomBarEnabled = false
viewModel.enableBottomBar(false)
}
}

override fun onResume() {
enableBottomBar(isBottomBarEnabled)
super.onResume()
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

Expand Down Expand Up @@ -64,6 +60,10 @@ class MainFragment : Fragment(R.layout.fragment_main) {
}
true
}

viewModel.isBottomBarEnabled.observe(viewLifecycleOwner) { isBottomBarEnabled ->
enableBottomBar(isBottomBarEnabled)
}
}

private fun initViewPager() {
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/org/openedx/app/MainViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.openedx.app

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import org.openedx.core.BaseViewModel

class MainViewModel: BaseViewModel() {
private val _isBottomBarEnabled = MutableLiveData(true)
val isBottomBarEnabled: LiveData<Boolean>
get() = _isBottomBarEnabled

fun enableBottomBar(enable: Boolean) {
_isBottomBarEnabled.value = enable
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.openedx.app.data.networking

import android.content.Context
import okhttp3.Interceptor
import okhttp3.Response
import org.openedx.app.BuildConfig
import org.openedx.core.data.storage.CorePreferences
import org.openedx.core.BuildConfig.ACCESS_TOKEN_TYPE
import org.openedx.core.data.storage.CorePreferences

class HeadersInterceptor(private val preferencesManager: CorePreferences) : Interceptor {
class HeadersInterceptor(private val context: Context, private val preferencesManager: CorePreferences) : Interceptor {

override fun intercept(chain: Interceptor.Chain): Response = chain.run {
proceed(
Expand All @@ -19,12 +20,10 @@ class HeadersInterceptor(private val preferencesManager: CorePreferences) : Inte
}

addHeader("Accept", "application/json")
//TODO
addHeader(
"User-Agent", System.getProperty("http.agent") + " " +
// context.getString(org.openedx.core.R.string.app_name) + "/" +
"edX" + "/" +
"org.edx.mobile" + "/" +
"User-Agent", System.getProperty("http.agent") + " " +
context.getString(org.openedx.core.R.string.app_name) + "/" +
BuildConfig.APPLICATION_ID + "/" +
BuildConfig.VERSION_NAME
)
}.build()
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/org/openedx/app/di/NetworkingModule.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package org.openedx.app.di

import org.openedx.auth.data.api.AuthApi
import org.openedx.core.data.api.CookiesApi
import org.openedx.core.data.api.CourseApi
import org.openedx.discussion.data.api.DiscussionApi
import org.openedx.app.data.networking.HandleErrorInterceptor
import org.openedx.app.data.networking.HeadersInterceptor
import org.openedx.app.data.networking.OauthRefreshTokenAuthenticator
import org.openedx.profile.data.api.ProfileApi
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.koin.dsl.module
import org.openedx.app.data.networking.AppUpgradeInterceptor
import org.openedx.app.data.networking.HandleErrorInterceptor
import org.openedx.app.data.networking.HeadersInterceptor
import org.openedx.app.data.networking.OauthRefreshTokenAuthenticator
import org.openedx.auth.data.api.AuthApi
import org.openedx.core.BuildConfig
import org.openedx.core.data.api.CookiesApi
import org.openedx.core.data.api.CourseApi
import org.openedx.discussion.data.api.DiscussionApi
import org.openedx.profile.data.api.ProfileApi
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit
Expand All @@ -25,7 +25,7 @@ val networkingModule = module {
OkHttpClient.Builder().apply {
writeTimeout(60, TimeUnit.SECONDS)
readTimeout(60, TimeUnit.SECONDS)
addInterceptor(HeadersInterceptor(get()))
addInterceptor(HeadersInterceptor(get(), get()))
if (BuildConfig.DEBUG) {
addNetworkInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
}
Expand Down
4 changes: 3 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 @@ -4,13 +4,14 @@ import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.core.qualifier.named
import org.koin.dsl.module
import org.openedx.app.AppViewModel
import org.openedx.app.MainViewModel
import org.openedx.auth.data.repository.AuthRepository
import org.openedx.auth.domain.interactor.AuthInteractor
import org.openedx.auth.presentation.restore.RestorePasswordViewModel
import org.openedx.auth.presentation.signin.SignInViewModel
import org.openedx.auth.presentation.signup.SignUpViewModel
import org.openedx.core.Validator
import org.openedx.core.presentation.dialog.select_bottom.SelectDialogViewModel
import org.openedx.core.presentation.dialog.selectorbottomsheet.SelectDialogViewModel
import org.openedx.course.data.repository.CourseRepository
import org.openedx.course.domain.interactor.CourseInteractor
import org.openedx.course.presentation.container.CourseContainerViewModel
Expand Down Expand Up @@ -53,6 +54,7 @@ import org.openedx.whatsnew.presentation.whatsnew.WhatsNewViewModel
val screenModule = module {

viewModel { AppViewModel(get(), get(), get(), get(named("IODispatcher")), get()) }
viewModel { MainViewModel() }

factory { AuthRepository(get(), get()) }
factory { AuthInteractor(get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class RestorePasswordViewModel(
val uiMessage: LiveData<UIMessage>
get() = _uiMessage

private val _appUpgradeEvent = SingleEventLiveData<AppUpgradeEvent>()
private val _appUpgradeEvent = MutableLiveData<AppUpgradeEvent>()
val appUpgradeEventUIState: LiveData<AppUpgradeEvent>
get() = _appUpgradeEvent

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SignInViewModel(
val loginSuccess: LiveData<Boolean>
get() = _loginSuccess

private val _appUpgradeEvent = SingleEventLiveData<AppUpgradeEvent>()
private val _appUpgradeEvent = MutableLiveData<AppUpgradeEvent>()
val appUpgradeEvent: LiveData<AppUpgradeEvent>
get() = _appUpgradeEvent

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class SignUpViewModel(
val validationError: LiveData<Boolean>
get() = _validationError

private val _appUpgradeEvent = SingleEventLiveData<AppUpgradeEvent>()
private val _appUpgradeEvent = MutableLiveData<AppUpgradeEvent>()
val appUpgradeEvent: LiveData<AppUpgradeEvent>
get() = _appUpgradeEvent

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openedx.core.presentation.dialog.app_upgrade
package org.openedx.core.presentation.dialog.appupgrade

import android.graphics.drawable.ColorDrawable
import android.os.Bundle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openedx.core.presentation.dialog.select_bottom
package org.openedx.core.presentation.dialog.selectorbottomsheet

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openedx.core.presentation.dialog.select_bottom
package org.openedx.core.presentation.dialog.selectorbottomsheet

import androidx.lifecycle.viewModelScope
import org.openedx.core.BaseViewModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.openedx.core.presentation.global.app_upgrade

import android.content.res.Configuration.ORIENTATION_LANDSCAPE
import android.content.res.Configuration.UI_MODE_NIGHT_NO
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.compose.foundation.Image
Expand Down Expand Up @@ -27,6 +28,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
Expand Down Expand Up @@ -96,13 +98,21 @@ fun AppUpgradeRecommendDialog(
onNotNowClick: () -> Unit,
onUpdateClick: () -> Unit
) {
val orientation = LocalConfiguration.current.orientation
val imageModifier = if (orientation == ORIENTATION_LANDSCAPE) {
Modifier.size(60.dp)
} else {
Modifier
}

Surface(
modifier = modifier,
color = Color.Transparent
) {
Box(
modifier = modifier
.fillMaxSize()
.padding(horizontal = 12.dp)
.noRippleClickable {
onNotNowClick()
},
Expand All @@ -127,6 +137,7 @@ fun AppUpgradeRecommendDialog(
verticalArrangement = Arrangement.spacedBy(20.dp)
) {
Image(
modifier = imageModifier,
painter = painterResource(id = R.drawable.core_ic_icon_upgrade),
contentDescription = null
)
Expand Down Expand Up @@ -182,13 +193,6 @@ fun AppUpgradeRequiredContent(
textAlign = TextAlign.Center,
style = MaterialTheme.appTypography.bodyMedium
)
// IconText(
// text = stringResource(R.string.core_why_do_you_need_update),
// painter = painterResource(id = R.drawable.core_ic_question),
// textStyle = MaterialTheme.appTypography.labelLarge,
// color = MaterialTheme.appColors.primary,
// onClick = {}
// )
}
AppUpgradeRequiredButtons(
showAccountSettingsButton = showAccountSettingsButton,
Expand Down
13 changes: 0 additions & 13 deletions core/src/main/res/drawable/core_ic_question.xml

This file was deleted.

1 change: 0 additions & 1 deletion core/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
<string name="core_account_settings">Налаштування аккаунту</string>
<string name="core_app_update_required_title">Необхідне оновлення додатку</string>
<string name="core_app_update_required_description">Ця версія додатка %1$s застаріла. Щоб продовжити навчання та отримати останні можливості та виправлення, будь ласка, оновіть до останньої версії.</string>
<string name="core_why_do_you_need_update">Чому мені потрібно оновити?</string>
<string name="core_version">Версія: %1$s</string>
<string name="core_up_to_date">Оновлено</string>
<string name="core_tap_to_update_to_version">Натисніть, щоб оновити до версії %1$s</string>
Expand Down
1 change: 0 additions & 1 deletion core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
<string name="core_account_settings">Account Settings</string>
<string name="core_app_update_required_title">App Update Required</string>
<string name="core_app_update_required_description">This version of the OpenEdX app is out-of-date. To continue learning and get the latest features and fixes, please upgrade to the latest version.</string>
<string name="core_why_do_you_need_update">Why do I need to update?</string>
<string name="core_version">Version: %1$s</string>
<string name="core_up_to_date">Up-to-date</string>
<string name="core_tap_to_update_to_version">Tap to update to version %1$s</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,19 @@ import androidx.compose.ui.Modifier
import androidx.core.os.bundleOf
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.media3.cast.CastPlayer
import androidx.media3.cast.SessionAvailabilityListener
import androidx.media3.common.MediaItem
import androidx.media3.common.MediaMetadata
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.ExoPlayer
import androidx.window.layout.WindowMetricsCalculator
import com.google.android.gms.cast.framework.CastContext
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.parameter.parametersOf
import org.openedx.core.extension.computeWindowSizeClasses
import org.openedx.core.extension.dpToPixel
import org.openedx.core.extension.objectToString
import org.openedx.core.extension.stringToObject
import org.openedx.core.presentation.dialog.select_bottom.SelectBottomDialogFragment
import org.openedx.core.presentation.dialog.selectorbottomsheet.SelectBottomDialogFragment
import org.openedx.core.presentation.global.viewBinding
import org.openedx.core.ui.WindowSize
import org.openedx.core.ui.theme.OpenEdXTheme
Expand All @@ -45,7 +41,6 @@ import org.openedx.course.presentation.CourseRouter
import org.openedx.course.presentation.ui.ConnectionErrorView
import org.openedx.course.presentation.ui.VideoSubtitles
import org.openedx.course.presentation.ui.VideoTitle
import java.util.concurrent.Executors
import kotlin.math.roundToInt

class VideoUnitFragment : Fragment(R.layout.fragment_video_unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.koin.core.parameter.parametersOf
import org.openedx.core.extension.computeWindowSizeClasses
import org.openedx.core.extension.objectToString
import org.openedx.core.extension.stringToObject
import org.openedx.core.presentation.dialog.select_bottom.SelectBottomDialogFragment
import org.openedx.core.presentation.dialog.selectorbottomsheet.SelectBottomDialogFragment
import org.openedx.core.ui.WindowSize
import org.openedx.core.ui.theme.OpenEdXTheme
import org.openedx.core.ui.theme.appColors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.koin.androidx.viewmodel.ext.android.viewModel
import org.openedx.core.UIMessage
import org.openedx.core.domain.model.Course
import org.openedx.core.domain.model.Media
import org.openedx.core.presentation.dialog.app_upgrade.AppUpgradeDialogFragment
import org.openedx.core.presentation.dialog.appupgrade.AppUpgradeDialogFragment
import org.openedx.core.presentation.global.app_upgrade.AppUpgradeRecommendedBox
import org.openedx.core.system.notifier.AppUpgradeEvent
import org.openedx.core.ui.*
Expand Down

0 comments on commit 0777de9

Please sign in to comment.