<?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 Atif Mukhtiar on Medium]]></title>
        <description><![CDATA[Stories by Atif Mukhtiar on Medium]]></description>
        <link>https://medium.com/@atifmukhtar?source=rss-f4d15e0bd240------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*J7JOCuN997xiiW0ipwytDg.jpeg</url>
            <title>Stories by Atif Mukhtiar on Medium</title>
            <link>https://medium.com/@atifmukhtar?source=rss-f4d15e0bd240------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 22:13:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@atifmukhtar/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[MVVM JAVA (Model View View Model) + LiveData]]></title>
            <link>https://medium.com/@atifmukhtar/mvvm-java-model-view-view-model-livedata-148475d7f383?source=rss-f4d15e0bd240------2</link>
            <guid isPermaLink="false">https://medium.com/p/148475d7f383</guid>
            <category><![CDATA[mvvm]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[livedata]]></category>
            <category><![CDATA[viewmodel]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Atif Mukhtiar]]></dc:creator>
            <pubDate>Thu, 29 Aug 2019 02:45:37 GMT</pubDate>
            <atom:updated>2019-08-29T03:26:00.939Z</atom:updated>
            <content:encoded><![CDATA[<h3>MVVM JAVA (Model View View-Model) + LiveData</h3><p>Simplest, as it can be! It&#39;s really easy to understand what is MVVM in words. But most of the people have made it really hard to understand it in coding or implement.</p><p>I will start with one to two line of introduction of each and then we will start coding and understanding of the concept. I will provide google code as a reference too at the end.</p><blockquote><strong>View:</strong> The part of the App which the user sees, interact with or touches on the screen. In other words, A view can do what activity or Fragments can do. You can call it Activity JAVA class as a view. we will update the views in activity. <strong>No Bussiness logic!</strong></blockquote><blockquote><strong>View Model: </strong>We write our business logic in it and provide the finest data to the Activity for the XML views using Observer/LiveData.</blockquote><blockquote><strong>Model: </strong>It is a simple java class same as POJO class.</blockquote><p><strong>Note:</strong> A view can have many View-Models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*NPM-ycYLnu2yM8zb55WVjw.png" /><figcaption>One to many relationships</figcaption></figure><p><strong>Step 1:</strong> add a dependency in Gradle.<br><em>implementation </em><strong><em>‘android.arch.lifecycle:extensions:1.1.1’</em><br></strong>for<strong> </strong>ViewModelProviders and Observer.</p><p><strong>Step2: XML</strong></p><pre><em>&lt;?</em><strong>xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;</strong><em>?&gt;<br></em>&lt;<strong>LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    android:gravity=&quot;center&quot;<br>    android:orientation=&quot;vertical&quot;</strong>&gt;<br><br><br>    &lt;<strong>Button<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:onClick=&quot;buttonPress&quot;<br>        android:text=&quot;Update View&quot; </strong>/&gt;<br><br>    &lt;<strong>TextView<br>        android:id=&quot;@+id/txtView_email&quot;<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:hint=&quot;Email&quot; </strong>/&gt;<br><br>    &lt;<strong>TextView<br>        android:id=&quot;@+id/txtView_pass&quot;<br>        android:layout_width=&quot;wrap_content&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        android:hint=&quot;Pass&quot; </strong>/&gt;<br><br><br>&lt;/<strong>LinearLayout</strong>&gt;</pre><p><strong>Step3: </strong>Model</p><pre><strong>public class </strong>User {<br>    <strong>private </strong>String <strong>email</strong>;<br>    <strong>private </strong>String <strong>password</strong>;<br><br><br>    <strong>public </strong>String getEmail() {<br>        <strong>return email</strong>;<br>    }<br><br>    <strong>public void </strong>setEmail(String email) {<br>        <strong>this</strong>.<strong>email </strong>= email;<br>    }<br><br>    <strong>public </strong>String getPassword() {<br>        <strong>return password</strong>;<br>    }<br><br>    <strong>public void </strong>setPassword(String password) {<br>        <strong>this</strong>.<strong>password </strong>= password;<br>    }<br>}</pre><p><strong>Step 4:</strong></p><pre><strong>public class </strong>LoginViewModel <strong>extends </strong>ViewModel {<br><br>    <strong>private </strong>MutableLiveData&lt;User&gt; <strong>userObject</strong>;<br><br>    <strong>public </strong>LoginViewModel() {<br>        <strong>userObject </strong>= <strong>new </strong>MutableLiveData&lt;&gt;();<br>    }<br><br>    <strong>public </strong>LiveData&lt;User&gt; getUserObject() {<br>        <strong>return userObject</strong>;<br>    }<br><br>    <strong>public void </strong>doAction() {<br>        User user = <strong>new </strong>User();<br>        user.setEmail(<strong>&quot;atif.mukhtar1992@gmail.com&quot;</strong>);<br>        user.setPassword(<strong>&quot;1234&quot;</strong>);<br>        <strong>userObject</strong>.setValue(user);<br>    }<br><br>}</pre><p>Step 5: Activity updating the view.</p><pre><strong>public class </strong>MainActivity <strong>extends </strong>AppCompatActivity {<br>    <br>    MainActivity <strong>context</strong>;<br>    LoginViewModel <strong>model</strong>;<br>    <br>    @Override<br>    <strong>protected void </strong>onCreate(Bundle savedInstanceState) {<br>        <strong>super</strong>.onCreate(savedInstanceState);<br>        setContentView(R.layout.<strong><em>activity_main</em></strong>);<br>        <strong>context </strong>= <strong>this</strong>;<br>        <strong>model </strong>= ViewModelProviders.<em>of</em>(<strong>context</strong>).get(LoginViewModel.<strong>class</strong>);<br>        <strong>model</strong>.getUserObject().observe(<strong>context</strong>, <strong>userObjectObserver</strong>);<br>    }<br><br><br>    <strong>private final </strong>Observer&lt;User&gt; <strong>userObjectObserver </strong>= <strong>new </strong>Observer&lt;User&gt;() {<br>        @Override<br>        <strong>public void </strong>onChanged(@Nullable <strong>final </strong>User userObject) {<br>            <em>//Update UI<br>            </em>((TextView) findViewById(R.id.<strong><em>txtView_email</em></strong>)).setText(userObject.getEmail());<br>            ((TextView) findViewById(R.id.<strong><em>txtView_pass</em></strong>)).setText(userObject.getPassword());<br>            Toast.<em>makeText</em>(<strong>context</strong>, <strong>&quot;Email : &quot; </strong>+ userObject.getEmail() + <strong>&quot;\nPassword : &quot; </strong>+ userObject.getPassword(), Toast.<strong><em>LENGTH_SHORT</em></strong>).show();<br>        }<br>    };<br>    <br>    <strong>public void </strong>buttonPress(View view) {<br>        <em>//populating the data in view model<br>        </em><strong>model</strong>.doAction();<br>    }<br>}</pre><p>here is the code link <a href="https://github.com/AtifMukhtiar/mvvm_livedata">MVVM_LIVEDATA</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=148475d7f383" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Image Resizing in React Native]]></title>
            <link>https://medium.com/@atifmukhtar/image-resizing-in-react-native-f8c4eb69a40d?source=rss-f4d15e0bd240------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8c4eb69a40d</guid>
            <category><![CDATA[responsive-images]]></category>
            <category><![CDATA[different-screen-sizes]]></category>
            <category><![CDATA[image-resizing]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Atif Mukhtiar]]></dc:creator>
            <pubDate>Sat, 10 Jun 2017 21:36:54 GMT</pubDate>
            <atom:updated>2018-04-28T12:55:46.668Z</atom:updated>
            <content:encoded><![CDATA[<p>It appears that it is difficult to create a same sized Views or Images for every device in React Native. So i have created a class name “ImageResizer” that has some methods which returns the height and width in pixels. Its like calculating percentages of the image on the device screen. <br>Its covers two types of devices aspect ratio<br>1) 4:3 (Resolution 2048 x 1536).<br>2) 1.6 (Resolution 2560 x 1600)</p><p>Although we have almost 4 types of aspect ratios.<br>1) 4:3 which is “1.3” (Resolution 2048 x 1536).<br>2) 16:10 which is 1.6 (Resolution 2560 x 1600)<br>3) 17:10 which is 1.7 (Resolution 1024 x 600)<br>4) 16:9 which is 1.78</p><p>So what i think covering these two types of device ratios can also solve others too because the ratios 1.6,1.7 and 1.78 have a little bit difference.</p><pre><em>/**<br> * Created by Atif Mukhtiar on 6/10/2017.<br> */<br></em><br><strong>import </strong>{<br>    Dimensions<br>}<strong>from &#39;react-native&#39;</strong>;<br><br><strong>maxCanvasWidth1600 </strong>= 1600;<br><strong>maxCanvasHeight2560 </strong>= 2560;<br><br><br><strong>maxCanvasWidth1536 </strong>= 1536;<br><strong>maxCanvasHeight2048 </strong>= 2048;<br><br><strong>export default class </strong>ImageResizer {<br>    constructor() {<br>        <strong>deviceHeight </strong>= Dimensions.<em>get</em>(<strong>&#39;window&#39;</strong>).height;<br>        <strong>deviceWidth </strong>= Dimensions.<em>get</em>(<strong>&#39;window&#39;</strong>).width;<br>    }<em>// end of constructor<br><br><br>    </em>getHeight(imgHeight) {<br>        <strong>if </strong>(<strong>this</strong>.getCurrentDeviceAspectRadio() === <strong>this</strong>.get2048DeviceAspectRatio()) {<br>            <strong>return </strong>((imgWidth / <strong>maxCanvasHeight2048</strong>) * deviceScreenWidth);<br>        } <strong>else </strong>{<br>            <strong>return </strong>((imgHeight / <strong>maxCanvasHeight2560</strong>) * <strong>deviceHeight</strong>);<br>        }<br>    }<em>// end of getHeight<br><br>    </em>getWidth(imgWidth) {<br>        <strong>if </strong>(<strong>this</strong>.getCurrentDeviceAspectRadio() === <strong>this</strong>.get2048DeviceAspectRatio()) {<br>            <strong>return </strong>((imgWidth / <strong>maxCanvasWidth1536</strong>) * <strong>deviceWidth</strong>);<br>        } <strong>else </strong>{<br>            <strong>return </strong>((imgWidth / <strong>maxCanvasWidth1600</strong>) * <strong>deviceWidth</strong>);<br>        }<br>    }<em>// end of getHeight<br><br><br>    </em>getCurrentDeviceAspectRadio() {<br>        <strong>return </strong>(<strong>deviceWidth </strong>/ <strong>deviceHeight</strong>);<br>    }<em>// end of getCurrentAspectRadio<br><br>    </em>get2048DeviceAspectRatio() {<br>        <strong>return </strong>(<strong>maxCanvasHeight2048 </strong>/ <strong>maxCanvasWidth1536</strong>);<br>    }<em>// end of getCurrentDeviceAspectRatio<br><br></em>}<em>// end of class ImageResizer</em></pre><h3>Resizing the Images</h3><p>Now giving the height, width and margins to the Views and Images.</p><pre><em>/**<br> * Created by Atif Mukhtiar on 6/10/2017.<br> */<br></em><strong>import </strong>React, {<strong>Component</strong>} <strong>from &#39;react&#39;</strong>;<br><strong>import </strong>{<br>    View,<br>    StyleSheet,<br>    Text,<br>    Image<br>}<strong>from &#39;react-native&#39;</strong>;<br><strong>import </strong>ImageResizing <strong>from &#39;../Utils/ImageResizer&#39;</strong>;<br><strong>let </strong>imageResizerObj = <strong>new </strong>ImageResizing();<br><strong>export default class </strong>Home <strong>extends Component </strong>{<br><br>    render() {<br>        <strong>return </strong>(<br>            &lt;<strong>View style=</strong>{style.<strong>mainContainer</strong>}&gt;<br><br>                &lt;<strong>View style=</strong>{style.<strong>topHeader</strong>}&gt;<br><br>                    &lt;<strong>Image style=</strong>{style.<strong>topLeftButton</strong>}<br>                           <strong>resizeMode=</strong>{<strong>&#39;contain&#39;</strong>}<br>                           <strong>source=</strong>{<em>require</em>(<strong>&#39;../assets/Images/icon_menu.png&#39;</strong>)}<br>                    &gt;<br>                    &lt;/<strong>Image</strong>&gt;<br><br>                &lt;/<strong>View</strong>&gt;<br><br><br>                &lt;<strong>Image<br>                    resizeMode=</strong>{<strong>&#39;contain&#39;</strong>}<br>                    <strong>style=</strong>{style.<strong>imgMinion</strong>}<br>                    <strong>source=</strong>{<em>require</em>(<strong>&#39;../assets/Images/img_minions.png&#39;</strong>)}<br>                &gt;&lt;/<strong>Image</strong>&gt;<br><br>            &lt;/<strong>View</strong>&gt;<br>        );<br>    }<br>}<em>// end of Home<br></em><strong>const </strong>style = StyleSheet.create({<br>    <strong>mainContainer</strong>: {<br>        <strong>flex</strong>: 1,<br>        <strong>backgroundColor</strong>: <strong>&#39;white&#39;</strong>,<br>    },<br>    <strong>topHeader</strong>: {<br>        <strong>height</strong>: imageResizerObj.getHeight(200),<br>        <strong>backgroundColor</strong>: <strong>&#39;#cecece&#39;</strong>,<br>    },<br>    <strong>topLeftButton</strong>: {<br>        <strong>height</strong>: imageResizerObj.getHeight(72),<br>        <strong>width</strong>: imageResizerObj.getWidth(110),<br>        <strong>marginTop</strong>: imageResizerObj.getHeight(60),<br>        <strong>marginLeft</strong>: imageResizerObj.getWidth(40),<br>    },<br>    <strong>imgMinion</strong>:{<br>        <strong>height</strong>:imageResizerObj.getHeight(601),<br>        <strong>width</strong>:imageResizerObj.getWidth(1591),<br>        <strong>marginLeft</strong>:imageResizerObj.getWidth(5),<br>        <strong>marginRight</strong>:imageResizerObj.getWidth(5)<br>    }<br>})<em>// end of StyleSheet Create</em></pre><h3>Screens shots of two devices</h3><p>Nexus S, Screen size 480 x 800</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*1loBqrLtUyEddsqbDxKaBQ.png" /><figcaption>Nexus S (400 x 800)</figcaption></figure><p>Nexus 5, Screen size 1080 x 1920</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VrWXip5lU4i_OXWzj9kSnA.png" /><figcaption>Nexus 5 (1080 x 1920)</figcaption></figure><p>This is it. :) Enjoy resizing :P</p><p>Please let me know if anyone wants some information or help regarding devices screen sizes their ratios etc.<br>Email : atif.mukhtar1992@gmail.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8c4eb69a40d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>