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
<manifest | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.package.here"> | |
<application | |
android:name="com.package.here.MyApplication" | |
android:allowBackup="true" | |
android:icon="@drawable/ic_launcher" | |
android:label="@string/app_name" | |
android:theme="@style/AppTheme"> |
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
Imagine that you, and your new Pixel device, have gone back in time to 1980. | |
Lucky for you, your friend Marty mcFly, the developer of "WatchStarWars" application, and you're just about to watch "Episode V", you're about to watch it for the 1st time. | |
WatchStarWars app has a single activity, WatchStarwarsActivity. | |
It's an activity with one button "Say Something", that when clicked, logs an interesting fact about the movie to the log, a fact that, if you haven't watched Episode V, you might find to be a spoiler. | |
In its OnCreate method, WatchStarwarsActivity posts-delayed a "Finished Watching Starwars" log message for x milliseconds. | |
Marty loves technology. He uses Timber for injecting a testable log into the activity with Dagger. He is also a very pragmatic developer - he tests his app with Espresso, with this scenario: | |
Open the activity |
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
import android.util.Log; | |
public class ClassWithInnerObject { | |
private final InnerObject innerObject; | |
public ClassWithInnerObject() { | |
innerObject = new InnerObject(); | |
} |
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 KolGeneProvider extends ContentProvider { | |
//... | |
@Nullable @Override public Uri insert(@NonNull Uri uri, ContentValues values) { | |
//open DB for write | |
final SQLiteDatabase db = mOpenHelper.getWritableDatabase(); | |
//match URI to action. | |
final int match = sUriMatcher.match(uri); | |
Uri returnUri; | |
switch (match) { | |
//case of creating order. |
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
@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 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 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 = |
OlderNewer