Skip to content

Commit dd2e8e2

Browse files
Remove ScreenViewModel references and align docs
1 parent c535ff6 commit dd2e8e2

File tree

9 files changed

+275
-203
lines changed

9 files changed

+275
-203
lines changed

docs/core/core-module.md

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,53 @@
11
# Core Module
22

3-
The **core** package provides foundational building blocks shared across AppToolkit features. It offers base domain models, UI abstractions, utility helpers and dependency injection qualifiers used throughout the library.
3+
The **core** package provides building blocks shared across the app. It offers domain models, ViewModel classes, utility helpers and dependency injection qualifiers used throughout the project.
44

55
## Packages
66

77
### domain
8-
Defines reusable result wrappers and UI state models, plus base use case interfaces for repositories and operations.
8+
Houses use case classes and other business logic that operate on repositories.
99

1010
### ui
11-
Hosts composable components and base classes like `ScreenViewModel` and `DefaultSnackbarHost` that standardize screen state handling and Snackbar presentation.
11+
Contains Activities, Fragments and ViewModels such as `MainViewModel`.
1212

1313
### utils
14-
Includes helpers, extensions, constants and `DispatcherProvider` to access standard `CoroutineDispatcher` instances.
14+
Provides helpers like `OpenSourceLicensesUtils`, `ReviewHelper` and `EdgeToEdgeDelegate`.
1515

1616
### di
17-
Contains qualifiers such as `GithubToken` to assist dependency injection frameworks.
17+
Contains Hilt modules and qualifiers for dependency injection.
1818

1919
## Usage examples
2020

21-
### ScreenViewModel
22-
```kotlin
23-
class ExampleViewModel : ScreenViewModel<UiScreen, ExampleEvent, ExampleAction>(
24-
initialState = UiStateScreen(data = UiScreen())
25-
) {
26-
// handle events
21+
### ViewModel
22+
```java
23+
public class MainViewModel extends ViewModel {
24+
private final ShouldShowStartupScreenUseCase shouldShowStartupScreenUseCase;
25+
26+
public MainViewModel(ShouldShowStartupScreenUseCase shouldShowStartupScreenUseCase) {
27+
this.shouldShowStartupScreenUseCase = shouldShowStartupScreenUseCase;
28+
}
29+
30+
public boolean shouldShowStartupScreen() {
31+
return shouldShowStartupScreenUseCase.invoke();
32+
}
2733
}
2834
```
2935

30-
### DefaultSnackbarHost
31-
```kotlin
32-
val snackbarHostState = remember { SnackbarHostState() }
33-
34-
Scaffold(
35-
snackbarHost = { DefaultSnackbarHost(snackbarState = snackbarHostState) }
36-
) { /* screen content */ }
36+
### Snackbar helper
37+
```java
38+
Snackbar.make(view, "Message", Snackbar.LENGTH_SHORT).show();
3739
```
3840

39-
### DispatcherProvider
40-
```kotlin
41-
class ExampleRepository(private val dispatchers: DispatcherProvider) {
42-
suspend fun load() = withContext(dispatchers.io) {
43-
/* blocking work */
44-
}
45-
}
41+
### ReviewHelper
42+
```java
43+
ReviewHelper.launchInAppReviewIfEligible(activity, sessionCount, hasPromptedBefore, () -> {
44+
// callback when review flow finishes
45+
});
4646
```
4747

4848
## See also
4949

50-
- [[Library]] – overview of all modules and features.
51-
- [[Issue-Reporter-Module]] – demonstrates use of `ScreenViewModel` and networking helpers.
52-
- [[Support-Module]] – integrates `DispatcherProvider` for billing and donation flows.
50+
- [[Architecture]] – overview of app layers.
51+
- [[Data Layer]] – repository and data source details.
52+
- [[UI Components]] – common reusable views.
53+

docs/core/data-layer.md

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,80 @@
11
# Data Layer
22

3-
This page outlines the data-related building blocks provided by AppToolkit.
3+
This page outlines how the app manages and persists data.
44

5-
## HTTP client
5+
## Repositories
66

7-
`apptoolkit/data/client` exposes **KtorClient**, a factory for a preconfigured Ktor `HttpClient`. It installs JSON content negotiation, request timeouts, default headers and optional logging so callers only need to supply their own endpoints.
7+
Repositories expose data to the rest of the app and hide the underlying storage.
88

9-
### Setup
10-
11-
```kotlin
12-
val client = KtorClient().createClient(enableLogging = true)
9+
```java
10+
public interface MainRepository {
11+
boolean shouldShowStartupScreen();
12+
void markStartupScreenShown();
13+
}
1314
```
1415

15-
## DataStore
16-
17-
The `apptoolkit/data/datastore` package wraps Android DataStore in a singleton `CommonDataStore`. It centralizes preferences such as startup flags, theme options and user consents, exposing them as Kotlin `Flow`s with suspend functions to persist updates.
16+
`DefaultMainRepository` implements these methods using `SharedPreferences`:
1817

19-
### Usage
18+
```java
19+
public class DefaultMainRepository implements MainRepository {
20+
private final Context context;
2021

21-
```kotlin
22-
val dataStore = CommonDataStore.getInstance(context)
22+
public DefaultMainRepository(Context context) {
23+
this.context = context.getApplicationContext();
24+
}
2325

24-
// Observe a value
25-
val adsEnabled = dataStore.ads(default = true)
26+
@Override
27+
public boolean shouldShowStartupScreen() {
28+
SharedPreferences startup = context.getSharedPreferences("startup", Context.MODE_PRIVATE);
29+
return startup.getBoolean("value", true);
30+
}
2631

27-
// Save a value
28-
scope.launch { dataStore.saveThemeMode("dark") }
32+
@Override
33+
public void markStartupScreenShown() {
34+
SharedPreferences startup = context.getSharedPreferences("startup", Context.MODE_PRIVATE);
35+
startup.edit().putBoolean("value", false).apply();
36+
}
37+
}
2938
```
3039

31-
## Ads
40+
## Data sources
41+
42+
Remote and local sources supply the repositories with data. For example, `DefaultHomeRemoteDataSource` uses Volley to fetch promoted apps:
43+
44+
```java
45+
public class DefaultHomeRemoteDataSource implements HomeRemoteDataSource {
46+
private final RequestQueue requestQueue;
47+
private final String apiUrl;
48+
49+
public DefaultHomeRemoteDataSource(RequestQueue requestQueue, String apiUrl) {
50+
this.requestQueue = requestQueue;
51+
this.apiUrl = apiUrl;
52+
}
53+
54+
@Override
55+
public void fetchPromotedApps(PromotedAppsCallback callback) {
56+
JsonObjectRequest request = new JsonObjectRequest(
57+
Request.Method.GET,
58+
apiUrl,
59+
null,
60+
response -> { /* parse and callback */ },
61+
error -> { /* handle error */ }
62+
);
63+
requestQueue.add(request);
64+
}
65+
}
66+
```
3267

33-
Ads are configured through preferences in `CommonDataStore` via the `ads` flag and related consent entries. The `core/ads` package provides `AdsCoreManager`, which checks those preferences before initializing Google Mobile Ads and manages app-open ad loading and display.
68+
## Models
3469

35-
Use `AdsCoreManager` when the application should show an app-open ad on start or resume:
70+
Model classes like `PromotedApp` encapsulate the data returned by the layer:
3671

37-
```kotlin
38-
val adsManager = AdsCoreManager(context, buildInfoProvider)
39-
scope.launch { adsManager.initializeAds("ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx") }
40-
adsManager.showAdIfAvailable(activity, scope)
72+
```java
73+
public record PromotedApp(String name, String packageName, String iconUrl) {}
4174
```
4275

76+
## See also
77+
78+
- [[Architecture]] – overview of app layers.
79+
- [[Core Module]] – shared utilities and components.
80+

0 commit comments

Comments
 (0)