From 148c9e585c6820e567ac19c33df5ca055c0d680f Mon Sep 17 00:00:00 2001
From: Janne Koschinski <janne@kuschku.de>
Date: Tue, 17 Oct 2017 01:01:18 +0200
Subject: [PATCH] Improves readability of recents menu by changing the
 background color of the header to the primaryDark color by default, removes
 debug statement in crash handler

---
 .../quasseldroid_ng/ui/setup/SetupActivity.kt | 17 +++++++++++++++++
 .../util/helper/ActivityHelper.kt             | 19 +++++++++++++++++--
 .../util/service/ServiceBoundActivity.kt      | 16 ++++++++++++++++
 .../java/de/kuschku/malheur/CrashHandler.kt   |  4 ++--
 4 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/setup/SetupActivity.kt b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/setup/SetupActivity.kt
index 0493f4682..5465c5995 100644
--- a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/setup/SetupActivity.kt
+++ b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/setup/SetupActivity.kt
@@ -4,6 +4,8 @@ import android.arch.lifecycle.MutableLiveData
 import android.arch.lifecycle.Observer
 import android.os.Bundle
 import android.os.Parcelable
+import android.support.annotation.ColorRes
+import android.support.annotation.DrawableRes
 import android.support.design.widget.FloatingActionButton
 import android.support.v4.app.FragmentManager
 import android.support.v4.app.FragmentStatePagerAdapter
@@ -17,6 +19,7 @@ import de.kuschku.quasseldroid_ng.R
 import de.kuschku.quasseldroid_ng.util.helper.observeSticky
 import de.kuschku.quasseldroid_ng.util.helper.or
 import de.kuschku.quasseldroid_ng.util.helper.switchMap
+import de.kuschku.quasseldroid_ng.util.helper.updateRecentsHeaderIfExisting
 
 abstract class SetupActivity : AppCompatActivity() {
   @BindView(R.id.view_pager)
@@ -32,6 +35,11 @@ abstract class SetupActivity : AppCompatActivity() {
   private val currentPage = MutableLiveData<SlideFragment?>()
   private val isValid = currentPage.switchMap(SlideFragment::valid).or(false)
 
+  @DrawableRes
+  protected val icon: Int = R.mipmap.ic_launcher
+  @ColorRes
+  protected val recentsHeaderColor: Int = R.color.colorPrimaryDark
+
   private val pageChangeListener = object : ViewPager.OnPageChangeListener {
     override fun onPageScrollStateChanged(state: Int) {
       when (state) {
@@ -54,6 +62,14 @@ abstract class SetupActivity : AppCompatActivity() {
     button.setImageResource(drawable)
   }
 
+  fun updateRecentsHeader()
+    = updateRecentsHeaderIfExisting(title.toString(), icon, recentsHeaderColor)
+
+  override fun setTitle(title: CharSequence?) {
+    super.setTitle(title)
+    updateRecentsHeader()
+  }
+
   override fun onCreate(savedInstanceState: Bundle?) {
     setTheme(R.style.Theme_SetupTheme)
     super.onCreate(savedInstanceState)
@@ -81,6 +97,7 @@ abstract class SetupActivity : AppCompatActivity() {
     })
     viewPager.addOnPageChangeListener(pageChangeListener)
     pageChanged()
+    updateRecentsHeader()
   }
 
   private fun onDoneInternal() {
diff --git a/app/src/main/java/de/kuschku/quasseldroid_ng/util/helper/ActivityHelper.kt b/app/src/main/java/de/kuschku/quasseldroid_ng/util/helper/ActivityHelper.kt
index 5df45db66..4662c5653 100644
--- a/app/src/main/java/de/kuschku/quasseldroid_ng/util/helper/ActivityHelper.kt
+++ b/app/src/main/java/de/kuschku/quasseldroid_ng/util/helper/ActivityHelper.kt
@@ -10,6 +10,22 @@ import android.support.annotation.ColorRes
 import android.support.annotation.DrawableRes
 import android.support.annotation.StringRes
 
+/**
+ * Modifies the display of an {@see Activity} in the Android Recents menu if the current version
+ * of Android supports doing so.
+ *
+ * @param label The text shown as label
+ * @param icon The icon displayed in recents - passed as Android Drawable Resource
+ * @param colorPrimary The color used as background for the header of the recents card - passed as Android
+ * Color Resource
+ */
+fun Activity.updateRecentsHeaderIfExisting(
+  label: String, @DrawableRes icon: Int, @ColorRes colorPrimary: Int) {
+  val iconRaw = BitmapFactory.decodeResource(resources, icon)
+  val colorPrimaryRaw = resources.getColorBackport(colorPrimary, theme)
+  updateRecentsHeaderIfExisting(label, iconRaw, colorPrimaryRaw)
+}
+
 /**
  * Modifies the display of an {@see Activity} in the Android Recents menu if the current version
  * of Android supports doing so.
@@ -51,6 +67,5 @@ fun Activity.updateRecentsHeaderIfExisting(label: String, icon: Bitmap, colorPri
 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
 private fun Activity.updateRecentsHeader(label: String, icon: Bitmap,
                                          colorPrimary: Int) {
-  setTaskDescription(ActivityManager.TaskDescription(label,
-                                                     icon, colorPrimary))
+  setTaskDescription(ActivityManager.TaskDescription(label, icon, colorPrimary))
 }
diff --git a/app/src/main/java/de/kuschku/quasseldroid_ng/util/service/ServiceBoundActivity.kt b/app/src/main/java/de/kuschku/quasseldroid_ng/util/service/ServiceBoundActivity.kt
index b7a6d0b4e..07fe3b2d4 100644
--- a/app/src/main/java/de/kuschku/quasseldroid_ng/util/service/ServiceBoundActivity.kt
+++ b/app/src/main/java/de/kuschku/quasseldroid_ng/util/service/ServiceBoundActivity.kt
@@ -6,13 +6,20 @@ import android.content.Intent
 import android.content.ServiceConnection
 import android.os.Bundle
 import android.os.IBinder
+import android.support.annotation.ColorRes
+import android.support.annotation.DrawableRes
 import android.support.v7.app.AppCompatActivity
 import de.kuschku.libquassel.session.Backend
 import de.kuschku.quasseldroid_ng.R
 import de.kuschku.quasseldroid_ng.service.QuasselService
+import de.kuschku.quasseldroid_ng.util.helper.updateRecentsHeaderIfExisting
 
 abstract class ServiceBoundActivity : AppCompatActivity() {
   protected val backend = MutableLiveData<Backend?>()
+  @DrawableRes
+  protected val icon: Int = R.mipmap.ic_launcher
+  @ColorRes
+  protected val recentsHeaderColor: Int = R.color.colorPrimaryDark
 
   private val connection = object : ServiceConnection {
     override fun onServiceDisconnected(component: ComponentName?) {
@@ -37,6 +44,15 @@ abstract class ServiceBoundActivity : AppCompatActivity() {
     setTheme(R.style.Theme_ChatTheme_Quassel_Light)
     super.onCreate(savedInstanceState)
     startService(Intent(this, QuasselService::class.java))
+    updateRecentsHeader()
+  }
+
+  fun updateRecentsHeader()
+    = updateRecentsHeaderIfExisting(title.toString(), icon, recentsHeaderColor)
+
+  override fun setTitle(title: CharSequence?) {
+    super.setTitle(title)
+    updateRecentsHeader()
   }
 
   override fun onStart() {
diff --git a/malheur/src/main/java/de/kuschku/malheur/CrashHandler.kt b/malheur/src/main/java/de/kuschku/malheur/CrashHandler.kt
index 7d98d97cd..a371e6648 100644
--- a/malheur/src/main/java/de/kuschku/malheur/CrashHandler.kt
+++ b/malheur/src/main/java/de/kuschku/malheur/CrashHandler.kt
@@ -34,7 +34,7 @@ object CrashHandler {
             buildConfig = buildConfig,
             stackTraces = stackTraces
           ), config))
-          println(json)
+          // FIXME STOPSHIP Implement crash handling
         } catch (e: Throwable) {
           e.printStackTrace()
           originalHandler?.uncaughtException(activeThread, throwable)
@@ -48,5 +48,5 @@ object CrashHandler {
     myHandler?.uncaughtException(Thread.currentThread(), throwable)
   }
 
-  var myHandler: Thread.UncaughtExceptionHandler? = null
+  private var myHandler: Thread.UncaughtExceptionHandler? = null
 }
-- 
GitLab