From f8f97794653ac460a9159057070db93162f479d5 Mon Sep 17 00:00:00 2001
From: mueller-ma <mueller-ma@users.noreply.github.com>
Date: Tue, 25 Sep 2018 18:40:55 +0200
Subject: [PATCH] Use Toasty library for Toasts (#991)

Signed-off-by: mueller-ma <mueller-ma@users.noreply.github.com>
---
 mobile/build.gradle                                    |  1 +
 .../org/openhab/habdroid/core/OpenHABVoiceService.java | 10 +++++++---
 .../org/openhab/habdroid/ui/OpenHABMainActivity.java   |  8 +++-----
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/mobile/build.gradle b/mobile/build.gradle
index c6bdd2c9..2b840ae3 100644
--- a/mobile/build.gradle
+++ b/mobile/build.gradle
@@ -120,6 +120,7 @@ dependencies {
     implementation('com.mikepenz:aboutlibraries:6.0.8@aar') {
         transitive = true
     }
+    implementation 'com.github.GrenderG:Toasty:1.3.0'
 
     // Crash reporting
     fullImplementation('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
diff --git a/mobile/src/main/java/org/openhab/habdroid/core/OpenHABVoiceService.java b/mobile/src/main/java/org/openhab/habdroid/core/OpenHABVoiceService.java
index e91d6f35..2f44f9ed 100644
--- a/mobile/src/main/java/org/openhab/habdroid/core/OpenHABVoiceService.java
+++ b/mobile/src/main/java/org/openhab/habdroid/core/OpenHABVoiceService.java
@@ -15,6 +15,7 @@ import android.os.Handler;
 import android.os.Looper;
 import android.speech.RecognizerIntent;
 import android.support.annotation.Nullable;
+import android.support.v4.content.ContextCompat;
 import android.util.Log;
 import android.widget.Toast;
 
@@ -28,9 +29,10 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
 
+import es.dmoral.toasty.Toasty;
+
 /**
- * This service handles voice commands and sends them to OpenHAB.
- * It will use the openHAB base URL if passed in the intent's extra.
+ * This service handles voice commands and sends them to openHAB.
  */
 public class OpenHABVoiceService extends IntentService {
     private static final String TAG = OpenHABVoiceService.class.getSimpleName();
@@ -92,6 +94,8 @@ public class OpenHABVoiceService extends IntentService {
     }
 
     private void showToast(CharSequence text) {
-        mHandler.post(() -> Toast.makeText(this, text, Toast.LENGTH_SHORT).show());
+        mHandler.post(() -> Toasty.custom(this, text, R.drawable.ic_openhab_appicon_24dp,
+                ContextCompat.getColor(this, R.color.openhab_orange), Toast.LENGTH_SHORT,
+                true, true).show());
     }
 }
diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/OpenHABMainActivity.java b/mobile/src/main/java/org/openhab/habdroid/ui/OpenHABMainActivity.java
index 9c478dd2..b2c6c8d3 100644
--- a/mobile/src/main/java/org/openhab/habdroid/ui/OpenHABMainActivity.java
+++ b/mobile/src/main/java/org/openhab/habdroid/ui/OpenHABMainActivity.java
@@ -108,6 +108,7 @@ import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
+import es.dmoral.toasty.Toasty;
 import okhttp3.Call;
 import okhttp3.Headers;
 import okhttp3.Request;
@@ -507,9 +508,6 @@ public class OpenHABMainActivity extends AppCompatActivity implements
         openNotificationsPageIfNeeded();
     }
 
-    /**
-     * Overriding onStop to enable Google Analytics stats collection
-     */
     @Override
     public void onStop() {
         Log.d(TAG, "onStop()");
@@ -1012,8 +1010,8 @@ public class OpenHABMainActivity extends AppCompatActivity implements
                 startActivity(new Intent(Intent.ACTION_VIEW,
                         Uri.parse("market://details?id=com.google.android.googlequicksearchbox")));
             } catch (ActivityNotFoundException appStoreNotFoundException) {
-                Toast.makeText(this, R.string.error_no_app_store_found,
-                        Toast.LENGTH_LONG).show();
+                Toasty.error(this, getString(R.string.error_no_app_store_found),
+                        Toast.LENGTH_LONG, true).show();
             }
         }
     }
-- 
GitLab