Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjoongcho committed Oct 2, 2023
1 parent 50ce23d commit f72f9b1
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.blog.korn123.easydiary.fragments

import android.app.DatePickerDialog
import android.content.Context
import android.content.Intent
import android.graphics.Color
Expand Down Expand Up @@ -40,6 +41,21 @@ class StockLineChartFragment : androidx.fragment.app.Fragment() {
* global properties
*
***************************************************************************************************/
private lateinit var mSDatePickerDialog: DatePickerDialog
private lateinit var mEDatePickerDialog: DatePickerDialog
private val mStartCalendar = Calendar.getInstance(Locale.getDefault()).apply { add(Calendar.YEAR, -1) }
private val mEndCalendar = Calendar.getInstance(Locale.getDefault())
private var mStartMillis = mStartCalendar.timeInMillis
private var mEndMillis = 0L
private var mStartDateListener: DatePickerDialog.OnDateSetListener = DatePickerDialog.OnDateSetListener { _, year, month, dayOfMonth ->
mStartMillis = EasyDiaryUtils.datePickerToTimeMillis(dayOfMonth, month, year)
drawChart()
}

private var mEndDateListener: DatePickerDialog.OnDateSetListener = DatePickerDialog.OnDateSetListener { _, year, month, dayOfMonth ->
mEndMillis = EasyDiaryUtils.datePickerToTimeMillis(dayOfMonth, month, year)
drawChart()
}
private lateinit var mBinding: FragmentStockLineChartBinding
private lateinit var mCombineChart: CombinedChart
private lateinit var mKospiChart: LineChart
Expand Down Expand Up @@ -161,6 +177,13 @@ class StockLineChartFragment : androidx.fragment.app.Fragment() {
setupTitle() // determine title parameter
setupChartOptions()
drawChart()

mSDatePickerDialog = DatePickerDialog(requireContext(), mStartDateListener, mStartCalendar.get(Calendar.YEAR), mStartCalendar.get(Calendar.MONTH), mStartCalendar.get(Calendar.DAY_OF_MONTH))
mEDatePickerDialog = DatePickerDialog(requireContext(), mEndDateListener, mEndCalendar.get(Calendar.YEAR), mEndCalendar.get(Calendar.MONTH), mEndCalendar.get(Calendar.DAY_OF_MONTH))
mBinding.run {
cardFromDate.setOnClickListener { mSDatePickerDialog.show() }
cardToDate.setOnClickListener { mSDatePickerDialog.show() }
}
}

override fun onDestroy() {
Expand Down Expand Up @@ -482,7 +505,7 @@ class StockLineChartFragment : androidx.fragment.app.Fragment() {

EasyDiaryDbHelper.getTemporaryInstance().let { realmInstance ->
val listDiary = EasyDiaryDbHelper.findDiary(
null, false, 0, 0, DAILY_STOCK, realmInstance = realmInstance
null, false, mStartMillis, mEndMillis, DAILY_STOCK, realmInstance = realmInstance
)
var index = 0
var totalSum = 0F
Expand Down
24 changes: 23 additions & 1 deletion app/src/main/res/layout-land/fragment_stock_line_chart.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,34 @@
app:contentPaddingBottom="5dp"
app:contentPadding="@dimen/dashboard_card_padding">
<com.simplemobiletools.commons.views.MyTextView
android:text="Chart Options"
android:text="Options"
android:ellipsize="end"
android:singleLine="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</me.blog.korn123.easydiary.views.FixedCardView>
<me.blog.korn123.easydiary.views.FixedCardView
android:id="@+id/card_from_date"
style="@style/card_dashboard_inner"
app:contentPaddingTop="5dp"
app:contentPaddingBottom="5dp"
app:contentPadding="@dimen/dashboard_card_padding">
<com.simplemobiletools.commons.views.MyTextView
android:text="From"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</me.blog.korn123.easydiary.views.FixedCardView>
<me.blog.korn123.easydiary.views.FixedCardView
android:id="@+id/card_to_date"
style="@style/card_dashboard_inner"
app:contentPaddingTop="5dp"
app:contentPaddingBottom="5dp"
app:contentPadding="@dimen/dashboard_card_padding">
<com.simplemobiletools.commons.views.MyTextView
android:text="To"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</me.blog.korn123.easydiary.views.FixedCardView>
</com.google.android.flexbox.FlexboxLayout>

<androidx.appcompat.widget.LinearLayoutCompat
Expand Down
24 changes: 23 additions & 1 deletion app/src/main/res/layout/fragment_stock_line_chart.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,29 @@
app:contentPaddingBottom="5dp"
app:contentPadding="@dimen/dashboard_card_padding">
<com.simplemobiletools.commons.views.MyTextView
android:text="Chart Options"
android:text="Options"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</me.blog.korn123.easydiary.views.FixedCardView>
<me.blog.korn123.easydiary.views.FixedCardView
android:id="@+id/card_from_date"
style="@style/card_dashboard_inner"
app:contentPaddingTop="5dp"
app:contentPaddingBottom="5dp"
app:contentPadding="@dimen/dashboard_card_padding">
<com.simplemobiletools.commons.views.MyTextView
android:text="From"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</me.blog.korn123.easydiary.views.FixedCardView>
<me.blog.korn123.easydiary.views.FixedCardView
android:id="@+id/card_to_date"
style="@style/card_dashboard_inner"
app:contentPaddingTop="5dp"
app:contentPaddingBottom="5dp"
app:contentPadding="@dimen/dashboard_card_padding">
<com.simplemobiletools.commons.views.MyTextView
android:text="To"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</me.blog.korn123.easydiary.views.FixedCardView>
Expand Down

0 comments on commit f72f9b1

Please sign in to comment.