<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yassine Gharsallah on Medium]]></title>
        <description><![CDATA[Stories by Yassine Gharsallah on Medium]]></description>
        <link>https://medium.com/@yassinegharsallah?source=rss-c8fe45927c1a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*kupyZO3WkDLrgfwh.jpg</url>
            <title>Stories by Yassine Gharsallah on Medium</title>
            <link>https://medium.com/@yassinegharsallah?source=rss-c8fe45927c1a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 21:41:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yassinegharsallah/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[MVP + Dagger 2 + RX = Clean/Modern Android App/Code]]></title>
            <link>https://medium.com/android-news/mvp-dagger-2-rx-clean-modern-android-app-code-74f63c9a6f2f?source=rss-c8fe45927c1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/74f63c9a6f2f</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[rxjava]]></category>
            <category><![CDATA[mvp]]></category>
            <category><![CDATA[dagger-2]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Yassine Gharsallah]]></dc:creator>
            <pubDate>Tue, 04 Apr 2017 06:25:44 GMT</pubDate>
            <atom:updated>2017-04-05T09:02:30.098Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F82rySC5Ngvn30ke4bPjSQ.png" /><figcaption>MVP + Dagger = magic</figcaption></figure><p>In this Tutoriel I will show you how to use Dagger 2 to inject MVP layers (Model-View-Presenter) into each Activity/Screen of your App . So your code will be clean, maintainble, and easy to test : wich is the three thing each developer have to keep in mind when developing mobile apps.</p><p>So to do this i have created a simple App : MarvelHeroesApp . The code of this App is available in my Github Account : <a href="https://github.com/yassine-gharsallah/marvel">App Code </a>.</p><p>The final visual of the app is like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*9NcCR24tHcU8Ri2vBUVbQw.png" /><figcaption>Marvel Hero App</figcaption></figure><p>This Article is divided in three parts :</p><ul><li>Part 1 : i will be talking about the most useful library that i have used in this app and each Android developer should use because they facilitate devs.</li><li>Part 2 : i will talk about MVP pattern and how to use it in android apps dev context .</li><li>Part 3 : i will talk about how to use dagger2 to inject MVP layers</li></ul><h3>App Libraries</h3><p>In this Project i have used many api which i will not go into details for each library but i will describe each one briefly, So let’s take a look at the Gradle app file :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IONQ-Er1AVYdQmxniRpVtg.png" /><figcaption>Gradle app file</figcaption></figure><p>In this project i have used a bunch of must have/use api like :</p><p><strong>Leak Canary</strong> : a Library from Square that analyse the memory of your App and notifiy you whenever a leak happens, it’s easy to set up and it’s really helpful.</p><p><strong>GLide</strong> : Image Loading and caching library very useful for loading images from the net especially for listview whith images from internet.</p><p><strong>Timber : </strong>Another library from Square which allow you customise your log for Debug and release version .</p><p><strong>ButterKnife</strong> :Dependencies Injection library for views into Android Component like Activity/Fragment…</p><p><strong>Retrofit</strong> : Retrofit is one of the most popular HTTP Client Library for Android as a result of its simplicity and its great performance compare to the others.</p><p><strong>RxJava/RxAndroid </strong>: Reactive extension for Java . I highly recommend to use it in each android app because we are reacting to user interactions while a background network thread is running in background and orchestrating all of this quickly become unmanageable code mess. In the Other side this is a case where <a href="https://github.com/ReactiveX/RxJava">RxJava</a> (ReactiveX) excels — orchestrating multiple actions that happen due to certain events in the system.</p><p><strong>Retrolambda</strong> : Please visit my article below for more details on how to set up and use retrolambda :</p><p><a href="https://medium.com/@yassinegharsallah/retrolambda-nothing-to-lose-everything-to-gain-e96b9ff1f0b9">Retrolambda : Nothing to lose, Everything to Gain</a></p><h3>Implementing MVP core</h3><p>Now let’s begin the real stuff :</p><p>The project is structured into 5 packages :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*Xi6lxJehCFhrw1ySIgPwog.png" /><figcaption>packages</figcaption></figure><p><strong>api </strong>: package where the retrofit api reside in .</p><pre>@GET(&quot;test-mobile/iOS/json/test2.json&quot;)<br>Observable&lt;Heroes&gt; getHeroes();</pre><p>I highly recommend when you have an app that consumes a webservice to use retrofit rxjava adapter so you can easily manipulate ws call with the handy Rxjava operator like OnNext , flatMap …..</p><p><strong>application</strong> : package where we put all the generic modules of our app to be used by Activities . So you have to think of the application as it‘s a container of our Activities and it still alive all along the app is running . Also you have to differentiate between Application Context and the Activity Context bacause this is a really important point.</p><p>In our Exemple we have to expose Schedulers (Threads where our tasks will be executed and attached to ) and the Retrofit api service as shown in code below :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04c3514cd6c979ebffe370a64d8a7566/href">https://medium.com/media/04c3514cd6c979ebffe370a64d8a7566/href</a></iframe><p><strong>models</strong> : package where our POJO class reside</p><p><strong>Screens</strong> : each screen of the app is in separarte package as a child of this parent package.</p><p>This is the most important parts of our app i will go into details in this part to show you how to decouple each layer of the Pattern MVP and how the code will look like at the end, for this i will take as an exemple the splash Screen :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/1*IsVE8SbuxID-9ySGdGtlLg.png" /><figcaption>Splash screen package</figcaption></figure><p>1- First of all create SplashView class inflate the view from the layout and bind it with ButterKnife :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6fb38caa4da61c1c57fca51fc05901d6/href">https://medium.com/media/6fb38caa4da61c1c57fca51fc05901d6/href</a></iframe><p>2- Create SplachModel class which provide a bunch of methods to access DB or network with a return type <strong><em>Observable</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0417b60d6280b2ca5042423dc81491a2/href">https://medium.com/media/0417b60d6280b2ca5042423dc81491a2/href</a></iframe><p>3 Create SplashPresenter class which take as a parameters all the observable from SplashModel and turn them into<strong><em> Subscriptions</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/93a93fd55ebd5c399f6e0b85d4a19768/href">https://medium.com/media/93a93fd55ebd5c399f6e0b85d4a19768/href</a></iframe><p>this is how you have to concept your app, image below describes better the flow of data in our app and you should do this in each app to obtain a maintanble and a testable app :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*gbOHsfytQL3gzemnlMeB_A.png" /><figcaption>Clean Android Architecture</figcaption></figure><p>At the end this is how your MVP core should look like :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xy2FBmyOJK4c2bt6G8BxrQ.png" /><figcaption>MVP</figcaption></figure><h3>Dagger 2 Take place here</h3><p>Dagger 2 come to our rescue right here to inject MVP layers into our Activity .</p><p>Dagger is based especially on three annotations which are :</p><p><em>@Inject</em> : to be used for Object we want to provide .</p><p>@Component : used like an interface between @Inject and @Module</p><p>@Module : wich uses @Provides for each method we want to provide in a specific</p><p>SplashActivity need SplashView and SplashPresenter so we Inject them using the @Inject dagger annotation like the code below :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/756f92311aeed3dd34012407fc636873/href">https://medium.com/media/756f92311aeed3dd34012407fc636873/href</a></iframe><p>We can see right here that the code of the activity is very sharp and clean and there is no boilerplate.</p><p>Presenter and View are provided by the dagger Component defined as below :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9a9b79074f9a6e4b1eeb3f74e9fa1d8/href">https://medium.com/media/d9a9b79074f9a6e4b1eeb3f74e9fa1d8/href</a></iframe><p>This Component use SplashModule class to provide our Presenter and View :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/317537610f6dfe8c54668c5670769f1a/href">https://medium.com/media/317537610f6dfe8c54668c5670769f1a/href</a></iframe><p>T<em>hat’s it guys for this Article, In the next Article i will write to you how to create fonctionnal Test and also how to unit test your code . because if you create a clean and a well decoupled Code Testing will become a piece of cake.</em></p><p>Certainly creating a modern/clean app need more time than creating an app the classic way but at the end we are sure that we have a maintainble code . That’s why Generally I have to explain to my clients that we have to spend more time on devs to get a modern/clean code .</p><p>Questions? Comments? Leave a note here or email me at :</p><p><em>yassine.gharsallah@gmail.com</em></p><p>Twitter : <a href="https://twitter.com/YGharsallah">Ygharsallah</a></p><p>Also, click the 💚 below so more people will see this article here on Medium. And stay tuned next article will be online soon….</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F3e491f%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2F3e491f%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ae57c1b4448392f65f474b01a127fbf/href">https://medium.com/media/2ae57c1b4448392f65f474b01a127fbf/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74f63c9a6f2f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/mvp-dagger-2-rx-clean-modern-android-app-code-74f63c9a6f2f">MVP + Dagger 2 + RX =👌 Clean/Modern Android App/Code</a> was originally published in <a href="https://medium.com/android-news">AndroidPub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Retrolambda : Nothing to lose, Everything to Gain]]></title>
            <link>https://medium.com/android-news/retrolambda-nothing-to-lose-everything-to-gain-e96b9ff1f0b9?source=rss-c8fe45927c1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e96b9ff1f0b9</guid>
            <category><![CDATA[retrolambda]]></category>
            <category><![CDATA[rxandroid]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[rxjava]]></category>
            <dc:creator><![CDATA[Yassine Gharsallah]]></dc:creator>
            <pubDate>Mon, 03 Apr 2017 17:44:03 GMT</pubDate>
            <atom:updated>2017-04-04T13:19:38.241Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*qCNzc4zhI3yfKFeNErBq1A.png" /></figure><p>In this Article I will show how to set up retrolambda in your Android project in a few steps, And how to get the most out of it .</p><h3><strong>How to set up Retrolambda</strong></h3><p>All you had to do is to apply in your app gradle the plugin of retrolambda and to add the compileOptions like shown in the image below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*DyYr0gvPkqV1K1gNJiT7NA.png" /><figcaption>Build.gradle app</figcaption></figure><p>Then in your build.gradle project file add this line :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yP5WvPEJRPQxsP2yL5DKhA.png" /><figcaption>build.gradle project file</figcaption></figure><p>Now you are good to go to use retrolambda and to see it’s magic and how it reduce our boilerplate code.</p><h3>Pro Tip</h3><p>After setting retrolambda forget about it and go type some code for exemple :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hREPOzEGue12ULxJ_yHGTA.png" /><figcaption>Old Way</figcaption></figure><p>At some point you will see part of your code turn grey, when you hover it android studio offer you to use lambda expression so don’t hesitate to use them to reduce your code like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4gCFa-Ig2Bq9ZTbCjihZLQ.png" /><figcaption>New way</figcaption></figure><p>I highly recommend using retrolambda when using RXJava and RXandroid on your project because it reduces the amount of your code ,and your code will be more clear like in this exemple below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n5iJxEOQzENGzGqUCHPpgg.png" /><figcaption>Lambda vs Plain cod</figcaption></figure><p>In the top image you see the difference between between applying lambda expression and coding the old way and how it reduces code lines numbers and as i told you before part where lambda expressions can be used are <em>GREY</em> , So it up to you to decide !</p><p>That&#39;s it guys, I hope you will begin to use Retrolambda if you’re not already using it. It’s intuitive and remember all you have to do is to set it up .</p><p>Questions? Comments? Leave a note here or email me at :</p><p><em>yassine.gharsallah@gmail.com</em></p><p>Twitter : <a href="https://twitter.com/YGharsallah">Ygharsallah</a></p><p>Also, click the 💚 below so more people will see this article here on Medium.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F3e491f%3Fas_embed%3Dtrue&amp;url=https%3A%2F%2Fupscri.be%2F3e491f%2F&amp;image=https%3A%2F%2Fupscri.be%2Fmedia%2Fform.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ae57c1b4448392f65f474b01a127fbf/href">https://medium.com/media/2ae57c1b4448392f65f474b01a127fbf/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e96b9ff1f0b9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/retrolambda-nothing-to-lose-everything-to-gain-e96b9ff1f0b9">Retrolambda : Nothing to lose, Everything to Gain</a> was originally published in <a href="https://medium.com/android-news">AndroidPub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Calculateur Vitesse , Radar Vitesse, Idée?]]></title>
            <link>https://medium.com/@yassinegharsallah/calculateur-vitesse-radar-vitesse-id%C3%A9e-b03a8f8a3878?source=rss-c8fe45927c1a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b03a8f8a3878</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[ideas]]></category>
            <category><![CDATA[startup-ideas]]></category>
            <dc:creator><![CDATA[Yassine Gharsallah]]></dc:creator>
            <pubDate>Thu, 09 Feb 2017 07:44:14 GMT</pubDate>
            <atom:updated>2017-02-09T07:44:14.865Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*ndRkeyNuA8iWiwn7ZyQzUQ.png" /><figcaption>CREDIT : <a href="https://dribbble.com/mathelme">mathelme</a></figcaption></figure><p>Aujourd’hui, en roulant sur la fameuse A86, il y’avait un dispositif sur la chaussé pour calculer le nombre de voitures qui passent par cette voie (utilisé généralement pour des fins du statistiques pour calculer le flux des voitures qui passent sur une plage horaire donné . Ce dispositif est décrit par l’image suivante :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*vnGOTkJycECbVIQ2XDXhUg.jpeg" /><figcaption>Comptage voiture</figcaption></figure><p>Bref, j’ai eu l’idée de calculer la vitesse d’une voiture a partir d’un dispositif similaire que je vait expliquer dans ce qui suit :</p><p>D’une façon générale pour calculer la vitesse d’une voiture la formule est simple :</p><p>Vitesse = Distance / Temps .</p><p>Pour notre cas il faut placer un capteur comme celui utilisé pour le comptage des véhicules sur la chaussée et il faut que ce dernier a chaque contact avec les roues avant ou arrière enregistre le temps du passage en millisecondes .</p><p>Donc pour calculer la vitesse on procède comme suit :</p><p>vitesse véhicule = distance entre les roues avant et roue arrière / (T2 -T1)</p><p>T2 = moment de passage des deux roues arrière sur le fils de comptage .</p><p>T1 = moment de passage des deux roues avant sur le fils de comptage .</p><p>le problème c’est que la distance entre l’essieu avant et l’essieu arrière diffère d’une voiture a l’autre . pour borner l’erreur et pour tester le système j’ai crée un petit simulateur pour effectuer des tests sur ce petit projet, et comme je suis un développeur Android, j’ai crée une petite application Android qui simule ce système de calcul de vitesse</p><p>Ci dessous une screenshot de l’application que je vait expliquer comment ça marche :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*cgy52pKHojyvFyJF0Ub-vg.png" /></figure><p>La première ligne correspond au temps du mon premier Tap sur la zone bleu</p><p>La deuxième ligne correspond au temps du mon deuxième Tap sur la zone bleu</p><p>La Troisième ligne correspond a la vitesse en KM/H calculé en prenons comme valeur d’empattement moyen des voitures qui est de : <strong>2,57 mètres </strong>.</p><p>En naviguant un peu sur internet et en suivant ce lien :</p><p><a href="http://www.fiches-auto.fr/articles-auto/classements-comparatifs-auto/s-548-classement-par-empattement.php">empattement véhicules</a> j’ai constaté que :</p><p>2.2 métres ≤Empattement Auto ≤ 3 métres</p><p>pour borner l’erreur de ce radar ou calculateur de vitesse j’ai fait les tests suivant avec le simulateur :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*sMrEaAQd5G4rNHP1afHg0g.png" /></figure><p>J’ai constater que l’erreur maximale de ce système entre les 2 valeurs limites est de 17 km/h</p><p>en prenant la valeur moyenne et la plus générique : 2.57 on aura une erreur max de 9km/h</p><p>Donc on peut utiliser ce système pour le calcul de la vitesse de toutes les voitures avec une fiabilité de +/- 10km/h (erreur )</p><p>Contraintes :</p><p>* les Semi remorques et les bus ??</p><p>*les 2 roues : moto, vélo, scooter…??</p><p>Ce système peut être très fiable si on veut calculer la vitesse d’une voiture connu d’avance.</p><p><strong>C’était une petite idée que j’ai eu et j’ai voulu la partager avec vous avec mon raisonnement la dessus .</strong></p><p>Toutes vos questions, contraintes, critiques , améliorations sont les bienvenues…</p><p>PS : Le code source de l’application Android est disponible en suivant ce lien :</p><p><a href="https://github.com/yassine-gharsallah/vitesse">https://github.com/yassine-gharsallah/vitesse</a>t</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b03a8f8a3878" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>