Skip to content
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

#457: Converted java to Kotlin #835

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from

Conversation

rahul13agrawal
Copy link

}
}


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra newlines to be removed.

constructor(filePath: String) : this(GifInfoHandle(filePath))

/**
* Equivalent to `` GifMetadata(file.getPath())}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Equivalent to `` GifMetadata(file.getPath())}
* Equivalent to `GifMetadata(file.getPath())}`

* Current frame can be copied to 2D texture when needed. See [.glTexImage2D] and [.glTexSubImage2D].
*/
class GifTexImage2D(inputSource: InputSource, options: GifOptions?) {
private val mGifInfoHandle: GifInfoHandle?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be nullable

*/
get() = mGifInfoHandle!!.duration

@Throws(Throwable::class)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this annotation is useless, please remove

try {
return GifDrawable(resources, resId)
} catch (ignored: IOException) {
// ignored
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is not needed

Comment on lines 14 to 15
private var conditionVariable: ConditionVariable? = null
private var waiter: Waiter? = null
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be lateinit instead of nullable

val isRecycled: Boolean
get() = gifInfoPtr == 0L

@Throws(Throwable::class)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be removed

android-gif-drawable/src/main/c/bitmap.c Show resolved Hide resolved
Copy link
Owner

@koral-- koral-- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another set of comments. This is still not the last one.

@@ -9,8 +10,8 @@ android {
compileSdkVersion versions.compileSdk

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project does not compile for me when I move it back to 1.8

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll check this further ASAP.

val resources = getInstrumentation().context.resources
val drawable = GifDrawable(resources, pl.droidsonroids.gif.test.R.raw.test)
val metaData = GifAnimationMetaData(resources, pl.droidsonroids.gif.test.R.raw.test)
Assertions.assertThat(drawable.frameByteCount + metaData.allocationByteCount)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import Assertions.assertThat
here and in other similar files

@Before
fun setUp() {
val context = InstrumentationRegistry.getInstrumentation().context
rootView = LayoutInflater.from(context).inflate(pl.droidsonroids.gif.test.R.layout.attrributes, null, false)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import pl.droidsonroids.gif.test.R here and in other tests.

Comment on lines 24 to 26
val responseStream: InputStream = ByteArrayInputStream(buffer)
val gifDrawable = GifDrawable(responseStream)
Assertions.assertThat(gifDrawable.error).isEqualTo(GifError.NO_ERROR)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val responseStream: InputStream = ByteArrayInputStream(buffer)
val gifDrawable = GifDrawable(responseStream)
Assertions.assertThat(gifDrawable.error).isEqualTo(GifError.NO_ERROR)
val responseStream: InputStream = ByteArrayInputStream(buffer)
val gifDrawable = GifDrawable(responseStream)
Assertions.assertThat(gifDrawable.error).isEqualTo(GifError.NO_ERROR)

Separate arrange, act and assert sections with a newlines. Here and in other tests.

/**
* See [GifDrawable.getDuration]
*
* @return duration of of one loop the animation in milliseconds. Result is always multiple of 10.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @return duration of of one loop the animation in milliseconds. Result is always multiple of 10.
* @return duration of one loop the animation in milliseconds. Result is always multiple of 10.

Comment on lines 24 to 25
abstract fun open(): GifInfoHandle
@Throws(IOException::class)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
abstract fun open(): GifInfoHandle
@Throws(IOException::class)
abstract fun open(): GifInfoHandle
@Throws(IOException::class)

fun testNotEqualReferences() {
val reference = CallbackWeakReference(callback)
val anotherReference = CallbackWeakReference(anotherCallback)
Java6Assertions.assertThat(reference).isNotEqualTo(anotherReference)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace L4 with import org.assertj.core.api.Java6Assertions.assertThat
Remove Java6Assertions. prefixes from the test methods.

Comment on lines 19 to 21
@RunWith(
MockitoJUnitRunner::class
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@RunWith(
MockitoJUnitRunner::class
)
@RunWith(MockitoJUnitRunner::class)

Change also similar places, if any.

lateinit var resources: Resources

private fun getMockedResources(resourceDensity: Int, displayDensity: Int): Resources {
Mockito.doAnswer { invocation ->
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import Mockito just like Java6Assertions from one of the previous comments.

/**
* Frame buffer, holds current frame.
*/
var mBuffer: Bitmap
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be internal. This also applies to most (if not all) other members which were previously package private.
But, it may break the backwards compatibility.
Please hold on any changes in this matter for now. I need to think about that.

@rahul13agrawal
Copy link
Author

@koral-- Let me know if more comments on the review. I have resolved the comments couple of days back.

@koral--
Copy link
Owner

koral-- commented Oct 20, 2023

Changes are looking very good. Great work!

I plan to add some binary compatibility checker https://plugins.gradle.org/search?term=binary-compatibility
and depending on the results decide whether it will be version 2.x or we can keep the backwards compatibility and stick to 1.x.
Some minor changes like changing the visibility to internal may be required next.

I'll try to do that in a few days from now.

@koral--
Copy link
Owner

koral-- commented Oct 24, 2023

Hi @rahul13agrawal I've just added https://github.com/Kotlin/binary-compatibility-validator. You can rebase on the latest dev and execute the gradle tasks:

  • apiCheck- this will give you a diff in terminal
  • apiDump - this will overwrite the current apiDump file so you can inspect the git diff in your Android Studio or whatever you prefer

It is perfectly OK that some method or class gets added. It will happen for e.g. all companion objects.
But, if signature of the method, class or field has changed it can break the compatibility for existing users.
The diff is quite large now, but here are some easily fixable insights:

  1. classes become final by default in kotlin, so we need to add open modifiers, this also applies to methods
  2. some fields like GifError.description were replaced by methods, you can probably use @JvmField for them
  3. some extra methods are added like GifDrawable.setMIsRunning which should probably not be part of an API

@rahul13agrawal
Copy link
Author

@koral-- I will go through this by this weekend.

@rahul13agrawal
Copy link
Author

Hi @koral-- Sorry for such late response. I have rebase with the latest changes but whenever I run ./gradlew apiCheck or apiDump I get build successful. I am unable to find any changes. Neither in Android Studio nor in the terminal.
I have gone through https://github.com/Kotlin/binary-compatibility-validator and tried to check but with no result.

@koral--
Copy link
Owner

koral-- commented Nov 15, 2023

Indeed, it seems that disabling the check in the sample module only causes disabling it entirely. I need to investigate this.

In the meantime you can comment out or delete this line: https://github.com/koral--/android-gif-drawable/blob/dev/sample/build.gradle#L65 and ignore the generate dump of the sample module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants