Parcourir la source

[세팅][New] 세팅 메인 로직 추가 2

hyodong.min il y a 7 ans
Parent
commit
e3aa14dd7e

+ 2 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/setting/ISettingView.java

@@ -37,4 +37,6 @@ public interface ISettingView extends IView {
 
   void notifyUpdate();
 
+  void click(int index);
+
 }

+ 15 - 3
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/setting/SettingExpandableListViewAdapter.java

@@ -7,6 +7,7 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import kr.co.zumo.app.R;
@@ -29,10 +30,13 @@ public class SettingExpandableListViewAdapter extends RecyclerView.Adapter<Setti
   private Context context;
   private IEventListener listener;
   private RecyclerView recyclerView;
+  private List<SettingViewHolder> holders;
 
   public SettingExpandableListViewAdapter(Context context, IEventListener listener) {
     this.context = context;
     this.listener = listener;
+
+    holders = new ArrayList<>();
   }
 
   @Override
@@ -75,15 +79,17 @@ public class SettingExpandableListViewAdapter extends RecyclerView.Adapter<Setti
 
     holder.bind(event -> {
       if (null != listener) {
+
+        listener.onEvent(event);
+
         if (event.getEventId() == Event.TOGGLE) {
           recyclerView.scrollToPosition(event.getInteger());
         }
-        else {
-          listener.onEvent(event);
-        }
       }
     });
 
+    holders.add(holder);
+
   }
 
   @Override
@@ -117,4 +123,10 @@ public class SettingExpandableListViewAdapter extends RecyclerView.Adapter<Setti
       notifyItemChanged(i, settingBean);
     }
   }
+
+  public void click(int index) {
+    for (SettingViewHolder holder : holders) {
+      holder.click(index);
+    }
+  }
 }

+ 7 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/setting/SettingFragment.java

@@ -64,8 +64,9 @@ public class SettingFragment extends FragmentBase<SettingPresenter> implements I
     textUpdate = findViewById(R.id.text_update);
 
     textUpdate.setOnClickListener(v -> {
-      presenter.onEvent(new Event.Builder(Event.CLICK).integer(4).build());
+      presenter.onEvent(new Event.Builder(Event.CLICK).integer(SettingPresenter.SETTING_UPDATE).build());
     });
+
   }
 
   @Override
@@ -130,4 +131,9 @@ public class SettingFragment extends FragmentBase<SettingPresenter> implements I
   public void notifyUpdate() {
     adapter.update(settingBean);
   }
+
+  @Override
+  public void click(int index) {
+    adapter.click(index);
+  }
 }

+ 48 - 4
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/setting/SettingPresenter.java

@@ -20,6 +20,12 @@ import kr.co.zumo.app.lifeplus.view.Event;
 import kr.co.zumo.app.lifeplus.view.command.AppUpdateCommand;
 import kr.co.zumo.app.lifeplus.view.command.FragmentBackStackChangeCommand;
 import kr.co.zumo.app.lifeplus.view.command.TextShareCommand;
+import kr.co.zumo.app.lifeplus.view.dialog.DialogBase;
+import kr.co.zumo.app.lifeplus.view.dialog.DialogBuilder;
+import kr.co.zumo.app.lifeplus.view.dialog.DialogID;
+import kr.co.zumo.app.lifeplus.view.dialog.IAttribute;
+import kr.co.zumo.app.lifeplus.view.dialog.IDialogResultListener;
+import kr.co.zumo.app.lifeplus.view.dialog.TextDialog;
 import kr.co.zumo.app.lifeplus.view.presenter.Presenter;
 
 /**
@@ -40,10 +46,11 @@ public class SettingPresenter extends Presenter<SettingModel, ISettingView> {
   public static final int SETTING_INFO = 3;
   public static final int SETTING_UPDATE = 4;
 
+  private boolean isEnabled = false;
+
   public SettingPresenter(SettingModel model, ISettingView view) {
     super(model, view);
 
-    this.model.loadSettingInfo();
   }
 
   @Override
@@ -53,7 +60,8 @@ public class SettingPresenter extends Presenter<SettingModel, ISettingView> {
 
   @Override
   protected void startInternal() {
-
+    this.model.loadSettingInfo();
+    isEnabled = false;
   }
 
   @Override
@@ -89,7 +97,7 @@ public class SettingPresenter extends Presenter<SettingModel, ISettingView> {
 
   @Override
   protected void pauseInternal() {
-
+    isEnabled = false;
   }
 
   @Override
@@ -100,12 +108,19 @@ public class SettingPresenter extends Presenter<SettingModel, ISettingView> {
 
   @Override
   protected void onEventInternal(Event event) {
+    if (false == isEnabled) {
+      return;
+    }
+    
     Log.i("APP# SettingPresenter | onEventInternal", "|" + event.toString());
     int index = event.getInteger();
     int id = event.getEventId();
     String str = event.getString();
     boolean bool = event.getBool();
     switch (event.getEventId()) {
+      case Event.TOGGLE:
+        view.click(index);
+        break;
       case Event.SWITCH:
         if (index == SettingPresenter.SETTING_COMMON) {
           // 기본 설정
@@ -132,7 +147,7 @@ public class SettingPresenter extends Presenter<SettingModel, ISettingView> {
         break;
       case Event.CLICK:
         if (index == SettingPresenter.SETTING_COMMON) {
-          if(str.equals(SettingViewHolder.MEMBER_CONFIRM)) {
+          if (str.equals(SettingViewHolder.MEMBER_CONFIRM)) {
             // 회원 관리/확인
             // todo 회원 비회원 구분
           }
@@ -191,13 +206,42 @@ public class SettingPresenter extends Presenter<SettingModel, ISettingView> {
         if (Event.SETTING_LOAD == event.getInteger()) {
           // 세팅 로딩 완료
           render();
+          isEnabled = true;
         }
         break;
+      case Event.ERROR:
+        showErrorDialog(event.getString());
+        break;
       default:
         break;
     }
   }
 
+  private void showErrorDialog(String string) {
+    DialogBuilder.create(DialogID.CONFIRM)
+      .listener(new IDialogResultListener() {
+        @Override
+        public void onDialogResult(DialogBase dialog, Event event) {
+          if (event.getEventId() == Event.CONFIRM) {
+            dialog.dispose();
+
+            onBackPressed();
+          }
+        }
+
+        @Override
+        public void onDialogCanceled(DialogBase dialog) {
+          dialog.dispose();
+
+          onBackPressed();
+        }
+      })
+      .attribute((IAttribute<TextDialog>) dialog -> {
+        dialog.setText(string);
+      })
+      .show();
+  }
+
   private void render() {
     SettingBean settingBean = model.getSettingBean();
 

+ 9 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/setting/SettingViewHolder.java

@@ -53,16 +53,24 @@ public abstract class SettingViewHolder extends RecyclerView.ViewHolder {
 
   public abstract void update(SettingHolderBean settingBean);
 
+  public void click(int index) {
+    if (index == getAdapterPosition()) {
+      onClickHolderInternal();
+    }
+  }
+
   protected final void dispatchEvent(Event event) {
     if (null != listener) {
       listener.onEvent(event);
     }
   }
+
   protected final void onClickHolder() {
     listener.onEvent(new Event.Builder(Event.TOGGLE).integer(getAdapterPosition()).build());
-    onClickHolderInternal();
   }
 
+
   protected abstract void bindInternal();
+
   protected abstract void onClickHolderInternal();
 }

+ 1 - 0
app/src/main/res/layout/setting_custom_menu1.xml

@@ -3,6 +3,7 @@
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
+  android:background="@color/CFFFFFF"
   android:id="@+id/setting_custom_menu_layout1"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"

+ 3 - 2
app/src/main/res/layout/setting_custom_menu2.xml

@@ -4,6 +4,7 @@
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:id="@+id/setting_custom_menu_layout1"
+  android:background="@color/CFFFFFF"
   android:layout_width="match_parent"
   android:layout_height="wrap_content">
 
@@ -80,13 +81,13 @@
       android:layout_height="wrap_content"
       android:lineSpacingExtra="4sp"
       android:padding="10dp"
-      android:text="@string/setting_menu2_code"
       android:textColor="@color/C666666"
       android:textSize="12sp"
       app:layout_constraintBottom_toBottomOf="@+id/text_view_share"
       app:layout_constraintEnd_toEndOf="parent"
       app:layout_constraintEnd_toStartOf="@+id/guide_end"
-      app:layout_constraintTop_toTopOf="@+id/text_view_share"/>
+      app:layout_constraintTop_toTopOf="@+id/text_view_share"
+      tools:text="@string/setting_menu2_code"/>
 
     <TextView
       android:id="@+id/text_view_register_code"

+ 1 - 0
app/src/main/res/layout/setting_custom_menu3.xml

@@ -4,6 +4,7 @@
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:id="@+id/setting_custom_menu_layout1"
+  android:background="@color/CFFFFFF"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:minHeight="70dp">

+ 1 - 0
app/src/main/res/layout/setting_custom_menu4.xml

@@ -4,6 +4,7 @@
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:id="@+id/setting_custom_menu_layout1"
+  android:background="@color/CFFFFFF"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:minHeight="70dp">