-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create class by type: ClassHelper.kt
* change ui on state change by decideOnState: PagingDataAdapterHelper.kt * clear ConcatAdapterHelper.kt * commit fragments more easily: FragmentHelper.kt * more extensions: EdittextHelper.kt, InputValidator.kt, IterableHelper.kt, LiveEventBusHelper.kt, NumberHelper.kt, ScrollViewHelper.kt, StringHelper.kt, ViewModelHelper.kt * update versions
- Loading branch information
Showing
14 changed files
with
255 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package ir.am3n.needtool | ||
|
||
|
||
inline fun <reified T> createClass(): T { | ||
return T::class.java.newInstance() | ||
} |
12 changes: 12 additions & 0 deletions
12
needtool/src/main/java/ir/am3n/needtool/ConcatAdapterHelper.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,12 @@ | ||
package ir.am3n.needtool | ||
|
||
import androidx.recyclerview.widget.ConcatAdapter | ||
|
||
|
||
fun ConcatAdapter.clear() { | ||
while (adapters.size > 0) { | ||
removeAdapter(adapters[0]) | ||
notifyItemRemoved(0) | ||
} | ||
} | ||
|
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
13 changes: 13 additions & 0 deletions
13
needtool/src/main/java/ir/am3n/needtool/LiveEventBusHelper.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,13 @@ | ||
package ir.am3n.needtool | ||
|
||
import com.jeremyliao.liveeventbus.LiveEventBus | ||
import com.jeremyliao.liveeventbus.core.Observable | ||
|
||
|
||
fun postLiveEventBus(key: String, value: Any? = null) { | ||
LiveEventBus.get<Any>(key).post(value) | ||
} | ||
|
||
fun getLiveEventBus(key: String): Observable<Any> { | ||
return LiveEventBus.get(key, Any::class.java) | ||
} |
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
29 changes: 29 additions & 0 deletions
29
needtool/src/main/java/ir/am3n/needtool/PagingDataAdapterHelper.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,29 @@ | ||
package ir.am3n.needtool | ||
|
||
import androidx.paging.LoadState | ||
import androidx.paging.PagingDataAdapter | ||
|
||
fun PagingDataAdapter<*, *>.decideOnState( | ||
showLoadStates: (showLoading: Boolean, showEmpty: Boolean, showError: Boolean) -> Unit | ||
) { | ||
|
||
addLoadStateListener { loadState -> | ||
|
||
val errorState = loadState.source.append as? LoadState.Error | ||
?: loadState.source.prepend as? LoadState.Error | ||
?: loadState.source.refresh as? LoadState.Error | ||
?: loadState.append as? LoadState.Error | ||
?: loadState.prepend as? LoadState.Error | ||
?: loadState.refresh as? LoadState.Error | ||
|
||
val loading = loadState.refresh is LoadState.Loading && itemCount == 0 | ||
|
||
val empty = loadState.source.append is LoadState.NotLoading && loadState.source.append.endOfPaginationReached && itemCount == 0 | ||
|
||
val error = errorState != null && itemCount == 0 | ||
|
||
showLoadStates(loading, empty, error) | ||
|
||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
needtool/src/main/java/ir/am3n/needtool/ScrollViewHelper.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,12 @@ | ||
package ir.am3n.needtool | ||
|
||
import android.view.View | ||
import android.widget.ScrollView | ||
|
||
|
||
fun ScrollView.focusOn(view: View) { | ||
val vTop = view.top | ||
val vBottom = view.bottom | ||
val sHeight = bottom | ||
smoothScrollTo((vTop + vBottom - sHeight) / 2, 0) | ||
} |
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
20 changes: 20 additions & 0 deletions
20
needtool/src/main/java/ir/am3n/needtool/ViewModelHelper.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,20 @@ | ||
package ir.am3n.needtool | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.CoroutineStart | ||
import kotlinx.coroutines.launch | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.coroutines.EmptyCoroutineContext | ||
|
||
|
||
val ViewModel.scope: CoroutineScope get() = viewModelScope | ||
|
||
fun ViewModel.launch( | ||
context: CoroutineContext = EmptyCoroutineContext, | ||
start: CoroutineStart = CoroutineStart.DEFAULT, | ||
block: suspend CoroutineScope.() -> Unit | ||
) { | ||
scope.launch(context, start, block) | ||
} |