-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A lot of changes: Kotlin, time/date formatting fixes, demo activity for whole view snapping... #97
base: develop
Are you sure you want to change the base?
Conversation
-added ability to scroll whole view (entire week, for example) like a ViewPager. -made default first day of week to be the one of the calendar.
…es some delicate work. -fixed some time/date formatting related issues: alamkanak#497 alamkanak#495 (but not fixed RTL alignment issue) -created a new activity to demonstrate the paging of entire view (example: week by week snapping), based on this pull request: Quivr#88
I did not try your code actually. But there is some changes to do in the Kotlin code. I will try to test it this afternoon. I probably forgot to notify things in the code, so if someone has the courage to double check everything, that would be great. |
@SkyleKayma I've now tested this fork: About Kotlin, I think it can be shortened a lot, but as the code became more complex, and because I've done it multiple times already with the other forks (tried various ones till I got here), I decided to do less this time. |
Can you explain to me what is the issue in 3days view with the changes you had with this PR ? You are on the real fork actually. It's the last one that is active. So if you need to do some changes with Kotlin code, it's clearly in this repo. |
@SkyleKayma My code doesn't have this issue. The 3-days view issue is of this repository that I've tested: About the fork, I've now worked on even more changes and fixes. One fix is of a bug I didn't even report yet, that the day-month formatting in the header doesn't consider the one of the device. In many countries, the day is before the month, so you should see something like "15/4" instead of "4/15" . I really hope I can fix the other issues too. |
@AndroidDeveloperLB First, thanks for your PR I think I would merge this PR if you added tests (which we still don't have 😞 ) so we can be more certain about it functioning correct. |
I'm probably stupid (or I missed something), but why want to fix a bug that you do not have in your code? :/ Btw, your code is working well. If you could do the little changes I said before, it could be awesome. (Or tell me if you are not agree with what I wrote) |
I don't want to fix a bug that I don't have in the code. I want to fix a bug that I do have in the code (and in the original code, before I even forked it). This bug is quite serious compared to the RTL and shortened text issues and easy to reproduce, so if you can fix it, please let me know. About my code working well, I did it in a delicate way, after having experienced with the same procedure on other forks here (we want all code of ours to be in Kotlin, so I wanted to do it here too).
|
@jhoobergs I never have time for unit tests (literally) . Not on my free time and not at the office. We are just too few developers who are in tight schedule. |
Quivr#98 -added a feature to put text next to the week days -added a feature to set only the week days to have a background, instead of week-days and all-day events. -replaced Java "List" class with "MutableList" instead of Kotlin "List", to avoid possible crashes at runtime (because Kotlin "List" cannot be modified and is more restricted). That being said, I think in most cases, it's ok to use Kotlin "List", because in many cases you don't really need to modify the lists. -some code cleaning and refactoring, including conversion of some fields to be Kotlin properties (setters and getters near the field itself)
OK here I've made a new commit with those changes. |
Where are the changes about what I have notified before ? (findViewById, apply, retrofit 2, 0f instead of 0.toFloat(), tools:replace instead of tools:ignore ...) |
@SkyleKayma I don't know what you are talking about. Please explain. |
replaced findViewById with synthetic ones of Kotlin.
@SkyleKayma But speaking of findViewById, I decided to replace them all :) |
sample/build.gradle
Outdated
@@ -22,6 +21,6 @@ android { | |||
dependencies { | |||
compile fileTree(dir: 'libs', include: ['*.jar']) | |||
compile project(':library') | |||
compile 'com.android.support:appcompat-v7:25.1.0' | |||
compile 'com.android.support:appcompat-v7:27.1.1' | |||
compile 'com.squareup.retrofit:retrofit:1.9.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls go with new version since everything has been updated, why not that?
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
And change all "compile" by "implementation".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Added.
The retrofit one is problematic. API has changed, and I don't want to see what should be changed just for this. Need to do other work... Will stay with 1.9.0 for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok ok ;D
} | ||
|
||
override fun onLoad(periodIndex: Int): List<WeekViewEvent>? { | ||
return onMonthChangeListener!!.onMonthChange(periodIndex / 12, periodIndex % 12 + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can you be sure that "onMonthChangeListener" will not be null here ?
I think that nullable "?" is better. It returns nullable List btw.
invalidate() | ||
} | ||
private var mTimeTextPaint: Paint? = null | ||
private var mTimeTextWidth: Float = 0.toFloat() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't use this :
0.toFloat()
Use this instead :
0f
If you can do the change everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. This was part of the auto-conversion. Fixed that too.
canvas.drawRect(start, startY, startPixel + mWidthPerDay, height.toFloat(), futurePaint!!) | ||
} | ||
} else { | ||
canvas.drawRect(start, mHeaderHeight + (mHeaderRowPadding * 2).toFloat() + mTimeTextHeight / 2 + mHeaderMarginBottom, startPixel + mWidthPerDay, height.to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to avoid usage of reserved words. If you could rename this by something like "value", it could be great.
constructor(id: String, name: String, startYear: Int, startMonth: Int, startDay: Int, startHour: Int, startMinute: Int, endYear: Int, endMonth: Int, endDay: Int, endHour: Int, endMinute: Int) { | ||
this.identifier = id | ||
|
||
this.startTime = Calendar.getInstance() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Kotlin you have the "apply" function that allow you a better way to do:
this.startTime = Calendar.getInstance().apply{ set(Calendar.YEAR, startYear) set(Calendar.MONTH, startMonth - 1) set(Calendar.DAY_OF_MONTH, startDay) set(Calendar.HOUR_OF_DAY, startHour) set(Calendar.MINUTE, startMinute) }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let a line jump between lines, can't do it on Github.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems ok. Done
startActivity(intent) | ||
} | ||
|
||
findViewById<View>(R.id.buttonAsynchronous).setOnClickListener { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, don't use findViewById
val intent = Intent(this@MainActivity, AsynchronousActivity::class.java) | ||
startActivity(intent) | ||
} | ||
findViewById<View>(R.id.buttonWholeViewSnap).setOnClickListener { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, don't use findViewById
weekView.setMaxTime(24) | ||
weekView.isScrollNumberOfVisibleDays = true | ||
setDayViewType(TYPE_WEEK_VIEW) | ||
val cal = Calendar.getInstance() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use "apply"
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
if (item.itemId == R.id.action_today) { | ||
val cal = Calendar.getInstance() | ||
cal.set(Calendar.DAY_OF_WEEK, cal.firstDayOfWeek) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use apply
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine. Though I think the original code is easier to read.
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" android:layout_height="match_parent" android:background="#fff" | ||
android:orientation="vertical" tools:context=".MainActivity"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you could avoid to put all values in the same line, it could be great
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for after
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just the style we have in other projects. Can I set it to be the standard one just in this project? I don't want to set a global rule...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's push like this, I could do this later ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually prefer the way it is now, because it's easier to see view hierarchy even in XML. Many times, when a view has a lot of attributes, it causes me to scroll a lot and try to remember what's happening around. Hard to read and understand what's going on, while also seeing the attributes.
But I do understand the request: it's the standard. In the past I also wanted to use WhiteSmith code style for Java, but I left it in the end because I couldn't convince anyone to use it (I still think it's better than all the rest).
Oh ! My bad, I totaly forgot to submit the review x) Now it's done !(Some comments are outdated now, because I wrote this Yesterday x) ) |
Removed old fonts, using Lato font, which is more modern and used on Android's latest versions. fixed issues of fonts, which didn't apply to all texts. getting fonts by using the support library.
ok done with all the comments you've written, and also fixed some of my own. |
} | ||
|
||
override fun onLoad(periodIndex: Int): List<WeekViewEvent>? { | ||
return onMonthChangeListener!!.onMonthChange(periodIndex / 12, periodIndex % 12 + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can you be sure that "onMonthChangeListener" will not be null here ?
I think that nullable "?" is better. It returns nullable List btw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are both correct and incorrect. For some reason the library has code to check it that when you use it, you must set a listener:
if (weekViewLoader == null && !isInEditMode)
throw IllegalStateException("You must provide a MonthChangeListener")
and then when you set it:
var monthChangeListener: MonthLoader.MonthChangeListener?
get() = if (weekViewLoader is MonthLoader) (weekViewLoader as MonthLoader).onMonthChangeListener else null
set(monthChangeListener) {
this.weekViewLoader = MonthLoader(monthChangeListener)
}
So you can't escape it from being non null.
But why this requirement exists at all?
How odd...
I think it's better to remove the requirement, and check for null...
For now I will let it stay how it is.
You did great dude. Could you take a look just above ? |
Done. Please, if you know how to fix the snapping issue, let me know. I've worked a lot on this library all around, but couldn't find why this occurs. |
…e dates being shown in the headers.
…of current time&date. You can test it by setting the time of the day to be 23:59, and wait a minute... cleaned code a bit.
…le, using `untitledEventText`
added getters to some of the inner fields, so that you can put views on top of the WeekView on the correct places. replaced the time auto-update mechanism that used Handler to update every minute. Now uses proper BroadcastReceiver instead.
fixed issue of not getting correct lastVisibleDate.
I've fixed a lot of issues and improved performance by about x2 of the library (mostly by using cached results). I'm sure there are more that can be optimized. |
… there are multiple of them from same calendar, it looks bad. minor performance improvements.
… there are multiple of them from same calendar, it looks bad. minor performance improvements.
…id-Week-View into develop # Conflicts: # library/src/main/java/com/alamkanak/weekview/WeekView.kt
…he current year. minor improvements.
Updated to use Android-X instead of support library.
@AndroidDeveloperLB is your kotlin library has drag and drop event features ? , I noticed someone trying to implement drag and drop features but its not actually working with existing events , do you have any idea how we can achieve this feature ? |
@nivritgupta I didn't implement this feature, and when I converted (and before), I've noticed it made the UI very slow, so I think the implementation of it is very flawed and I don't recommend using this feature in its current form. |
@AndroidDeveloperLB did you know any alternative calendar that have the same functionality like android week view with drag and drop events features ? I am trying to implement drag and drop features in "android week view" but I think its very hard to achieve this functionality with current coding structure . |
@nivritgupta Sorry, I don't. |
Sorry for sitting on this PR for so long, but as you can probably understand a large PR like this is quite hard to review and we're afraid that the library might no longer behave as we expect it to. However, a kotlin conversion is definitely necessary for the future of this library and so I hope I find the time to test this. I've looked over everything quickly for now and I only have a few questions/concerns:
|
@reilem Ok I have comments to the comments:
I think you should embrace this change. Sooner or later it's nicer to have it all in Kotlin. I think what i did made the library more mature. I've also written where it can be better, what else should be fixed... |
Alright thanks, currently we are working quite heavily on another project but if I have time I will try to locally merge your PR and test all important functionality. As for the double bang operator, my concern is exactly what you stated. Kotlin adds nice functionality and lots of improvements, and we shouldn't rely on old java logic for null checking. Since all you need to do is add a |
@reilem It's not that you should avoid "!!". It's just that it means that you are aware of what you are doing, that it shouldn't be null when you reach there. |
All I really want to say is that adding a I have looked at this situation and understand that right now it seems obvious to you, but to future contributors this sort of coding behaviour can be very confusing. I have been in a few situations where a new programmer joins a team and causes these types of bugs due to previous developer negligence. And what I mean is that since I am very anal about these type of safety measures haha. And that there's a good chance I will be adding the Edit: I’ve removed some of our comments below so that this thread stays on-topic. |
@reilem It really depends on the case. Adding null checks everywhere doesn't make sense in all cases. |
I've prepared a pull request that allows to snap by entire view (week by week, for example) based on this pull request, together with some fixes of issues I've found, and conversion to 100% Kotlin code.
Sadly, some issues that I've found still exist:
-Scroll by week instead of day #31 (comment) - snapping can be to part of the day.
My repository is here:
https://github.com/AndroidDeveloperLB/Android-Week-View
You can use latest commit in the project, from here:
https://jitpack.io/#AndroidDeveloperLB/Android-Week-View