Skip to content

Commit

Permalink
feat: 모두 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JangWoojun committed Aug 25, 2024
1 parent d84db04 commit 3988c06
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.seogaemo.hackseoul_android.data

class CreatedAt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.seogaemo.hackseoul_android.data

data class PipLineBody(
val companyId: String,
val description: String,
val productItemId: String,
val title: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.seogaemo.hackseoul_android.data

data class ProditemResponse(
val createdAt: CreatedAt,
val modelNumber: String,
val productId: String,
val title: String,
val uid: String
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.seogaemo.hackseoul_android.network

import com.seogaemo.hackseoul_android.data.CompanyResponse
import com.seogaemo.hackseoul_android.data.PipLineBody
import com.seogaemo.hackseoul_android.data.ProditemResponse
import com.seogaemo.hackseoul_android.data.ProductResponse
import com.seogaemo.hackseoul_android.data.SignInRequest
import com.seogaemo.hackseoul_android.data.SignInResponse
Expand All @@ -21,12 +23,23 @@ interface RetrofitAPI {
@GET("company/{id}")
suspend fun getCompany(
@Header("Authorization") authorization: String,
@Path(value = "id") id : Int
@Path(value = "id") id : String
): Response<CompanyResponse>

@GET("product/{id}")
suspend fun getProduct(
@Header("Authorization") authorization: String,
@Path(value = "id") id : Int
@Path(value = "id") id : String
): Response<ProductResponse>

@GET("blockchain/proditem/{id}")
suspend fun getProdItem(
@Header("Authorization") authorization: String,
@Path(value = "id") id : String
): Response<ProditemResponse>

@POST("blockchain/pipeline")
suspend fun postPipeline(
@Body body: PipLineBody
): Response<Void>
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package com.seogaemo.hackseoul_android.view

import android.content.Intent
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.seogaemo.hackseoul_android.R
import com.seogaemo.hackseoul_android.databinding.ActivityHomeBinding

class HomeActivity : AppCompatActivity() {
private lateinit var binding: ActivityHomeBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_home)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
binding = ActivityHomeBinding.inflate(layoutInflater)
setContentView(binding.root)

binding.loginButton.setOnClickListener {
startActivity(Intent(this@HomeActivity, LoginActivity::class.java))
}

binding.qrButton.setOnClickListener {
startActivity(Intent(this@HomeActivity, MainActivity::class.java))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,85 @@
package com.seogaemo.hackseoul_android.view

import android.content.Context
import android.os.Bundle
import android.widget.Toast
import androidx.lifecycle.lifecycleScope
import com.bumptech.glide.Glide
import com.seogaemo.hackseoul_android.data.PipLineBody
import com.seogaemo.hackseoul_android.data.ProductResponse
import com.seogaemo.hackseoul_android.database.SharedPreference
import com.seogaemo.hackseoul_android.databinding.ActivityJobHistoryBinding
import com.seogaemo.hackseoul_android.network.RetrofitAPI
import com.seogaemo.hackseoul_android.network.RetrofitClient
import com.seogaemo.hackseoul_android.util.BaseActivity
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class JobHistoryActivity : BaseActivity() {
private lateinit var binding: ActivityJobHistoryBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityJobHistoryBinding.inflate(layoutInflater)
setContentView(binding.root)

val id = intent.getStringExtra("id").toString()

lifecycleScope.launch {
getProduct(this@JobHistoryActivity, id)?.let {
binding.titleText.text = it.title
Glide.with(this@JobHistoryActivity)
.load(it.imageUrl)
.centerCrop()
.into(binding.itemImageView)
}

binding.backButton.setOnClickListener {
finish()
}

binding.submitButton.setOnClickListener {
}
}
}

private suspend fun postPipeline(body: PipLineBody): Void? {
return try {
withContext(Dispatchers.IO) {
val retrofitAPI = RetrofitClient.getInstance().create(RetrofitAPI::class.java)
val response = retrofitAPI.postPipeline(body)
if (response.isSuccessful) {
response.body()
} else {
withContext(Dispatchers.Main) {
}
null
}
}
} catch (e: Exception) {
withContext(Dispatchers.Main) {
}
null
}
}


private suspend fun getProduct(context: Context, id: String): ProductResponse? {
return try {
withContext(Dispatchers.IO) {
val retrofitAPI = RetrofitClient.getInstance().create(RetrofitAPI::class.java)
val response = retrofitAPI.getProduct("bearer ${SharedPreference.token}", id)
if (response.isSuccessful) {
response.body()
} else {

null
}
}
} catch (e: Exception) {

null
}
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.seogaemo.hackseoul_android.view

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.view.View
Expand All @@ -17,6 +19,7 @@ import com.journeyapps.barcodescanner.BarcodeCallback
import com.journeyapps.barcodescanner.BarcodeResult
import com.journeyapps.barcodescanner.DefaultDecoderFactory
import com.seogaemo.hackseoul_android.R
import com.seogaemo.hackseoul_android.database.SharedPreference
import com.seogaemo.hackseoul_android.databinding.ActivityMainBinding
import com.seogaemo.hackseoul_android.util.BaseActivity

Expand Down Expand Up @@ -85,7 +88,17 @@ class MainActivity : BaseActivity() {

private fun createRequest(qrCodeText: String) {
if (qrCodeText.startsWith("http://") || qrCodeText.startsWith("https://")) {

val uri = Uri.parse(qrCodeText)
val id = uri.getQueryParameter("id")
if (SharedPreference.isFirst) {
val intent = Intent(this@MainActivity, ProductActivity::class.java)
intent.putExtra("id", id)
startActivity(intent)
} else {
val intent = Intent(this@MainActivity, JobHistoryActivity::class.java)
intent.putExtra("id", id)
startActivity(intent)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.appcompat.app.AppCompatActivity
import com.seogaemo.hackseoul_android.data.JobHistory
import com.seogaemo.hackseoul_android.database.SharedPreference
import com.seogaemo.hackseoul_android.databinding.ActivitySplashBinding

Expand All @@ -25,18 +26,23 @@ class SplashActivity : AppCompatActivity() {
val data: Uri? = intent?.data

Handler(Looper.getMainLooper()).postDelayed({
if (SharedPreference.isFirst) {
startActivity(Intent(this@SplashActivity, LoginActivity::class.java))
} else {
if (action == Intent.ACTION_VIEW) {
val id = data?.getQueryParameter("id")
val intent = Intent(this@SplashActivity, ProductActivity::class.java)

if (action == Intent.ACTION_VIEW) {
val id = data?.getQueryParameter("id")
if (SharedPreference.isFirst) {
val intent = Intent(this@SplashActivity, JobHistoryActivity::class.java)
intent.putExtra("id", id)
startActivity(intent)
} else {
startActivity(Intent(this@SplashActivity, MainActivity::class.java))
val intent = Intent(this@SplashActivity, ProductActivity::class.java)
intent.putExtra("id", id)
startActivity(intent)
}
} else {
val intent = Intent(this@SplashActivity, HomeActivity::class.java)
startActivity(intent)
}

finishAffinity()
}, 1500)
}
Expand Down
66 changes: 66 additions & 0 deletions app/src/main/res/layout/activity_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,72 @@
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Background_Base_Elevated"
tools:context=".view.HomeActivity">

<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:src="@drawable/coupang"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<View
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/Background_Base_Border"
app:layout_constraintBottom_toTopOf="@+id/login_button" />

<androidx.cardview.widget.CardView
app:cardElevation="0dp"
android:layout_marginBottom="4dp"
android:layout_marginHorizontal="16dp"
android:id="@+id/login_button"
android:layout_width="match_parent"
android:layout_height="44dp"
app:cardBackgroundColor="@color/Background_Accent_Default"
app:cardCornerRadius="4dp"
app:layout_constraintBottom_toTopOf="@+id/qr_button"
app:layout_constraintStart_toStartOf="parent">

<TextView
style="@style/SemiBold15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="로그인하기"
android:textColor="@color/Background_Base_Elevated" />


</androidx.cardview.widget.CardView>

<com.google.android.material.card.MaterialCardView
app:cardElevation="0dp"
android:id="@+id/qr_button"
android:layout_marginHorizontal="16dp"
android:layout_marginBottom="8dp"
app:cardCornerRadius="4dp"
android:layout_width="match_parent"
android:layout_height="44dp"
app:cardBackgroundColor="@color/Background_Base_Elevated"
app:layout_constraintBottom_toBottomOf="parent"
app:strokeColor="@color/Background_Base_Border"
app:strokeWidth="1dp">

<TextView
android:layout_gravity="center"
android:layout_marginVertical="10dp"
style="@style/SemiBold15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="QR 인식하기"
android:textColor="@color/Text_Default_Primary" />

</com.google.android.material.card.MaterialCardView>


</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 3988c06

Please sign in to comment.