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
@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
@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
@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
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
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 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 abstract class BasePresenter<T extends MvpView> { | |
HandlerThread thread; | |
Looper looper; | |
Handler handler; | |
private T mView; | |
public BasePresenter() { | |
} |
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 MainPresenter extends BasePresenter<MainActivityView> { | |
public static final String LOAD_COMPLETE_ACTION = | |
"com.academy.android.starwarsmovies.load_complete"; | |
public static final String DATA_KEY = "data_key"; | |
private StarWarsMovieDataReceiver movieDataReceiver; | |
private ArrayList<StarWarsMovie> movieList; | |
@Override public void attachView(MainActivityView mainActivityView) { | |
super.attachView(mainActivityView); | |
registerLoadDataReceiver(); |
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 { | |
public StarWarsService() { | |
super("StarWarsService"); | |
} | |
@Override protected void onHandleIntent(Intent intent) { | |
if (intent != null) { | |
String json = ResourcesUtil.loadJson(this); | |
Gson gson = new GsonBuilder().setDateFormat("MMM d, yyyy").create(); | |
ArrayList<StarWarsMovie> moviesList = |