Skip to content

Commit 84201fc

Browse files
Use Pager instead of a single Composable page child,
Animate SearchBar appearance, Nicer insets in the ExtensionScreen.kt and ExtensionSearchScreen.kt, Fixed infinite loading in the library, Global media search
1 parent 9db0ac1 commit 84201fc

File tree

22 files changed

+552
-329
lines changed

22 files changed

+552
-329
lines changed
23 Bytes
Binary file not shown.
16 Bytes
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
package com.mrboomdev.awery.core.utils
22

3+
import android.content.pm.ApplicationInfo
34
import android.util.Log
5+
import com.mrboomdev.awery.core.Awery
6+
import com.mrboomdev.awery.core.context
7+
8+
private val isDebug by lazy {
9+
(Awery.context.applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE) != 0
10+
}
411

512
actual object Log {
613
actual fun i(tag: String, message: String) {
14+
if(!isDebug) return
715
Log.i(tag, message)
816
}
917

1018
actual fun d(tag: String, message: String) {
19+
if(!isDebug) return
1120
Log.d(tag, message)
1221
}
1322

1423
actual fun w(tag: String, message: String) {
24+
if(!isDebug) return
1525
Log.w(tag, message)
1626
}
1727

1828
actual fun e(tag: String, message: String, throwable: Throwable?) {
29+
if(!isDebug) return
1930
Log.e(tag, message, throwable)
2031
}
2132
}

core/src/commonMain/kotlin/com/mrboomdev/awery/core/utils/CommonUtils.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.mrboomdev.awery.core.utils
22

3-
import com.mrboomdev.awery.core.utils.Log.e
4-
import java.io.Closeable
53
import java.lang.AutoCloseable
64
import kotlin.contracts.ExperimentalContracts
75
import kotlin.contracts.InvocationKind
@@ -55,13 +53,15 @@ inline fun await(block: () -> Boolean) {
5553
while(!block()) {}
5654
}
5755

58-
inline fun <T> retryUntilSuccess(block: () -> T): T {
56+
inline fun <T> retryUntilSuccess(onFailure: (Throwable) -> Unit = {}, block: () -> T): T {
5957
var result: T? = null
6058

6159
while(result == null) {
6260
try {
6361
result = block()
64-
} catch(t: Throwable) {}
62+
} catch(t: Throwable) {
63+
onFailure(t)
64+
}
6565
}
6666

6767
return result

core/src/commonMain/kotlin/com/mrboomdev/awery/core/utils/CoroutineUtils.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ fun CoroutineScope.launchTrying(
4949
block = block
5050
)
5151

52+
fun CoroutineScope.launchSupervise(
53+
context: CoroutineContext = EmptyCoroutineContext,
54+
start: CoroutineStart = CoroutineStart.DEFAULT,
55+
block: suspend CoroutineScope.() -> Unit
56+
) = launch(context, start) {
57+
supervisorScope(block)
58+
}
59+
5260
/**
5361
* Useful for view models.
5462
*/

core/src/commonMain/kotlin/com/mrboomdev/awery/core/utils/Log.kt

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.mrboomdev.awery.core.utils
22

3+
import com.mrboomdev.awery.core.utils.collection.iterate
4+
35
private const val DEFAULT_TAG = "Awery"
46
private const val DISALLOWED_CLASS_NAME_PREFIX = "com.mrboomdev.awery.core.utils.Log"
57

@@ -22,7 +24,7 @@ expect object Log {
2224
* the class or activity where the log call occurs.
2325
* @param message The message you would like logged.
2426
*/
25-
fun i(tag: String, message: String)
27+
fun i(tag: String = DEFAULT_TAG, message: String)
2628

2729
/**
2830
* Sends a debug message to the log.
@@ -31,7 +33,7 @@ expect object Log {
3133
* the class or activity where the log call occurs.
3234
* @param message The message to log.
3335
*/
34-
fun d(tag: String, message: String)
36+
fun d(tag: String = DEFAULT_TAG, message: String)
3537

3638
/**
3739
* Sends a warning log message.
@@ -40,7 +42,7 @@ expect object Log {
4042
* the class or activity where the log call occurs.
4143
* @param message The message you would like logged.
4244
*/
43-
fun w(tag: String, message: String)
45+
fun w(tag: String = DEFAULT_TAG, message: String)
4446

4547
/**
4648
* Sends an error log message.
@@ -49,7 +51,7 @@ expect object Log {
4951
* @param message The message you would like logged.
5052
* @param throwable An exception to log.
5153
*/
52-
fun e(tag: String, message: String, throwable: Throwable? = null)
54+
fun e(tag: String = DEFAULT_TAG, message: String, throwable: Throwable? = null)
5355
}
5456

5557
class Logger internal constructor(val tag: String) {
@@ -98,4 +100,26 @@ fun logger() = LoggerDelegate()
98100
* Creates a [Logger] with the specified tag.
99101
* @param tag The tag for the logger.
100102
*/
101-
fun logger(tag: String) = Logger(tag)
103+
fun logger(tag: String) = Logger(tag)
104+
105+
fun Log.debug(vararg variables: Pair<String, Any>) = d(
106+
tag = "AweryDebug",
107+
message = buildString {
108+
if(variables.isEmpty()) {
109+
append("{}")
110+
return@buildString
111+
}
112+
113+
append("{")
114+
115+
variables.toList().iterate { (key, value) ->
116+
append("\n\t\"${key}\": \"${value}\"")
117+
118+
if(hasNext()) {
119+
append(",")
120+
}
121+
}
122+
123+
append("\n}")
124+
}
125+
)

core/src/commonMain/kotlin/com/mrboomdev/awery/core/utils/collection/CollectionUtils.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ inline fun <T> Iterable<T>.iterateIndexed(block: Iterator<T>.(Int, T) -> Unit) {
3535
}
3636
}
3737

38-
inline fun <T> Iterable<T>.iterate(block: Iterator<T>.(T) -> Unit) {
39-
val iterator = iterator()
40-
41-
while(iterator.hasNext()) {
42-
block(iterator, iterator.next())
38+
inline fun <T> Iterator<T>.iterate(block: Iterator<T>.(T) -> Unit) {
39+
while(hasNext()) {
40+
block(this, next())
4341
}
4442
}
4543

44+
inline fun <T> Iterable<T>.iterate(block: Iterator<T>.(T) -> Unit) = iterator().iterate(block)
45+
inline fun <T> Array<T>.iterate(block: Iterator<T>.(T) -> Unit) = iterator().iterate(block)
46+
4647
fun <T> List<T>.next(after: T): T {
4748
val index = indexOf(after)
4849
return get(if(index > size - 2) 0 else index + 1)
@@ -57,4 +58,8 @@ fun <E> MutableList<E>.replace(oldElement: E, newElement: E) {
5758
} else {
5859
add(newElement)
5960
}
61+
}
62+
63+
fun <T> List<T>.limit(maxSize: Int): List<T> {
64+
return if(size <= maxSize) toList() else subList(0, maxSize)
6065
}

core/src/commonMain/kotlin/com/mrboomdev/awery/core/utils/collection/MutableStateListFlow.kt

Lines changed: 0 additions & 147 deletions
This file was deleted.

data/src/commonMain/kotlin/com/mrboomdev/awery/data/database/dao/ListDao.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
package com.mrboomdev.awery.data.database.dao
22

3-
import androidx.room.Dao
4-
import androidx.room.Delete
5-
import androidx.room.Insert
6-
import androidx.room.OnConflictStrategy
7-
import androidx.room.Query
8-
import androidx.room.Transaction
9-
import androidx.room.Update
3+
import androidx.room.*
104
import com.mrboomdev.awery.data.database.entity.DBList
115
import com.mrboomdev.awery.data.database.entity.DBMedia
126
import kotlinx.coroutines.flow.Flow
@@ -27,6 +21,9 @@ interface ListDao {
2721
@Query("SELECT COUNT(*) FROM DBList")
2822
fun observeCount(): Flow<Int>
2923

24+
@Query("SELECT COUNT(*) FROM DBList")
25+
suspend fun count(): Int
26+
3027
@Transaction
3128
suspend fun updateLists(collection: Collection<DBList>) {
3229
collection.forEach { insert(it) }

data/src/commonMain/kotlin/com/mrboomdev/awery/data/database/dao/fff

Whitespace-only changes.

0 commit comments

Comments
 (0)