This code was written before inside oncreate it was working fine but when i shifted it down in order to create a function this "it" is showing these errors, i had checked there is no variable like "it"
this is the code
if (manager.getInt("limitOfBox") > 0) {
Bloom.with(this)
.setParticleRadius(5f)
.setEffector(
BloomEffector.Builder()
.setDuration(1500)
.setAnchor(
(it.width / 2).toFloat(),
(it.height / 2).toFloat()
)
.build()
)
.boom(it)
and these are the errors, "it" is turned red
so please tell me what to write instead of "it" , so that it don't throw errors.
this is the old code which was working perfectly :-
class LuckyBoxActivity : AppCompatActivity() {
lateinit var binding: ActivityLuckyBoxBinding
lateinit var db: FirebaseFirestore
lateinit var myRepo: MyRepo
lateinit var manager: PrefManager
val activity = this
@SuppressLint("SetTextI18n")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityLuckyBoxBinding.inflate(layoutInflater)
setContentView(binding.root)
showProgress()
var winningCoins = 0
var limit = 0
db = FirebaseFirestore.getInstance()
myRepo = MyRepo(this)
manager = PrefManager(this)
loadBanner()
db.collection("Earning").document("box")
.addSnapshotListener { value, error ->
if (error == null) {
val data = value?.toObject(WatchVideoModel::class.java)
winningCoins = data?.winningCoins.toString().toInt()
limit = data?.limit.toString().toInt()
Log.e("luck Box", "onCreate: $winningCoins")
Log.e("luck Box", "onCreate: $limit")
if (manager.getInt("limitOfBox") == 102) {
binding.limit.text = "$limit"
manager.setInt("limitOfBox", limit)
} else {
binding.limit.text = manager.getInt("limitOfBox").toString()
}
dismissProgress()
}
}
binding.giftImg.setOnClickListener {
val winningAmount = (0..winningCoins).random()
if (manager.getInt("limitOfBox") > 0) {
Bloom.with(this)
.setParticleRadius(5f)
.setEffector(
BloomEffector.Builder()
.setDuration(1500)
.setAnchor(
(it.width / 2).toFloat(),
(it.height / 2).toFloat()
)
.build()
)
.boom(it)
Handler(Looper.getMainLooper()).postDelayed(Runnable {
binding.giftImg.visibility = View.INVISIBLE
}, 1000)
Handler(Looper.getMainLooper()).postDelayed(Runnable {
manager.setInt("limitOfBox", manager.getInt("limitOfBox") - 1)
binding.limit.text = manager.getInt("limitOfBox").toString()
binding.resultText.visibility = View.VISIBLE
if (winningAmount == 0) {
binding.resultText.text =
"Oops !! better luck next time..."
} else {
binding.resultText.text = "$winningAmount Coins"
myRepo.addCoins(winningAmount.toString().toDouble())
}
}, 1500)
} else {
showToast("Daily Limit Over")
}
}
}
fun loadBanner() {
val view = BannerView(this@LuckyBoxActivity, constants.banner, UnityBannerSize(320, 50))
view.load()
binding.bannerAd.addView(view)
}
companion object {
private const val TAG = "LuckyBoxActivity"
}
}
CodePudding user response:
it
here stands for the view that you want this Bloom Effect
on.
Refer to the example given by the library itself.
Bloom.with('activity')
.setParticleRadius(5)
.setEffector(new BloomEffector.Builder()
.setDuration(800)
.setAnchor(view.getWidth() / 2, view.getHeight() / 2)
.build())
.boom(view);
here view is the item in which the effect is to be created.
CodePudding user response:
Where you moved your code from most likely was inside a scope function. We can't tell you what it
is without you showing us the code in onCreate where you got it from.
A very common scope function is the scope funtion let
. If you do for example
val a = "test"
a.let {
print(it)
}
then it
refers to the variable a
. Maybe something like that was used there.
You can read more about scope functions here