Skip to content

Instantly share code, notes, and snippets.

View mibrahimdev's full-sized avatar
🐞
Bugging

Mohamed Ibrahim mibrahimdev

🐞
Bugging
View GitHub Profile
package com.experiments.preferencehelper
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import com.experiments.preferencehelper.PreferenceHelper.get
import com.experiments.preferencehelper.PreferenceHelper.set
class MainActivity : AppCompatActivity() {
@mibrahimdev
mibrahimdev / build.gradle
Created June 24, 2018 21:24 — forked from gpeal/build.gradle
Airbnb Gradle Flavors
...
apply from: './flavors.gradle'
...
android {
buildTypes {
productFlavors {
project.flavors.each { flavor, config ->
"$flavor" {
dimension 'scope'
if (flavor != 'full') {
@mibrahimdev
mibrahimdev / SimpleDemo.kt
Created June 24, 2018 20:47 — forked from gpeal/SimpleDemo.kt
Airbnb MvRx Early Look
data class SimpleDemoState(val listing: Async<Listing> = Uninitialized)
class SimpleDemoViewModel(override val initialState: SimpleDemoState) : MvRxViewModel<SimpleDemoState>() {
init {
fetchListing()
}
private fun fetchListing() {
// This automatically fires off a request and maps its response to Async<Listing>
// which is a sealed class and can be: Unitialized, Loading, Success, and Fail.
public LiveData<List<WeatherEntry>> getCurrentWeatherForecasts() {
initializeData();
Date today = SunshineDateUtils.getNormalizedUtcDateForToday();
return mWeatherDao.getCurrentWeatherForecasts(today);
}
@Database(entities = { WeatherEntry.class , UserEntry.class}, version = 2)
//any change to tables .. you must increase version, and define a migration methodology
@TypeConverters(DateConverter.class)
public abstract class SunshineDatabase extends RoomDatabase {
...
public static SunshineDatabase getInstance(Context context) {
if (sInstance == null) {
synchronized (LOCK) {
@Dao
public interface WeatherDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
void bulkInsert(WeatherEntry... entries);
@Query("SELECT * FROM weather where date = :date")
LiveData<WeatherEntry> getWeatherByDate(Date date);
@Entity(tableName = "weather", indices = @Index(value = "date", unique = true))
public class WeatherEntry {
@PrimaryKey(autoGenerate = true) private int id;
private int weatherIconId;
..
..
mLiveDataTimerViewModel.getElapsedTime().observe(this, new Observer<Long>() {
@Overridepublic void onChanged(@Nullable Long aLong) {
//update UI
}
});
private MutableLiveData<Long> mElapsedTime = new MutableLiveData<>();
public class ChronoActivity2 extends AppCompatActivity {
@Overrideprotected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// The ViewModelStore provides a new ViewModel or one previously created.
ChronometerViewModel chronometerViewModel
= ViewModelProviders.of(this).get(ChronometerViewModel.class);