Skip to content

Commit

Permalink
Migrate to AndroidX
Browse files Browse the repository at this point in the history
Major update to add support to `androidx` libraries, fixed all broken imports and tests.
  • Loading branch information
pzagalsky authored Apr 3, 2020
2 parents b56eba4 + af78faa commit ecdc624
Show file tree
Hide file tree
Showing 48 changed files with 352 additions and 312 deletions.
51 changes: 13 additions & 38 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.netflix.nebula:gradle-extra-configurations-plugin:2.2.0'
}
}

task wrapper(type: Wrapper) {
description 'Creates the gradle wrapper.'
gradleVersion '4.9'
}

allprojects {
repositories {
mavenLocal()
Expand All @@ -24,39 +19,36 @@ allprojects {
}

ext {
minSdkVersion = 14
minSdkVersion = 21
targetSdkVersion = 27
compileSdkVersion = 27
compileSdkVersion = 29
sourceCompatibilityVersion = JavaVersion.VERSION_1_8
targetCompatibilityVersion = JavaVersion.VERSION_1_8
}

def supportLibVersion = '27.1.1'

ext.deps = [
// Android
android : 'com.google.android:android:4.1.1.4',
support_v4 : 'com.google.android:support-v4:r7',
preference_v7 : "com.android.support:preference-v7:${supportLibVersion}",
appcompat_v7 : "com.android.support:appcompat-v7:${supportLibVersion}",
support_annotations : "com.android.support:support-annotations:${supportLibVersion}",
android : "com.google.android:android:4.1.1.4",
preference : "androidx.preference:preference:1.1.0",
appcompat : "androidx.appcompat:appcompat:1.1.0",
annotations : "androidx.annotation:annotation:1.1.0",

// Processor
javapoet : 'com.squareup:javapoet:1.6.1',

// Test dependencies
junit : 'junit:junit:4.12',
mockito : 'org.mockito:mockito-all:1.10.19',
compiletesting : 'com.google.testing.compile:compile-testing:0.7',
roboelectric : 'org.robolectric:robolectric:3.8',
robolectric_support : 'org.robolectric:shadows-supportv4:3.8',
equalsverifier : 'nl.jqno.equalsverifier:equalsverifier:2.1.8'
compiletesting : 'com.google.testing.compile:compile-testing:0.18',
roboelectric : 'org.robolectric:robolectric:4.3.1',
equalsverifier : 'nl.jqno.equalsverifier:equalsverifier:2.1.8',
fragment_testing : 'androidx.fragment:fragment-testing:1.2.0',
androidx_junit : 'androidx.test.ext:junit:1.1.1'
]

// Static analysis
subprojects { project ->
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'findbugs'

checkstyle {
toolVersion = "7.2"
Expand All @@ -71,23 +63,6 @@ subprojects { project ->

classpath = files()
}

task pmd(type: Pmd) {
description 'Finds common programming flaws throw static analysis of code.'
ignoreFailures false
}

findbugs {
ignoreFailures = false
toolVersion = "3.0.0"
}

tasks.withType(FindBugs) {
reports {
xml.enabled = false
html.enabled = true
}
}
}

// configure Java projects
Expand Down
4 changes: 2 additions & 2 deletions examples/basic/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}
dependencies {
// replace with the current version of the Android plugin
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:3.6.2'
}
}

Expand All @@ -32,5 +32,5 @@ dependencies {
annotationProcessor project(":lightcycle-processor")

implementation project(":lightcycle-lib")
implementation deps.appcompat_v7
implementation deps.appcompat
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.soundcloud.lightcycle.sample.basic;


import com.soundcloud.lightcycle.DefaultActivityLightCycle;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;

class ActivityLogger extends DefaultActivityLightCycle<AppCompatActivity> {

private static final String TAG = "ACTIVITY_LOG";
Expand Down
6 changes: 3 additions & 3 deletions examples/basic/src/main/res/layout/activity_sample.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:textColor="@color/soundcloud"
android:text="@string/app_name" />

</RelativeLayout>
</FrameLayout>
4 changes: 2 additions & 2 deletions examples/real-world/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}
dependencies {
// replace with the current version of the Android plugin
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:3.6.2'
}
}

Expand Down Expand Up @@ -34,7 +34,7 @@ dependencies {
annotationProcessor "com.squareup.dagger:dagger-compiler:1.2.2"
implementation "com.squareup.dagger:dagger:1.2.2"

implementation deps.appcompat_v7
implementation deps.appcompat

testImplementation deps.junit
testImplementation deps.mockito
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import com.soundcloud.lightcycle.DefaultActivityLightCycle;

import android.os.Bundle;
import android.support.annotation.Nullable;

import androidx.annotation.Nullable;

import javax.inject.Inject;

class DescriptionPresenter extends DefaultActivityLightCycle<HomeView> {

@Inject
public DescriptionPresenter() {}
public DescriptionPresenter() {
}

@Override
public void onCreate(HomeView homeView, @Nullable Bundle bundle) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.soundcloud.lightcycle.sample.real_world.home;

import android.os.Bundle;

import androidx.annotation.Nullable;

import com.soundcloud.lightcycle.DefaultActivityLightCycle;
import com.soundcloud.lightcycle.sample.real_world.R;
import com.soundcloud.lightcycle.sample.real_world.utils.DateProvider;

import android.os.Bundle;
import android.support.annotation.Nullable;

import javax.inject.Inject;

class HeaderPresenter extends DefaultActivityLightCycle<HomeView> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import com.soundcloud.lightcycle.sample.real_world.SampleApp;
import com.soundcloud.lightcycle.sample.real_world.tracker.ScreenTracker;

import android.support.annotation.StringRes;
import android.widget.TextView;

import androidx.annotation.StringRes;

import javax.inject.Inject;

public class HomeActivity extends LightCycleAppCompatActivity<HomeView> implements HomeView {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.soundcloud.lightcycle.sample.real_world.home;

import com.soundcloud.lightcycle.sample.real_world.tracker.Screen;
import androidx.annotation.StringRes;

import android.support.annotation.StringRes;
import com.soundcloud.lightcycle.sample.real_world.tracker.Screen;

interface HomeView extends Screen {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.soundcloud.lightcycle.sample.real_world.license;

import com.soundcloud.lightcycle.LightCycle;
import com.soundcloud.lightcycle.LightCycleSupportFragment;
import com.soundcloud.lightcycle.sample.real_world.R;
import com.soundcloud.lightcycle.sample.real_world.SampleApp;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.soundcloud.lightcycle.LightCycle;
import com.soundcloud.lightcycle.LightCycleSupportFragment;
import com.soundcloud.lightcycle.sample.real_world.R;
import com.soundcloud.lightcycle.sample.real_world.SampleApp;

import javax.inject.Inject;

public class LicenseFragment extends LightCycleSupportFragment<LicenseView> implements LicenseView {

@Inject @LightCycle LicensePresenter licensePresenter;

public LicenseFragment() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.soundcloud.lightcycle.sample.real_world.utils;

import android.support.annotation.VisibleForTesting;
import androidx.annotation.VisibleForTesting;

import javax.inject.Inject;
import java.util.Calendar;
Expand Down
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ VERSION_NAME=1.7.0
VERSION_CODE=0
GROUP=com.soundcloud.lightcycle

android.useAndroidX=true
android.enableJetifier=false

android.enableUnitTestBinaryResources=true

POM_DESCRIPTION=LightCycle lets self-contained classes respond to Android’s lifecycle events
POM_URL=https://github.com/soundcloud/lightcycle
POM_SCM_URL=https://github.com/soundcloud/lightcycle
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 0 additions & 2 deletions lightcycle-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ checkstyle {

dependencies {
compileOnly deps.android
compileOnly deps.support_v4

testImplementation deps.android
testImplementation deps.support_v4
testImplementation deps.junit
testImplementation deps.equalsverifier
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.hamcrest.core.IsSame.sameInstance;

import nl.jqno.equalsverifier.EqualsVerifier;

import org.junit.Test;

import android.app.Activity;
Expand Down Expand Up @@ -50,9 +51,9 @@ public void liftedFragmentLightCycleAreEqualsWhenTheSourceIsTheSame() {

@Test
public void liftedSupportFragmentLightCycleAreEqualsWhenTheSourceIsTheSame() {
final DefaultSupportFragmentLightCycle<android.support.v4.app.Fragment> lightCycle = new DefaultSupportFragmentLightCycle<>();
final SupportFragmentLightCycle<android.support.v4.app.Fragment> lift1 = LightCycles.lift(lightCycle);
final SupportFragmentLightCycle<android.support.v4.app.Fragment> lift2 = LightCycles.lift(lightCycle);
final DefaultSupportFragmentLightCycle<Fragment> lightCycle = new DefaultSupportFragmentLightCycle<>();
final SupportFragmentLightCycle<Fragment> lift1 = LightCycles.lift(lightCycle);
final SupportFragmentLightCycle<Fragment> lift2 = LightCycles.lift(lightCycle);

assertThat(lift1, not(sameInstance(lift2)));
assertThat(lift1, equalTo(lift2));
Expand Down
7 changes: 5 additions & 2 deletions lightcycle-integration-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ dependencies {

implementation project(":lightcycle-lib")

implementation deps.appcompat_v7
implementation deps.appcompat
implementation deps.fragment_testing

testImplementation deps.roboelectric
testImplementation deps.robolectric_support
testImplementation deps.compiletesting
testImplementation deps.fragment_testing
testImplementation deps.junit
testImplementation deps.androidx_junit
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;

import androidx.appcompat.app.AppCompatActivity;

import com.soundcloud.lightcycle.integration_test.callback.ActivityLifecycleCallback;

class AppCompatActivityLogger extends BaseActivityLogger<AppCompatActivity> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.soundcloud.lightcycle.integration_test;


import android.app.Fragment;

import com.soundcloud.lightcycle.DefaultFragmentLightCycle;
import com.soundcloud.lightcycle.FragmentLightCycle;
import com.soundcloud.lightcycle.FragmentLightCycleDispatcher;
import com.soundcloud.lightcycle.LightCycle;

import android.app.Fragment;

class SampleFragmentDispatcher extends FragmentLightCycleDispatcher<Fragment> {
@LightCycle DefaultFragmentLightCycle<Fragment> lightCycle = new DefaultFragmentLightCycle<>();
@LightCycle
DefaultFragmentLightCycle<Fragment> lightCycle = new DefaultFragmentLightCycle<>();

int bindCount = 0;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.soundcloud.lightcycle.integration_test;

import androidx.fragment.app.Fragment;

import com.soundcloud.lightcycle.DefaultSupportFragmentLightCycle;
import com.soundcloud.lightcycle.LightCycle;
import com.soundcloud.lightcycle.SupportFragmentLightCycle;
import com.soundcloud.lightcycle.SupportFragmentLightCycleDispatcher;

import android.support.v4.app.Fragment;

class SampleSupportFragmentDispatcher extends SupportFragmentLightCycleDispatcher<Fragment> {
@LightCycle DefaultSupportFragmentLightCycle<Fragment> lightCycle = new DefaultSupportFragmentLightCycle<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:textColor="@color/soundcloud"
android:text="@string/app_name" />

</RelativeLayout>
</FrameLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
android:id="@+id/action_search"
android:icon="@android:drawable/ic_menu_search"
app:showAsAction="always"
app:actionViewClass="android.support.v7.widget.SearchView"
app:actionViewClass="androidx.appcompat.widget.SearchView"
android:title="@string/menu_search_title"/>
</menu>
Loading

0 comments on commit ecdc624

Please sign in to comment.