Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/kotlin version #559

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
android_compileSdk = "34"
android_gradle_plugin = "8.2.2"
android_minSdk = "19"
kotlin_plugin = "1.9.0"
kotlin_plugin = "1.7.20"
sonarqube_plugin = "3.3"
android_buildTools = "34.0.0"
detekt_gradle_plugin = "1.20.0-RC1"
Expand Down
1 change: 0 additions & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ android {
}
}
buildFeatures {
dataBinding true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ExpandableListView
import android.widget.Toast
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
Expand All @@ -30,21 +31,24 @@ import com.clevertap.demo.R
import com.clevertap.demo.ViewModelFactory
import com.clevertap.demo.WebViewActivity
import com.clevertap.demo.action
import com.clevertap.demo.databinding.HomeScreenFragmentBinding
import com.clevertap.demo.snack
import org.json.JSONObject

private const val TAG = "HomeScreenFragment"
private const val PERMISSIONS_REQUEST_CODE = 34

data class HomeScreenFragmentBinding(
val expandableListView: ExpandableListView,
val root: CoordinatorLayout
)

class HomeScreenFragment : Fragment() {

private val viewModel by viewModels<HomeScreenViewModel> {
ViewModelFactory((activity as? HomeScreenActivity)?.cleverTapDefaultInstance)
}

companion object {

fun newInstance() = HomeScreenFragment()
}

Expand All @@ -54,12 +58,15 @@ class HomeScreenFragment : Fragment() {
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
listItemBinding = HomeScreenFragmentBinding.inflate(layoutInflater, container, false).apply {
viewmodel = viewModel
}
val view = LayoutInflater.from(context).inflate(R.layout.home_screen_fragment, container, false)
listItemBinding = HomeScreenFragmentBinding(
expandableListView = view.findViewById(R.id.expandableListView),
root = view.findViewById(R.id.home_root)
)

listItemBinding.expandableListView.isNestedScrollingEnabled = true

return listItemBinding.root
return view
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -95,14 +102,9 @@ class HomeScreenFragment : Fragment() {
}

private fun setupListAdapter() {
val viewModel = listItemBinding.viewmodel
if (viewModel != null) {
val listAdapter =
HomeScreenListAdapter(viewModel, HomeScreenModel.listData.keys.toList(), HomeScreenModel.listData)
listItemBinding.expandableListView.setAdapter(listAdapter)
} else {
Log.w(TAG, "ViewModel not initialized when attempting to set up adapter.")
}
listItemBinding.expandableListView.setAdapter(
HomeScreenListAdapter(viewModel, HomeScreenModel.listData.keys.toList(), HomeScreenModel.listData)
)
}

private fun initCTGeofenceApi(cleverTapInstance: CleverTapAPI) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseExpandableListAdapter
import com.clevertap.demo.databinding.CtFeatureFunctionsBinding
import com.clevertap.demo.databinding.CtFeatureRowBinding
import android.widget.TextView
import com.clevertap.demo.R

data class CtFeatureRowBinding(
val title: TextView
)

data class CtFeatureFunctionsBinding(
val fTitle: TextView
)
class HomeScreenListAdapter(
private val viewModel: HomeScreenViewModel, private val titleList: List<String>,
private val viewModel: HomeScreenViewModel,
private val titleList: List<String>,
private val detailsList: Map<String, List<String>>
) : BaseExpandableListAdapter() {

Expand All @@ -19,21 +27,18 @@ class HomeScreenListAdapter(
override fun hasStableIds(): Boolean = false

override fun getGroupView(groupPosition: Int, isExpanded: Boolean, convertView: View?, parent: ViewGroup?): View {
var convertViewShadow = convertView
val binding: CtFeatureRowBinding

if (convertViewShadow == null) {
val layoutInflater = LayoutInflater.from(parent?.context)
binding = CtFeatureRowBinding.inflate(layoutInflater, parent, false)
convertViewShadow = binding.root
} else {
binding = convertViewShadow.tag as CtFeatureRowBinding
}

binding.title = getGroup(groupPosition) as String
val view = convertView
?: LayoutInflater.from(parent?.context).inflate(R.layout.ct_feature_row, parent, false).also { view ->
val binding = CtFeatureRowBinding(
title = view.findViewById(R.id.featureTitle)
)
view.tag = binding
}

(view.tag as? CtFeatureRowBinding)?.title?.text = getGroup(groupPosition) as String

convertViewShadow.tag = binding
return convertViewShadow
return view
}

override fun getChildrenCount(groupPosition: Int): Int {
Expand All @@ -53,24 +58,23 @@ class HomeScreenListAdapter(
convertView: View?,
parent: ViewGroup?
): View {
var convertViewShadow = convertView
val binding: CtFeatureFunctionsBinding

if (convertViewShadow == null) {
val layoutInflater = LayoutInflater.from(parent?.context)
binding = CtFeatureFunctionsBinding.inflate(layoutInflater, parent, false)
convertViewShadow = binding.root
} else {
binding = convertViewShadow.tag as CtFeatureFunctionsBinding
}

binding.fTitle = getChild(groupPosition, childPosition) as String
binding.groupPosition = groupPosition
binding.childPosition = childPosition
binding.viewmodel = viewModel
val view = convertView
?: LayoutInflater.from(parent?.context).inflate(R.layout.ct_feature_functions, parent, false).also { view ->
val binding = CtFeatureFunctionsBinding(
fTitle = view.findViewById(R.id.functionTitle)
)
view.tag = binding
}
(view.tag as? CtFeatureFunctionsBinding)?.fTitle?.apply {
text = getChild(groupPosition, childPosition) as String
setOnClickListener(null)
setOnClickListener {
viewModel.onChildClick(groupPosition = groupPosition, childPosition = childPosition)
}
}

convertViewShadow.tag = binding
return convertViewShadow
return view
}

override fun getChildId(groupPosition: Int, childPosition: Int): Long = childPosition.toLong()
Expand Down
57 changes: 16 additions & 41 deletions sample/src/main/res/layout/ct_feature_functions.xml
Original file line number Diff line number Diff line change
@@ -1,45 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

<variable
name="fTitle"
type="java.lang.String" />

<variable
name="groupPosition"
type="java.lang.Integer" />

<variable
name="childPosition"
type="java.lang.Integer" />

<variable
name="viewmodel"
type="com.clevertap.demo.ui.main.HomeScreenViewModel" />
</data>


<androidx.constraintlayout.widget.ConstraintLayout
<TextView
android:id="@+id/functionTitle"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/functionTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:onClick="@{() -> viewmodel.onChildClick(groupPosition,childPosition)}"
android:paddingBottom="12dp"
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
android:paddingStart="?android:attr/expandableListPreferredChildPaddingLeft"
android:paddingTop="12dp"
android:text="@{fTitle}"
android:textColor="@android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:paddingBottom="12dp"
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
android:paddingStart="?android:attr/expandableListPreferredChildPaddingLeft"
android:paddingTop="12dp"
android:textColor="@android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
48 changes: 18 additions & 30 deletions sample/src/main/res/layout/ct_feature_row.xml
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<data>

<variable
name="title"
type="java.lang.String" />

</data>

<androidx.constraintlayout.widget.ConstraintLayout
<TextView
android:id="@+id/featureTitle"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/featureTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#757de8"
android:paddingBottom="15dp"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:paddingStart="?android:attr/expandableListPreferredItemPaddingLeft"
android:paddingTop="15dp"
android:text="@{title}"
android:textColor="@android:color/white"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
android:layout_height="wrap_content"
android:background="#757de8"
android:paddingStart="?android:attr/expandableListPreferredItemPaddingLeft"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:textColor="@android:color/white"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading
Loading