(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| import android.support.v4.app.Fragment; | |
| public class FragmentUtils { | |
| /** | |
| * @param fragment | |
| * The Fragment whose parent is to be found | |
| * @param parentClass | |
| * The interface that the parent should implement | |
| * @return The parent of fragment that implements parentClass, |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| package com.github.manuelpeinado.toolbartest; | |
| import android.graphics.Color; | |
| import android.graphics.drawable.Drawable; | |
| import android.os.Bundle; | |
| import android.support.v7.app.ActionBarActivity; | |
| import android.support.v7.widget.Toolbar; | |
| import android.view.Menu; | |
| import android.view.View; |
| import android.support.v7.widget.RecyclerView; | |
| import android.view.View; | |
| import android.view.ViewGroup; | |
| import android.widget.Button; | |
| import android.widget.TextView; | |
| /** | |
| * Created by khaled bakhtiari on 10/26/2014. | |
| * <a href="http://about.me/kh.bakhtiari"> | |
| */ |
| import android.support.v7.widget.LinearLayoutManager; | |
| import android.support.v7.widget.RecyclerView; | |
| public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener { | |
| public static String TAG = EndlessRecyclerOnScrollListener.class.getSimpleName(); | |
| private int previousTotal = 0; // The total number of items in the dataset after the last load | |
| private boolean loading = true; // True if we are still waiting for the last set of data to load. | |
| private int visibleThreshold = 5; // The minimum amount of items to have below your current scroll position before loading more. | |
| int firstVisibleItem, visibleItemCount, totalItemCount; |
| // Make a custom Gson instance, with a custom TypeAdapter for each wrapper object. | |
| // In this instance we only have RealmList<RealmInt> as a a wrapper for RealmList<Integer> | |
| Type token = new TypeToken<RealmList<RealmInt>>(){}.getType(); | |
| Gson gson = new GsonBuilder() | |
| .setExclusionStrategies(new ExclusionStrategy() { | |
| @Override | |
| public boolean shouldSkipField(FieldAttributes f) { | |
| return f.getDeclaringClass().equals(RealmObject.class); | |
| } |
| /** | |
| * Custom Scroll listener for RecyclerView. | |
| * Based on implementation https://gist.github.com/ssinss/e06f12ef66c51252563e | |
| */ | |
| public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener { | |
| public static String TAG = "EndlessScrollListener"; | |
| private int previousTotal = 0; // The total number of items in the dataset after the last load | |
| private boolean loading = true; // True if we are still waiting for the last set of data to load. | |
| private int visibleThreshold = 5; // The minimum amount of items to have below your current scroll position before loading more. |
| # Backup | |
| docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql | |
| # Restore | |
| cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE | |
Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.