This file contains hidden or 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
fun setUpOneDimenNoAspectRatioImage(imageUrl: String?, imageView: AppCompatImageView, @DimenRes defaultHeight: Int, @DimenRes marginToBeAdjusted: Int, availableWidth: Int? = null) { | |
if (imageUrl?.isNotEmpty() == true) { | |
imageView.visibility = View.VISIBLE | |
GlideApp.with(imageView.context) | |
.load(imageUrl) | |
.centerCrop() | |
.into(object : CustomTarget<Drawable>() { | |
override fun onLoadFailed(errorDrawable: Drawable?) { | |
} |
This file contains hidden or 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
from xml.dom.minidom import parseString | |
# Documentation on Permissions in AndroidManifest.xml | |
# https://developer.android.com/guide/topics/manifest/manifest-intro#perms | |
data = '' # string data from file | |
with open('AndroidManifest.xml', 'r') as f: | |
data = f.read() | |
dom = parseString(data) # parse file contents to xml dom |
This file contains hidden or 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
class LoginFragment : Fragment(){ | |
private val viewModel: LoginViewModel by viewModels() | |
override fun onCreateView( | |
inflater: LayoutInflater, container: ViewGroup?, | |
savedInstanceState: Bundle? | |
): View { | |
val binding = LoginFragmentBinding.inflate(inflater, container, false) | |
This file contains hidden or 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
sealed class Result<out T>{ | |
object Loading(): Result<Nothing>() | |
class Success<T>(val value: T): Result<T>() | |
class Error(val message:String): Result<Nothing>() | |
} |
This file contains hidden or 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
data class User(val id: String, val name:String, val token: String){ | |
fun toJson(): Map<String, String> = mapOf { | |
"id" to id, | |
"name" to name, | |
"token" to token, | |
} | |
} |
This file contains hidden or 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
interface AuthRepository{ | |
fun isSignedIn(): Flow<Result<Boolean>> | |
fun isRegistered(token: String): Flow<Result<Boolean>> | |
fun signIn(user: User): Flow<Result<Boolean>> | |
fun register(user: User): Flow<Result<Boolean>> | |
} | |
class AuthRepoImpl(val remoteService: MyService){ | |
override fun isSignedIn(): Flow<Result<Boolean>> = | |
callbackFlow { |
This file contains hidden or 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
data class LoginUiState( | |
val loading: Boolean = false, | |
val navigateToHome = false, | |
val navigateToRegistration = false, | |
val errorMessages = listOf<String>() | |
) |
This file contains hidden or 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
class LoginViewModel(val repository: AuthRepository): ViewMode() { | |
private val _state = mutableStateOf(LoginUiState()) | |
val state = _state.asStateFlow() | |
fun onLoginAttemp(user: User) { | |
viewModelScope.launch { | |
repository.isRegistered(user).collect { registered -> | |
when (registered) { | |
is Result.Loading -> { | |
_state.update { it.copy(loading = true) } |
This file contains hidden or 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
import android.graphics.Rect | |
import android.view.View | |
import androidx.recyclerview.widget.GridLayoutManager | |
import androidx.recyclerview.widget.LinearLayoutManager | |
import androidx.recyclerview.widget.RecyclerView.ItemDecoration | |
import androidx.recyclerview.widget.RecyclerView | |
import androidx.recyclerview.widget.StaggeredGridLayoutManager | |
/** | |
* Give equal margin around each [RecyclerView] items, adaptively. Supports known direct subclasses of |
This file contains hidden or 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
import android.content.Context | |
import android.os.RemoteException | |
import com.android.installreferrer.api.InstallReferrerClient | |
import com.android.installreferrer.api.InstallReferrerStateListener | |
import com.android.installreferrer.api.ReferrerDetails | |
import kotlinx.coroutines.CompletableDeferred | |
/** | |
* https://developer.android.com/google/play/installreferrer/library | |
* |