Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rc/6.0.1 #36

Merged
merged 6 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ android {
applicationId appId
minSdk 24
targetSdk 34
versionCode 1
versionName "1.0.0"
versionCode 6000001
versionName "6.0.1"

resourceConfigurations += ["en", "uk"]

Expand Down Expand Up @@ -92,11 +92,12 @@ android {
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

if (firebaseEnabled) {
firebaseCrashlytics {
mappingFileUploadEnabled false
mappingFileUploadEnabled true
}
}
}
Expand Down
159 changes: 159 additions & 0 deletions core/src/main/java/org/openedx/core/domain/model/Version.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package org.openedx.core.domain.model

import java.text.ParseException
import java.util.*
import kotlin.math.abs
import kotlin.math.min

/**
* Simple representation of the app's version.
*/
class Version
/**
* Create a new instance from the provided version string.
*
* @param version The version string. The first three present dot-separated
* tokens will be parsed as major, minor, and patch version
* numbers respectively, and any further tokens will be
* discarded.
* @throws ParseException If one or more of the first three present dot-
* separated tokens contain non-numeric characters.
*/
@Throws(ParseException::class) constructor(version: String) : Comparable<Version> {

/**
* The version numbers
*/
private val numbers = IntArray(3)

/**
* @return The major version.
*/
private val majorVersion: Int
get() = getVersionAt(0)

/**
* @return The minor version.
*/
private val minorVersion: Int
get() = getVersionAt(1)

/**
* @return The patch version.
*/
val patchVersion: Int
get() = getVersionAt(2)

init {
val numberStrings = version.split("\\.".toRegex())
val versionsCount = min(NUMBERS_COUNT, numberStrings.size)
for (i in 0 until versionsCount) {
val numberString = numberStrings[i]/* Integer.parseInt() parses a string as a signed integer value, and
* there is no available method for parsing as unsigned instead.
* Therefore, we first check the first character manually to see
* whether it's a plus or minus sign, and throw a ParseException if
* it is.
*/
val firstChar = numberString[0]
if (firstChar == '-' || firstChar == '+') {
throw VersionParseException(0)
}
try {
numbers[i] = Integer.parseInt(numberString)
} catch (e: NumberFormatException) {
// Rethrow as a checked ParseException
throw VersionParseException(version.indexOf(numberString))
}

}
}

/**
* Returns the version number at the provided index.
*
* @param index The index at which to get the version number
* @return The version number.
*/
private fun getVersionAt(index: Int): Int {
return if (index < numbers.size) numbers[index] else 0
}

override fun equals(other: Any?): Boolean {
return this === other || (other is Version && numbers.contentEquals(other.numbers))
}

override fun compareTo(other: Version): Int {
for (i in 0 until NUMBERS_COUNT) {
val number = numbers[i]
val otherNumber = other.numbers[i]
if (number != otherNumber) {
return if (number < otherNumber) -1 else 1
}
}
return 0
}

override fun hashCode(): Int {
return numbers.contentHashCode()
}

override fun toString(): String {
when (numbers.size) {
0 -> return ""
1 -> return numbers[0].toString()
}
val sb = StringBuilder()
sb.append(numbers[0])
for (i in 1 until numbers.size) {
sb.append(".")
sb.append(numbers[i])
}
return sb.toString()
}

/**
* Convenience subclass of [ParseException], with the detail
* message already provided.
*/
private class VersionParseException
/**
* Constructs a new instance of this class with its stack
* trace, detail message and the location of the error filled
* in.
*
* @param location The location of the token at which the parse
* exception occurred.
*/
(location: Int) : ParseException("Token couldn't be parsed as a valid number.", location)

/**
* Compares this version with the specified version, to determine if minor versions'
* difference between both is greater than or equal to the specified value.
*
* @param otherVersion The version to compare to this instance.
* @return `true` if difference is greater than or equal to the specified value,
* `false` otherwise.
*/
fun isMinorVersionsDiff(otherVersion: Version): Boolean {
// Difference in major version is consider to be valid for any minor versions difference
return abs(this.majorVersion - otherVersion.majorVersion) >= 1 || abs(this.minorVersion - otherVersion.minorVersion) >= 1
}

/**
* Compares this version with the specified version and determine if both have same major and
* minor versions.
*
* @param otherVersion The version to compare to this instance.
* @return `true` if both have same major and minor versions, `false` otherwise.
*/
fun hasSameMajorMinorVersion(otherVersion: Version): Boolean {
return this.majorVersion == otherVersion.majorVersion && this.minorVersion == otherVersion.minorVersion
}

companion object {
/**
* The number of version number tokens to parse.
*/
private const val NUMBERS_COUNT = 3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ class CourseContainerViewModel(
delay(500L)
courseNotifier.send(CourseOpenBlock(resumeBlockId))
}
_canShowUpgradeButton.value =
isIAPEnabled && courseDetails.isUpgradeable.isTrue()
_dataReady.value = true
if (isIAPFlow) {
iapNotifier.send(CourseDataUpdated())
Expand Down
19 changes: 15 additions & 4 deletions whatsnew/src/main/java/org/openedx/whatsnew/WhatsNewManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.openedx.whatsnew
import android.content.Context
import com.google.gson.Gson
import org.openedx.core.config.Config
import org.openedx.core.domain.model.Version
import org.openedx.core.presentation.global.AppData
import org.openedx.core.presentation.global.WhatsNewGlobalManager
import org.openedx.whatsnew.data.model.WhatsNewItem
Expand All @@ -23,9 +24,19 @@ class WhatsNewManager(
}

override fun shouldShowWhatsNew(): Boolean {
val dataVersion = getNewestData().version
return appData.versionName == dataVersion
&& whatsNewPreferences.lastWhatsNewVersion != dataVersion
&& config.isWhatsNewEnabled()
return try {
val dataVersion = Version(getNewestData().version)
val appVersion = Version(appData.versionName)
if (whatsNewPreferences.lastWhatsNewVersion.isEmpty()) {
appVersion.hasSameMajorMinorVersion(dataVersion)
} else {
val lastWhatsNewVersion = Version(whatsNewPreferences.lastWhatsNewVersion)
lastWhatsNewVersion.isMinorVersionsDiff(appVersion) &&
appVersion.hasSameMajorMinorVersion(dataVersion)
}
} catch (e: Exception) {
e.printStackTrace()
false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,15 @@ private fun WhatsNewScreenPortrait(
state = pagerState
) { page ->
val image = whatsNewItem.messages[page].image
Image(
modifier = Modifier
.fillMaxWidth(),
painter = painterResource(id = image),
contentDescription = null
)
Box(modifier = Modifier.fillMaxSize()) {
Image(
modifier = Modifier
.fillMaxWidth()
.align(Alignment.Center),
painter = painterResource(id = image),
contentDescription = null
)
}
}
Column(
horizontalAlignment = Alignment.CenterHorizontally,
Expand Down
Binary file modified whatsnew/src/main/res/drawable-nodpi/screen_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified whatsnew/src/main/res/drawable-nodpi/screen_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed whatsnew/src/main/res/drawable-nodpi/screen_3.jpg
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions whatsnew/src/main/res/raw/whats_new.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
[
{
"version": "6.0",
"messages": [
{
"image": "screen_1",
"title": "A Whole New Design",
"message": "Experience the completely redesigned app with an intuitive and modern interface that enhances your learning journey."
},
{
"image": "screen_2",
"title": "Focused Learning",
"message": "Keep your most active course at the forefront with a dedicated card on the Learn tab for seamless access and engagement."
},
{
"image": "screen_3",
"title": "Dates",
"message": "Easily track your course dates with a new layout that groups past due, upcoming, and completed course content for better clarity."
},
{
"image": "screen_4",
"title": "Discussions",
"message": "Enjoy a revamped forum with improved organization for discussion topics and posts, making it easier to follow and engage."
},
{
"image": "screen_5",
"title": "Feedback Submission",
"message": "We value your input! Use our new feedback button in Settings to share your thoughts and help us enhance your app experience."
},
{
"image": "screen_6",
"title": "Dark Mode",
"message": "Switch to Dark Mode for a visually comfortable and eye-friendly learning experience, especially in low-light environments."
}
]
},
{
"version": "1.0",
"messages": [
Expand Down
Loading