<?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 Mihail Urmanschi on Medium]]></title>
        <description><![CDATA[Stories by Mihail Urmanschi on Medium]]></description>
        <link>https://medium.com/@urmanschi.mihail?source=rss-fd037882bf88------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*06WNKPL1QROhukFR.</url>
            <title>Stories by Mihail Urmanschi on Medium</title>
            <link>https://medium.com/@urmanschi.mihail?source=rss-fd037882bf88------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 02:28:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@urmanschi.mihail/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[Dealing with view check’s in Presenters]]></title>
            <link>https://medium.com/@urmanschi.mihail/dealing-with-view-checks-in-presenters-59a9de955cf5?source=rss-fd037882bf88------2</link>
            <guid isPermaLink="false">https://medium.com/p/59a9de955cf5</guid>
            <category><![CDATA[android-mvp]]></category>
            <category><![CDATA[view-check]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[mvp]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Mihail Urmanschi]]></dc:creator>
            <pubDate>Thu, 19 Oct 2017 11:42:11 GMT</pubDate>
            <atom:updated>2017-10-19T11:42:11.669Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<p>I’d like to share the approach I use to check if the view attached to presenter is null or not, simplifying the code and make it more readable</p><h4>Requirements</h4><p>MVP pattern and lambdas (for now using Retrolambda)</p><h4>Introduction</h4><p>MVP is one of the best approach to separate you code in logical layer when you easily can make changes and maintain you code, of course it has some flaws but with some persistence you can find how to deal with them, on of those flays is checking the nullability of the view in presenter, of course in <strong>Kotlin</strong> you simply put a “?” in front of view and that’s it, but in java is not that simple, and writing every time ‘if statements” is not that pretty and consumes a lot of time and add frustration.</p><p>I want to write presenters with something like <strong><em>getView().doSomething()</em></strong> … it is possible in java to do that, you can look at <a href="https://github.com/Arello-Mobile/Moxy">this</a> Github repository that I was using for some time, but almost all MVP libraries are using annotation processors, and have a lot of code, methods… so I was searching for a way to do it a little bit easier and by my self without using any library</p><h4>Explanation</h4><p>The best this I came to is something like <strong><em>getView(v -&gt; v.doSomething())</em></strong>, not as pretty as expected but fairly easy to do and easy to write</p><p>The first step is to <em>create you interfaces, the view and presenter</em>, the presenter is not always necessary but I prefer to write it to.</p><p>Next, you write an <em>abstract presenter</em> that takes as template param the view.</p><p><em>Encapsulate the view in a weakReference</em>, this way is easier to deal with memory leaks.</p><p>Inside the base presenter(the abstract class) you going to need a protected interface with a method that takes as param the template view.</p><p>And the last needed is a method that takes as param this interface, inside check if the view is not null and executes the method of the interface if so.</p><h4>Example</h4><p>The result is something like this:</p><pre>public abstract class BasePresenter&lt;V&gt; {</pre><pre>    private WeakReference&lt;V&gt; view;<br><br>    public void getView(ViewState&lt;V&gt; v) {<br>        if (view.get() != null)<br>            v.execute(view.get());<br>    }<br><br>    public void attachView(V view) {<br>        this.view = new WeakReference&lt;&gt;(view);<br>    }<br><br>    protected interface ViewState&lt;View&gt; {<br>        void execute(View v);<br>    }<br>}</pre><p>Dn example of the interfaces could be:</p><pre>public interface ExampleContract {<br><br>    interface View{<br>        void doSomething();<br>    }<br><br>    interface Presenter{<br>        void callSomething();<br>    }<br><br>}</pre><p>I write them inside another interface just to keep them organized.</p><p>An implementation of a presenter is something like this:</p><pre>public class Presenter extends BasePresenter&lt;ExampleContract.View&gt;<br>                       implements ExampleContract.Presenter {<br><br>    @Override<br>    public void callSomething() {<br>        getView(v -&gt; v.doSomething());<br>    }<br><br>}</pre><h4>Thats’it!</h4><p>If you have any questions feel free to leave a comment or make a suggestion.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59a9de955cf5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fast and lazy .apk distribution with Crashlytics]]></title>
            <link>https://medium.com/@urmanschi.mihail/fast-and-lazy-apk-distribution-with-crashlytics-9a6d33804fde?source=rss-fd037882bf88------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a6d33804fde</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[distribution]]></category>
            <category><![CDATA[fabric]]></category>
            <category><![CDATA[release-notes]]></category>
            <dc:creator><![CDATA[Mihail Urmanschi]]></dc:creator>
            <pubDate>Thu, 05 Oct 2017 13:18:23 GMT</pubDate>
            <atom:updated>2017-10-05T13:18:23.679Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-liUTqqyf30g_J7TpsCeDw.jpeg" /></figure><blockquote>The hardest thing for me to do is to write release notes, and anyway, if I write commits for gradle, why not use them as release notes?</blockquote><p>Luckily git allows that, and with <a href="https://gradle.org/">gradle</a> for android is there easy to write some small scripts and get the job done in one click.</p><h3><strong>Getting the release notes:</strong></h3><p>Since we need to properly add release notes since last distribution, a good way to control that is by tagging every time you release. This way you can add to release notes only the commits since the last tag.</p><p>To <a href="https://stackoverflow.com/questions/12082981/how-to-get-all-commits-since-last-tag">get all commits since last tag</a> we can use the following command :</p><pre><a href="https://stackoverflow.com/questions/12082981/how-to-get-all-commits-since-last-tag">git log `git describe --tags --abbrev=0`..HEAD --oneline</a></pre><p>This command contains an inner command to get the last tag:</p><p>git describe --tags --abbrev=0</p><p>In groovy to get the last tag write a function like that :</p><pre>def getLastTag() {<br>    def stdout = new ByteArrayOutputStream()<br>    exec {<br>        commandLine &#39;git&#39;, &#39;describe&#39;, &#39;--tags&#39;, &#39;--abbrev=0&#39;<br>        standardOutput = stdout<br>    }<br>    return stdout.toString()<br>}</pre><p>With that, we will get the last tag, and to get the commits the following function will do the job:</p><pre>def getCommitsSinceLastTag() {<br>    def range = getLastTag() + &#39;..HEAD&#39;<br>    def stdout = new ByteArrayOutputStream()<br>    exec {<br>        commandLine &#39;git&#39;, &#39;log&#39;, range.toString().replace(&#39;\n&#39;, &#39;&#39;), &#39;--oneline&#39;<br>        standardOutput = stdout<br>    }<br>    return stdout.toString()<br>}</pre><h3>Distribution with Crashlytics:</h3><p>Let’s keep thing short, not much description for the above…</p><p>add the following tasks to build.gradle :</p><pre>def groupName = &quot;distribution&quot;</pre><pre>task buildCandidate() {<br>    group = groupName<br>    dependsOn &#39;clean&#39;<br>    finalizedBy &#39;assembleDebug&#39;<br>}</pre><pre>task sendCandidateToCrashlytics() {<br>    group = groupName<br>    dependsOn buildCandidate<br>    finalizedBy &#39;crashlyticsUploadDistributionDebug&#39;<br>}</pre><p>and for release notes and the group to distribute :</p><pre>debug {<br>    ext.betaDistributionReleaseNotes = getCommitsSinceLastTag()<br>    ext.betaDistributionGroupAliases=&quot;GroupName&quot;<br>}</pre><p>To release press the sendCandidateToCrashlytics task on the new gradle created group:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*iu97L4uOeyTr0ZjqfZpFiA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a6d33804fde" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MVP Fragment navigation (from inside fragments)]]></title>
            <link>https://medium.com/@urmanschi.mihail/mvp-fragment-navigation-from-inside-fragments-2c4388f97904?source=rss-fd037882bf88------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c4388f97904</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[fragment-navigation]]></category>
            <category><![CDATA[mvp]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Mihail Urmanschi]]></dc:creator>
            <pubDate>Tue, 11 Apr 2017 14:19:14 GMT</pubDate>
            <atom:updated>2018-10-04T05:37:15.053Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>MVP</strong> is one of the most used architectural patterns in Android to separate view logic from the business logic. But aside its beneficial parts he comes with some obstacles in here or there.</p><p>One obstacle in android programming and not only in <strong>MVP</strong> is fragment navigation. Is pretty hard to make the navigation pretty in code. So I make my research and found some solicitous as using <strong>Event-buss</strong>, to post on one subscribed method in <strong>Activity</strong> I needed to open some fragment or casting context to <strong>Activity’s</strong> <strong>context</strong>, but always the code seems ugly and with <strong>MVP</strong> is even uglier.</p><p>So… one day testing an <strong>MVP</strong> framework I found on <strong><em>GitHub</em></strong>, I ended with a new idea of android fragment navigation that I really liked how it the code looks I enjoyed as well.</p><p>First I added a MainActivity with his presenter as sown in below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*cQk8tY7uGLfeCIwyfg-SFA.png" /><figcaption>MVP — Activity and his Presenter</figcaption></figure><p>The diagrams are made in PlantUML, with his AndoridStudioPlugin.</p><p>A pretty simple, basic MVP pattern with his code and stuff. The same for the fragments :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*PKCMjmS8QIgWILuLojWaPw.png" /><figcaption>MVP Fragment and his Presenter</figcaption></figure><p>About the interfaces I like to keep them in another interface to group them easily:</p><pre>public interface MainActivityVP {<br>    interface View{<br>        void setFragment(BaseFragment fragment);<br>    }</pre><pre>    interface Presenter{<br>        void getRandomFragment();<br>    }<br>}</pre><p>This way is easier to find what you need.</p><p>Finally, let’s start with navigation, first, I added a BaseFragment:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*xaYwK4xKtAoTk7ZFA1GOBQ.png" /></figure><p>Then create a new interface for navigation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*ySzPC3qSxqizD7trJ_gCHQ.png" /></figure><p>Code below:</p><pre>public interface FragmentNavigation {<br>    interface View {<br>        void atachPresenter(Presenter presenter);</pre><pre>    }</pre><pre>    interface Presenter {<br>        void addFragment(BaseFragment fragment);<br>    }<br>}</pre><p>And now putting all together it looks something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*WZcJ4tsM6SGbTqVVlGGlgA.png" /></figure><p>When I drew the diagram I thought that is complicated but in code is really easy.</p><p>In the BaseFragment set the implementation of the navigation method like:</p><pre>public abstract class BaseFragment extends Fragment implements FragmentNavigation.View {</pre><pre>  <em><br>  </em><strong><em>  </em>protected FragmentNavigation.Presenter navigationPresenter;</strong></pre><pre><em>    </em>@Override<br>    public void atachPresenter(<br>                    <em>FragmentNavigation.Presenter </em><strong><em>presenter</em></strong>) {<br>      <strong>  navigationPresenter = presenter;</strong><br>    }</pre><pre>}</pre><p>Then in the MainPresenter implement the Presenter navigation logic:</p><pre>public class MainActivityPresenter implements            <br>       MainActivityVP.Presenter, <br>       FragmentNavigation.Presenter {</pre><pre><em>//...</em></pre><pre><strong>@Override<br>    public void addFragment(BaseFragment fragment) {<br>        view.setFragment(fragment);<br>    }</strong><br>}</pre><p>In the main activity just implement the logic like below:</p><pre>public class MainActivity extends AppCompatActivity implements MainActivityVP.View{</pre><pre>   //...</pre><pre><em>    </em>@Override<br>    public void setFragment(BaseFragment fragment) {<br>      <em>  //ataching to fragment the navigation presenter</em><br>       <strong> fragment.atachPresenter(presenter);</strong><br>       <em> //showing the presenter on screen</em><br>        <strong>getSupportFragmentManager()<br>                .beginTransaction()<br>                .replace(R.id.<em>fragment_container</em>,fragment)<br>                .commit();</strong><br>    }<br>}</pre><p>And that’s it, the hard part is gone, now just call the navigationPresenter and send in param field what fragment to show on screen:</p><pre>button.setOnClickListener(new View.OnClickListener() {<br>    @Override<br>    public void onClick(View v) {<br>        <strong>navigationPresenter.addFragment(new FragmentTow());</strong><br>    }<br>});</pre><p>Of course, you can explore the code on <a href="https://github.com/dsdmsa/FragmentNavigationMVP">GitHub</a> if you want to understand this better or if I didn’t explain very well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c4388f97904" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>