Skip to content

Commit

Permalink
chore: update deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
jahirfiquitiva committed Jul 17, 2023
1 parent 9eac2a0 commit 700cb8f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import dev.jahir.frames.extensions.views.setPaddingTop
import kotlin.math.min
import kotlin.math.roundToInt

@Suppress("DEPRECATION")
internal fun DrawerBlueprintActivity.enableTranslucentStatusBar(enable: Boolean = true) {
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
val params: WindowManager.LayoutParams = window.attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal fun FragmentActivity.pickIcon(icon: Icon, drawable: Drawable?, pickerKe
if (bitmap.isRecycled) bitmap
else bitmap.copy(bitmap.config, false)
)
} catch (e: Exception) {
} catch (_: Exception) {
}
val iconRes = Intent.ShortcutIconResource.fromContext(this, icon.resId)
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes)
Expand All @@ -51,4 +51,4 @@ internal fun FragmentActivity.pickIcon(icon: Icon, drawable: Drawable?, pickerKe
setResult(RESULT_CANCELED, intent)
}
finish()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Intent
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.View
import androidx.activity.result.contract.ActivityResultContracts
import androidx.recyclerview.widget.LinearLayoutManager
import dev.jahir.blueprint.R
import dev.jahir.blueprint.data.models.Icon
Expand All @@ -23,6 +24,14 @@ import dev.jahir.frames.ui.fragments.base.BaseFramesFragment

class IconsCategoriesFragment : BaseFramesFragment<IconsCategory>() {

private val pickIconIntentLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
activity?.let {
it.setResult(result.resultCode, result.data)
it.finish()
}
}

private val iconsCategoriesAdapter: IconsCategoriesAdapter by lazy {
IconsCategoriesAdapter(::onOpenCategory, ::onIconClick)
}
Expand Down Expand Up @@ -97,22 +106,12 @@ class IconsCategoriesFragment : BaseFramesFragment<IconsCategory>() {

private fun onOpenCategory(category: IconsCategory) {
val pickerKey = (activity as? BlueprintActivity)?.pickerKey ?: 0
startActivityForResult(
Intent(context, IconsCategoryActivity::class.java).apply {
putExtra(IconsCategoryActivity.CATEGORY_KEY, category)
putExtra(IconsCategoryActivity.PICKER_KEY, pickerKey)
}, if (pickerKey != 0) 55 else 54
)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == 55) {
activity?.let {
it.setResult(resultCode, data)
it.finish()
}
val pickIconIntent = Intent(context, IconsCategoryActivity::class.java).apply {
putExtra(IconsCategoryActivity.CATEGORY_KEY, category)
putExtra(IconsCategoryActivity.PICKER_KEY, pickerKey)
}
if (pickerKey != 0) pickIconIntentLauncher.launch(pickIconIntent)
else startActivity(pickIconIntent)
}

private fun onIconClick(icon: Icon, drawable: Drawable?) {
Expand Down

0 comments on commit 700cb8f

Please sign in to comment.