Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaozhan committed May 10, 2022
2 parents a5cc5ab + c7b1c58 commit 1815b88
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import com.github.submob.basemob.adapter.BaseVBRecyclerViewAdapter
import com.oztechan.ccc.analytics.AnalyticsManager
import com.oztechan.ccc.analytics.model.EventParam
import com.oztechan.ccc.analytics.model.FirebaseEvent
import com.oztechan.ccc.android.util.setBackgroundByName
import com.oztechan.ccc.client.model.Currency
import com.oztechan.ccc.client.util.getFormatted
import com.oztechan.ccc.client.util.toStandardDigits
import com.oztechan.ccc.client.viewmodel.calculator.CalculatorEvent
import com.oztechan.ccc.resources.setBackgroundByName
import mustafaozhan.github.com.mycurrencies.databinding.ItemCalculatorBinding

class CalculatorAdapter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import com.oztechan.ccc.analytics.AnalyticsManager
import com.oztechan.ccc.analytics.model.UserProperty
import com.oztechan.ccc.android.util.copyToClipBoard
import com.oztechan.ccc.android.util.dataState
import com.oztechan.ccc.android.util.getImageResourceByName
import com.oztechan.ccc.android.util.getNavigationResult
import com.oztechan.ccc.android.util.setBackgroundByName
import com.oztechan.ccc.android.util.setBannerAd
import com.oztechan.ccc.android.util.showLoading
import com.oztechan.ccc.android.util.showSnack
import com.oztechan.ccc.client.util.toValidList
import com.oztechan.ccc.client.viewmodel.calculator.CalculatorEffect
import com.oztechan.ccc.client.viewmodel.calculator.CalculatorViewModel
import com.oztechan.ccc.resources.getDrawableIdByFileName
import com.oztechan.ccc.resources.setBackgroundByName
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import mustafaozhan.github.com.mycurrencies.R
Expand Down Expand Up @@ -162,7 +162,7 @@ class CalculatorFragment : BaseVBFragment<FragmentCalculatorBinding>() {
is CalculatorEffect.ShowRate -> showSnack(
requireView(),
viewEffect.text,
icon = getDrawableIdByFileName(viewEffect.name)
icon = requireContext().getImageResourceByName(viewEffect.name)
)
}
}.launchIn(viewLifecycleOwner.lifecycleScope)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import android.view.ViewGroup
import android.view.animation.AnimationUtils
import androidx.recyclerview.widget.DiffUtil
import com.github.submob.basemob.adapter.BaseVBRecyclerViewAdapter
import com.oztechan.ccc.android.util.setBackgroundByName
import com.oztechan.ccc.client.model.Currency
import com.oztechan.ccc.client.viewmodel.currencies.CurrenciesEvent
import com.oztechan.ccc.resources.setBackgroundByName
import mustafaozhan.github.com.mycurrencies.R
import mustafaozhan.github.com.mycurrencies.databinding.ItemCurrenciesBinding

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import com.github.submob.basemob.adapter.BaseVBRecyclerViewAdapter
import com.oztechan.ccc.android.util.setBackgroundByName
import com.oztechan.ccc.client.model.Currency
import com.oztechan.ccc.client.viewmodel.selectcurrency.SelectCurrencyEvent
import com.oztechan.ccc.resources.setBackgroundByName
import mustafaozhan.github.com.mycurrencies.databinding.ItemSelectCurrencyBinding

class SelectCurrencyAdapter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ import android.view.animation.Animation
import android.view.animation.Transformation
import android.view.inputmethod.InputMethodManager
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import co.touchlab.kermit.Logger
import com.github.submob.logmob.w
import com.github.submob.scopemob.castTo
import com.oztechan.ccc.ad.AdManager
import com.oztechan.ccc.client.model.RateState
import com.oztechan.ccc.resources.toImageFileName
import mustafaozhan.github.com.mycurrencies.R
import java.io.FileNotFoundException

private const val ANIMATION_DURATION = 500L

Expand Down Expand Up @@ -133,3 +138,18 @@ fun View.copyToClipBoard(text: String) {
showSnack(this, context.getString(R.string.copied_to_clipboard))
}
}

fun ImageView.setBackgroundByName(
name: String
) = setImageResource(context.getImageResourceByName(name))

fun Context.getImageResourceByName(name: String): Int = try {
resources.getIdentifier(
name.toImageFileName(),
"drawable",
packageName
)
} catch (e: FileNotFoundException) {
Logger.w(e)
R.drawable.unknown
}
2 changes: 1 addition & 1 deletion ios/CCC/Util/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension ResourcesImageResource {

extension String {
func getImage() -> UIImage {
return ResourcesKt.getImageByFileName(name: self).toUIImage()!
return IOSResourcesKt.getImageByFileName(name: self).toUIImage()!
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package com.oztechan.ccc.resources

import dev.icerock.moko.resources.ImageResource
import dev.icerock.moko.resources.getImageByFileName

fun getImageByFileName(
name: String
): ImageResource = MR.images.getImageByFileName(name.toImageFileName()) ?: MR.images.unknown

fun String.toImageFileName() = lowercase()
.replace("try", "tryy")
.ifEmpty { "unknown" }
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ package com.oztechan.ccc.resources

import dev.icerock.moko.graphics.toUIColor
import dev.icerock.moko.resources.ColorResource
import dev.icerock.moko.resources.ImageResource
import dev.icerock.moko.resources.StringResource
import dev.icerock.moko.resources.desc.Resource
import dev.icerock.moko.resources.desc.ResourceFormatted
import dev.icerock.moko.resources.desc.StringDesc
import dev.icerock.moko.resources.getColor
import dev.icerock.moko.resources.getImageByFileName
import platform.UIKit.UIColor
import platform.UIKit.UIScreen

fun getImageByFileName(
name: String
): ImageResource = MR.images.getImageByFileName(name.toImageFileName()) ?: MR.images.unknown


fun getString(stringResource: StringResource): StringDesc {
return StringDesc.Resource(stringResource)
}
Expand Down

0 comments on commit 1815b88

Please sign in to comment.