This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface MainActivityView extends MvpView { | |
ListView getListView(); | |
ProgressBar getProgressBar(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity implements MainActivityView { | |
@BindView(R.id.lv_am_movie_list) ListView listView; | |
@BindView(R.id.pb_am_loading) ProgressBar progressBar; | |
public static MainPresenter mainPresenter; | |
@Override protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StarWarsService extends IntentService { | |
@Inject AppDatabase db; | |
public StarWarsService() { | |
super("StarWarsService"); | |
} | |
@Override public void onCreate() { | |
super.onCreate(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Dao | |
public interface StarWarsMovieDao { | |
@Query("select * from StarWarsMovie") LiveData<List<StarWarsMovie>> loadMovies(); | |
@Query("DELETE FROM StarWarsMovie") void deleteAll(); | |
@Insert(onConflict = REPLACE) void insertMovie(StarWarsMovie starWarsMovie); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Database(entities = { StarWarsMovie.class }, version = 1) public abstract class AppDatabase | |
extends RoomDatabase { | |
public abstract StarWarsMovieDao starWarsMovieModel(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module public class AppModule { | |
private Application application; | |
public AppModule(Application application) { | |
this.application = application; | |
} | |
@Provides @Singleton Context providesAppContext() { | |
return application.getApplicationContext(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainViewModel extends AndroidViewModel { | |
private LiveData<List<StarWarsMovie>> moviesLiveData; | |
@Inject AppDatabase mDb; | |
public MainViewModel(Application application) { | |
super(application); | |
((StarWarsApplication) getApplication()).getAppComponent().inject(this); | |
requestDataUpdates(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends LifecycleActivity implements Observer<List<StarWarsMovie>> { | |
@BindView(R.id.lv_am_movie_list) ListView listView; | |
@BindView(R.id.pb_am_loading) ProgressBar progressBar; | |
private MainViewModel mainViewModel; | |
@Override protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
mainViewModel = ViewModelProviders.of(this).get(MainViewModel.class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SyncOrderService extends GcmTaskService { | |
//... | |
public static void scheduleOrderSending(Context context, int id) { | |
GcmNetworkManager manager = GcmNetworkManager.getInstance(context); | |
Bundle bundle = new Bundle(); | |
bundle.putInt(SyncOrderService.ORDER_ID, id); | |
OneoffTask task = new OneoffTask.Builder().setService(SyncOrderService.class) | |
.setTag(SyncOrderService.getTaskTag(id)) | |
.setExecutionWindow(0L, 30L) | |
.setExtras(bundle) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SendOrderService extends IntentService { | |
@Override protected void onHandleIntent(Intent intent) { | |
int orderId = intent.getIntExtra(ORDER_ID, 0); | |
if (orderId == 0 || orderId == -1) { | |
return; | |
} | |
Cursor c = null; | |
try { |