diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt index c616f66cd..9e8d1a23e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt @@ -42,25 +42,15 @@ open class BaseActivity : AppCompatActivity() { supportActionBar?.subtitle = getString(titleResource) } - fun snack(text: String?, duration: Int = Snackbar.LENGTH_LONG) { - val snack = Snackbar.make(findViewById(android.R.id.content)!!, text ?: getString(R.string.unknown_error), duration) - val textView = snack.view.findViewById(android.support.design.R.id.snackbar_text) as TextView - textView.setTextColor(Color.WHITE) - snack.show() - } - - fun snack(text: String?, actionRes: Int, actionFunc: () -> Unit, - duration: Int = Snackbar.LENGTH_LONG, view: View = findViewById(android.R.id.content)!!) { - - val snack = Snackbar.make(view, text ?: getString(R.string.unknown_error), duration) - .setAction(actionRes, { actionFunc() }) - - val textView = snack.view.findViewById(android.support.design.R.id.snackbar_text) as TextView - textView.setTextColor(Color.WHITE) - snack.show() - } - protected val app: App get() = App.get(this) + inline fun View.snack(message: String, length: Int = Snackbar.LENGTH_LONG, f: Snackbar.() -> Unit) { + val snack = Snackbar.make(this, message, length) + val textView = snack.view.findViewById(android.support.design.R.id.snackbar_text) as TextView + textView.setTextColor(Color.WHITE) + snack.f() + snack.show() + } + } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt index c26f7afec..7fe75a443 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueFragment.kt @@ -20,6 +20,7 @@ import eu.kanade.tachiyomi.ui.base.fragment.BaseRxFragment import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaActivity import eu.kanade.tachiyomi.util.getResourceDrawable +import eu.kanade.tachiyomi.util.snack import eu.kanade.tachiyomi.util.toast import eu.kanade.tachiyomi.widget.EndlessGridScrollListener import eu.kanade.tachiyomi.widget.EndlessListScrollListener @@ -355,10 +356,12 @@ class CatalogueFragment : BaseRxFragment(), FlexibleViewHold hideProgressBar() Timber.e(error, error.message) - baseActivity.snack(error.message, R.string.action_retry, { - showProgressBar() - presenter.retryRequest() - }) + catalogue_view.snack(error.message ?: "") { + setAction(R.string.action_retry) { + showProgressBar() + presenter.retryRequest() + } + } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index ffe67ceca..8bf7f0e38 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -5,9 +5,7 @@ import android.os.Build import android.os.Bundle import android.support.v4.app.Fragment import android.support.v4.view.GravityCompat -import android.support.v4.widget.DrawerLayout import android.view.MenuItem -import android.view.View import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.backup.BackupFragment import eu.kanade.tachiyomi.ui.base.activity.BaseActivity @@ -40,19 +38,9 @@ class MainActivity : BaseActivity() { setupToolbar(toolbar, backNavigation = false) supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp) - drawer.addDrawerListener(object : DrawerLayout.SimpleDrawerListener() { - override fun onDrawerSlide(drawerView: View, slideOffset: Float) { - if (Build.VERSION.SDK_INT >= 21) { - window.statusBarColor = theme.getResourceColor(R.attr.status_bar_trans) - } - } - - override fun onDrawerClosed(drawerView: View) { - if (Build.VERSION.SDK_INT >= 21) { - window.statusBarColor = theme.getResourceColor(R.attr.colorPrimaryDark) - } - } - }) + if (Build.VERSION.SDK_INT >= 21) { + window.statusBarColor = android.R.color.transparent; + } // Set behavior of Navigation drawer nav_view.setNavigationItemSelectedListener { item -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt index a2f1c5d70..3fab969ea 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ViewExtensions.kt @@ -1,7 +1,10 @@ package eu.kanade.tachiyomi.util +import android.graphics.Color import android.graphics.Point +import android.support.design.widget.Snackbar import android.view.View +import android.widget.TextView /** * Returns coordinates of view. @@ -9,11 +12,19 @@ import android.view.View * * @return coordinates of view */ -fun View.getCoordinates(): Point -{ - var cx = (this.left + this.right) / 2; - var cy = (this.top + this.bottom) / 2; - - return Point(cx, cy) -} +fun View.getCoordinates() = Point((left + right) / 2, (top + bottom) / 2) +/** + * Shows a snackbar in this view. + * + * @param message the message to show. + * @param length the duration of the snack. + * @param f a function to execute in the snack, allowing for example to define a custom action. + */ +inline fun View.snack(message: String, length: Int = Snackbar.LENGTH_LONG, f: Snackbar.() -> Unit) { + val snack = Snackbar.make(this, message, length) + val textView = snack.view.findViewById(android.support.design.R.id.snackbar_text) as TextView + textView.setTextColor(Color.WHITE) + snack.f() + snack.show() +} \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_catalogue.xml b/app/src/main/res/layout/fragment_catalogue.xml index 346a3e94b..1f5ec2e4e 100644 --- a/app/src/main/res/layout/fragment_catalogue.xml +++ b/app/src/main/res/layout/fragment_catalogue.xml @@ -5,6 +5,7 @@ android:layout_height="match_parent" android:fitsSystemWindows="true" android:orientation="vertical" + android:id="@+id/catalogue_view" tools:context="eu.kanade.tachiyomi.ui.catalogue.CatalogueFragment">