<?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 Ivan Velichkovski on Medium]]></title>
        <description><![CDATA[Stories by Ivan Velichkovski on Medium]]></description>
        <link>https://medium.com/@ivanvelickovski?source=rss-5bebfcaeeb41------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6rIJi3BXPh4WY_NHC8BShQ.jpeg</url>
            <title>Stories by Ivan Velichkovski on Medium</title>
            <link>https://medium.com/@ivanvelickovski?source=rss-5bebfcaeeb41------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 19:18:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ivanvelickovski/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[How I used Fable to create a better World Cup format]]></title>
            <link>https://medium.com/@ivanvelickovski/how-i-used-fable-to-create-a-better-world-cup-format-4b47f7df0fa0?source=rss-5bebfcaeeb41------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b47f7df0fa0</guid>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[football]]></category>
            <category><![CDATA[world-cup]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[fable]]></category>
            <dc:creator><![CDATA[Ivan Velichkovski]]></dc:creator>
            <pubDate>Fri, 17 Jul 2026 11:58:11 GMT</pubDate>
            <atom:updated>2026-07-17T11:58:11.002Z</atom:updated>
            <content:encoded><![CDATA[<p>It was a warm summer night in July and I had nothing to do.</p><p>Well actually, I had a lot to do. Chores and whatnot. But somehow also not much to do. And that is because I got used to pretending that I’m doing something, just like the rest of the world. Ever since the (FIFA) World Cup began in June I got obsessed with it (…as always).</p><p>I don’t really know what the magic behind the World Cup is, but I never fully grew out of its charm. Ever since I was a little child I was obsessed with this cup.</p><p>In the past I would collect stickers and go through the album trying to remember every single detail about each and every team in the tournament and their road towards it.</p><p>Coming from a country which never got the opportunity to play on the biggest stage, I would carefully choose my (second) favorite and preferred winner months in advance. In retrospect, I almost always settled on France (the Zidane effect) and the Netherlands (due to my obsession with Ruud van Nistelrooy, who used to be my favorite player for Manchester United). Funny how in the end I ended up relocated in the Netherlands itself.</p><p>And that brings me to today.</p><p>Now I don’t really have the time to obsess over every single football detail, and to be quite frank — I’ve somehow grown out of my love for this sport in the last few years. Perhaps it’s just my age, or I am just one of those angry (old?) guys shouting at clouds (or more probably — shouting at VAR decisions), but the fact is: rarely do I experience the thrill or the motivation to watch football for 90 minutes straight.</p><p>That is definitely not the case with the World Cup though. And I think it might be related to its cyclical nature. I tend to find these kinds of games a lot more interesting than those that are available at “all times”… as in, I know that if I skip the Champions League this year, I will still be able to watch it next year.</p><p>Somehow skipping the World Cup, or the Olympics (whichever version of them) feels the same way as if I am skipping years of my life. I’d argue that this is one of the reasons why football, and especially the World Cup is owned by the whole of humanity. I believe that all, or most of us feel something similar to what I’m describing here.</p><p>Which is why I got myself thinking how can I, or we (together), improve the World Cup (even?) further.</p><p>While getting a 48-team tournament was really cool for the inclusion of smaller and less successful national teams, some of them turning out to be quite the challengers too (looking at you, Cabo Verde! or you too — Norway, though you weren’t much of an outsider, were you?), it is also a fact that some of the duels during the group phase were not that exciting to begin with.</p><p>At first, I was pointing my finger at the extension of the format to 48 teams, but then I realized… maybe it is not the number of teams itself that is the issue.</p><p>What if we simply change the group based format to something more exciting?</p><p>What if we can use some already existing alternative which proved its worth?</p><p>So then I did what I do best: I explained my (not so) crazy idea to Fable and curiously looked at the result.</p><h3><strong>The idea, in one sentence</strong></h3><p><a href="https://world-cup-reimagined.vercel.app/">Here</a> it is, stripped of all the football-romantic packaging I’ve wrapped it in above: <strong>what if the World Cup ditched the little groups of four and played a single, giant league instead — exactly like the new UEFA Champions League format?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WXMiZgvMhoPl5UG4-yik2A.png" /><figcaption>Let’s reimagine the World Cup, together! Simulator: <a href="https://world-cup-reimagined.vercel.app/">https://world-cup-reimagined.vercel.app/</a></figcaption></figure><p>If you haven’t been paying attention to club football lately (no judgement — see above re: shouting at clouds), UEFA quietly did something rather brave a couple of seasons ago. They killed the old Champions League groups. Instead of eight cozy little tables of four, there is now <em>one</em> table of 36 teams. Everybody plays eight games against eight different opponents, everyone lands in the same standings, and where you finish decides everything — who goes straight through, who has to sweat through a play-off, who goes home.</p><p>And here is the thing… it worked. Suddenly a random Tuesday night group game between two teams you’d normally ignore actually <em>mattered</em>, because those three points moved someone up or down the one table everybody was watching.</p><p>So my (not so) crazy idea was simply: steal it. Take that shape, shrink it to fit a summer tournament, and point it at the World Cup.</p><h3><strong>Why groups are the problem (and not the 48 teams)</strong></h3><p>Let me defend my earlier finger-pointing, because I did unpoint it.</p><p>The classic group stage has a design flaw that we’ve all just… accepted. By the third and final group game, the maths has usually already spoken. Someone is safely through, someone is mathematically out, and the two of them are forced to play each other anyway while the rest of us watch what is essentially a very expensive training session. We even have a name for it — the <strong><em>dead rubber</em> </strong>— which should tell you something. When your format needs a dedicated term for “the game that doesn’t matter,” maybe the format is the problem.</p><p>Three group games also means a debutant nation — the exact kind of team the 48-team expansion was <em>supposed</em> to celebrate — can fly home after three matches, possibly without ever sharing a pitch with a genuine giant. That’s the dream cut short before it even gets going.</p><p>So no, it was never really about 48 teams. It was about the <em>shape</em> the teams were poured into.</p><h3><strong>What “the World Cup as a league” actually looks like</strong></h3><p>This is where the fun started, because talking about a format is one thing, but I wanted to <em>see</em> it. So Fable and I built it — a full, working simulator you can open in a browser and play with. More on that in a second, but first the rules we landed on.</p><p>Every nation plays <strong>four league matches</strong>, and here’s the part I’m quietly proud of — the four opponents are not random. You play one team from each strength tier:</p><blockquote>One against the elite, one against the strong, one against the hopeful, one against the dreamers.</blockquote><p>That single design choice does something the old format could never promise. It <em>guarantees</em> blockbusters. Every team, no matter how small, is handed one night against a Pot 1 giant — by design, not by luck of the draw. Brazil–France, Argentina–Spain, England–Germany in the <em>league phase</em>, weeks before a final. The old format hides its giants from each other until the semis, like it’s saving the good stuff. This one puts them out on matchday one.</p><p>All four results feed a single table of every nation on earth. Then the table decides your fate:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QW7VnW92KS3C-DKJ4hpv2A.png" /><figcaption>The new (World League) format with 32, 48 and 64 teams</figcaption></figure><p>Finish near the top and you earn a bye straight into the main bracket — because four games of consistency should <em>*count*</em> for something. Land in the middle and you drop into a play-off round: a whole extra layer of one-off, sudden-death knockout drama that today’s World Cup simply doesn’t have. And yes, the bottom of the table goes home — but having had their giant-killing shot along the way.</p><h3><strong>But how much bigger is it, really?</strong></h3><p>This is the question I expected to lose on, so let’s put the numbers on the table before anyone else does.</p><p>The real 2026 World Cup — 48 teams, twelve groups of four, best third-placed teams sneaking through — runs to <strong>104 matches</strong>. My 48-team league version runs to That’s <em>fifteen</em> extra matches. Fifteen. For that price, every nation gets a fourth game instead of a third, every nation gets a guaranteed night against a Pot 1 giant, and the whole tournament gains an entire extra knockout round.</p><p>The old 32-team World Cup, the one most of us actually grew up on, was 64 matches. The league version of the same 32 teams is 87.</p><p>I’m not going to pretend fifteen matches is nothing — it’s a longer June and more air miles, and I’ll come back to that. But when I started this I assumed the honest answer was “yes, it’s <em>much</em> bigger, sorry.” It isn’t. The group stage was never efficient. It was just short.</p><h3><strong>No more meaningless minutes</strong></h3><p>If I had to put the whole argument on a t-shirt, it would be this: <strong>a month of football should not contain a single meaningless minute.</strong></p><p>In one giant table, a late equalizer in a game you weren’t even watching can shove a completely different team out of a bye and into the play-offs. Eighth place is a free pass; ninth is an extra knockout tie you might not survive. Nothing is settled early, because nothing <em>can</em> be — there are no group standings to clinch, just one enormous standings that stays alive until the final whistle of the final matchday.</p><p>That’s the claim, anyway. The nice thing about having built the thing is that I didn’t have to leave it as a claim.</p><p>After every matchday the simulator quietly replays the entire rest of the tournament — all remaining league fixtures, then a full knockout bracket off the resulting table — a thousand times over, using the same engine the real matches use. It counts how often each nation lands a bye, survives the league, and lifts the trophy, and puts those three percentages right in the table next to the points column, with little arrows showing which way each one moved overnight.</p><p>I did not expect this to become my favorite part. But watching a team’s bye chances fall from 61% to 23% because of a goal scored in someone else’s match, on the other side of the tournament, while they weren’t even playing — that’s the whole argument, rendered as a number. “That 1–1 mattered” stops being a feeling you have to take on faith. The table just tells you how much, and to whom.</p><p>The bracket gets the same treatment: before each knockout round, five hundred simulations of everything still to come, so you always know who the machine thinks is actually winning this.</p><p>One table also does something eight little ones never could. Eight parallel group tables are homework — arithmetic you do to figure out who’s going through. <em>One</em> table of every nation on the planet is a story. The whole tournament compressed onto a single page, scanned every morning over coffee, argued about in every café from Buenos Aires to Skopje.</p><p>And the simulator writes that story out loud. After every matchday it generates newspaper headlines from what actually happened — <strong>ON THE RISE</strong> when a team leaps eight places overnight, <strong>FREE-FALL</strong> when they tumble, <strong>SURGING</strong> and <strong>FADING</strong> when the odds move hard, plus the moment a nation mathematically clinches its bye or gets mathematically eliminated. I built it as a bit of fun. It turned out to be the thing that makes a table of 48 rows feel like a tournament instead of a spreadsheet.</p><p>I should add the honest footnote, because I’m not trying to sell you a miracle: yes, it’s more matches (fifteen of them), a heavier calendar, more travel, more tired legs in June. FIFA would probably love this idea for all the wrong (commercial) reasons. I love it for the right ones.</p><h3><strong>The best part: you can actually play with it</strong></h3><p>Here’s what I find genuinely delightful about doing this in 2026 instead of scribbling it on a napkin — I didn’t have to just <em>describe</em> the format and hope you’d trust me. Fable and I turned it into a thing you can open and touch.</p><p>It’s a single web page. No install, no account, no fuss. You pick an edition — 32, 48, or 64 teams — hit the draw, and watch a whole tournament play out.</p><p>And it starts the way a World Cup is supposed to start: with a draw ceremony. The nations come out of the four pots one ball at a time, filling the bowls in front of you. You can skip it. I never skip it.</p><p>You also get to decide <em>what kind</em> of draw you want, which turned out to be a far more interesting question than I expected:</p><ul><li><strong>Balanced</strong> — after the balls come out, an optimizer quietly reshuffles the pots until every team’s four opponents add up to roughly the same difficulty. A fair draw, engineered.</li><li><strong>Pure random</strong> — the classic blind draw, in all its unfairness. Somebody always lands the best of every pot, and somebody else gets the red carpet.</li><li><strong>Chaos</strong> — exactly what it sounds like.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BHEZ1-4-0zARwEb2rnjP8w.gif" /><figcaption>The draw ceremony 👀</figcaption></figure><p>Then it grades its own work. Every draw reports a <strong>balance score</strong> out of 100, and flags the two teams that matter most: 🔥 the nation handed the toughest road, 🧊 the one handed the softest. Every row in the table carries its strength-of-schedule, so when somebody finishes ninth you can actually check whether they were unlucky or just worse. I find this quietly satisfying in a way I can’t fully justify.</p><p>And then you get to mess with all of it:</p><ul><li><strong>Watch matches happen.</strong> Matchdays play out minute by minute — goals land as they’re scored, the table re-sorts underneath you with the rows sliding into their new positions, and there’s a whistle and a crowd roar if you want the sound on. Or fast-forward the whole thing. There’s a play button that just keeps going until someone lifts the trophy.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FTtIqZdDuoXWOu5S0KBFQg.gif" /><figcaption>Live table re-sort during a matchday</figcaption></figure><ul><li><strong>Every score is editable.</strong> Type any result into the league and the table re-sorts live in front of you — odds and all. Change a knockout score and the ripple runs all the way down the bracket.</li><li><strong>Take the penalties yourself.</strong> When a knockout tie goes to a shoot-out you can watch it, or step up and pick your corner, kick by kick. The keeper is guessing. Sometimes correctly.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FExRBkCYRjTW2EV2t1xW0Q.gif" /><figcaption>Penalty shoot-out 😱</figcaption></figure><ul><li><strong>Pick your favorite.</strong> Choose a preferred winner and they get a gentle “destiny boost” in every simulated match — though football, being football, still reserves the right to break your heart on penalties. (It’s me. I’m football’s favorite heart to break.)</li><li><strong>Build your own.</strong> Don’t like the field? Hand-pick any nations from a big pool and the pots re-seed around your selection.</li><li><strong>Re-roll anything.</strong> One match, a whole round, or the entire thing.</li><li><strong>Brag about it.</strong> Win the tournament and you get a share card for your champion. Purely so I could post mine.</li></ul><p>Under the hood, matches aren’t just coin flips. They’re simulated with a Poisson goal model running over approximate FIFA ranking points — which is a fancy way of saying the favorites usually win, but a giant can <em>always</em> slip on a wet Tuesday night. Which, if you’ve read this far, you’ll know is the entire point.</p><p>That same model runs everything, incidentally: the match you’re watching, the thousand background simulations behind the odds, the shoot-out. Nothing is decided by a different, secret set of rules than the ones on screen.</p><h3><strong>So, is it actually better?</strong></h3><p>I genuinely think so — though I’d say that, wouldn’t I. But I also think the honest answer is: <em>go find out for yourself.</em> <a href="https://world-cup-reimagined.vercel.app/">Open the thing</a>, run a 48-team edition, favorite your own country (or your Zidane, or your van Nistelrooy), and see whether a summer with no dead rubbers and a giant-killing night guaranteed for everyone feels more like the World Cup you fell in love with as a kid.</p><p>That’s what I did, on a warm summer night in July with nothing — and somehow everything — to do.</p><p>For the love of the game.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b47f7df0fa0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s coming up in Kotlin? (KotlinConf 2025 overview)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://levelup.gitconnected.com/whats-coming-up-in-kotlin-kotlinconf-2025-overview-3466e28af88a?source=rss-5bebfcaeeb41------2"><img src="https://cdn-images-1.medium.com/max/1600/1*sOJkFZnswYKOiAjJ5taKcg.png" width="1600"></a></p><p class="medium-feed-snippet">KotlinConf, a conference organized by JetBrains and solely focused (as its title suggests) on the Kotlin programming language was a very&#x2026;</p><p class="medium-feed-link"><a href="https://levelup.gitconnected.com/whats-coming-up-in-kotlin-kotlinconf-2025-overview-3466e28af88a?source=rss-5bebfcaeeb41------2">Continue reading on Level Up Coding »</a></p></div>]]></description>
            <link>https://levelup.gitconnected.com/whats-coming-up-in-kotlin-kotlinconf-2025-overview-3466e28af88a?source=rss-5bebfcaeeb41------2</link>
            <guid isPermaLink="false">https://medium.com/p/3466e28af88a</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Ivan Velichkovski]]></dc:creator>
            <pubDate>Mon, 21 Jul 2025 08:48:20 GMT</pubDate>
            <atom:updated>2025-08-10T13:07:23.322Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How to use Firebase as your app’s back-end and CMS (part 1)]]></title>
            <link>https://levelup.gitconnected.com/how-to-use-firebase-as-your-apps-back-end-and-cms-part-1-563fbf6d3740?source=rss-5bebfcaeeb41------2</link>
            <guid isPermaLink="false">https://medium.com/p/563fbf6d3740</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ivan Velichkovski]]></dc:creator>
            <pubDate>Sun, 19 Jan 2020 23:14:48 GMT</pubDate>
            <atom:updated>2020-01-23T17:05:42.208Z</atom:updated>
            <content:encoded><![CDATA[<pre>This is part 1 of the <a href="http://ivanruns.tech/how-to-use-firebase-as-your-apps-back-end-and-cms-part-1/">series</a>. Stand by for the next parts... and together, we will build the best CMS!</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5kLHVW2DvldK45KcNOrQdA.png" /></figure><p>One of the most painful things that mobile developers face, myself included, is the agony when they have to build the back-end for themselves. Unless you have a budget where you can pay another back-end developer to do it for you in a more classic way you will most probably want to use some of the &quot;free&quot; solutions such as Firebase (it is free until your app &quot;explodes&quot;, in which case <a href="https://firebase.google.com/pricing">paying</a> for the service will hopefully not be a problem).</p><p>If you&#39;ve been sleeping in the last few years and you&#39;re not picking up the name from scratch, <a href="https://firebase.google.com/">Firebase</a> is now what <a href="https://parseplatform.org/">Parse</a> was before Facebook bought it and <a href="https://techcrunch.com/2016/01/28/facebook-shutters-its-parse-developer-platform/">ruined it for good</a>. It is undoubtedly the king of all BaaS (Business as a Service) solutions and being backed up by Google it seems like it won&#39;t be going anywhere anytime soon.</p><p>To put things into perspective I will just name a few of the things you can accomplish by using Firebase:</p><ul><li>user authentication via email, Facebook, Google... basically any social media you can think of, with <strong>Firebase Authentication</strong></li><li>store your NoSQL database with <strong>Realtime Database</strong>/<strong>Cloud Firestore</strong></li><li>store files in the <strong>Firebase Storage</strong></li><li>create and host a web app with <strong>Firebase Hosting</strong></li><li>create JavaScript functions that respond to events and invoke functionality exposed by other Firebase features with <strong>Firebase Functions</strong></li><li>keep track of your app&#39;s statistics with <strong>Firebase Analytics</strong></li><li>keep track of your app&#39;s performances with <strong>Firebase Quality</strong></li><li>create and send notifications to your users via <strong>Firebase Cloud Messaging</strong></li></ul><p>... and the list goes on and on. Quite simply said, anything that you can think of as a (mobile) developer, you can implement it with Firebase as your BaaS.</p><h3>What are we going to build?</h3><p>The back-bone of every mobile app out there is the data it uses and propagates to the user. Most of the mobile developers nowadays are simply getting the data by using a back-end done by other development team(s). If you&#39;re a part of a professional team as a mobile developer you&#39;ll probably never really bother with this data. The problem occurs once you want to do something on your own.</p><p>This post will look at the core of this problem. The solution I propose is to use the many features of the Firebase service. We will use the Firebase Hosting to create a simple web app that everyone in the world will be able to use. We will use the Firebase Database to show data in our web app. And finally, we will use the Firebase Authentication to create admin users for populating our data.</p><h3>Step 1: Create the web app</h3><p>Once you create your project in Firebase you will need to select Hosting in the &quot;Develop&quot; menu on the left side and click on the &quot;Get started&quot; button. After this, you need to follow the steps which include the installation of Firebase CLI (command line tool), initialization of the project and deploying it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ySlkULN0ksOha0tf.png" /></figure><p>Select the project you want from the list of projects and just accept everything else Firebase CLI suggests you. Now you only need to enter &quot;<strong>firebase deploy</strong>&quot; in the console.</p><p>And boom! Just like that, once you switch to the Firebase console, you will see that you already have a web app up and running with its URL proudly presented to you. You can even add a custom domain for it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kD4RR_OVPGy8RomF.png" /></figure><h3>Step 2: Create the pages in the web app</h3><p>Our web app will have 4 pages for:</p><ol><li>Login or registration of a user</li><li>Selection or creation of database node</li><li>List of options for a selected node</li><li>Details for an option which was selected from the node</li></ol><p>For that we will create 4 documents: login.html, app.html, list.html and details.html and we will remove the index.html. Once you do that make sure to enter another &quot;firebase deploy&quot; in the terminal and see what&#39;s going to happen.</p><p>Did an error occur? Most probably yes, unless you didn&#39;t forget to change your <strong>firebase.json</strong> file which holds the details for the hosting we&#39;re setting up.</p><p>In this file we need to change the default setting which always redirects to user to an index.html page which, if you followed me, you should&#39;ve deleted it. Here&#39;s the code I&#39;m using in my firebase.json:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c8a7baaccaeac2eb4a43097a95daede/href">https://medium.com/media/9c8a7baaccaeac2eb4a43097a95daede/href</a></iframe><p>Bonus point if you looked into the <strong>cleanUrls</strong> parameter up there. That one will make your site pages look cooler by removing the .html extension!</p><h3>Step 3: Enable Firebase Authentication + create login/register flow</h3><p>Since our first page is the login/registration we will first enable <a href="https://firebase.google.com/docs/auth/web/start">Firebase Authentication</a>. You can select any of the many options that Firebase has, but in this post we&#39;ll look into simple email authentication with user/pass credentials.</p><p>Once you enable this option in the Firebase console, you can add the following code in your login page:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1a093c3684394642286b76f306da41d/href">https://medium.com/media/f1a093c3684394642286b76f306da41d/href</a></iframe><p>This will add simple buttons and input views needed for the login/register flow as seen in the next screenshots:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/0*KbxgdVWS_1h85_bE.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/0*vx9SLE2pr92RuB1q.png" /></figure><p>To actually do something with these fields we will need to use the simple Firebase Email/Password authentication explained in detail <a href="https://firebase.google.com/docs/auth/web/password-auth">here</a>. The left screenshot above with the confirm password field is actually not even needed. This field is simply added there so that it&#39;s cohesive to the user registration flow that most of the sites use and if you want, you can remove it from your implementation.</p><p>Register code snippet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ad8860886038446779252ae3e68baf7/href">https://medium.com/media/5ad8860886038446779252ae3e68baf7/href</a></iframe><p>Login code snippet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c98977f3759bf5c86fe85bfd9eaad73/href">https://medium.com/media/4c98977f3759bf5c86fe85bfd9eaad73/href</a></iframe><p>Another thing that we might find it handy to do is to create a check in our app (landing) page if the user is logged in, and if not, to redirect it to the login page.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f242717cc9737de420489e6ec2d3f026/href">https://medium.com/media/f242717cc9737de420489e6ec2d3f026/href</a></iframe><p>Now we have our demo working completely for the user log-in/registration flow. We will continue building this web app in an instant, but first, let&#39;s check how it&#39;s looking at the moment:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FWOI9IF0GJvRrRk3LG0%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FWOI9IF0GJvRrRk3LG0%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FWOI9IF0GJvRrRk3LG0%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="243" frameborder="0" scrolling="no"><a href="https://medium.com/media/8fcb78012e1f7c75a7497540dd64267e/href">https://medium.com/media/8fcb78012e1f7c75a7497540dd64267e/href</a></iframe><p><a href="https://www.urbandictionary.com/define.php?term=blyatiful"><strong>Blyatiful</strong></a><strong>, isn&#39;t it?</strong></p><p>Thus, we conclude part 1 of this series. In the second part we will look into creation of the Firebase Database for our project. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=563fbf6d3740" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/how-to-use-firebase-as-your-apps-back-end-and-cms-part-1-563fbf6d3740">How to use Firebase as your app’s back-end and CMS (part 1)</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Save fragment history and state inside BottomNavigationView tab(s) with FragmentPagerAdapter]]></title>
            <link>https://medium.com/@ivanvelickovski/save-fragment-history-and-state-inside-bottomnavigationview-tab-s-with-fragmentpageradapter-982a92f94207?source=rss-5bebfcaeeb41------2</link>
            <guid isPermaLink="false">https://medium.com/p/982a92f94207</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[fragmentpageradapter]]></category>
            <category><![CDATA[bottomnavigationview]]></category>
            <dc:creator><![CDATA[Ivan Velichkovski]]></dc:creator>
            <pubDate>Sun, 22 Dec 2019 18:52:31 GMT</pubDate>
            <atom:updated>2019-12-22T18:52:31.600Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*MhCpO-QLImKHPAtjQLG2Ww.jpeg" /></figure><p>Recently I faced a problem where I had to save the state of all views inside tabs. Consider the following design: you have, for example, three (bottom) tabs with three base views, which can have a lot of inner views that you’d want to be cached/stored in memory at all times (for the sake of this post, let’s not go into the issue of the UX as to why we show the inner fragments inside the tabs navigation instead of a separate new modal view/activity).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*m-Gr4MhFnnEu1Ugv.png" /></figure><p>In the case you can see on the screenshot, we have 3 tabs: info, search and help. We want to be able to iterate inside of them all and save their state at all times, i.e. if we go inside inner Info view #1 (by clicking the button “Go in inner fragment” shown above), then switch to Search tab, and then again tap on Info tab we’d like to show the inner Info view #1 that was opened previously with the state it had the last time.</p><p>At this point it’s pretty obvious that we can use either one of those: the <strong>FragmentPagerAdapter</strong> or the <strong>FragmentStatePagerAdapter</strong>. As I mentioned previously, we want our views to be <strong>cached</strong> in memory and easily restored when switching back and forth between the tabs, so FragmentPagerAdapter it is!</p><p>Bear in mind that we don’t care about the possible memory issues that might occur and I haven’t tested how much of a hit this is for the app when compared to the state pager adapter which destroys the views once they are not visible.</p><p>We start, of course, by creating a simple MainActivity class with ViewPager and BottomNavigationView.</p><p>activity_main.xml:</p><pre><em>&lt;?</em><strong>xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;</strong><em>?&gt;<br></em>&lt;<strong>androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;<br>    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;<br>    xmlns:tools=&quot;http://schemas.android.com/tools&quot;<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;match_parent&quot;<br>    tools:context=&quot;.MainActivity&quot;</strong>&gt;</pre><pre>    &lt;<strong>androidx.viewpager.widget.ViewPager<br>        android:id=&quot;@+id/viewPager&quot;<br>        android:layout_width=&quot;0dp&quot;<br>        android:layout_height=&quot;0dp&quot;<br>        app:layout_constraintBottom_toTopOf=&quot;@id/bottomNavigationView&quot;<br>        app:layout_constraintLeft_toLeftOf=&quot;parent&quot;<br>        app:layout_constraintRight_toRightOf=&quot;parent&quot;<br>        app:layout_constraintTop_toTopOf=&quot;parent&quot; </strong>/&gt;</pre><pre>    &lt;<strong>com.google.android.material.bottomnavigation.BottomNavigationView<br>        android:id=&quot;@+id/bottomNavigationView&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot;<br>        app:menu=&quot;@menu/bottom_menu_nav&quot;<br>        app:layout_constraintBottom_toBottomOf=&quot;parent&quot;<br>        app:itemBackground=&quot;@color/colorPrimary&quot;<br>        app:itemIconTint=&quot;@android:color/white&quot;<br>        app:itemTextColor=&quot;@android:color/white&quot;</strong>/&gt;</pre><pre>&lt;/<strong>androidx.constraintlayout.widget.ConstraintLayout</strong>&gt;</pre><p>You might ask yourself why do we need the ViewPager at all? The answer is, we need it because we’ll use it to cache our inner fragments (as well as the base fragments) inside its adapter. For that, we create our own implementation of the FragmentPagerAdapter.</p><p>MainFragmentPagerAdapter.class:</p><pre><em>/*<br>    *<br>    * Pager adapter that keeps state of the fragments inside the bottom page navigation tabs<br>    *<br> */<br></em><strong>public class </strong>MainFragmentPagerAdapter <strong>extends </strong>FragmentPagerAdapter {</pre><pre>    <em>//region Statics<br>    </em><strong>private static final </strong>List&lt;Fragment&gt; <strong><em>BASE_FRAGMENTS </em></strong>= Arrays.<em>asList</em>(InfoFragment.<em>newInstance</em>(), SearchFragment.<em>newInstance</em>(), HelpFragment.<em>newInstance</em>());</pre><pre>    <strong>private static final int <em>INFO_POSITION </em></strong>= 0;<br>    <strong>private static final int <em>SEARCH_POSITION </em></strong>= 1;<br>    <strong>private static final int <em>HELP_POSITION </em></strong>= 2;<br>    <em>//endregion</em></pre><pre><em>    //region Fields<br>    </em><strong>private </strong>List&lt;Fragment&gt; <strong>mInfoFragments</strong>;<br>    <strong>private </strong>List&lt;Fragment&gt; <strong>mSearchFragments</strong>;<br>    <strong>private </strong>List&lt;Fragment&gt; <strong>mHelpFragments</strong>;<br>    <em>//endregion</em></pre><pre><em>    //region constructor<br>    </em><strong>public </strong>MainFragmentPagerAdapter(@NonNull FragmentManager fragmentManager) {<br>        <strong>super</strong>(fragmentManager);<br>        <strong>mInfoFragments </strong>= <strong>new </strong>ArrayList&lt;&gt;();<br>        <strong>mSearchFragments </strong>= <strong>new </strong>ArrayList&lt;&gt;();<br>        <strong>mHelpFragments </strong>= <strong>new </strong>ArrayList&lt;&gt;();<br>    }<br>    <em>//endregion</em><br>...</pre><p>Next, we want to be able to differentiate our base fragments vs. our so-called inner fragments, so that we can use that information in our onBackPress in the activity. For that we will override the getItemId method:</p><pre>@Override<br><strong>public long </strong>getItemId(<strong>int </strong>position) {<br>    <strong>if </strong>(position == <strong><em>INFO_POSITION<br>            </em></strong>&amp;&amp; getItem(position).equals(<strong><em>BASE_FRAGMENTS</em></strong>.get(position))) {<br>        <strong>return <em>INFO_POSITION</em></strong>;<br>    } <strong>else if </strong>(position == <strong><em>SEARCH_POSITION<br>            </em></strong>&amp;&amp; getItem(position).equals(<strong><em>BASE_FRAGMENTS</em></strong>.get(position))) {<br>        <strong>return <em>SEARCH_POSITION</em></strong>;<br>    } <strong>else if </strong>(position == <strong><em>HELP_POSITION<br>            </em></strong>&amp;&amp; getItem(position).equals(<strong><em>BASE_FRAGMENTS</em></strong>.get(position))) {<br>        <strong>return <em>HELP_POSITION</em></strong>;<br>    }</pre><pre>    <strong>return </strong>getItem(position).hashCode();<br>}</pre><p>If the list of fragments for the current selected tab position is empty we simply return the tab position, and if not, we return the hashCode of the fragment. Pretty neat, right?</p><p>Similarly, we check the same thing for our getItem overridden method:</p><pre>@Override<br>@NonNull<br><strong>public </strong>Fragment getItem(<strong>int </strong>position) {<br>    <strong>if </strong>(position == <strong><em>INFO_POSITION</em></strong>) {<br>        <strong>if </strong>(<strong>mInfoFragments</strong>.isEmpty()) {<br>            <strong>return <em>BASE_FRAGMENTS</em></strong>.get(position);<br>        }<br>        <strong>return mInfoFragments</strong>.get(<strong>mInfoFragments</strong>.size() - 1);<br>    } <strong>else if </strong>(position == <strong><em>SEARCH_POSITION</em></strong>) {<br>        <strong>if </strong>(<strong>mSearchFragments</strong>.isEmpty()) {<br>            <strong>return <em>BASE_FRAGMENTS</em></strong>.get(position);<br>        }<br>        <strong>return mSearchFragments</strong>.get(<strong>mSearchFragments</strong>.size() - 1);<br>    } <strong>else </strong>{<br>        <strong>if </strong>(<strong>mHelpFragments</strong>.isEmpty()) {<br>            <strong>return <em>BASE_FRAGMENTS</em></strong>.get(position);<br>        }<br>        <strong>return mHelpFragments</strong>.get(<strong>mHelpFragments</strong>.size() - 1);<br>    }<br>}</pre><p>Now that we’ve set the basics, we can focus on creating helper methods which will add and remove fragments in the pager adapter:</p><pre><strong>public void </strong>updateFragment(Fragment fragment, <strong>int </strong>position) {<br>    <strong>if </strong>(!<strong><em>BASE_FRAGMENTS</em></strong>.contains(fragment)) {<br>        addInnerFragment(fragment, position);<br>    }<br>    notifyDataSetChanged();<br>}</pre><pre><strong>private void </strong>addInnerFragment(Fragment fragment, <strong>int </strong>position) {<br>    <strong>if </strong>(position == <strong><em>INFO_POSITION</em></strong>) {<br>        <strong>mInfoFragments</strong>.add(fragment);<br>    } <strong>else if </strong>(position == <strong><em>SEARCH_POSITION</em></strong>) {<br>        <strong>mSearchFragments</strong>.add(fragment);<br>    } <strong>else </strong>{<br>        <strong>mHelpFragments</strong>.add(fragment);<br>    }<br>}</pre><pre><strong>public boolean </strong>removeFragment(Fragment fragment, <strong>int </strong>position) {<br>    <strong>if </strong>(position == <strong><em>INFO_POSITION</em></strong>) {<br>        <strong>if </strong>(<strong>mInfoFragments</strong>.contains(fragment)) {<br>            removeInnerFragment(fragment, <strong>mInfoFragments</strong>);<br>            <strong>return true</strong>;<br>        }<br>    } <strong>else if </strong>(position == <strong><em>SEARCH_POSITION</em></strong>) {<br>        <strong>if </strong>(<strong>mSearchFragments</strong>.contains(fragment)) {<br>            removeInnerFragment(fragment, <strong>mSearchFragments</strong>);<br>            <strong>return true</strong>;<br>        }<br>    } <strong>else if </strong>(position == <strong><em>HELP_POSITION</em></strong>) {<br>        <strong>if </strong>(<strong>mHelpFragments</strong>.contains(fragment)) {<br>            removeInnerFragment(fragment, <strong>mHelpFragments</strong>);<br>            <strong>return true</strong>;<br>        }<br>    }</pre><pre>    <strong>return false</strong>;<br>}</pre><pre><strong>private void </strong>removeInnerFragment(Fragment fragment, List&lt;Fragment&gt; tabFragments) {<br>    tabFragments.remove(fragment);<br>    notifyDataSetChanged();<br>}</pre><p>And that’s pretty much it! We can now use this set-up in our MainActivity and store as many inner fragments inside our tabs as we want to, and we can also use the boolean value of removeFragment to not have any onBackPress trouble(s).</p><pre><em>//region Activity lifecycle<br></em>@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>    ButterKnife.<em>bind</em>(<strong>this</strong>);</pre><pre>    <strong>mPagerAdapter </strong>= <strong>new </strong>MainFragmentPagerAdapter(getSupportFragmentManager());<br>    <strong>mViewPager</strong>.setAdapter(<strong>mPagerAdapter</strong>);<br>    <strong>mViewPager</strong>.setOffscreenPageLimit(3);</pre><pre>    <strong>mBottomNavigationView</strong>.setOnNavigationItemSelectedListener(menuItem -&gt; {<br>        <strong>switch </strong>(menuItem.getItemId()) {<br>            <strong>case </strong>R.id.<strong><em>menuInfo</em></strong>:<br>                <strong>mCurrentTabPosition </strong>= InfoFragment.<strong><em>TAB_POSITION</em></strong>;<br>                <strong>mViewPager</strong>.setCurrentItem(<strong>mCurrentTabPosition</strong>);<br>                <strong>return true</strong>;<br>            <strong>case </strong>R.id.<strong><em>menuSearch</em></strong>:<br>                <strong>mCurrentTabPosition </strong>= SearchFragment.<strong><em>TAB_POSITION</em></strong>;<br>                <strong>mViewPager</strong>.setCurrentItem(<strong>mCurrentTabPosition</strong>);<br>                <strong>return true</strong>;<br>            <strong>case </strong>R.id.<strong><em>menuHelp</em></strong>:<br>                <strong>mCurrentTabPosition </strong>= HelpFragment.<strong><em>TAB_POSITION</em></strong>;<br>                <strong>mViewPager</strong>.setCurrentItem(<strong>mCurrentTabPosition</strong>);<br>                <strong>return true</strong>;<br>            <strong>default</strong>:<br>                <strong>return false</strong>;<br>        }<br>    });<br>}</pre><pre>@Override<br><strong>public void </strong>onBackPressed() {<br>    <strong>if </strong>(!<strong>mPagerAdapter</strong>.removeFragment(<strong>mPagerAdapter</strong>.getItem(<strong>mCurrentTabPosition</strong>), <strong>mCurrentTabPosition</strong>)) {<br>        finish();<br>    }<br>}<br><em>//endregion</em></pre><p>Adding an inner fragment is as easy as the following snippet in InfoFragment.class:</p><pre>@OnClick(R.id.<strong><em>btInnerFragment</em></strong>)<br><strong>void </strong>onInnerButtonClick() {<br>    <strong>mFragmentUpdateCallback</strong>.addFragment(InnerInfoFragment.<em>newInstance</em>(), <strong><em>TAB_POSITION</em></strong>);<br>}</pre><p>FragmentUpdateCallback is also easily understandable:</p><pre><em>/*<br>    *<br>    * Interface used for app navigation/updating the bottom tab fragments<br>    *<br> */<br></em><strong>public interface </strong>FragmentUpdateCallback {<br>    <strong>void </strong>addFragment(Fragment fragment, <strong>int </strong>tabPosition);<br>}</pre><p>The result of the onInnerButtonClick being:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/0*V9fRbdkVKnUa2Zz5.png" /></figure><p>OnBackPress will return the user to base Info tab, and another onBackPress will simply destroy the Activity.</p><p>You can see the full sample in action <a href="https://github.com/IvanVelickovski/FragmentPagerApp">here</a>.</p><p>Don’t forget to suggest possible improvements and/or star the repo!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=982a92f94207" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>