Skip to content

Commit d7b9309

Browse files
bug fixed.
1 parent 7400979 commit d7b9309

File tree

4 files changed

+25
-82
lines changed

4 files changed

+25
-82
lines changed

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JCalendar/src/main/java/com/javadsh98/jcalendar/JCalendarAdapter.kt

Lines changed: 8 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ class JCalendarAdapter(
129129
backgroundRes: Drawable
130130
) = with(itemView) {
131131

132-
Log.i(TAG, "onBind: triggered")
133132

134133
daysOfMonth = textView_days_of_month_selected
135134
daysOfWeek = textView_day_of_week_selected
@@ -238,92 +237,22 @@ class JCalendarAdapter(
238237
backgroundRes: Drawable
239238
) = with(itemView) {
240239

241-
daysOfMonth = textView_days_of_month_normal
242-
daysOfWeek = textView_day_of_week_normal
243-
model = jModel
244-
245-
textView_days_of_month_normal.text = jModel.dayOfMonth.toString()
246240
textView_day_of_week_normal.text = jModel.dayOfWeek
241+
textView_days_of_month_normal.text = jModel.dayOfMonth.toString()
247242

248-
textView_days_of_month_normal.setTextColor(
249-
ContextCompat.getColor(
250-
context,
251-
dayOfMonthTextColor
252-
)
253-
)
254-
textView_day_of_week_normal.setTextColor(
255-
ContextCompat.getColor(
256-
context,
257-
nameOfWeekTextColor
258-
)
259-
)
243+
textView_day_of_week_normal.setTextColor(ContextCompat.getColor(context, nameOfWeekTextColor))
244+
textView_days_of_month_normal.setTextColor(ContextCompat.getColor(context, dayOfMonthTextColor))
260245
background = backgroundRes
261246

262-
var holder = this@NormalViewHolder
263247
setOnClickListener {
264-
//when user double tap on item
265-
if (jModel !== selected) {
266-
jModel.selected = true
267-
selected.selected = false
268-
selected = jModel
269-
270-
//send model into callback
271-
onJItemClickListener.invoke(jModel)
272248

273-
//set ui of selecting item
274-
textView_days_of_month_normal.setTextColor(
275-
androidx.core.content.ContextCompat.getColor(
276-
context,
277-
dayOfMonthTextColorSelected
278-
)
279-
)
280-
textView_day_of_week_normal.setTextColor(
281-
androidx.core.content.ContextCompat.getColor(
282-
context,
283-
nameOfWeekTextColorSelected
284-
)
285-
)
286-
background = backgroundResSelected
249+
jModel.selected = true
250+
selected.selected = false
251+
selected = jModel
287252

288-
//set ui of previous selected item
289-
if (selectedViewHolder is NormalViewHolder) {
290-
with(selectedViewHolder.itemView) {
291-
292-
textView_days_of_month_normal.setTextColor(
293-
ContextCompat.getColor(
294-
context,
295-
dayOfMonthTextColorNormal
296-
)
297-
)
298-
textView_day_of_week_normal.setTextColor(
299-
ContextCompat.getColor(
300-
context,
301-
nameOfWeekTextColorNormal
302-
)
303-
)
304-
background = backgroundResNormal
305-
}
306-
} else if (selectedViewHolder is SelectedViewHolder) {
307-
with(selectedViewHolder.itemView) {
253+
onJItemClickListener.invoke(selected)
254+
notifyDataSetChanged()
308255

309-
textView_days_of_month_selected.setTextColor(
310-
ContextCompat.getColor(
311-
context,
312-
dayOfMonthTextColorNormal
313-
)
314-
)
315-
textView_day_of_week_selected.setTextColor(
316-
ContextCompat.getColor(
317-
context,
318-
nameOfWeekTextColorNormal
319-
)
320-
)
321-
background = backgroundResNormal
322-
}
323-
}
324-
selectedViewHolder = holder
325-
notifyDataSetChanged()
326-
}
327256
}
328257

329258

JCalendar/src/main/java/com/javadsh98/jcalendar/JCalendarView.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.javadsh98.jcalendar
33
import android.content.Context
44
import android.graphics.drawable.Drawable
55
import android.util.AttributeSet
6+
import android.util.Log
67
import android.widget.TextView
78
import androidx.constraintlayout.widget.ConstraintLayout
89
import androidx.core.content.ContextCompat
@@ -91,12 +92,15 @@ class JCalendarView :ConstraintLayout {
9192

9293
nameOfMonth.text = model.monthName
9394

95+
val gregorian = model.intoGregorian()
96+
val jalali = model.intoJalali()
97+
9498
jalaliListener?.let {
95-
it.onJalali(model.intoJalali())
99+
it.onJalali(jalali)
96100
}
97101

98102
gregorianListener?.let {
99-
it.onGregorian(model.intoGregorian())
103+
it.onGregorian(gregorian)
100104
}
101105

102106
}

app/src/main/java/com/javadsh98/jcalendarexample/MainActivity.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package com.javadsh98.jcalendarexample
22

3+
import android.nfc.Tag
34
import androidx.appcompat.app.AppCompatActivity
45
import android.os.Bundle
6+
import android.util.Log
57
import androidx.core.content.res.ResourcesCompat
68
import com.javadsh98.jcalendar.JGregorianListener
79
import com.javadsh98.jcalendar.JJalaliListener
810
import kotlinx.android.synthetic.main.activity_main.*
9-
1011
class MainActivity : AppCompatActivity() {
12+
13+
val Tag = "my date"
14+
1115
override fun onCreate(savedInstanceState: Bundle?) {
1216
super.onCreate(savedInstanceState)
1317
setContentView(R.layout.activity_main)

0 commit comments

Comments
 (0)