Skip to content

Instantly share code, notes, and snippets.

View magdamiu's full-sized avatar

Magda Miu magdamiu

View GitHub Profile
@magdamiu
magdamiu / OnGetUsersCallback.java
Created January 14, 2019 21:57
OnGetUsersCallback interface to manage the response from the API
public interface OnGetUsersCallback {
void onSuccess(List<User> users);
void onError();
}
@magdamiu
magdamiu / GithubApi
Created January 14, 2019 21:59
Github API interface
public interface GithubApi {
@GET("/users")
Call<List<User>> getAllUsers();
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String", "BASE_MOVIES_URL", '"https://api.themoviedb.org/3/"'
buildConfigField "String", "BASE_GITHUB_URL", '"https://api.github.com/"'
}
debug {
buildConfigField "String", "BASE_MOVIES_URL", '"https://api.themoviedb.org/3/"'
buildConfigField "String", "BASE_GITHUB_URL", '"https://api.github.com/"'
@Database(entities = {Item.class}, version = 1, exportSchema = false)
public abstract class ItemRoomDatabase extends RoomDatabase {
public abstract ItemDao itemDao();
private static ItemRoomDatabase INSTANCE;
static ItemRoomDatabase getDatabase(final Context context) {
if (INSTANCE == null) {
synchronized (ItemRoomDatabase.class) {
@magdamiu
magdamiu / Example.java
Created April 6, 2019 11:51
Delay the UI
new Handler().postDelayed(new Runnable() {
@Override public void run() {
// do what you want to do
}
}, 4000); // Delay in millis
@magdamiu
magdamiu / Activity.java
Created April 6, 2019 12:12
Set RecyclerView horizontal
mRecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false));
@magdamiu
magdamiu / shape_and_stroke.xml
Last active May 4, 2019 09:33
Shape drawable with stroke and gradient
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="0"
android:centerColor="#1976d2"
android:centerX="0.1"
android:centerY="0.1"
android:endColor="#6200ea"
android:gradientRadius="100"
class SyncWorker(c: Context, wp: WorkerParameters):Worker(c, wp) {
override fun doWork(): Result {
loadData()
return Result.success()
}
}
@magdamiu
magdamiu / WorkManagerExample.kt
Last active July 4, 2019 18:16
Defining the type of the Worker
val syncOnlyOnce = OneTimeWorkRequestBuilder<SyncWorker>().build()
val syncPeriodically = PeriodicWorkRequestBuilder<SyncWorker>(1, TimeUnit.HOURS).build()
val periodicRefreshRequest = PeriodicWorkRequest.Builder(
SyncWorker::class.java, // the worker class
30, // repeating interval
TimeUnit.Minutes,
15, // flex interval - worker will run somehow within this period of time, but at the end of repeating interval
@magdamiu
magdamiu / build.gradle
Created July 4, 2019 18:19
Dependencies declared in order to use WorkManager
dependencies {
def work_version = "2.0.1"
// (Java only)
implementation "androidx.work:work-runtime:$work_version"
// Kotlin + coroutines
implementation "androidx.work:work-runtime-ktx:$work_version"
// optional - RxJava2 support