|
|
@ -59,20 +59,21 @@ open class BaseScreen(@JvmField protected var activity: BaseActivity) {
|
|
|
|
* Notifies the screen that its contents should be updated.
|
|
|
|
* Notifies the screen that its contents should be updated.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
fun invalidate() {
|
|
|
|
fun invalidate() {
|
|
|
|
if (rootView == null) return
|
|
|
|
rootView?.invalidate()
|
|
|
|
rootView!!.invalidate()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun invalidateToolbar() {
|
|
|
|
fun invalidateToolbar() {
|
|
|
|
if (rootView == null) return
|
|
|
|
rootView?.let { root ->
|
|
|
|
activity.runOnUiThread {
|
|
|
|
activity.runOnUiThread {
|
|
|
|
val toolbar = rootView!!.getToolbar()
|
|
|
|
val toolbar = root.getToolbar()
|
|
|
|
activity.setSupportActionBar(toolbar)
|
|
|
|
activity.setSupportActionBar(toolbar)
|
|
|
|
val actionBar = activity.supportActionBar ?: return@runOnUiThread
|
|
|
|
activity.supportActionBar?.let { actionBar ->
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(rootView!!.displayHomeAsUp)
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(root.displayHomeAsUp)
|
|
|
|
val color = rootView!!.getToolbarColor()
|
|
|
|
val color = root.getToolbarColor()
|
|
|
|
setActionBarColor(actionBar, color)
|
|
|
|
setActionBarColor(actionBar, color)
|
|
|
|
setStatusBarColor(color)
|
|
|
|
setStatusBarColor(color)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -114,9 +115,10 @@ open class BaseScreen(@JvmField protected var activity: BaseActivity) {
|
|
|
|
fun setRootView(rootView: BaseRootView?) {
|
|
|
|
fun setRootView(rootView: BaseRootView?) {
|
|
|
|
this.rootView = rootView
|
|
|
|
this.rootView = rootView
|
|
|
|
activity.setContentView(rootView)
|
|
|
|
activity.setContentView(rootView)
|
|
|
|
if (rootView == null) return
|
|
|
|
rootView?.let {
|
|
|
|
rootView.onAttachedToScreen(this)
|
|
|
|
it.onAttachedToScreen(this)
|
|
|
|
invalidateToolbar()
|
|
|
|
invalidateToolbar()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -135,26 +137,28 @@ open class BaseScreen(@JvmField protected var activity: BaseActivity) {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
fun showMessage(@StringRes stringId: Int?) {
|
|
|
|
fun showMessage(@StringRes stringId: Int?) {
|
|
|
|
if (stringId == null || rootView == null) return
|
|
|
|
if (stringId == null || rootView == null) return
|
|
|
|
if (snackbar == null) {
|
|
|
|
(snackbar?.setText(stringId)
|
|
|
|
snackbar = Snackbar.make(rootView!!, stringId, Snackbar.LENGTH_SHORT)
|
|
|
|
?: run {
|
|
|
|
val tvId = R.id.snackbar_text
|
|
|
|
val snack = Snackbar.make(rootView!!, stringId, Snackbar.LENGTH_SHORT)
|
|
|
|
val tv = snackbar!!.view.findViewById<View>(tvId) as TextView
|
|
|
|
val tvId = R.id.snackbar_text
|
|
|
|
tv.setTextColor(Color.WHITE)
|
|
|
|
val tv = snack.view.findViewById<View>(tvId) as TextView
|
|
|
|
} else snackbar!!.setText(stringId)
|
|
|
|
tv.setTextColor(Color.WHITE)
|
|
|
|
snackbar!!.show()
|
|
|
|
this.snackbar = snack
|
|
|
|
|
|
|
|
snack
|
|
|
|
|
|
|
|
}).show()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun showSendEmailScreen(@StringRes toId: Int,
|
|
|
|
fun showSendEmailScreen(@StringRes toId: Int, @StringRes subjectId: Int, content: String?) {
|
|
|
|
@StringRes subjectId: Int,
|
|
|
|
|
|
|
|
content: String?) {
|
|
|
|
|
|
|
|
val to = activity.getString(toId)
|
|
|
|
val to = activity.getString(toId)
|
|
|
|
val subject = activity.getString(subjectId)
|
|
|
|
val subject = activity.getString(subjectId)
|
|
|
|
val intent = Intent()
|
|
|
|
val intent = Intent()
|
|
|
|
intent.action = Intent.ACTION_SEND
|
|
|
|
.apply {
|
|
|
|
intent.type = "message/rfc822"
|
|
|
|
action = Intent.ACTION_SEND
|
|
|
|
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf(to))
|
|
|
|
type = "message/rfc822"
|
|
|
|
intent.putExtra(Intent.EXTRA_SUBJECT, subject)
|
|
|
|
putExtra(Intent.EXTRA_EMAIL, arrayOf(to))
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, content)
|
|
|
|
putExtra(Intent.EXTRA_SUBJECT, subject)
|
|
|
|
|
|
|
|
putExtra(Intent.EXTRA_TEXT, content)
|
|
|
|
|
|
|
|
}
|
|
|
|
activity.startActivity(intent)
|
|
|
|
activity.startActivity(intent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -162,10 +166,12 @@ open class BaseScreen(@JvmField protected var activity: BaseActivity) {
|
|
|
|
val file = File(archiveFilename)
|
|
|
|
val file = File(archiveFilename)
|
|
|
|
val fileUri = FileProvider.getUriForFile(activity, "org.isoron.uhabits", file)
|
|
|
|
val fileUri = FileProvider.getUriForFile(activity, "org.isoron.uhabits", file)
|
|
|
|
val intent = Intent()
|
|
|
|
val intent = Intent()
|
|
|
|
intent.action = Intent.ACTION_SEND
|
|
|
|
.apply {
|
|
|
|
intent.type = "application/zip"
|
|
|
|
action = Intent.ACTION_SEND
|
|
|
|
intent.putExtra(Intent.EXTRA_STREAM, fileUri)
|
|
|
|
type = "application/zip"
|
|
|
|
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
|
|
|
|
putExtra(Intent.EXTRA_STREAM, fileUri)
|
|
|
|
|
|
|
|
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
|
|
|
|
|
|
|
|
}
|
|
|
|
activity.startActivity(intent)
|
|
|
|
activity.startActivity(intent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -192,13 +198,14 @@ open class BaseScreen(@JvmField protected var activity: BaseActivity) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private inner class ActionModeWrapper : ActionMode.Callback {
|
|
|
|
private inner class ActionModeWrapper : ActionMode.Callback {
|
|
|
|
override fun onActionItemClicked(mode: ActionMode?,
|
|
|
|
override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?): Boolean =
|
|
|
|
item: MenuItem?): Boolean {
|
|
|
|
if (item == null || selectionMenu == null) {
|
|
|
|
return if (item == null || selectionMenu == null) false else selectionMenu!!.onItemClicked(item)
|
|
|
|
false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
selectionMenu!!.onItemClicked(item)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCreateActionMode(mode: ActionMode?,
|
|
|
|
override fun onCreateActionMode(mode: ActionMode?, menu: Menu?): Boolean {
|
|
|
|
menu: Menu?): Boolean {
|
|
|
|
|
|
|
|
if (selectionMenu == null) return false
|
|
|
|
if (selectionMenu == null) return false
|
|
|
|
if (mode == null || menu == null) return false
|
|
|
|
if (mode == null || menu == null) return false
|
|
|
|
selectionMenu!!.onCreate(activity.menuInflater, mode, menu)
|
|
|
|
selectionMenu!!.onCreate(activity.menuInflater, mode, menu)
|
|
|
@ -206,14 +213,15 @@ open class BaseScreen(@JvmField protected var activity: BaseActivity) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onDestroyActionMode(mode: ActionMode?) {
|
|
|
|
override fun onDestroyActionMode(mode: ActionMode?) {
|
|
|
|
if (selectionMenu == null) return
|
|
|
|
selectionMenu?.onFinish()
|
|
|
|
selectionMenu!!.onFinish()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onPrepareActionMode(mode: ActionMode?,
|
|
|
|
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?): Boolean =
|
|
|
|
menu: Menu?): Boolean {
|
|
|
|
if (selectionMenu == null || menu == null) {
|
|
|
|
return if (selectionMenu == null || menu == null) false else selectionMenu!!.onPrepare(menu)
|
|
|
|
false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
selectionMenu!!.onPrepare(menu)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
companion object {
|
|
|
@ -221,32 +229,29 @@ open class BaseScreen(@JvmField protected var activity: BaseActivity) {
|
|
|
|
@Deprecated("")
|
|
|
|
@Deprecated("")
|
|
|
|
fun getDefaultActionBarColor(context: Context): Int {
|
|
|
|
fun getDefaultActionBarColor(context: Context): Int {
|
|
|
|
return if (VERSION.SDK_INT < VERSION_CODES.LOLLIPOP) {
|
|
|
|
return if (VERSION.SDK_INT < VERSION_CODES.LOLLIPOP) {
|
|
|
|
ResourcesCompat.getColor(context.resources,
|
|
|
|
ResourcesCompat.getColor(context.resources, R.color.grey_900, context.theme)
|
|
|
|
R.color.grey_900, context.theme)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
val res = StyledResources(context)
|
|
|
|
StyledResources(context).getColor(R.attr.colorPrimary)
|
|
|
|
res.getColor(R.attr.colorPrimary)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
@JvmStatic
|
|
|
|
@Deprecated("")
|
|
|
|
@Deprecated("")
|
|
|
|
fun setupActionBarColor(activity: AppCompatActivity,
|
|
|
|
fun setupActionBarColor(activity: AppCompatActivity, color: Int) {
|
|
|
|
color: Int) {
|
|
|
|
activity.findViewById<Toolbar>(R.id.toolbar)?.let { toolbar ->
|
|
|
|
val toolbar = activity.findViewById<View>(R.id.toolbar) as Toolbar ?: return
|
|
|
|
activity.setSupportActionBar(toolbar)
|
|
|
|
activity.setSupportActionBar(toolbar)
|
|
|
|
activity.supportActionBar?.let { actionBar ->
|
|
|
|
val actionBar = activity.supportActionBar ?: return
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true)
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true)
|
|
|
|
val drawable = ColorDrawable(color)
|
|
|
|
val drawable = ColorDrawable(color)
|
|
|
|
actionBar.setBackgroundDrawable(drawable)
|
|
|
|
actionBar.setBackgroundDrawable(drawable)
|
|
|
|
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
|
|
|
|
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
|
|
|
|
val darkerColor = mixColors(color, Color.BLACK, 0.75f)
|
|
|
|
val darkerColor = mixColors(color, Color.BLACK, 0.75f)
|
|
|
|
activity.window.statusBarColor = darkerColor
|
|
|
|
activity.window.statusBarColor = darkerColor
|
|
|
|
toolbar.elevation = dpToPixels(activity, 2f)
|
|
|
|
toolbar.elevation = dpToPixels(activity, 2f)
|
|
|
|
activity.findViewById<View>(R.id.toolbarShadow)?.visibility = View.GONE
|
|
|
|
var view = activity.findViewById<View>(R.id.toolbarShadow)
|
|
|
|
activity.findViewById<View>(R.id.headerShadow)?.visibility = View.GONE
|
|
|
|
if (view != null) view.visibility = View.GONE
|
|
|
|
}
|
|
|
|
view = activity.findViewById(R.id.headerShadow)
|
|
|
|
}
|
|
|
|
if (view != null) view.visibility = View.GONE
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|