<?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 Dmitry Marinin on Medium]]></title>
        <description><![CDATA[Stories by Dmitry Marinin on Medium]]></description>
        <link>https://medium.com/@436910463q?source=rss-b529891bd48d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*33QdotLdB_yJIjorMHYNKQ.jpeg</url>
            <title>Stories by Dmitry Marinin on Medium</title>
            <link>https://medium.com/@436910463q?source=rss-b529891bd48d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 05:58:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@436910463q/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[UICollectionView With Autosizing Cells Based on Texts or Images]]></title>
            <link>https://medium.com/better-programming/uicollectionview-with-autosizing-cell-based-on-items-text-image-814cc0e93302?source=rss-b529891bd48d------2</link>
            <guid isPermaLink="false">https://medium.com/p/814cc0e93302</guid>
            <category><![CDATA[uicollectionview]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[autolayout]]></category>
            <category><![CDATA[custom-layout]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Dmitry Marinin]]></dc:creator>
            <pubDate>Mon, 15 Jul 2019 17:51:01 GMT</pubDate>
            <atom:updated>2019-07-20T13:22:27.466Z</atom:updated>
            <content:encoded><![CDATA[<h4>Source code and an explanation for resizing cell height</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_qmBczD1HjiLKR9OV-z9nA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@pemmax?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Przemyslaw Marczynski</a> on <a href="https://unsplash.com/search/photos/ios?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><em>Note: This method has been tested on iOS versions above 12 using base SDK</em></p><p>You’ve likely used the default flow layout — a layout class provided by UIKit which consists of a basic grid layout with some customizations — but you can also implement your own custom layouts to arrange the views any way you like. This is what makes the collection view so flexible and powerful.</p><p>Or maybe you’ve used Auto Layout and added<strong> </strong>constraints<strong> </strong>to the width of a cell or maybe from the last element in a cell to bottom anchor cell.</p><h4>Introduction</h4><p>In this piece, I’ll talk about resizing cells using a <em>Custom View Layout</em><strong>. </strong>I was thinking about how to make cells as versatile as possible so that they depend entirely on the data that we put there, for example, a picture or text. Since everything is much easier with a picture, we can recognize its height from the properties, such as UIImageView.size.height, but text is much more complicated, as it depends on the type of font, the number of cells in a line, margins, and padding. Because we “hardcoded<em>”</em> cell height, I decided to make my customLayout cache cell attributes when building them. Let’s get started!</p><h3>Creating Custom Collection View Layouts</h3><p>Your first step in creating a stunning collection view is to create a custom layout class for your items.</p><p>After we create a class that implements UICollectionViewLayout, in this case, AdaptiveCollectionLayout, add it to collectionView in xCode. If you build and run your app, you’ll see an empty collection view. This is a good sign, believe it or not. This means the collection view is using your custom layout class. The cells aren’t shown yet because the AdaptiveCollectionLayout class doesn’t yet implement any of the methods involved in the layout process.</p><h3>Core Layout Process</h3><p>Take a moment to think about the collection view layout process, which is a collaboration between the collection view and the layout object. When the collection view needs layout information, it asks your layout object to provide it by calling certain methods in a specific order:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*yqohckgJwOeWN5og.png" /></figure><p>Your layout subclass must implement the following methods:</p><ul><li>collectionViewContentSize: This method returns the width and height of the collection view’s contents. You must override it, then return the height and width of the entire collection view’s content — not just the visible content. The collection view uses this information internally to configure its scroll view’s content size.</li><li>prepare(): This method is called whenever a layout operation is about to take place. It’s your opportunity to prepare and perform any calculations required to determine the collection view’s size and the position of the items.</li><li>layoutAttributesForElements(in:): In this method, you need to return the layout attributes for all the items inside the given rectangle. You return the attributes to the collection view as an array of UICollectionViewLayoutAttributes.</li><li>layoutAttributesForItem(at:): This method provides on-demand layout information to the collection view. You need to override it and return the layout attributes for the item at the requested indexPath.</li></ul><p>Okay, so you know what you need to implement — but how do you go about calculating these attributes?</p><h3>Calculating Layout Attributes</h3><p>For this layout, you need to dynamically calculate the height of every item since you don’t know what the height of the photo or how much the text will be in advance. We’ll declare a protocol that will provide this information when AdaptiveCollectionLayout needs it.</p><p>This code declares the AdaptiveCollectionLayoutDelegate protocol, which has a method to request the height of the cell. You’ll implement this protocol in YourViewController shortly.</p><p>There’s just one more thing to do before implementing the layout methods; you need to declare some properties that will help with the layout process.</p><blockquote>Before we start. Let’s create a Config swift file for define properties in which one based structure</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3792e76750b52b96f1c87e6e800f23e/href">https://medium.com/media/a3792e76750b52b96f1c87e6e800f23e/href</a></iframe><p>We calculate the attributes for the collection view items, which for now will consist of the frame. To understand how this works, take a look at the following diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*NhepxOFtS5wfedqB.png" /></figure><p>We’ll calculate the frame of every item based on its column (tracked by xOffset) and the position of the previous item in the same column (tracked by yOffset).</p><p>To calculate the horizontal position, we’ll use the starting X coordinate of the column the item belongs to and then add the cell padding. The vertical position is the starting position of the prior item in that column, plus the height of that prior item. The overall item height is the sum of the image height and the content padding.</p><p>You’ll do this in prepare(), where we calculate an instance of UICollectionViewLayoutAttributes for every item in the layout.</p><p><em>NOTE: Check the comments in the code.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d323383b9d158e7913b0c3dea1f3740d/href">https://medium.com/media/d323383b9d158e7913b0c3dea1f3740d/href</a></iframe><p>Before you can see your layout in action, you need to implement the layout delegate. For exampleMyCollectionAdapter relies upon this to provide text annotation heights when calculating the height of an attribute&#39;s frame.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38a9d26ab83dcb89d6d3b5f7e8a206bd/href">https://medium.com/media/38a9d26ab83dcb89d6d3b5f7e8a206bd/href</a></iframe><blockquote>Note: Don’t forget to add delegate for your layout</blockquote><p>Time to see how things are shaping up! Build and run your app. You’ll see the cells are properly positioned and sized based on the length of the text:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*xwXVdxkn5YNQKzCL-qkYIw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=814cc0e93302" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/uicollectionview-with-autosizing-cell-based-on-items-text-image-814cc0e93302">UICollectionView With Autosizing Cells Based on Texts or Images</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sending Files Between Devices Has Never Been Easier]]></title>
            <link>https://medium.com/better-programming/sending-files-between-devices-has-never-been-easer-wifi-direct-open-source-8337a54e8497?source=rss-b529891bd48d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8337a54e8497</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Dmitry Marinin]]></dc:creator>
            <pubDate>Wed, 11 Apr 2018 19:55:43 GMT</pubDate>
            <atom:updated>2019-07-22T12:53:21.526Z</atom:updated>
            <content:encoded><![CDATA[<h4>Wi-Fi Direct open source</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*-Rgk51wJccHXTK1l_merxw.jpeg" /></figure><h3>Introduction</h3><p>Have you ever tried to transfer data between two or more devices? Usually, we use clouds and other ways to transfer data, which require the internet. In android version 4.0, there was a feature that was supposed to change the world. It was called Wi-Fi Direct. Unfortunately, this did not happen, as the algorithm was too hard and it wasn’t user friendly enough. I decided to change the situation by using P2P technology. There are many messengers in Google Play or GitHub.</p><p>At the moment, all the apps in Google Play that help you transfer files either only function inside your local network by FTP or you would have to create a hotspot, e.g. SHAREit, or use a P2P protocol. But normally something unexpected happens. My app is on <a href="https://github.com/YaphetS1/WiFi-Direct-File-Transfer-App">GitHub</a> and on <a href="https://play.google.com/store/apps/details?id=com.app.wi_fi_direct">Google Play</a>. Here is <a href="https://www.youtube.com/watch?v=NezpvBeRgrw&amp;t=1s">a demo</a> of how it works with various devices.</p><p>Before we start:</p><h4><strong>Recommended Reading</strong></h4><p><a href="http://developer.android.com/guide/topics/connectivity/wifip2p.html">General Overview</a><br><a href="http://developer.android.com/training/connect-devices-wirelessly/nsd-wifi-direct.html">Service Discovery</a><br><a href="http://www.drjukka.com/blog/wordpress/?p=95">Power Consumption</a><br><a href="http://www.drjukka.com/blog/wordpress/?p=81">More Recommended Reading</a></p><h3>Let’s Begin</h3><p>I had the following tasks:</p><ul><li>Show me a list of nearby devices.</li><li>Manage connecting, disconnecting, and reconnecting devices.</li><li>Send messages between devices that are connected to you in order to verify it (unavailable in the official API Android).</li><li>Share multiple files to both connected devices.</li><li>Being able to visualize what are you sending and receiving and being able to open the received files without disconnecting</li><li>Automatic restart of the server that is responsible for receiving files and device information</li></ul><p>I will add my code (FileActivity) with comments, and there you will be able to see the specific methods that I use hence sending and receiving files and all other functions as well as a design working as one Activity. That’s a compelled action as the main goal is to send and receive files at the same time without a repeated initialization WifiP2PManager etc.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74441be50d927eb2a909a658bb59b12a/href">https://medium.com/media/74441be50d927eb2a909a658bb59b12a/href</a></iframe><p>Let’s look at a specific task called FileServerAsynck:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5b469ec601a4e920b3b5d2f7258e9b8/href">https://medium.com/media/e5b469ec601a4e920b3b5d2f7258e9b8/href</a></iframe><p>And TransferData:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/026e01d8c289b98277f7635ce2fde5a8/href">https://medium.com/media/026e01d8c289b98277f7635ce2fde5a8/href</a></iframe><p>As we see, the file transfer is simultaneous and synchronized. Therefore in the future, I’d have to change the code in order to split the file before sending it.</p><h3>What Needs to Be Done:</h3><ul><li>Change sending and receiving of files from simultaneous and synchronized to desynchronized.</li><li>The current version does not allow transfer of a file larger than 60mb.</li><li>A connection between a larger amount of devices (currently only two)</li><li>Etc.</li></ul><p>The full code is available for you to see on my GitHub, <a href="https://github.com/YaphetS1/WiFi-Direct-File-Transfer-App">wifi-file-transfer</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8337a54e8497" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/sending-files-between-devices-has-never-been-easer-wifi-direct-open-source-8337a54e8497">Sending Files Between Devices Has Never Been Easier</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>