Skip to content

Commit

Permalink
opt
Browse files Browse the repository at this point in the history
  • Loading branch information
orbitalsonic committed Dec 31, 2024
1 parent 8911bcd commit d14d60c
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 110 deletions.
101 changes: 73 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ To fetch prayer times, use the `PrayerTimeManager` class. The following examples

#### Fetching Prayer Times

##### Note
The arguments passed for fetching prayer and fasting times are defaults. You must update the latitude, longitude, and other parameters as per your specific requirements.

##### Initialize `PrayerTimeManager`
```kotlin
val prayerTimeManager = PrayerTimeManager()
Expand All @@ -85,8 +82,10 @@ prayerTimeManager.fetchTodayPrayerTimes(
organizationStandard = OrganizationStandard.KARACHI,
timeFormat = TimeFormat.HOUR_12
) { result ->
result.onSuccess { prayerTimes ->
prayerTimes.forEach {
result.onSuccess { prayerItem ->
val date = Date(prayerItem.date)
Log.d("PrayerTimeTag", "Date: $date")
prayerItem.prayerList.forEach {
Log.d("PrayerTimeTag", "${it.prayerName}: ${it.prayerTime}")
}
}.onFailure { exception ->
Expand All @@ -105,10 +104,11 @@ prayerTimeManager.fetchCurrentMonthPrayerTimes(
organizationStandard = OrganizationStandard.KARACHI,
timeFormat = TimeFormat.HOUR_12
) { result ->
result.onSuccess { prayerTimes ->
prayerTimes.forEachIndexed { index, dailyPrayerList ->
Log.d("PrayerTimeTag", "----Day ${index + 1}----")
dailyPrayerList.forEach {
result.onSuccess { prayerItems ->
prayerItems.forEachIndexed { index, prayerItem ->
val date = Date(prayerItem.date)
Log.d("PrayerTimeTag", "Day ${index + 1} (${date}):")
prayerItem.prayerList.forEach {
Log.d("PrayerTimeTag", "${it.prayerName}: ${it.prayerTime}")
}
}
Expand All @@ -128,12 +128,13 @@ prayerTimeManager.fetchCurrentYearPrayerTimes(
organizationStandard = OrganizationStandard.KARACHI,
timeFormat = TimeFormat.HOUR_12
) { result ->
result.onSuccess { prayerTimes ->
prayerTimes.forEachIndexed { monthIndex, monthlyPrayerList ->
Log.d("PrayerTimeTag", "--------Month ${monthIndex + 1}--------")
monthlyPrayerList.forEachIndexed { dayIndex, dailyPrayerList ->
Log.d("PrayerTimeTag", "--------Day ${dayIndex + 1}--------")
dailyPrayerList.forEach {
result.onSuccess { prayerItems ->
prayerItems.forEachIndexed { monthIndex, monthlyPrayerItems ->
Log.d("PrayerTimeTag", "Month ${monthIndex + 1}:")
monthlyPrayerItems.forEachIndexed { dayIndex, prayerItem ->
val date = Date(prayerItem.date)
Log.d("PrayerTimeTag", "Day ${dayIndex + 1} (${date}):")
prayerItem.prayerList.forEach {
Log.d("PrayerTimeTag", "${it.prayerName}: ${it.prayerTime}")
}
}
Expand All @@ -143,15 +144,11 @@ prayerTimeManager.fetchCurrentYearPrayerTimes(
}
}
```
---

### Fasting Time Manager
To fetch fasting times, use the `PrayerTimeManager` class in conjunction with fasting-related methods and LiveData. The following examples demonstrate its usage.

#### Fetching Fasting Times
---

##### Note
The arguments passed for fetching fasting and prayer times are defaults. You must update the latitude, longitude, and other parameters as per your specific requirements.
## Fasting Time Manager
To fetch fasting times, use the `PrayerTimeManager` class in conjunction with fasting-related methods. The following examples demonstrate its usage.

### Fetching Fasting Times

Expand All @@ -166,6 +163,8 @@ prayerTimeManager.fetchTodayFastingTimes(
timeFormat = TimeFormat.HOUR_12
) { result ->
result.onSuccess { fastingItem ->
val date = Date(fastingItem.date)
Log.d("FastingTimeTag", "Date: $date")
Log.d("FastingTimeTag", "Sehri: ${fastingItem.sehriTime}, Iftar: ${fastingItem.iftaarTime}")
}.onFailure { exception ->
Log.e("FastingTimeTag", "Error fetching daily fasting times", exception)
Expand All @@ -185,7 +184,8 @@ prayerTimeManager.fetchCurrentMonthFastingTimes(
) { result ->
result.onSuccess { fastingTimes ->
fastingTimes.forEachIndexed { index, fastingItem ->
Log.d("FastingTimeTag", "Day ${index + 1} -> Sehri: ${fastingItem.sehriTime}, Iftar: ${fastingItem.iftaarTime}")
val date = Date(fastingItem.date)
Log.d("FastingTimeTag", "Day ${index + 1} (${date}): Sehri: ${fastingItem.sehriTime}, Iftar: ${fastingItem.iftaarTime}")
}
}.onFailure { exception ->
Log.e("FastingTimeTag", "Error fetching monthly fasting times", exception)
Expand All @@ -205,9 +205,10 @@ prayerTimeManager.fetchCurrentYearFastingTimes(
) { result ->
result.onSuccess { fastingTimes ->
fastingTimes.forEachIndexed { monthIndex, monthlyFastingList ->
Log.d("FastingTimeTag", "--------Month ${monthIndex + 1}--------")
Log.d("FastingTimeTag", "Month ${monthIndex + 1}:")
monthlyFastingList.forEachIndexed { dayIndex, fastingItem ->
Log.d("FastingTimeTag", "Day ${dayIndex + 1} -> Sehri: ${fastingItem.sehriTime}, Iftar: ${fastingItem.iftaarTime}")
val date = Date(fastingItem.date)
Log.d("FastingTimeTag", "Day ${dayIndex + 1} (${date}): Sehri: ${fastingItem.sehriTime}, Iftar: ${fastingItem.iftaarTime}")
}
}
}.onFailure { exception ->
Expand All @@ -218,9 +219,54 @@ prayerTimeManager.fetchCurrentYearFastingTimes(

---

## Configuration Options
### Models

Below is a categorized list of configuration options, their parent enums, and descriptions:
#### PrayerItem
```kotlin
/**
* Represents the prayer times for a specific day.
*
* @property date Date of the prayer times in milliseconds.
* @property prayerList List of individual prayers and their times.
*/
data class PrayerItem(
var date: Long,
var prayerList: List<PrayerTimes>
)
```
#### PrayerTimes
```kotlin
/**
* Represents an individual prayer.
*
* @property prayerName Name of the prayer (e.g., Fajr, Dhuhr, etc.).
* @property prayerTime Formatted time of the prayer.
* @property isCurrentPrayer Indicates if this is the currently active prayer.
*/
data class PrayerTimes(
var prayerName: String,
var prayerTime: String,
var isCurrentPrayer: Boolean = false
)
```
#### FastingItem
```kotlin
/**
* Represents fasting times for a specific day.
*
* @property date Date of the fasting times in milliseconds.
* @property sehriTime Time for Sehri (pre-dawn meal).
* @property iftaarTime Time for Iftar (breaking the fast).
*/
data class FastingItem(
var date: Long,
val sehriTime: String,
val iftaarTime: String
)
```
---

## Configuration Options

### High Latitude Adjustment (`HighLatitudeAdjustment`)

Expand Down Expand Up @@ -283,4 +329,3 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import com.orbitalsonic.opt.enums.JuristicMethod
import com.orbitalsonic.opt.enums.OrganizationStandard
import com.orbitalsonic.opt.enums.TimeFormat
import com.orbitalsonic.opt.manager.PrayerTimeManager
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

class DailyFastingTimeFragment : Fragment() {

Expand All @@ -26,6 +29,9 @@ class DailyFastingTimeFragment : Fragment() {

private val logBuilder = StringBuilder()

// Initialize SimpleDateFormat globally to save memory
private val dateFormatter = SimpleDateFormat("dd MMM, yyyy", Locale.getDefault())

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -49,8 +55,9 @@ class DailyFastingTimeFragment : Fragment() {
timeFormat = TimeFormat.HOUR_12
) { result ->
result.onSuccess { fastingItem ->
val formattedDate = dateFormatter.format(Date(fastingItem.date))
logBuilder.appendLine("----Daily Fasting Times----")
logBuilder.appendLine("")
logBuilder.appendLine("Date: $formattedDate")
logBuilder.appendLine("")
logBuilder.appendLine("Sehri: ${fastingItem.sehriTime}, Iftar: ${fastingItem.iftaarTime}")
updateTextView()
Expand All @@ -70,4 +77,4 @@ class DailyFastingTimeFragment : Fragment() {
super.onDestroyView()
_binding = null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import com.orbitalsonic.opt.enums.JuristicMethod
import com.orbitalsonic.opt.enums.OrganizationStandard
import com.orbitalsonic.opt.enums.TimeFormat
import com.orbitalsonic.opt.manager.PrayerTimeManager
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

class MonthlyFastingTimeFragment : Fragment() {

Expand All @@ -26,6 +29,9 @@ class MonthlyFastingTimeFragment : Fragment() {

private val logBuilder = StringBuilder()

// Initialize SimpleDateFormat globally to save memory
private val dateFormatter = SimpleDateFormat("dd MMM, yyyy", Locale.getDefault())

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -51,10 +57,14 @@ class MonthlyFastingTimeFragment : Fragment() {
result.onSuccess { fastingTimes ->
logBuilder.appendLine("----Monthly Fasting Times----")
logBuilder.appendLine("")
logBuilder.appendLine("")

fastingTimes.forEachIndexed { index, fastingItem ->
logBuilder.appendLine("Day ${index + 1} -> Sehri: ${fastingItem.sehriTime}, Iftar: ${fastingItem.iftaarTime}")
val formattedDate = dateFormatter.format(Date(fastingItem.date))
logBuilder.appendLine("Day ${index + 1} - Date: $formattedDate")
logBuilder.appendLine("Sehri: ${fastingItem.sehriTime}, Iftar: ${fastingItem.iftaarTime}")
logBuilder.appendLine("")
}

updateTextView()
}.onFailure { exception ->
logBuilder.appendLine("Error fetching monthly fasting times: ${exception.message}")
Expand All @@ -72,4 +82,4 @@ class MonthlyFastingTimeFragment : Fragment() {
super.onDestroyView()
_binding = null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import com.orbitalsonic.opt.enums.JuristicMethod
import com.orbitalsonic.opt.enums.OrganizationStandard
import com.orbitalsonic.opt.enums.TimeFormat
import com.orbitalsonic.opt.manager.PrayerTimeManager
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

class YearlyFastingTimeFragment : Fragment() {

Expand All @@ -26,6 +29,9 @@ class YearlyFastingTimeFragment : Fragment() {

private val logBuilder = StringBuilder()

// Initialize SimpleDateFormat globally to save memory
private val dateFormatter = SimpleDateFormat("dd MMM, yyyy", Locale.getDefault())

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -51,18 +57,23 @@ class YearlyFastingTimeFragment : Fragment() {
result.onSuccess { fastingTimes ->
logBuilder.appendLine("----Yearly Fasting Times----")
logBuilder.appendLine("")
logBuilder.appendLine("")

fastingTimes.forEachIndexed { monthIndex, monthlyFastingList ->
logBuilder.appendLine("Month ${monthIndex + 1}")
logBuilder.appendLine("")
logBuilder.appendLine("")

monthlyFastingList.forEachIndexed { dayIndex, fastingItem ->
logBuilder.appendLine("Day ${dayIndex + 1} -> Sehri: ${fastingItem.sehriTime}, Iftar: ${fastingItem.iftaarTime}")
val formattedDate = dateFormatter.format(Date(fastingItem.date))

logBuilder.appendLine("Day ${dayIndex + 1} - Date: $formattedDate")
logBuilder.appendLine("Sehri: ${fastingItem.sehriTime}, Iftar: ${fastingItem.iftaarTime}")
logBuilder.appendLine("")

}

logBuilder.appendLine("")
logBuilder.appendLine("")
}

updateTextView()
}.onFailure { exception ->
logBuilder.appendLine("Error fetching yearly fasting times: ${exception.message}")
Expand All @@ -80,4 +91,4 @@ class YearlyFastingTimeFragment : Fragment() {
super.onDestroyView()
_binding = null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import com.orbitalsonic.opt.enums.JuristicMethod
import com.orbitalsonic.opt.enums.OrganizationStandard
import com.orbitalsonic.opt.enums.TimeFormat
import com.orbitalsonic.opt.manager.PrayerTimeManager
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

class DailyPrayerTimeFragment : Fragment() {

Expand All @@ -26,6 +29,9 @@ class DailyPrayerTimeFragment : Fragment() {

private val logBuilder = StringBuilder()

// Initialize SimpleDateFormat globally to save memory
private val dateFormatter = SimpleDateFormat("dd MMM, yyyy", Locale.getDefault())

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -48,13 +54,16 @@ class DailyPrayerTimeFragment : Fragment() {
organizationStandard = OrganizationStandard.KARACHI,
timeFormat = TimeFormat.HOUR_12
) { result ->
result.onSuccess { prayerTimes ->
result.onSuccess { prayerItem ->
val formattedDate = dateFormatter.format(Date(prayerItem.date))
logBuilder.appendLine("----Daily Prayer Times----")
logBuilder.appendLine("Date: $formattedDate")
logBuilder.appendLine("")
logBuilder.appendLine("")
prayerTimes.forEach {

prayerItem.prayerList.forEach {
logBuilder.appendLine("${it.prayerName}: ${it.prayerTime}")
}

updateTextView()
}.onFailure { exception ->
logBuilder.appendLine("Error fetching daily prayer times: ${exception.message}")
Expand All @@ -72,4 +81,5 @@ class DailyPrayerTimeFragment : Fragment() {
super.onDestroyView()
_binding = null
}
}
}

Loading

0 comments on commit d14d60c

Please sign in to comment.