Skip to content

Android library for displaying an overview of events for a week like in a schedule(us) or timetable(uk).

License

Notifications You must be signed in to change notification settings

tobiasschuerg/android-week-view

Repository files navigation

Build Status

Android Week View

Modern Android library for displaying weekly schedules and events with both Compose and Classic View implementations.

Initially created for Schedule Deluxe, this library provides a flexible week view component that's perfect for calendar apps, timetables, and schedule management.

πŸ“± Screenshots

View-based Implementation Compose Implementation
Legacy View-based WeekView Modern Compose WeekView
⚠️ Deprecated βœ… Recommended

πŸ—οΈ Implementation Options

Option 1: Modern Compose Implementation

The modern, performant implementation built with Jetpack Compose.

Add to your Compose UI:

@Composable
fun MyWeekView() {
    val weekData = remember { WeekData() }
    val eventConfig = remember { EventConfig() }
    val weekViewConfig = remember { WeekViewConfig() }

    WeekViewCompose(
        weekData = weekData,
        eventConfig = eventConfig,
        weekViewConfig = weekViewConfig,
        onEventClick = { eventId ->
            // Handle event click
        }
    )
}

Create and add events:

val event = Event.Single(
    id = 1L,
    date = LocalDate.now(),
    title = "Team Meeting",
    shortTitle = "Meeting",
    timeSpan = TimeSpan.of(LocalTime.of(10, 0), Duration.ofHours(1)),
    backgroundColor = Color.Blue,
    textColor = Color.White
)

weekData.add(event)

Option 2: Legacy View Implementation (⚠️ Deprecated)

⚠️ Warning: The View-based implementation is deprecated. Please migrate to the Compose version for better performance, modern UI patterns, and future support.

Add to your XML layout:

<de.tobiasschuerg.weekview.view.WeekView android:id="@+id/week_view" android:layout_width="match_parent" android:layout_height="wrap_content" app:accent_color="@color/colorAccent" app:start_hour="8" app:end_hour="18" />

Configure in your Activity:

// ⚠️ DEPRECATED - Use WeekViewCompose instead
val config = EventConfig(showSubtitle = false, showTimeEnd = false)
weekView.eventConfig = config
weekView.setShowNowIndicator(true)

weekView.setEventClickListener { eventView ->
    // Handle event click
}

val event = Event.Single(
    id = 1337,
    date = LocalDate.now(),
    title = "Dentist Appointment",
    shortTitle = "DENT",
    timeSpan = TimeSpan.of(LocalTime.of(10, 0), Duration.ofHours(1)),
    backgroundColor = Color.RED,
    textColor = Color.WHITE
)
weekView.addEvent(event)

🎨 Customization

Event Configuration

val eventConfig = EventConfig(
    showSubtitle = true,
    showTimeEnd = true
)

Week View Configuration

val weekViewConfig = WeekViewConfig().apply {
    scalingFactor = 1.2f
}

Available Event Types

// Single event with specific time (fully supported)
val meeting = Event.Single(
    id = 1L,
    date = LocalDate.of(2024, 1, 15),
    title = "Project Review",
    shortTitle = "Review",
    timeSpan = TimeSpan.of(LocalTime.of(14, 0), Duration.ofHours(2)),
    backgroundColor = Color.Blue,
    textColor = Color.White
)

// All-day event (data model available)
val holiday = Event.AllDay(
    id = 2L,
    date = LocalDate.of(2024, 1, 16),
    title = "National Holiday",
    shortTitle = "Holiday"
)

// Multi-day event (data model available)
val conference = Event.MultiDay(
    id = 3L,
    date = LocalDate.of(2024, 1, 20),
    title = "Tech Conference",
    shortTitle = "Conf",
    lastDate = LocalDate.of(2024, 1, 22)
)

Note: Currently, only Event.Single is fully implemented in the view rendering. Event.AllDay and Event.MultiDay have data models but no view implementation yet.

πŸ“¦ Installation

Step 1: Add JitPack repository

Add this to your root build.gradle file:

allprojects {
    repositories {
        // ... other repositories
        maven { url 'https://jitpack.io' }
    }
}

Step 2: Add the dependency

Add this to your app build.gradle file:

dependencies {
    implementation 'com.github.tobiasschuerg:android-week-view:2.0.0'
    
    // Required for Compose implementation
    implementation platform('androidx.compose:compose-bom:2025.08.01')
    implementation 'androidx.compose.ui:ui'
    implementation 'androidx.compose.material3:material3'
    
    // Required for java.time API support on older Android versions
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5'
}

Step 3: Enable desugaring (required)

In your app build.gradle:

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
        coreLibraryDesugaringEnabled true
    }
}

πŸ”„ Migration Guide

Migrating from View-based to Compose

Before (Deprecated):

// XML Layout
<de.tobiasschuerg.weekview.view.WeekView android : id ="@+id/week_view" ... />

// Activity
weekView.addEvent(event)
weekView.setEventClickListener { ... }

After (Recommended):

// Compose
WeekViewCompose(
    weekData = weekData.apply { add(event) },
    onEventClick = { eventId -> TODO }
)

πŸ“± Sample App

The included sample app demonstrates both implementations:

  • Modern Compose WeekView
  • Legacy View-based WeekView

Run the sample app to see all features in action and choose the implementation that fits your needs.

πŸ“‹ API Documentation

Migration Notes

Starting from version 2.0.0:

  • βœ… Compose implementation is the recommended approach
  • ⚠️ View-based implementation is deprecated but maintained for compatibility

Starting from version 1.8.0:

  • Switched from ThreeTen Backport to core library desugaring
  • Requires coreLibraryDesugaring to be enabled

🀝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Run ./gradlew ktlintFormat before committing
  4. Add tests for new functionality
  5. Update documentation
  6. Submit a pull request

πŸ”— Links


⭐ Don't forget to star this repository if you find it useful!

About

Android library for displaying an overview of events for a week like in a schedule(us) or timetable(uk).

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages