openmrs-contrib-android-client icon indicating copy to clipboard operation
openmrs-contrib-android-client copied to clipboard

AC-821 Fix Java and Kotlin deprecation warnings

Open Anshul-9923 opened this issue 3 years ago • 30 comments

Description of what I changed

In Travis-ci while building this project many Java and Kotlin deprecation warnings were arising so to fix all those warnings, I have made changes in 4 files.

Issue I worked on

JIRA Issue: https://issues.openmrs.org/browse/AC-821

Checklist: I completed these to help reviewers :)

  • [X] My pull request only contains ONE single commit (the number above, next to the 'Commits' tab is 1).
  • [x] I have added tests to cover my changes. (If you refactored existing code that was well tested you do not have to add tests)
  • [X] All new and existing tests passed.
  • [X] My pull request is based on the latest changes of the master branch.

Anshul-9923 avatar Jan 31 '22 06:01 Anshul-9923

@LuGO0 Please review my code and merge PR, if any changes are required let me know.

Anshul-9923 avatar Jan 31 '22 06:01 Anshul-9923

@Anshul-9923 few warnings are still left just supress them if you think they are not critical

LuGO0 avatar Jan 31 '22 19:01 LuGO0

@LuGO0 Should I also have to fix deprecated build features and can you please tell me which other files are needed to be changed to fix the remaining warnings? I am not able to get which other files needed to be changed seeing the Travis-ci build.

Anshul-9923 avatar Jan 31 '22 19:01 Anshul-9923

Oh okay @Anshul-9923 I will look into it if I can find something.

LuGO0 avatar Feb 01 '22 20:02 LuGO0

public abstract class AppDatabase extends RoomDatabase {
                ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 warning

I think this is the one which is not related to build warnings is it? ^

w: C:\projects\openmrs-contrib-android-client\openmrs-client\src\main\java\org\openmrs\mobile\activities\dashboard\DashboardFragment.kt: (116, 13): Condition 'root != null' is always 'true'
w: C:\projects\openmrs-contrib-android-client\openmrs-client\src\main\java\org\openmrs\mobile\activities\formadmission\FormAdmissionPresenter.kt: (142, 21): Unreachable code
w: C:\projects\openmrs-contrib-android-client\openmrs-client\src\main\java\org\openmrs\mobile\activities\formlist\FormListFragment.kt: (57, 51): Parameter 'parent' is never used, could be renamed to _
w: C:\projects\openmrs-contrib-android-client\openmrs-client\src\main\java\org\openmrs\mobile\activities\formlist\FormListFragment.kt: (57, 103): Parameter 'id' is never used, could be renamed to _
w: C:\projects\openmrs-contrib-android-client\openmrs-client\src\main\java\org\openmrs\mobile\activities\formlist\FormListFragment.kt: (72, 48): Parameter 'v' is never used, could be renamed to _
w: C:\projects\openmrs-contrib-android-client\openmrs-client\src\main\java\org\openmrs\mobile\activities\formlist\FormListFragment.kt: (168, 29): Variable 'json' initializer is redundant
w: C:\projects\openmrs-contrib-android-client\openmrs-client\src\main\java\org\openmrs\mobile\activities\formlist\FormListFragment.kt: (180, 32): Variable 'obj' initializer is redundant
w: C:\projects\openmrs-contrib-android-client\openmrs-client\src\main\java\org\openmrs\mobile\activities\logs\LogsFragment.kt: (51, 30): Parameter 'context' is never used
w: C:\projects\openmrs-contrib-android-client\openmrs-client\src\main\java\org\openmrs\mobile\listeners\watcher\PatientBirthdateValidatorWatcher.kt: (39, 13): Unreachable code
w: C:\projects\openmrs-contrib-android-client\openmrs-client\src\main\java\org\openmrs\mobile\listeners\watcher\PatientBirthdateValidatorWatcher.kt: (40, 13): Unreachable code
w: C:\projects\openmrs-contrib-android-client\openmrs-client\src\main\java\org\openmrs\mobile\listeners\watcher\PatientBirthdateValidatorWatcher.kt: (45, 17): Unreachable code
w: C:\projects\openmrs-contrib-android-client\openmrs-client\src\main\java\org\openmrs\mobile\listeners\watcher\PatientBirthdateValidatorWatcher.kt: (46, 17): Unreachable code
w: C:\projects\openmrs-contrib-android-client\openmrs-client\src\main\java\org\openmrs\mobile\utilities\NotificationUtil.kt: (30, 43): 'constructor Builder(Context!)' is deprecated. Deprecated in Java

I came across these warnings as well in the CI build logs can you fix them with this PR only?

LuGO0 avatar Feb 02 '22 17:02 LuGO0

@LuGO0 I have fixed the remaining deprecated warnings. Please review my code.

Anshul-9923 avatar Feb 03 '22 15:02 Anshul-9923

@LuGO0 I did changes as told by you. PTAL

Anshul-9923 avatar Feb 05 '22 14:02 Anshul-9923

Please check the build is failing

LuGO0 avatar Feb 05 '22 16:02 LuGO0

Please check the build is failing

@LuGO0 It is because of changing compileSdkVersion and targetSdkVersion to 30.

Anshul-9923 avatar Feb 05 '22 16:02 Anshul-9923

Please check the build is failing

@LuGO0 It is because of changing compileSdkVersion and targetSdkVersion to 30.

So

Please check the build is failing

@LuGO0 It is because of changing compileSdkVersion and targetSdkVersion to 30.

I think we dont need this change . We can simply have a build version check and have 2 different implementations for network Utils. Suppress the older implementation using a method level supress annotation, does it help?

LuGO0 avatar Feb 06 '22 19:02 LuGO0

Please check the build is failing

@LuGO0 It is because of changing compileSdkVersion and targetSdkVersion to 30.

So

Please check the build is failing

@LuGO0 It is because of changing compileSdkVersion and targetSdkVersion to 30.

I think we dont need this change . We can simply have a build version check and have 2 different implementations for network Utils. Suppress the older implementation using a method level supress annotation, does it help?

@LuGO0 So, Should I change library from android.preference.PreferenceManager to androidx.preference.PreferenceManager as it is deprecated warning.

Anshul-9923 avatar Feb 08 '22 15:02 Anshul-9923

I think we dont need this change . We can simply have a build version check and have 2 different implementations for network Utils. Suppress the older implementation using a method level supress annotation, does it help?

@LuGO0 So, Should I change library from android.preference.PreferenceManager to androidx.preference.PreferenceManager as it is deprecated warning.

Yes, just add a supress annotation locally if the build is failing and you are unable to fix it.

LuGO0 avatar Feb 08 '22 16:02 LuGO0

I think we dont need this change . We can simply have a build version check and have 2 different implementations for network Utils. Suppress the older implementation using a method level supress annotation, does it help?

@LuGO0 So, Should I change library from android.preference.PreferenceManager to androidx.preference.PreferenceManager as it is deprecated warning.

Yes, just add a supress annotation locally if the build is failing and you are unable to fix it.

@LuGO0 After importing it build fails and asks for changing minCompileSdk to 31. Screenshot (465)

Anshul-9923 avatar Feb 08 '22 16:02 Anshul-9923

@LuGO0 Done with the changes as told by you.

Anshul-9923 avatar Feb 10 '22 16:02 Anshul-9923

@LuGO0 I have reverted the changes wherever told by you. PTAL

Anshul-9923 avatar Feb 10 '22 18:02 Anshul-9923

Few warnings are still there but we can merge this will try running the application locally then merge this PR Thanks!

LuGO0 avatar Feb 11 '22 18:02 LuGO0

Few warnings are still there but we can merge this will try running the application locally then merge this PR Thanks!

Ok @LuGO0

Anshul-9923 avatar Feb 12 '22 04:02 Anshul-9923

@LuGO0 You have not merged my PR, do I need to do any changes?

Anshul-9923 avatar Feb 16 '22 07:02 Anshul-9923

Will run it locally then merge it.

LuGO0 avatar Feb 16 '22 09:02 LuGO0

@shubhamsgit need some help verifying this PR locally, and let me know if it works fine? Thanks!

LuGO0 avatar Feb 19 '22 17:02 LuGO0

@LuGO0 When will the idealist release for GSoC projects by openmrs?

Anshul-9923 avatar Mar 01 '22 04:03 Anshul-9923

@LuGO0 When will the idealist release for GSoC projects by openmrs?

Not sure @Anshul-9923, you can find it on OpenMRS Talk or ask the GSOC co-ordinators like Jennifer and Moses ! Also sorry for the delay in this PR's review haven't got a chance to run it locally once !

LuGO0 avatar Mar 01 '22 18:03 LuGO0

@LuGO0 When will the idealist release for GSoC projects by openmrs?

Not sure @Anshul-9923, you can find it on OpenMRS Talk or ask the GSOC co-ordinators like Jennifer and Moses ! Also sorry for the delay in this PR's review haven't got a chance to run it locally once !

Thanks @LuGO0

Anshul-9923 avatar Mar 01 '22 18:03 Anshul-9923

Please dont delete any unreachable code since these are probably part of some unfinished module. I would be happy to keep them as they are for now with a warning supression.

LuGO0 avatar Mar 01 '22 19:03 LuGO0

Please dont delete any unreachable code since these are probably part of some unfinished module. I would be happy to keep them as they are for now with a warning supression.

No need to delete @LuGO0 The unreachable code's position just has to be changed

shubhamsgit avatar Mar 01 '22 19:03 shubhamsgit

Please dont delete any unreachable code since these are probably part of some unfinished module. I would be happy to keep them as they are for now with a warning supression.

You mean 'redundant code' or 'unreachable code'?

shubhamsgit avatar Mar 01 '22 19:03 shubhamsgit

Unreachable code, like the formAdmissionPresenter portion.

LuGO0 avatar Mar 01 '22 19:03 LuGO0

Unreachable code, like the formAdmissionPresenter portion.

I think that code can be removed as program control never reaches view.enableSubmitButton(true) because error(errorMessage) throws IllegalStateException and program terminates.

shubhamsgit avatar Mar 01 '22 19:03 shubhamsgit

and in PatientBirthdateValidatorWatcher, edmonth.text.clear() and edyr.text.clear() these two lines should be moved before the error() function. This can be counted as a bug though. Can open a new PR if you want.

shubhamsgit avatar Mar 01 '22 19:03 shubhamsgit

Yupp create new PRs if needed with each one for a specific use case, don't do it in this one!

LuGO0 avatar Mar 02 '22 16:03 LuGO0