HarperDB Studio Mobile And a bonus feature to be excited for...

HarperDB Studio Mobile And a bonus feature to be excited for...

Once again, it's that time of the year where I remember that I have a personal blog and I need something to blog on. But, to write something, I definitely need to do something worth writing on. As you guessed from the title, I'm back from my cave with another cool project for HarperDB.

The first time I came across HarperDB, it was just a cool hybrid DB and I used it for something. Then, second time , I wrote a Kotlin based library for HarperDB Studio. So, first time, I used HarperDB and second time I made something to use HarperDB. For third time, I was at my wits end... "What should I do this time? What should I try?". Then I remembered about the time I was scrolling through their Bounty program and came across an interesting idea and tried following up on it , but never got around to actually kickstart it. So, I stole that idea... Evil Grin ...

Huehuehuehuehue

So, I present you with a cross-platform app (iOS, Android, UWP and more) for HarperDB Studio, i.e., HarperDB Studio Mobile.

I've got few things to discuss about this project and HarperDB in general, so this might be a little longer to go through. But, let me give you some features of this HarperDB Studio Mobile first.

Note: Last one is a cool feature and was a little tricky to work with, but it came through ;).

FEATURES

  • Supported on Android, iOS, UWP (Windows 10) and many more.
  • Easily portable to other platforms as well (hopefully Windows 11 in near future too).
  • Create new records, edit existing records or delete existing records for any table in any schema.
  • Cached logins, so you don't have to enter everything again and again.
  • Offline mode, i.e., ability to sync your changes when you're offline. Read more about this below.

So, with the features out of the way, here's a video of a little walkthrough of the application.

iOS Demo

Android Demo

This POC that I made, it gives a pretty good insight on which directions we can go in the final application (the planned updates mentioned below). I don't want to keep things "too technical" in this post, but, I do want to share some setbacks I faced while developing this application and certain things that bugged me a little. If you want to read more about the "offline mode", scroll down to see it in action and understand how it works.

SETBACKS

I have a full-time job, so it was a little bit of a challenge to complete and work in those hours and then spend 2-3 hours daily to work on this application. Surely, I have worked with Xamarin Forms for a very long time ( 5 years now), but, it has been on personal projects and they have tons of updates coming every few months. So, I was finally able to work with Xamarin Forms V4 and it was another task, because they introduced "Shell" in stable version and then there are other things that got deprecated. So, learning that and implementing that was a little bit of challenge in itself.

Now, Xamarin is a good framework. But, it lacks these few necessary things that you need to design/build yourself from scratch. If you're little bit lucky, you might find a third part library....and if you're very lucky, that third party library might work for your needs. In my case, I was only little lucky and here's my "setback" story :

  • No inbuilt support for displaying Tabular Data: This is one of the most basic component that gets used. Xamarin has been out since 2014 and I think 6-7 years is more than enough of a time to be able to provide support to display tabular data. So, I did what a normal programmer does....I went for code shopping on Stackoverflow and Xamarin forums. Found 2 options that showed some promise ( Syncfusion's Datagrid and Ebubekir Akgül's Datagrid ). Well, to no surprise, I spent 2-3 days on getting these and few more libraries to work and show data. Nope, nada... didn't work. These might work when you have a CLASS OBJECT and a structured data and its structure should be known. When you query any NoSQL DB, you wouldn't know the structure of the data. But, you might think "Hey, C# has ExpandoObject or Dynamic object that you can utilize". Sure, yes.... but, I have to support iOS as well and due to AOT compiler's policies, ExpandoObject or Dynamic object wouldn't work. So, I ended up build my own component for a Dynamic Table. Now, building that was tricky because it's dynamic data in not just "length", but also "type". Also, creating and managing Tap events and adding gestures took me a while to get working. But, In the end, all the hard work paid off when it worked like a charm. I won't post code in this post because it'll be too long, but, I might write a detailed blog on achieving that later.

  • Another setback was Xamarin's "Flyout" menu: "But, hey.. that's supposed to be a useful feature for sidebar menu, right? How's that a setback?" Well, I thought so too and I had some cool plans on utilising it. But, there's this weird thing happening on it. The very first Flyout menu item will be the page/view that opens whenever you open your app. Yep, read it correct. Not sure who thought it would be a good idea to default to that behaviour, but they definitely went and did that. Now, yes, you can modify that behaviour with some code and there are some workaround for it (browsed through StackOverflow, of course). But, ask yourself this simple question "Should I be spending hours on trying to override this behaviour? should I?"... well, I did and the whole app's experience went to crap when I implemented the workaround. So, in the end, I dropped that idea and removed the Flyout menu entirely from the app and went with toolbar items for my basic purpose (logout and resources link to harperDB).

  • Now, I wouldn't call this as a "setback", but, found another half-arsed built component, i.e., "CHECKBOX". When I add a checkbox component to screen, I want to be able to add some text in front of that checkbox. I just don't want to show a checbox on the screen... it doesn't make any sense. So, anyways, I slapped a label in front of it and added tap gesture on that label to trigger checkbox checked state.

Well, there were few other things that slowed me down, but, I got around them eventually (YAY!).

OFFLINE MODE

The HarperDB bounty program I was talking about, from where I got this idea. Actually, I've been wanting to build a cross-platform app utilising HarperDB ever since I came across the first Hackathon (2018), but, this offline mode idea has been stuck in my head ever since I came across this thread. So, here's what the offline mode does or works like.

Let's say you're trying to add a new row or update existing data and suddenly network goes off on your device. As soon as the app detects that your network is down, "offline mode" is switched on and from thereon, your operations are recorded and cached. By operations I mean.. adding a new row, updating an existing row and deleting any existing row. Yep, it's not just adding a new row that gets saved... even edited row data is saved and cached. So, even if you were to close the application after making those changes, the changes are retained. So, next time when you open the app and there's network connection, those cached operations are run in background and your data is synced with the online HarperDB Studio instance. You don't have to do anything.. it's taken care of. It just works. Pretty cool and handy, right? There are few optimisations I want to make in this area, just to squeeze out some better performance, but the current implementation doesn't lack anything. It works flawlessly.

Here's a little video demonstrating the offline mode.

NOTES TO HARPERDB TEAM

Last time I was working with HarperDB, I was just checking their documentation and didn't really see how their online studio was actually working. I saw few things that I feel are not safe to do. A security risk, if you can say... Let me point some of these out. So, HarperDB Team, if you folks are still reading this post, do think about these please:

  • Credentials are being sent in plain text: Yes, only the user using the browser can see it in the NETWORK tab. But, it makes your service susceptible to MITM. It's your service, maybe utilize some kind of encryption mechanism. Like before sending the credentials to your back-end service, encrypt them in the UI itself and decrypt them in back-end. Yes, it'll make it a little slow as a whole login process, but, I think it won't be that much. Here's a screenshot of what I'm talking about: Naked Credentials

  • Plain Application Cache: Every webapp/website stores cookies and some cache data for faster lookups. Nothing wrong with that. But, it's always a good idea to store them as encrypted tokens. If you go to chrome's dev tools and move over to "Application" tab and look at local cache.... you'll see the login details of your instances stored... as plain text. Guys, not good. Here's a screenshot of the same: Instance Credentials Stored as plain text

In the cookies, I could see plain text credentials of my main dashboard login. These could be easily stolen and misused. I would strongly suggest that you guys do something about this.

FUTURE UPDATES

  • Encrypted stored cached data for added security.
  • Ability to create or delete Organizations/Instances.
  • Complete offline mode (from "logging in" to browsing instances and organizations).
  • UI/UX improvements.

I wrote a big paragraph on where HarperDB team should be working on, but this app I built isn't storing cached data in encrypted strings either. Well, there is a reason for that and it's that Xamarin doesn't have any inbuilt "cryptography" mechanism. They do have "SecureStorage", which is said to be better than storing any data in cache in plain string format. But, since I was developing and testing on "Simulator" (iOS), that implementation failed. So, I had to resort to normal App settings cache for storing data. But, when I'm done with these mentioned changes, I'll invest some time in that area as well.

The offline mode is good, the only limit of it as of now is that it kicks in only if you're on the grid page (where you can access tables and schema). So, if you're browsing Organizations or looking at Instance list, you can't browse the entire application in offline mode. So, I'd like to work on that area and will try to make this entire app "offline" itself.

WHERE DA APP AT?

Good lord, you read this whole post? Wow. As a reward, here's the link to the Github repo for this app: HarperDB Studio Mobile

You can download the "android apk" from the latest stable releases to test it out. But, if you want to use iOS app, you would need to setup the development environment for Xamarin to launch this app. Because, I can't distribute iOS apps without a signing identity (one of the reasons why I love android and UWP development). However, you should be able to try out the UWP version too.

Running This Project :

The minimum Android OS that you need to run this project is Lollipop (5.0) (API Level 21). So, make sure you're satisfying the minimum requirements first. Otherwise, your handset won't be able to parse the apk file.

  • Permissions Required :

    This application requires you to provide few permissions to it, in order to work properly. Here's the list of permissions that the application needs :

    • Internet Access
    • View WiFi Connections
    • Storage (Read/Write Perms For Cache)
  • Instructions For Direct APK Installation :

    If you want to run this application on your android phone, please move over to the "Release" section and download the latest stable APK build for your android phone. You do not need any external libraries or application.

  • Instructions For Developers/Testers :

    If you're a developer or any user who wishes to test this application and run this android project, it's recommended to install Visual Studio with Xamarin Support and Android SDKs on your system. Remember that Android SDKs should be in your local path for you to be able to compile the project properly. You can find the source code in the "SOURCE" directory.

    If you do not happen to have Visual Studio, it is recommended to get it because it'll download all the required packages on its own, if they're not present. You can use Visual Studio's Free Community Edition. It'll work, as we've developed this application on it. But, if for some reason, you don't want to or can't install Visual Studio, you will need to have .NET, Xamarin, Android SDK and required Packages in your system's local path for you to be able to compile and execute this application project.

Sidenote

Just a side note, I'm excited for Windows 11 launch and I would want to try to run this app on windows 11 and see if it runs from the get go. My guess is that it will run without any hiccups. Let's see though.

Props to you for making this far. Hope you like the final result of this as much as I enjoyed those obstacles in building this application. It was fun learning and finally being able to build something for HarperDB team.