Skip to content

Games‐Tab

Abdul Mueed | AM Dev edited this page Jun 29, 2026 · 2 revisions

🎮 Games Tab

The Games tab provides users with access to a curated collection of web-based games with smart caching, offline support, and a modern search UI.


📁 File Locations

Kotlin Files

File Path
Main Fragment ui/game/GameFragment.kt
ViewModel ui/game/GameViewModel.kt
Data Models ui/game/GameModel.kt
Cache Manager ui/game/GameCacheManager.kt
Game Player ui/game/GamePlayerFragment.kt
Adapter ui/game/GameAdapter.kt

Layout Files

File Path
Main Layout res/layout/fragment_game.xml
Game Player res/layout/fragment_game_player.xml
Normal Item res/layout/item_game_normal.xml
Large Item res/layout/item_game_large.xml
Shimmer res/layout/shimmer_game_grid.xml

External Data

Resource URL
Games JSON https://cdn.jsdelivr.net/gh/am-abdulmueed/PluginStream-Games@main/games_final_lite.json
GitHub API https://api.github.com/repos/am-abdulmueed/PluginStream-Games/commits

🗃️ Data Models

GameResponse

data class GameResponse(
    val title: String,
    val total_count: Int,
    val hits: List<GameModel>
)

GameModel

data class GameModel(
    val title: String,
    val gameURL: String,
    val genres: List<String> = emptyList(),
    val images: GameImages,
    val isFeatured: Boolean = false
)

GameImages

data class GameImages(
    val icon: String,
    val poster: String
)

🖥️ UI Components

Main Game Screen (GameFragment)

  • Search Bar — Real-time filtering by title and genres
  • Grid Layout — Responsive grid with featured game highlights
  • Shimmer Loading — Skeleton animation while data loads
  • Offline Support — Shows cached games when offline
  • Offers Navigation — Direct link to Offers section

Featured Game Pattern

Every 5th game gets a large poster card treatment:

isFeatured = (index + 1) % 5 == 0

This creates visual hierarchy — featured games stand out in the grid.

Game Player (GamePlayerFragment)

  • WebView — Embedded browser for game playback
  • Fullscreen — Immersive gaming mode
  • Network Detection — Handles online/offline states
  • Progress Indicator — Shows loading state on game init

🔄 API Flow

Initial Load

GameFragment
  └─ GameViewModel.fetchGamesIfNeeded()
       └─ GameCacheManager.fetchGamesWithCache()
            ├─ Check cache validity
            ├─ If outdated: Download from GitHub → Cache → Return
            └─ If current: Return cached data immediately

Search Flow

User types in search bar
  └─ GameViewModel.filterGames(query)
       └─ Filter cached games locally
            └─ Update UI instantly (no network call)

Game Launch Flow

User clicks game
  └─ Navigate to GamePlayerFragment
       └─ Load game URL in WebView (fullscreen)

💾 Caching System

The GameCacheManager uses GitHub commit hashes to detect if the games file has changed.

Cache Keys (SharedPreferences)

Key Purpose
KEY_CACHED_GAMES Stored games JSON
KEY_LAST_COMMIT Last known GitHub commit hash
KEY_CACHE_TIMESTAMP Cache creation time

Cache Logic

  1. First Launch → Download from GitHub, cache locally
  2. Subsequent Launches → Check GitHub for new commit hash
  3. If Changed → Download fresh data, update cache
  4. If Same → Use cached data immediately
  5. Offline → Use cached data regardless

Useful Methods

GameCacheManager.clearCache(context)         // Force refresh
GameCacheManager.hasCache(context)           // Check cache exists
GameCacheManager.getCacheInfo(context)       // Debug info

🔍 Search Implementation

fun filterGames(query: String): List<GameModel> {
    val currentGames = _allGames.value ?: emptyList()
    if (query.isBlank()) return currentGames

    return currentGames.filter { game ->
        game.title.contains(query, ignoreCase = true) ||
        game.genres.any { it.contains(query, ignoreCase = true) }
    }
}
  • Searches both title and genres
  • Case-insensitive
  • Real-time (instant results as user types)

⚠️ Error Handling

Scenario Behavior
Network error Use cached data, show offline indicator
No cached data Show empty state with message
Game URL invalid Exception caught, user notified
WebView error Graceful fallback with retry option

🐛 Debug Logging

val cacheInfo = GameCacheManager.getCacheInfo(context)
Log.d("Games", "Cache exists: ${cacheInfo.hasCache}")
Log.d("Games", "Last update: ${cacheInfo.lastUpdateTimestamp}")
Log.d("Games", "Commit hash: ${cacheInfo.lastCommitHash}")

🔧 Games JSON Optimization (Playgama Scripts)

The games_final_lite.json is produced by PowerShell and Batch scripts that optimize raw game data.

Script Files

File Purpose
UpdateGameList.ps1 Main data collection & transformation
optimize_games.bat Initiates and schedules optimization
games.json Raw unoptimized source data
games_final_lite.json Final optimized output

Optimization Steps

  1. Collect — Scan Playgama API for game metadata
  2. Filter — Remove duplicates, validate URLs and images
  3. Standardize — Normalize genre names
  4. Trim — Remove unnecessary fields, minify JSON
  5. Output — Produce lightweight games_final_lite.json

Final JSON Structure (per game)

{
    "title": "Fruits into Baskets",
    "gameURL": "https://playgama.com/export/game/fruits-into-baskets?clid=...",
    "genres": ["puzzle", "food", "logic", "easy"],
    "images": {
        "icon": "https://playgama.com/cdn-cgi/imagedelivery/.../enlarged",
        "poster": "https://playgama.com/cdn-cgi/imagedelivery/.../enlarged"
    }
}

📡 GitHub API Response Example

[
    {
        "sha": "abc123def456",
        "commit": {
            "message": "Update games list",
            "author": {
                "date": "2026-05-08T12:00:00Z"
            }
        }
    }
]

🗺️ Planned Features (Roadmap)

  • Game categories / advanced genre filtering
  • Favorites system
  • Recently played history
  • Play time and achievement tracking
  • Background sync when online
  • A/B testing framework

🔒 Security

  • All games load over HTTPS only
  • WebView runs in a secure sandbox
  • Game data cached in SharedPreferences (private to app)
  • All network traffic uses SSL/TLS

⚡ Performance Tips

  • Cached data loads instantly on app open
  • GitHub commit check runs in background (non-blocking)
  • Search filtering is local — no network calls needed
  • RecyclerView uses DiffUtil for efficient list updates