Skip to content

adaptyteam/Focus-Journal-Android

Repository files navigation

Focus Journal for Android - Complete with Adapty Integration

This is a complete Android implementation of a journal app using Jetpack Compose and the Adapty SDK for subscription management. The app demonstrates how to implement premium feature gating with real subscription processing.

Features

  • Free journal entry creation - Users can write and save daily journal entries
  • Premium features behind paywall - History viewing requires a premium subscription
  • Real subscription processing - Powered by Adapty SDK with Google Play Billing
  • Native Android design - Built with Jetpack Compose following Material Design 3
  • Local data persistence - Journal entries stored using Room database

Prerequisites

Before running this project, ensure you have:

  • Android Studio (Arctic Fox or later)
  • Android SDK (API level 26+)
  • Kotlin (1.9.0+)
  • Adapty account - Sign up here
  • Google Play Console account - For subscription products

Getting Started

1. Clone the Repository

git clone https://github.com/ferrousguy/Focus-Journal-Android.git
cd FocusJournal

2. Configure Adapty SDK

  1. Go to your Adapty Dashboard
  2. Copy your API Key from General settings
  3. Open app/src/main/java/io/adapty/focusjournal/utils/AppConstants.kt
  4. Replace "API key goes here" with your actual Adapty API key
object AppConstants {
    object Adapty {
        const val API_KEY = "your_adapty_api_key_here"
        const val ACCESS_LEVEL_ID = "premium"
        const val PLACEMENT_ID = "on_tap_history"
    }
}

3. Set Up Adapty Dashboard

Configure the following in your Adapty dashboard:

  • Access Level: Create an access level with ID "premium"
  • Placement: Create a placement with ID "on_tap_history"
  • Products: Set up your subscription products in Google Play Console and link them in Adapty
  • Paywall: Configure a paywall for the placement

4. Install Dependencies

Open the project in Android Studio and sync Gradle files. All dependencies will be automatically downloaded.

5. Run the App

  1. Connect an Android device or start an emulator
  2. Click Run in Android Studio or use:
./gradlew installDebug

Project Structure

app/src/main/java/io/adapty/focusjournal/
├── FocusJournalApplication.kt          # App initialization & Adapty setup
├── MainActivity.kt                     # Main activity
├── data/
│   ├── dao/
│   │   └── JournalEntryDao.kt         # Room database access
│   ├── database/
│   │   ├── Converters.kt              # Room type converters
│   │   └── FocusJournalDatabase.kt    # Room database setup
│   ├── model/
│   │   └── JournalEntry.kt            # Data model
│   └── repository/
│       └── JournalRepository.kt       # Data repository
├── navigation/
│   └── FocusJournalNavigation.kt      # Navigation setup
├── ui/
│   ├── screen/
│   │   ├── HistoryScreen.kt           # Premium history view
│   │   ├── HomeScreen.kt              # Main journal entry screen
│   │   └── PaywallScreen.kt           # Subscription paywall
│   └── theme/
│       ├── Color.kt                   # App colors
│       ├── Theme.kt                   # Material theme
│       └── Type.kt                    # Typography
├── utils/
│   └── AppConstants.kt                # Configuration constants
└── viewmodel/
    └── ProfileManager.kt              # Subscription & data management

Adapty Integration

SDK Initialization

The Adapty SDK is initialized in FocusJournalApplication.kt:

class FocusJournalApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        Adapty.activate(this, Builder(AppConstants.Adapty.API_KEY).build())
    }
}

Premium Access Control

Premium status is managed in ProfileManager.kt:

val isPremium: StateFlow<Boolean> = customerProfile.map { profile ->
        profile?.accessLevels?.get(AppConstants.Adapty.ACCESS_LEVEL_ID)?.let { accessLevel ->
            accessLevel.isActive || accessLevel.isInGracePeriod || accessLevel.isLifetime
        } ?: false
    }.stateIn(
        scope = viewModelScope,
        started = SharingStarted.WhileSubscribed(5000),
        initialValue = false
    )

Paywall Implementation

The paywall is triggered when non-premium users try to access history:

  • Placement ID: "on_tap_history"
  • Access Level: "premium"
  • Purchase Flow: Handled through Adapty SDK with callbacks

Running the Example

  1. Free User Flow:

    • Launch the app
    • Create journal entries freely
    • Tap "View History" → Paywall appears
    • Purchase subscription → History unlocks
  2. Premium User Flow:

    • Launch the app (with active subscription)
    • Create journal entries
    • Tap "View History" → History view opens directly

Features

Available to All Users

  • Create and save journal entries
  • Local storage of entries

Premium Features (Subscription Required)

  • View complete history of all journal entries
  • Chronological display with timestamps

Learn More

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages