itstimetoact


Source link: https://github.com/seroperson/itstimetoact

Description

itstimetoact - it's an android library, inspired by once, that can help you with planning events in your awesome application. It requires api level >= 1, so can be used in any project.

Structure

As it's a very lightweight library, the core module hasn't anything except the base classes, but there is several additional modules with some tasty implementations included. Moreover, if you feel the lack of it, then flexible, awesome, simple and documentated API will help you with creating your own! For now the following modules are available:

  • itstimetoact-core - provides several base classes. Actually you may use only this module if you are going to implement all of your events and serialization/deserialization mechanism by yourself.
  • itstimetoact-serializable - implementation that uses java.io serializables to serialize/deserialize events. The main pros of this module that it hasn't any external dependencies (unlike the next one).
  • itstimetoact-gson - another one implementation that uses gson library to serialize/deserialize events. It is preferable to use this one over of previous one (especially if you already use gson in your project or if you are using your own event implementations).
  • itstimetoact-extras - the set of some useful event implementations, that, I hope, will satisfy most of your needs.

Usage

It will be great start to check the itstimetoact-sample module. If you too lazy for it, read the stuff below.

Initializing

Okay, let's start. Initially, you need to create TimeToAct instance. It can be performed in Application#onCreate or in Activity#onCreate(Bundle). Anyway, it fits great with something like dagger, so there is no much difference.

TimeToAct timeToActInstance = new GsonTimeToAct(this);
 // or SerializableTimeToAct

Restoring previous state

The next thing which you need to do is restore previous state. Even if it's a first run ever, you need to call this method:

timeToActInstance.loadEventData();

Keep in mind, that this method isn't async, so can stuck your UI-thread.

Action

Now you can write your code. Imagine, that all of next stuff were written in Activity#onCreate(Bundle).

For example, the following code will be executed after each application update:

ActEvent afterUpdateEvent = timeToActInstance.watchEvent(new AfterUpdateEvent(this, "key0"));
 if(afterUpdateEvent.isHappened()) {

  // ...
  // show changelog or something like that
  // ...
  timeToActInstance.watchLastDropped("key0");
 
}

The following code will be executed after five days:

ActEvent timeEvent = timeToActInstance.watchEvent(new TimeEvent(TimeUnit.DAYS.toMillis(5), "key1"));
 if(timeEvent.isHappened()) {

  // ...
  // show 'rate me' dialog
  // ... 
}

Next one will be executed only once per install:

OneShotEvent oneShotEvent = timeToActInstance.watchEvent(new OneShotEvent("key2"));
 if(!oneShotEvent.isHappened()) {

  // ...
  // show application tutorial
  // ...
  oneShotEvent.step();
 
}

You also can combine they together to describe more difficult situations. And as I said above, there is a flexible API, so you can implement your own awesome 'is happened' logic!

Now imagine the following situation. You have 'rate me' dialog (that must appears after two days since install) with three buttons: " Don't show again", " Reming me later", " Rate now". With the library it can be implemented like this (example from real application):

OneShotEvent neverShowClicked = timeToActInstance.watchEvent(new OneShotEvent(KEY_SHOW_RATE_ME));
 TimeEvent cycle = timeToActInstance.watchEvent(new TimeEvent(TimeUnit.DAYS.toMillis(2), KEY_SHOW_RATE_ME_CYCLE));
 if(!neverShowClicked.isHappened() && cycle.isHappened()) {

  // ...
  // some dialog creation logic
  // ...
  dialog.show(new DialogListener() {

@Override

protected void onViewCreated(View view) {

 applyListener(view, R.id.rate_no, this::dontShowAgain);

 applyListener(view, R.id.rate_later, () -> timeToActInstance.watchLastDropped(KEY_SHOW_RATE_ME_CYCLE));

 applyListener(view, R.id.rate_yes, () -> {

  openMarketPage();

  dontShowAgain();

 
}
);

}

 private void dontShowAgain() {

 neverShowClicked.step();

}

  
}
);
 
}

Working with sources

To assemble all of available targets:

./gradlew assemble

Or the following to run tests:

./gradlew test

Pull requests are welcome.

Download

Just include required line in your build.gradle

compile 'com.seroperson.itstimetoact:itstimetoact-core:0.2' compile 'com.seroperson.itstimetoact:itstimetoact-serializable:0.2' compile 'com.seroperson.itstimetoact:itstimetoact-gson:0.2' compile 'com.seroperson.itstimetoact:itstimetoact-extras:0.2'

Be sure that you included jcenter() in list of your repositories.

License

The MIT License (MIT)  Copyright (c) 2016 Daniil Sivak  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 

Resources

A cool beer styled progress view with realistic bubbles.

Simple test to see if all models in project correctly implement Parcelable.

Android Library for downloading and saving images from given URLs.

Minimized/Floating Youtube.

A nice swipe layout that provides new actions with a material design look and feel.

FireCrasher is designed to handle the Uncaught Exceptions in your android application and helps to recover without exiting from the application.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes