Skip to content

Instantly share code, notes, and snippets.

View Tarek-Bohdima's full-sized avatar

Tarek Bohdima Tarek-Bohdima

View GitHub Profile
@Tarek-Bohdima
Tarek-Bohdima / ConcurrencyHelpers.kt
Created October 5, 2023 19:27 — forked from objcode/ConcurrencyHelpers.kt
Helpers to control concurrency for one shot requests using Kotlin coroutines.
/* Copyright 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
/* Copyright 2019 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
public class LiveDataTestUtil {
public static <T> T getOrAwaitValue(final LiveData<T> liveData) throws InterruptedException {
final Object[] data = new Object[1];
final CountDownLatch latch = new CountDownLatch(1);
Observer<T> observer = new Observer<T>() {
@Override
public void onChanged(@Nullable T o) {
data[0] = o;
@Tarek-Bohdima
Tarek-Bohdima / ActivityClass.java
Created November 16, 2020 16:24 — forked from ExNDY/ActivityClass.java
Monitoring network connection for Android ( API 24+ ) with using LiveData
public class Activity extends AppCompatActivity{
...
private NetworkConnectionMonitor connectionMonitor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
...
connectionMonitor = new NetworkConnectionMonitor(getApplicationContext());

1. Store api keys in a xml file

Put xml file "api_keys.xml" in the directory "res/value/".

api_keys.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="THE_MOVIE_DB_API_TOKEN">XXXXX</string>
</resources>