Which Android Dependency Injection is best?

This post is a summary of first impressions of a few android related frameworks that we (Tell Me How Blog) tried out during a competences session recently.

What is Android Dependency Injection?

Dagger

“Dagger constructs instances of your application classes and satisfies their dependencies. ”
Dagger is a dependency injection framework, unfortunately most of us did not manage to setupdagger or failed to get dagger running once setup. So I can not give a proper overview of dagger2.
Read more: http://google.github.io/dagger/

Butterknife

“Annotate fields with @InjectView and a view ID for Butter Knife to find and automatically cast the corresponding view in your layout.”
Butterkife is a view injection lib for android. As such it only handles injection of view components and does this using a InjectView annotation. So some boilerplate is removed and less code has to be written. Some of us found the result a bit harder to read and in some cases the reduction of code was not noticeably, but this is most likely true for the other injection frameworks to and not something specific for Butterknife. Setup was easy with just one dependency. Stack-traces was reportedly difficult to read when Butterknife was used.
Read more: http://jakewharton.github.io/butterknife/

RoboGuice 3

“RoboGuice 3 takes the guesswork out of development. Inject your View, Resource, System Service, or any other object, and let RoboGuice 3 take care of the details.”
RoboGuice 3 is similar to AndroidAnnotations and Butterknife, easy to setup, two dependency’s needs to be added to the build file. This framework seems like it should be easy to use if you are already familiar with Guice, and even if you don’t its not that hard to understand and use. It is similar to the other dependency injection frameworks that you don’t get all that much for your money, but it’s easy to use and removes some boilerplate. The documentation could use a touch-up.
Read more: https://github.com/roboguice/roboguice

Final Verdict:

The views on the frameworks above is the result of a 3 hour session where we tried them out and had a short discussion about each of them to sum up the experiences. Given the limited time we spent on each of the frameworks we might have missed some important things, if you find and mistakes or are missing some important information please post a comment below.

Read more >> Comparison of All Android Dependency Injection 

Advertisements

MVC V/s MVP V/s MVVM

The user interface often contains a lot of cluttered code primarily because of the complicated logic it needs to handle. The presentation patterns are design primarily with one objective in mind, reducing the complex code in the presentation layer and making the code in the user interface clean and manageable.

In this post, I will present a discussion on the MVC, MVP, and MVVM design patterns and highlight when one should be the design of choice over the other.

Model View Controller

The Model View Controller (commonly known as MVC) framework helps you to build applications that are easier to test and maintain. It comprises of three major components, namely:

  1. Model — this is the layer that represents the application’s data
  2. View — this represents the presentation or the user interface layer
  3. Controller — this layer typically contains the business logic of your application

The primary objective of the MVC design pattern is separation of concerns to facilitate testability. The Model View Controller design pattern enables you to isolate the concerns and makes your application’s code easier to test and maintain. In a typical MVC design, the request first arrives at the controller which binds the model with the corresponding view. In the MVC design pattern, the view and the controller makes use of strategy design and the view and the model are synchronized using the observer design. Hence, we may say that MVC is a compound pattern. The controller and the view are loosely coupled and one controller can be used by multiple views. The view subscribes to the changes in the model.

Model View Presenter

The MVP (Model View Presenter) design pattern also comprises of three components – the model, the view and the presenter. In the MVP design pattern, the Controller (in MVC) is replaced by the Presenter.

You can see : Android MVP Pattern Example

Unlike the MVC design pattern, the Presenter refers back to the view due to which mocking of the view is easier and unit testing of applications that leverage the MVP design pattern over the MVC design pattern are much easier. In the MVP design pattern, the presenter manipulates the model and also updates the view. There are two variations of this design. These include the following.

  1. Passive View — in this strategy, the view is not aware of the model and the presenter updates the view to reflect the changes in the model.
  2. Supervising Controller — in this strategy, the view interacts with the model directly to bind data to the data controls without the intervention of the presenter. The presenter is responsible for updating the model. It manipulates the view only if needed — if you need a complex user interface logic to be executed.

While both these variants promote testability of the presentation logic, the passive view variant is preferred over the other variant (supervising controller) as far as testability is concerned primarily because you have all the view updated logic inside the presenter.

The MVP design pattern is preferred over MVC when your application needs to provide support for multiple user interface technologies. It is also preferred if you have complex user interface with a lot of user interaction. If you would like to have automated unit test on the user interface of your application, the MVP design pattern is well suited and preferred over the traditional MVC design.

Model – View – ViewModel (MVVM)

The Model – View – ViewModel (MVVM) is a variation of Martin Fowler’s Presentation Model design pattern. The MVVM is a refinement of the popular MVC design and the ViewModel in MVVM is used to facilitation Presentation Separation. In the MVVM the logic is stored in the presenter and the view is completely isolated from the model.

See this : Top 10 Programming Architectural Patterns

While the presenter isn’t aware of the view, the view is aware of the presenter — the presenter in MVVM is used to represent an abstract view of the user interface. A passive view implies that the view doesn’t have any knowledge of the model. In the MVVM design pattern, the View is active and contains behaviors, events and data binding information. Note that the view in MVVM is not responsible for managing the state information — the view is rather synchronized with the viewmodel. The viewmodel in MVVM is responsible for presentation separation and exposes methods and commands to manage the state of a view and manipulate the model.

How does the view and the viewmodel in MVVM communicate? Well, the view and the viewmodel in MVVM communicates using methods, properties and events. The bi-directional databinding or the two way databinding between the view and the viewmodel ensures that the models and properties in the viewmodel is in sync with the view. The MVVM design pattern is well suited in applications that need support for bi-directional databinding.

Google Play Protect – New Security features 

Thanks to the increasing number of security holes and increased number of cyber attacks, protecting your phone is more important than ever before.

Google knows this so they’ve begun rolling out Google Play Protect which was originally announced at I/O 2017.

Essentially a part of the company’s existing security services, Google Play Protect begins rolling out today to Google Mobile Services 11 and up. You can find out which version of Google Mobile Services your device is running by heading to Settings > Google > Security > Verify Apps.

You can read some comparison with Google Oreo :

Compared to the existing security services,Play Protect is more visible and better highlights the security it’s providing.

Google says it will automatically scan apps from the Play Store that are installed on your phone to ensure they’re safe; any apps that don’t measure up will either be blocked or removed from your device.

Play Protect is still rolling out to the Google Play Store and will appear in the Updates section.  Apps will soon also include a “Verified by Google Play Protect” badge to help reassure you.

The security system that never sleeps

Google Play Protect continuously works to keep your device, data and apps safe. It actively scans your device and is constantly improving to make sure that you have the latest in mobile security. Your device is automatically scanned around the clock to give you peace of mind.

One less worry for over a billion users

Backed by the strength of Google, Play Protect brings control to your fingertips while giving guidance along the way. Together, we lay out the ideal security blanket for your mobile device. Consider yourself covered.

Control within reach, even if your device isn’t

If you’ve misplaced your device, just take a breath. Find My Device has you covered. You can locate your device by signing into your Google account, or even call it directly from your browser. Lock your phone remotely or display a message on the lock screen, so that if someone finds it they know whom to contact. If you’re convinced it’s lost for good, you can erase all your data. Crisis averted.

Kotlin Pitfalls and How to remove them? 

Kotlin is all the rage lately. And while I do agree that the language is well thought out, it does have — as with everything else — its flaws.

As we already discuss about disadvantage of Kotlin but today in this article I’ll explain some of the Kotlin problems I encountered and try to help you avoid them.

You have to see : Advantage and why you should switch to Kotlin

Top 9 Kotlin problems with their solution:

The mystery null

Image result for null

In Kotlin you can write your code as if null never existed and this can make you forget that null is omnipresent but it hides. Let’s look at this simple and seemingly innocent class:

  1. class Foo {
  2. private val c: String
  3. init {
  4. bar()
  5. c = “”
  6. }
  7. private fun bar() {
  8. println(c.length)
  9. }
  10. }

If you try to instantiate this, you’ll get a NullPointerException because bartried to access the length of c before it was initialized.

Of course the application logic was flawed here, but you still got an Exception. The worst part of this is that your IDE won’t complain about this.

The takeaway here is that Kotlin will help you in a lot of cases (nearly all) to avoid null, but you can’t forget about it and from time to time you’ll encounter things like this.

For every Kotlin developer : Top 20 Daily used Kotlin Code Snippet

Handling nulls from the JDK

Image result for Handling nulls

Kotlin’s standard library handles nulls fine. But if you use classes from the JDK, you will have to handle possible null pointers from library functions by hand.

Most of the time the Kotlin classes are enough, but sometimes you have to use something like the ConcurrentHashMap:

  1. val map = ConcurrentHashMap<String, String>()
  2. map[“foo”] = “bar”
  3. val bar: String = map[“foo”]!!

In this case, you have to use the !! operator. But in other cases the nullsafety operator (?) can also work. Nevertheless, if you use Java libraries extensively you’ll have to litter your code with !!s and ?s or write adapters for Java classes. This is something you can’t really avoid.

There’s another more hideous problem you might bump into. When using methods on JDK classes, they can return null and don’t have syntactic sugar like the Map access above.

Source: Kotlin Problems and How to avoid them? 

How to Implement Vega Scroll Layout Android Slider?

Vega Scroll Layout is a lightweight animation flowlayout which fade and shrink the head itemView when scrolling.

example-plain

How i found Vega Scroll Layout library?

As you can see in above image its cool effect for your scroll layout and i used this library in my current project which is based on trading data. Previously we discuss infinite scroll in Kotlin and my author partner Ponglang Petrung suggest about Android DiscreteScrollViewto used for this. But i was looking for something new effect and after half hour googling i found Vega Scroll Layout library on dribble. And i am sharing tutorial on this with you.

Demo

 Example of Vega Scroll Layout Androidq

Source: Vega Scroll Layout Android Slider 

What is Android Rich Path Animator?

Animation in Android is a best way to give a valuable UI in any application. So today i am going to how to implement Android rich path animator which can draw as you want animate much as you can.

What is Android Rich Path Animator?

How to implement Android Rich Path Animator?

This library define in simple three line:

💪 Rich Android Path.

:clown_face: Draw as you want.

🎉 Animate much as you can.

That line is sufficient to tell much more about Android Rich Path Animator and now we dive in implementation of this library.

Source: Implement Android Rich Path Animator 

How to Create Android Topbar Menu with Guillotine animation?

How to Create Android Topbar Menu with Guillotine animation? Have you ever wondered why a sidebar in apps has to be a “side” bar? Why not to make it a “topbar,” or a “bottombar,” or a “cornerbar,” etc.?

Do you know : How to add Android Jelly Toolbar Animation?

A new animated trend in the generation of navigation bars is what we are going to talk about this time. Animations are fun but most importantly, they are useful. They can change your way of thinking, make your product catchy, and improve user experience.

Android Topbar Menu with Guillotine animation
Android Topbar Menu with Guillotine animation

“From time to time every designer gets bored. All these fixes, cuts, specifications – they leave very little space for imagination. In these minutes I feel like opening my Adobe After Effects and creating something interesting.

You should read : Uber Car Animation in Android

When I started thinking about what to create this time, I caught myself on a thought that a typical sidebar menu which sadly gets out of the left part of the screen moving all content to the right, is so unbearably boring! What if a sidebar becomes a topbar?

It’s going to drop down from the top of the page and turn in a unique way. Sounds like fun, doesn’t it?”

Source: Create Android Topbar Menu with Guillotine animation