Skip to content
This repository was archived by the owner on Jun 28, 2019. It is now read-only.

Commit 7463c06

Browse files
authored
Merge pull request #19 from studyplus/feature/androidx
AndroidX対応、StudyRecordの仕様変更
2 parents 61d5442 + 4cdd797 commit 7463c06

File tree

17 files changed

+208
-199
lines changed

17 files changed

+208
-199
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)
7373
Create a record and post.
7474

7575
```
76-
val record = StudyRecordBuilder()
77-
.setComment("勉強した!!!")
78-
.setAmountTotal(30)
79-
.setDurationSeconds(2 * 60)
80-
.build()
76+
val record = StudyRecord(
77+
duration = 2 * 60,
78+
amount = StudyRecordAmountTotal(30),
79+
comment = "勉強した!!!"
80+
)
8181
Studyplus.instance.postRecord(this@MainActivity, record,
8282
object : Studyplus.Companion.OnPostRecordListener {
8383
override fun onResult(success: Boolean, recordId: Long?, throwable: Throwable?) {

build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
buildscript {
44
ext.kotlin_version = '1.3.21'
55
ext.versions = [
6-
'compileSdk': 27,
7-
'minSdk': 16,
8-
'targetSdk': 27,
9-
'supportLibrary': '27.1.1',
6+
'compileSdk' : 28,
7+
'minSdk' : 21,
8+
'targetSdk' : 28,
9+
'appcompat' : '1.0.2',
1010
'constraintLayout': '1.1.3'
1111
]
1212
repositories {
1313
google()
1414
jcenter()
1515
}
1616
dependencies {
17-
classpath 'com.android.tools.build:gradle:3.4.0'
17+
classpath 'com.android.tools.build:gradle:3.4.1'
1818
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1919
}
2020
}

gradle.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@ org.gradle.jvmargs=-Xmx1536m
1111
# This option should only be used with decoupled projects. More details, visit
1212
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1313
# org.gradle.parallel=true
14+
# AndroidX package structure to make it clearer which packages are bundled with the
15+
# Android operating system, and which are packaged with your app's APK
16+
# https://developer.android.com/topic/libraries/support-library/androidx-rn
17+
android.useAndroidX=true
18+
# Automatically convert third-party libraries to use AndroidX
19+
android.enableJetifier=true
20+
# Kotlin code style for this project: "official" or "obsolete":
21+
kotlin.code.style=official

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip

sdk-example-java/build.gradle

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ android {
1010
versionCode 1
1111
versionName "1.0"
1212

13-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1414

1515
}
1616

@@ -20,6 +20,10 @@ android {
2020
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2121
}
2222
}
23+
compileOptions {
24+
sourceCompatibility = 1.8
25+
targetCompatibility = 1.8
26+
}
2327

2428
}
2529

@@ -30,12 +34,12 @@ repositories {
3034
dependencies {
3135
implementation fileTree(dir: 'libs', include: ['*.jar'])
3236

33-
implementation "com.android.support:appcompat-v7:${versions.supportLibrary}"
34-
implementation "com.android.support.constraint:constraint-layout:${versions.constraintLayout}"
37+
implementation "androidx.appcompat:appcompat:${versions.appcompat}"
38+
implementation "androidx.constraintlayout:constraintlayout:${versions.constraintLayout}"
3539

3640
implementation 'jp.studyplus.android.sdk:studyplus-android-sdk2:2.2.1'
3741

3842
testImplementation 'junit:junit:4.12'
39-
androidTestImplementation 'com.android.support.test:runner:1.0.2'
40-
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
43+
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
44+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
4145
}

sdk-example-java/src/androidTest/java/jp/studyplus/android/sdk_example_java/ExampleInstrumentedTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package jp.studyplus.android.sdk_example_java;
22

33
import android.content.Context;
4-
import android.support.test.InstrumentationRegistry;
5-
import android.support.test.runner.AndroidJUnit4;
6-
4+
import androidx.test.core.app.ApplicationProvider;
5+
import androidx.test.ext.junit.runners.AndroidJUnit4;
76
import org.junit.Test;
87
import org.junit.runner.RunWith;
98

10-
import static org.junit.Assert.*;
9+
import static org.junit.Assert.assertEquals;
1110

1211
/**
1312
* Instrumented test, which will execute on an Android device.
@@ -19,7 +18,7 @@ public class ExampleInstrumentedTest {
1918
@Test
2019
public void useAppContext() {
2120
// Context of the app under test.
22-
Context appContext = InstrumentationRegistry.getTargetContext();
21+
Context appContext = ApplicationProvider.getApplicationContext();
2322

2423
assertEquals("jp.studyplus.android.sdk_example_java", appContext.getPackageName());
2524
}

sdk-example-java/src/main/java/jp/studyplus/android/sdk_example_java/MainActivity.java

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
import android.app.Activity;
44
import android.content.ActivityNotFoundException;
55
import android.content.Intent;
6-
import android.support.annotation.Nullable;
7-
import android.support.v7.app.AppCompatActivity;
86
import android.os.Bundle;
9-
import android.view.View;
107
import android.widget.Button;
118
import android.widget.TextView;
129
import android.widget.Toast;
13-
10+
import androidx.annotation.Nullable;
11+
import androidx.appcompat.app.AppCompatActivity;
1412
import jp.studyplus.android.sdk.Studyplus;
1513
import jp.studyplus.android.sdk.record.StudyRecord;
16-
import jp.studyplus.android.sdk.record.StudyRecordBuilder;
14+
import jp.studyplus.android.sdk.record.StudyRecordAmountTotal;
15+
16+
import java.util.Locale;
1717

1818
public class MainActivity extends AppCompatActivity {
1919

@@ -29,44 +29,31 @@ protected void onCreate(Bundle savedInstanceState) {
2929
getString(R.string.consumer_secret));
3030

3131
Button startAuthButton = findViewById(R.id.start_auth);
32-
startAuthButton.setOnClickListener(new View.OnClickListener() {
33-
@Override
34-
public void onClick(View view) {
35-
try {
36-
Studyplus.getInstance().startAuth(MainActivity.this, REQUEST_CODE_AUTH);
37-
} catch (ActivityNotFoundException e) {
38-
e.printStackTrace();
39-
Toast.makeText(MainActivity.this, "Need for Studyplus 2.14.0+", Toast.LENGTH_LONG).show();
40-
}
32+
startAuthButton.setOnClickListener(view -> {
33+
try {
34+
Studyplus.getInstance().startAuth(MainActivity.this, REQUEST_CODE_AUTH);
35+
} catch (ActivityNotFoundException e) {
36+
e.printStackTrace();
37+
Toast.makeText(MainActivity.this, "Need for Studyplus 2.14.0+", Toast.LENGTH_LONG).show();
4138
}
4239
});
4340

4441
Button postRecordButton = findViewById(R.id.post_study_record);
45-
postRecordButton.setOnClickListener(new View.OnClickListener() {
46-
@Override
47-
public void onClick(View view) {
48-
StudyRecord record = new StudyRecordBuilder()
49-
.setComment("勉強した!!!")
50-
.setAmountTotal(30)
51-
.setDurationSeconds(2 * 60)
52-
.build();
53-
Studyplus.getInstance().postRecord(MainActivity.this, record,
54-
new Studyplus.Companion.OnPostRecordListener() {
55-
@Override
56-
public void onResult(boolean success, Long recordId, Throwable throwable) {
57-
if (success) {
58-
Toast.makeText(MainActivity.this,
59-
String.format("Post Study Record!! (%d)", recordId), Toast.LENGTH_LONG).show();
60-
} else {
61-
Toast.makeText(MainActivity.this, "error!!", Toast.LENGTH_LONG).show();
62-
if (throwable != null) {
63-
throwable.printStackTrace();
64-
}
65-
}
42+
postRecordButton.setOnClickListener(view -> {
43+
StudyRecord record = new StudyRecord(2 * 60, new StudyRecordAmountTotal(30), "勉強した!!!");
44+
Studyplus.getInstance().postRecord(MainActivity.this, record,
45+
(success, recordId, throwable) -> {
46+
if (success) {
47+
Toast.makeText(MainActivity.this,
48+
String.format(Locale.US, "Post Study Record!! (%d)", recordId), Toast.LENGTH_LONG).show();
49+
} else {
50+
Toast.makeText(MainActivity.this, "error!!", Toast.LENGTH_LONG).show();
51+
if (throwable != null) {
52+
throwable.printStackTrace();
6653
}
67-
});
54+
}
55+
});
6856

69-
}
7057
});
7158
}
7259

sdk-example-java/src/main/res/layout/activity_main.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
44
android:layout_width="match_parent"
55
android:layout_height="match_parent"
@@ -8,8 +8,8 @@
88
<LinearLayout
99
android:layout_width="match_parent"
1010
android:layout_height="match_parent"
11-
android:orientation="vertical"
1211
android:gravity="center_horizontal"
12+
android:orientation="vertical"
1313
android:padding="24dp">
1414

1515
<TextView
@@ -44,4 +44,4 @@
4444

4545
</LinearLayout>
4646

47-
</android.support.constraint.ConstraintLayout>
47+
</androidx.constraintlayout.widget.ConstraintLayout>

sdk-example-kt/build.gradle

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ android {
1212
targetSdkVersion versions.targetSdk
1313
versionCode 1
1414
versionName "1.0"
15-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1616
}
1717
buildTypes {
1818
release {
1919
minifyEnabled false
2020
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2121
}
2222
}
23+
compileOptions {
24+
sourceCompatibility = 1.8
25+
targetCompatibility = 1.8
26+
}
2327
}
2428

2529
repositories {
@@ -29,12 +33,12 @@ repositories {
2933
dependencies {
3034
implementation fileTree(include: ['*.jar'], dir: 'libs')
3135
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
32-
implementation "com.android.support:appcompat-v7:${versions.supportLibrary}"
33-
implementation "com.android.support.constraint:constraint-layout:${versions.constraintLayout}"
36+
implementation "androidx.appcompat:appcompat:${versions.appcompat}"
37+
implementation "androidx.constraintlayout:constraintlayout:${versions.constraintLayout}"
3438

3539
implementation 'jp.studyplus.android.sdk:studyplus-android-sdk2:2.2.1'
3640

3741
testImplementation 'junit:junit:4.12'
38-
androidTestImplementation 'com.android.support.test:runner:1.0.2'
39-
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
42+
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
43+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
4044
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package jp.studyplus.android.sdk_example_kt
22

3-
import android.support.test.InstrumentationRegistry
4-
import android.support.test.runner.AndroidJUnit4
5-
3+
import android.content.Context
4+
import androidx.test.core.app.ApplicationProvider
5+
import androidx.test.ext.junit.runners.AndroidJUnit4
6+
import org.junit.Assert.assertEquals
67
import org.junit.Test
78
import org.junit.runner.RunWith
89

9-
import org.junit.Assert.*
10-
1110
/**
1211
* Instrumented test, which will execute on an Android device.
1312
*
@@ -18,7 +17,7 @@ class ExampleInstrumentedTest {
1817
@Test
1918
fun useAppContext() {
2019
// Context of the app under test.
21-
val appContext = InstrumentationRegistry.getTargetContext()
20+
val appContext = ApplicationProvider.getApplicationContext<Context>()
2221
assertEquals("jp.studyplus.android.sdk", appContext.packageName)
2322
}
2423
}

0 commit comments

Comments
 (0)