<?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 Hamza Aktay on Medium]]></title>
        <description><![CDATA[Stories by Hamza Aktay on Medium]]></description>
        <link>https://medium.com/@aktayhamza?source=rss-9666d1d3ed00------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WgxEV3_C9L8iMUD7eEjxnw@2x.jpeg</url>
            <title>Stories by Hamza Aktay on Medium</title>
            <link>https://medium.com/@aktayhamza?source=rss-9666d1d3ed00------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 17:19:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aktayhamza/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[“Yapay Zeka Bize Her Şeyi Verebilir… Ama Biz Neyi İstiyoruz?”]]></title>
            <link>https://medium.com/@aktayhamza/yapay-zeka-bize-her-%C5%9Feyi-verebilir-ama-biz-neyi-i%CC%87stiyoruz-f06131487473?source=rss-9666d1d3ed00------2</link>
            <guid isPermaLink="false">https://medium.com/p/f06131487473</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[einstein]]></category>
            <dc:creator><![CDATA[Hamza Aktay]]></dc:creator>
            <pubDate>Tue, 04 Feb 2025 10:38:14 GMT</pubDate>
            <atom:updated>2025-02-04T10:38:14.013Z</atom:updated>
            <content:encoded><![CDATA[<h3>“Yapay Zeka Bize Her Şeyi Verebilir… Ama Biz Neyi İstiyoruz?”<br>Dostoyevski, Einstein ve İnsanlığın Unuttuğu Soru</h3><p>Einstein, bir mektubunda şöyle diyordu:<br>“Dostoyevski bana, tüm bilim insanlarından daha fazlasını verdi.”</p><p>Bilimin sınırlarını zorlayan bir dâhi, neden bir edebiyat dehâsından bu kadar etkilenmişti?</p><p>Belki de “insanı anlamak”, verilerin ötesinde bir şey gerektiriyordu.</p><p>Yapay zeka çağındayız.<br>AI bize istediğimiz her şeyi verebilir:</p><blockquote>Daha hızlı sonuçlar<br>Daha kesin tahminler<br>Daha kusursuz optimizasyonlar</blockquote><p>Ama “basit isteklerle” sınırlı kalırsak, belki de “basit bir insanlığa” mahkûm oluruz.</p><blockquote>Dostoyevski, Karamazov Kardeşler’de şunu sorar:<br>“Eğer Tanrı yoksa, her şey mubah mı?”</blockquote><p>Bugünün sorusu belki şu olmalı:<br>“Eğer AI her şeyi yapabilirse, biz neyi talep etmeye cesaret edeceğiz?”</p><blockquote>Felsefenin bize hatırlattığı şey:<br>Teknoloji araçtır; niyetimiz ise pusula.</blockquote><p>AI’ya “daha çok tüketim” mi öğretiyoruz, yoksa “daha derin anlam”ı mı?<br>“Verimlilik” mi istiyoruz, yoksa “merhamet”i de kodlamayı mı?<br>“Doğru cevaplar” mı arıyoruz, yoksa “doğru sorular”ı sormayı mı?</p><p>Einstein’ın Dostoyevski’den öğrendiği şey, belki de buydu:<br>İnsanın karmaşık ruhu, denklemlerin çözemediği bir bilmece.</p><p>AI ise bize bir ayna tutuyor:<br>Ne kadar derine bakmaya hazırız?</p><blockquote>Bugünün Çağrısı:<br>Yapay zekâyı “hızlandırma aracı” olarak değil, “insanlığı derinleştirme fırsatı” olarak görelim.</blockquote><p><strong>Şirketlerde:</strong> Müşteri memnuniyeti algoritmalarına, <strong>“etik sorgulamalar”</strong> ekleyelim.<br><strong>Eğitimde:</strong> “Beceri kazandıran” AI’lara, <strong>“eleştirel düşünce”yi de</strong> öğretelim.<br><strong>Kendimizde: </strong>“Kolay olanı” değil, <strong>“anlamlı olanı” </strong>talep edelim.<br>Unutmayalım:<br>Dostoyevski, Einstein’a “bilimden fazlasını” verdi çünkü onu “insan olmanın çelişkisiyle” yüzleştirdi.</p><p>AI da bize ancak sorduğumuz kadarını verecek.</p><p><strong>Belki de asıl mesele, “neyi sormayı unuttuğumuzu” hatırlamakta.</strong></p><blockquote>İleriye koşalım, ama ruhumuzu geride bırakmadan.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f06131487473" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Multipart/Form-Data with Retrofit for Android: How to Send File Uploads and Text Data with…]]></title>
            <link>https://medium.com/@aktayhamza/using-multipart-form-data-with-retrofit-for-android-how-to-send-file-uploads-and-text-data-with-d84541506fea?source=rss-9666d1d3ed00------2</link>
            <guid isPermaLink="false">https://medium.com/p/d84541506fea</guid>
            <dc:creator><![CDATA[Hamza Aktay]]></dc:creator>
            <pubDate>Wed, 03 Apr 2024 22:31:23 GMT</pubDate>
            <atom:updated>2024-04-03T22:31:23.114Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using Multipart/Form-Data with Retrofit for Android: How to Send File Uploads and Text Data with Multipart/Form-Data</h3><p>Developers who develop mobile applications communicate with the backend through an API in various ways and exchange data. Sometimes we send information such as a user’s name, age, gender, etc., while in other scenarios we send files such as photos and images in addition to this information. Multipart/Form-Data comes to our rescue in this data transfer process, which is more complex than its original form.</p><p>What is Multipart/Form-Data?<br>Multipart/form-data allows us to send binary data and multiple data types in a single request. Using web forms, it allows users to upload files as well as text information.</p><p>Normally, when a web form is submitted, the data is sent using the application/x-www-form-urlencoded encoding type. This encoding type sends form data in name/value pairs and does not support file content. However, if a file upload is to be performed on the form, the enctype property of the form is set to multipart/form-data.</p><p>This encoding type is especially important because it can support binary data, which is required for file uploads. Multipart/form-data packages each form element and uploaded files into separate sections. Each section can contain a Content-Type header to identify the content and the file name for file uploads.</p><p><strong>How to use Multipart/Form-Data?<br></strong>Let’s use an example scenario to send data with Multipart/form-data so that what we say is not left in the air.</p><pre>@Multipart<br>    @POST(PRODUCTS)<br>    suspend fun addProduct(<br>        @Part(&quot;name&quot;) name: RequestBody,<br>        @Part(&quot;description&quot;) description: RequestBody,<br>        @Part(&quot;brandId&quot;) brandId: RequestBody,<br>        @Part(&quot;categoryId&quot;) categoryId: RequestBody,<br>        @Part(&quot;price&quot;) price: RequestBody,<br>        @Part(&quot;quantity&quot;) quantity: RequestBody,<br>        @Part(&quot;weight&quot;) weight: RequestBody,<br>        @Part(&quot;quality&quot;) quality: RequestBody,<br>        @Part attachments: List&lt;MultipartBody.Part&gt;,<br>        @Part attributes: List&lt;MultipartBody.Part&gt;,<br>    ): Response&lt;YourResponse&gt;</pre><p><strong>@Multipart<br></strong>We use the @Multipart annotation when the method needs to send text data as well as images, videos, etc. using the multipart/form-data encoding type. This annotation allows Retrofit to package the request appropriately to contain multiple parts.</p><p><strong>@Part<br></strong> @Part annotation identifies each part of our request. These parts can be form data, files or other types of content. Each parameter specified with @Part is treated as part of the request. Text or numeric data is expressed with RequestBody, while files are passed as MultipartBody.Part objects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/0*30qLnASFHuYrptgG.png" /></figure><p><strong>RequestBody<br></strong>RequestBody represents the body of an HTTP request. This class, used by Retrofit and OkHttp, contains the data to be sent in the request body. It can carry any kind of data such as text, JSON data or file content. In this example, text-based data (e.g. name, description) are wrapped as RequestBody objects and marked with @Part annotation, thus making each one part of a multipart request.</p><p><strong>MultipartBody.Part<br></strong>MultipartBody.Part is used to send files or other large blocks of data in multipart requests. It can contain information such as the contents of a file (a byte array), the media type (for example, “image/jpeg”) and the file name. This object can contain file data as well as other complex data types, each of which is included as part of the multipart request with the @Part annotation.</p><p>This structure allows various types of data to be sent to an API together, including files and text data. Using these annotations and classes, Retrofit automatically packages the data to be sent in the appropriate multipart/form-data format and forwards it to the server. This allows developers to easily create and manage complex HTTP requests.</p><p>In the RepositoryImpl section, a classic Repository is created after the data submission process;</p><p>attachments.map { … }: Each file selected by the user (given as a list of Uri) is processed with the map function. Each Uri is converted into a file path and then the contents of that file are translated into a byte array using openInputStream. The resulting byte array is converted into a RequestBody object with toRequestBody and made into a multipart part with MultipartBody.Part.createFormData. This part is prepared to be sent to the server under the name attachments.</p><p><strong>Preparation of Specifications<br></strong>attributes.mapIndexed { index, value -&gt; … }: Each attribute (product properties) is processed through pairs of index and value. The attributes are prepared as a string in JSON format and each one is packaged as a multipart fragment with the name attributes[index] to be sent to the server.</p><p><strong>API Call and Request Submission<br></strong>safeApiCall { … }: This function performs the API call within a structure that provides error handling. If an error occurs in the API call, it returns an error message. In case of a successful call, it processes the server’s response.</p><p>productService.addProduct(…): A POST request is made to the addProduct API endpoint via ProductService. This request contains product information and added files. Each text-based parameter is converted into a RequestBody object using toRequestBody and sent to the server in multipart/form-data format.</p><p>Returns Resource.Success in case of a successful request and Resource.Error in case of an error. This is used to easily manage whether the operation result was successful or not.</p><p>If you’ve read this far, all in all, this code snippet is an example of how to send file uploads and complex data structures via REST APIs in Android development. Using the power of Kotlin coroutines and Retrofit, Kotlin allows us developers to easily perform asynchronous data sending and processing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d84541506fea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android için Retrofit ile Multipart/Form-Data Kullanımı: Multipart/Form-Data ile dosya Yüklemeleri…]]></title>
            <link>https://medium.com/@aktayhamza/android-i%C3%A7in-retrofit-ile-multipart-form-data-kullan%C4%B1m%C4%B1-multipart-form-data-ile-dosya-y%C3%BCklemeleri-aea026905ced?source=rss-9666d1d3ed00------2</link>
            <guid isPermaLink="false">https://medium.com/p/aea026905ced</guid>
            <dc:creator><![CDATA[Hamza Aktay]]></dc:creator>
            <pubDate>Wed, 03 Apr 2024 22:12:54 GMT</pubDate>
            <atom:updated>2024-04-03T22:12:54.274Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Android için Retrofit ile Multipart/Form-Data Kullanımı: Multipart/Form-Data ile dosya Yüklemeleri ve Metin Verileri Nasıl Gönderilir?</strong></h3><p>Mobil uygulama geliştiren developerlar çeşitli şekillerde bir API aracılığıyla backend ile iletişime geçerek veri alışverişi yaparlar. Bazen bir kullanıcıya ait isim, yaş, cinsiyet gibi bilgiler gönderilirken bazı senaryolarda ise kullanıcı bu bilgilerinin yanında fotoğraf, resim gibi dosyalar da göndeririz. İlk haline göre daha kompleks olan bu veri transferi işleminde imdadımıza <strong>Multipart/Form-Data </strong>yetişir.</p><p><strong>Multipart/Form-Data nedir?<br></strong>Multipart/form-data, ikili verileri ve birden fazla veri türünü tek bir istekte göndermemize olanak tanır. Web formlarını kullanarak kullanıcıların metin bilgilerinin yanı sıra dosya yüklemelerini de yapabilmelerini sağlar.</p><p>Normalde, bir web formu gönderildiğinde, veri application/x-www-form-urlencoded kodlama türü kullanılarak gönderilir. Bu kodlama türü, form verilerini ad/değer çiftleri halinde gönderir ve dosya içeriğini desteklemez. Ancak, formda bir dosya yükleme işlemi gerçekleştirilecekse, formun enctype özelliği multipart/form-data olarak ayarlanır.</p><p>Bu kodlama türü, özellikle dosya yüklemeleri için gerekli olan ikili verileri destekleyebilmesi nedeniyle önemlidir. Multipart/form-data, her bir form elemanını ve yüklenen dosyaları ayrı bölümler halinde paketler. Her bölüm, içeriği tanımlamak için bir Content-Type başlığı ve dosya yüklemeleri için dosya adını içerebilir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QCdndT6t1_ULCYHn70ndkg.jpeg" /></figure><p><strong>Multipart/Form-Data nasıl kullanılır?<br></strong>Söylediklerimizin havada kalmaması adına örnek bir senaryo üzerinden Multipart/form-data ile veri gönderme işlemini yapalım.</p><pre>@Multipart<br>    @POST(PRODUCTS)<br>    suspend fun addProduct(<br>        @Part(&quot;name&quot;) name: RequestBody,<br>        @Part(&quot;description&quot;) description: RequestBody,<br>        @Part(&quot;brandId&quot;) brandId: RequestBody,<br>        @Part(&quot;categoryId&quot;) categoryId: RequestBody,<br>        @Part(&quot;price&quot;) price: RequestBody,<br>        @Part(&quot;quantity&quot;) quantity: RequestBody,<br>        @Part(&quot;weight&quot;) weight: RequestBody,<br>        @Part(&quot;quality&quot;) quality: RequestBody,<br>        @Part attachments: List&lt;MultipartBody.Part&gt;,<br>        @Part attributes: List&lt;MultipartBody.Part&gt;,<br>    ): Response&lt;YourResponse&gt;</pre><h3>@Multipart</h3><p>@Multipart anotasyonunu, metodun multipart/form-data kodlama türünü kullanarak resim, video gibi verilerin yanı sıra metin verilerinin de gönderilmesi gerektiğinde kullanıyoruz. Bu anotasyon, Retrofit&#39;in isteği, birden fazla parça içerecek şekilde uygun bir biçimde paketlemesini sağlar.</p><h3>@Part</h3><ul><li>@Part anotasyonu, isteğimizin her bir bölümünü tanımlar. Bu bölümler, form verileri, dosyalar veya diğer türde içerikler olabilir. @Part ile belirtilen her parametre, isteğin bir parçası olarak işlenir. Metin veya sayısal veriler RequestBody ile ifade edilirken, dosyalar MultipartBody.Part nesneleri olarak iletilir.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*zMGCt0IbjOgVBtRhwSUhfQ.png" /></figure><h3>RequestBody</h3><ul><li>RequestBody bir HTTP isteğinin gövdesini temsil eder. Retrofit ve OkHttp tarafından kullanılan bu sınıf, istek gövdesinde gönderilecek verileri içerir. Metin, JSON verisi veya dosya içeriği gibi her türlü veriyi taşıyabilir. Bu örnekte, metin bazlı veriler (örneğin name, description) RequestBody nesneleri olarak sarılarak @Part anotasyonu ile işaretlenmiş ve böylece her biri multipart isteğin bir parçası haline getirilmiştir.</li></ul><h3>MultipartBody.Part</h3><ul><li>MultipartBody.Part ise, çok parçalı isteklerde dosyaları veya diğer büyük veri bloklarını göndermek için kullanılır. Bir dosyanın içeriği (byte dizisi), medya türü (örneğin, &quot;image/jpeg&quot;) ve dosya adı gibi bilgileri içerebilir. Bu nesne, dosya verilerinin yanı sıra diğer karmaşık veri türlerini de içerebilir ve her biri @Part anotasyonu ile multipart isteğin bir parçası olarak eklenir.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k09k3o0EJeyczhKwAa7DsQ.jpeg" /></figure><p>Bu yapı, bir API’ye dosyalar ve metin verileri dahil olmak üzere çeşitli veri türlerinin birlikte gönderilmesine olanak tanır. Retrofit, bu anotasyonları ve sınıfları kullanarak, gönderilecek verileri uygun multipart/form-data formatında otomatik olarak paketler ve sunucuya iletir. Bu sayede, geliştiriciler karmaşık HTTP isteklerini kolaylıkla oluşturabilir ve yönetebilirler.</p><p>Veri gönderme işleminin devamında klasik bir Repository oluşumunun ardından RepositoryImpl kısmında ise;</p><pre>override suspend fun addProduct(<br>        name: String,<br>        description: String,<br>        brandId: Int,<br>        categoryId: Int,<br>        price: Double,<br>        quantity: Int,<br>        weight: Double,<br>        quality: Int,<br>        attachments: List&lt;Uri&gt;,<br>        attributes: List&lt;SelectedValue&gt;,<br>    ): Resource&lt;YourResponse&gt; {<br>        val fileList = attachments.map {<br>            val file = File(it.toString())<br>            val requestFile =<br>                context.applicationContext.contentResolver.openInputStream(it).use { inputStream -&gt;<br>                    inputStream?.readBytes()?.toRequestBody(&quot;image/*&quot;.toMediaTypeOrNull())<br>                } ?: return Resource.Fail(R.string.error_title)<br><br>            MultipartBody.Part.createFormData(&quot;attachments&quot;, file.name, requestFile)<br>        }<br><br>        val attributeList = attributes.mapIndexed { index, value -&gt;<br>            val attributeJson = StringBuilder().apply {<br>                append(&quot;{&quot;)<br>                append(&quot;\&quot;variantId\&quot;:${value.id},&quot;)<br>                append(&quot;\&quot;variantValueId\&quot;:${value.valueId}&quot;)<br>                append(&quot;}&quot;)<br>            }.toString()<br>            MultipartBody.Part.createFormData(&quot;attributes[$index]&quot;, attributeJson)<br>        }<br><br>        return safeApiCall {<br>            productService.addProduct(<br>                name = name.toRequestBody(&quot;text/plain&quot;.toMediaTypeOrNull()),<br>                description = description.toRequestBody(&quot;text/plain&quot;.toMediaTypeOrNull()),<br>                brandId = brandId.toString().toRequestBody(&quot;text/plain&quot;.toMediaTypeOrNull()),<br>                categoryId = categoryId.toString().toRequestBody(&quot;text/plain&quot;.toMediaTypeOrNull()),<br>                price = price.toString().toRequestBody(&quot;text/plain&quot;.toMediaTypeOrNull()),<br>                quantity = quantity.toString().toRequestBody(&quot;text/plain&quot;.toMediaTypeOrNull()),<br>                weight = weight.toString().toRequestBody(&quot;text/plain&quot;.toMediaTypeOrNull()),<br>                quality = quality.toString().toRequestBody(&quot;text/plain&quot;.toMediaTypeOrNull()),<br>                attributes = attributeList,<br>                attachments = fileList<br>            )<br>        }<br>    }</pre><p>attachments.map { ... }: Kullanıcı tarafından seçilen her bir dosya (Uri listesi olarak verilir), map işlevi ile işlenir. Her Uri, bir dosya yoluna dönüştürülür ve ardından bu dosyanın içeriği openInputStream kullanılarak byte dizisine çevrilir. Elde edilen byte dizisi, toRequestBody ile bir RequestBody nesnesine dönüştürülür ve MultipartBody.Part.createFormData ile multipart bir parça haline getirilir. Bu parça, attachments ismi altında sunucuya gönderilmek üzere hazırlanır.</p><h3>Özelliklerin Hazırlanması</h3><p>attributes.mapIndexed { index, value -&gt; ... }: Her bir attribute (ürün özellikleri), index ve değer çiftleri üzerinden işlenir. Özellikler, JSON formatında bir string olarak hazırlanır ve her biri attributes[index] ismiyle multipart bir parça olarak sunucuya gönderilmek üzere paketlenir.</p><h3>API Çağrısı ve İstek Gönderme</h3><ul><li>safeApiCall { ... }: Bu fonksiyon, hata yönetimi sağlayan bir yapı içerisinde API çağrısını gerçekleştirir. Eğer API çağrısında bir hata oluşursa, bir hata mesajı döndürür. Başarılı bir çağrı durumunda ise, sunucunun yanıtını işler.</li><li>productService.addProduct(...): ProductService üzerinden addProduct API endpoint&#39;ine bir POST isteği yapılır. Bu istek, ürün bilgileri ve eklenen dosyaları içerir. Her bir metin bazlı parametre, toRequestBody kullanılarak bir RequestBody nesnesine dönüştürülür ve multipart/form-data formatında sunucuya gönderilir.</li><li>Başarılı bir istek durumunda Resource.Success, hata durumunda ise Resource.Error döner. Bu, işlem sonucunun başarılı olup olmadığını kolayca yönetebilmek için kullanılır.</li></ul><p>Eğer buraya kadar okuduysanız tüm bunların sonucunda bu kod parçası, Android geliştirme sürecinde dosya yüklemeleri ve karmaşık veri yapılarının REST API’ler üzerinden nasıl gönderileceğini gösteren bir örnektir. Kotlin coroutines ve Retrofit’in gücünü kullanarak, biz developerların asenkron olarak veri gönderme ve işleme işlevlerini kolayca gerçekleştirmesine olanak tanır.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aea026905ced" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to pass data between fragments? Using setFragmentResult]]></title>
            <link>https://medium.com/@aktayhamza/how-to-pass-data-between-fragments-using-setfragmentresult-5a98952d4a9f?source=rss-9666d1d3ed00------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a98952d4a9f</guid>
            <dc:creator><![CDATA[Hamza Aktay]]></dc:creator>
            <pubDate>Thu, 29 Feb 2024 15:10:54 GMT</pubDate>
            <atom:updated>2024-02-29T15:10:54.082Z</atom:updated>
            <content:encoded><![CDATA[<p>While working on an android project, we often pass data between fragments. Sometimes while pass id between two fragments, sometimes we want to get a string and print the string we get to a field in the other fragment. In this context, setFragmentResult comes to our rescue and helps us move data cleanly.</p><p>In particular, we will focus on how to perform dynamic filtering based on user selections in a product addition scenario.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*Qx0-9GN0ufCea1D0.png" /><figcaption>developer.android.com</figcaption></figure><p><strong>Example Scenario: Dynamic Filtering on Product Add Page<br></strong>In an e-commerce application, we want to enable users to apply various filters (gender, brand, color, etc.) when adding products. These filters should be dynamically updated according to user selections. This is where setFragmentResult and setFragmentResultListener come into play.</p><p><strong>Dynamic Data Listening with setFragmentResultListener<br></strong>In AddProductFragment, we use setFragmentResultListener to listen for user selections. This allows us to take this information when the user selects a filter and perform the corresponding operations in our ViewModel.</p><pre>setFragmentResultListener(&quot;AddProduct&quot;) { _, bundle -&gt;<br>    bundle.getInt(&quot;selectedGenderId&quot;, -1).takeIf { it != -1 }?.let { selectedGenderId -&gt;<br>        viewModel.setEvent(AddProductEvent.FilterSubChildIdSelected(selectedGenderId))<br>    }<br><br>    bundle.getString(&quot;selectedGender&quot;)?.let {<br>        viewModel.setEvent(AddProductEvent.FilterSubChildSelected(it))<br>    }<br><br>    bundle.getInt(&quot;selectedBrandId&quot;, -1).takeIf { it != -1 }?.let {<br>        viewModel.setEvent(AddProductEvent.FilterBrandIdSelected(it))<br>    }<br><br>    bundle.getString(&quot;selectedBrandName&quot;)?.let {<br>        viewModel.setEvent(AddProductEvent.FilterBrandNameSelected(it))<br>    }<br><br>    bundle.getParcelable&lt;SelectedValue&gt;(&quot;selectedAttribute&quot;)?.let {<br>        viewModel.setEvent(AddProductEvent.FilterValueSelected(it))<br>    }<br><br>    bundle.getString(&quot;selectedColorName&quot;)?.let {<br>        viewModel.setEvent(AddProductEvent.FilterColorNameSelected(it))<br>    }<br><br>    bundle.getString(&quot;selectedSizeName&quot;)?.let {<br>        viewModel.setEvent(AddProductEvent.FilterSizeNameSelected(it))<br>    }<br>}</pre><p><strong>Send Data from ViewModel to Fragment<br></strong>When the user selects a brand, setFragmentResult is used to send this selection and the corresponding ID back to AddProductFragment. This is important so that user selections can be used in the next step.</p><pre>private fun collectEffect() {<br>    viewModel.effect.collect(viewLifecycleOwner) { effect -&gt;<br>        when (effect) {<br>            is FilterBrandEffect.ShowError -&gt; handleError(effect.throwable)<br>            FilterBrandEffect.GoToBack -&gt; onBackClicked()<br>            is FilterBrandEffect.GoToBackWithBrand -&gt; {<br>                setFragmentResult(<br>                    &quot;AddProduct&quot;,<br>                    bundleOf(<br>                        &quot;selectedBrandName&quot; to effect.brandName,<br>                        &quot;selectedBrandId&quot; to effect.brandId<br>                    )<br>                )<br>                onBackClicked()<br>            }<br>        }<br>    }<br>}</pre><p>Extra resources:<strong><br></strong><a href="https://developer.android.com/guide/fragments/communicate">developer.android.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a98952d4a9f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fragmentlar arası veri taşıma nasıl yapılır? setFragmentResult kullanımı]]></title>
            <link>https://medium.com/@aktayhamza/fragmentlar-aras%C4%B1-veri-ta%C5%9F%C4%B1ma-nas%C4%B1l-yap%C4%B1l%C4%B1r-setfragmentresult-kullan%C4%B1m%C4%B1-3d921eeea696?source=rss-9666d1d3ed00------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d921eeea696</guid>
            <category><![CDATA[setfragmentresultlistener]]></category>
            <category><![CDATA[setfragmetresult]]></category>
            <category><![CDATA[fragments]]></category>
            <category><![CDATA[pass-data-fragment]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Hamza Aktay]]></dc:creator>
            <pubDate>Thu, 29 Feb 2024 15:02:16 GMT</pubDate>
            <atom:updated>2024-02-29T15:05:13.220Z</atom:updated>
            <content:encoded><![CDATA[<p>Herkese selamlar uzun süredir bu platformda yazı yazmak için karar almış fakat bir türlü hayata geçirmeye fırsatım olmamıştı. Ta ki bu güne kadar :)</p><p>Platformdaki ilk yazım olan <strong>setFragmentResult ve setFragmentResultListener kullanarak veri taşıma</strong> ile sizlerleyim.</p><p>Bir android projesinde çalışırken çoğu zaman fragmentlar arası veri taşıma yaparız. Bazen iki fragment arasında id taşıma yaparken bazen de bir string alır ve diğer fragmenttaki bir alana getirdiğimiz stringi basmak isteriz. Bu kapsamda setFragmentResult imdadımıza yetişerek temiz bir şekilde veri taşımamıza yardımcı olur.</p><p>Özellikle, bir ürün ekleme senaryosunda, kullanıcı seçimlerine dayalı olarak dinamik filtreleme işlemlerini nasıl gerçekleştireceğimize odaklanacağız.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vJ8RK2xJh8uLV4sC.png" /><figcaption>developer.android.com</figcaption></figure><h3>Örnek Senaryo: Ürün Ekleme Sayfasında Dinamik Filtreleme</h3><p>Bir e-ticaret uygulamasında, kullanıcıların ürün eklerken çeşitli filtreler (cinsiyet, marka, renk vb.) uygulayabilmelerini sağlamak istiyoruz. Bu filtreler, kullanıcı seçimlerine göre dinamik olarak güncellenmelidir. İşte bu noktada setFragmentResult ve setFragmentResultListener devreye girer.</p><h3>setFragmentResultListener ile Dinamik Veri Dinleme</h3><p>AddProductFragment içinde, kullanıcı seçimlerini dinlemek için setFragmentResultListener kullanıyoruz. Bu, kullanıcı bir filtre seçtiğinde, bu bilgileri alıp ViewModel&#39;imizde ilgili işlemleri gerçekleştirmemize olanak tanır.</p><pre>setFragmentResultListener(&quot;AddProduct&quot;) { _, bundle -&gt;<br>    // Cinsiyet filtresi<br>    bundle.getInt(&quot;selectedGenderId&quot;, -1).takeIf { it != -1 }?.let { selectedGenderId -&gt;<br>        viewModel.setEvent(AddProductEvent.FilterSubChildIdSelected(selectedGenderId))<br>    }<br><br>    bundle.getString(&quot;selectedGender&quot;)?.let {<br>        viewModel.setEvent(AddProductEvent.FilterSubChildSelected(it))<br>    }<br><br>    // Marka filtresi<br>    bundle.getInt(&quot;selectedBrandId&quot;, -1).takeIf { it != -1 }?.let {<br>        viewModel.setEvent(AddProductEvent.FilterBrandIdSelected(it))<br>    }<br><br>    bundle.getString(&quot;selectedBrandName&quot;)?.let {<br>        viewModel.setEvent(AddProductEvent.FilterBrandNameSelected(it))<br>    }<br><br>    // Diğer filtreler<br>    bundle.getParcelable&lt;SelectedValue&gt;(&quot;selectedAttribute&quot;)?.let {<br>        viewModel.setEvent(AddProductEvent.FilterValueSelected(it))<br>    }<br><br>    bundle.getString(&quot;selectedColorName&quot;)?.let {<br>        viewModel.setEvent(AddProductEvent.FilterColorNameSelected(it))<br>    }<br><br>    bundle.getString(&quot;selectedSizeName&quot;)?.let {<br>        viewModel.setEvent(AddProductEvent.FilterSizeNameSelected(it))<br>    }<br>}</pre><h3>ViewModel’den Fragment’a Veri Gönderimi</h3><p>Kullanıcı bir marka seçtiğinde, bu seçimi ve ilgili ID’yi AddProductFragment&#39;a geri göndermek için setFragmentResult kullanılır. Bu, kullanıcı seçimlerinin bir sonraki adımda kullanılabilmesi için önemlidir.</p><pre>private fun collectEffect() {<br>    viewModel.effect.collect(viewLifecycleOwner) { effect -&gt;<br>        when (effect) {<br>            is FilterBrandEffect.ShowError -&gt; handleError(effect.throwable)<br>            FilterBrandEffect.GoToBack -&gt; onBackClicked()<br>            is FilterBrandEffect.GoToBackWithBrand -&gt; {<br>                setFragmentResult(<br>                    &quot;AddProduct&quot;,<br>                    bundleOf(<br>                        &quot;selectedBrandName&quot; to effect.brandName,<br>                        &quot;selectedBrandId&quot; to effect.brandId<br>                    )<br>                )<br>                onBackClicked()<br>            }<br>        }<br>    }<br>}</pre><p><strong>Ekstra kaynak:</strong></p><p><a href="https://developer.android.com/guide/fragments/communicate">developer.android.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d921eeea696" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>