-
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.
Merge pull request #58 from sieunju/preview
Preview
- Loading branch information
Showing
8 changed files
with
235 additions
and
0 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
52 changes: 52 additions & 0 deletions
52
core/src/main/java/com/hmju/core/ui/payloads/RvPayloadModel.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,52 @@ | ||
package com.hmju.core.ui.payloads | ||
|
||
import com.hmju.core.ui.base.BaseUiModel | ||
|
||
/** | ||
* Description : RecyclerView Payload Update 전용 데이터 모델 | ||
* | ||
* Created by juhongmin on 2024. 6. 30. | ||
*/ | ||
data class RvPayloadModel( | ||
var firstPos: Int = -1, | ||
var lastPos: Int = -1, | ||
val list: MutableList<BaseUiModel> = mutableListOf() | ||
) { | ||
|
||
fun isValidate(): Boolean { | ||
return list.isNotEmpty() | ||
} | ||
|
||
fun isRangeValidate(): Boolean { | ||
return firstPos != -1 && lastPos != -1 | ||
} | ||
|
||
/** | ||
* 업데이트 리스트의 최소 / 최대 범위를 찾아서 업데이트할 정보를 셋팅하는 함수 | ||
* 단, 인자값으로 넣는 리스트는 data class 이거나, CurrentList 에 있는 데이터 그대로 | ||
* payloadList 에 추가만 하도록 해야함 [Collection.indexOf] 내부 로직 때문 | ||
* 성능 N X M | ||
* LiveData 를 사용하는 경우 setValue 를 해줘야 합니다. AKA. notifyObserver | ||
* @param list Current List | ||
* @param payloadList Update List | ||
*/ | ||
fun update(list: List<BaseUiModel>, payloadList: List<BaseUiModel>) { | ||
if (list.isEmpty() || payloadList.isEmpty()) return | ||
var firstPos = -1 | ||
var lastPos = 1 | ||
payloadList.forEach { | ||
val findIndex = list.indexOf(it) | ||
if (findIndex == -1) return@forEach | ||
firstPos = if (firstPos == -1) { | ||
findIndex | ||
} else { | ||
firstPos.coerceAtMost(findIndex) | ||
} | ||
lastPos = lastPos.coerceAtLeast(findIndex) | ||
} | ||
this.firstPos = firstPos | ||
this.lastPos = lastPos.plus(1) | ||
this.list.clear() | ||
this.list.addAll(payloadList) | ||
} | ||
} |
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,19 @@ | ||
package com.hmju.core.util | ||
|
||
import android.content.res.Resources | ||
import androidx.annotation.ColorRes | ||
import androidx.annotation.StringRes | ||
|
||
/** | ||
* Description : Android Resource Manager | ||
* | ||
* Created by juhongmin on 6/22/24 | ||
*/ | ||
interface ResourceManager { | ||
fun getRes(): Resources | ||
fun getColor(@ColorRes color: Int): Int | ||
fun getString(@StringRes resId: Int): CharSequence | ||
|
||
fun getString(@StringRes resId: Int, vararg args: Any): CharSequence | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
core/src/main/java/com/hmju/core/util/ResourceManagerImpl.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,34 @@ | ||
package com.hmju.core.util | ||
|
||
import android.content.Context | ||
import android.content.res.Resources | ||
import androidx.annotation.ColorRes | ||
import androidx.annotation.StringRes | ||
import androidx.core.content.ContextCompat | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import javax.inject.Inject | ||
|
||
/** | ||
* Description : | ||
* | ||
* Created by juhongmin on 6/22/24 | ||
*/ | ||
internal class ResourceManagerImpl @Inject constructor( | ||
@ApplicationContext private val context: Context | ||
) : ResourceManager { | ||
override fun getRes(): Resources { | ||
return context.resources | ||
} | ||
|
||
override fun getColor(@ColorRes color: Int): Int { | ||
return ContextCompat.getColor(context, color) | ||
} | ||
|
||
override fun getString(@StringRes resId: Int): CharSequence { | ||
return context.resources.getString(resId) | ||
} | ||
|
||
override fun getString(resId: Int, vararg args: Any): CharSequence { | ||
return context.resources.getString(resId, args) | ||
} | ||
} |
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,17 @@ | ||
package com.hmju.core.util | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
internal abstract class UtilModule { | ||
@Singleton | ||
@Binds | ||
abstract fun bindResourceManager( | ||
impl: ResourceManagerImpl | ||
): ResourceManager | ||
} |