Pq 2 лет назад
Родитель
Сommit
69885b4bc2

+ 19 - 9
musictuner/src/main/java/com/cooleshow/musictuner/MusicTunerActivity.java

@@ -65,18 +65,13 @@ public class MusicTunerActivity extends BaseActivity<ActivityMusicTunerLayoutBin
                 @Override
                 public void onResult(float pitchInHz) {
                     VoiceToneBean voiceToneBean = VoiceDataUtils.getInstance().searchTarget(pitchInHz);
+                    if (!checkActivityExist()) {
+                        return;
+                    }
                     runOnUiThread(new Runnable() {
                         @Override
                         public void run() {
-                            if (voiceToneBean != null) {
-                                viewBinding.tvResult.setText(getResultText(voiceToneBean));
-                                viewBinding.tvResultVoiceTones.setText(voiceToneBean.name);
-                                viewBinding.tvBeforeResultVoiceTones.setText(voiceToneBean.beforeName);
-                                viewBinding.tvAfter.setText(voiceToneBean.afterName);
-                                long differenceText = getDifferenceText(voiceToneBean.difference);
-                                viewBinding.tvDifference.setText(differenceText != -1 ? String.format("%d¢", differenceText) : "");
-                                viewBinding.viewDashBoard.setProgress((int) differenceText);
-                            }
+                            updateUI(voiceToneBean);
                         }
                     });
                 }
@@ -85,6 +80,21 @@ public class MusicTunerActivity extends BaseActivity<ActivityMusicTunerLayoutBin
         mMusicTunerHelper.start();
     }
 
+    private void updateUI(VoiceToneBean voiceToneBean) {
+        if (voiceToneBean != null) {
+            if (!checkActivityExist()) {
+                return;
+            }
+            viewBinding.tvResult.setText(getResultText(voiceToneBean));
+            viewBinding.tvResultVoiceTones.setText(voiceToneBean.name);
+            viewBinding.tvBeforeResultVoiceTones.setText(voiceToneBean.beforeName);
+            viewBinding.tvAfter.setText(voiceToneBean.afterName);
+            long differenceText = getDifferenceText(voiceToneBean.difference);
+            viewBinding.tvDifference.setText(differenceText != -1 ? String.format("%d¢", differenceText) : "");
+            viewBinding.viewDashBoard.setProgress((int) differenceText);
+        }
+    }
+
     private String getResultText(VoiceToneBean voiceToneBean) {
         if (voiceToneBean != null) {
             int value = (int) voiceToneBean.voiceFrequencyValue;