Skip to content

Fav_Apilnterfave, xml 🍞 #12

Description

@honghyoeun

1. ApiInterface.java__[Retrofit을 μ‚¬μš©ν•˜μ—¬ μ„œλ²„μ™€μ˜ 톡신 처리 λ©”μ†Œλ“œ]

/*μƒν’ˆ 이미지λ₯Ό μ—…λ‘œλ“œ*/
@Multipart
    @POST("/api/v1/product/newimage/{productId}")
    Call<ProductImageResponse> uploadProductImage(@Header("Authorization") String TOKEN, @Path("productId") Integer productId, @Part MultipartBody.Part image);

/*μ‚¬μš©μžκ°€ μ’‹μ•„ν•˜λŠ” μƒν’ˆ λͺ©λ‘ κ°€μ Έμ˜€κΈ°*/
    @GET("/api/v1/product/like")
    Call<List<FavModel>> getMyFav(@Header("Authorization") String TOKEN);

각각의 λ©”μ†Œλ“œλŠ” μ„œλ²„μ˜ API μ—”λ“œν¬μΈνŠΈμ™€ ν†΅μ‹ ν•˜κΈ° μœ„ν•œ μš”μ²­ ν˜•μ‹ μ •μ˜, 비동기적인 ν˜ΈμΆœμ„ μ²˜λ¦¬ν•  수 μžˆλŠ” β€˜Call’ 객체 λ°˜ν™˜

  • @Multipart : λ©€ν‹°νŒŒνŠΈ μš”μ²­μ— μ‚¬μš©, ν…μŠ€νŠΈμ™€ 파일 λ“± λ‹€μ–‘ν•œ μ’…λ₯˜μ˜ 데이터λ₯Ό ν•¨κ»˜ μ„œλ²„λ‘œ 전솑
  • @post : post λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•˜μ—¬ μ§€μ •λœ 경둜("/api/v1/product/newimage/{productId}")둜 μš”μ²­μ„ 보냄, {productId}λŠ” 경둜 λ³€μˆ˜λ‘œ, μš”μ²­ν•  λ•Œ μ‹€μ œ prodectId 값을 λŒ€μ²΄
  • Call<ProductImageResponse> : Retrofit의 β€˜call’ 클래슀λ₯Ό μ‚¬μš©ν•˜μ—¬ λΉ„λ™κΈ°μ μœΌλ‘œ μ„œλ²„λ‘œλΆ€ν„° 응닡 받을 수 μžˆλŠ” 호좜 μ •μ˜
  • @Header("Authorization")String TOKEN : μš”μ²­ 헀더에 TOKEN κ°’ 포함, 이λ₯Ό 톡해 μ„œλ²„λŠ” μš”μ²­μ„ 보낸 μ‚¬μš©μžλ₯Ό μΈμ¦ν•˜κ³  κΆŒν•œ 확인
  • @Path : λ©€ν‹°νŒŒνŠΈ μš”μ²­μ˜ 일뢀인 image κ°’ μ •μ˜
  • @GET**("/api/v1/product/like")** : GET λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•˜μ—¬ ("/api/v1/product/like") 경둜둜 μš”μ²­μ„ 보냄
  • @Call<List<FavModel>> : FavModel 객체의 리슀트λ₯Ό λΉ„λ™κΈ°μ μœΌλ‘œ 받을 수 μžˆλŠ” 호좜 μ •μ˜
  • @Header("Authorization" String TOKEN) : 헀더와 ν•¨κ»˜ TOKEN κ°’ μš”μ²­ 헀더에 포함

2. fragment_favorite.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <androidx.appcompat.widget.Toolbar
            android:id="@+id/detail_navbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/greenbtn"
            android:elevation="4dp">

            <TextView
                android:id="@+id/toolbar_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:textColor="@color/black"
                android:drawableStart="@drawable/ic_favorite_border"
                android:drawablePadding="5dp"
                android:text="MY"
                android:textSize="22sp"
                android:textStyle="bold" />
        </androidx.appcompat.widget.Toolbar>

    <ListView
        android:id="@+id/favListV"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    </LinearLayout>
</FrameLayout>
  • **android:orientation="vertical" :** ν¬ν•¨λœ 뷰듀을 수직 λ°©ν–₯으둜 λ°°μΉ˜ν•˜λŠ” λ°©ν–₯ μ§€μ •
  • **android:elevation** : νˆ΄λ°”μ˜ 고도λ₯Ό μ„€μ •, 고도 값이 λ†’μ„μˆ˜λ‘ νˆ΄λ°”κ°€ 더 높은 μœ„μΉ˜μ— λ–  있음

image

3. fav_item.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="8dp">

    <ImageView
        android:id="@+id/productImage"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:src="@drawable/ic_user" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="4">

            <ImageButton
                android:id="@+id/removeFav"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:background="#00ff0000"
                android:src="@drawable/ic_favorite"
                app:tint="@color/pink3" />

        </LinearLayout>

        <TextView
            android:id="@+id/productTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="product name"
            android:textSize="22sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/productPrice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="hohoho"
            android:textSize="18sp" />

    </LinearLayout>

</LinearLayout>

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions