Skip to content

Commit 6e19f99

Browse files
committed
use separate textview and checkbox to avoid rtl issue
1 parent b8d314b commit 6e19f99

File tree

2 files changed

+59
-25
lines changed

2 files changed

+59
-25
lines changed

app/src/main/java/com/parishod/watomatic/adapter/InstalledAppsAdapter.kt

+30-14
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,41 @@ class InstalledAppsAdapter(private var installedAppsList: List<App>): RecyclerVi
5353
itemView.appIcon.colorFilter = cf
5454
}
5555
itemView.appName.text = app.name
56-
itemView.appName.tag = app
57-
itemView.appName.isChecked = newlyAddedApps.contains(app)
58-
itemView.appName.setOnClickListener {
56+
itemView.appNameCheckBox.tag = app
57+
itemView.appNameCheckBox.isChecked = newlyAddedApps.contains(app)
58+
itemView.appNameCheckBox.setOnClickListener{
5959
val view = it as CheckBox
6060
if(view.isChecked){
61-
if(!dbUtils.isPackageAlreadyAdded((view.tag as App).packageName)) {
62-
dbUtils.insertSupportedApp(view.tag as App)
63-
itemView.context?.let {
64-
Toast.makeText(it, "${(view.tag as App).name} added to list.", Toast.LENGTH_SHORT).show()
65-
}
66-
}
67-
61+
addToList(view.tag as App)
62+
}else{
63+
removeFromList(view.tag as App)
64+
}
65+
}
66+
itemView.setOnClickListener {
67+
val view = itemView.appNameCheckBox as CheckBox
68+
view.isChecked = !view.isChecked //Toggle checkbox
69+
if(view.isChecked){
70+
addToList(view.tag as App)
6871
}else{
69-
dbUtils.removeSupportedApp(view.tag as App)
70-
itemView.context?.let {
71-
Toast.makeText(it, "${(view.tag as App).name} removed from list.", Toast.LENGTH_SHORT).show()
72-
}
72+
removeFromList(view.tag as App)
73+
}
74+
}
75+
}
76+
77+
fun addToList(app: App){
78+
if(!dbUtils.isPackageAlreadyAdded(app.packageName)) {
79+
dbUtils.insertSupportedApp(app)
80+
itemView.context?.let {
81+
Toast.makeText(it, "${app.name} added to list.", Toast.LENGTH_SHORT).show()
7382
}
7483
}
7584
}
85+
86+
fun removeFromList(app: App){
87+
dbUtils.removeSupportedApp(app)
88+
itemView.context?.let {
89+
Toast.makeText(it, "${app.name} removed from list.", Toast.LENGTH_SHORT).show()
90+
}
91+
}
7692
}
7793
}

app/src/main/res/layout/installed_apps_list.xml

+29-11
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,52 @@
22
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
5+
android:id="@+id/parentLayout"
56
android:layout_width="match_parent"
67
android:layout_height="wrap_content"
7-
tools:context=".activity.enabledapps.EnabledAppsActivity"
8-
android:id="@+id/parentLayout">
8+
tools:context=".activity.enabledapps.EnabledAppsActivity">
99

1010
<com.google.android.material.imageview.ShapeableImageView
1111
android:id="@+id/appIcon"
1212
android:layout_width="50dp"
1313
android:layout_height="50dp"
14+
android:padding="2dp"
1415
android:src="@drawable/ic_android_default_round"
1516
app:layout_constraintBottom_toBottomOf="parent"
1617
app:layout_constraintStart_toStartOf="parent"
1718
app:layout_constraintTop_toTopOf="parent"
1819
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.App.CornerSize50Percent"
19-
app:strokeWidth="3dp"
2020
app:strokeColor="@android:color/darker_gray"
21-
android:padding="2dp"/>
21+
app:strokeWidth="3dp" />
2222

23-
<!-- Using layout direction rtl to show check box on right side, this might show odd id design view but it'll be right in device-->
24-
<CheckBox
23+
<androidx.appcompat.widget.AppCompatTextView
2524
android:id="@+id/appName"
26-
android:layout_width="match_parent"
25+
android:layout_width="0dp"
2726
android:layout_height="match_parent"
28-
android:layout_marginStart="60dp"
29-
app:layout_constraintStart_toEndOf="@+id/appIcon"
27+
android:layout_marginStart="10dp"
28+
android:textColor="@color/black"
29+
android:textSize="18sp"
3030
app:layout_constraintBottom_toBottomOf="parent"
31+
app:layout_constraintStart_toEndOf="@+id/appIcon"
3132
app:layout_constraintTop_toTopOf="parent"
32-
android:layoutDirection="rtl"
33-
/>
33+
app:layout_constraintEnd_toStartOf="@+id/guideline3"/>
34+
35+
<androidx.constraintlayout.widget.Guideline
36+
android:id="@+id/guideline3"
37+
android:layout_width="wrap_content"
38+
android:layout_height="wrap_content"
39+
android:orientation="vertical"
40+
app:layout_constraintGuide_percent="0.9"
41+
app:layout_constraintGuide_begin="20dp" />
42+
43+
<CheckBox
44+
android:id="@+id/appNameCheckBox"
45+
android:layout_width="wrap_content"
46+
android:layout_height="match_parent"
47+
android:layout_marginStart="5dp"
48+
app:layout_constraintBottom_toBottomOf="parent"
49+
app:layout_constraintEnd_toEndOf="parent"
50+
app:layout_constraintStart_toEndOf="@+id/guideline3"
51+
app:layout_constraintTop_toTopOf="parent" />
3452

3553
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)