mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-09-10 19:33:24 +02:00
Make status bar transparent on API > 21 properly. Snack function moved to an extension method in View
This commit is contained in:
parent
8c9db2db61
commit
11f6c44442
@ -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()
|
||||
}
|
||||
|
||||
}
|
@ -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<CataloguePresenter>(), FlexibleViewHold
|
||||
hideProgressBar()
|
||||
Timber.e(error, error.message)
|
||||
|
||||
baseActivity.snack(error.message, R.string.action_retry, {
|
||||
catalogue_view.snack(error.message ?: "") {
|
||||
setAction(R.string.action_retry) {
|
||||
showProgressBar()
|
||||
presenter.retryRequest()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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)
|
||||
window.statusBarColor = android.R.color.transparent;
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDrawerClosed(drawerView: View) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
window.statusBarColor = theme.getResourceColor(R.attr.colorPrimaryDark)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Set behavior of Navigation drawer
|
||||
nav_view.setNavigationItemSelectedListener { item ->
|
||||
|
@ -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;
|
||||
fun View.getCoordinates() = Point((left + right) / 2, (top + bottom) / 2)
|
||||
|
||||
return Point(cx, cy)
|
||||
/**
|
||||
* 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()
|
||||
}
|
||||
|
||||
|
@ -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">
|
||||
|
||||
<ProgressBar
|
||||
|
Loading…
Reference in New Issue
Block a user