PlayerAndroid/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMainActivityFragment.kt

64 lines
2.5 KiB
Kotlin
Raw Normal View History

2020-10-06 08:46:04 +00:00
/*
* Copyright (c) 2020 Hemanth Savarla.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
*/
2019-04-20 05:29:45 +00:00
package code.name.monkey.retromusic.fragments.base
2018-11-30 01:06:16 +00:00
import android.os.Bundle
import android.view.View
import androidx.annotation.LayoutRes
import code.name.monkey.appthemehelper.util.ATHUtil
2018-11-30 01:06:16 +00:00
import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.R
2019-04-20 05:29:45 +00:00
import code.name.monkey.retromusic.activities.MainActivity
import code.name.monkey.retromusic.extensions.setLightStatusBarAuto
import code.name.monkey.retromusic.extensions.setTaskDescriptionColorAuto
import code.name.monkey.retromusic.fragments.LibraryViewModel
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
2018-11-30 01:06:16 +00:00
abstract class AbsMainActivityFragment(@LayoutRes layout: Int) : AbsMusicServiceFragment(layout) {
val libraryViewModel: LibraryViewModel by sharedViewModel()
2018-11-30 01:06:16 +00:00
val mainActivity: MainActivity
get() = activity as MainActivity
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
setHasOptionsMenu(true)
mainActivity.setTaskDescriptionColorAuto()
}
2019-12-01 11:28:57 +00:00
private fun setStatusBarColor(view: View, color: Int) {
2018-11-30 01:06:16 +00:00
val statusBar = view.findViewById<View>(R.id.status_bar)
if (statusBar != null) {
2019-12-05 18:18:54 +00:00
if (VersionUtils.hasMarshmallow()) {
statusBar.setBackgroundColor(color)
mainActivity.setLightStatusBarAuto(color)
2018-11-30 01:06:16 +00:00
} else {
statusBar.setBackgroundColor(color)
}
}
}
2019-12-01 11:28:57 +00:00
fun setStatusBarColorAuto(view: View) {
2019-12-05 18:18:54 +00:00
val colorPrimary = ATHUtil.resolveColor(requireContext(), R.attr.colorSurface)
2018-11-30 01:06:16 +00:00
// we don't want to use statusbar color because we are doing the color darkening on our own to support KitKat
if (VersionUtils.hasMarshmallow()) {
2019-12-01 11:28:57 +00:00
setStatusBarColor(view, colorPrimary)
2018-11-30 01:06:16 +00:00
} else {
2019-12-01 11:28:57 +00:00
setStatusBarColor(view, ColorUtil.darkenColor(colorPrimary))
2018-11-30 01:06:16 +00:00
}
}
}