element-hq / element-x-android

Android Matrix messenger application using the Matrix Rust Sdk and Jetpack Compose
GNU Affero General Public License v3.0
1.08k stars 155 forks source link

Use FFI interfaces rather than implementation #3482

Closed bmarty closed 1 month ago

bmarty commented 2 months ago

Content

Use FFI interfaces rather than implementation

Motivation and context

This is good practice this way we will be able to add more unit tests.

Screenshots / GIFs

Tests

Tested devices

Checklist

github-actions[bot] commented 2 months ago

:iphone: Scan the QR code below to install the build (arm64 only) for this PR. QR code If you can't scan the QR code you can install the build via this link: https://i.diawi.com/a1sYp7

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 82.66%. Comparing base (dbc4c8f) to head (be48552).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #3482 +/- ## ======================================== Coverage 82.66% 82.66% ======================================== Files 1731 1731 Lines 40829 40829 Branches 4964 4964 ======================================== Hits 33750 33750 Misses 5320 5320 Partials 1759 1759 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

jmartinesp commented 1 month ago

The only downsides I see to this are having to use (FooInterface as? Foo)?.destroy() and (FooInterface as? Foo)?.use { ... } since neither the Disposable nor the Closeable interfaces are part of those *Interface components.

If we don't care about destroying the Rust objects ourselves and we leave that to the Cleaner using these interfaces should have no real downsides AFAICT.

EDIT: oh, I see you already handled those in the PR, nice!

bmarty commented 1 month ago

I think the PR is now mergeable. The changes it contains will allow to add more unit test (maybe in #3450)

sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

ganfra commented 1 month ago

I'm not sure to see the interest to replace the classes by interface inside the Rust implementation classes... if they are called RustBlablaService, we are expecting to use Rust classes, not fakes. Most of our code inside this module is already just wrapper to avoid exposing the rust.

bmarty commented 1 month ago

OK, will open another PR with just some cleanup then.