ソースを参照

begin pagination fragment

tags/0.0.5
Robin Thoni 9年前
コミット
c170e8cdeb
19個のファイルの変更654行の追加226行の削除
  1. 23
    0
      app/src/main/java/com/rthoni/camotion/business/SensorsBusiness.java
  2. 29
    0
      app/src/main/java/com/rthoni/camotion/dataaccess/SensorsDataAccess.java
  3. 2
    2
      app/src/main/java/com/rthoni/camotion/dbo/CameraDbo.java
  4. 63
    0
      app/src/main/java/com/rthoni/camotion/dbo/SensorDbo.java
  5. 36
    0
      app/src/main/java/com/rthoni/camotion/dbo/SensorValueDbo.java
  6. 2
    4
      app/src/main/java/com/rthoni/camotion/ui/MainActivity.java
  7. 16
    49
      app/src/main/java/com/rthoni/camotion/ui/fragments/CamerasFragment.java
  8. 3
    51
      app/src/main/java/com/rthoni/camotion/ui/fragments/CamotionFragment.java
  9. 0
    24
      app/src/main/java/com/rthoni/camotion/ui/fragments/CommandsFragment.java
  10. 3
    18
      app/src/main/java/com/rthoni/camotion/ui/fragments/DefaultFragment.java
  11. 0
    24
      app/src/main/java/com/rthoni/camotion/ui/fragments/SensorsFragment.java
  12. 6
    0
      app/src/main/java/com/rthoni/camotion/ui/views/CameraView.java
  13. 139
    0
      app/src/main/java/com/rthoni/camotion/ui/views/SensorView.java
  14. 1
    49
      app/src/main/res/layout/sensors_layout.xml
  15. 24
    0
      luticateutils/src/main/java/com/luticate/utils/business/LuPromise.java
  16. 21
    5
      luticateutils/src/main/java/com/luticate/utils/business/LuRequest.java
  17. 161
    0
      luticateutils/src/main/java/com/luticate/utils/ui/PaginationFragment.java
  18. 42
    0
      luticateutils/src/main/java/com/luticate/utils/ui/ViewPaginationFragment.java
  19. 83
    0
      luticateutils/src/main/res/layout/view_pagination_fragment_layout.xml

+ 23
- 0
app/src/main/java/com/rthoni/camotion/business/SensorsBusiness.java ファイルの表示

@@ -0,0 +1,23 @@
1
+package com.rthoni.camotion.business;
2
+
3
+import com.luticate.utils.business.LuBusinessManager;
4
+import com.luticate.utils.business.LuPromise;
5
+import com.luticate.utils.dbo.LuDataAccessConfigDbo;
6
+import com.rthoni.camotion.dataaccess.SensorsDataAccess;
7
+import com.rthoni.camotion.dbo.SensorDbo;
8
+import com.rthoni.camotion.dbo.SensorValueDbo;
9
+
10
+/**
11
+ * Created by robin on 12/3/15.
12
+ */
13
+public class SensorsBusiness extends LuBusinessManager {
14
+    public static LuPromise<SensorDbo.MultipleSensorDbo> getAll(LuDataAccessConfigDbo config, int page, int perPage)
15
+    {
16
+        return SensorsDataAccess.getAll(config, page, perPage);
17
+    }
18
+
19
+    public static LuPromise<SensorValueDbo> getImage(LuDataAccessConfigDbo config, SensorDbo sensor)
20
+    {
21
+        return SensorsDataAccess.getValue(config, sensor.getId());
22
+    }
23
+}

+ 29
- 0
app/src/main/java/com/rthoni/camotion/dataaccess/SensorsDataAccess.java ファイルの表示

@@ -0,0 +1,29 @@
1
+package com.rthoni.camotion.dataaccess;
2
+
3
+import com.luticate.utils.business.LuPromise;
4
+import com.luticate.utils.business.LuRequest;
5
+import com.luticate.utils.dataaccess.LuDataAccess;
6
+import com.luticate.utils.dbo.LuDataAccessConfigDbo;
7
+import com.rthoni.camotion.dbo.SensorDbo;
8
+import com.rthoni.camotion.dbo.SensorValueDbo;
9
+
10
+import java.util.HashMap;
11
+
12
+/**
13
+ * Created by robin on 12/3/15.
14
+ */
15
+public class SensorsDataAccess extends LuDataAccess {
16
+
17
+    public static LuPromise<SensorDbo.MultipleSensorDbo> getAll(LuDataAccessConfigDbo config, int page, int perPage)
18
+    {
19
+        HashMap<String, String> params = new HashMap<>();
20
+        params.put("page", "" + page);
21
+        params.put("perPage", "" + perPage);
22
+        return LuRequest.get(config, SensorDbo.MultipleSensorDbo.class, "/api/sensors", params);
23
+    }
24
+
25
+    public static LuPromise<SensorValueDbo> getValue(LuDataAccessConfigDbo config, int id)
26
+    {
27
+        return LuRequest.post(config, SensorValueDbo.class, "/api/sensors/" + id + "/value");
28
+    }
29
+}

+ 2
- 2
app/src/main/java/com/rthoni/camotion/dbo/CameraDbo.java ファイルの表示

@@ -17,6 +17,8 @@ public class CameraDbo extends LuDbo {
17 17
 
18 18
     private String _name;
19 19
 
20
+    private String _description;
21
+
20 22
     public String getDescription() {
21 23
         return _description;
22 24
     }
@@ -41,8 +43,6 @@ public class CameraDbo extends LuDbo {
41 43
         _id = id;
42 44
     }
43 45
 
44
-    private String _description;
45
-
46 46
     public static class MultipleCameraDbo extends LuMultipleDbo<CameraDbo> {
47 47
     }
48 48
 

+ 63
- 0
app/src/main/java/com/rthoni/camotion/dbo/SensorDbo.java ファイルの表示

@@ -0,0 +1,63 @@
1
+package com.rthoni.camotion.dbo;
2
+
3
+import com.luticate.utils.dbo.LuDbo;
4
+import com.luticate.utils.dbo.LuMultipleDbo;
5
+
6
+import org.json.JSONException;
7
+import org.json.JSONObject;
8
+
9
+import java.util.HashMap;
10
+
11
+/**
12
+ * Created by robin on 12/4/15.
13
+ */
14
+public class SensorDbo extends LuDbo {
15
+    private int _id;
16
+
17
+    private String _name;
18
+
19
+    private String _description;
20
+
21
+    public String getDescription() {
22
+        return _description;
23
+    }
24
+
25
+    public void setDescription(String description) {
26
+        _description = description;
27
+    }
28
+
29
+    public String getName() {
30
+        return _name;
31
+    }
32
+
33
+    public void setName(String name) {
34
+        _name = name;
35
+    }
36
+
37
+    public int getId() {
38
+        return _id;
39
+    }
40
+
41
+    public void setId(int id) {
42
+        _id = id;
43
+    }
44
+
45
+    public static class MultipleSensorDbo extends LuMultipleDbo<SensorDbo> {
46
+    }
47
+
48
+    @Override
49
+    public void fromJson(JSONObject json) throws JSONException {
50
+        _id = json.getInt("Id");
51
+        _description = json.getString("Description");
52
+        _name = json.getString("Name");
53
+    }
54
+
55
+    @Override
56
+    public HashMap<String, Object> toArray() {
57
+        HashMap<String, Object> array = new HashMap<>();
58
+        array.put("Id", _id);
59
+        array.put("Description", _description);
60
+        array.put("Name", _name);
61
+        return array;
62
+    }
63
+}

+ 36
- 0
app/src/main/java/com/rthoni/camotion/dbo/SensorValueDbo.java ファイルの表示

@@ -0,0 +1,36 @@
1
+package com.rthoni.camotion.dbo;
2
+
3
+import com.luticate.utils.dbo.LuDbo;
4
+
5
+import org.json.JSONException;
6
+import org.json.JSONObject;
7
+
8
+import java.util.HashMap;
9
+
10
+/**
11
+ * Created by robin on 12/4/15.
12
+ */
13
+public class SensorValueDbo extends LuDbo {
14
+
15
+    private int _value;
16
+
17
+    public int getValue() {
18
+        return _value;
19
+    }
20
+
21
+    public void setValue(int value) {
22
+        _value = value;
23
+    }
24
+
25
+    @Override
26
+    public void fromJson(JSONObject json) throws JSONException {
27
+        _value = json.getInt("Value");
28
+    }
29
+
30
+    @Override
31
+    public HashMap<String, Object> toArray() {
32
+        HashMap<String, Object> array = new HashMap<>();
33
+        array.put("Value", _value);
34
+        return array;
35
+    }
36
+}

+ 2
- 4
app/src/main/java/com/rthoni/camotion/ui/MainActivity.java ファイルの表示

@@ -23,9 +23,7 @@ import com.rthoni.camotion.dbo.LocationDbo;
23 23
 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
-import com.rthoni.camotion.ui.fragments.CommandsFragment;
27 26
 import com.rthoni.camotion.ui.fragments.DefaultFragment;
28
-import com.rthoni.camotion.ui.fragments.SensorsFragment;
29 27
 
30 28
 import java.util.List;
31 29
 
@@ -143,13 +141,13 @@ public class MainActivity extends AppCompatActivity
143 141
         CamotionFragment fragment;
144 142
         if (view == R.id.nav_cameras) {
145 143
             fragment = new CamerasFragment();
146
-        } else if (view == R.id.nav_sensors) {
144
+        } /*else if (view == R.id.nav_sensors) {
147 145
             fragment = new SensorsFragment();
148 146
         } else if (view == R.id.nav_commands) {
149 147
             fragment = new CommandsFragment();
150 148
         } else if (view == -1) {
151 149
             fragment = new DefaultFragment();
152
-        } else {
150
+        } */else {
153 151
             return;
154 152
         }
155 153
         fragment.setCamotionDbo(_fullLoginDbo, _currentLocation);

+ 16
- 49
app/src/main/java/com/rthoni/camotion/ui/fragments/CamerasFragment.java ファイルの表示

@@ -1,15 +1,9 @@
1 1
 package com.rthoni.camotion.ui.fragments;
2 2
 
3
-import android.os.Bundle;
4
-import android.view.LayoutInflater;
5 3
 import android.view.View;
6
-import android.view.ViewGroup;
7
-import android.widget.ImageView;
8
-import android.widget.LinearLayout;
9
-import android.widget.Toast;
10 4
 
11 5
 import com.luticate.utils.business.LuPromise;
12
-import com.rthoni.camotion.R;
6
+import com.luticate.utils.dbo.LuMultipleDbo;
13 7
 import com.rthoni.camotion.business.CamerasBusiness;
14 8
 import com.rthoni.camotion.dbo.CameraDbo;
15 9
 import com.rthoni.camotion.ui.views.CameraView;
@@ -18,52 +12,25 @@ import com.rthoni.camotion.ui.views.CameraView;
18 12
  *
19 13
  * Created by robin on 11/29/15.
20 14
  */
21
-public class CamerasFragment extends CamotionFragment {
22
-
23
-    private CameraDbo.MultipleCameraDbo _cameras = null;
24
-
25
-    private int _page = 0;
26
-
27
-    private int _perPage = 6;
15
+public class CamerasFragment extends CamotionFragment<CameraDbo> {
28 16
 
29 17
     @Override
30
-    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
31
-    {
32
-        View rootView = inflater.inflate(R.layout.cameras_layout, container, false);
33
-        return rootView;
18
+    protected LuPromise<LuMultipleDbo<CameraDbo>> getLoadPagePromise(int page, int perPage, String query) {
19
+        return CamerasBusiness.getAll(_currentLocation.getConfig(_fullLoginDbo.getLoginDbo()), page, perPage)
20
+                .map(new LuPromise.LuConverter<CameraDbo.MultipleCameraDbo, LuMultipleDbo<CameraDbo>>() {
21
+                    @Override
22
+                    public LuMultipleDbo<CameraDbo> convert(CameraDbo.MultipleCameraDbo data) {
23
+                        return data;
24
+                    }
25
+                });
34 26
     }
35 27
 
36 28
     @Override
37
-    public void onResume() {
38
-        super.onResume();
39
-        if (_cameras == null) {
40
-            showProgress(true);
41
-            CamerasBusiness.getAll(_currentLocation.getConfig(_fullLoginDbo.getLoginDbo()), _page, _perPage)
42
-                    .then(new LuPromise.LuConsumer<CameraDbo.MultipleCameraDbo>() {
43
-                        @Override
44
-                        public void execute(CameraDbo.MultipleCameraDbo data) {
45
-                            _cameras = data;
46
-
47
-                            LinearLayout layout = (LinearLayout) getView().findViewById(R.id.imagesLayoutScrollView);
48
-
49
-                            for (CameraDbo camera : _cameras.getData())
50
-                            {
51
-                                CameraView imageView = new CameraView(getActivity());
52
-                                imageView.setCamotionDbo(_fullLoginDbo, _currentLocation);
53
-                                imageView.setCamera(camera);
54
-                                imageView.togglePlay();
55
-                                layout.addView(imageView);
56
-                            }
57
-
58
-                            showProgress(false);
59
-                        }
60
-                    }, new LuPromise.LuConsumer<LuPromise.LuPromiseError>() {
61
-                        @Override
62
-                        public void execute(LuPromise.LuPromiseError error) {
63
-                            Toast.makeText(getActivity(), error.toString(), Toast.LENGTH_LONG).show();
64
-                            showProgress(false);
65
-                        }
66
-                    });
67
-        }
29
+    protected View getDboView(CameraDbo camera) {
30
+        CameraView imageView = new CameraView(getActivity());
31
+        imageView.setCamotionDbo(_fullLoginDbo, _currentLocation);
32
+        imageView.setCamera(camera);
33
+        imageView.play();
34
+        return imageView;
68 35
     }
69 36
 }

+ 3
- 51
app/src/main/java/com/rthoni/camotion/ui/fragments/CamotionFragment.java ファイルの表示

@@ -1,19 +1,14 @@
1 1
 package com.rthoni.camotion.ui.fragments;
2 2
 
3
-import android.animation.Animator;
4
-import android.animation.AnimatorListenerAdapter;
5
-import android.app.Fragment;
6
-import android.os.Build;
7
-import android.view.View;
8
-
9 3
 import com.luticate.auth.dbo.LuFullLoginDbo;
10
-import com.rthoni.camotion.R;
4
+import com.luticate.utils.dbo.LuDbo;
5
+import com.luticate.utils.ui.ViewPaginationFragment;
11 6
 import com.rthoni.camotion.dbo.LocationDbo;
12 7
 
13 8
 /**
14 9
  * Created by robin on 12/3/15.
15 10
  */
16
-public abstract class CamotionFragment extends Fragment {
11
+public abstract class CamotionFragment<Dbo extends LuDbo> extends ViewPaginationFragment<Dbo> {
17 12
     protected LuFullLoginDbo _fullLoginDbo = null;
18 13
     protected LocationDbo _currentLocation = null;
19 14
 
@@ -22,47 +17,4 @@ public abstract class CamotionFragment extends Fragment {
22 17
         _fullLoginDbo = fullLoginDbo;
23 18
         _currentLocation = currentLocation;
24 19
     }
25
-
26
-    protected void showProgress(final boolean show)
27
-    {
28
-        View v = getView();
29
-        if (!isAdded() || v == null)
30
-            return;
31
-
32
-        final View imagesScrollView = v.findViewById(R.id.mainScrollView);
33
-        final View loadingView = v.findViewById(R.id.loadStatus);
34
-
35
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
36
-        {
37
-            int shortAnimTime =
38
-                    getResources().getInteger(android.R.integer.config_shortAnimTime);
39
-
40
-            loadingView.setVisibility(View.VISIBLE);
41
-            loadingView.animate().setDuration(shortAnimTime).alpha(show ? 1 : 0)
42
-                    .setListener(new AnimatorListenerAdapter()
43
-                    {
44
-                        @Override
45
-                        public void onAnimationEnd(Animator animation)
46
-                        {
47
-                            loadingView.setVisibility(show ? View.VISIBLE : View.GONE);
48
-                        }
49
-                    });
50
-
51
-            imagesScrollView.setVisibility(View.VISIBLE);
52
-            imagesScrollView.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1)
53
-                    .setListener(new AnimatorListenerAdapter()
54
-                    {
55
-                        @Override
56
-                        public void onAnimationEnd(Animator animation)
57
-                        {
58
-                            imagesScrollView.setVisibility(show ? View.GONE : View.VISIBLE);
59
-                        }
60
-                    });
61
-        }
62
-        else
63
-        {
64
-            loadingView.setVisibility(show ? View.VISIBLE : View.GONE);
65
-            imagesScrollView.setVisibility(show ? View.GONE : View.VISIBLE);
66
-        }
67
-    }
68 20
 }

+ 0
- 24
app/src/main/java/com/rthoni/camotion/ui/fragments/CommandsFragment.java ファイルの表示

@@ -1,24 +0,0 @@
1
-package com.rthoni.camotion.ui.fragments;
2
-
3
-import android.os.Bundle;
4
-import android.view.LayoutInflater;
5
-import android.view.View;
6
-import android.view.ViewGroup;
7
-
8
-import com.rthoni.camotion.R;
9
-
10
-/**
11
- *
12
- * Created by robin on 11/29/15.
13
- */
14
-public class CommandsFragment extends CamotionFragment {
15
-
16
-    @Override
17
-    public View onCreateView(LayoutInflater inflater, ViewGroup container,
18
-                             Bundle savedInstanceState)
19
-    {
20
-        Bundle args = getArguments();
21
-        View rootView = inflater.inflate(R.layout.commands_layout, container, false);
22
-        return rootView;
23
-    }
24
-}

+ 3
- 18
app/src/main/java/com/rthoni/camotion/ui/fragments/DefaultFragment.java ファイルの表示

@@ -1,24 +1,9 @@
1 1
 package com.rthoni.camotion.ui.fragments;
2 2
 
3
-import android.os.Bundle;
4
-import android.view.LayoutInflater;
5
-import android.view.View;
6
-import android.view.ViewGroup;
7
-
8
-import com.rthoni.camotion.R;
3
+import android.app.Fragment;
9 4
 
10 5
 /**
11
- *
12
- * Created by robin on 11/29/15.
6
+ * Created by robin on 12/6/15.
13 7
  */
14
-public class DefaultFragment extends CamotionFragment {
15
-
16
-    @Override
17
-    public View onCreateView(LayoutInflater inflater, ViewGroup container,
18
-                             Bundle savedInstanceState)
19
-    {
20
-        Bundle args = getArguments();
21
-        View rootView = inflater.inflate(R.layout.default_layout, container, false);
22
-        return rootView;
23
-    }
8
+public class DefaultFragment extends Fragment {
24 9
 }

+ 0
- 24
app/src/main/java/com/rthoni/camotion/ui/fragments/SensorsFragment.java ファイルの表示

@@ -1,24 +0,0 @@
1
-package com.rthoni.camotion.ui.fragments;
2
-
3
-import android.os.Bundle;
4
-import android.view.LayoutInflater;
5
-import android.view.View;
6
-import android.view.ViewGroup;
7
-
8
-import com.rthoni.camotion.R;
9
-
10
-/**
11
- *
12
- * Created by robin on 11/29/15.
13
- */
14
-public class SensorsFragment extends CamotionFragment {
15
-
16
-    @Override
17
-    public View onCreateView(LayoutInflater inflater, ViewGroup container,
18
-                             Bundle savedInstanceState)
19
-    {
20
-        Bundle args = getArguments();
21
-        View rootView = inflater.inflate(R.layout.sensors_layout, container, false);
22
-        return rootView;
23
-    }
24
-}

+ 6
- 0
app/src/main/java/com/rthoni/camotion/ui/views/CameraView.java ファイルの表示

@@ -135,4 +135,10 @@ public class CameraView extends RelativeLayout {
135 135
                     }
136 136
                 });
137 137
     }
138
+
139
+    @Override
140
+    protected void onDetachedFromWindow() {
141
+        super.onDetachedFromWindow();
142
+        pause();
143
+    }
138 144
 }

+ 139
- 0
app/src/main/java/com/rthoni/camotion/ui/views/SensorView.java ファイルの表示

@@ -0,0 +1,139 @@
1
+package com.rthoni.camotion.ui.views;
2
+
3
+import android.content.Context;
4
+import android.graphics.Bitmap;
5
+import android.os.Handler;
6
+import android.util.AttributeSet;
7
+import android.view.View;
8
+import android.widget.ImageView;
9
+import android.widget.RelativeLayout;
10
+import android.widget.TextView;
11
+
12
+import com.luticate.auth.dbo.LuFullLoginDbo;
13
+import com.luticate.utils.business.LuPromise;
14
+import com.rthoni.camotion.R;
15
+import com.rthoni.camotion.business.CamerasBusiness;
16
+import com.rthoni.camotion.dbo.CameraDbo;
17
+import com.rthoni.camotion.dbo.LocationDbo;
18
+import com.rthoni.camotion.dbo.SensorDbo;
19
+
20
+/**
21
+ * Created by robin on 12/4/15.
22
+ */
23
+public class SensorView extends RelativeLayout {
24
+    private LuFullLoginDbo _fullLoginDbo = null;
25
+    private LocationDbo _currentLocation = null;
26
+
27
+    private SensorDbo _sensor;
28
+
29
+    private ImageView _imageView;
30
+
31
+    private int _interval = 500;
32
+
33
+    private boolean _playing = false;
34
+    private LuPromise<Bitmap> _promise = null;
35
+
36
+    public void setCamotionDbo(LuFullLoginDbo fullLoginDbo, LocationDbo currentLocation)
37
+    {
38
+        _fullLoginDbo = fullLoginDbo;
39
+        _currentLocation = currentLocation;
40
+    }
41
+
42
+    public SensorDbo getSensor() {
43
+        return _sensor;
44
+    }
45
+
46
+    public void setSensor(SensorDbo sensor) {
47
+        _sensor = sensor;
48
+
49
+        /*((TextView)findViewById(R.id.textViewName)).setText(_sensor.getName());
50
+
51
+        findViewById(R.id.imageViewPause).setOnClickListener(new OnClickListener() {
52
+            @Override
53
+            public void onClick(View v) {
54
+                togglePlay();
55
+            }
56
+        });
57
+
58
+        _imageView = (ImageView) findViewById(R.id.imageView);
59
+        _imageView.setContentDescription(_camera.getDescription());
60
+        _imageView.setOnClickListener(new OnClickListener() {
61
+            @Override
62
+            public void onClick(View v) {
63
+                togglePlay();
64
+            }
65
+        });*/
66
+    }
67
+
68
+    public SensorView(Context context) {
69
+        super(context);
70
+        init();
71
+    }
72
+
73
+    public SensorView(Context context, AttributeSet attrs) {
74
+        super(context, attrs);
75
+        init();
76
+    }
77
+
78
+    public SensorView(Context context, AttributeSet attrs, int defStyleAttr) {
79
+        super(context, attrs, defStyleAttr);
80
+        init();
81
+    }
82
+
83
+    private void init()
84
+    {
85
+        inflate(getContext(), R.layout.sensors_layout, this);
86
+    }
87
+
88
+    public void togglePlay()
89
+    {
90
+        if (_playing)
91
+        {
92
+            pause();
93
+        }
94
+        else
95
+        {
96
+            play();
97
+        }
98
+    }
99
+
100
+    public void pause()
101
+    {
102
+        _playing = false;
103
+        findViewById(R.id.imageViewPause).setVisibility(VISIBLE);
104
+    }
105
+
106
+    public void play()
107
+    {
108
+        _playing = true;
109
+        findViewById(R.id.imageViewPause).setVisibility(GONE);
110
+        if (_promise == null || _promise.getStatus() != LuPromise.LuPromiseStatus.Running) {
111
+            _play();
112
+        }
113
+    }
114
+
115
+    private void _play()
116
+    {
117
+        /*_promise = CamerasBusiness.getImage(_currentLocation.getConfig(_fullLoginDbo.getLoginDbo()), _camera)
118
+                .then(new LuPromise.LuConsumer<Bitmap>() {
119
+                    @Override
120
+                    public void execute(Bitmap image) {
121
+                        if (_playing) {
122
+                            _imageView.setImageBitmap(image);
123
+                            Handler h = new Handler();
124
+                            h.postDelayed(new Runnable() {
125
+                                @Override
126
+                                public void run() {
127
+                                    _play();
128
+                                }
129
+                            }, _interval);
130
+                        }
131
+                    }
132
+                }, new LuPromise.LuConsumer<LuPromise.LuPromiseError>() {
133
+                    @Override
134
+                    public void execute(LuPromise.LuPromiseError data) {
135
+
136
+                    }
137
+                });*/
138
+    }
139
+}

+ 1
- 49
app/src/main/res/layout/sensors_layout.xml ファイルの表示

@@ -39,58 +39,10 @@
39 39
         android:layout_weight="0.33" >
40 40
 
41 41
         <LinearLayout
42
-            android:id="@+id/imagesLayoutScrollView"
42
+            android:id="@+id/sensorsLayoutScrollView"
43 43
             android:layout_width="wrap_content"
44 44
             android:layout_height="match_parent"
45 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 46
         </LinearLayout>
95 47
     </ScrollView>
96 48
 </LinearLayout>

+ 24
- 0
luticateutils/src/main/java/com/luticate/utils/business/LuPromise.java ファイルの表示

@@ -1,5 +1,8 @@
1 1
 package com.luticate.utils.business;
2 2
 
3
+import com.luticate.utils.dbo.LuDbo;
4
+import com.luticate.utils.dbo.LuMultipleDbo;
5
+
3 6
 /**
4 7
  *
5 8
  * Created by robin on 11/27/15.
@@ -10,6 +13,10 @@ public class LuPromise<T> {
10 13
         void execute(T data);
11 14
     }
12 15
 
16
+    public interface LuConverter<T, T2> {
17
+        T2 convert(T data);
18
+    }
19
+
13 20
     public static class LuPromiseError {
14 21
 
15 22
         public LuPromiseError()
@@ -111,6 +118,23 @@ public class LuPromise<T> {
111 118
         }
112 119
     }
113 120
 
121
+    public <T2> LuPromise<T2> map(final LuConverter<T, T2> converter)
122
+    {
123
+        final LuPromise<T2> promise = new LuPromise<>();
124
+        then(new LuConsumer<T>() {
125
+            @Override
126
+            public void execute(T data) {
127
+                promise.resolve(converter.convert(data));
128
+            }
129
+        }, new LuConsumer<LuPromiseError>() {
130
+            @Override
131
+            public void execute(LuPromiseError error) {
132
+                promise.reject(error);
133
+            }
134
+        });
135
+        return promise;
136
+    }
137
+
114 138
     public LuConsumer<LuPromiseError> rejectConsumer()
115 139
     {
116 140
         return new LuConsumer<LuPromiseError>() {

+ 21
- 5
luticateutils/src/main/java/com/luticate/utils/business/LuRequest.java ファイルの表示

@@ -1,6 +1,7 @@
1 1
 package com.luticate.utils.business;
2 2
 
3 3
 import android.content.Context;
4
+import android.net.Uri;
4 5
 
5 6
 import com.android.volley.AuthFailureError;
6 7
 import com.android.volley.Request;
@@ -92,12 +93,12 @@ public class LuRequest {
92 93
             }
93 94
 
94 95
             @Override
95
-            protected Map<String, String> getParams() throws AuthFailureError {
96
+            protected Map<String, String> getParams() {
96 97
                 return params;
97 98
             }
98 99
 
99 100
             @Override
100
-            public Map<String, String> getHeaders() throws AuthFailureError {
101
+            public Map<String, String> getHeaders() {
101 102
                 return config.getHeaders();
102 103
             }
103 104
         };
@@ -105,10 +106,25 @@ public class LuRequest {
105 106
         return promise;
106 107
     }
107 108
 
108
-    public static <T extends LuDbo> LuPromise<T> get(LuDataAccessConfigDbo config, Class<T> type,
109
-                                                     String url, HashMap<String, String> getParams)
109
+    public static <T extends LuDbo> LuPromise<T> get(final LuDataAccessConfigDbo config, Class<T> type,
110
+                                                     String url, final HashMap<String, String> getParams)
110 111
     {
111
-        return request(config, Request.Method.GET, type, url, getParams);
112
+        Uri.Builder uri = Uri.parse(url).buildUpon();
113
+        for (String key : getParams.keySet())
114
+        {
115
+            uri.appendQueryParameter(key, getParams.get(key));
116
+        }
117
+        LuPromise<T> promise = new LuPromise<>();
118
+        StringRequest request = new StringRequest(Request.Method.GET, config.getBaseUrl() + uri.toString(),
119
+                getListener(type, promise), getErrorListener(promise))
120
+        {
121
+            @Override
122
+            public Map<String, String> getHeaders() {
123
+                return config.getHeaders();
124
+            }
125
+        };
126
+        _requestQueue.add(request);
127
+        return promise;
112 128
     }
113 129
 
114 130
     public static <T extends LuDbo> LuPromise<T> get(LuDataAccessConfigDbo config, Class<T> type,

+ 161
- 0
luticateutils/src/main/java/com/luticate/utils/ui/PaginationFragment.java ファイルの表示

@@ -0,0 +1,161 @@
1
+package com.luticate.utils.ui;
2
+
3
+import android.animation.Animator;
4
+import android.animation.AnimatorListenerAdapter;
5
+import android.app.Fragment;
6
+import android.os.Build;
7
+import android.os.Bundle;
8
+import android.view.LayoutInflater;
9
+import android.view.View;
10
+import android.view.ViewGroup;
11
+import android.widget.LinearLayout;
12
+import android.widget.TextView;
13
+
14
+import com.luticate.utils.R;
15
+import com.luticate.utils.business.LuPromise;
16
+import com.luticate.utils.dbo.LuDbo;
17
+import com.luticate.utils.dbo.LuMultipleDbo;
18
+
19
+import java.util.List;
20
+import java.util.Vector;
21
+
22
+/**
23
+ * Created by robin on 12/6/15.
24
+ */
25
+public abstract class PaginationFragment<Dbo extends LuDbo> extends Fragment {
26
+
27
+    protected int _page = 0;
28
+
29
+    protected int _perPage = 6;
30
+
31
+    protected int _maxPage = 1;
32
+
33
+    protected String _query = "";
34
+
35
+    protected LuMultipleDbo<Dbo> _items = new LuMultipleDbo<>();
36
+
37
+    @Override
38
+    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
39
+    {
40
+        return inflater.inflate(getLayoutId(), container, false);
41
+    }
42
+
43
+    @Override
44
+    public void onStart() {
45
+        super.onStart();
46
+        loadPage(_page);
47
+    }
48
+
49
+    protected void showProgress(final boolean show)
50
+    {
51
+        View v = getView();
52
+        if (!isAdded() || v == null)
53
+            return;
54
+
55
+        final View imagesScrollView = v.findViewById(getScrollViewId());
56
+        final View loadingView = v.findViewById(getLoaderViewId());
57
+
58
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
59
+        {
60
+            int shortAnimTime =
61
+                    getResources().getInteger(android.R.integer.config_shortAnimTime);
62
+
63
+            loadingView.setVisibility(View.VISIBLE);
64
+            loadingView.animate().setDuration(shortAnimTime).alpha(show ? 1 : 0)
65
+                    .setListener(new AnimatorListenerAdapter()
66
+                    {
67
+                        @Override
68
+                        public void onAnimationEnd(Animator animation)
69
+                        {
70
+                            loadingView.setVisibility(show ? View.VISIBLE : View.GONE);
71
+                        }
72
+                    });
73
+
74
+            imagesScrollView.setVisibility(View.VISIBLE);
75
+            imagesScrollView.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1)
76
+                    .setListener(new AnimatorListenerAdapter()
77
+                    {
78
+                        @Override
79
+                        public void onAnimationEnd(Animator animation)
80
+                        {
81
+                            imagesScrollView.setVisibility(show ? View.GONE : View.VISIBLE);
82
+                        }
83
+                    });
84
+        }
85
+        else
86
+        {
87
+            loadingView.setVisibility(show ? View.VISIBLE : View.GONE);
88
+            imagesScrollView.setVisibility(show ? View.GONE : View.VISIBLE);
89
+        }
90
+    }
91
+
92
+    public void loadPage(final int page)
93
+    {
94
+        showProgress(true);
95
+        _items.setData(new Vector<Dbo>());
96
+        getLoadPagePromise(page, _perPage, _query).then(new LuPromise.LuConsumer<LuMultipleDbo<Dbo>>() {
97
+            @Override
98
+            public void execute(LuMultipleDbo<Dbo> items) {
99
+                _items = items;
100
+                _page = page;
101
+                _maxPage = Math.max(items.getCount() / _perPage, 1);
102
+                updatePages();
103
+                onPageChanged();
104
+                showProgress(false);
105
+            }
106
+        }, new LuPromise.LuConsumer<LuPromise.LuPromiseError>() {
107
+            @Override
108
+            public void execute(LuPromise.LuPromiseError error) {
109
+
110
+                showProgress(false);
111
+            }
112
+        });
113
+    }
114
+
115
+    protected List<Integer> getPages()
116
+    {
117
+        List<Integer> pages = new Vector<>();
118
+        int start = Math.max(0, _page - 2);
119
+        int end = Math.min(start + 5, _maxPage);
120
+        for (int i = start; i < end; ++i)
121
+        {
122
+            pages.add(i);
123
+        }
124
+        return pages;
125
+    }
126
+
127
+    protected void updatePages()
128
+    {
129
+        View v = getView();
130
+        ViewGroup layout = (ViewGroup) v.findViewById(R.id.pagesLayout);
131
+        if (layout != null)
132
+        {
133
+            layout.removeAllViews();
134
+            for (final int page : getPages())
135
+            {
136
+                TextView tv = new TextView(getActivity());
137
+                tv.setText(" " + String.valueOf(page + 1) + " ");
138
+                tv.setOnClickListener(new View.OnClickListener() {
139
+                    @Override
140
+                    public void onClick(View v) {
141
+                        loadPage(page);
142
+                    }
143
+                });
144
+                tv.setTextAppearance(getActivity(), android.R.style.TextAppearance_DeviceDefault_Large);
145
+                layout.addView(tv);
146
+            }
147
+        }
148
+    }
149
+
150
+    protected void onPageChanged()
151
+    {
152
+    }
153
+
154
+    protected abstract LuPromise<LuMultipleDbo<Dbo>> getLoadPagePromise(int page, int perPage, String query);
155
+
156
+    protected abstract int getScrollViewId();
157
+
158
+    protected abstract int getLoaderViewId();
159
+
160
+    protected abstract int getLayoutId();
161
+}

+ 42
- 0
luticateutils/src/main/java/com/luticate/utils/ui/ViewPaginationFragment.java ファイルの表示

@@ -0,0 +1,42 @@
1
+package com.luticate.utils.ui;
2
+
3
+import android.view.View;
4
+import android.widget.LinearLayout;
5
+
6
+import com.luticate.utils.R;
7
+import com.luticate.utils.dbo.LuDbo;
8
+
9
+/**
10
+ * Created by robin on 12/6/15.
11
+ */
12
+public abstract class ViewPaginationFragment<Dbo extends LuDbo> extends PaginationFragment<Dbo> {
13
+
14
+    @Override
15
+    protected int getLoaderViewId() {
16
+        return R.id.loadStatus;
17
+    }
18
+
19
+    @Override
20
+    protected int getScrollViewId() {
21
+        return R.id.mainScrollView;
22
+    }
23
+
24
+    @Override
25
+    protected int getLayoutId() {
26
+        return R.layout.view_pagination_fragment_layout;
27
+    }
28
+
29
+    @Override
30
+    protected void onPageChanged() {
31
+        super.onPageChanged();
32
+        LinearLayout layout = (LinearLayout) getView().findViewById(R.id.itemsLayoutScrollView);
33
+        layout.removeAllViews();
34
+        for (Dbo item : _items.getData())
35
+        {
36
+            View v = getDboView(item);
37
+            layout.addView(v);
38
+        }
39
+    }
40
+
41
+    protected abstract View getDboView(Dbo dbo);
42
+}

+ 83
- 0
luticateutils/src/main/res/layout/view_pagination_fragment_layout.xml ファイルの表示

@@ -0,0 +1,83 @@
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
+    </LinearLayout>
24
+
25
+    <!-- Layout -->
26
+
27
+    <ScrollView
28
+        android:id="@+id/mainScrollView"
29
+        android:layout_width="match_parent"
30
+        android:layout_height="0dp"
31
+        android:layout_weight="0.33">
32
+
33
+        <RelativeLayout
34
+            android:layout_width="match_parent"
35
+            android:layout_height="wrap_content">
36
+
37
+            <LinearLayout
38
+                android:id="@+id/itemsLayoutScrollView"
39
+                android:layout_width="match_parent"
40
+                android:layout_height="match_parent"
41
+                android:orientation="vertical">
42
+
43
+                <ProgressBar
44
+                    style="?android:attr/progressBarStyleLarge"
45
+                    android:layout_width="wrap_content"
46
+                    android:layout_height="wrap_content"
47
+                    android:layout_marginBottom="8dp"/>
48
+            </LinearLayout>
49
+
50
+
51
+            <LinearLayout
52
+                android:layout_width="match_parent"
53
+                android:layout_height="wrap_content"
54
+                android:layout_below="@+id/itemsLayoutScrollView"
55
+                android:gravity="center">
56
+
57
+                <TextView
58
+                    android:layout_width="wrap_content"
59
+                    android:layout_height="wrap_content"
60
+                    android:id="@+id/previousPageView"
61
+                    android:textAppearance="?android:attr/textAppearanceLarge"
62
+                    android:layout_margin="2dp"
63
+                    android:text=" &lt; "/>
64
+
65
+                <LinearLayout
66
+                    android:id="@+id/pagesLayout"
67
+                    android:layout_width="wrap_content"
68
+                    android:layout_height="match_parent"
69
+                    android:layout_gravity="center_horizontal"
70
+                    android:orientation="horizontal">
71
+                </LinearLayout>
72
+
73
+                <TextView
74
+                    android:layout_width="wrap_content"
75
+                    android:layout_height="wrap_content"
76
+                    android:id="@+id/nextPageView"
77
+                    android:textAppearance="?android:attr/textAppearanceLarge"
78
+                    android:layout_margin="2dp"
79
+                    android:text=" &gt; "/>
80
+            </LinearLayout>
81
+        </RelativeLayout>
82
+    </ScrollView>
83
+</LinearLayout>

読み込み中…
キャンセル
保存