Skip to content

Commit d87d65a

Browse files
authored
Upgrade gradle and cleanup (#19)
1 parent 1a55afc commit d87d65a

File tree

13 files changed

+144
-121
lines changed

13 files changed

+144
-121
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ jobs:
3232
- name: Clean old builds
3333
run: rm $GITHUB_WORKSPACE/builds/*.cs3
3434

35-
- name: Setup JDK 11
35+
- name: Setup JDK 17
3636
uses: actions/setup-java@v1
3737
with:
38-
java-version: 11
38+
java-version: 17
3939

4040
- name: Setup Android SDK
4141
uses: android-actions/setup-android@v2

ExampleProvider/build.gradle.kts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
dependencies {
2-
implementation("androidx.legacy:legacy-support-v4:1.0.0")
3-
implementation("com.google.android.material:material:1.4.0")
4-
implementation("androidx.recyclerview:recyclerview:1.2.1")
2+
implementation("com.google.android.material:material:1.12.0")
3+
implementation("androidx.recyclerview:recyclerview:1.3.2")
54
}
6-
// use an integer for version numbers
7-
version = -1
85

6+
// Use an integer for version numbers
7+
version = 1
98

109
cloudstream {
11-
// All of these properties are optional, you can safely remove them
10+
// All of these properties are optional, you can safely remove any of them.
1211

1312
description = "Lorem ipsum"
14-
authors = listOf("Cloudburst")
13+
authors = listOf("Cloudburst", "Luna712")
1514

1615
/**
17-
* Status int as the following:
16+
* Status int as one of the following:
1817
* 0: Down
1918
* 1: Ok
2019
* 2: Slow
21-
* 3: Beta only
22-
* */
23-
status = 1
20+
* 3: Beta-only
21+
**/
22+
status = 1 // Will be 3 if unspecified
2423

2524
tvTypes = listOf("Movie")
2625

2726
requiresResources = true
2827
language = "en"
2928

30-
// random cc logo i found
29+
// Random CC logo I found
3130
iconUrl = "https://upload.wikimedia.org/wikipedia/commons/2/2f/Korduene_Logo.png"
3231
}
3332

3433
android {
3534
buildFeatures {
35+
buildConfig = true
3636
viewBinding = true
3737
}
38-
}
38+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest package="com.example"/>
2+
<manifest />
Lines changed: 55 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,94 @@
11
package com.example
22

3+
import android.annotation.SuppressLint
34
import android.content.res.ColorStateList
45
import android.graphics.drawable.Drawable
56
import android.os.Build
67
import android.os.Bundle
7-
import androidx.fragment.app.Fragment
88
import android.view.LayoutInflater
99
import android.view.View
1010
import android.view.ViewGroup
11-
import com.lagradost.cloudstream3.R
1211
import android.widget.ImageView
1312
import android.widget.TextView
1413
import androidx.annotation.RequiresApi
1514
import androidx.core.content.res.ResourcesCompat
15+
import androidx.core.widget.TextViewCompat
16+
import androidx.fragment.app.Fragment
1617
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
18+
import com.lagradost.cloudstream3.R
1719
import 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+
}
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
package com.example
22

3-
import com.lagradost.cloudstream3.plugins.CloudstreamPlugin
4-
import com.lagradost.cloudstream3.plugins.Plugin
5-
import com.lagradost.cloudstream3.APIHolder
63
import android.content.Context
7-
import android.util.Log
84
import androidx.appcompat.app.AppCompatActivity
5+
import com.lagradost.cloudstream3.plugins.CloudstreamPlugin
6+
import com.lagradost.cloudstream3.plugins.Plugin
97

108
@CloudstreamPlugin
11-
class TestPlugin: Plugin() {
12-
var activity: AppCompatActivity? = null
9+
class ExamplePlugin: Plugin() {
10+
private var activity: AppCompatActivity? = null
1311

1412
override fun load(context: Context) {
15-
activity = context as AppCompatActivity
13+
activity = context as? AppCompatActivity
14+
1615
// All providers should be added in this manner
17-
registerMainAPI(ExampleProvider(this))
16+
registerMainAPI(ExampleProvider())
1817

19-
openSettings = { ctx ->
18+
openSettings = {
2019
val frag = BlankFragment(this)
21-
frag.show(activity!!.supportFragmentManager, "Frag")
20+
activity?.let {
21+
frag.show(it.supportFragmentManager, "Frag")
22+
}
2223
}
2324
}
2425
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
package com.example
22

3-
import androidx.appcompat.app.AppCompatActivity
4-
import com.lagradost.cloudstream3.TvType
53
import com.lagradost.cloudstream3.MainAPI
64
import com.lagradost.cloudstream3.SearchResponse
5+
import com.lagradost.cloudstream3.TvType
76

8-
class ExampleProvider(val plugin: TestPlugin) : MainAPI() { // all providers must be an intstance of MainAPI
7+
class ExampleProvider : MainAPI() { // All providers must be an instance of MainAPI
98
override var mainUrl = "https://example.com/"
109
override var name = "Example provider"
1110
override val supportedTypes = setOf(TvType.Movie)
1211

1312
override var lang = "en"
1413

15-
// enable this when your provider has a main page
14+
// Enable this when your provider has a main page
1615
override val hasMainPage = true
1716

18-
// this function gets called when you search for something
17+
// This function gets called when you search for something
1918
override suspend fun search(query: String): List<SearchResponse> {
20-
return listOf<SearchResponse>()
19+
return listOf()
2120
}
2221
}

ExampleProvider/src/main/res/drawable/ic_android_24dp.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
android:viewportHeight="24" android:viewportWidth="24"
33
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
44
<path android:fillColor="#FF000000" android:pathData="M17.6,11.48 L19.44,8.3a0.63,0.63 0,0 0,-1.09 -0.63l-1.88,3.24a11.43,11.43 0,0 0,-8.94 0L5.65,7.67a0.63,0.63 0,0 0,-1.09 0.63L6.4,11.48A10.81,10.81 0,0 0,1 20L23,20A10.81,10.81 0,0 0,17.6 11.48ZM7,17.25A1.25,1.25 0,1 1,8.25 16,1.25 1.25,0 0,1 7,17.25ZM17,17.25A1.25,1.25 0,1 1,18.25 16,1.25 1.25,0 0,1 17,17.25Z"/>
5-
</vector>
5+
</vector>

ExampleProvider/src/main/res/layout/fragment_blank.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:app="http://schemas.android.com/apk/res-auto"
43
xmlns:tools="http://schemas.android.com/tools"
54
android:id="@+id/mainFragmentLayout"
65
android:layout_width="match_parent"
@@ -19,7 +18,7 @@
1918
android:id="@+id/textView2"
2019
android:layout_width="wrap_content"
2120
android:layout_height="wrap_content"
22-
android:text="[loaded from app trans]" />
21+
android:text="@string/loaded_from_app_trans" />
2322

2423
<LinearLayout
2524
android:layout_width="wrap_content"
@@ -30,13 +29,15 @@
3029
android:id="@+id/imageView"
3130
android:layout_width="wrap_content"
3231
android:layout_height="wrap_content"
33-
tools:src="@drawable/ic_android_24dp" />
32+
tools:src="@drawable/ic_android_24dp"
33+
tools:ignore="ContentDescription" />
3434

3535
<ImageView
3636
android:id="@+id/imageView2"
3737
android:layout_width="wrap_content"
3838
android:layout_height="wrap_content"
39-
tools:src="@drawable/ic_android_24dp" />
39+
tools:src="@drawable/ic_android_24dp"
40+
tools:ignore="ContentDescription" />
4041
</LinearLayout>
4142

4243
</LinearLayout>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<string name="hello_fragment">Witaj zabawny fragmencie!!</string>
4+
<string name="loaded_from_app_trans">[Załadowane z aplikacji trans]</string>
45
</resources>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<string name="hello_fragment">Hello funny fragment!!</string>
4+
<string name="loaded_from_app_trans">[loaded from app trans]</string>
45
</resources>

0 commit comments

Comments
 (0)