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
|
2020-07-30 14:11:19 +00:00
|
|
|
import androidx.annotation.LayoutRes
|
2019-10-09 13:46:25 +00:00
|
|
|
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
|
2021-12-01 19:07:43 +00:00
|
|
|
import code.name.monkey.retromusic.extensions.setLightStatusBarAuto
|
|
|
|
import code.name.monkey.retromusic.extensions.setTaskDescriptionColorAuto
|
2020-09-26 20:39:07 +00:00
|
|
|
import code.name.monkey.retromusic.fragments.LibraryViewModel
|
|
|
|
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
|
2018-11-30 01:06:16 +00:00
|
|
|
|
2020-07-30 14:11:19 +00:00
|
|
|
abstract class AbsMainActivityFragment(@LayoutRes layout: Int) : AbsMusicServiceFragment(layout) {
|
2020-09-26 20:39:07 +00:00
|
|
|
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)
|
2021-12-01 19:07:43 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|