- Consider static factory methods instead of constructors
- One advantage of static factory methods is that, unlike constructors, they have names.
- A second advantage of static factory methods is that, unlike constructors, they are not required to create a new object each time they’re invoked.
- A third advantage of static factory methods is that, unlike constructors, they can return an object of any subtype of their return type.
- A fourth advantage of static factory methods is that they reduce the verbosity of creating parameterized type instances.
- The main disadvantage of providing only static factory methods is that classes without public or protected constructors cannot be subclassed.
- A second disadvantage of static factory methods is that they are not readily distinguishable from other static methods.
- Consider a builder when faced with many constructor parameters
- The telescoping constructor pattern works, but it is hard to write client code when there are many parameters, and hard
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 CustomViewGroup extends FrameLayout { | |
@Override | |
public boolean dispatchKeyEventPreIme(KeyEvent event) { | |
Timber.d(""); | |
if(event != null){ | |
int keyCode = event.getKeyCode(); | |
if(keyCode == KeyEvent.KEYCODE_BACK){ | |
// hide search suggestions UI |
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 NetworkLogUtility { | |
public static void logFailure(Call call, Throwable throwable){ | |
if(call != null){ | |
if (call.isCanceled()) | |
Timber.e("Request was cancelled"); | |
Request request = call.request(); | |
if(request != null){ | |
HttpUrl httpUrl = request.url(); |
- Test most important flows in the app (Request a table flow). By focusing the test you will get more actionable results.
- Test popular phone manufacturers (Samsung, LG, HTC, Motorola)
- Changing the look of an app can create intense dissatisfaction among your user base. Run user tests on major UI changes before you push them out to market.
- Test for usability and emotional engagement
- Usability means the ability of a typical user to easily figure out how to use your app. Mobile users are notoriously impatient; if an app confuses them, they will probably move on to something else.
- Do users understand what they're supposed to do?
- Have you made the most important features easy to find?
- Usability means the ability of a typical user to easily figure out how to use your app. Mobile users are notoriously impatient; if an app confuses them, they will probably move on to something else.
- Emotional engagement measures the user's motivation to use your app.
- Are you providing features that users actually want, and have you made it easy to get to them?
- Do people feel rewarded enough by your app that they want to return?
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 BaseFragment extends Fragment { | |
// region Member Variables | |
protected List<Call> calls; | |
// endregion | |
// region Lifecycle Methods | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); |
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 MoviesFragment extends BaseFragment { | |
// region Member Variables | |
private CompositeSubscription compositeSubscription; | |
// endregion | |
// region Lifecycle Methods | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); |
Observable.combineLatest(
Api.getService(Api.getEndpointUrl()).getUserProfile(SoundcloudConstants.USERNAME),
Api.getService(Api.getEndpointUrl()).getFavoriteTracks(SoundcloudConstants.USERNAME),
new Func2<UserProfile, List<Track>, Account>() {
@Override
public Account call(UserProfile userProfile, List<Track> tracks) {
return new Account(userProfile, tracks);
}
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
@Override | |
public void onScrolled(RecyclerView recyclerView, int dx, int dy) { | |
super.onScrolled(recyclerView, dx, dy); | |
int visibleItemCount = recyclerView.getChildCount(); | |
int totalItemCount = recyclerView.getAdapter().getItemCount(); | |
int[] positions = layoutManager.findFirstVisibleItemPositions(null); | |
int firstVisibleItem = positions[1]; | |
if (!isLoading && !isLastPage) { |
- Package by Feature
- Dagger
- MVP
- The MVP Pattern is a user interface software architecture pattern that reduces the behavior of the UI components, in this case those are the views, widgets, fragments, and activities. The MVP Pattern reduces the UI components behavior to a bare minimum by using a presenter. A presenter is simply a controller like class that handles the presentation logic and updates the view accordingly. Using this pattern, you can pull your UI logic out of the Android components and place it into your presenters, making it much easier to test and much faster to test. It is faster to test since we no longer need the Android framework to test our inputs and outputs. The Android context is gone. We don't need to fire up an Android emulator or an Android device. We can just rely solely on the JVM which is very fast.
- A repository is essentially a location where data may be stored. This can be stored in mem
OlderNewer