-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
88 changed files
with
2,491 additions
and
0 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
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
/build |
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,52 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'kotlin-android' | ||
id 'com.google.gms.google-services' | ||
} | ||
|
||
android { | ||
compileSdk 31 | ||
|
||
defaultConfig { | ||
applicationId "net.flow9.thisiskotlin.firebase" | ||
minSdk 21 | ||
targetSdk 31 | ||
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' | ||
} | ||
buildFeatures { | ||
viewBinding true | ||
} | ||
} | ||
|
||
dependencies { | ||
// 두 줄 추가 | ||
implementation platform('com.google.firebase:firebase-bom:29.0.0') | ||
implementation 'com.google.firebase:firebase-analytics-ktx' | ||
// Realtime Database | ||
implementation 'com.google.firebase:firebase-database-ktx' | ||
|
||
implementation 'androidx.core:core-ktx:1.7.0' | ||
implementation 'androidx.appcompat:appcompat:1.3.1' | ||
implementation 'com.google.android.material:material:1.4.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.1.1' | ||
testImplementation 'junit:junit:4.+' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.3' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' | ||
} |
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,69 @@ | ||
{ | ||
"project_info": { | ||
"project_number": "304871030893", | ||
"firebase_url": "https://this-is-android-with-kot-df246-default-rtdb.asia-southeast1.firebasedatabase.app", | ||
"project_id": "this-is-android-with-kot-df246", | ||
"storage_bucket": "this-is-android-with-kot-df246.appspot.com" | ||
}, | ||
"client": [ | ||
{ | ||
"client_info": { | ||
"mobilesdk_app_id": "1:304871030893:android:7934b217728bb20e88bf64", | ||
"android_client_info": { | ||
"package_name": "net.flow9.thisiskotlin.firebase" | ||
} | ||
}, | ||
"oauth_client": [ | ||
{ | ||
"client_id": "304871030893-ab02iq9kro1lb0hsd0lj0k7rfeupjvr8.apps.googleusercontent.com", | ||
"client_type": 3 | ||
} | ||
], | ||
"api_key": [ | ||
{ | ||
"current_key": "AIzaSyDtpT4MZVMAlu7tqzTsqsdiLW8iCIuvINg" | ||
} | ||
], | ||
"services": { | ||
"appinvite_service": { | ||
"other_platform_oauth_client": [ | ||
{ | ||
"client_id": "304871030893-ab02iq9kro1lb0hsd0lj0k7rfeupjvr8.apps.googleusercontent.com", | ||
"client_type": 3 | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"client_info": { | ||
"mobilesdk_app_id": "1:304871030893:android:3be7ad65a6cd1aa088bf64", | ||
"android_client_info": { | ||
"package_name": "net.flow9.thisiskotlin.firebasechat" | ||
} | ||
}, | ||
"oauth_client": [ | ||
{ | ||
"client_id": "304871030893-ab02iq9kro1lb0hsd0lj0k7rfeupjvr8.apps.googleusercontent.com", | ||
"client_type": 3 | ||
} | ||
], | ||
"api_key": [ | ||
{ | ||
"current_key": "AIzaSyDtpT4MZVMAlu7tqzTsqsdiLW8iCIuvINg" | ||
} | ||
], | ||
"services": { | ||
"appinvite_service": { | ||
"other_platform_oauth_client": [ | ||
{ | ||
"client_id": "304871030893-ab02iq9kro1lb0hsd0lj0k7rfeupjvr8.apps.googleusercontent.com", | ||
"client_type": 3 | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"configuration_version": "1" | ||
} |
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,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 |
24 changes: 24 additions & 0 deletions
24
Firebase/app/src/androidTest/java/net/flow9/thisiskotlin/firebase/ExampleInstrumentedTest.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,24 @@ | ||
package net.flow9.thisiskotlin.firebase | ||
|
||
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("net.flow9.thisiskotlin.firebase", appContext.packageName) | ||
} | ||
} |
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,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="net.flow9.thisiskotlin.firebase"> | ||
|
||
<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.Firebase"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
99 changes: 99 additions & 0 deletions
99
Firebase/app/src/main/java/net/flow9/thisiskotlin/firebase/MainActivity.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,99 @@ | ||
package net.flow9.thisiskotlin.firebase | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.util.Log | ||
import com.google.firebase.database.* | ||
import com.google.firebase.database.ktx.database | ||
import com.google.firebase.ktx.Firebase | ||
import net.flow9.thisiskotlin.firebase.databinding.ActivityMainBinding | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
val database = Firebase.database("https://this-is-android-with-kot-df246-default-rtdb.asia-southeast1.firebasedatabase.app") | ||
val myRef = database.getReference("users") | ||
|
||
val binding by lazy { ActivityMainBinding.inflate(layoutInflater)} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(binding.root) | ||
|
||
with(binding){ | ||
btnPost.setOnClickListener { | ||
val name = editName.text.toString() | ||
val password = editPassword.text.toString() | ||
val user = User(name, password) | ||
addItem(user) | ||
} | ||
} | ||
|
||
myRef.addValueEventListener( object: ValueEventListener { | ||
override fun onDataChange(snapshot: DataSnapshot) { | ||
// 먼저 textList를 지운다 | ||
with(binding) { | ||
textList.setText("") | ||
for (item in snapshot.children) { | ||
item.getValue(User::class.java)?.let { user -> | ||
textList.append("${user.name} : ${user.password} \n") | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
override fun onCancelled(error: DatabaseError) { | ||
print(error.message) | ||
} | ||
}) | ||
|
||
// write() | ||
// readOnce() | ||
// readData() | ||
} | ||
// 목록 형태로 추가하기 | ||
fun addItem(user:User) { | ||
val id = myRef.push().key!! | ||
user.id = id | ||
myRef.child(id).setValue(user) | ||
} | ||
// 계속 읽기 | ||
fun readData() { | ||
myRef.child("name").addValueEventListener( object: ValueEventListener { | ||
override fun onDataChange(snapshot: DataSnapshot) { | ||
Log.d("파이어베이스", "${snapshot.value}") | ||
print( snapshot.value ) // 값이 변경 될때마다 매번 호출 | ||
} | ||
override fun onCancelled(error: DatabaseError) { | ||
print( error.message ) | ||
} | ||
}) | ||
} | ||
// 한번 읽기 | ||
fun readOnce() { | ||
myRef.child("name").get().addOnSuccessListener { | ||
Log.d("파이어베이스", "name=${it.value}") // 한 번 호출 | ||
}.addOnFailureListener { | ||
Log.d("파이어베이스", "error=${it}") | ||
} | ||
} | ||
// 쓰기 | ||
fun write() { | ||
myRef.child("name").setValue("Scott") | ||
myRef.child("age").setValue(19) | ||
} | ||
} | ||
|
||
|
||
class User { | ||
var id:String = "" | ||
var name:String = "" | ||
var password:String = "" | ||
|
||
constructor() // 파이어베이스에서 데이터 변환을 위해서 필요 | ||
|
||
constructor(name:String, password:String) { | ||
this.name = name | ||
this.password = password | ||
} | ||
} |
Oops, something went wrong.