-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/development'
- Loading branch information
Showing
5 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
4 changes: 4 additions & 0 deletions
4
...src/main/java/com/fivegmag/a5gmscommonlibrary/eventbus/MediaStreamHandlerMessageEvents.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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.fivegmag.a5gmscommonlibrary.eventbus | ||
import androidx.media3.exoplayer.source.MediaLoadData | ||
|
||
class DownstreamFormatChangedEvent(val mediaLoadData: MediaLoadData) |
83 changes: 83 additions & 0 deletions
83
app/src/main/java/com/fivegmag/a5gmscommonlibrary/helpers/Utils.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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.fivegmag.a5gmscommonlibrary.helpers | ||
|
||
import java.text.SimpleDateFormat | ||
import java.time.Duration | ||
import java.util.Date | ||
import java.util.Random | ||
import java.util.TimeZone | ||
import okhttp3.Headers | ||
|
||
class Utils { | ||
|
||
fun getCurrentTimestamp(): Long { | ||
return System.currentTimeMillis(); | ||
} | ||
|
||
fun convertTimestampToXsDateTime(timestampInMillis: Long): String { | ||
// Create a Date object using the provided timestamp | ||
val date = Date(timestampInMillis) | ||
|
||
// Create a SimpleDateFormat object to format the date | ||
val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") | ||
dateFormat.timeZone = TimeZone.getTimeZone("UTC") | ||
|
||
// Format the date to xs:datetime string | ||
return dateFormat.format(date) | ||
} | ||
|
||
fun getCurrentXsDateTime(): String { | ||
val currentTimestamp = getCurrentTimestamp() | ||
|
||
return convertTimestampToXsDateTime(currentTimestamp) | ||
} | ||
|
||
fun millisecondsToISO8601(milliseconds: Long): String? { | ||
// Create a Duration object from milliseconds | ||
val duration: Duration = Duration.ofMillis(milliseconds) | ||
|
||
// Extract the components from the duration | ||
val years: Long = duration.toDays() / 365 | ||
val days: Long = duration.toDays() % 365 | ||
val hours: Long = duration.toHours() % 24 | ||
val minutes: Long = duration.toMinutes() % 60 | ||
val seconds: Long = duration.seconds % 60 | ||
|
||
// Construct the ISO 8601 period string | ||
return "P" + years + "Y" + days + "D" + | ||
"T" + hours + "H" + minutes + "M" + seconds + "S" | ||
} | ||
|
||
fun generateRandomFloat(): Float { | ||
val random = Random() | ||
return random.nextFloat() * 100.0f | ||
} | ||
|
||
fun addTrailingSlashIfNeeded(input: String): String { | ||
return if (!input.endsWith("/")) { | ||
"$input/" | ||
} else { | ||
input | ||
} | ||
} | ||
|
||
fun hasResponseChanged( | ||
headers: Headers, | ||
previousResponseHeaders: Headers? | ||
): Boolean { | ||
if (previousResponseHeaders == null) { | ||
return true | ||
} | ||
val headersToValidate = arrayOf("last-modified", "etag") | ||
|
||
return headersToValidate.all { header -> | ||
hasHeaderChanged( | ||
headers.get(header), | ||
previousResponseHeaders.get(header) | ||
) | ||
} | ||
} | ||
|
||
private fun hasHeaderChanged(headerA: String?, headerB: String?): Boolean { | ||
return headerA == null || headerB == null || headerA != headerB | ||
} | ||
} |