Convert Figma logo to code with AI

JakeWharton logou2020

A sample Android app which showcases advanced usage of Dagger among other open source libraries.

5,683
932
5,683
14

Top Related Projects

43,026

A type-safe HTTP client for Android and the JVM

45,699

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

17,430

A fast dependency injector for Android and Java.

50,119

Google core libraries for Java

47,869

RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.

Quick Overview

The JakeWharton/u2020 repository is a sample Android application that demonstrates best practices for Android development. It serves as a reference implementation for building robust, production-ready Android applications.

Pros

  • Clean Architecture: The project follows the Clean Architecture principles, which promote separation of concerns and testability.
  • Comprehensive Tooling: The project utilizes a wide range of modern Android development tools and libraries, such as Dagger, RxJava, Retrofit, and Timber.
  • Extensive Testing: The project includes a comprehensive suite of unit, integration, and UI tests, ensuring the codebase is well-tested and maintainable.
  • Continuous Integration: The project is set up with a continuous integration (CI) pipeline, ensuring that changes are automatically built, tested, and deployed.

Cons

  • Complexity: The project's comprehensive nature and use of advanced architectural patterns may make it challenging for beginners to understand and navigate.
  • Potential Overkill: Depending on the scope and requirements of a specific project, the level of complexity and the number of dependencies in u2020 may be overkill.
  • Outdated Dependencies: Some of the dependencies used in the project may be outdated, and developers may need to update them to use the latest versions.
  • Limited Documentation: While the project provides a good reference implementation, the documentation could be more comprehensive, especially for newcomers to the codebase.

Code Examples

N/A (This is not a code library)

Getting Started

N/A (This is not a code library)

Competitor Comparisons

43,026

A type-safe HTTP client for Android and the JVM

Pros of Retrofit

  • Widely adopted and actively maintained library for API communication
  • Extensive documentation and community support
  • Seamless integration with OkHttp for efficient networking

Cons of Retrofit

  • Steeper learning curve for beginners
  • Requires more setup and configuration compared to simpler alternatives
  • May be overkill for small projects with basic API needs

Code Comparison

Retrofit:

public interface GitHubService {
  @GET("users/{user}/repos")
  Call<List<Repo>> listRepos(@Path("user") String user);
}

u2020:

@Singleton
public class DataModule {
  @Provides @Singleton ApiService provideApiService() {
    return new ApiService();
  }
}

Key Differences

  • Retrofit focuses on API communication, while u2020 is a demo app showcasing various Android development practices
  • Retrofit is a library that can be integrated into projects, whereas u2020 is a complete application
  • u2020 demonstrates Dagger usage for dependency injection, while Retrofit doesn't enforce any specific DI framework

Use Cases

  • Choose Retrofit for robust API integration in Android projects
  • Use u2020 as a learning resource for modern Android development techniques

Community and Support

  • Retrofit has a larger community and more frequent updates
  • u2020 serves as an educational resource but may not reflect the latest Android best practices
45,699

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

Pros of OkHttp

  • Widely adopted HTTP client with extensive features and robust performance
  • Actively maintained with frequent updates and improvements
  • Comprehensive documentation and strong community support

Cons of OkHttp

  • Focused solely on HTTP networking, lacking the broader application architecture of u2020
  • May require additional libraries for higher-level functionality like image loading or dependency injection

Code Comparison

u2020 (Retrofit usage, which is built on OkHttp):

@Inject OkHttpClient client;
@Inject RestAdapter restAdapter;

public ApiService apiService() {
  return restAdapter.create(ApiService.class);
}

OkHttp (direct usage):

OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
    .url("https://api.example.com/data")
    .build();
Response response = client.newCall(request).execute();

Summary

While u2020 serves as a comprehensive demo app showcasing various Android development practices, OkHttp focuses specifically on efficient HTTP networking. OkHttp provides a powerful foundation for network operations, which can be integrated into larger architectures like those demonstrated in u2020. The choice between the two depends on whether you need a full application structure (u2020) or a dedicated networking solution (OkHttp).

17,430

A fast dependency injector for Android and Java.

Pros of Dagger

  • More actively maintained with regular updates and releases
  • Broader adoption in the Android development community
  • Extensive documentation and official Google support

Cons of Dagger

  • Steeper learning curve for beginners
  • More complex setup and configuration
  • Can lead to increased build times in large projects

Code Comparison

u2020:

public class U2020Module {
  @Provides @Singleton AppContainer provideAppContainer() {
    return AppContainer.DEFAULT;
  }
}

Dagger:

@Module
public class AppModule {
  @Provides
  @Singleton
  AppContainer provideAppContainer() {
    return new ProductionAppContainer();
  }
}

Key Differences

  • u2020 is a sample app showcasing various Android development practices, while Dagger is a dependency injection framework
  • u2020 uses an older version of Dagger, whereas the Dagger repository contains the latest version
  • u2020 demonstrates practical usage of Dagger in a real-world scenario, while Dagger itself focuses on providing the core DI functionality

Use Cases

  • Use u2020 to learn about Android app architecture and best practices
  • Choose Dagger for implementing dependency injection in production Android applications

Community and Support

  • u2020 has a smaller, more focused community
  • Dagger benefits from Google's backing and a larger user base
50,119

Google core libraries for Java

Pros of Guava

  • Extensive utility library with a wide range of functionalities
  • Well-maintained and actively developed by Google
  • Comprehensive documentation and widespread adoption in the Java ecosystem

Cons of Guava

  • Large library size, which may increase app size and compilation time
  • Steeper learning curve due to its extensive API
  • May introduce unnecessary dependencies for projects that only need a few utilities

Code Comparison

u2020:

@Provides @Singleton
Picasso providePicasso(OkHttpClient client, @Named("API") String endpoint) {
  return new Picasso.Builder(this)
      .downloader(new OkHttpDownloader(client))
      .listener(new Picasso.Listener() {
        @Override public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) {
          Timber.e(e, "Failed to load image: %s", uri);
        }
      })
      .build();
}

Guava:

List<String> names = Lists.newArrayList("John", "Jane", "Adam");
Set<String> uniqueNames = Sets.newHashSet(names);
Map<String, Integer> nameToAge = Maps.newHashMap();
nameToAge.put("John", 25);
nameToAge.put("Jane", 30);

The code snippets showcase different aspects of the libraries. u2020 demonstrates dependency injection and image loading configuration, while Guava highlights its collection utilities for creating and manipulating data structures.

47,869

RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.

Pros of RxJava

  • Comprehensive reactive programming library with a wide range of operators
  • Supports multiple programming paradigms (imperative, functional, reactive)
  • Extensive documentation and community support

Cons of RxJava

  • Steeper learning curve due to its complexity and extensive API
  • Can lead to overuse of reactive patterns in scenarios where simpler solutions suffice
  • Potential for performance overhead in simple use cases

Code Comparison

RxJava:

Observable.just(1, 2, 3, 4, 5)
    .filter(x -> x % 2 == 0)
    .map(x -> x * 2)
    .subscribe(System.out::println);

u2020:

List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
numbers.stream()
    .filter(x -> x % 2 == 0)
    .map(x -> x * 2)
    .forEach(System.out::println);

Summary

RxJava is a powerful reactive programming library offering extensive functionality for handling asynchronous data streams. It excels in complex scenarios but may be overkill for simpler tasks. u2020, while not directly comparable as it's a demo app, represents a more traditional approach using Java 8 streams for data manipulation. The choice between these approaches depends on the specific requirements of your project and the complexity of your data flow.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

U+2020

A sample Android app which showcases advanced usage of Dagger among other open source libraries.

Watch the corresponding talk or view the slides.

The ObjectGraph is created in the U2020App's onCreate method. The Modules class provides a single method, list, which returns the list of module instances to use.

In order to add functionality in the 'debug' version of the app, this class is only present in the release/ and debug/ build type folders. The 'release' version only includes the U2020Module while the 'debug' version includes both U2020Module and DebugU2020Module, the latter of which is only present in the debug/ build type folder and is an override module.

Through the use of Dagger overrides, the 'debug' version of the app adds a slew of debugging features to the app which are presented in the Debug Drawer™. The drawer is opened by a bezel swipe from the right of the screen. From here you can change and view all of the developer options of the application.

The drawer is provided by the simple interface ViewContainer. This is an indirection that the single activity uses to fetch its container into which it can place its content. The default implementation returns the Android-provided content view. The 'debug' version overrides this with DebugViewContainer which is responsible for creating the drawer, adding it to the activity, and returning its content view group. It also injects all of the developer objects and binds them to controls in the drawer.

The most notable feature the 'debug' version exposes is the concept of endpoints. Using the spinner at the top of the drawer, you can change the endpoint to which the app communicates. We also expose a false endpoint named "Mock Mode" which simulates an in-memory server inside the app. This "Mock Mode" eases manual testing and also provides a static set of data to write instrumentation tests against.

"Mock Mode" can be queried when modules are configuring their dependencies which is what allows simulating the remote server in-memory.

@Singleton class MockFoo() {
  @Inject MockFoo() {}
  // ...
}
@Provides @Singleton Foo provideFoo(@IsMockMode boolean isMockMode, MockFoo mockFoo) {
  return isMockMode ? return mockFoo : new RealFoo();
}

See DebugDataModule and DebugApiModule to see this in action in the real app.

The mock implementations of these types are some of those injected into the DebugViewContainer for binding in the drawer. This allows us to do things like control their fake network behavior and alter their behavior.

In order to keep the shared state which represents the server-side data we use a ServerDatabase singleton. At present this is only done with a combination of in-memory collections and images in the debug/assets/. In a more complex app you could even use a full database. This class is injected into each mock service which uses its methods to query and mutate state (e.g., MockGalleryService).

Debug drawer

Libraries

To Do

  • Something with animations to showcase animation control.
  • Network errors probably crash the app.
  • Add another part of the app other than 'trending' so we can demo child graphs.

License

Copyright 2014 Jake Wharton

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.