MinePacu / BoothListManager_ForAndroid

안드로이드용 부스 관리 프로그램
0 stars 0 forks source link

부스 번호와 부스 이름을 받으면 시트에 자동으로 부스 번호를 붙이는 기능 #31

Open MinePacu opened 6 months ago

MinePacu commented 6 months ago

목표

사용자에게 부스 번호와 부스 이름을 입력 받아서 시트에서 자동으로 해당 부스의 행을 찾아 부스 번호를 넣어주는 기능 구현해보기

MinePacu commented 6 months ago

UI - fragment_hyperlinkgenerator

추가 코드 목록

부스 번호 할당 카드

        <com.google.android.material.card.MaterialCardView
            android:id="@+id/card_putBoothnumber"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="8dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/card_moveBoothInfo">

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

제목 및 서브 제목

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="16dp">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="부스 번호 붙이기"
                    android:textAppearance="?attr/textAppearanceTitleMedium" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="3dp"
                    android:text="입력받은 부스 이름과 부스 번호로 시트에서 해당 부스를 찾아 부스 번호를 지정합니다."
                    android:textAppearance="?attr/textAppearanceBodyMedium"
                    android:textColor="?android:attr/textColorSecondary" />

                </LinearLayout>

시트 선택기

                <com.google.android.material.button.MaterialButtonToggleGroup
                    android:id="@+id/selection_sheet_putBoothNumber"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="16dp"
                    android:layout_gravity="center"
                    app:singleSelection="true"
                    app:selectionRequired="true">
                    <Button
                        style="?attr/materialButtonOutlinedStyle"
                        android:id="@+id/preorderButton_putBoothNumber"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="선입금, 인포"
                        />
                    <Button
                        style="?attr/materialButtonOutlinedStyle"
                        android:id="@+id/maIlorderButton_putBoothNumber"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="통신판매"
                        />
                    <Button
                        style="?attr/materialButtonOutlinedStyle"
                        android:id="@+id/graspingdemandButton_putBoothNumber"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="수요조사"
                        />
                </com.google.android.material.button.MaterialButtonToggleGroup>

부스 이름 및 부스 번호 텍스트 필드

                <com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/edit_boothname_layout_putBoothNumber"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:layout_marginTop="12dp"
                    android:layout_marginEnd="15dp"
                    android:ems="10"
                    android:hint="부스 이름"
                    app:helperText="부스 번호를 붙일 부스의 이름입니다. 워크 시트에 해당 부스가 없으면 번호가 등록되지 않습니다."
                    android:inputType="text"
                    app:errorEnabled="true"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:endIconMode="clear_text">

                    <com.google.android.material.textfield.TextInputEditText
                        android:id="@+id/edit_boothname_toputBoothNumber"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />
                </com.google.android.material.textfield.TextInputLayout>

                <com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/edit_BoothNumber_layout_toputBoothNumer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:layout_marginTop="12dp"
                    android:layout_marginEnd="15dp"
                    android:ems="10"
                    android:hint="부스 번호"
                    app:helperText="공식에서 해당 부스에 부여한 부스 번호입니다. 일반적으로 [부스 종류 코드] + [숫자] 조합입니다."
                    android:inputType="text"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/edit_linkLabel_layout"
                    app:endIconMode="clear_text">

                    <com.google.android.material.textfield.TextInputEditText
                        android:id="@+id/edit_boothnumber_toputBoothNumber"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />
                </com.google.android.material.textfield.TextInputLayout>

할당 및 텍스트 비우기 버튼

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="right">

                    <Button
                        android:id="@+id/putBoothNumberButton"
                        style="@style/Widget.Material3.Button"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_marginEnd="21dp"
                        android:layout_marginBottom="16dp"
                        android:text="부스 번호 등록"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintTop_toBottomOf="@id/edit_movedrownumber_layout" />

                    <Button
                        android:id="@+id/EmptyTextFieldButton_putBoothNumber"
                        style="@style/Widget.Material3.Button.ElevatedButton"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_marginRight="24dp"
                        android:text="@string/button_emptyText"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintRight_toLeftOf="@id/moveBoothDataButton"
                        app:layout_constraintTop_toBottomOf="@id/edit_movedrownumber_layout"
                        app:layout_constraintVertical_bias="0.857" />

                </LinearLayout>

Code - HyperLinkGeneratorFragment, HyperLinkGeneratorViewModel

추가 코드 목록

HyperLinkGeneratorFragment - 시트 선택기 기능 할당 밑 버튼 기능 할당

        // 시트 선택기 기능 할당
        binding.selectionSheetPutBoothNumber.addOnButtonCheckedListener { buttonToggleGroup, checkedId, isChecked ->
            changeSheetNumber(view, prefs, buttonToggleGroup)
        }

        // 부스 번호 할당 버튼 기능 할당 (HyperLinkGeneratorVIewModel로 변수 전달)
        binding.putBoothNumberButton.setOnClickListener {
            val boothname_put = binding.editBoothnameToputBoothNumber.text.toString()
            val boothNumber_put = binding.editBoothnumberToputBoothNumber.text.toString()

            customProgressPage?.window?.setBackgroundDrawable(
                ColorDrawable(Color.TRANSPARENT)
            )
            customProgressPage?.show()

            //  텍스트 비우기 버튼 기능 할당
            hyperLinkGeneratorViewModel.putBoothNumberToSpecificBooth(it, customProgressPage, boothname_put, boothNumber_put)
        }

        binding.EmptyTextFieldButtonPutBoothNumber.setOnClickListener {
            binding.editBoothnameToputBoothNumber.setText("")
            binding.editBoothnumberToputBoothNumber.setText("")
        }

HyperLinkGeneratorViewModel - PythonClass로 변수 전달

    fun putBoothNumberToSpecificBooth(view: View, processingRing: ProgressPage?, boothName: String, boothNumber: String) : Job {
        return viewModelScope.launch {
            val result = PythonClass.putBoothNumbertoSpecificBooth(boothName, boothNumber)

            when (result) {
                is Result.Success<Boolean> -> {
                    processingRing?.hide()
                    Snackbar.make(view, "부스 정보를 성공적으로 이동했습니다.", Snackbar.LENGTH_LONG)
                        .show()
                }
                else -> {
                    processingRing?.hide()
                    Snackbar.make(view, "부스 정보를 이동하지 못했습니다.", Snackbar.LENGTH_LONG)
                        .show()
                }
            }
        }
    }

Code - PythonClass

추가 코드 목록

Python 모듈의 함수 호출

        suspend fun putBoothNumbertoSpecificBooth(boothName: String, boothNumber: String) : Result<Boolean> {
            return withContext(Dispatchers.IO) {
                Log.d("Debug", "Fun putBoothNumbertoSpecificBooth is Executed")
                val result = boothListManagementModule.callAttr("putBoothNumbertoSpecificBooth", boothName, boothNumber)

                Log.d(
                    "Debug",
                    when {
                        (result == null) -> "IsNull of result from putBoothNumbertoSpecificBooth : true"
                        else -> "IsNull of result from putBoothNumbertoSpecificBooth : false"
                    })

                if (result != null) {
                    Result.Success(true)
                } else {
                    Result.Error(Exception("부스 번호를 등록하지 못했습니다."))
                }
            }
        }

Code - BoothListManagementModule

추가 코드 목록

부스 번호 할당 함수 정의

def putBoothNumbertoSpecificBooth(boothname: str, boothnumber: str):
  """
  매개 변수 boothname에 해당하는 부스 데이터에 지정한 부스 번호 (boothnumber) 를 할당합니다.
  해당 부스를 찾지 못한 경우, None을 반환합니다.

  :param boothname 부스 번호를 할당할 부스의 이름
  :param boothnumber 할당할 부스 번호, 일반적으로 [부스 코드] + [숫자] 조합이며, [부스 코드]에 소문자 알파벳이 있을 경우, 자동으로 대문자로 변환합니다. 
  """
  sh  = gc.open_by_key(sheetId)
  sheet = sh.get_worksheet(sheetNumber)

  uppered_boothnumber = boothnumber.upper()

  cell = sheet.find(boothname)
  if cell != None:
    return sheet.update_acell(f"{BoothNumber_Col_Alphabet}{cell.row}", uppered_boothnumber)
  else:
    return None