diff --git a/library/src/main/kotlin/dev/jahir/kuper/data/viewmodels/RequiredAppsViewModel.kt b/library/src/main/kotlin/dev/jahir/kuper/data/viewmodels/RequiredAppsViewModel.kt index 72ab11c8..cfa64837 100644 --- a/library/src/main/kotlin/dev/jahir/kuper/data/viewmodels/RequiredAppsViewModel.kt +++ b/library/src/main/kotlin/dev/jahir/kuper/data/viewmodels/RequiredAppsViewModel.kt @@ -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 @@ -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 ) ) @@ -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 ) ) @@ -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" ) ) @@ -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 ) ) @@ -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" ) ) @@ -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 ) ) @@ -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 ) ) @@ -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 ) ) diff --git a/library/src/main/kotlin/dev/jahir/kuper/ui/activities/KuperActivity.kt b/library/src/main/kotlin/dev/jahir/kuper/ui/activities/KuperActivity.kt index 9435255b..c7f60232 100644 --- a/library/src/main/kotlin/dev/jahir/kuper/ui/activities/KuperActivity.kt +++ b/library/src/main/kotlin/dev/jahir/kuper/ui/activities/KuperActivity.kt @@ -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 @@ -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() } diff --git a/library/src/main/kotlin/dev/jahir/kuper/ui/adapters/ComponentsAdapter.kt b/library/src/main/kotlin/dev/jahir/kuper/ui/adapters/ComponentsAdapter.kt index 560d1e44..95a0d2ee 100644 --- a/library/src/main/kotlin/dev/jahir/kuper/ui/adapters/ComponentsAdapter.kt +++ b/library/src/main/kotlin/dev/jahir/kuper/ui/adapters/ComponentsAdapter.kt @@ -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 @@ -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() } diff --git a/library/src/main/kotlin/dev/jahir/kuper/ui/fragments/ComponentsFragment.kt b/library/src/main/kotlin/dev/jahir/kuper/ui/fragments/ComponentsFragment.kt index 28c49b45..5e213498 100644 --- a/library/src/main/kotlin/dev/jahir/kuper/ui/fragments/ComponentsFragment.kt +++ b/library/src/main/kotlin/dev/jahir/kuper/ui/fragments/ComponentsFragment.kt @@ -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 @@ -47,15 +50,14 @@ class ComponentsFragment : BaseFramesFragment() { 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) @@ -94,7 +96,7 @@ class ComponentsFragment : BaseFramesFragment() { 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) } } diff --git a/library/src/main/kotlin/dev/jahir/kuper/ui/viewholders/ComponentViewHolder.kt b/library/src/main/kotlin/dev/jahir/kuper/ui/viewholders/ComponentViewHolder.kt index c2f9b919..fd4c5277 100644 --- a/library/src/main/kotlin/dev/jahir/kuper/ui/viewholders/ComponentViewHolder.kt +++ b/library/src/main/kotlin/dev/jahir/kuper/ui/viewholders/ComponentViewHolder.kt @@ -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 @@ -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 = diff --git a/library/src/main/kotlin/dev/jahir/kuper/ui/viewholders/RequiredAppViewHolder.kt b/library/src/main/kotlin/dev/jahir/kuper/ui/viewholders/RequiredAppViewHolder.kt index e2f999f8..b08a3ecd 100644 --- a/library/src/main/kotlin/dev/jahir/kuper/ui/viewholders/RequiredAppViewHolder.kt +++ b/library/src/main/kotlin/dev/jahir/kuper/ui/viewholders/RequiredAppViewHolder.kt @@ -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 @@ -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