diff --git a/README.md b/README.md index 4b47f7b..dd63996 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ dependencyResolutionManagement { ```gradle dependencies { - implementation 'com.github.trycourier:courier-android:3.1.2' + implementation 'com.github.trycourier:courier-android:3.1.3' } ``` diff --git a/android/src/main/java/com/courier/android/Courier.kt b/android/src/main/java/com/courier/android/Courier.kt index aafd2f5..3a64838 100644 --- a/android/src/main/java/com/courier/android/Courier.kt +++ b/android/src/main/java/com/courier/android/Courier.kt @@ -59,7 +59,7 @@ class Courier private constructor(internal val context: Context) : Application.A companion object { var USER_AGENT = CourierAgent.NATIVE_ANDROID - internal const val VERSION = "3.1.2" + internal const val VERSION = "3.1.3" internal const val TAG = "Courier SDK" internal const val COURIER_PENDING_NOTIFICATION_KEY = "courier_pending_notification_key" internal val eventBus by lazy { NotificationEventBus() } diff --git a/android/src/main/java/com/courier/android/ui/preferences/CourierPreferences.kt b/android/src/main/java/com/courier/android/ui/preferences/CourierPreferences.kt index c789f94..d48d088 100644 --- a/android/src/main/java/com/courier/android/ui/preferences/CourierPreferences.kt +++ b/android/src/main/java/com/courier/android/ui/preferences/CourierPreferences.kt @@ -19,7 +19,6 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import com.courier.android.Courier import com.courier.android.Courier.Companion.coroutineScope import com.courier.android.R -import com.courier.android.models.CourierAgent import com.courier.android.models.CourierException import com.courier.android.models.CourierPreferenceChannel import com.courier.android.models.CourierPreferenceStatus @@ -42,32 +41,39 @@ class CourierPreferences @JvmOverloads constructor(context: Context, attrs: Attr private var state = State.LOADING set(value) { - field = value - when (field) { - State.LOADING -> { - refreshLayout.isVisible = false - infoView.isVisible = false - loadingIndicator.isVisible = true - } - State.ERROR -> { - refreshLayout.isVisible = false - infoView.isVisible = true - detailTextView.text = field.title - loadingIndicator.isVisible = false - } - State.CONTENT -> { - refreshLayout.isVisible = true - infoView.isVisible = false - detailTextView.text = null - loadingIndicator.isVisible = false - } - State.EMPTY -> { - refreshLayout.isVisible = false - infoView.isVisible = true - detailTextView.text = field.title - loadingIndicator.isVisible = false + + coroutineScope.launch(Dispatchers.Main) { + + field = value + + when (field) { + State.LOADING -> { + refreshLayout.isVisible = false + infoView.isVisible = false + loadingIndicator.isVisible = true + } + State.ERROR -> { + refreshLayout.isVisible = false + infoView.isVisible = true + detailTextView.text = field.title + loadingIndicator.isVisible = false + } + State.CONTENT -> { + refreshLayout.isVisible = true + infoView.isVisible = false + detailTextView.text = null + loadingIndicator.isVisible = false + } + State.EMPTY -> { + refreshLayout.isVisible = false + infoView.isVisible = true + detailTextView.text = field.title + loadingIndicator.isVisible = false + } } + } + } sealed class Mode { @@ -290,7 +296,6 @@ class CourierPreferences @JvmOverloads constructor(context: Context, attrs: Attr preferencesAdapter = ConcatAdapter(sections) recyclerView.adapter = preferencesAdapter - preferencesAdapter.notifyDataSetChanged() state = if (preferences.items.isEmpty()) State.EMPTY.apply { title = "No preferences found" } else State.CONTENT refreshLayout.isRefreshing = false @@ -483,27 +488,27 @@ class CourierPreferences @JvmOverloads constructor(context: Context, attrs: Attr // } // } - @SuppressLint("NotifyDataSetChanged") - private fun RecyclerView.forceReactNativeLayoutFix() { - - if (Courier.USER_AGENT != CourierAgent.REACT_NATIVE_ANDROID) { - return - } - - try { - - // Forces the layout to refresh - // This is a react native bug - adapter?.notifyDataSetChanged() - scrollBy(0, 0) - - } catch (e: Exception) { - - Courier.error(e.toString()) - - } - - } +// @SuppressLint("NotifyDataSetChanged") +// private fun RecyclerView.forceReactNativeLayoutFix() { +// +// if (Courier.USER_AGENT != CourierAgent.REACT_NATIVE_ANDROID) { +// return +// } +// +// try { +// +// // Forces the layout to refresh +// // This is a react native bug +// adapter?.notifyDataSetChanged() +// scrollBy(0, 0) +// +// } catch (e: Exception) { +// +// Courier.error(e.toString()) +// +// } +// +// } // override fun onAttachedToWindow() { // super.onAttachedToWindow() diff --git a/android/src/main/res/layout/courier_preferences.xml b/android/src/main/res/layout/courier_preferences.xml index 9e2bcb5..d6c3da7 100644 --- a/android/src/main/res/layout/courier_preferences.xml +++ b/android/src/main/res/layout/courier_preferences.xml @@ -15,7 +15,7 @@ android:layout_height="0dp" android:layout_weight="1"> - +