11package com.example
22
3+ import android.annotation.SuppressLint
34import android.content.res.ColorStateList
45import android.graphics.drawable.Drawable
56import android.os.Build
67import android.os.Bundle
7- import androidx.fragment.app.Fragment
88import android.view.LayoutInflater
99import android.view.View
1010import android.view.ViewGroup
11- import com.lagradost.cloudstream3.R
1211import android.widget.ImageView
1312import android.widget.TextView
1413import androidx.annotation.RequiresApi
1514import androidx.core.content.res.ResourcesCompat
15+ import androidx.core.widget.TextViewCompat
16+ import androidx.fragment.app.Fragment
1617import com.google.android.material.bottomsheet.BottomSheetDialogFragment
18+ import com.lagradost.cloudstream3.R
1719import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
1820
19- // TODO: Rename parameter arguments, choose names that match
20- // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
21- private const val ARG_PARAM1 = " param1"
22- private const val ARG_PARAM2 = " param2"
23-
2421/* *
2522 * A simple [Fragment] subclass.
26- * Use the [BlankFragment.newInstance] factory method to
27- * create an instance of this fragment.
2823 */
29- class BlankFragment (val plugin : TestPlugin ) : BottomSheetDialogFragment() {
30- // TODO: Rename and change types of parameters
31- private var param1: String? = null
32- private var param2: String? = null
33-
34- override fun onCreate (savedInstanceState : Bundle ? ) {
35- super .onCreate(savedInstanceState)
36- arguments?.let {
37- param1 = it.getString(ARG_PARAM1 )
38- param2 = it.getString(ARG_PARAM2 )
39- }
40- }
24+ class BlankFragment (private val plugin : ExamplePlugin ) : BottomSheetDialogFragment() {
4125
26+ // Helper function to get a drawable resource by name
27+ @SuppressLint(" DiscouragedApi" )
28+ @Suppress(" SameParameterValue" )
4229 private fun getDrawable (name : String ): Drawable ? {
43- val id = plugin.resources!! .getIdentifier(name, " drawable" , BuildConfig .LIBRARY_PACKAGE_NAME )
44- return ResourcesCompat .getDrawable(plugin.resources!! , id , null )
30+ val id = plugin.resources? .getIdentifier(name, " drawable" , BuildConfig .LIBRARY_PACKAGE_NAME )
31+ return id?. let { ResourcesCompat .getDrawable(plugin.resources ? : return null , it , null ) }
4532 }
4633
34+ // Helper function to get a string resource by name
35+ @SuppressLint(" DiscouragedApi" )
36+ @Suppress(" SameParameterValue" )
4737 private fun getString (name : String ): String? {
48- val id = plugin.resources!! .getIdentifier(name, " string" , BuildConfig .LIBRARY_PACKAGE_NAME )
49- return plugin.resources!! .getString(id)
38+ val id = plugin.resources? .getIdentifier(name, " string" , BuildConfig .LIBRARY_PACKAGE_NAME )
39+ return id?. let { plugin.resources? .getString(it) }
5040 }
5141
52- private fun <T : View > View.findView (name : String ): T {
53- val id = plugin.resources!! .getIdentifier(name, " id" , BuildConfig .LIBRARY_PACKAGE_NAME )
54- return this .findViewById(id)
42+ // Generic findView function to find views by name
43+ @SuppressLint(" DiscouragedApi" )
44+ private fun <T : View > View.findViewByName (name : String ): T ? {
45+ val id = plugin.resources?.getIdentifier(name, " id" , BuildConfig .LIBRARY_PACKAGE_NAME )
46+ return findViewById(id ? : return null )
5547 }
5648
49+ @SuppressLint(" DiscouragedApi" )
5750 override fun onCreateView (
58- inflater : LayoutInflater , container : ViewGroup ? ,
51+ inflater : LayoutInflater ,
52+ container : ViewGroup ? ,
5953 savedInstanceState : Bundle ?
6054 ): View ? {
6155 // Inflate the layout for this fragment
62- val id = plugin.resources!! .getIdentifier(" fragment_blank" , " layout" , BuildConfig .LIBRARY_PACKAGE_NAME )
63- val layout = plugin.resources!! .getLayout(id)
64- return inflater.inflate(layout, container, false )
56+ val layoutId = plugin.resources?.getIdentifier(" fragment_blank" , " layout" , BuildConfig .LIBRARY_PACKAGE_NAME )
57+ return layoutId?.let {
58+ inflater.inflate(plugin.resources?.getLayout(it), container, false )
59+ }
6560 }
6661
6762 @RequiresApi(Build .VERSION_CODES .M )
68- override fun onViewCreated (view : View , savedInstanceState : Bundle ? ) {
69- val imageView = view.findView< ImageView >( " imageView " )
70- val imageView2 = view.findView< ImageView >( " imageView2 " )
71- val textView = view.findView< TextView >( " textView " )
72- val textView2 = view.findView< TextView >( " textView2 " )
63+ override fun onViewCreated (
64+ view : View ,
65+ savedInstanceState : Bundle ?
66+ ) {
67+ super .onViewCreated(view, savedInstanceState )
7368
74- textView.text = getString(" hello_fragment" )
75- textView.setTextAppearance(view.context, R .style.ResultInfoText )
76- textView2.text = view.context.resources.getText(R .string.legal_notice_text)
69+ // Initialize views
70+ val imageView: ImageView ? = view.findViewByName(" imageView" )
71+ val imageView2: ImageView ? = view.findViewByName(" imageView2" )
72+ val textView: TextView ? = view.findViewByName(" textView" )
73+ val textView2: TextView ? = view.findViewByName(" textView2" )
74+
75+ // Set text and styling if the views are found
76+ textView?.apply {
77+ text = getString(" hello_fragment" )
78+ TextViewCompat .setTextAppearance(this , R .style.ResultInfoText )
79+ }
7780
78- imageView.setImageDrawable(
79- getDrawable(" ic_android_24dp" )
80- )
81- imageView.imageTintList = ColorStateList .valueOf(view.context.getColor(R .color.white))
81+ textView2?.text = view.context.resources.getText(R .string.legal_notice_text)
8282
83- imageView2.setImageDrawable(
84- getDrawable(" ic_android_24dp" )
85- )
86- imageView2.imageTintList = ColorStateList .valueOf(view.context.colorFromAttribute(R .attr.white))
83+ // Set image resources and tint if the views are found
84+ imageView?.apply {
85+ setImageDrawable(getDrawable(" ic_android_24dp" ))
86+ imageTintList = ColorStateList .valueOf(view.context.getColor(R .color.white))
87+ }
88+
89+ imageView2?.apply {
90+ setImageDrawable(getDrawable(" ic_android_24dp" ))
91+ imageTintList = ColorStateList .valueOf(view.context.colorFromAttribute(R .attr.white))
92+ }
8793 }
88- }
94+ }
0 commit comments