persiancal / android-sdk

Android SDK for Persian calendar events
6 stars 4 forks source link
android kotlin library persian-calendar

Android SDK for PersianCal

Build Status

Setup

1. Provide the gradle dependency

Add it in your root build.gradle at the end of repositories:

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

Add the dependency:

dependencies {
    //required
    implementation "com.github.persiancal.android-sdk:core:${latestRelease}"

    //optional
    implementation "com.github.persiancal.android-sdk:sdk-local:${latestRelease}"
    implementation "com.github.persiancal.android-sdk:sdk-remote:${latestRelease}"
}

2. Add codes

add INTERNET permission to android manifest

<uses-permission android:name="android.permission.INTERNET" />

implement init function of RemoteClandarEvents in application class

override fun onCreate() {
        super.onCreate()
        ...
        RemoteCalendarEvents
            .addCalendar(CalendarType.JALALI)
            .addCalendar(CalendarType.HIJRI)
            .addCalendar(CalendarType.GREGORIAN)
            .init(this)
    //or

        LocalCalendarEvents
            .addCalendar(CalendarType.JALALI)
            .addCalendar(CalendarType.HIJRI)
            .addCalendar(CalendarType.GREGORIAN)
            .init(this)
        ...
}

You can add each type of calenders that want

there is three function for getting calendar events

- getJalaliEvents(dayOfMonth: Int, month: Int): MutableList<RemoteJalaliEventsDb>?
- getHijriEvents(dayOfMonth: Int, month: Int): MutableList<RemoteHijriEventsDb>?
- getGregorianEvents(dayOfMonth: Int, month: Int): MutableList<RemoteGregorianEventsDb>?

After init RemoteCalendarEvents you can access instance of it everywhere:

RemoteCalendarEvents.getInstance()

for example we want Jalali events of month=2 & dayOfMonth=1

val jalaliEvents= RemoteCalendarEvents.getInstance().getJalaliEvents(1,2)

Requirements

Libraries & Dependencies in the Demo

Libraries & Dependencies in the SDK