Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to gradle 3.0.0 and replace Handler with runonUiThread for ConcurrencyDemoFragment #112

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
buildscript {
repositories {
// mavenCentral()
mavenCentral()
jcenter()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.6.0'
classpath 'me.tatarka:gradle-retrolambda:3.7.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
}

Expand Down Expand Up @@ -38,7 +38,7 @@ dependencies {

compile "android.arch.lifecycle:runtime:${archComponentsVersion}"
compile "android.arch.lifecycle:extensions:${archComponentsVersion}"
kapt "android.arch.lifecycle:compiler:${archComponentsVersion}"
kapt "android.arch.lifecycle:compiler:${archComponentsVersion}"

// ----------------------------------
// Rx dependencies
Expand Down Expand Up @@ -90,4 +90,5 @@ android {
packagingOptions {
pickFirst 'META-INF/rxjava.properties'
}
buildToolsVersion '26.0.2'
}
70 changes: 36 additions & 34 deletions app/src/main/java/com/morihacky/android/rxjava/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,59 @@
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;

import com.morihacky.android.rxjava.fragments.MainFragment;
import com.morihacky.android.rxjava.fragments.RotationPersist1WorkerFragment;
import com.morihacky.android.rxjava.fragments.RotationPersist2WorkerFragment;
import com.morihacky.android.rxjava.rxbus.RxBus;

public class MainActivity extends AppCompatActivity {

private RxBus _rxBus = null;
private RxBus _rxBus = null;

@Override
public void onBackPressed() {
super.onBackPressed();
_removeWorkerFragments();
}
@Override
public void onBackPressed() {
super.onBackPressed();
_removeWorkerFragments();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.replace(android.R.id.content, new MainFragment(), this.toString())
.commit();
if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.replace(android.R.id.content, new MainFragment(), this.toString())
.commit();
}
}
}

// This is better done with a DI Library like Dagger
public RxBus getRxBusSingleton() {
if (_rxBus == null) {
_rxBus = new RxBus();
// This is better done with a DI Library like Dagger
public RxBus getRxBusSingleton() {
if (_rxBus == null) {
_rxBus = new RxBus();
}

return _rxBus;
}
return _rxBus;
}

private void _removeWorkerFragments() {
Fragment frag =
getSupportFragmentManager()
.findFragmentByTag(RotationPersist1WorkerFragment.class.getName());
private void _removeWorkerFragments() {
Fragment frag =
getSupportFragmentManager()
.findFragmentByTag(RotationPersist1WorkerFragment.class.getName());

if (frag != null) {
getSupportFragmentManager().beginTransaction().remove(frag).commit();
}
if (frag != null) {
getSupportFragmentManager().beginTransaction().remove(frag).commit();
}

frag =
getSupportFragmentManager()
.findFragmentByTag(RotationPersist2WorkerFragment.class.getName());
frag =
getSupportFragmentManager()
.findFragmentByTag(RotationPersist2WorkerFragment.class.getName());

if (frag != null) {
getSupportFragmentManager().beginTransaction().remove(frag).commit();
if (frag != null) {
getSupportFragmentManager().beginTransaction().remove(frag).commit();
}
}
}

}
50 changes: 26 additions & 24 deletions app/src/main/java/com/morihacky/android/rxjava/MyApp.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
package com.morihacky.android.rxjava;

import android.support.multidex.MultiDexApplication;

import com.morihacky.android.rxjava.volley.MyVolley;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;

import timber.log.Timber;

public class MyApp extends MultiDexApplication {

private static MyApp _instance;
private RefWatcher _refWatcher;
private static MyApp _instance;
private RefWatcher _refWatcher;

public static MyApp get() {
return _instance;
}
public static MyApp get() {
return _instance;
}

public static RefWatcher getRefWatcher() {
return MyApp.get()._refWatcher;
}
public static RefWatcher getRefWatcher() {
return MyApp.get()._refWatcher;
}

@Override
public void onCreate() {
super.onCreate();
@Override
public void onCreate() {
super.onCreate();

if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return;
}
if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return;
}

_instance = (MyApp) getApplicationContext();
_refWatcher = LeakCanary.install(this);
_instance = (MyApp) getApplicationContext();
_refWatcher = LeakCanary.install(this);

// for better RxJava debugging
//RxJavaHooks.enableAssemblyTracking();
// for better RxJava debugging
//RxJavaHooks.enableAssemblyTracking();

// Initialize Volley
MyVolley.init(this);
// Initialize Volley
MyVolley.init(this);

Timber.plant(new Timber.DebugTree());
}
Timber.plant(new Timber.DebugTree());
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.morihacky.android.rxjava.fragments;

import android.support.v4.app.Fragment;

import com.morihacky.android.rxjava.MyApp;
import com.squareup.leakcanary.RefWatcher;

public class BaseFragment extends Fragment {

@Override
public void onDestroy() {
super.onDestroy();
RefWatcher refWatcher = MyApp.getRefWatcher();
refWatcher.watch(this);
}
@Override
public void onDestroy() {
super.onDestroy();
RefWatcher refWatcher = MyApp.getRefWatcher();
refWatcher.watch(this);
}
}