-
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.
TODO * 認証後にLoginActivityにコールバックする際のURLは変更する。 * LoginActivityのViewModel、Repositoryを作成する。
- Loading branch information
Showing
8 changed files
with
124 additions
and
4 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
72 changes: 72 additions & 0 deletions
72
app/src/main/java/org/ageage/eggplant/login/LoginActivity.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 |
---|---|---|
@@ -1,13 +1,85 @@ | ||
package org.ageage.eggplant.login | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.view.MenuItem | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AppCompatActivity | ||
import io.reactivex.android.schedulers.AndroidSchedulers | ||
import io.reactivex.schedulers.Schedulers | ||
import kotlinx.android.synthetic.main.activity_login.* | ||
import org.ageage.eggplant.BuildConfig | ||
import org.ageage.eggplant.R | ||
import org.ageage.eggplant.common.oauth.HatenaOAuthManager | ||
|
||
private const val KEY_OAUTH_VERIFIER = "oauth_verifier" | ||
|
||
class LoginActivity : AppCompatActivity() { | ||
|
||
private val oAuthManager = | ||
HatenaOAuthManager(BuildConfig.CONSUMER_KEY, BuildConfig.CONSUMER_SECRET) | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_login) | ||
initViews() | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem?): Boolean { | ||
when (item?.itemId) { | ||
android.R.id.home -> finish() | ||
} | ||
return super.onOptionsItemSelected(item) | ||
} | ||
|
||
override fun onNewIntent(intent: Intent?) { | ||
super.onNewIntent(intent) | ||
intent?.let { | ||
if (it.action == Intent.ACTION_VIEW) { | ||
it.data?.let { uri -> | ||
uri.getQueryParameter(KEY_OAUTH_VERIFIER)?.let { oAuthVerifier -> | ||
oAuthManager.fetchAccessToken(oAuthVerifier) | ||
.subscribeOn(Schedulers.io()) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribe( | ||
{ | ||
Toast.makeText(this, "成功", Toast.LENGTH_SHORT).show() | ||
}, | ||
{ | ||
Toast.makeText(this, "失敗", Toast.LENGTH_SHORT).show() | ||
} | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun initViews() { | ||
setupActionBar() | ||
setupLoginButton() | ||
} | ||
|
||
private fun setupActionBar() { | ||
supportActionBar?.let { | ||
it.setDisplayHomeAsUpEnabled(true) | ||
it.title = getString(R.string.title_login_activity) | ||
} | ||
} | ||
|
||
private fun setupLoginButton() { | ||
buttonLogin.setOnClickListener { | ||
oAuthManager.fetchAuthorizationUrl() | ||
.subscribeOn(Schedulers.io()) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribe( | ||
{ | ||
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(it))) | ||
}, | ||
{ | ||
} | ||
) | ||
} | ||
} | ||
} |
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,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,5c1.66,0 3,1.34 3,3s-1.34,3 -3,3 -3,-1.34 -3,-3 1.34,-3 3,-3zM12,19.2c-2.5,0 -4.71,-1.28 -6,-3.22 0.03,-1.99 4,-3.08 6,-3.08 1.99,0 5.97,1.09 6,3.08 -1.29,1.94 -3.5,3.22 -6,3.22z" /> | ||
</vector> |
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,8 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<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.LoginActivity"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
<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> |
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