Browse Source

sensors fragment; pause on pause; play on resume

tags/0.0.5
Robin Thoni 8 years ago
parent
commit
211ee1a082

+ 1
- 1
app/src/main/java/com/rthoni/camotion/business/SensorsBusiness.java View File

@@ -16,7 +16,7 @@ public class SensorsBusiness extends LuBusinessManager {
16 16
         return SensorsDataAccess.getAll(config, page, perPage);
17 17
     }
18 18
 
19
-    public static LuPromise<SensorValueDbo> getImage(LuDataAccessConfigDbo config, SensorDbo sensor)
19
+    public static LuPromise<SensorValueDbo> getValue(LuDataAccessConfigDbo config, SensorDbo sensor)
20 20
     {
21 21
         return SensorsDataAccess.getValue(config, sensor.getId());
22 22
     }

+ 3
- 2
app/src/main/java/com/rthoni/camotion/ui/MainActivity.java View File

@@ -24,6 +24,7 @@ import com.rthoni.camotion.ui.dialogs.LoginDialog;
24 24
 import com.rthoni.camotion.ui.fragments.CamerasFragment;
25 25
 import com.rthoni.camotion.ui.fragments.CamotionFragment;
26 26
 import com.rthoni.camotion.ui.fragments.DefaultFragment;
27
+import com.rthoni.camotion.ui.fragments.SensorsFragment;
27 28
 
28 29
 import java.util.List;
29 30
 
@@ -141,9 +142,9 @@ public class MainActivity extends AppCompatActivity
141 142
         CamotionFragment fragment;
142 143
         if (view == R.id.nav_cameras) {
143 144
             fragment = new CamerasFragment();
144
-        } /*else if (view == R.id.nav_sensors) {
145
+        } else if (view == R.id.nav_sensors) {
145 146
             fragment = new SensorsFragment();
146
-        } else if (view == R.id.nav_commands) {
147
+        } /*else if (view == R.id.nav_commands) {
147 148
             fragment = new CommandsFragment();
148 149
         } else if (view == -1) {
149 150
             fragment = new DefaultFragment();

+ 20
- 4
app/src/main/java/com/rthoni/camotion/ui/fragments/CamerasFragment.java View File

@@ -1,7 +1,5 @@
1 1
 package com.rthoni.camotion.ui.fragments;
2 2
 
3
-import android.view.View;
4
-
5 3
 import com.luticate.utils.business.LuPromise;
6 4
 import com.luticate.utils.dbo.LuMultipleDbo;
7 5
 import com.rthoni.camotion.business.CamerasBusiness;
@@ -12,7 +10,7 @@ import com.rthoni.camotion.ui.views.CameraView;
12 10
  *
13 11
  * Created by robin on 11/29/15.
14 12
  */
15
-public class CamerasFragment extends CamotionFragment<CameraDbo> {
13
+public class CamerasFragment extends CamotionFragment<CameraDbo, CameraView> {
16 14
 
17 15
     @Override
18 16
     protected LuPromise<LuMultipleDbo<CameraDbo>> getLoadPagePromise(int page, int perPage, String query) {
@@ -26,7 +24,25 @@ public class CamerasFragment extends CamotionFragment<CameraDbo> {
26 24
     }
27 25
 
28 26
     @Override
29
-    protected View getDboView(CameraDbo camera) {
27
+    public void onPause() {
28
+        super.onPause();
29
+        for (CameraView view : _views)
30
+        {
31
+            view.pause();
32
+        }
33
+    }
34
+
35
+    @Override
36
+    public void onResume() {
37
+        super.onResume();
38
+        for (CameraView view : _views)
39
+        {
40
+            view.play();
41
+        }
42
+    }
43
+
44
+    @Override
45
+    protected CameraView getDboView(CameraDbo camera) {
30 46
         CameraView imageView = new CameraView(getActivity());
31 47
         imageView.setCamotionDbo(_fullLoginDbo, _currentLocation);
32 48
         imageView.setCamera(camera);

+ 3
- 1
app/src/main/java/com/rthoni/camotion/ui/fragments/CamotionFragment.java View File

@@ -1,5 +1,7 @@
1 1
 package com.rthoni.camotion.ui.fragments;
2 2
 
3
+import android.view.View;
4
+
3 5
 import com.luticate.auth.dbo.LuFullLoginDbo;
4 6
 import com.luticate.utils.dbo.LuDbo;
5 7
 import com.luticate.utils.ui.fragments.ViewPaginationFragment;
@@ -8,7 +10,7 @@ import com.rthoni.camotion.dbo.LocationDbo;
8 10
 /**
9 11
  * Created by robin on 12/3/15.
10 12
  */
11
-public abstract class CamotionFragment<Dbo extends LuDbo> extends ViewPaginationFragment<Dbo> {
13
+public abstract class CamotionFragment<Dbo extends LuDbo, DboView extends View> extends ViewPaginationFragment<Dbo, DboView> {
12 14
     protected LuFullLoginDbo _fullLoginDbo = null;
13 15
     protected LocationDbo _currentLocation = null;
14 16
 

+ 55
- 0
app/src/main/java/com/rthoni/camotion/ui/fragments/SensorsFragment.java View File

@@ -0,0 +1,55 @@
1
+package com.rthoni.camotion.ui.fragments;
2
+
3
+import com.luticate.utils.business.LuPromise;
4
+import com.luticate.utils.dbo.LuMultipleDbo;
5
+import com.rthoni.camotion.business.CamerasBusiness;
6
+import com.rthoni.camotion.business.SensorsBusiness;
7
+import com.rthoni.camotion.dbo.CameraDbo;
8
+import com.rthoni.camotion.dbo.SensorDbo;
9
+import com.rthoni.camotion.ui.views.CameraView;
10
+import com.rthoni.camotion.ui.views.SensorView;
11
+
12
+/**
13
+ *
14
+ * Created by robin on 11/29/15.
15
+ */
16
+public class SensorsFragment extends CamotionFragment<SensorDbo, SensorView> {
17
+
18
+    @Override
19
+    protected LuPromise<LuMultipleDbo<SensorDbo>> getLoadPagePromise(int page, int perPage, String query) {
20
+        return SensorsBusiness.getAll(_currentLocation.getConfig(_fullLoginDbo.getLoginDbo()), page, perPage)
21
+                .map(new LuPromise.LuConverter<SensorDbo.MultipleSensorDbo, LuMultipleDbo<SensorDbo>>() {
22
+                    @Override
23
+                    public LuMultipleDbo<SensorDbo> convert(SensorDbo.MultipleSensorDbo data) {
24
+                        return data;
25
+                    }
26
+                });
27
+    }
28
+
29
+    @Override
30
+    public void onPause() {
31
+        super.onPause();
32
+        for (SensorView view : _views)
33
+        {
34
+            view.pause();
35
+        }
36
+    }
37
+
38
+    @Override
39
+    public void onResume() {
40
+        super.onResume();
41
+        for (SensorView view : _views)
42
+        {
43
+            view.play();
44
+        }
45
+    }
46
+
47
+    @Override
48
+    protected SensorView getDboView(SensorDbo sensor) {
49
+        SensorView imageView = new SensorView(getActivity());
50
+        imageView.setCamotionDbo(_fullLoginDbo, _currentLocation);
51
+        imageView.setSensor(sensor);
52
+        imageView.play();
53
+        return imageView;
54
+    }
55
+}

+ 13
- 12
app/src/main/java/com/rthoni/camotion/ui/views/SensorView.java View File

@@ -13,9 +13,11 @@ import com.luticate.auth.dbo.LuFullLoginDbo;
13 13
 import com.luticate.utils.business.LuPromise;
14 14
 import com.rthoni.camotion.R;
15 15
 import com.rthoni.camotion.business.CamerasBusiness;
16
+import com.rthoni.camotion.business.SensorsBusiness;
16 17
 import com.rthoni.camotion.dbo.CameraDbo;
17 18
 import com.rthoni.camotion.dbo.LocationDbo;
18 19
 import com.rthoni.camotion.dbo.SensorDbo;
20
+import com.rthoni.camotion.dbo.SensorValueDbo;
19 21
 
20 22
 /**
21 23
  * Created by robin on 12/4/15.
@@ -26,12 +28,12 @@ public class SensorView extends RelativeLayout {
26 28
 
27 29
     private SensorDbo _sensor;
28 30
 
29
-    private ImageView _imageView;
31
+    private TextView _textView;
30 32
 
31 33
     private int _interval = 500;
32 34
 
33 35
     private boolean _playing = false;
34
-    private LuPromise<Bitmap> _promise = null;
36
+    private LuPromise<SensorValueDbo> _promise = null;
35 37
 
36 38
     public void setCamotionDbo(LuFullLoginDbo fullLoginDbo, LocationDbo currentLocation)
37 39
     {
@@ -46,9 +48,10 @@ public class SensorView extends RelativeLayout {
46 48
     public void setSensor(SensorDbo sensor) {
47 49
         _sensor = sensor;
48 50
 
49
-        /*((TextView)findViewById(R.id.textViewName)).setText(_sensor.getName());
51
+        ((TextView)findViewById(R.id.textViewName)).setText(_sensor.getName());
52
+        _textView = (TextView)findViewById(R.id.textViewValue);
50 53
 
51
-        findViewById(R.id.imageViewPause).setOnClickListener(new OnClickListener() {
54
+        /*findViewById(R.id.imageViewPause).setOnClickListener(new OnClickListener() {
52 55
             @Override
53 56
             public void onClick(View v) {
54 57
                 togglePlay();
@@ -82,7 +85,7 @@ public class SensorView extends RelativeLayout {
82 85
 
83 86
     private void init()
84 87
     {
85
-        inflate(getContext(), R.layout.sensors_layout, this);
88
+        inflate(getContext(), R.layout.sensor_view, this);
86 89
     }
87 90
 
88 91
     public void togglePlay()
@@ -100,13 +103,11 @@ public class SensorView extends RelativeLayout {
100 103
     public void pause()
101 104
     {
102 105
         _playing = false;
103
-        findViewById(R.id.imageViewPause).setVisibility(VISIBLE);
104 106
     }
105 107
 
106 108
     public void play()
107 109
     {
108 110
         _playing = true;
109
-        findViewById(R.id.imageViewPause).setVisibility(GONE);
110 111
         if (_promise == null || _promise.getStatus() != LuPromise.LuPromiseStatus.Running) {
111 112
             _play();
112 113
         }
@@ -114,12 +115,12 @@ public class SensorView extends RelativeLayout {
114 115
 
115 116
     private void _play()
116 117
     {
117
-        /*_promise = CamerasBusiness.getImage(_currentLocation.getConfig(_fullLoginDbo.getLoginDbo()), _camera)
118
-                .then(new LuPromise.LuConsumer<Bitmap>() {
118
+        _promise = SensorsBusiness.getValue(_currentLocation.getConfig(_fullLoginDbo.getLoginDbo()), _sensor)
119
+                .then(new LuPromise.LuConsumer<SensorValueDbo>() {
119 120
                     @Override
120
-                    public void execute(Bitmap image) {
121
+                    public void execute(SensorValueDbo value) {
121 122
                         if (_playing) {
122
-                            _imageView.setImageBitmap(image);
123
+                            _textView.setText(String.valueOf(value.getValue()));
123 124
                             Handler h = new Handler();
124 125
                             h.postDelayed(new Runnable() {
125 126
                                 @Override
@@ -134,6 +135,6 @@ public class SensorView extends RelativeLayout {
134 135
                     public void execute(LuPromise.LuPromiseError data) {
135 136
 
136 137
                     }
137
-                });*/
138
+                });
138 139
     }
139 140
 }

+ 0
- 48
app/src/main/res/layout/cameras_layout.xml View File

@@ -1,48 +0,0 @@
1
-<?xml version="1.0" encoding="utf-8"?>
2
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
-              android:layout_width="match_parent"
4
-              android:layout_height="match_parent"
5
-              android:orientation="vertical" >
6
-
7
-    <!-- Loading progress -->
8
-
9
-    <LinearLayout
10
-        android:id="@+id/loadStatus"
11
-        android:layout_width="wrap_content"
12
-        android:layout_height="wrap_content"
13
-        android:layout_gravity="center"
14
-        android:gravity="center_horizontal"
15
-        android:orientation="vertical"
16
-        android:visibility="gone" >
17
-
18
-        <ProgressBar
19
-            style="?android:attr/progressBarStyleLarge"
20
-            android:layout_width="wrap_content"
21
-            android:layout_height="wrap_content"
22
-            android:layout_marginBottom="8dp" />
23
-
24
-        <TextView
25
-            android:id="@+id/loading_status_message"
26
-            android:layout_width="wrap_content"
27
-            android:layout_height="wrap_content"
28
-            android:layout_marginBottom="16dp"
29
-            android:text="@string/loading"
30
-            android:textAppearance="?android:attr/textAppearanceMedium" />
31
-    </LinearLayout>
32
-
33
-    <!-- Layout -->
34
-
35
-    <ScrollView
36
-        android:id="@+id/mainScrollView"
37
-        android:layout_width="match_parent"
38
-        android:layout_height="0dp"
39
-        android:layout_weight="0.33" >
40
-
41
-        <LinearLayout
42
-            android:id="@+id/imagesLayoutScrollView"
43
-            android:layout_width="wrap_content"
44
-            android:layout_height="match_parent"
45
-            android:orientation="vertical" >
46
-        </LinearLayout>
47
-    </ScrollView>
48
-</LinearLayout>

+ 0
- 96
app/src/main/res/layout/commands_layout.xml View File

@@ -1,96 +0,0 @@
1
-<?xml version="1.0" encoding="utf-8"?>
2
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
-              android:layout_width="match_parent"
4
-              android:layout_height="match_parent"
5
-              android:orientation="vertical" >
6
-
7
-    <!-- Loading progress -->
8
-
9
-    <LinearLayout
10
-        android:id="@+id/loadStatus"
11
-        android:layout_width="wrap_content"
12
-        android:layout_height="wrap_content"
13
-        android:layout_gravity="center"
14
-        android:gravity="center_horizontal"
15
-        android:orientation="vertical"
16
-        android:visibility="gone" >
17
-
18
-        <ProgressBar
19
-            style="?android:attr/progressBarStyleLarge"
20
-            android:layout_width="wrap_content"
21
-            android:layout_height="wrap_content"
22
-            android:layout_marginBottom="8dp" />
23
-
24
-        <TextView
25
-            android:id="@+id/loading_status_message"
26
-            android:layout_width="wrap_content"
27
-            android:layout_height="wrap_content"
28
-            android:layout_marginBottom="16dp"
29
-            android:text="@string/loading"
30
-            android:textAppearance="?android:attr/textAppearanceMedium" />
31
-    </LinearLayout>
32
-
33
-    <!-- Layout -->
34
-
35
-    <ScrollView
36
-        android:id="@+id/mainScrollView"
37
-        android:layout_width="match_parent"
38
-        android:layout_height="0dp"
39
-        android:layout_weight="0.33" >
40
-
41
-        <LinearLayout
42
-            android:id="@+id/imagesLayoutScrollView"
43
-            android:layout_width="wrap_content"
44
-            android:layout_height="match_parent"
45
-            android:orientation="vertical" >
46
-
47
-            <ImageView
48
-                android:contentDescription="42"
49
-                android:layout_width="match_parent"
50
-                android:layout_height="wrap_content"
51
-                android:layout_margin="10px"
52
-                android:adjustViewBounds="true"
53
-                android:src="@drawable/camera_loading" />
54
-
55
-            <ImageView
56
-                android:contentDescription="42"
57
-                android:layout_width="match_parent"
58
-                android:layout_height="wrap_content"
59
-                android:layout_margin="10px"
60
-                android:adjustViewBounds="true"
61
-                android:src="@drawable/camera_loading" />
62
-
63
-            <ImageView
64
-                android:contentDescription="42"
65
-                android:layout_width="match_parent"
66
-                android:layout_height="wrap_content"
67
-                android:layout_margin="10px"
68
-                android:adjustViewBounds="true"
69
-                android:src="@drawable/camera_loading" />
70
-
71
-            <ImageView
72
-                android:contentDescription="42"
73
-                android:layout_width="match_parent"
74
-                android:layout_height="wrap_content"
75
-                android:layout_margin="10px"
76
-                android:adjustViewBounds="true"
77
-                android:src="@drawable/camera_loading" />
78
-
79
-            <ImageView
80
-                android:contentDescription="42"
81
-                android:layout_width="match_parent"
82
-                android:layout_height="wrap_content"
83
-                android:layout_margin="10px"
84
-                android:adjustViewBounds="true"
85
-                android:src="@drawable/camera_loading" />
86
-
87
-            <ImageView
88
-                android:contentDescription="42"
89
-                android:layout_width="match_parent"
90
-                android:layout_height="wrap_content"
91
-                android:layout_margin="10px"
92
-                android:adjustViewBounds="true"
93
-                android:src="@drawable/camera_loading" />
94
-        </LinearLayout>
95
-    </ScrollView>
96
-</LinearLayout>

+ 27
- 0
app/src/main/res/layout/sensor_view.xml View File

@@ -0,0 +1,27 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+              android:layout_width="match_parent"
4
+              android:layout_height="match_parent">
5
+
6
+    <TextView
7
+        android:layout_width="wrap_content"
8
+        android:layout_height="wrap_content"
9
+        android:textAppearance="?android:attr/textAppearanceMedium"
10
+        android:text=""
11
+        android:id="@+id/textViewName"
12
+        android:layout_alignParentTop="true"
13
+        android:layout_alignParentLeft="true"
14
+        android:layout_alignParentStart="true"
15
+        android:layout_toLeftOf="@+id/textViewValue"
16
+        android:layout_toStartOf="@+id/textViewValue"/>
17
+
18
+    <TextView
19
+        android:layout_width="wrap_content"
20
+        android:layout_height="wrap_content"
21
+        android:textAppearance="?android:attr/textAppearanceMedium"
22
+        android:text=""
23
+        android:id="@+id/textViewValue"
24
+        android:layout_alignParentTop="true"
25
+        android:layout_alignParentRight="true"
26
+        android:layout_alignParentEnd="true"/>
27
+</RelativeLayout>

+ 0
- 48
app/src/main/res/layout/sensors_layout.xml View File

@@ -1,48 +0,0 @@
1
-<?xml version="1.0" encoding="utf-8"?>
2
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
-              android:layout_width="match_parent"
4
-              android:layout_height="match_parent"
5
-              android:orientation="vertical" >
6
-
7
-    <!-- Loading progress -->
8
-
9
-    <LinearLayout
10
-        android:id="@+id/loadStatus"
11
-        android:layout_width="wrap_content"
12
-        android:layout_height="wrap_content"
13
-        android:layout_gravity="center"
14
-        android:gravity="center_horizontal"
15
-        android:orientation="vertical"
16
-        android:visibility="gone" >
17
-
18
-        <ProgressBar
19
-            style="?android:attr/progressBarStyleLarge"
20
-            android:layout_width="wrap_content"
21
-            android:layout_height="wrap_content"
22
-            android:layout_marginBottom="8dp" />
23
-
24
-        <TextView
25
-            android:id="@+id/loading_status_message"
26
-            android:layout_width="wrap_content"
27
-            android:layout_height="wrap_content"
28
-            android:layout_marginBottom="16dp"
29
-            android:text="@string/loading"
30
-            android:textAppearance="?android:attr/textAppearanceMedium" />
31
-    </LinearLayout>
32
-
33
-    <!-- Layout -->
34
-
35
-    <ScrollView
36
-        android:id="@+id/mainScrollView"
37
-        android:layout_width="match_parent"
38
-        android:layout_height="0dp"
39
-        android:layout_weight="0.33" >
40
-
41
-        <LinearLayout
42
-            android:id="@+id/sensorsLayoutScrollView"
43
-            android:layout_width="wrap_content"
44
-            android:layout_height="match_parent"
45
-            android:orientation="vertical" >
46
-        </LinearLayout>
47
-    </ScrollView>
48
-</LinearLayout>

+ 9
- 4
luticateutils/src/main/java/com/luticate/utils/ui/fragments/AbstractPaginationFragment.java View File

@@ -29,7 +29,7 @@ public abstract class AbstractPaginationFragment<Dbo extends LuDbo> extends Frag
29 29
 
30 30
     protected String _query = "";
31 31
 
32
-    protected LuMultipleDbo<Dbo> _items = new LuMultipleDbo<>();
32
+    protected LuMultipleDbo<Dbo> _items = null;
33 33
 
34 34
     @Override
35 35
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
@@ -48,7 +48,9 @@ public abstract class AbstractPaginationFragment<Dbo extends LuDbo> extends Frag
48 48
                 loadPage(page);
49 49
             }
50 50
         });
51
-        loadPage(_page);
51
+        if (_items == null) {
52
+            loadPage(_page);
53
+        }
52 54
     }
53 55
 
54 56
     protected void showProgress(final boolean show)
@@ -97,10 +99,13 @@ public abstract class AbstractPaginationFragment<Dbo extends LuDbo> extends Frag
97 99
     public void loadPage(final int page)
98 100
     {
99 101
         final View v = getView();
100
-        if (!isAdded() || v == null)
102
+        if (!isAdded() || v == null) {
101 103
             return;
104
+        }
102 105
         showProgress(true);
103
-        _items.setData(new Vector<Dbo>());
106
+        if (_items != null) {
107
+            _items.setData(new Vector<Dbo>());
108
+        }
104 109
         getLoadPagePromise(page, _perPage, _query).then(new LuPromise.LuConsumer<LuMultipleDbo<Dbo>>() {
105 110
             @Override
106 111
             public void execute(LuMultipleDbo<Dbo> items) {

+ 10
- 3
luticateutils/src/main/java/com/luticate/utils/ui/fragments/ViewPaginationFragment.java View File

@@ -6,10 +6,15 @@ import android.widget.LinearLayout;
6 6
 import com.luticate.utils.R;
7 7
 import com.luticate.utils.dbo.LuDbo;
8 8
 
9
+import java.util.List;
10
+import java.util.Vector;
11
+
9 12
 /**
10 13
  * Created by robin on 12/6/15.
11 14
  */
12
-public abstract class ViewPaginationFragment<Dbo extends LuDbo> extends AbstractPaginationFragment<Dbo> {
15
+public abstract class ViewPaginationFragment<Dbo extends LuDbo, DboView extends View> extends AbstractPaginationFragment<Dbo> {
16
+
17
+    protected List<DboView> _views = new Vector<>();
13 18
 
14 19
     @Override
15 20
     protected int getLoaderViewId() {
@@ -36,12 +41,14 @@ public abstract class ViewPaginationFragment<Dbo extends LuDbo> extends Abstract
36 41
         View view = getView();
37 42
         LinearLayout layout = (LinearLayout) view.findViewById(R.id.itemsLayoutScrollView);
38 43
         layout.removeAllViews();
44
+        _views.clear();
39 45
         for (Dbo item : _items.getData())
40 46
         {
41
-            View v = getDboView(item);
47
+            DboView v = getDboView(item);
42 48
             layout.addView(v);
49
+            _views.add(v);
43 50
         }
44 51
     }
45 52
 
46
-    protected abstract View getDboView(Dbo dbo);
53
+    protected abstract DboView getDboView(Dbo dbo);
47 54
 }

Loading…
Cancel
Save