Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/compiler.xml

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

2 changes: 1 addition & 1 deletion .idea/misc.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/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ apply plugin: 'realm-android'

android {
compileSdkVersion 30
buildFeatures {
viewBinding true
}
defaultConfig {
applicationId "com.log28"
minSdkVersion 19
Expand Down
29 changes: 16 additions & 13 deletions app/src/main/java/com/log28/CalendarView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import devs.mulham.horizontalcalendar.utils.Utils
import com.log28.databinding.FragmentCalendarViewBinding
import io.realm.Realm
import kotlinx.android.synthetic.main.fragment_calendar_view.*
import pl.rafman.scrollcalendar.contract.MonthScrollListener
import pl.rafman.scrollcalendar.data.CalendarDay
import java.util.*
Expand All @@ -24,14 +23,18 @@ class CalendarView : Fragment() {
//TODO use a tree for better calendar performance?
private var periodDates = mutableListOf<Long>()
private val cycleInfo = realm.getCycleInfo()
private var _binding: FragmentCalendarViewBinding? = null
private val binding get() = _binding!!

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_calendar_view, container, false)
_binding = FragmentCalendarViewBinding.inflate(inflater, container, false)
return binding.root
}

override fun onDestroy() {
super.onDestroy()
_binding = null
realm.close()
}

Expand All @@ -44,15 +47,15 @@ class CalendarView : Fragment() {
results, changeSet ->
if (changeSet != null) {
periodDates = predictFuturePeriods(periodDateObjects.map { d -> d.date }.toMutableList())
scrollCalendar.adapter.notifyDataSetChanged()
binding.scrollCalendar.adapter.notifyDataSetChanged()
}
}

cycleInfo.addChangeListener<CycleInfo> {
_, changeSet ->
if (changeSet != null) {
periodDates = predictFuturePeriods(periodDateObjects.map { d -> d.date }.toMutableList())
scrollCalendar.adapter.notifyDataSetChanged()
binding.scrollCalendar.adapter.notifyDataSetChanged()
}
}
setupScrollCalendar()
Expand All @@ -62,19 +65,19 @@ class CalendarView : Fragment() {
private fun setupScrollCalendar() {
// show periods on the calendar as it renders
val today = Calendar.getInstance()
scrollCalendar.setDateWatcher({
year, month, day ->
binding.scrollCalendar.setDateWatcher { year, month, day ->
if ((year.toLong() * 10000) + (month.toLong() * 100) + day.toLong() in periodDates) {
CalendarDay.SELECTED
} else if (year == today.get(Calendar.YEAR) &&
month == today.get(Calendar.MONTH) && day == today.get(Calendar.DAY_OF_MONTH)) {
month == today.get(Calendar.MONTH) && day == today.get(Calendar.DAY_OF_MONTH)
) {
CalendarDay.TODAY
} else CalendarDay.DEFAULT
})
}

// we call the underlying activity and tell it to navigate to the day view and set the day
scrollCalendar.setOnDateClickListener({
year, month, day -> val cal = Calendar.getInstance()
binding.scrollCalendar.setOnDateClickListener { year, month, day ->
val cal = Calendar.getInstance()
cal.set(Calendar.YEAR, year)
cal.set(Calendar.MONTH, month)
cal.set(Calendar.DAY_OF_MONTH, day)
Expand All @@ -83,9 +86,9 @@ class CalendarView : Fragment() {
//TODO redo this tangled mess with some RX code calendar tap -> event -> dayview updates
if (cal.before(Calendar.getInstance()) || cal.isToday())
(this.activity as? MainActivity)?.navToDayView(cal)
})
}

scrollCalendar.setMonthScrollListener(object : MonthScrollListener {
binding.scrollCalendar.setMonthScrollListener(object : MonthScrollListener {
override fun shouldAddNextMonth(lastDisplayedYear: Int, lastDisplayedMonth: Int): Boolean {
// don't let the user scroll more than 4 months into the future
val fourMonths = Calendar.getInstance()
Expand Down
19 changes: 11 additions & 8 deletions app/src/main/java/com/log28/CycleHistory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.log28.databinding.FragmentCycleHistoryBinding
import com.log28.groupie.HistoryItem
import com.xwray.groupie.GroupAdapter
import com.xwray.groupie.GroupieViewHolder
import devs.mulham.horizontalcalendar.utils.Utils
import io.realm.Realm
import io.realm.RealmResults
import kotlinx.android.synthetic.main.fragment_cycle_history.*
import java.util.*
import kotlin.math.roundToInt

Expand All @@ -30,6 +29,8 @@ class CycleHistory : Fragment() {
data class CycleData(val cycleStarts: List<Calendar>, val periodEnds: List<Calendar>)
private val realm = Realm.getDefaultInstance()
private val periodDates = realm.getPeriodDaysDecending()
private var _binding: FragmentCycleHistoryBinding? = null
private val binding get() = _binding!!

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Expand All @@ -41,27 +42,29 @@ class CycleHistory : Fragment() {
Log.d(TAG, "cycleLengths: $cycleLengths, periodLengths: $periodLengths")

if (cycleLengths.isNotEmpty())
avg_cycle_length.text = cycleLengths.average().roundToInt().toString()
binding.avgCycleLength.text = cycleLengths.average().roundToInt().toString()
else // if we don't have any data yet, just show what's been entered
avg_cycle_length.text = realm.getCycleInfo().cycleLength.toString()
binding.avgCycleLength.text = realm.getCycleInfo().cycleLength.toString()

if (periodLengths.isNotEmpty())
avg_period_length.text = periodLengths.average().roundToInt().toString()
binding.avgPeriodLength.text = periodLengths.average().roundToInt().toString()
else
avg_period_length.text = realm.getCycleInfo().periodLength.toString()
binding.avgPeriodLength.text = realm.getCycleInfo().periodLength.toString()

setupPreviousCycles(cycleData.cycleStarts, periodLengths, cycleLengths)
}

override fun onDestroy() {
super.onDestroy()
realm.close()
_binding = null
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_cycle_history, container, false)
_binding = FragmentCycleHistoryBinding.inflate(inflater, container, false)
return binding.root
}

private fun setupPreviousCycles(cycleStarts: List<Calendar>, periodLengths: List<Int>,
Expand All @@ -70,7 +73,7 @@ class CycleHistory : Fragment() {
val dividerItem = DividerItemDecoration(context, layout.orientation)
val groupAdapter = GroupAdapter<GroupieViewHolder>()

previous_cycles.apply {
binding.previousCycles.apply {
layoutManager = layout
adapter = groupAdapter
this.addItemDecoration(dividerItem)
Expand Down
16 changes: 10 additions & 6 deletions app/src/main/java/com/log28/DayView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.log28.databinding.FragmentDayViewBinding
import com.xwray.groupie.ExpandableGroup
import devs.mulham.horizontalcalendar.HorizontalCalendar
import java.util.*
import devs.mulham.horizontalcalendar.utils.HorizontalCalendarListener
import kotlinx.android.synthetic.main.fragment_day_view.*
import com.xwray.groupie.GroupAdapter
import com.xwray.groupie.Section
import com.xwray.groupie.kotlinandroidextensions.*
Expand Down Expand Up @@ -48,11 +48,14 @@ class DayView : Fragment() {
// reference to the notes and sleep amount
private var notesAndSleep = Section()
private lateinit var notesItem: NotesItem
private var _binding: FragmentDayViewBinding? = null
private val binding get() = _binding!!

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
val rootView = inflater.inflate(R.layout.fragment_day_view, container, false)
_binding = FragmentDayViewBinding.inflate(inflater, container, false)
val rootView = binding.root
setupHorizontalCalendar(rootView)
return rootView
}
Expand All @@ -79,6 +82,7 @@ class DayView : Fragment() {
categories.removeAllChangeListeners()
symptoms.removeAllChangeListeners()
realm.close()
_binding = null
}

// if the day has changed
Expand All @@ -94,7 +98,7 @@ class DayView : Fragment() {
super.onViewCreated(view, savedInstanceState)
setDayText(currentDay)

day_view_recycler.apply {
binding.dayViewRecycler.apply {
layoutManager = LinearLayoutManager(context)
adapter = groupAdapter
}
Expand Down Expand Up @@ -226,11 +230,11 @@ class DayView : Fragment() {
yesterday.add(Calendar.DAY_OF_MONTH, -1)

if (Utils.isSameDate(day, now))
day_text.text = context!!.getString(R.string.today)
binding.dayText.text = context!!.getString(R.string.today)
else if (Utils.isSameDate(day, yesterday))
day_text.text = context!!.getString(R.string.yesterday)
binding.dayText.text = context!!.getString(R.string.yesterday)
else
day_text.text = context!!.getString(R.string.days_ago, Utils.daysBetween(day, now))
binding.dayText.text = context!!.getString(R.string.days_ago, Utils.daysBetween(day, now))
}

companion object {
Expand Down
19 changes: 11 additions & 8 deletions app/src/main/java/com/log28/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import android.preference.PreferenceManager
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import kotlinx.android.synthetic.main.activity_main.*
import com.log28.databinding.ActivityMainBinding
import com.log28.intro.AppIntroActivity
import java.util.*

class MainActivity : AppCompatActivity() {
private val SETTINGS_CODE = 3392
private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
val view = binding.root

val preferences = PreferenceManager.getDefaultSharedPreferences(this)
val firstStart = preferences.getBoolean("first_start", true)
Expand All @@ -36,19 +39,19 @@ class MainActivity : AppCompatActivity() {
preferences.edit().putBoolean("appetite_present", true).apply()
}

setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
setContentView(view)
setSupportActionBar(binding.toolbar)

// Get the ViewPager and set it's PagerAdapter so that it can display items
val pagerAdapter = TabPagerAdapter(supportFragmentManager,
this@MainActivity)
viewPager.adapter = pagerAdapter
binding.viewPager.adapter = pagerAdapter

// Give the TabLayout the ViewPager
sliding_tabs.setupWithViewPager(viewPager)
binding.slidingTabs.setupWithViewPager(binding.viewPager)

for (i in pagerAdapter.tabText.indices) {
sliding_tabs.getTabAt(i)?.customView = pagerAdapter.getTabView(i)
binding.slidingTabs.getTabAt(i)?.customView = pagerAdapter.getTabView(i)
}
}

Expand Down Expand Up @@ -85,8 +88,8 @@ class MainActivity : AppCompatActivity() {
*/
fun navToDayView(day: Calendar) {
// go to the index of the day view
viewPager.currentItem = 1
(viewPager.adapter as? TabPagerAdapter)?.setDayViewDay(day)
binding.viewPager.currentItem = 1
(binding.viewPager.adapter as? TabPagerAdapter)?.setDayViewDay(day)
}

companion object {
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/log28/SettingsView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import android.util.SparseArray
import android.view.MenuItem
import android.widget.Toast
import io.realm.Realm
import kotlinx.android.synthetic.main.activity_settings.*
import android.app.AlarmManager
import android.app.PendingIntent
import androidx.preference.Preference
import androidx.preference.PreferenceDataStore
import com.log28.databinding.ActivitySettingsBinding
import com.takisoft.preferencex.PreferenceFragmentCompat
import java.util.*

Expand Down Expand Up @@ -104,10 +104,12 @@ class SettingsView : PreferenceFragmentCompat() {
}

class SettingsActivity : AppCompatActivity() {
private lateinit var binding: ActivitySettingsBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
setSupportActionBar(toolbar)
binding = ActivitySettingsBinding.inflate(layoutInflater)
setContentView(binding.root)
setSupportActionBar(binding.toolbar)
// draw the back button
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/log28/TabPagerAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import android.view.LayoutInflater
import android.view.View
import kotlinx.android.synthetic.main.custom_tab.view.*
import com.log28.databinding.CustomTabBinding
import java.util.*

class TabPagerAdapter(fm: FragmentManager, private val context: Context) : FragmentPagerAdapter(fm) {
Expand Down Expand Up @@ -47,11 +47,11 @@ class TabPagerAdapter(fm: FragmentManager, private val context: Context) : Fragm
}

fun getTabView(position: Int): View {
val view = LayoutInflater.from(context).inflate(R.layout.custom_tab, null)
view.tab_text.text = tabText[position]
view.tab_icon.setImageResource(tabIcons[position])
val binding = CustomTabBinding.inflate(LayoutInflater.from(context))
binding.tabText.text = tabText[position]
binding.tabIcon.setImageResource(tabIcons[position])

return view
return binding.root
}

}
Loading