Skip to content
Iseeyourmonsters edited this page Jun 4, 2025 · 1 revision

Album Module Documentation

Table of Contents

Overview

The Album Module is a comprehensive solution for managing photo albums in the application. It provides functionality for creating, viewing, and managing albums, with support for different album types (custom, time-based, and location-based).

Key Features

  • Album creation and management
  • Multiple album types (Custom, Time, Location)
  • Album cover management
  • Photo organization
  • Album deletion
  • Media scanning and synchronization

Architecture

The module follows the MVVM (Model-View-ViewModel) architecture pattern:

  • View Layer: AlbumFragment, PhotoinAlbumFragment
  • ViewModel Layer: AlbumViewModel, PhotoinAlbumViewModel
  • Model Layer: AlbumDao, FileRepository
  • Adapter Layer: AlbumAdapter, PhotoinAlbumAdapter

Components

AlbumFragment

Purpose

AlbumFragment serves as the main UI component for displaying and managing albums. It implements a hierarchical view of albums categorized by type.

Key Methods

onCreateView
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

Initializes the fragment's UI components and sets up the album display.

Implementation Details:

  • Initializes section views (custom, time, location)
  • Sets up RecyclerViews with GridLayoutManager
  • Configures adapters for each section
  • Sets up click listeners and observers
toggleManageMode
private void toggleManageMode()

Toggles the album management mode, enabling/disabling album deletion.

Implementation Details:

  • Updates all adapters' management mode
  • Shows/hides delete icons
  • Maintains consistent state across sections
toggleSection
private void toggleSection(RecyclerView recyclerView, ImageView arrow)

Handles section expansion/collapse.

Parameters:

  • recyclerView: The section's RecyclerView
  • arrow: The section's arrow indicator

AlbumViewModel

Purpose

AlbumViewModel manages album data and operations, handling the business logic for album management.

Key Properties

private MutableLiveData<List<Album>> albumList
private MutableLiveData<DeleteEvent> deleteEvent
private MutableLiveData<String> event

Key Methods

loadAlbums
public void loadAlbums()

Loads the user's albums from the database.

Implementation Details:

  • Retrieves albums from AlbumDao
  • Categorizes albums by type
  • Updates LiveData with results
addAlbum
public void addAlbum(String name, int userId, boolean isAutoGenerated, 
                    boolean isCollaborative, String visibility)

Creates a new album.

Parameters:

  • name: Album name
  • userId: User identifier
  • isAutoGenerated: Whether the album is auto-generated
  • isCollaborative: Whether the album is collaborative
  • visibility: Album visibility setting
deleteAlbum
public void deleteAlbum(int albumId, String name)

Deletes an album and its contents.

Parameters:

  • albumId: Album identifier
  • name: Album name

AlbumAdapter

Purpose

AlbumAdapter manages the display of album items in RecyclerViews.

Key Features

  • Album cover display
  • Album name display
  • Delete functionality
  • Management mode support

Key Methods

onBindViewHolder
@Override
public void onBindViewHolder(AlbumViewHolder holder, int position)

Binds album data to view holder.

Implementation Details:

  • Sets album name
  • Loads album cover using Glide
  • Handles click events
  • Manages delete icon visibility
setManageMode
public void setManageMode(boolean isManageMode)

Toggles management mode.

Parameters:

  • isManageMode: Whether to enable management mode

PhotoinAlbum Components

PhotoinAlbumFragment

Manages the display of photos within an album.

PhotoinAlbumViewModel

Handles photo data and operations within an album.

PhotoinAlbumAdapter

Manages the display of photos in the album view.

Features

Album Types

  1. Custom Albums

    • User-created albums
    • Full management capabilities
    • Custom covers
  2. Time-based Albums

    • Auto-generated by date
    • Year and month organization
    • Automatic photo categorization
  3. Location-based Albums

    • Auto-generated by location
    • Geographic organization
    • Location-based photo grouping

Album Management

  • Creation
  • Deletion
  • Cover management
  • Photo organization
  • Visibility settings

Media Handling

  • Automatic media scanning
  • Cover image management
  • Photo synchronization
  • Efficient image loading

Implementation Details

Data Flow

  1. Album Creation

    User Input → AlbumViewModel → AlbumDao → FileRepository → UI Update
    
  2. Album Loading

    AlbumViewModel → AlbumDao → LiveData → UI Update
    
  3. Photo Management

    User Action → PhotoinAlbumViewModel → FileRepository → UI Update
    

Permission Handling

private boolean checkPermissions()
  • Checks for required permissions
  • Handles different Android versions
  • Manages storage access

Media Scanning

fileRepository.triggerMediaScanForAlbum(album.name, callback)
  • Asynchronous media scanning
  • Callback-based updates
  • Efficient resource management