Skip to content

Instantly share code, notes, and snippets.

Avatar

Magda Miu magdamiu

View GitHub Profile
@magdamiu
magdamiu / OnGetUsersCallback.java
Created Jan 14, 2019
OnGetUsersCallback interface to manage the response from the API
View OnGetUsersCallback.java
public interface OnGetUsersCallback {
void onSuccess(List<User> users);
void onError();
}
@magdamiu
magdamiu / GithubApi
Created Jan 14, 2019
Github API interface
View GithubApi
public interface GithubApi {
@GET("/users")
Call<List<User>> getAllUsers();
}
View build.gradle
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/"'
View ItemRoomDatabase.java
@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) {
View Example.java
new Handler().postDelayed(new Runnable() {
@Override public void run() {
// do what you want to do
}
}, 4000); // Delay in millis
@magdamiu
magdamiu / Activity.java
Created Apr 6, 2019
Set RecyclerView horizontal
View Activity.java
mRecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false));
@magdamiu
magdamiu / shape_and_stroke.xml
Last active May 4, 2019
Shape drawable with stroke and gradient
View shape_and_stroke.xml
<?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"
View SyncWorker.kt
class SyncWorker(c: Context, wp: WorkerParameters):Worker(c, wp) {
override fun doWork(): Result {
loadData()
return Result.success()
}
}
@magdamiu
magdamiu / WorkManagerExample.kt
Last active Jul 4, 2019
Defining the type of the Worker
View WorkManagerExample.kt
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 Jul 4, 2019
Dependencies declared in order to use WorkManager
View build.gradle
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