<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ahmad Jawid</title>
    <description>The latest articles on DEV Community by Ahmad Jawid (@jawidmuhammadi).</description>
    <link>https://dev.to/jawidmuhammadi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F393021%2F5167cc61-b691-4191-a5ff-1f606669c110.jpeg</url>
      <title>DEV Community: Ahmad Jawid</title>
      <link>https://dev.to/jawidmuhammadi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jawidmuhammadi"/>
    <language>en</language>
    <item>
      <title>Couchbase Mobile</title>
      <dc:creator>Ahmad Jawid</dc:creator>
      <pubDate>Sun, 06 Feb 2022 15:15:16 +0000</pubDate>
      <link>https://dev.to/jawidmuhammadi/couchbase-mobile-3dmf</link>
      <guid>https://dev.to/jawidmuhammadi/couchbase-mobile-3dmf</guid>
      <description>&lt;h2&gt;
  
  
  Why Couchbase Mobile?
&lt;/h2&gt;

&lt;p&gt;Couchbase Mobile is the complete NoSQL database solution for all data storage, access, sync, and security across the entire&lt;br&gt;
application stack. It includes an Embedded database, Rest API, and Synchronization which is critical for enabling&lt;br&gt;
offline-first mobile apps. The two critical aspects of enabling this are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The ability to locally store data on the device so it is always available to the user, whether online or offline&lt;/li&gt;
&lt;li&gt;The ability to sync data to the cloud so it is available to the users on other devices when online. This includes secure routing of data across devices, enforcement of access conflict, and handling of data conflicts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Couchbase Mobile brings the power of NoSQL to the edge. It is comprised of three important components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Couchbase Lite,&lt;/strong&gt; an embedded, NoSQL JSON Document Style database for your mobile apps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sync Gateway,&lt;/strong&gt; an internet-facing synchronization mechanism that securely syncs data between mobile clients and server.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Couchbase Server,&lt;/strong&gt; a highly scalable, distributed NoSQL database platform.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Couchbase Lite:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To include Couchbase Lite support within an Android app add the following within &lt;em&gt;app/build.gradle&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependencies {
    ...

    implementation 'com.couchbase.lite:couchbase-lite-android-ee:2.7.1'
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For more details about how to integrated and use Couchbase Lite follow this &lt;a href="https://docs.couchbase.com/userprofile-couchbase-mobile/standalone/userprofile/android/userprofile_basic.html"&gt;Tutorial&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Sync Gateway:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Click on this &lt;a href="https://docs.couchbase.com/sync-gateway/current/gs-sgw-install.html"&gt;link&lt;/a&gt; to download and install Sync Gateway. Follow the instructions carefully and install it based on your Operation System which you use in your machine.&lt;/p&gt;

&lt;p&gt;To stop/start the &lt;em&gt;sync_gateway&lt;/em&gt; service, use the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo service sync_gateway start

sudo service sync_gateway stop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After starting &lt;em&gt;sync_gateway&lt;/em&gt; try the following URLs. (URL may differ depending on the PORT NUMBER where it’s installed, but by default these ports are used).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:4984/

http://localhost:4985/

http://localhost:4985/_admin/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Couchbase Server:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Click on this &lt;a href="https://docs.couchbase.com/tutorials/getting-started-ce/install-manage/tutorial_en.html"&gt;link&lt;/a&gt; to download and install Couchbase Server's community version. the server starts automatically after installation. If everything went well during installation and when you open up your browser on&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:8091/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you should see the Couchbase Server Web Console then do the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a new cluster (Click &lt;a href="https://docs.couchbase.com/tutorials/getting-started-ce/install-manage/tutorial_en.html"&gt;here&lt;/a&gt; for more details)&lt;/li&gt;
&lt;li&gt;Create a bucket named &lt;code&gt;finecract-cn-mobile&lt;/code&gt; and leave the other variables as default.&lt;/li&gt;
&lt;li&gt;Click on the Security tab on the left side and add a user as &lt;code&gt;Name: fineract-cn, Password: password&lt;/code&gt; and give it &lt;em&gt;full admin access&lt;/em&gt; as a role. We use this user to authenticate during replicating data from Mobile to local Couchbase Server.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Data Synchronization
&lt;/h2&gt;

&lt;p&gt;In V1.x of Couchbase Mobile, replication was implemented using a REST-based protocol originated by CouchDB over HTTP(s). Effectively, the replication logic was implemented as a series of API calls over HTTP.&lt;/p&gt;

&lt;p&gt;To start synchronizing your data with the local server follow the following steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Client-Side (Android App)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To start replicating data use the following utility class and call the &lt;code&gt;startReplicating(Database database)&lt;/code&gt; method once you initialize and create Couchbase Database.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Replicate {

    public static void startReplicating(Database database) throws URISyntaxException {

        Endpoint targetEndpoint = new URLEndpoint(URI.create("ws://10.0.2.2:4984/fineract-cn/"));
        ReplicatorConfiguration config = new ReplicatorConfiguration(database, targetEndpoint);
        config.setReplicatorType(ReplicatorType.PUSH_AND_PULL);
        config.setAuthenticator(new BasicAuthenticator("sync_gateway", "password"));
        Replicator replicator = new Replicator(config);

        replicator.addChangeListener(change -&amp;gt; {
            if (change.getStatus().getError() != null) {
                Log.e(TAG, "Error message:  " + change.getStatus().getProgress());
            }
        });

        replicator.start();
    }
}    
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in here &lt;code&gt;targetEndPoint&lt;/code&gt; is the address of the database in Sync Gateway, not the Couchbase server.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The local server and Android Application should be on the same network.&lt;/li&gt;
&lt;li&gt;Disable the Firewall on the Local Server. (steps might differ depending on the Operating System)&lt;/li&gt;
&lt;li&gt;Create a new file &lt;em&gt;res &amp;gt; xml &amp;gt; network_security_config.xml&lt;/em&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;network-security-config&amp;gt;
    &amp;lt;base-config cleartextTrafficPermitted="true"&amp;gt;
        &amp;lt;trust-anchors&amp;gt;
            &amp;lt;certificates src="system" /&amp;gt;
        &amp;lt;/trust-anchors&amp;gt;
    &amp;lt;/base-config&amp;gt;
&amp;lt;/network-security-config&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Make the below changes to the AndroidManifest.xml file:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;application
    ...
    android:networkSecurityConfig="@xml/network_security_config"
    ...&amp;gt;

    ...
&amp;lt;/application&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Configure Sync Gateway&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a file named as &lt;code&gt;sync-gateway-config.json&lt;/code&gt; with the following configurations:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; {
    "log": ["*"],
     "databases": {
        "fineract-cn": {
        "server": "http://localhost:8091/",
        "bucket": "fineract-cn-mobile",
        "username": "fineract-cn",
        "password": "password",
        "enable_shared_bucket_access": true,
        "import_docs": true,
        "num_index_replicas": 0,
        "users": {
            "GUEST": { "disabled": false, "admin_channels": ["*"] },
            "sync_gateway": {"password": "password"}
        }
     }
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;From terminal start the &lt;em&gt;sync_gateway&lt;/em&gt; with the created configuration file by running this command:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;/opt/couchbase-sync-gateway/bin/sync_gateway [file_path_address]/sync-gateway-config.json&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If everyting went well, you can see the &lt;code&gt;fineract-cn&lt;/code&gt; database name when you open the sync gateway from &lt;code&gt;http://localhost:4985/_admin/&lt;/code&gt; on the browser.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The Offline First approach has been implemented in some functionalities of the &lt;strong&gt;Fineract CN mobile&lt;/strong&gt; app using Couchbase Lite. Please view this &lt;a href="https://github.com/jawidMuhammadi/fineract-cn-mobile/pull/2/commits/671e6832c87efc3f7b75f6520cdf077f93951658"&gt;pull request&lt;/a&gt; to see how it has been implemented. &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/jawidMuhammadi/CouchbaseNote"&gt;CouchbaseNote&lt;/a&gt; is another small project which is created using Couchbase Lite as a Local Data storage.&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hod.greeley.org/blog/?p=476"&gt;Getting Comfortable with Couchbase Mobile&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.couchbase.com/products/mobile"&gt;Couchbase Mobile&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.couchbase.com/userprofile-couchbase-mobile/standalone/userprofile/android/userprofile_basic.html"&gt;Tutorial&lt;/a&gt;: Getting started with Couchbase Lite and Android.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>android</category>
      <category>database</category>
    </item>
    <item>
      <title>SpotlightDo</title>
      <dc:creator>Ahmad Jawid</dc:creator>
      <pubDate>Fri, 22 May 2020 17:14:47 +0000</pubDate>
      <link>https://dev.to/jawidmuhammadi/spotlightdo-31f</link>
      <guid>https://dev.to/jawidmuhammadi/spotlightdo-31f</guid>
      <description>&lt;h2&gt;
  
  
  My Final Project in College
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=com.plannerdo.android.mydo&amp;amp;hl=en"&gt;Demo Link on Google Play Store&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/jawidMuhammadi/SpolightDo"&gt;GitHub Repo&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is this project about?
&lt;/h2&gt;

&lt;p&gt;SpotlightDo app is a smart To do list reminder app with alarm for everyday use and also you can create notes or convert an image to text offline (OCR) and add to your notes. To-do list app is truly usable with great user experience, no matter who you are and what you do, you will be better organized!&lt;/p&gt;

&lt;h2&gt;
  
  
  How I built it?
&lt;/h2&gt;

&lt;p&gt;I started building this application in the second semester of college. At the first days of my journey to App development, I didn't know anything about &lt;code&gt;GitHub&lt;/code&gt; and &lt;code&gt;Version Control System&lt;/code&gt; so I used to make copies of each version to different folders, whenever I made any change or develop any new feature then going back or reverting the changes was a disaster. After knowing about &lt;code&gt;GitHub&lt;/code&gt; and &lt;code&gt;Version Control System&lt;/code&gt; my speed in writing code and Android App Development changed and increased dramatically, I started coding fast without worrying about breaking anything. I developed a lot of apps and contributed to many Open Source projects using GitHub.&lt;/p&gt;

&lt;p&gt;After 1 year in Google Play Store, my app has reached more than &lt;strong&gt;50,000&lt;/strong&gt; downloads with thousands of daily active users. It is a small project but I am sure that my app is helping people who are using it in their daily routines.&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Thoughts / Feelings / Stories
&lt;/h2&gt;

&lt;p&gt;Thanks to GitHub for providing this amazing platform free for all developers around the world!&lt;/p&gt;

</description>
      <category>octograd2020</category>
    </item>
  </channel>
</rss>
