Skip to content

Commit

Permalink
[WIP]
Browse files Browse the repository at this point in the history
TODO

* ユーザー情報を取得してDBに保存する処理を実装する
* Statusクラスは改良の余地があるかも?
  • Loading branch information
jageishi committed Apr 14, 2020
1 parent 53618d0 commit 61270db
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ dependencies {
implementation "com.github.scribejava:scribejava:$scribe_java_version"
implementation "com.github.scribejava:scribejava-core:$scribe_java_version"


def room_version = "2.2.2"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"

implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
testImplementation 'junit:junit:4.12'
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/org/ageage/eggplant/common/api/UserService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.ageage.eggplant.common.api

import io.reactivex.Single
import org.ageage.eggplant.common.api.response.User
import retrofit2.http.GET

interface UserService {
@GET("/rest/1/my")
fun userData(): Single<User>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.ageage.eggplant.common.api.response

data class User(
val name: String
)
13 changes: 13 additions & 0 deletions app/src/main/java/org/ageage/eggplant/common/db/entity/User.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.ageage.eggplant.common.db.entity

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity
data class User(
@PrimaryKey(autoGenerate = true) val id: Int,
@ColumnInfo(name = "name") val name: String,
@ColumnInfo(name = "oauth_token") val oAuthToken: String,
@ColumnInfo(name = "oauth_token_secret") val oAuthTokenSecret: String
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.ageage.eggplant.common.oauth

import com.github.scribejava.core.builder.ServiceBuilder
import com.github.scribejava.core.model.OAuth1AccessToken
import com.github.scribejava.core.model.OAuth1RequestToken
import com.github.scribejava.core.oauth.OAuth10aService
import io.reactivex.Single
Expand Down Expand Up @@ -29,11 +30,11 @@ class HatenaOAuthManager(
}
}

fun fetchAccessToken(oauthVerifier: String): Single<String> {
fun fetchAccessToken(oauthVerifier: String): Single<OAuth1AccessToken> {
return Single.create {
service?.let { oAuthService ->
val accessToken = oAuthService.getAccessToken(requestToken, oauthVerifier)
it.onSuccess(accessToken.rawResponse)
it.onSuccess(accessToken)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ class LoginRepository {
fun fetchAuthorizationUrl() = oAuthManager.fetchAuthorizationUrl()

fun fetchAccessToken(oAuthVerifier: String) = oAuthManager.fetchAccessToken(oAuthVerifier)

fun fetchUserData() {

}
}
10 changes: 10 additions & 0 deletions app/src/main/java/org/ageage/eggplant/login/LoginFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class LoginFragment : Fragment() {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(it.data)))
}
is LoginViewModel.Status.Error -> {
Toast.makeText(
requireContext(),
getString(R.string.failed_to_link_with_hatena),
Toast.LENGTH_SHORT
).show()
}
}
})
Expand All @@ -53,6 +58,11 @@ class LoginFragment : Fragment() {
Toast.makeText(requireContext(), "成功", Toast.LENGTH_SHORT).show()
}
is LoginViewModel.Status.Error -> {
Toast.makeText(
requireContext(),
getString(R.string.failed_to_login),
Toast.LENGTH_SHORT
).show()
}
}
})
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@
<string name="button_text_for_access_to_hatena">はてなとの連携を許可する</string>
<string name="hint_for_login_to_hatena">コードを貼り付けてください</string>
<string name="button_text_for_login_to_hatena">はてなにログインする</string>
<string name="failed_to_link_with_hatena">はてなとの連携に失敗しました。</string>
<string name="failed_to_login">ログインに失敗しました。</string>
</resources>

0 comments on commit 61270db

Please sign in to comment.