Skip to content

Commit 88fb247

Browse files
authored
Merge pull request #7 from ENTS-H104/daffa/dev
90% complete 🤩✨
2 parents 5ea7b93 + 22c8c04 commit 88fb247

File tree

60 files changed

+1175
-557
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1175
-557
lines changed

app/build.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,13 @@ dependencies {
9898

9999
//paging 3
100100
implementation("androidx.paging:paging-runtime-ktx:3.3.0")
101+
102+
// Library PhotoPicker
103+
implementation("androidx.activity:activity-compose:1.9.0")
104+
implementation("androidx.activity:activity-ktx:1.9.0")
105+
// Library Crop Image
106+
// implementation("com.github.yalantis:ucrop:2.2.8")
107+
108+
//skeleton
109+
implementation("com.facebook.shimmer:shimmer:0.5.0")
101110
}

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
tools:ignore="ScopedStorage" />
99
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
1010
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
11+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
12+
android:maxSdkVersion="32" />
1113

1214
<application
1315
android:allowBackup="true"
@@ -24,6 +26,7 @@
2426
android:screenOrientation="portrait"
2527
android:exported="false"
2628
android:windowSoftInputMode="adjustPan" />
29+
2730
<activity
2831
android:name=".ui.auth.AuthActivity"
2932
android:screenOrientation="portrait"
33.1 KB
Loading

app/src/main/java/com/entsh104/highking/data/model/Request.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ data class UpdateUserRequest(val username: String, val phone_number: String)
1010

1111
data class UpdatePhotoUserRequest(val imageUrl: String)
1212

13-
1413
data class CreateTransactionRequest(
1514
val user_uid: String,
1615
val partner_uid: String,

app/src/main/java/com/entsh104/highking/data/model/Response.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ data class UserUpdateResponse(
2323
val phone_number: String?
2424
)
2525

26+
data class UpdatePhotoResponse(
27+
val status: Int,
28+
val message: String,
29+
val data: PhotoData
30+
)
31+
32+
data class PhotoData(
33+
val image_url: String
34+
)
35+
2636
data class UserResponse(
2737
val user_uid: String?,
2838
val verified_status_uuid: String?,
@@ -193,6 +203,24 @@ data class CreateTransactionResponse(
193203
val data: TransactionData
194204
)
195205

206+
data class TransactionDetailResponse(
207+
val status: Int,
208+
val message: String,
209+
val data: List<TransactionDetail>
210+
)
211+
212+
data class TransactionDetail(
213+
val token: String?,
214+
val name: String,
215+
val phone_number: String,
216+
val start_date: String,
217+
val start_time: String,
218+
val status_accepted: String,
219+
val status_payment: String,
220+
val meeting_point: String,
221+
val name_participant: String
222+
)
223+
196224
data class TransactionData(
197225
val transaction_logs_uuid: String,
198226
val user_uid: String,

app/src/main/java/com/entsh104/highking/data/repository/UserRepository.kt

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import androidx.lifecycle.LiveData
2-
import androidx.paging.Pager
3-
import androidx.paging.PagingConfig
4-
import androidx.paging.PagingData
5-
import androidx.paging.PagingSource
6-
import androidx.paging.PagingSourceFactory
1+
import android.content.ContentResolver
2+
import android.net.Uri
3+
import android.provider.OpenableColumns
4+
import android.util.Log
75
import com.entsh104.highking.data.model.BasicResponse
86
import com.entsh104.highking.data.model.LoginRequest
97
import com.entsh104.highking.data.model.MitraProfileResponse
@@ -16,14 +14,21 @@ import com.entsh104.highking.data.model.ResetPasswordRequest
1614
import com.entsh104.highking.data.model.SearchOpenTripResponse
1715
import com.entsh104.highking.data.model.TokenResponse
1816
import com.entsh104.highking.data.model.TripFilter
17+
import com.entsh104.highking.data.model.UpdatePhotoResponse
1918
import com.entsh104.highking.data.model.UpdateUserRequest
20-
import com.entsh104.highking.data.model.UserApiResponse
2119
import com.entsh104.highking.data.model.UserResponse
2220
import com.entsh104.highking.data.model.UserUpdateApiResponse
2321
import com.entsh104.highking.data.source.local.SharedPreferencesManager
24-
import com.entsh104.highking.ui.cust.mountain.MountainPagingSource
22+
import kotlinx.coroutines.CoroutineScope
2523
import kotlinx.coroutines.Dispatchers
24+
import kotlinx.coroutines.launch
2625
import kotlinx.coroutines.withContext
26+
import okhttp3.MediaType.Companion.toMediaTypeOrNull
27+
import okhttp3.MultipartBody
28+
import okhttp3.RequestBody.Companion.asRequestBody
29+
import java.io.File
30+
import java.io.FileInputStream
31+
import java.io.FileOutputStream
2732

2833
class UserRepository(
2934
private val apiService: ApiService,
@@ -81,6 +86,51 @@ class UserRepository(
8186
}
8287
}
8388

89+
suspend fun uploadPhoto(
90+
contentResolver: ContentResolver,
91+
cacheDir: File,
92+
imageUri: Uri
93+
): Result<UpdatePhotoResponse> {
94+
val token = prefs.getToken() ?: return Result.failure(Exception("Token not found"))
95+
Log.d("UploadPhoto", "Token: $token")
96+
val parcelFileDescriptor = contentResolver.openFileDescriptor(imageUri, "r", null) ?: return Result.failure(Exception("Failed to open file descriptor"))
97+
Log.d("UploadPhoto", "File Descriptor opened successfully")
98+
val inputStream = FileInputStream(parcelFileDescriptor.fileDescriptor)
99+
val file = File(cacheDir, contentResolver.getFileName(imageUri))
100+
val outputStream = FileOutputStream(file)
101+
inputStream.copyTo(outputStream)
102+
103+
val requestFile = file.asRequestBody("image/*".toMediaTypeOrNull())
104+
val body = MultipartBody.Part.createFormData("image", file.name, requestFile)
105+
106+
return try {
107+
val response = apiService.updatePhotoUser("Bearer $token", body)
108+
Log.d("UploadPhoto", "Response: ${response.message()}")
109+
if (response.isSuccessful) {
110+
Result.success(response.body()!!)
111+
} else {
112+
Result.failure(Exception("Failed to upload photo: ${response.message()}"))
113+
}
114+
} catch (e: Exception) {
115+
Log.e("UploadPhoto", "Error: ${e.message}", e)
116+
Result.failure(e)
117+
}
118+
119+
}
120+
121+
122+
fun ContentResolver.getFileName(uri: Uri): String {
123+
var name = ""
124+
val returnCursor = this.query(uri, null, null, null, null)
125+
if (returnCursor != null) {
126+
val nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
127+
returnCursor.moveToFirst()
128+
name = returnCursor.getString(nameIndex)
129+
returnCursor.close()
130+
}
131+
return name
132+
}
133+
84134
suspend fun registerUser(
85135
email: String,
86136
username: String,

app/src/main/java/com/entsh104/highking/data/source/local/MountainEntity.kt renamed to app/src/main/java/com/entsh104/highking/data/source/local/entity/MountainEntity.kt

File renamed without changes.

app/src/main/java/com/entsh104/highking/data/source/local/TripEntity.kt renamed to app/src/main/java/com/entsh104/highking/data/source/local/entity/TripEntity.kt

File renamed without changes.

app/src/main/java/com/entsh104/highking/data/source/remote/ApiService.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import com.entsh104.highking.data.model.RegisterRequest
1111
import com.entsh104.highking.data.model.ResetPasswordRequest
1212
import com.entsh104.highking.data.model.SearchOpenTripResponse
1313
import com.entsh104.highking.data.model.TokenResponse
14+
import com.entsh104.highking.data.model.TransactionDetailResponse
1415
import com.entsh104.highking.data.model.TransactionHistoryResponse
16+
import com.entsh104.highking.data.model.UpdatePhotoResponse
1517
import com.entsh104.highking.data.model.UpdatePhotoUserRequest
1618
import com.entsh104.highking.data.model.UpdateUserRequest
1719
import com.entsh104.highking.data.model.UserApiResponse
@@ -46,11 +48,12 @@ interface ApiService {
4648
@Body request: UpdateUserRequest
4749
): Response<UserUpdateApiResponse>
4850

51+
@Multipart
4952
@PUT("users/update/photo")
5053
suspend fun updatePhotoUser(
5154
@Header("Authorization") token: String,
52-
@Part("image_url") imageUrl: MultipartBody.Part
53-
): Response<UserUpdateApiResponse>
55+
@Part imageUrl: MultipartBody.Part
56+
): Response<UpdatePhotoResponse>
5457

5558

5659
@GET("users/get-current-user")
@@ -95,6 +98,9 @@ interface ApiService {
9598
@Query("status") status: String
9699
): Response<TransactionHistoryResponse>
97100

101+
@GET("transaction/get-detail_transaction/{id}")
102+
suspend fun getTransactionDetail(@Path("id") transactionId: String): Response<TransactionDetailResponse>
103+
98104
@GET("open-trips/partners/{partner_uid}")
99105
suspend fun getMitraProfile(@Path("partner_uid") partnerUid: String): Response<MitraProfileResponse>
100106

app/src/main/java/com/entsh104/highking/ui/adapters/OrdersAdapter.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.entsh104.highking.ui.adapters
22

3+
import android.util.Log
34
import android.view.LayoutInflater
45
import android.view.View
56
import android.view.ViewGroup
@@ -16,7 +17,7 @@ import com.entsh104.highking.ui.util.NavOptionsUtil
1617

1718
class OrdersAdapter(
1819
private val orders: Map<String, OpenTripDetail>,
19-
pendingOrders: List<TransactionHistory>
20+
Orders: List<TransactionHistory>
2021
) :
2122
RecyclerView.Adapter<OrdersAdapter.OrderViewHolder>() {
2223

@@ -27,7 +28,7 @@ class OrdersAdapter(
2728
}
2829

2930
override fun onBindViewHolder(holder: OrderViewHolder, position: Int) {
30-
holder.bind(orders.values.elementAt(position))
31+
holder.bind(orders.keys.elementAt(position), orders.values.elementAt(position))
3132
}
3233

3334
override fun getItemCount(): Int {
@@ -39,7 +40,7 @@ class OrdersAdapter(
3940
private val textViewOrderName: TextView = itemView.findViewById(R.id.textViewOrderName)
4041
private val textViewPrice: TextView = itemView.findViewById(R.id.textViewOrderPrice)
4142

42-
fun bind(order: OpenTripDetail?) {
43+
fun bind(transactionId: String, order: OpenTripDetail?) {
4344
Glide.with(itemView.context)
4445
.load(order?.image_url)
4546
.into(imageView)
@@ -49,8 +50,9 @@ class OrdersAdapter(
4950

5051
itemView.setOnClickListener {
5152
if (order != null) {
52-
val action = TicketFragmentDirections.actionNavOrdersToOrderDetailsFragment(order)
53-
it.findNavController().navigate(action, NavOptionsUtil.defaultNavOptions)
53+
val action =
54+
TicketFragmentDirections.actionNavOrdersToOrderDetailsFragment(transactionId, order)
55+
it.findNavController().navigate(action)
5456
}
5557
}
5658
}

0 commit comments

Comments
 (0)