Skip to content

Commit 66c523f

Browse files
committed
Android - #17
- Set up testing ground for Remote Layout development
1 parent bde4ee7 commit 66c523f

File tree

15 files changed

+179
-10
lines changed

15 files changed

+179
-10
lines changed

android/SmartIRHub/.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

android/SmartIRHub/app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,7 @@ dependencies {
9595
//Expandable RecyclerView
9696
implementation 'com.xwray:groupie:2.3.0'
9797
implementation 'com.xwray:groupie-databinding:2.3.0'
98+
99+
//Potential Remote Layout Base
100+
implementation 'com.ernestoyaquello.dragdropswiperecyclerview:drag-drop-swipe-recyclerview:0.4.1'
98101
}

android/SmartIRHub/app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
android:roundIcon="@mipmap/ic_launcher_round"
1212
android:supportsRtl="true"
1313
android:theme="@style/AppTheme">
14+
<activity android:name="._tests.dev_playground.remote_layout.TestRemoteLayout">
15+
</activity>
1416
<activity android:name=".create_command.CC_ChooseIrSignalActivity">
1517
</activity>
1618
<activity android:name=".create_command.CC_ChooseActionsActivity">
@@ -42,14 +44,14 @@
4244
</activity>
4345
<activity android:name=".create_button.CBWalkThroughActivity">
4446
</activity>
45-
<activity android:name=".TestViewActivity">
47+
<activity android:name="._tests.dev_playground.misc.TestViewActivity">
4648
</activity>
4749
<activity
4850
android:name=".main_view.MainViewActivity"
4951
android:label="@string/title_activity_main_view">
5052
</activity>
5153
<activity
52-
android:name=".TestActivity"
54+
android:name="._tests.dev_playground.misc.TestActivity"
5355
android:label="@string/app_name"
5456
android:theme="@style/AppTheme">
5557
</activity>

android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/TestActivity.kt renamed to android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/_tests/dev_playground/misc/TestActivity.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ms8.smartirhub.android
1+
package com.ms8.smartirhub.android._tests.dev_playground.misc
22

33
import android.Manifest
44
import android.content.pm.PackageManager
@@ -10,6 +10,7 @@ import android.util.Log
1010
import androidx.databinding.ObservableArrayMap
1111
import androidx.databinding.ObservableMap
1212
import com.google.firebase.auth.FirebaseAuth
13+
import com.ms8.smartirhub.android.R
1314
import com.ms8.smartirhub.android.databinding.TestActivityBinding
1415
import com.ms8.smartirhub.android.firebase.AuthActions
1516
import com.ms8.smartirhub.android.firebase.FirestoreActions
@@ -113,7 +114,8 @@ class TestActivity : AppCompatActivity() {
113114
ActivityCompat.requestPermissions(
114115
this,
115116
arrayOf(Manifest.permission.RECORD_AUDIO),
116-
REQ_WIFI_STATE)
117+
REQ_WIFI_STATE
118+
)
117119
}
118120

119121
private fun printUserToken() {

android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/TestViewActivity.kt renamed to android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/_tests/dev_playground/misc/TestViewActivity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
package com.ms8.smartirhub.android
1+
package com.ms8.smartirhub.android._tests.dev_playground.misc
22

33
import androidx.appcompat.app.AppCompatActivity
44
import android.os.Bundle
55
import androidx.databinding.DataBindingUtil
6+
import com.ms8.smartirhub.android.R
67
import com.ms8.smartirhub.android.databinding.ACreateButtonWalkthroughBinding
78

89
class TestViewActivity : AppCompatActivity() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package com.ms8.smartirhub.android._tests.dev_playground.remote_layout
2+
3+
import android.content.Context
4+
import android.util.AttributeSet
5+
import android.util.Log
6+
import android.view.View
7+
import android.widget.TextView
8+
import androidx.recyclerview.widget.StaggeredGridLayoutManager
9+
import androidx.recyclerview.widget.StaggeredGridLayoutManager.GAP_HANDLING_NONE
10+
import com.ernestoyaquello.dragdropswiperecyclerview.DragDropSwipeAdapter
11+
import com.ernestoyaquello.dragdropswiperecyclerview.DragDropSwipeRecyclerView
12+
import com.ms8.smartirhub.android.R
13+
import com.ms8.smartirhub.android._tests.dev_playground.remote_layout.layout_manager.RemoteLayoutManager
14+
import com.ms8.smartirhub.android.models.firestore.RemoteProfile
15+
16+
class RemoteLayout(
17+
context : Context,
18+
attributeSet : AttributeSet? = null
19+
) : DragDropSwipeRecyclerView(context, attributeSet) {
20+
21+
var widthCount: Int = 4
22+
set(value) {
23+
field = value
24+
layoutManager = getRemoteLayoutManager()
25+
adapter = getRemoteAdapter()
26+
}
27+
28+
var remoteProfile: RemoteProfile? = null
29+
set(value) {
30+
field = value
31+
(adapter as RemoteLayoutAdapter?)?.apply {
32+
dataSet = field?.buttons?.toList() ?: emptyList()
33+
notifyDataSetChanged()
34+
}
35+
}
36+
37+
private fun getRemoteAdapter(): RemoteLayoutAdapter {
38+
return RemoteLayoutAdapter(remoteProfile?.buttons?.toList() ?: emptyList())
39+
.apply {
40+
remoteProperties = object : RemoteLayoutAdapter.RemoteLayoutProperties {
41+
override fun getWidth() = width
42+
}
43+
}
44+
}
45+
46+
private fun getRemoteLayoutManager() : RemoteLayoutManager {
47+
return RemoteLayoutManager(widthCount, VERTICAL or HORIZONTAL)
48+
.apply {
49+
gapStrategy = GAP_HANDLING_NONE
50+
}
51+
}
52+
53+
init {
54+
orientation = ListOrientation.GRID_LIST_WITH_HORIZONTAL_SWIPING
55+
orientation?.removeSwipeDirectionFlag(ListOrientation.DirectionFlag.LEFT)
56+
orientation?.removeSwipeDirectionFlag(ListOrientation.DirectionFlag.RIGHT)
57+
layoutManager = getRemoteLayoutManager()
58+
itemLayoutId = R.layout.v_rmt_btn_base
59+
adapter = getRemoteAdapter()
60+
}
61+
62+
class RemoteLayoutAdapter(dataSet: List<RemoteProfile.Button> = emptyList())
63+
: DragDropSwipeAdapter<RemoteProfile.Button, RemoteLayoutAdapter.ViewHolder>(dataSet) {
64+
65+
var remoteProperties : RemoteLayoutProperties? = null
66+
67+
override fun getViewHolder(itemView: View): ViewHolder = ViewHolder(itemView)
68+
69+
override fun onBindViewHolder(item: RemoteProfile.Button, viewHolder: ViewHolder, position: Int) {
70+
viewHolder.innerView.text = item.name
71+
when (position) {
72+
2,6,8 -> {
73+
remoteProperties?.getWidth()?.let {
74+
val layoutParams = viewHolder.innerView.layoutParams
75+
layoutParams.width = it/3
76+
layoutParams.height = it/2
77+
viewHolder.itemView.layoutParams = layoutParams
78+
viewHolder.itemView.invalidate()
79+
}
80+
}
81+
}
82+
}
83+
84+
override fun getViewToTouchToStartDraggingItem(
85+
item: RemoteProfile.Button,
86+
viewHolder: ViewHolder,
87+
position: Int
88+
): View? {
89+
return null
90+
}
91+
92+
interface RemoteLayoutProperties {
93+
fun getWidth() : Int
94+
}
95+
96+
class ViewHolder(itemView: View) : DragDropSwipeAdapter.ViewHolder(itemView) {
97+
val innerView: TextView = itemView.findViewById(R.id.btnRmtInnerView)
98+
}
99+
}
100+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.ms8.smartirhub.android._tests.dev_playground.remote_layout
2+
3+
import androidx.appcompat.app.AppCompatActivity
4+
import android.os.Bundle
5+
import com.ms8.smartirhub.android.R
6+
import com.ms8.smartirhub.android.models.firestore.RemoteProfile
7+
import kotlinx.android.synthetic.main.test__remote_layout.*
8+
9+
class TestRemoteLayout : AppCompatActivity() {
10+
override fun onCreate(savedInstanceState: Bundle?) {
11+
super.onCreate(savedInstanceState)
12+
setContentView(R.layout.test__remote_layout)
13+
14+
remoteLayout.remoteProfile = RemoteProfile()
15+
.apply {
16+
for (i in 0 until 19)
17+
buttons.add(RemoteProfile.Button()
18+
.apply {
19+
name = "Button $i"
20+
}
21+
)
22+
}
23+
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.ms8.smartirhub.android._tests.dev_playground.remote_layout.layout_manager;
2+
3+
public class RemoteAdapterHelper {
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.ms8.smartirhub.android._tests.dev_playground.remote_layout.layout_manager;
2+
3+
public class RemoteLayoutManager {
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.ms8.smartirhub.android._tests.dev_playground.remote_layout.layout_manager;
2+
3+
public class RemoteLayoutState {
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.ms8.smartirhub.android._tests.dev_playground.remote_layout.layout_manager;
2+
3+
public class RemoteOpReorderer {
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.ms8.smartirhub.android._tests.dev_playground.remote_layout.layout_manager;
2+
3+
public class RemoteScrollbarHelper {
4+
}

android/SmartIRHub/app/src/main/java/com/ms8/smartirhub/android/splash/SplashActivity3.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import com.google.firebase.firestore.FirebaseFirestoreException
2929
import com.google.firebase.firestore.FirebaseFirestoreSettings
3030
import com.google.firebase.firestore.QuerySnapshot
3131
import com.ms8.smartirhub.android.R
32+
import com.ms8.smartirhub.android._tests.dev_playground.remote_layout.TestRemoteLayout
3233
import com.ms8.smartirhub.android.models.firestore.Group
3334
import com.ms8.smartirhub.android.models.firestore.User
3435
import com.ms8.smartirhub.android.database.LocalData
@@ -653,7 +654,7 @@ private fun moveLogoUp(animate: Boolean) {
653654
val groupSize = LocalData.user?.groups?.size ?: -1
654655
if (LocalData.user != null && groupSize == LocalData.groups.size) {
655656
Log.d("UserGroupListener", "Done fetching user groups... (${LocalData.user!!.groups.size} == ${LocalData.groups.size}")
656-
context?.startActivity(Intent(context, MainViewActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
657+
context?.startActivity(Intent(context, TestRemoteLayout::class.java).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
657658
context?.finish()
658659
}
659660
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent">
6+
7+
<com.ms8.smartirhub.android._tests.dev_playground.remote_layout.RemoteLayout
8+
android:id="@+id/remoteLayout"
9+
android:layout_width="match_parent"
10+
android:layout_height="match_parent"/>
11+
12+
</LinearLayout>

android/SmartIRHub/app/src/main/res/values/strings.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@
118118
<string name="begin_learning_title">Tap \"Start Listening\" to begin recording an IR signal</string>
119119
<string name="tips_title">Tips:</string>
120120
<string name="start_listening">Start Listening</string>
121-
<string name="learning_tips_desc">Tap \"Start Listening\", then point your remote at the IR SmartHub and press the button you wish to learn.
122-
After a successful pairing, you can ensure the IR signal was correctly learned by tapping \"Test Signal\". If something went wrong, you can try again by tapping the \"Retry\" button.
121+
<string name="learning_tips_desc">Tap \"Start Listening\", then point your remote at the IR SmartHub and press the
122+
button you wish to learn.
123+
After a successful pairing, you can ensure the IR signal was correctly learned by tapping \"Test Signal\". If
124+
something went wrong, you can try again by tapping the \"Retry\" button.
123125
</string>
124126
<string name="learned_signal_info_title">Learned Signal:</string>
125127
<string name="signal_type_title">Signal Type:</string>
@@ -140,7 +142,8 @@
140142
hub and please try again.
141143
</string>
142144
<string name="err_unknown_sig_title">Error (Code: 800)</string>
143-
<string name="err_unknown_sig_desc">Something went wrong while listening for an IR signal. Please try again.</string>
145+
<string name="err_unknown_sig_desc">Something went wrong while listening for an IR signal. Please try again.
146+
</string>
144147
<string name="save">Save</string>
145148
<string name="help_name_sig_desc">Try describing what the signal does in 1-3 words. \n\nFor example: If this signal
146149
increases the volume of a TV, try naming it TV VOL UP.

0 commit comments

Comments
 (0)