This repository has been archived by the owner on Mar 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 #724 from NotWoods/viewmodel-no-leak
Remove HomeViewModel memory leak
- Loading branch information
Showing
11 changed files
with
122 additions
and
131 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
37 changes: 37 additions & 0 deletions
37
app/src/main/java/com/vanced/manager/core/CombinedLiveData.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,37 @@ | ||
package com.vanced.manager.core | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MediatorLiveData | ||
|
||
/** | ||
* CombinedLiveData is a helper class to combine results from two LiveData sources. | ||
* @param combine Function reference that will be used to combine all LiveData data. | ||
* @param R The type of data returned after combining all LiveData data. | ||
* Usage: | ||
* CombinedLiveData( | ||
* getLiveData1(), | ||
* getLiveData2() | ||
* ) { data1, data2 -> | ||
* // Use datas[0], datas[1], ..., datas[N] to return a value | ||
* } | ||
*/ | ||
class CombinedLiveData<R, A, B>( | ||
liveDataA: LiveData<A>, | ||
liveDataB: LiveData<B>, | ||
private val combine: (a: A?, b: B?) -> R | ||
) : MediatorLiveData<R>() { | ||
|
||
private var a: A? = null | ||
private var b: B? = null | ||
|
||
init { | ||
addSource(liveDataA) { | ||
a = it | ||
value = combine(a, b) | ||
} | ||
addSource(liveDataB) { | ||
b = it | ||
value = combine(a, b) | ||
} | ||
} | ||
} |
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,5 +1,10 @@ | ||
package com.vanced.manager.model | ||
|
||
enum class ButtonTag { | ||
INSTALL, UPDATE, REINSTALL | ||
import androidx.annotation.DrawableRes | ||
import com.vanced.manager.R | ||
|
||
enum class ButtonTag(@DrawableRes val image: Int) { | ||
INSTALL(R.drawable.ic_app_download), | ||
UPDATE(R.drawable.ic_app_update), | ||
REINSTALL(R.drawable.ic_app_reinstall) | ||
} |
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
Oops, something went wrong.