Skip to content

Latest commit

 

History

History
225 lines (161 loc) · 6.75 KB

reference.md

File metadata and controls

225 lines (161 loc) · 6.75 KB

Documentation for Android SDK: Workmate

Overview

The Workmate Android SDK is designed to facilitate task management for field teams by providing a set of functionalities such as task creation, task updates, session management (start/end workday), and user authentication. This SDK leverages the SOLID principles to ensure high maintainability, scalability, and flexibility.


SDK Class Structure

1. WorkmateSDK

The WorkmateSDK class is the entry point for initializing the SDK and setting up the required configuration.

public class WorkmateSDK {
    public void initialize(Context context, String clientId, String clientSecret, String appId, String deviceId, WorkmateAuthListener authListener) {
        // Implementation for initializing the SDK with necessary configurations.
    }
}

Responsibilities:

  • Initializes the SDK with necessary authentication details.
  • Acts as a central point for accessing various managers like TaskManager, AuthManager, and SessionManager.

2. AuthManager

The AuthManager class handles all authentication-related tasks.

public class AuthManager {
    public void authenticate(String clientId, String clientSecret, WorkmateAuthListener authListener) {
        // Implementation for user authentication.
    }

    public void refreshToken(String refreshToken) {
        // Implementation for refreshing the authentication token.
    }
}

Responsibilities:

  • Handles user authentication.
  • Manages token refresh and other authentication-related tasks.

SOLID Application:

  • SRP: Manages only authentication.
  • OCP: Can extend to support different authentication methods without modifying existing code.

3. SessionManager

The SessionManager class is responsible for managing user sessions, including starting and ending the workday.

public class SessionManager {
    public void startWorkDay(WorkmateSessionListener sessionListener) {
        // Implementation to start the workday session.
    }

    public void endWorkDay(WorkmateSessionListener sessionListener) {
        // Implementation to end the workday session.
    }
}

Responsibilities:

  • Manages the lifecycle of a workday session.
  • Provides callbacks for session-related events.

SOLID Application:

  • SRP: Focuses on session management.
  • ISP: Interfaces are segregated based on functionality; clients only implement what they need.

4. TaskManager

The TaskManager class manages tasks, including creating, updating, and checking in/out of tasks.

public class TaskManager {
    public Task createTask(TaskDetails taskDetails) {
        // Implementation for creating a new task.
    }

    public boolean updateTask(String taskId, TaskDetails updatedTaskDetails) {
        // Implementation for updating an existing task.
    }

    public boolean checkInToTask(String taskId, WorkmateTaskListener taskListener) {
        // Implementation for checking in to a task.
    }

    public boolean checkOutFromTask(String taskId, WorkmateTaskListener taskListener) {
        // Implementation for checking out from a task.
    }
}

Responsibilities:

  • Manages task-related operations such as creating, updating, and managing the status of tasks.
  • Provides necessary methods for checking in and checking out of tasks.

SOLID Application:

  • SRP: Dedicated to task management.
  • OCP: Allows new types of tasks to be added without changing the existing code.
  • LSP: Ensures that any subclass can be used without altering the intended task management operations.

Interfaces and Models

1. Listener Interfaces

These interfaces handle asynchronous responses and events from the SDK:

  • WorkmateAuthListener: Handles authentication events.
  • WorkmateSessionListener: Manages session start/end events.
  • WorkmateTaskListener: Manages task-related events.

Example:

public interface WorkmateAuthListener {
    void onAuthSuccess(AuthResponse authResponse);
    void onAuthFailure(AuthError authError);
}

SOLID Application:

  • ISP: Clients implement only the interfaces relevant to their needs.

2. Data Models

Data models represent various entities used within the SDK:

  • AuthResponse: Contains data related to authentication responses.
  • TaskDetails: Holds information about tasks.
  • AuthError, SessionError, TaskError: Represents error states for different operations.

Example:

public class TaskDetails {
    private String description;
    private Date dueDate;
    private int priority;

    // Constructors, getters, and setters
}

SOLID Application:

  • SRP: Each model represents a single entity.
  • OCP: Models can be extended with additional attributes as needed without altering existing ones.

Key Features and Usage

Initialization

To start using the Workmate SDK, initialize it using the initialize method with the necessary parameters:

WorkmateSDK sdk = new WorkmateSDK();
sdk.initialize(context, clientId, clientSecret, appId, deviceId, new WorkmateAuthListener() {
    @Override
    public void onAuthSuccess(AuthResponse authResponse) {
        // Handle successful authentication
    }

    @Override
    public void onAuthFailure(AuthError authError) {
        // Handle authentication failure
    }
});

Task Management

Create and manage tasks through TaskManager:

TaskManager taskManager = sdk.getTaskManager();
TaskDetails taskDetails = new TaskDetails("Task Description", new Date(), 1);
Task newTask = taskManager.createTask(taskDetails);

Session Management

Start and end workday sessions using SessionManager:

SessionManager sessionManager = sdk.getSessionManager();
sessionManager.startWorkDay(new WorkmateSessionListener() {
    @Override
    public void onSessionStarted() {
        // Handle session start
    }

    @Override
    public void onSessionEnded() {
        // Handle session end
    }

    @Override
    public void onSessionError(SessionError sessionError) {
        // Handle session errors
    }
});

Conclusion

The Workmate SDK, built on the principles of SOLID and OOD, provides a robust, flexible, and maintainable framework for managing tasks and user sessions in Android applications. Its modular design ensures ease of extension and customization, making it an ideal choice for developers looking to integrate task management functionality into their apps.

By adhering to SOLID principles, the SDK ensures that each component is highly focused, reducing complexity and improving testability. The use of interfaces allows for flexible implementations and easy integration with other components, providing a seamless experience for developers and end-users alike.