This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainEmptyActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
Intent activityIntent; | |
// go straight to main if a token is stored | |
if (Util.getToken() != null) { | |
activityIntent = new Intent(this, MainActivity.class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class LiveDataBus { | |
private static SparseArray<EventLiveData> sSubjectMap = new SparseArray<>(); | |
public static final int SUBJECT_DATA_LOADED = 0, SUBJECT_DOWNLOAD_COMPLETE = 1; | |
@Retention(SOURCE) | |
@IntDef({SUBJECT_DATA_LOADED, SUBJECT_DOWNLOAD_COMPLETE}) | |
@interface Subject { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable.fromCallable(() -> { | |
Request request = new Request.Builder() | |
.url(url) | |
.build(); | |
try { | |
Response response = sHttpClient.newCall(request).execute(); | |
return response.isSuccessful(); | |
} catch (IOException e) { | |
Log.e("Network request", "Failure", e); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<android.support.constraint.ConstraintLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<android.support.constraint.Guideline | |
android:id="@+id/guideline1" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:orientation="vertical" | |
app:layout_constraintGuide_percent="0.25"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EventLiveData extends LiveData<Object> { | |
private final int mSubject; | |
private final LifecycleRegistryOwner mLifecycle; | |
public EventLiveData(@LiveDataBus.Subject int subject, @NonNull LifecycleRegistryOwner lifecycle) { | |
mSubject = subject; | |
mLifecycle = lifecycle; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EventLiveData extends LiveData<Object> { | |
private final int mSubject; | |
public EventLiveData(@LiveDataBus.Subject int subject) { | |
mSubject = subject; | |
} | |
public void update(Object object) { | |
postValue(object); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Example Activity | |
public class MyActivity extends BaseActivity { | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.myactivity); | |
// with lambda | |
LiveDataBus.subscribe(LiveDataBus.SUBJECT_DATA_LOADED, this, (data) -> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ZooDAO { | |
private static Box<Zoo> getZooBox() { | |
BoxStore boxStore = App.getBoxStore(); | |
return boxStore.boxFor(Zoo.class); | |
} | |
public static DataSubscription subscribeToZooList(DataObserver<List<Zoo>> observer) { | |
return getZooBox().query().build().subscribe().on(AndroidScheduler.mainThread()).observer(observer); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Will process the data with the callable by splitting the data into the specified number of threads. | |
* <b>T</b> is ths type of data being parsed, and <b>U</b> is the type of data being returned. | |
*/ | |
public static <T, U> Iterable<U> parseDataInParallel(@NonNull List<T> data, Function<List<T>, ObservableSource<U>> worker) { | |
int threadCount = Runtime.getRuntime().availableProcessors(); | |
ExecutorService threadPoolExecutor = Executors.newFixedThreadPool(threadCount); | |
Scheduler scheduler = Schedulers.from(threadPoolExecutor); | |
AtomicInteger groupIndex = new AtomicInteger(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Used for subscribing to and publishing to subjects. Allowing you to send data between activities, fragments, etc. | |
* <p> | |
* Created by Pierce Zaifman on 2017-01-02. | |
*/ | |
public final class RxBus { | |
private static SparseArray<PublishSubject<Object>> sSubjectMap = new SparseArray<>(); | |
private static Map<Object, CompositeDisposable> sSubscriptionsMap = new HashMap<>(); |
NewerOlder