5 notes on MVP architecture pattern for Android

                                                           Image credits Macoscope

MVP (Model View and Presenter) is an architectural pattern inspired by the popular MVC pattern.

MVP addresses two main points :

  1. Make views as dumb as possible. The dumber the better.
  2. Make each layer loosely coupled and easily testable in isolation.

I am using MVP in one of my production project and have used in some dem0 apps. Here are my 5 notes on using MVP for android.

  1. Package Structure :

Android project contains lots of code and files even for application of medium complexity. Even when not following MVP I have found that arranging the project files in such a way that files that are accessed together are put in same package is more efficient and intuitive than any other approach.

What I prefer doing is create separate package for separate verticals of the app and put all related files like activities, fragments, views, presenters, adapters etc in that package.

ex. packages like add task, view task, list task for a To-Do app.

2. Libraries that are useful for MVP :

In MVP you want your model and presenter to be independent of the life cycle of view. For this, you can use dependency injector library like Dagger2.

Other than that, using RxJava and reactive programming principles for creating presenter is also becoming increasingly popular.

Libraries you can use for this purpose are : RxAndroid and EventBus.

3. Managing Remote and local data sources in the Model :

Android apps have to fetch data from the server. At the same time fetched data must be cached to make the app usable offline and increase the speed.

What I prefer doing is to create three model classes :

1. Remote Data Source

2. Local Data Source

3. Data Repository

All presenters talk to Data Repository class. Data repository model contains references to Local and Remote data repository and calls data from either according to situation.

As the name suggests Local Data Source deals with cached data and disk storage whereas Remote Data Source deals with API calls and responses.

4. User Experience is the top priority :

One thing that we all have to keep in mind that the real test of application is, if it is able to provide user a nice experience.

At the end of the day, user only notices the user experience of the application and not the architecture used. So if you have to make some design sacrifices to make the UX better, do it.

The real test of the machine is the satisfaction it provides to the mind. There is no other bigger test.

5. Testing Advantages :

Main motive behind MVP pattern was to make the testing of layers easy.

Basic idea is to keep the presenter and model android free, so that they can be tested without Android instrumentation by the JVM itself.

Views can then be tested by Android Instrumentation tests.

Mockito and Espresso can come handy for testing purposes.

Conclusion :

MVP, in my opinion is so far the best way to architect your android application project. It simplifies many issues like testing and making views lighter. Combine it it RxJava and dependency injection and you’ve got a nice recipe for android projects.

I am learning more about RxJava and testing frameworks will share my views on that soon.

Thanks.

Rise and Shine : How joining the 5 AM club affected my life

Being an early riser isn’t about trumpeting how hard you work. It’s about doing everything within your power to help your business achieve success; and if that means you have to get up at an hour not known to most, then you might as well enjoy the sunrise.

It is no secret that many high achievers have been advocating about the importance of waking up early in the morning. I have been following Robin Sharma for quite some time now and he proposes something called as the “5 AM club”. He refers it is as the elite club of people who wake up at 5 AM, each day and try to get the most out of the day.

I took the challenge for myself to wake up at 5 AM every day without fail for the entire month of November as a habit building process. I believe that against all the odds if you can sustain the habit for 1 month, you can stick with it for a longer time. That is the power of habit.

Becoming an early riser

It was obviously not easy to become an early riser. I had a typical teenager schedule prior to this. Stay up late till 2 AM and then sleep till 10 AM.

The first step I took was to decrease the waking up time gradually. Reducing it by 1 hour every 3 days.

I needed some additional help anyways. I asked one of my friends to wake up at 5 AM (Saumya this is you :P). If someone is holding you accountable for something, there is always a push to do it.

How waking up at 5 AM affected my mind and life?

  1. It allows me to enter the flow state : You get up early in the morning, no one is up. Enough time to do self-introspection and follow the morning rituals to get in the mood to conquer the world.
  2. Intrinsic motivation : When you get stuff done in the morning itself. It acts as an intrinsic motivation to keep going. You are optimistic and energetic for the entire day.
  3. Self-discipline : I started this challenge at the worst time. Cold November mornings. It took me a lot of mental strength to get out of warm bed to cold weather. But in the end, it was all worth it.

My new “Early Birdie” morning rituals

I wake up at 5 AM nowadays, and seldom fail at that.

5:30 to 7:30 is the time set apart for personal improvement. No email, no internship work, no college studies. Working on skills that you want to see yourself doing better with.

7:30 to 8:30 I exercise. Again the importance of exercising can not be emphasized more to become a high achiever. It gives more energy that is always helpful.

Then around 9 I start working and go forward with the day.

11 PM is the time to call the day and prepare for tomorrow. No mobile phone to bed and doze off at 11:30.

Do we all have to wake up at 5?

Yes and no. Though I certainly recommend it to try being the member of the 5 AM club at least once. Experience the hours of the day that are not known to most. Feel the sunrise and early morning serenity. It is a different kind of experience, a zen on its own.

How to detect emails, phone numbers, web URLs, hashtags in Android TextView? : SmartTextView library

Smart Text View

Star On GitHub Follow On GitHub

Many applications in android use TextView that detects and highlight various string patterns like emails, phone numbers, web URLs and even hashtags.

This functionality is very common and and is used extensively and frequently in many app. Thus to ease the process of adding this functionality I have authored an Android library SmartTextView.

Find and Star it on GitHubhttps://github.com/priyankvex/SmartTextView

smart_text_view_small

Features

  • Detect emails, mobile numbers, URLs
  • Detect #hash_tags and @mentions
  • Use default intents or set custom callbacks.
  • Set different colors for each pattern.

 

Usage

compile 'com.priyankvex:smarttextview:1.0.1'

In layout xml file

  <com.wordpress.priyankvex.smarttextview.SmartTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="9pt"
        android:id="@+id/textView"
        />

In java Activity or Fragment

mSmartTextView = (SmartTextView) findViewById(R.id.textView);
        mSmartTextView.setEmailColorCode("#3cb371");
        mSmartTextView.setPhoneNumberColorCode("#ff33aa");
        mSmartTextView.setHashTagColorCode("#f37735");
        mSmartTextView.setUrlColorCode("#ffc425");
        mSmartTextView.setMentionColorCode("#57b884");
        mSmartTextView.setDetectMentions(true);
        mSmartTextView.setDetectHashTags(true);
        mSmartTextView.setText(sampleText);
        mSmartTextView.setSmartTextCallback(this);

To use custom callbacks

implements SmartTextCallback

IIMBx: EP101x DO Your Venture : Course Experience on edX

The best way to win is to show grit and bid on your strengths and intuitions. I have been trying to start my own company now for quite a some time. This course came into my mail box by edX, title looked captivating and thus I decided to take it.

It was a light course. Not much effort needed other that just watching the videos and doing some assignments.

The course was focused on making people get off with their venture from the idea phase to execution phase.

Throughout the course I was evaluating  my ideas and operations using the learnings given by the course and it has been of some help at least.

The course was divided into 5 weeks :

Week 1 : The “Do” Philosophy 

DO philosophy is based on “do or do not. There is no try”. There is a gap between intent and action and thus best bid is to don’t wait for halcyons days and just DO IT.

It proposed a term equifinality which means that every entrepreneur and his path is different and there are many ways to entrepreneurship.

It then provided interviews with various startups like Bums On Saddle, Hobby in a Box etc founders sharing their journey so far.

Week 2 : Opportunities, Idea Creation & Generation!

This week was focused on how entrepreneurs come up with ideas. Few of them are  :

  • Hobby driven ideas
  • Painstorming
  • Change in some rules and regulations

Each of these points can provide you with a nice venture idea. I already had my idea prior to the course and thus just thought about it again from these view points.

Week 3 : Idea validation and Evaluation

After the idea has been selected. We have got to validate and evaluate it.

Some if the methods for this are :

  • Personal feasibility
  • Market feasibility
  • Customer feedback

Best way to validate idea is to talk to customers. Real unknown customers. Not just people in your acquaintance. We here at Rainbow Shelf went out to talk to retail shop owners (around 10) and tried to explain them the idea. Response was not very encouraging but it was an experience that helped us.

Week 4 : Lean Canvas

This week was all about the lean methodology used in startups. I have read the book The Lean Startup  and thus this all made sense to me.

The 5 principles of lean startup are :

  1. Entrepreneurs are everywhere
  2. Entrepreneurship is management
  3. Entrepreneurship is validated learning
  4. Build, Measure, Learn
  5. Innovation Accounting

The course also provided a lean canvas that should be used by startup to assess their idea.

Week 5 : Effectuation

Effectuation, which is defined as a “logic of thinking, discovered through scientific research, used by expert entrepreneurs to build successful ventures“.

This week was about measuring the uncertainty in the entrepreneurship.

Effectuation has these 4 principles :

Bird in Hand Principle – Start with your means. Don’t wait for the perfect opportunity. Start taking action, based on what you have readily available: who you are, what you know, and who you know.

Affordable Loss Principle – Set affordable loss. Evaluate opportunities based on whether the downside is acceptable, rather than on the attractiveness of the predicted upside.

Lemonade Principle – Leverage contingencies. Embrace surprises that arise from uncertain situations, remaining flexible rather than tethered to existing goals.

Crazy-Quilt Principle – Form partnerships. Form partnerships with people and organizations willing to make a real commitment to jointly creating the future–product, firm, market–with you. Don’t worry so much about competitive analyses and strategic planning.

 

Overall. I wasn’t expecting very complex and hard material in the course just normal guidelines stuff and this was exactly what the course provided. This course was offered by IIMB. And showed many startups that are incubated there are NSRCEL.

As of now I have taken many scattered courses on entrepreneurship from University of Maryland to MIT to IIMB. Now i have decided to just take the specialization offered by Coursera  and that should be enough for time being until my company scales.

I have now shifted my focus to learn more core technical and domain knowledge that will be required to build remarkable company that can stand out that bring value to its customers.

 

How to Win Friends and Influence People : Reading Experience and Summary

How to win friends and influence people is an all time classic book. I got to know about this book from the Goodreads recommendations and instantly decided to read this one. It starts stating that leadership is 15% technical skills and 85% skill to manage human relations. This sentence alone suffices the need of this book.

What you can get out of the book?

  • Gives you new ways to carry on meaningful conversations.
  • Make lasting connections with people by influencing them.
  • Win new clients, customers and team members.
  • Increase your confidence while approaching people.
  • Make you a better salesman, entrepreneur and leader.

This book is filled with historical examples that the author uses that just exemplifies the principles stated in the book. This is not a light read and taking notes is necessary to get the most out of this book.

Here is the summary  :

PART 1 : Fundamental techniques in handling people

Chapter 1: Fundamental Techniques in Handling People

  • Don’t  criticize people or blame them for anything. It makes them go defensive.
  • Criticism hurts their pride and sense of importance.
  • “I’ll speak ill of no man and speak all the good I know” – Benjamin Franklin
  • Even Abraham Lincoln made it a point not to criticise anyone not even his commander who made a big blunder during war.
  • Principle 1 : Don’t criticize, complain or condemn. 

Chapter 2 :  The big secret of dealing with people

  • “The only way I can get you to do anything is by giving you what you want”
  • Biggest craving in humans is to be appreciated, to be complemented.
  • Fill people with encouragement and give them an incentive to work.
  • Sincere appreciation is one of the secrets of success of handling men.
  • Know the difference between flattery and sincere appreciation.
  • Flattery is selfish and counterfeit. Appreciation is from the heart.
  • Principle 2 : Give honest and sincere appreciation

Chapter 3: He who can do this holds the whole world with him. He who cannot walks a lonely way

  • Only way to influence people is to talk about what they want.
  • Try to see things from other person’s point of view.
  • Convince person how something that you want them to o can benefit them.
  • Arouse in other person an eager want.
  • Self expression is dominant necessity in human nature.
  • Always let the other person think that it is their idea.
  • Principle 3  : Arouse in other person an eager want

Part 2  : Ways To Make People Like You

Chapter 1 : Do this and you’ll be welcome anywhere

  • Try to be interested in people, not to make them interested in you.
  • Always be grateful and interested in customers in business.
  • Principle 1 : Become genuinely interested in other people.

Chapter 2 : A simple way to make a good impression

  • Show people by expression that you are happy to meet them.
  • Preserve the attitude of courage, frankness and good cheer.
  • Principle 2  : Smile

Chapter 3 : If you don’t do this, you are headed for trouble

  • People are more interested in their names than all the names put together.
  • Always make effort to call people by their name.
  • If you are executive then you have remember name.
  • Even Charles Schwab said that he tried to call his employees by their names.
  • Principle 3  : Remember that a person’s name is to that person the sweetest and most important sound in any language.

Chapter 4 : An easy way to become good conversationalist

  • Be a good listener and encourage people to talk
  • Stop everything and listen whole heatedly to people
  • Listening gives people a feeling of importance
  • Principle 4 : Be  a good listener. Encourage others to talk about themselves. 

Chapter 5  : How to interest people

  • Talk about thing they treasure the most
  • Author gives as example how appreciating a clients office got him the deal.
  • Principle 5  : Talk in terms of other people’s interests. 

Chapter 6  : How to make people like you instantly

  • Talk to people about themselves.
  • Talk about things they admire the most. This will make them feel important.
  • Principle 6 : Make the other person feel important and do it sincerely.

Part 3  : How to win people to your way of thinking

Chapter 1 : You can’t win an argument

  • Avoid arguments like you avoid rattlesnakes.
  • Arguments are futile to change someone’s mind.
  • To avoid arguments : welcome disagreement, distrust first instinct to go defensive, control your temper, listen first, look for areas of agreement,  apologize for your mistakes, promise to think over your point, thank opponent for their interest, postpone action to think.
  • Principle 1 : Only way to get most of an argument is to avoid it.

Chapter 2  : A sure way of making enemies and how to avoid it

  • If you are going to prove anything, don’t let the other person know it.
  • “Be wiser that the other people if you can, but don’t let them know it”
  • Never tell a person straight away that they are wrong.
  • Principle 2  : Show respect for the other person’s opinions. Never say “You are wrong”

Chapter 3  : If you are wrong, admit it.

  • Criticize yourself before some else does that.
  • This will make temper of the other person cool down
  • Principle 3 : If you are wrong admit if quickly and emphatically 

Chapter 4 : A drop of honey

  • “A drop of honey catches more flies than a gallon of gall”
  • Always begin in friendly way and appreciate the other person.
  • A renter wanted his rent reduced so he first praised the apartment in which he was living.
  • Principle 4  : Begin in a friendly way.

Chapter 5 :  Secret of Socrates

  • In talking to people don’t begin by discussing things that you differ on.
  • Ask questions that makes your opponent say yes yes!
  • Principle 5  : Get the other person saying yes yes immediately.

Chapter 6 : The safety valve in handling complaints

  • Let the other people talk themselves out.
  • Even if you disagree don’t interrupt.
  • Principle 6 : Let the other person do a great deal of talking

Chapter 7 : How to get cooperation

  • People want to be consulted about their wants.
  • People want to buy/accept something on their own accord, not to be sold.
  • Make people believe that the idea is theirs.
  • Principle 7 : Let the other person feel that the idea is his/hers.

Chapter 8 : A formula that will work wonders for you

  • Always try to understand why a person would say something like this.
  • Try to think with the person’s point of view.
  • Principle 8 : Try honestly to see things from other person’s point of view.

Chapter 9 : What everybody wants

  • People are thirsting for sympathy – give it to them.
  • When a person is debating with you remember to react differently than the others.
  • Principle 9 : Be sympathetic with other person’s ideas and desires.

Chapter 10 : An appeal that everyone likes

  • Show the person the motives that sound good.
  • Principle 10 : Appeal to the nobler motives.

Chapter 11 : The Movies Do it. TV Does it. Why Don’t You Do it?

  • Stating truth is not enough. You have to dramatize them.
  • Make it vivid, impressive and interesting.
  • Principle 11 : Dramatize your ideas.

Chapter 12 :  When nothing else works try this

  • Make the work exciting and challenging.
  • Schwab invoked a challenge among morning and night shift workers to increase the efficiency of the factory.
  • Principle 12 : Throw down a challenge.

Part 4 : Be a Leader: How to Change People Without Giving Offense or Arousing Resentment

Chapter 1 : If you must find fault this is the way to begin

  • Say something pleasant before criticizing.
  • A barber always lathers a man before he shaves him.
  • Principle 1 : Begin with praise and honest appreciation.

Chapter 2  : How to criticize and not to be hated for it

  • Never use the word “but” after appreciation. It makes appreciation looks fake.
  • Use other words like “and”.
  • Principle 2 : Call attention to people’s mistake indirectly

Chapter 3 : Talk about your own mistakes first

  • Admit and talk about your own mistakes first before criticizing the other person.
  • Principle 3 : Talk about your own mistakes before criticizing the other person.

Chapter 4 : No one likes to take orders

  • Give suggestions instead if orders and you’ll hit the person’s pride less.
  • Involve people in the decision making by asking them questions.
  • Principle 4 : Ask questions instead of giving direct orders.

Chapter 5 : Let the other person save face

  • “I have no right to say or do anything that diminishes a man in his own eyes. “
  • Don’t belittle a person.
  • Principle 5 : Let the other person save face.

Chapter 6 : How to spur people to success

  • Praise every little improvement in the person.
  • Be hearty in your approbation and lavish in your praise.
  • Charles Dickens was once praised by a editor when he was poor little boy and it changed his life.
  • Principle 6  :  Praise the slightest improvement. Be hearty in your approbation and lavish in your praise.

Chapter 7 : Give a dog a good name

  • To change the person’s behavior give him a good reputation to live up to.
  • Example : “You are one if the best worker. Lately you’ve been slow. We know there is a reason. Let’s discuss it”
  • Principle  7 : Give the other person a fine reputation to live up to.

Chapter 8 : Make the fault seem easy to correct

  • Praise the person’s good point and make them feel that their faults are very minor.
  • Other wise you’ll destroy their will to improve.
  • Principle 8 : Use encouragement. Make fault  seem easy.

Chapter 9 : Making people glad to do what you want

  • Make people happy and excited about their job.
  • Show the person the benefits of the job.
  • Ask yourself what the other person really wants.
  • Principle 9 : Make the other person happy about doing the thing you suggest.

 

Business In Boxers 3 : The Psychological Roller Coaster

One of my favorite things about instrumental music is that the listener is encouraged to use his or her imagination. I have been a huge Owl City and Adam Young fan since forever. Lately he is releasing sets of instrumental music called as Adam Young Scores inspired by incidents that made a lasting impression on the world.  Reading about all those incidents has made a lasting impression on my mind for sure, our small failures and success doesn’t even matter to the world, we have got to make it large.

This month has been a wacky psychological roller coaster. A slow motion wave on the ocean stirring my emotion up like a rain cloud. When you are trying to start something new and you know odds are against you I guess this happens, you become very paranoid in some sense. Each blow shakes your confidence and you have to build that up again. It’s exhausting some time. Here is where a nice snack helps 😀

IMG_20160619_122004

At start of this month we all were very keen towards making the MVP (minimum viable product) ready but my mentor and CEO of the startup where I am working suggested to do a market research and look for idea validation. So one afternoon me and my friend visited few shops and tried to convey the idea to them . Very few got the idea and showed interest. I guess demography plays a vital role here. We all made peace with it that we will need real tangible product to make people excited about it.

But soon things got hard. Workload at intern got high and juggling both my startup and intern got really difficult. This made me think that how hard it would be to manage it with a full-time job. This was the first blow. And soon other members of team took off for exams or campus preparation or god knows what excuse.

Lately realized that to become good entrepreneur you should know the shit you are dealing with. Though I know that we learn stuff on the way, but still first we should invest in our-self. That’s why I am learning rails and other things needed to run the company. Attention to details will cause a momentarily pain in the ass. But it will be worth all the while.

As an overview all startups working on similar domain look the same. It is the one who really dig deeper and strive for great brand experience that makes all the difference. This what I believe in and want to do.

That’s why I took sales course before going to sellers for local survey. This is why I was studying business plan of Vinod Khosla to know and set my goals. This is why I am honing my technical skills. It all comes down to this, you should believe that whatever you are doing can be hard, but in the end it will be worth all the while.

I guess now we are on track now. Now that I have stopped counting on the members who were just pretending to be part of the team, I can be sure of what we can do in certain time. We are now clear to drop every operation and just build the damn product. Period. After 8 months I’ll be graduating and I want to be ready with a use-able product before that.

Meanwhile I am also trying to concrete the company goals. So that we can start moving. Breaking down to achievable goals with deadlines and metrics to measure how we are moving.

One more habit I am trying to develop is to write down my very specific goals for the day twice. In morning and at evening. It kinda helps you keep track. I have also started to workout and exercise more regularly than I used to, it’s good to do more of what makes you feel good about yourself because it reflects in all the other things that you do.

I am still not properly over of thinking whether I am making the right bets or not, I guess you can never tell. It like I am on emotional state of PMS.

But I know one thing for sure, whatever you do your job is to tell the story.

Thanks. See you next time.

 

 

Marketing Your Retail Store in the Internet Age by Bob Negen : Reading Experience

This was the book that I knew prior to reading it that it won’t be too interesting and might even feel too slow. I searched it on the internet and picked it to read to get a perspective of a retail seller. As me and my team are trying to start a company that will work very closely with retail stores and their owners I thought this book will provide some value.

What I liked about this book how it delivers simple and effective tactics that a store owner can use to create customer loyalty, make lasting seller-customer relationships and compete against online retail giants.

It compares getting customers to getting a girlfriend. They are demanding and they want to feel special or else they’ll move on.

It brings focus on few very effective retail techniques like bag stuffers and doughnut marketing. It also covers basics of copywriting and its importance.

What I didn’t like about the book was that it was too slow and dumb at times. As a young person who is aware of technology world you’ll feel few things too stupid to be covered in that detail in the book. May be that’s a better fit for old shop owners.

Overall it was a good read. Not as per my expectations but still can give you an image of a mind of a retailer.

I’ll definitely use the concepts of this book in my company as me and my team too believe that the best shopping experience for a customer can be provided at a local retail store. All they need  is a power up and better tools now.

My next book is “How to win friends and influence people”. Will share my experience about that too when’ll be done.

Thanks.