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;
### Keybase proof
I hereby claim:
* I am tarek-bohdima on github.
* I am tariqywsf (https://keybase.io/tariqywsf) on keybase.
* I have a public key ASAMDFlgT_Th26ES3USYfMIFN6-fiiI5Gkx0Fqv6qldLIAo
To claim this, I am signing this object:
@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>
package com.example.android.justjava;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;