OnboardingFragment: Drop theme and accent fragments
Still available in the settings Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.store.view.epoxy.views
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.util.AttributeSet
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.core.view.isVisible
|
||||
import com.airbnb.epoxy.CallbackProp
|
||||
import com.airbnb.epoxy.ModelProp
|
||||
import com.airbnb.epoxy.ModelView
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.model.Accent
|
||||
import com.aurora.store.databinding.ViewAccentBinding
|
||||
|
||||
@ModelView(
|
||||
autoLayout = ModelView.Size.WRAP_WIDTH_WRAP_HEIGHT,
|
||||
baseModelClass = BaseView::class
|
||||
)
|
||||
class AccentView : RelativeLayout {
|
||||
|
||||
private lateinit var B: ViewAccentBinding
|
||||
|
||||
constructor(context: Context?) : super(context) {
|
||||
init(context)
|
||||
}
|
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
|
||||
init(context)
|
||||
}
|
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
|
||||
context,
|
||||
attrs,
|
||||
defStyleAttr
|
||||
) {
|
||||
init(context)
|
||||
}
|
||||
|
||||
private fun init(context: Context?) {
|
||||
val view = inflate(context, R.layout.view_accent, this)
|
||||
B = ViewAccentBinding.bind(view)
|
||||
}
|
||||
|
||||
@ModelProp
|
||||
fun accent(accent: Accent) {
|
||||
if (accent.accent.isBlank()) {
|
||||
B.img.background = ResourcesCompat.getDrawable(
|
||||
context.resources,
|
||||
R.drawable.ic_settings_suggest,
|
||||
context.theme
|
||||
)
|
||||
} else {
|
||||
B.img.backgroundTintList = ColorStateList.valueOf(Color.parseColor(accent.accent))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ModelProp
|
||||
fun markChecked(isChecked: Boolean) {
|
||||
B.tick.isVisible = isChecked
|
||||
}
|
||||
|
||||
@CallbackProp
|
||||
fun click(onClickListener: OnClickListener?) {
|
||||
B.root.setOnClickListener(onClickListener)
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.store.view.epoxy.views
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.CompoundButton
|
||||
import android.widget.RelativeLayout
|
||||
import com.airbnb.epoxy.CallbackProp
|
||||
import com.airbnb.epoxy.ModelProp
|
||||
import com.airbnb.epoxy.ModelView
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.model.Theme
|
||||
import com.aurora.store.databinding.ViewThemeBinding
|
||||
|
||||
@ModelView(
|
||||
autoLayout = ModelView.Size.MATCH_WIDTH_WRAP_HEIGHT,
|
||||
baseModelClass = BaseView::class
|
||||
)
|
||||
class ThemeView : RelativeLayout {
|
||||
|
||||
private lateinit var B: ViewThemeBinding
|
||||
|
||||
constructor(context: Context?) : super(context) {
|
||||
init(context)
|
||||
}
|
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
|
||||
init(context)
|
||||
}
|
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
|
||||
context,
|
||||
attrs,
|
||||
defStyleAttr
|
||||
) {
|
||||
init(context)
|
||||
}
|
||||
|
||||
private fun init(context: Context?) {
|
||||
val view = inflate(context, R.layout.view_theme, this)
|
||||
B = ViewThemeBinding.bind(view)
|
||||
}
|
||||
|
||||
@ModelProp
|
||||
fun theme(theme: Theme) {
|
||||
B.line1.text = theme.title
|
||||
B.line2.text = theme.subtitle
|
||||
}
|
||||
|
||||
@ModelProp
|
||||
fun markChecked(isChecked: Boolean) {
|
||||
B.radiobutton.isChecked = isChecked
|
||||
}
|
||||
|
||||
@CallbackProp
|
||||
fun checked(onCheckedChangeListener: CompoundButton.OnCheckedChangeListener?) {
|
||||
B.radiobutton.setOnCheckedChangeListener(onCheckedChangeListener)
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.store.view.ui.onboarding
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import com.aurora.extensions.isSAndAbove
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.model.Accent
|
||||
import com.aurora.store.databinding.FragmentOnboardingAccentBinding
|
||||
import com.aurora.store.util.Preferences
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_THEME_ACCENT
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_THEME_TYPE
|
||||
import com.aurora.store.util.save
|
||||
import com.aurora.store.view.epoxy.views.AccentViewModel_
|
||||
import com.aurora.store.view.ui.commons.BaseFragment
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
@AndroidEntryPoint
|
||||
class AccentFragment : BaseFragment(R.layout.fragment_onboarding_accent) {
|
||||
|
||||
private var _binding: FragmentOnboardingAccentBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private var themeId: Int = 0
|
||||
private var accentId: Int = if (isSAndAbove()) 0 else 1
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
_binding = FragmentOnboardingAccentBinding.bind(view)
|
||||
|
||||
themeId = Preferences.getInteger(view.context, PREFERENCE_THEME_TYPE)
|
||||
accentId = Preferences.getInteger(view.context, PREFERENCE_THEME_ACCENT)
|
||||
|
||||
// RecyclerView
|
||||
with(binding.epoxyRecycler) {
|
||||
setHasFixedSize(true)
|
||||
layoutManager = StaggeredGridLayoutManager(5, StaggeredGridLayoutManager.VERTICAL)
|
||||
}
|
||||
|
||||
binding.epoxyRecycler.withModels {
|
||||
setFilterDuplicates(true)
|
||||
|
||||
loadAccentsFromAssets(view.context).forEach {
|
||||
if (it.id == 0) {
|
||||
if (!isSAndAbove()) return@forEach
|
||||
}
|
||||
|
||||
add(
|
||||
AccentViewModel_()
|
||||
.id(it.id)
|
||||
.accent(it)
|
||||
.markChecked(accentId == it.id)
|
||||
.click { _ ->
|
||||
accentId = it.id
|
||||
updateAccent(accentId)
|
||||
requestModelBuild()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
private fun updateAccent(accentId: Int) {
|
||||
requireActivity().recreate()
|
||||
save(PREFERENCE_THEME_ACCENT, accentId)
|
||||
}
|
||||
|
||||
private fun loadAccentsFromAssets(context: Context): List<Accent> {
|
||||
val inputStream = context.assets.open("accent.json")
|
||||
val bytes = ByteArray(inputStream.available())
|
||||
inputStream.read(bytes)
|
||||
inputStream.close()
|
||||
|
||||
val json = String(bytes, StandardCharsets.UTF_8)
|
||||
return gson.fromJson<MutableList<Accent>?>(
|
||||
json,
|
||||
object : TypeToken<MutableList<Accent?>?>() {}.type
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,6 @@ import androidx.lifecycle.Lifecycle
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
|
||||
import com.aurora.extensions.isSAndAbove
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.work.UpdateWorker
|
||||
import com.aurora.store.databinding.FragmentOnboardingBinding
|
||||
@@ -44,8 +43,6 @@ import com.aurora.store.util.Preferences.PREFERENCE_INSECURE_ANONYMOUS
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_INSTALLER_ID
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_INTRO
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_SIMILAR
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_THEME_ACCENT
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_THEME_TYPE
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_UPDATES_AUTO
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_UPDATES_CHECK_INTERVAL
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_UPDATES_EXTENDED
|
||||
@@ -68,16 +65,14 @@ class OnboardingFragment : Fragment(R.layout.fragment_onboarding) {
|
||||
when (position) {
|
||||
0 -> return WelcomeFragment()
|
||||
1 -> return InstallerFragment()
|
||||
2 -> return ThemeFragment()
|
||||
3 -> return AccentFragment()
|
||||
4 -> return AppLinksFragment()
|
||||
5 -> return PermissionsFragment()
|
||||
2 -> return AppLinksFragment()
|
||||
3 -> return PermissionsFragment()
|
||||
}
|
||||
return Fragment()
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return 6
|
||||
return 4
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,9 +121,9 @@ class OnboardingFragment : Fragment(R.layout.fragment_onboarding) {
|
||||
|
||||
fun refreshButtonState() {
|
||||
binding.btnBackward.isEnabled = lastPosition != 0
|
||||
binding.btnForward.isEnabled = lastPosition != 5
|
||||
binding.btnForward.isEnabled = lastPosition != 3
|
||||
|
||||
if (lastPosition == 5) {
|
||||
if (lastPosition == 3) {
|
||||
binding.btnForward.text = getString(R.string.action_finish)
|
||||
binding.btnForward.isEnabled = true
|
||||
binding.btnForward.setOnClickListener {
|
||||
@@ -160,8 +155,6 @@ class OnboardingFragment : Fragment(R.layout.fragment_onboarding) {
|
||||
save(PREFERENCE_VENDING_VERSION, 0)
|
||||
|
||||
/*Customization*/
|
||||
save(PREFERENCE_THEME_TYPE, 0)
|
||||
save(PREFERENCE_THEME_ACCENT, if (isSAndAbove()) 0 else 1)
|
||||
save(PREFERENCE_DEFAULT_SELECTED_TAB, 0)
|
||||
save(PREFERENCE_FOR_YOU, true)
|
||||
save(PREFERENCE_SIMILAR, true)
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Aurora Store
|
||||
* Copyright (C) 2021, Rahul Kumar Patel <whyorean@gmail.com>
|
||||
*
|
||||
* Aurora Store 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Aurora Store 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.aurora.store.view.ui.onboarding
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import com.aurora.store.R
|
||||
import com.aurora.store.data.model.Theme
|
||||
import com.aurora.store.databinding.FragmentOnboardingThemeBinding
|
||||
import com.aurora.store.util.Preferences
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_THEME_ACCENT
|
||||
import com.aurora.store.util.Preferences.PREFERENCE_THEME_TYPE
|
||||
import com.aurora.store.util.save
|
||||
import com.aurora.store.view.epoxy.views.ThemeViewModel_
|
||||
import com.aurora.store.view.ui.commons.BaseFragment
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
@AndroidEntryPoint
|
||||
class ThemeFragment : BaseFragment(R.layout.fragment_onboarding_theme) {
|
||||
|
||||
private var _binding: FragmentOnboardingThemeBinding? = null
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private var themeId: Int = 0
|
||||
private var accentId: Int = 0
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
_binding = FragmentOnboardingThemeBinding.bind(view)
|
||||
|
||||
themeId = Preferences.getInteger(view.context, PREFERENCE_THEME_TYPE)
|
||||
accentId = Preferences.getInteger(view.context, PREFERENCE_THEME_ACCENT)
|
||||
|
||||
// RecyclerView
|
||||
binding.epoxyRecycler.withModels {
|
||||
setFilterDuplicates(true)
|
||||
loadThemesFromAssets(view.context).forEach {
|
||||
add(
|
||||
ThemeViewModel_()
|
||||
.id(it.id)
|
||||
.theme(it)
|
||||
.markChecked(themeId == it.id)
|
||||
.checked { _, checked ->
|
||||
if (checked) {
|
||||
themeId = it.id
|
||||
update(themeId)
|
||||
requestModelBuild()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
private fun update(themeId: Int) {
|
||||
requireActivity().recreate()
|
||||
save(PREFERENCE_THEME_TYPE, themeId)
|
||||
}
|
||||
|
||||
private fun loadThemesFromAssets(context: Context): List<Theme> {
|
||||
val inputStream = context.assets.open("themes.json")
|
||||
val bytes = ByteArray(inputStream.available())
|
||||
inputStream.read(bytes)
|
||||
inputStream.close()
|
||||
|
||||
val json = String(bytes, StandardCharsets.UTF_8)
|
||||
return gson.fromJson<MutableList<Theme>?>(
|
||||
json,
|
||||
object : TypeToken<MutableList<Theme?>?>() {}.type
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user