Skip to content

Commit

Permalink
Added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
HeyPouya committed Feb 27, 2021
1 parent 5eb8980 commit 431dfb1
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .idea/dictionaries/pouyaheydari.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app/src/main/java/ir/apptune/calendar/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import dagger.hilt.android.AndroidEntryPoint

/**
* The single activity of the application
*/
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/ir/apptune/calendar/ResourceUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ private const val VACATION = "IsVacation"
private const val X_CALENDAR = "XCalendar"
private const val IS_VACATION = "1"

/**
* This class reads xml files that contain holidays dates
*/
class ResourceUtils(c: Context) {

private fun getHashMapResource(c: Context, hashMapResId: Int) {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/ir/apptune/calendar/base/BaseApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ package ir.apptune.calendar.base
import android.app.Application
import dagger.hilt.android.HiltAndroidApp

/**
* Application class
*/
@HiltAndroidApp
class BaseApplication : Application()
15 changes: 15 additions & 0 deletions app/src/main/java/ir/apptune/calendar/di/HiltModules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ import ir.apptune.calendar.utils.CalendarTool
import java.util.*
import javax.inject.Singleton

/**
* This object contains hilt modules needed for injection
*/
@Module
@InstallIn(SingletonComponent::class)
object DateModule {

/**
* Provides current date details
*/
@Provides
@Singleton
fun todayProvider(calendar: GregorianCalendar): CalendarModel {
Expand All @@ -25,14 +31,23 @@ object DateModule {
}
}

/**
* Provides Gregorian calendar instance
*/
@Provides
@Singleton
fun gregorianCalendarProvider() = GregorianCalendar()

/**
* Provides CalendarTool instance to convert dates from Gregorian to Shamsi
*/
@Provides
@Singleton
fun calendarToolProvider(calendar: GregorianCalendar) = CalendarTool(calendar)

/**
* Provides local repository
*/
@Provides
@Singleton
fun monthGeneratorProvider(app: Application, calendarModel: CalendarModel, calendarTool: CalendarTool): MonthGeneratorClass {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import ir.apptune.calendar.utils.extensions.toPersianWeekDay
import java.util.*

/**
* The activity that Pops-Up when user clicks on days, in MainPage calendar.
* Show details about the selected date in a popup form
*/
@AndroidEntryPoint
class DateDetailsDialogFragment : DialogFragment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ import ir.apptune.calendar.ResourceUtils
import ir.apptune.calendar.pojo.CalendarModel
import javax.inject.Inject

/**
* ViewModel Of DateDetailsDialogFragment
*/
@HiltViewModel
class DateDetailsViewModel @Inject constructor() : ViewModel() {

private val eventsLiveData = MutableLiveData<String>()

/**
* Checks if there are any events on the selected date
* @param date the selected date
*/
fun getEvents(date: CalendarModel) {
val persianTemp = date.iranianMonth * 100 + date.iranianDay
val gregorianTemp = date.gMonth * 100 + date.gDay
Expand All @@ -24,5 +31,8 @@ class DateDetailsViewModel @Inject constructor() : ViewModel() {
}
}

/**
* Returns live data of [eventsLiveData]
*/
fun getEventsLiveData(): LiveData<String> = eventsLiveData
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import ir.apptune.calendar.pojo.CalendarModel
import ir.apptune.calendar.utils.EMPTY_DATE
import ir.apptune.calendar.utils.extensions.toPersianNumber

/**
* Adapter to show the calendar days
*/
class CalendarAdapter(val clickListener: (CalendarModel) -> Unit) : ListAdapter<CalendarModel, CalendarViewHolder>(CalendarDiffUtils()) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CalendarViewHolder {
Expand All @@ -28,6 +31,9 @@ class CalendarAdapter(val clickListener: (CalendarModel) -> Unit) : ListAdapter<
inner class CalendarViewHolder(private val binding: CalendarItemBinding, containerView: View) :
RecyclerView.ViewHolder(containerView) {

/**
* Binds views via ViewBinding
*/
fun onBind(dateModel: CalendarModel) {
with(dateModel) {
with(binding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import ir.apptune.calendar.utils.extensions.toPersianNumber
import ir.apptune.calendar.utils.extensions.toPersianWeekDay
import javax.inject.Inject

/**
* Main view of the application that contains the calendar
*/
@AndroidEntryPoint
class CalendarFragment : Fragment() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import ir.apptune.calendar.pojo.MonthType.PREVIOUS_MONTH
import ir.apptune.calendar.repository.local.MonthGeneratorClass
import javax.inject.Inject

/**
* ViewModel of CalendarFragment
*/
@HiltViewModel
class CalendarViewModel @Inject constructor(private val monthGenerator: MonthGeneratorClass) : ViewModel() {

Expand All @@ -20,13 +23,22 @@ class CalendarViewModel @Inject constructor(private val monthGenerator: MonthGen
monthLiveData.value = monthGenerator.getMonthList(NEXT_MONTH)
}

/**
* Fetches and publishes the next month (from the month that currently user is watching) as a list of days
*/
fun getNextMonth() {
monthLiveData.value = monthGenerator.getMonthList(NEXT_MONTH)
}

/**
* Fetches and publishes the previous month (from the month that currently user is watching) as a list of days
*/
fun getPreviousMonth() {
monthLiveData.value = monthGenerator.getMonthList(PREVIOUS_MONTH)
}

/**
* Returns live data of [monthLiveData]
*/
fun getMonthLiveData(): LiveData<List<CalendarModel>> = monthLiveData
}
3 changes: 3 additions & 0 deletions app/src/main/java/ir/apptune/calendar/pojo/DateModel.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package ir.apptune.calendar.pojo

/**
* Contains details of a day
*/
data class DateModel(val year: Int, val month: Int, val dayNumber: Int)
3 changes: 3 additions & 0 deletions app/src/main/java/ir/apptune/calendar/pojo/MonthType.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package ir.apptune.calendar.pojo

/**
* An Enum to request next or previous month
*/
enum class MonthType { NEXT_MONTH, PREVIOUS_MONTH }
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,4 @@ class CalendarTool {
= 0
private var march // The march day of Farvardin the first (First day of jaYear)
= 0
} // End of Class 'JavaSource_Calendar
}

0 comments on commit 431dfb1

Please sign in to comment.