diff --git a/app/src/main/java/com/seogaemo/hackseoul_android/data/CreatedAt.kt b/app/src/main/java/com/seogaemo/hackseoul_android/data/CreatedAt.kt new file mode 100644 index 0000000..b72a129 --- /dev/null +++ b/app/src/main/java/com/seogaemo/hackseoul_android/data/CreatedAt.kt @@ -0,0 +1,3 @@ +package com.seogaemo.hackseoul_android.data + +class CreatedAt \ No newline at end of file diff --git a/app/src/main/java/com/seogaemo/hackseoul_android/data/PipLineBody.kt b/app/src/main/java/com/seogaemo/hackseoul_android/data/PipLineBody.kt new file mode 100644 index 0000000..fe5bca2 --- /dev/null +++ b/app/src/main/java/com/seogaemo/hackseoul_android/data/PipLineBody.kt @@ -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 +) \ No newline at end of file diff --git a/app/src/main/java/com/seogaemo/hackseoul_android/data/ProditemResponse.kt b/app/src/main/java/com/seogaemo/hackseoul_android/data/ProditemResponse.kt new file mode 100644 index 0000000..309f029 --- /dev/null +++ b/app/src/main/java/com/seogaemo/hackseoul_android/data/ProditemResponse.kt @@ -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 +) \ No newline at end of file diff --git a/app/src/main/java/com/seogaemo/hackseoul_android/network/RetrofitAPI.kt b/app/src/main/java/com/seogaemo/hackseoul_android/network/RetrofitAPI.kt index 121a761..cea8b04 100644 --- a/app/src/main/java/com/seogaemo/hackseoul_android/network/RetrofitAPI.kt +++ b/app/src/main/java/com/seogaemo/hackseoul_android/network/RetrofitAPI.kt @@ -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 @@ -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 @GET("product/{id}") suspend fun getProduct( @Header("Authorization") authorization: String, - @Path(value = "id") id : Int + @Path(value = "id") id : String ): Response + + @GET("blockchain/proditem/{id}") + suspend fun getProdItem( + @Header("Authorization") authorization: String, + @Path(value = "id") id : String + ): Response + + @POST("blockchain/pipeline") + suspend fun postPipeline( + @Body body: PipLineBody + ): Response } \ No newline at end of file diff --git a/app/src/main/java/com/seogaemo/hackseoul_android/view/HomeActivity.kt b/app/src/main/java/com/seogaemo/hackseoul_android/view/HomeActivity.kt index f727b04..a3334c7 100644 --- a/app/src/main/java/com/seogaemo/hackseoul_android/view/HomeActivity.kt +++ b/app/src/main/java/com/seogaemo/hackseoul_android/view/HomeActivity.kt @@ -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)) } } } \ No newline at end of file diff --git a/app/src/main/java/com/seogaemo/hackseoul_android/view/JobHistoryActivity.kt b/app/src/main/java/com/seogaemo/hackseoul_android/view/JobHistoryActivity.kt index bd5c9ee..8b798b3 100644 --- a/app/src/main/java/com/seogaemo/hackseoul_android/view/JobHistoryActivity.kt +++ b/app/src/main/java/com/seogaemo/hackseoul_android/view/JobHistoryActivity.kt @@ -1,8 +1,20 @@ 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 @@ -10,5 +22,64 @@ class JobHistoryActivity : BaseActivity() { 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 + } + } + } \ No newline at end of file diff --git a/app/src/main/java/com/seogaemo/hackseoul_android/view/MainActivity.kt b/app/src/main/java/com/seogaemo/hackseoul_android/view/MainActivity.kt index 6c68bb6..23c05e4 100644 --- a/app/src/main/java/com/seogaemo/hackseoul_android/view/MainActivity.kt +++ b/app/src/main/java/com/seogaemo/hackseoul_android/view/MainActivity.kt @@ -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 @@ -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 @@ -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) + } } } diff --git a/app/src/main/java/com/seogaemo/hackseoul_android/view/SplashActivity.kt b/app/src/main/java/com/seogaemo/hackseoul_android/view/SplashActivity.kt index ba2249d..cd705eb 100644 --- a/app/src/main/java/com/seogaemo/hackseoul_android/view/SplashActivity.kt +++ b/app/src/main/java/com/seogaemo/hackseoul_android/view/SplashActivity.kt @@ -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 @@ -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) } diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml index 6552111..bce10d3 100644 --- a/app/src/main/res/layout/activity_home.xml +++ b/app/src/main/res/layout/activity_home.xml @@ -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"> + + + + + + + + + + + + + + + + + + \ No newline at end of file