Discovering and enumerating with Metasploit

Metasploit is one of the best consoles for data gathering, as it is an exceptionally far-reaching penetration testing device. In this instructional tutorial, we are going to cover some…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Handle Search Using RXJAVA2 Android

Rx java is a reactive framework in which there will be Data Source(Observable) and there will be a guy who will listen to those changes(Observer)

Now let’s take one use-case, In our case, this will be Handling Search queries.

Below the operation, we will generally do while searching

Problem with traditional Approach:

The result of this would be zero readability, hard to maintain code, I will call this approach A Scary way.

Now let's focus What actually we want

That’s what actually we want but in the traditional way, your code will not say the same it will say lot’s of other things as well(throttling, threading), which is not right.

Now let's assume we have one data source which will produce data (Search queries) and one guy who is responsible for observing that data and take action (Make API/DB calls), Wasn’t that great if we will able to manage it like that somehow.

Now let’s try the above approach using Rx-Way

2. And Suppose we are querying it for Contacts, And there is one UseCase called GetContacts which take a query and call repository to give queried contacts.

3. There is repository Called ContactRepository which will handle all contact related data operation (Insertion, Deletion, Update, Get)

4. To Handle Logic according to UI state change we have one presenter called ContactPresenter, which will take Query Data Source and view interface, to communicate it with corresponding Activity/Fragment/or Platform View.

Now It’s time for the final touch, here we will setup presenter and render the result

Code Flow

So In the code above QueryTextWatcher is our Data source which contains query data and Contact Presenter is the guy who is using that data and calling UseCase to fetch contacts and once we get the data we are notifying it to the activity via presenter

Now let’s check, is this what we actually wanted

Looks like we achieved what actually we wanted, also our code becomes much cleaner, readable and Organized.

Cheers… Happy Coding :)

Add a comment

Related posts:

I learned how to beat meat and so can you!

My understanding of a blog is to impart my wisdom onto a reader, I would be incorrect in describing my life as perfect or something to model after. I am no expert on life, food, or organizing linen…

Rapid Research

Why is rapid user research the essence to truly successful product development? In times of exponential growth of digital connectivity and information overload, we are experiencing a constant flow of…

Like a Bridge over Troubled Water

Bridges are marvelous architectural works, fascinating structures that connect two different pieces of land. But bridges could also be an interesting metaphor to describe an invisible connection…