Tuesday, July 2, 2019

Updated our Motivational Quotes App to include "Night Mode" feature and to add Author Links.


I have released new version (versions 1.11) of our Motivational Quotes App  with below features.

  • Added Night Mode /Dark Mode Option.
  • Added Clickable Links to Author Names.
  • Optimized the Code to reduce file size.

A lot of people downloaded our Quotes App from Google play store. It is good to know that more than 20K people installed it in their mobile devices. But the DAU (Daily Active Users) and Active Installations are very low.
Based on the users' feedback, I thought adding Night Mode option can fix this user retention problem.


I had provided navigation buttons, shuffle button and Rate button at bottom of the screen for this App. Since there is no space available for adding any additional button, I decided to add Tool bar / Action bar menu for including Night Mode feature.

I added the Toolbar by including below piece of code in the layout xml file of the main activity.

<androidx.appcompat.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"

/>
Then changed the Apptheme as Theme.AppCompat.DayNight.NoActionBar


And, then called setSupportActionBar at the starting of the onCreate in the main activity.

//for showing Toolsbar/Action bar
Toolbar my_toolbar = findViewById(R.id.my_toolbar);
setSupportActionBar(my_toolbar);

Then I created, menu.xml to include the menu items.  I added few other menu items in addtion to the Night Mode menu.


<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:id="@+id/menuNightMode"
android:title="Change Night Mode" />

<item
android:id="@+id/menuBooks"
android:title="Quotes Books" />

<item
android:id="@+id/menuVideo"
android:title="Quotes Video" />
<item
android:id="@+id/menuPrivacy"
android:title="Privacy" />
</menu>

Added below function for creating the menu by populating the menu items.

//For showing Tool bar menu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu, menu);
return true;
}

For implementing the menu action, I added below piece of code.

@Override
public boolean onOptionsItemSelected(MenuItem item) {

switch(item.getItemId()){
case R.id.menuNightMode:
if (AppCompatDelegate.getDefaultNightMode()==AppCompatDelegate.MODE_NIGHT_YES) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);

}
this.recreate();
break;

case R.id.menuBooks:
open_url("https://www.thequotes.net/motivational-ebook/");
break;

case R.id.menuVideo:
open_url("https://www.youtube.com/watch?v=7pfwBa9Ibvw");
break;
case R.id.menuPrivacy:
open_url("https://www.blog.qualitypointtech.com/p/android-app-privacy-policy.html");
break;


}
return true;
}

I used AppCompatDelegate for setting the Night Mode option. I came to know that the Night mode change will come into the effect only after restarting the Activity. I spent a lot of time in adding code for restarting the activity without losing the state.
Finally, I found that it can be done by just using recreate() method.

It was working properly. i-e The current page was brought back while restarting the activity. But I found a problem when using Shuffle button. It was not keeping the shuffled order after the restart. So, I included the suffled data into the savedInstanceState bundle by overriding onSaveInstanceState.

protected void onSaveInstanceState(Bundle savedInstanceState) {

super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putStringArray("pagedata", pageData);

}
And, within onCreate(), I included below piece of code the load the shuffled quotes when restarting the Activity.

//Get the data to be swiped through
if (savedInstanceState != null) { //reload the quotes to keep the same order when restarting the activity
pageData=savedInstanceState.getStringArray("pagedata");
}
else //load data first time only
{
pageData = getResources().getStringArray(R.array.quotes);
}
Now I hope everthing is working fine. Let me know if you find any error.

As I explained in my previous post, I added clickable links to the Authors. It will help the App Users to know more about the Author of the Quote and read more Quotes of that Author.

I had to work really hard to add the Author links to around 900 Quotes. Let me know if you find any incorrect or broken links.

And, I optimized the code to reduce the file size as explained in my previous post. I replaced the Android support libraries with equivalent AndroidX libraries

You can install/update the app from Google Play Store here

Let me know if you have find any error when using this App. And, if you like this app, Review/Rate it and refer this to your Friends.

I am planning to add the Night Mode feature to my other apps also.

Read more ...

Search This Blog