Skip to content

Commit

Permalink
Merge branch 'feature/kotlin' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
iSoron committed Jul 21, 2017
1 parent 2db4c06 commit 180c18f
Show file tree
Hide file tree
Showing 147 changed files with 3,835 additions and 5,594 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ gen/
local.properties
crowdin.yaml
local
tmp/
3 changes: 0 additions & 3 deletions accept_images.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Álinson Santos Xavier <[email protected]>
* Copyright (C) 2016 Álinson Santos Xavier <[email protected]>
*
* This file is part of Loop Habit Tracker.
*
Expand All @@ -17,25 +17,26 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.isoron.uhabits.activities;
package org.isoron.androidbase.activities;

import org.isoron.uhabits.core.models.*;
import android.content.*;

import dagger.*;

@Module
public class HabitModule
public class ActivityContextModule
{
private final Habit habit;
private Context context;

public HabitModule(Habit habit)
public ActivityContextModule(Context context)
{
this.habit = habit;
this.context = context;
}

@Provides
public Habit getHabit()
@ActivityContext
public Context getContext()
{
return habit;
return context;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,20 @@

package org.isoron.androidbase.activities;

import android.content.*;

import dagger.*;

@Module
public class ActivityModule
public class BaseActivityModule
{
private BaseActivity activity;

public ActivityModule(BaseActivity activity)
public BaseActivityModule(BaseActivity activity)
{
this.activity = activity;
}

@Provides
public BaseActivity getActivity()
{
return activity;
}

@Provides
@ActivityContext
public Context getContext()
public BaseActivity getBaseActivity()
{
return activity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ public boolean getBoolean(@AttrRes int attrId)
return bool;
}

public int getDimension(@AttrRes int attrId)
{
TypedArray ta = getTypedArray(attrId);
int dim = ta.getDimensionPixelSize(0, 0);
ta.recycle();

return dim;
}

public int getColor(@AttrRes int attrId)
{
TypedArray ta = getTypedArray(attrId);
Expand Down Expand Up @@ -80,13 +89,13 @@ public float getFloat(@AttrRes int attrId)

public int[] getPalette()
{
int resourceId = getStyleResource(R.attr.palette);
int resourceId = getResource(R.attr.palette);
if (resourceId < 0) throw new RuntimeException("resource not found");

return context.getResources().getIntArray(resourceId);
}

int getStyleResource(@AttrRes int attrId)
public int getResource(@AttrRes int attrId)
{
TypedArray ta = getTypedArray(attrId);
int resourceId = ta.getResourceId(0, -1);
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
buildscript {
ext.kotlin_version = '1.1.2-4'
repositories {
jcenter()
maven { url 'https://maven.google.com' }
Expand All @@ -10,6 +11,7 @@ buildscript {
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.4'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'org.jacoco:org.jacoco.core:+'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Expand Down
22 changes: 22 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ uninstall_test_apk() {
$ADB uninstall ${PACKAGE_NAME}.test || fail
}

fetch_images() {
rm -rf tmp/test-screenshots > /dev/null
mkdir -p tmp/
adb pull /sdcard/Android/data/org.isoron.uhabits/files/test-screenshots tmp/
adb shell rm -rf /sdcard/Android/data/org.isoron.uhabits/files/test-screenshots
}

accept_images() {
find tmp/test-screenshots -name '*.expected*' -delete
rsync -av tmp/test-screenshots/ uhabits-android/src/androidTest/assets/
}

run_local_tests() {
clean_output_dir
run_adb_as_root
Expand Down Expand Up @@ -263,6 +275,14 @@ case "$1" in
run_local_tests
;;

fetch-images)
fetch_images
;;

accept-images)
accept_images
;;

install)
shift; parse_opts $*
build_apk
Expand All @@ -278,6 +298,8 @@ case "$1" in
ci-tests Start emulator silently, run tests then kill emulator
local-tests Run all tests on connected device
install Install app on connected device
fetch-images Fetches failed view test images from device
accept-images Copies fetched images to corresponding assets folder
Options:
-u --uninstall-first Uninstall existing APK first
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
org.gradle.parallel=true
org.gradle.parallel=false
org.gradle.daemon=true
org.gradle.jvmargs=-Xms1024m -Xmx4096m -XX:MaxPermSize=2048m
org.gradle.jvmargs=-Xms2048m -Xmx2048m -XX:MaxPermSize=2048m
29 changes: 19 additions & 10 deletions uhabits-android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
apply plugin: 'idea'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'jacoco'

android {
Expand All @@ -11,6 +13,13 @@ android {
minSdkVersion 19
targetSdkVersion 25
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArgument "size", "medium"

javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath false
}
}
}

buildTypes {
Expand Down Expand Up @@ -64,18 +73,16 @@ dependencies {
implementation 'com.google.dagger:dagger:2.9'
implementation 'com.jakewharton:butterknife:8.6.1-SNAPSHOT'
implementation 'org.apmem.tools:layouts:1.10'
implementation 'org.jetbrains:annotations-java5:15.0'
implementation 'com.google.code.gson:gson:2.7'
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

compileOnly 'javax.annotation:jsr250-api:1.0'
compileOnly 'com.google.auto.factory:auto-factory:1.0-beta3'
annotationProcessor 'com.google.dagger:dagger-compiler:2.9'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.1-SNAPSHOT'
annotationProcessor 'com.google.auto.factory:auto-factory:1.0-beta3'
kapt 'com.google.dagger:dagger-compiler:2.9'
kapt 'com.jakewharton:butterknife-compiler:8.6.1-SNAPSHOT'
kapt 'com.google.auto.factory:auto-factory:1.0-beta3'

androidTestAnnotationProcessor 'com.google.auto.factory:auto-factory:1.0-beta3'
androidTestAnnotationProcessor 'com.google.dagger:dagger-compiler:2.9'
androidTestAnnotationProcessor 'com.jakewharton:butterknife-compiler:8.6.1-SNAPSHOT'
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:2.2.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
Expand All @@ -87,16 +94,14 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.google.guava:guava:20.0'
androidTestImplementation project(":uhabits-core")
kaptAndroidTest 'com.google.dagger:dagger-compiler:2.9'

// mockito-android 2+ includes net.bytebuddy, which causes tests to fail.
// Excluding the package net.bytebuddy on AndroidManifest.xml breaks some
// AndroidJUnitRunner functionality, such as running individual methods.
androidTestImplementation "org.mockito:mockito-core:1+"
androidTestImplementation "com.google.dexmaker:dexmaker-mockito:+"

testAnnotationProcessor 'com.google.auto.factory:auto-factory:1.0-beta3'
testAnnotationProcessor 'com.google.dagger:dagger-compiler:2.9'
testAnnotationProcessor 'com.jakewharton:butterknife-compiler:8.6.1-SNAPSHOT'
testImplementation 'com.google.dagger:dagger:2.9'
testImplementation "org.mockito:mockito-core:2.8.9"
testImplementation "org.mockito:mockito-inline:2.8.9"
Expand All @@ -114,6 +119,10 @@ repositories {
mavenCentral()
}

kapt {
correctErrorTypes = true
}

task coverageReport(type: JacocoReport) {

jacocoClasspath = configurations['androidJacocoAnt']
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import junit.framework.*;

import org.isoron.androidbase.*;
import org.isoron.androidbase.activities.*;
import org.isoron.androidbase.utils.*;
import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.core.preferences.*;
Expand Down Expand Up @@ -67,12 +68,15 @@ public class BaseAndroidTest extends TestCase

protected CountDownLatch latch;

protected AndroidTestComponent component;
protected HabitsApplicationTestComponent appComponent;

protected ModelFactory modelFactory;

protected HabitsActivityTestComponent component;

private boolean isDone = false;

@Override
@Before
public void setUp()
{
Expand All @@ -86,21 +90,31 @@ public void setUp()
setTheme(R.style.AppBaseTheme);
setLocale("en", "US");

component = DaggerAndroidTestComponent
latch = new CountDownLatch(1);

appComponent = DaggerHabitsApplicationTestComponent
.builder()
.appContextModule(new AppContextModule(targetContext.getApplicationContext()))
.build();

HabitsApplication.setComponent(component);
prefs = component.getPreferences();
habitList = component.getHabitList();
taskRunner = component.getTaskRunner();
logger = component.getHabitsLogger();
HabitsApplication.setComponent(appComponent);
prefs = appComponent.getPreferences();
habitList = appComponent.getHabitList();
taskRunner = appComponent.getTaskRunner();
logger = appComponent.getHabitsLogger();
modelFactory = appComponent.getModelFactory();

prefs.reset();

modelFactory = component.getModelFactory();
fixtures = new HabitFixtures(modelFactory, habitList);
fixtures.purgeHabits(appComponent.getHabitList());
Habit habit = fixtures.createEmptyHabit();

latch = new CountDownLatch(1);
component = DaggerHabitsActivityTestComponent
.builder()
.activityContextModule(new ActivityContextModule(targetContext))
.habitsApplicationComponent(appComponent)
.build();
}

protected void assertWidgetProviderIsInstalled(Class componentClass)
Expand All @@ -118,7 +132,7 @@ protected void assertWidgetProviderIsInstalled(Class componentClass)

protected void awaitLatch() throws InterruptedException
{
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertTrue(latch.await(1, TimeUnit.SECONDS));
}

protected void setLocale(@NonNull String language, @NonNull String country)
Expand Down Expand Up @@ -195,4 +209,10 @@ protected void stopTracing()
{
Debug.stopMethodTracing();
}

protected Long day(int offset)
{
return DateUtils.getStartOfToday() -
offset * DateUtils.millisecondsInOneDay;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import android.graphics.*;
import android.support.annotation.*;
import android.support.test.*;
import android.view.*;
import android.widget.*;

Expand All @@ -31,14 +32,14 @@
import java.io.*;
import java.util.*;

import static android.os.Build.VERSION.*;
import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.KITKAT;
import static android.os.Build.VERSION_CODES.LOLLIPOP;
import static android.view.View.MeasureSpec.*;
import static android.view.View.MeasureSpec.makeMeasureSpec;

public class BaseViewTest extends BaseAndroidTest
{
double similarityCutoff = 0.00075;
public double similarityCutoff = 0.00015;

@Override
public void setUp()
Expand All @@ -49,6 +50,7 @@ public void setUp()
protected void assertRenders(View view, String expectedImagePath)
throws IOException
{
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
expectedImagePath = getVersionedPath(expectedImagePath);
Bitmap actual = renderView(view);
if(actual == null) throw new IllegalStateException("actual is null");
Expand Down Expand Up @@ -198,6 +200,7 @@ public Bitmap renderView(View view)

Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.invalidate();
view.draw(canvas);
return bitmap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public Habit createLongNumericalHabit()
habit.setName("Take a walk");
habit.setDescription("How many steps did you walk today?");
habit.setType(Habit.NUMBER_HABIT);
habit.setTargetType(Habit.AT_LEAST);
habit.setTargetValue(200.0);
habit.setUnit("steps");
habitList.add(habit);

long timestamp = DateUtils.getStartOfToday();
Expand Down
Loading

0 comments on commit 180c18f

Please sign in to comment.