Skip to content

Commit 36bef10

Browse files
committed
Update README
1 parent 362747e commit 36bef10

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

README.md

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,55 +15,62 @@
1515
Add it in your root build.gradle at the end of repositories:
1616

1717
```groovy
18-
allprojects {
19-
repositories {
20-
...
21-
maven { url 'https://jitpack.io' }
18+
allprojects {
19+
repositories {
20+
maven { url 'https://jitpack.io' }
2221
}
2322
}
2423
```
2524

2625
```groovy
27-
dependencies {
28-
implementation 'com.github.studyplus:Studyplus-Android-SDK:2.7.0'
29-
}
26+
dependencies {
27+
implementation 'com.github.studyplus:Studyplus-Android-SDK:3.0.0'
28+
}
3029
```
3130

3231
## Usage
3332

3433
### Setup
3534

35+
If you want to handle StudyplusSDK instance as a singleton, use [Dagger](https://dagger.dev).
36+
3637
```kotlin
37-
Studyplus.instance.setup("consumer_key", "consumer_secret")
38+
private val instance by lazy {
39+
Studyplus(
40+
context = this@MainActivity,
41+
consumerKey = "consumer_key",
42+
consumerSecret = "consumer_secret",
43+
)
44+
}
3845
```
3946

4047
### Authenticate
4148

4249
Open an Activity to connect with Studyplus.
4350

4451
```kotlin
45-
Studyplus.instance.startAuth(this@MainActivity, REQUEST_CODE_AUTH)
52+
instance.startAuth(this@MainActivity, REQUEST_CODE_AUTH)
4653
```
4754

48-
Then save its result.
55+
Then save the result.
4956

5057
```kotlin
5158
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
52-
when (requestCode) {
53-
REQUEST_CODE_AUTH -> {
54-
if (resultCode == Activity.RESULT_OK) {
55-
Studyplus.instance.setAuthResult(this, data)
56-
Toast.makeText(this@MainActivity, "Success!!", Toast.LENGTH_LONG).show()
57-
}
58-
}
59+
if (resultCode != RESULT_OK || data == null) {
60+
return
61+
}
62+
63+
if (requestCode == REQUEST_CODE_AUTH) {
64+
instance.setAuthResult(data)
65+
Toast.makeText(this@MainActivity, "Success!!", Toast.LENGTH_LONG).show()
5966
}
6067
}
6168
```
6269

6370
### Unauth
6471

6572
```kotlin
66-
Studyplus.instance.cancelAuth(this@MainActivity)
73+
instance.cancelAuth()
6774
```
6875

6976
### Post a record to Studyplus
@@ -76,19 +83,15 @@ val record = StudyRecord(
7683
amount = StudyRecordAmountTotal(30),
7784
comment = "勉強した!!!",
7885
)
79-
Studyplus.instance.postRecord(this@MainActivity, record,
80-
object : Studyplus.Companion.OnPostRecordListener {
81-
override fun onResult(success: Boolean, recordId: Long?, throwable: Throwable?) {
82-
if (success) {
83-
Toast.makeText(context, "Post Study Record!! ($recordId)", Toast.LENGTH_LONG).show()
84-
} else {
85-
throwable?.apply {
86-
Toast.makeText(context, "error!!", Toast.LENGTH_LONG).show()
87-
printStackTrace()
88-
}
89-
}
90-
}
91-
})
86+
instance.postRecord(record, object : PostCallback {
87+
override fun onSuccess() {
88+
Toast.makeText(context, "Post Study Record!!", Toast.LENGTH_LONG).show()
89+
}
90+
91+
override fun onFailure(e: StudyplusError) {
92+
Toast.makeText(context, "error!!", Toast.LENGTH_LONG).show()
93+
}
94+
})
9295
```
9396

9497
### More

0 commit comments

Comments
 (0)