-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ユーザーにコードを入力してもらう形式に変更 * ログイン画面のUIの管理をFragmentに任せるように修正 TODO * ユーザー情報を取得してDBに保存する処理を実装する
- Loading branch information
Showing
9 changed files
with
161 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
app/src/main/java/org/ageage/eggplant/login/LoginFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.ageage.eggplant.login | ||
|
||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Toast | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.viewModels | ||
import io.reactivex.android.schedulers.AndroidSchedulers | ||
import io.reactivex.schedulers.Schedulers | ||
import kotlinx.android.synthetic.main.fragment_login.* | ||
import org.ageage.eggplant.BuildConfig | ||
import org.ageage.eggplant.R | ||
import org.ageage.eggplant.common.oauth.HatenaOAuthManager | ||
|
||
class LoginFragment : Fragment() { | ||
|
||
private val viewModel: LoginViewModel by viewModels { LoginViewModelFactory() } | ||
private val oAuthManager = | ||
HatenaOAuthManager(BuildConfig.CONSUMER_KEY, BuildConfig.CONSUMER_SECRET) | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
// Inflate the layout for this fragment | ||
return inflater.inflate(R.layout.fragment_login, container, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
initViews() | ||
} | ||
|
||
private fun initViews() { | ||
setupAccessButton() | ||
setupLoginButton() | ||
} | ||
|
||
private fun setupAccessButton() { | ||
buttonAccess.setOnClickListener { | ||
oAuthManager.fetchAuthorizationUrl() | ||
.subscribeOn(Schedulers.io()) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribe( | ||
{ | ||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(it))) | ||
}, | ||
{ | ||
} | ||
) | ||
} | ||
} | ||
|
||
private fun setupLoginButton() { | ||
buttonLogin.setOnClickListener { | ||
oAuthVerifierEditText?.text.toString().let { oAuthVerifier -> | ||
oAuthManager.fetchAccessToken(oAuthVerifier) | ||
.subscribeOn(Schedulers.io()) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribe( | ||
{ | ||
Toast.makeText(requireContext(), "成功", Toast.LENGTH_SHORT).show() | ||
}, | ||
{ | ||
Toast.makeText(requireContext(), "失敗", Toast.LENGTH_SHORT).show() | ||
} | ||
) | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
fun newInstance() = LoginFragment() | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/org/ageage/eggplant/login/LoginViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.ageage.eggplant.login | ||
|
||
import androidx.lifecycle.ViewModel | ||
|
||
class LoginViewModel : ViewModel() { | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/org/ageage/eggplant/login/LoginViewModelFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.ageage.eggplant.login | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
|
||
class LoginViewModelFactory : ViewModelProvider.Factory { | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
override fun <T : ViewModel?> create(modelClass: Class<T>): T { | ||
if (modelClass != LoginViewModel::class.java) { | ||
throw IllegalArgumentException("Illegal ViewModel class.") | ||
} | ||
|
||
return LoginViewModel() as T | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/container" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
tools:context=".login.LoginActivity"> | ||
|
||
<androidx.appcompat.widget.AppCompatTextView | ||
android:id="@+id/description" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="20dp" | ||
android:text="@string/description_for_cooperation_hatena" /> | ||
|
||
<androidx.appcompat.widget.AppCompatButton | ||
android:id="@+id/buttonLogin" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="20dp" | ||
android:text="@string/button_text_for_login_hatena" /> | ||
|
||
</LinearLayout> | ||
tools:context=".login.LoginActivity" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
tools:context=".login.LoginFragment"> | ||
|
||
<androidx.appcompat.widget.AppCompatTextView | ||
android:id="@+id/description" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="20dp" | ||
android:text="@string/description_for_cooperation_hatena" /> | ||
|
||
<androidx.appcompat.widget.AppCompatButton | ||
android:id="@+id/buttonAccess" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="20dp" | ||
android:text="@string/button_text_for_access_to_hatena" /> | ||
|
||
<com.google.android.material.textfield.TextInputEditText | ||
android:id="@+id/oAuthVerifierEditText" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="20dp" | ||
android:hint="@string/hint_for_login_to_hatena" | ||
android:maxLines="1" /> | ||
|
||
<androidx.appcompat.widget.AppCompatButton | ||
android:id="@+id/buttonLogin" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="20dp" | ||
android:layout_marginEnd="20dp" | ||
android:text="@string/button_text_for_login_to_hatena" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters