PlayerAndroid/app/src/main/java/code/name/monkey/retromusic/fragments/settings/MainSettingsFragment.kt

87 lines
3.9 KiB
Kotlin
Raw Normal View History

2019-05-11 13:53:20 +00:00
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* 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.settings
2019-06-05 08:17:45 +00:00
import android.content.res.ColorStateList
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment
2019-06-04 04:00:11 +00:00
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ColorUtil
2019-06-05 08:17:45 +00:00
import code.name.monkey.appthemehelper.util.MaterialUtil
2019-06-04 04:00:11 +00:00
import code.name.monkey.appthemehelper.util.MaterialValueHelper
import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.R
2019-04-20 05:29:45 +00:00
import code.name.monkey.retromusic.activities.SettingsActivity
2019-06-05 08:17:45 +00:00
import code.name.monkey.retromusic.extensions.hide
import code.name.monkey.retromusic.extensions.show
2018-12-08 03:33:02 +00:00
import code.name.monkey.retromusic.util.NavigationUtil
import kotlinx.android.synthetic.main.fragment_main_settings.*
2018-12-08 03:33:02 +00:00
class MainSettingsFragment : Fragment(), View.OnClickListener {
override fun onClick(v: View) {
when (v.id) {
R.id.generalSettings -> inflateFragment(ThemeSettingsFragment(), R.string.general_settings_title)
R.id.audioSettings -> inflateFragment(AudioSettings(), R.string.pref_header_audio)
R.id.nowPlayingSettings -> inflateFragment(NowPlayingSettingsFragment(), R.string.now_playing)
R.id.personalizeSettings -> inflateFragment(PersonaizeSettingsFragment(), R.string.personalize)
R.id.imageSettings -> inflateFragment(ImageSettingFragment(), R.string.pref_header_images)
R.id.notificationSettings -> inflateFragment(NotificationSettingsFragment(), R.string.notification)
R.id.otherSettings -> inflateFragment(OtherSettingsFragment(), R.string.others)
2019-04-05 10:45:09 +00:00
R.id.aboutSettings -> NavigationUtil.goToAbout(activity!!)
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_main_settings, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
2019-02-17 18:03:12 +00:00
generalSettings.setOnClickListener(this)
audioSettings.setOnClickListener(this)
nowPlayingSettings.setOnClickListener(this)
personalizeSettings.setOnClickListener(this)
imageSettings.setOnClickListener(this)
notificationSettings.setOnClickListener(this)
otherSettings.setOnClickListener(this)
2019-04-05 10:45:09 +00:00
aboutSettings.setOnClickListener(this)
2019-06-04 04:00:11 +00:00
buyProContainer.apply {
if (App.isProVersion) show() else hide()
2019-06-04 04:00:11 +00:00
setOnClickListener {
NavigationUtil.goToProVersion(context)
}
}
buyPremium.setOnClickListener {
2019-08-05 16:13:44 +00:00
NavigationUtil.goToProVersion(requireContext())
2019-06-04 04:00:11 +00:00
}
2019-06-05 08:17:45 +00:00
MaterialUtil.setTint(buyPremium)
2019-08-05 16:13:44 +00:00
val primaryColor = MaterialValueHelper.getPrimaryTextColor(requireContext(), ColorUtil.isColorLight(ThemeStore.primaryColor(requireContext())))
2019-06-04 04:00:11 +00:00
text.setTextColor(ColorUtil.withAlpha(primaryColor, 0.75f))
text2.setTextColor(primaryColor)
2019-06-05 08:17:45 +00:00
text3.imageTintList = ColorStateList.valueOf(primaryColor)
2019-04-05 10:45:09 +00:00
}
2019-06-02 02:39:36 +00:00
private fun inflateFragment(fragment: Fragment, @StringRes title: Int) {
2019-08-05 16:13:44 +00:00
(requireActivity() as SettingsActivity).setupFragment(fragment, title)
}
}