Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/javafa/thisiskotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
javafa committed Jun 20, 2021
2 parents ffe3f31 + f12fa80 commit f8daf77
Show file tree
Hide file tree
Showing 44 changed files with 1,062 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,19 @@ class MainActivity : AppCompatActivity() {
}
}

fun printCheckedItems(){
fun printCheckedItems() {
var result = ""
if(apple) result = " 사과"
if(banana) result += " 바나나"
if(orange) result += " 오렌지"
if (apple) result = " 사과"

if (banana) {
if (result.isNotEmpty()) result += ""
result += " 바나나"
}
if (orange) {
if (result.isNotEmpty()) result += ""
result += " 오렌지"
}
binding.textView.text = "${result}가 선택되었습니다."
}

}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,4 @@
### 기타 - 책에 없는 것들
[Navigation Drawer](https://github.com/javafa/thisiskotlin/tree/master/NavigationDrawer)
[SwipeRefreshLayout](https://github.com/javafa/thisiskotlin/tree/master/SwipeRefresh)
[Retrofit : 회원가입, 로그인처리](https://github.com/javafa/thisiskotlin/tree/master/Retrofit_Login)
15 changes: 15 additions & 0 deletions Retrofit_Login/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
3 changes: 3 additions & 0 deletions Retrofit_Login/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Retrofit_Login/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Retrofit_Login/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions Retrofit_Login/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Retrofit_Login/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Retrofit_Login/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
51 changes: 51 additions & 0 deletions Retrofit_Login/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.kodonho.retrofit"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.github.bumptech.glide:glide:4.11.0'
// annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' // < 동작안함
kapt 'com.github.bumptech.glide:compiler:4.11.0'

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
21 changes: 21 additions & 0 deletions Retrofit_Login/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.kodonho.retrofit

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.kodonho.retrofit", appContext.packageName)
}
}
25 changes: 25 additions & 0 deletions Retrofit_Login/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kodonho.retrofit">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Retrofit"
android:usesCleartextTraffic="true">
<activity android:name=".RegisterActivity"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.kodonho.retrofit

data class LoginResponse(
val email: Int,
val id: Int,
val name: String,
val password: String,
val phonenum: String,
val seq: String,
val success: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.kodonho.retrofit

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.*

class MainActivity : AppCompatActivity() {

lateinit var id:EditText
lateinit var password:EditText
lateinit var button: Button
lateinit var btnRegister: TextView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

id = findViewById(R.id.textId)
password = findViewById(R.id.textPassword)
button = findViewById(R.id.button)
btnRegister = findViewById(R.id.btnRegister)

val retrofit = Retrofit.Builder()
.baseUrl("http://3.34.141.115") // 주소는 본인의 서버 주소로 설정
.addConverterFactory(GsonConverterFactory.create())
.build()

val service = retrofit.create(SignService::class.java)

button.setOnClickListener {
val idStr = id.text.toString()
val pwStr = password.text.toString()
service.login(idStr, pwStr).enqueue(object :Callback<LoginResponse> {
override fun onResponse(call: Call<LoginResponse>, response: Response<LoginResponse>) {
val result = response.body()
Log.d("로그인", "${result}")
}

override fun onFailure(call: Call<LoginResponse>, t: Throwable) {
Log.e("로그인", "${t.localizedMessage}")
}
})
}

btnRegister.setOnClickListener {
Intent(this, RegisterActivity::class.java).run {
startActivity(this)
}
}
}
}

interface SignService {
@FormUrlEncoded
@POST("login.php")
fun login(@Field("id") id:String, @Field("password") pw:String) : Call<LoginResponse>
}
Loading

0 comments on commit f8daf77

Please sign in to comment.