-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from appwrite/dev
Fix okttp with AGP 8.2+
- Loading branch information
Showing
7 changed files
with
55 additions
and
42 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
@@ -1,10 +1,34 @@ | ||
package io.appwrite | ||
|
||
import java.time.Instant | ||
import kotlin.math.floor | ||
import kotlin.random.Random | ||
|
||
class ID { | ||
companion object { | ||
// Generate an hex ID based on timestamp | ||
// Recreated from https://www.php.net/manual/en/function.uniqid.php | ||
private fun hexTimestamp(): String { | ||
val now = Instant.now() | ||
val sec = now.epochSecond | ||
val usec = (System.nanoTime() / 1000) % 1000 | ||
|
||
val hexTimestamp = "%08x%05x".format(sec, usec) | ||
|
||
return hexTimestamp | ||
} | ||
|
||
fun custom(id: String): String | ||
= id | ||
fun unique(): String | ||
= "unique()" | ||
|
||
// Generate a unique ID with padding to have a longer ID | ||
fun unique(padding: Int = 7): String { | ||
val baseId = hexTimestamp() | ||
val randomPadding = (1..padding) | ||
.map { Random.nextInt(0, 16).toString(16) } | ||
.joinToString("") | ||
|
||
return baseId + randomPadding | ||
} | ||
} | ||
} | ||
} |
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
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
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