zk před 1 rokem
rodič
revize
4262cfbedd

+ 7 - 1
app/src/main/java/com/atmob/voiceai/handlers/EventHandler.java

@@ -20,7 +20,8 @@ import dagger.hilt.components.SingletonComponent;
 
 public final class EventHandler {
 
-    private static final boolean isToastReport = false;
+    private static boolean isToastReport = false;
+
 
     private static volatile EventHandler INSTANCE;
     private final FirebaseHelper firebaseHelper;
@@ -38,6 +39,11 @@ public final class EventHandler {
         firebaseHelper = entryPoint.firebaseHelper();
     }
 
+    public static void setToastReport() {
+        isToastReport = true;
+        MAIN_HANDLER = new Handler(Looper.getMainLooper());
+    }
+
     private static EventHandler getInstance() {
         if (INSTANCE == null) {
             synchronized (EventHandler.class) {

+ 66 - 0
app/src/main/java/com/atmob/voiceai/module/setting/SettingActivity.java

@@ -9,7 +9,14 @@ import androidx.annotation.Nullable;
 
 import com.atmob.app.lib.base.BaseActivity;
 import com.atmob.voiceai.databinding.SettingActivityBinding;
+import com.atmob.voiceai.handlers.EventHandler;
+import com.atmob.voiceai.sdk.kochava.KochavaHelper;
+import com.atmob.voiceai.utils.ToastUtil;
 
+import java.util.concurrent.TimeUnit;
+
+import atmob.reactivex.rxjava3.core.Observable;
+import atmob.reactivex.rxjava3.disposables.Disposable;
 import dagger.hilt.android.AndroidEntryPoint;
 
 @AndroidEntryPoint
@@ -17,6 +24,11 @@ public class SettingActivity extends BaseActivity<SettingActivityBinding> {
 
     private SettingViewModel settingViewModel;
 
+    private int eventTimes = 0;
+    private Disposable eventSubscribe;
+
+    private int attrTimes = 0;
+    private Disposable attrSubscribe;
 
     public static void start(Context context) {
         Intent intent = new Intent(context, SettingActivity.class);
@@ -41,8 +53,51 @@ public class SettingActivity extends BaseActivity<SettingActivityBinding> {
     private void initView() {
         addTopStatusBarHeight(binding.toolbar);
         binding.toolbar.setNavigationOnClickListener(v -> finish());
+
+        binding.vEvent.setOnClickListener(v -> {
+            if (eventTimes == 0) {
+                if (eventSubscribe != null) {
+                    eventSubscribe.dispose();
+                }
+                eventSubscribe = Observable.timer(5000, TimeUnit.MILLISECONDS)
+                        .subscribe(aLong -> eventTimes = 0);
+                eventTimes++;
+            } else if (eventTimes == 10) {
+                showEventInfo();
+            } else {
+                eventTimes++;
+            }
+        });
+
+        binding.vAttr.setOnClickListener(v -> {
+            if (attrTimes == 0) {
+                if (attrSubscribe != null) {
+                    attrSubscribe.dispose();
+                }
+                attrSubscribe = Observable.timer(5000, TimeUnit.MILLISECONDS)
+                        .subscribe(aLong -> attrTimes = 0);
+                attrTimes++;
+            } else if (attrTimes == 10) {
+                showAttrInfo();
+            } else {
+                attrTimes++;
+            }
+        });
+    }
+
+    private void showAttrInfo() {
+        StringBuffer sb = new StringBuffer();
+        sb.append("ka attribute:");
+        sb.append(KochavaHelper.isAttributed());
+        ToastUtil.show(sb.toString(), ToastUtil.LENGTH_SHORT);
+    }
+
+    private void showEventInfo() {
+        EventHandler.setToastReport();
+        ToastUtil.show("Event toast is open.", ToastUtil.LENGTH_SHORT);
     }
 
+
     @Override
     protected boolean shouldImmersion() {
         return true;
@@ -54,4 +109,15 @@ public class SettingActivity extends BaseActivity<SettingActivityBinding> {
         settingViewModel = getViewModelProvider().get(SettingViewModel.class);
         binding.setSettingViewModel(settingViewModel);
     }
+
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+        if (eventSubscribe != null) {
+            eventSubscribe.dispose();
+        }
+        if (attrSubscribe != null) {
+            attrSubscribe.dispose();
+        }
+    }
 }

+ 15 - 0
app/src/main/res/layout/setting_activity.xml

@@ -163,6 +163,21 @@
             app:layout_constraintStart_toStartOf="parent"
             tools:text="version1.0" />
 
+        <View
+            android:id="@+id/v_event"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintBottom_toBottomOf="parent"
+            android:layout_width="60dp"
+            android:layout_height="60dp" />
+
+
+        <View
+            android:id="@+id/v_attr"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintBottom_toBottomOf="parent"
+            android:layout_width="60dp"
+            android:layout_height="60dp" />
+
 
     </androidx.constraintlayout.widget.ConstraintLayout>
 </layout>