Skip to content

Commit

Permalink
Use new extension functions. Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jahirfiquitiva committed Apr 7, 2020
1 parent 100ac2c commit d5ccb3b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.observe
import androidx.lifecycle.viewModelScope
import dev.jahir.frames.extensions.boolean
import dev.jahir.frames.extensions.lazyMutableLiveData
import dev.jahir.frames.extensions.string
import dev.jahir.kuper.R
import dev.jahir.kuper.data.models.RequiredApp
import dev.jahir.kuper.extensions.getFilesInAssetsFolder
Expand Down Expand Up @@ -55,8 +57,8 @@ class RequiredAppsViewModel : ViewModel() {
&& "templates".inAssetsAndWithContent(context)) {
apps.add(
RequiredApp(
context.getString(R.string.zooper_widget),
context.getString(R.string.required_for_widgets),
context.string(R.string.zooper_widget),
context.string(R.string.required_for_widgets),
R.drawable.ic_zooper, ZOOPER_PACKAGE
)
)
Expand All @@ -66,8 +68,8 @@ class RequiredAppsViewModel : ViewModel() {
&& "widgets".inAssetsAndWithContent(context)) {
apps.add(
RequiredApp(
context.getString(R.string.kwgt),
context.getString(R.string.required_for_widgets),
context.string(R.string.kwgt),
context.string(R.string.required_for_widgets),
R.drawable.ic_kustom, KWGT_PACKAGE
)
)
Expand All @@ -77,8 +79,8 @@ class RequiredAppsViewModel : ViewModel() {
&& "widgets".inAssetsAndWithContent(context)) {
apps.add(
RequiredApp(
context.getString(R.string.kwgt_pro),
context.getString(R.string.required_for_widgets),
context.string(R.string.kwgt_pro),
context.string(R.string.required_for_widgets),
R.drawable.ic_kustom, "$KWGT_PACKAGE.pro"
)
)
Expand All @@ -87,8 +89,8 @@ class RequiredAppsViewModel : ViewModel() {
if (!context.isAppInstalled(KLWP_PACKAGE) && "wallpapers".inAssetsAndWithContent(context)) {
apps.add(
RequiredApp(
context.getString(R.string.klwp),
context.getString(R.string.required_for_wallpapers),
context.string(R.string.klwp),
context.string(R.string.required_for_wallpapers),
R.drawable.ic_kustom, KLWP_PACKAGE
)
)
Expand All @@ -98,8 +100,8 @@ class RequiredAppsViewModel : ViewModel() {
&& "wallpapers".inAssetsAndWithContent(context)) {
apps.add(
RequiredApp(
context.getString(R.string.klwp_pro),
context.getString(R.string.required_for_wallpapers),
context.string(R.string.klwp_pro),
context.string(R.string.required_for_wallpapers),
R.drawable.ic_kustom, "$KLWP_PACKAGE.pro"
)
)
Expand All @@ -109,8 +111,8 @@ class RequiredAppsViewModel : ViewModel() {
&& "lockscreens".inAssetsAndWithContent(context)) {
apps.add(
RequiredApp(
context.getString(R.string.klck),
context.getString(R.string.required_for_lockscreens),
context.string(R.string.klck),
context.string(R.string.required_for_lockscreens),
R.drawable.ic_kustom, KLCK_PACKAGE
)
)
Expand All @@ -120,30 +122,30 @@ class RequiredAppsViewModel : ViewModel() {
&& "lockscreens".inAssetsAndWithContent(context)) {
apps.add(
RequiredApp(
context.getString(R.string.klck_pro),
context.getString(R.string.required_for_lockscreens),
context.string(R.string.klck_pro),
context.string(R.string.required_for_lockscreens),
R.drawable.ic_kustom, "$KLCK_PACKAGE.pro"
)
)
}

if (!context.isAppInstalled(MEDIA_UTILS_PACKAGE)
&& context.resources.getBoolean(R.bool.media_utils_required)) {
&& context.boolean(R.bool.media_utils_required)) {
apps.add(
RequiredApp(
context.getString(R.string.media_utils),
context.getString(R.string.required_for_widgets),
context.string(R.string.media_utils),
context.string(R.string.required_for_widgets),
R.drawable.ic_zooper, MEDIA_UTILS_PACKAGE
)
)
}

if (!context.isAppInstalled(KOLORETTE_PACKAGE)
&& context.resources.getBoolean(R.bool.kolorette_required)) {
&& context.boolean(R.bool.kolorette_required)) {
apps.add(
RequiredApp(
context.getString(R.string.kolorette),
context.getString(R.string.required_for_templates),
context.string(R.string.kolorette),
context.string(R.string.required_for_templates),
R.drawable.ic_palette, KOLORETTE_PACKAGE
)
)
Expand All @@ -152,8 +154,8 @@ class RequiredAppsViewModel : ViewModel() {
if (!areAssetsInstalled(context)) {
apps.add(
RequiredApp(
context.getString(R.string.widgets),
context.getString(R.string.required_assets),
context.string(R.string.widgets),
context.string(R.string.required_assets),
R.drawable.ic_zooper
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.fragment.app.Fragment
import com.fondesa.kpermissions.PermissionStatus
import dev.jahir.frames.extensions.getAppName
import dev.jahir.frames.extensions.lazyViewModel
import dev.jahir.frames.extensions.string
import dev.jahir.frames.ui.activities.FramesActivity
import dev.jahir.frames.ui.fragments.CollectionsFragment
import dev.jahir.frames.ui.fragments.WallpapersFragment
Expand Down Expand Up @@ -90,8 +91,8 @@ abstract class KuperActivity : FramesActivity() {

override fun getPermissionRationaleMessage(): String =
when (currentItemId) {
R.id.setup -> getString(R.string.permission_request_assets, getAppName())
R.id.widgets -> getString(R.string.permission_request_wallpaper, getAppName())
R.id.setup -> string(R.string.permission_request_assets, getAppName())
R.id.widgets -> string(R.string.permission_request_wallpaper, getAppName())
else -> super.getPermissionRationaleMessage()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.ViewGroup
import com.afollestad.sectionedrecyclerview.SectionedRecyclerViewAdapter
import com.afollestad.sectionedrecyclerview.SectionedViewHolder
import dev.jahir.frames.extensions.inflate
import dev.jahir.frames.extensions.string
import dev.jahir.frames.ui.viewholders.SectionHeaderViewHolder
import dev.jahir.kuper.R
import dev.jahir.kuper.data.models.Component
Expand Down Expand Up @@ -34,12 +35,12 @@ class ComponentsAdapter(private val onClick: (Component) -> Unit) :
if (sectionTitles.isNotEmpty()) return
sectionTitles.clear()
sectionTitles.add(
ctxt.getString(R.string.x_templates, ctxt.getString(R.string.zooper_widget))
ctxt.string(R.string.x_templates, ctxt.string(R.string.zooper_widget))
)
sectionTitles.add(ctxt.getString(R.string.komponents))
sectionTitles.add(ctxt.getString(R.string.x_templates, ctxt.getString(R.string.kwgt)))
sectionTitles.add(ctxt.getString(R.string.x_templates, ctxt.getString(R.string.klck)))
sectionTitles.add(ctxt.getString(R.string.x_templates, ctxt.getString(R.string.klwp)))
sectionTitles.add(ctxt.string(R.string.komponents))
sectionTitles.add(ctxt.string(R.string.x_templates, ctxt.string(R.string.kwgt)))
sectionTitles.add(ctxt.string(R.string.x_templates, ctxt.string(R.string.klck)))
sectionTitles.add(ctxt.string(R.string.x_templates, ctxt.string(R.string.klwp)))
notifyDataSetChanged()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import dev.jahir.frames.extensions.dimenPixelSize
import dev.jahir.frames.extensions.dpToPx
import dev.jahir.frames.extensions.hasContent
import dev.jahir.frames.extensions.integer
import dev.jahir.frames.extensions.lower
import dev.jahir.frames.extensions.mdDialog
import dev.jahir.frames.extensions.openLink
Expand Down Expand Up @@ -47,15 +50,14 @@ class ComponentsFragment : BaseFramesFragment<Component>() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val columnsCount =
context?.resources?.getInteger(R.integer.wallpapers_columns_count) ?: 2
val columnsCount = context?.integer(R.integer.wallpapers_columns_count, 2) ?: 2
val gridLayoutManager =
GridLayoutManager(context, columnsCount, GridLayoutManager.VERTICAL, false)
recyclerView?.layoutManager = gridLayoutManager
recyclerView?.addItemDecoration(
SectionedGridSpacingDecoration(
columnsCount,
resources.getDimensionPixelSize(R.dimen.grids_spacing)
context?.dimenPixelSize(R.dimen.grids_spacing, 8.dpToPx) ?: 8.dpToPx
)
)
componentsAdapter.setLayoutManager(gridLayoutManager)
Expand Down Expand Up @@ -94,7 +96,7 @@ class ComponentsFragment : BaseFramesFragment<Component>() {
else -> ""
}
if (itemPkg.hasContent()) {
contxt.toast(contxt.getString(R.string.app_not_installed))
contxt.toast(R.string.app_not_installed)
contxt.openLink(PLAY_STORE_LINK_PREFIX + itemPkg)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import android.view.View
import android.widget.ProgressBar
import android.widget.TextView
import androidx.appcompat.widget.AppCompatImageView
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import coil.api.load
import com.afollestad.sectionedrecyclerview.SectionedViewHolder
import dev.jahir.frames.extensions.context
import dev.jahir.frames.extensions.drawable
import dev.jahir.frames.extensions.findView
import dev.jahir.frames.extensions.gone
import dev.jahir.frames.extensions.lower
Expand Down Expand Up @@ -41,7 +41,7 @@ class ComponentViewHolder(itemView: View) : SectionedViewHolder(itemView) {
app?.text = component.type.toString().lower().capitalize()
icon?.visibleIf(component.hasIntent)
if (icon?.isVisible == true) {
icon?.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_open_app))
icon?.setImageDrawable(context.drawable(R.drawable.ic_open_app))
icon?.setOnClickListener { listener?.invoke(component) }
}
val rightPreview =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import android.view.View
import android.widget.TextView
import androidx.appcompat.widget.AppCompatButton
import androidx.appcompat.widget.AppCompatImageView
import androidx.core.content.ContextCompat
import com.afollestad.sectionedrecyclerview.SectionedViewHolder
import dev.jahir.frames.extensions.context
import dev.jahir.frames.extensions.drawable
import dev.jahir.frames.extensions.findView
import dev.jahir.frames.extensions.resolveColor
import dev.jahir.frames.utils.tint
Expand All @@ -21,8 +21,7 @@ class RequiredAppViewHolder(itemView: View) : SectionedViewHolder(itemView) {

fun bind(app: RequiredApp, listener: (RequiredApp) -> Unit) {
icon?.setImageDrawable(
ContextCompat.getDrawable(context, app.icon)
?.tint(context.resolveColor(R.attr.colorOnSurface))
context.drawable(app.icon)?.tint(context.resolveColor(R.attr.colorOnSurface))
)
title?.text = app.name
description?.text = app.description
Expand Down

0 comments on commit d5ccb3b

Please sign in to comment.