MCPcopy
hub / github.com/JakeWharton/u2020

github.com/JakeWharton/u2020 @main sqlite

repository ↗ · DeepWiki ↗
637 symbols 1,473 edges 106 files 63 documented · 10%
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

  • Dagger - http://square.github.io/dagger
  • ButterKnife - http://jakewharton.github.io/butterknife
  • Retrofit - http://square.github.io/retrofit
  • Moshi - https://github.com/square/moshi
  • Picasso - http://square.github.io/picasso
  • OkHttp - http://square.github.io/okhttp
  • RxJava - https://github.com/ReactiveX/RxJava
  • Timber - http://github.com/JakeWharton/timber
  • Madge - http://github.com/JakeWharton/madge
  • ProcessPhoenix - https://github.com/JakeWharton/ProcessPhoenix
  • Scalpel - http://github.com/JakeWharton/scalpel
  • LeakCanary - http://github.com/square/leakcanary
  • Telescope - https://github.com/mattprecious/telescope

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.

Extension points exported contracts — how you extend this code

ViewContainer (Interface)
An indirection which allows controlling the root container used for each activity. [4 implementers]
app/src/main/java/com/jakewharton/u2020/ui/ViewContainer.java
IntentFactory (Interface)
Creates Intents for launching into external applications. [2 implementers]
intent-factory/src/main/java/com/jakewharton/u2020/intentfactory/IntentFactory.java
MockResponseSupplier (Interface)
(no doc) [3 implementers]
service/github-mock/src/main/java/com/jakewharton/u2020/data/api/MockResponseSupplier.java
GithubService (Interface)
(no doc) [2 implementers]
service/github/src/main/java/com/jakewharton/u2020/data/api/GithubService.java
DrawerListener (Interface)
Listener for monitoring events about drawers. [2 implementers]
app/src/internalDebug/java/com/jakewharton/u2020/ui/debug/DebugDrawerLayout.java
BooleanSupplier (Interface)
(no doc)
intent-factory/src/debug/java/com/jakewharton/u2020/intentfactory/CapturingIntentFactory.java
ReportDetailsListener (Interface)
(no doc) [2 implementers]
app/src/internal/java/com/jakewharton/u2020/ui/bugreport/BugReportView.java
ReportListener (Interface)
(no doc) [2 implementers]
app/src/internal/java/com/jakewharton/u2020/ui/bugreport/BugReportDialog.java

Core symbols most depended-on inside this repo

append
called by 44
app/src/main/java/com/jakewharton/u2020/ui/misc/Truss.java
get
called by 40
service/github-mock/src/main/java/com/jakewharton/u2020/data/api/MockResponseSupplier.java
getContext
called by 30
app/src/main/java/com/jakewharton/u2020/ui/misc/BindableAdapter.java
set
called by 24
service/github-mock/src/main/java/com/jakewharton/u2020/data/api/MockResponseSupplier.java
build
called by 16
app/src/main/java/com/jakewharton/u2020/ui/misc/Truss.java
findDrawerWithGravity
called by 13
app/src/internalDebug/java/com/jakewharton/u2020/ui/debug/DebugDrawerLayout.java
isDrawerView
called by 13
app/src/internalDebug/java/com/jakewharton/u2020/ui/debug/DebugDrawerLayout.java
build
called by 12
service/github/src/main/java/com/jakewharton/u2020/data/api/SearchQuery.java

Shape

Method 518
Class 102
Interface 11
Enum 6

Languages

Java100%

Modules by API surface

app/src/internalDebug/java/com/jakewharton/u2020/ui/debug/DebugDrawerLayout.java118 symbols
app/src/internalDebug/java/com/jakewharton/u2020/data/DebugDataModule.java26 symbols
app/src/internalDebug/java/com/jakewharton/u2020/ui/debug/DebugView.java23 symbols
service/github-mock/src/main/java/com/jakewharton/u2020/data/api/SortUtil.java16 symbols
app/src/main/java/com/jakewharton/u2020/data/LumberYard.java15 symbols
app/src/internalDebug/java/com/jakewharton/u2020/ui/debug/ContextualDebugActions.java14 symbols
app/src/internalDebug/java/com/jakewharton/u2020/ui/logs/LogAdapter.java13 symbols
service/github/src/main/java/com/jakewharton/u2020/data/api/model/Repository.java12 symbols
app/src/main/java/com/jakewharton/u2020/ui/trending/TrendingAdapter.java12 symbols
app/src/main/java/com/jakewharton/u2020/ui/trending/TrendingView.java11 symbols
app/src/main/java/com/jakewharton/u2020/ui/misc/BindableAdapter.java10 symbols
app/src/main/java/com/jakewharton/u2020/data/DataModule.java10 symbols

For agents

$ claude mcp add u2020 \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact