소스 검색

Fixed fragments to use arguments

develop
Robin Thoni 6 년 전
부모
커밋
c5796a3714

+ 15
- 14
app/src/main/java/com/rthoni/camotion/ui/AddCommandShortcutActivity.java 파일 보기

@@ -14,11 +14,13 @@ import com.rthoni.camotion.dbo.CommandDbo;
14 14
 import com.rthoni.camotion.dbo.LocationDbo;
15 15
 import com.rthoni.camotion.ui.dialogs.LocationPickerDialog;
16 16
 import com.rthoni.camotion.ui.dialogs.LoginDialog;
17
-import com.rthoni.camotion.ui.fragments.AbstractCommandsFragment;
17
+import com.rthoni.camotion.ui.fragments.CommandsFragment;
18 18
 
19 19
 import io.fabric.sdk.android.Fabric;
20 20
 
21
-public class AddCommandShortcutActivity extends Activity {
21
+public class AddCommandShortcutActivity extends Activity implements CommandsFragment.OnCommandClickedInterface {
22
+
23
+    private LocationDbo _currentLocation = null;
22 24
 
23 25
     @Override
24 26
     protected void onCreate(Bundle savedInstanceState) {
@@ -52,7 +54,8 @@ public class AddCommandShortcutActivity extends Activity {
52 54
         dlg.loginFull(location).then(new LuPromise.LuConsumer<LuFullLoginDbo>() {
53 55
             @Override
54 56
             public void execute(LuFullLoginDbo loginDbo) {
55
-                showCommands(loginDbo, location);
57
+                _currentLocation = location;
58
+                showCommands(loginDbo);
56 59
             }
57 60
         }, new LuPromise.LuConsumer<LuPromise.LuPromiseError>() {
58 61
             @Override
@@ -63,22 +66,20 @@ public class AddCommandShortcutActivity extends Activity {
63 66
         });
64 67
     }
65 68
 
66
-    private void showCommands(final LuFullLoginDbo loginDbo, final LocationDbo location)
69
+    private void showCommands(final LuFullLoginDbo loginDbo)
67 70
     {
68
-        AbstractCommandsFragment fragment = new AbstractCommandsFragment() {
69
-            @Override
70
-            protected void onCommandClicked(CommandDbo command) {
71
-                addShortcut(location, command);
72
-            }
73
-        };
74
-        fragment.setCamotionDbo(loginDbo, location);
71
+        CommandsFragment fragment = new CommandsFragment();
72
+        Bundle args = new Bundle();
73
+        args.putString("CAMOTION_LOGIN_DBO", loginDbo.toString());
74
+        args.putString("CAMOTION_LOCATION_DBO", _currentLocation.toString());
75
+        fragment.setArguments(args);
75 76
         getFragmentManager().beginTransaction().replace(R.id.container, fragment).commit();
76 77
     }
77 78
 
78
-    private void addShortcut(LocationDbo location, CommandDbo command)
79
-    {
79
+    @Override
80
+    public void onCommandClicked(CommandDbo command) {
80 81
         Intent shortcutIntent = new Intent(this, CommandExecActivity.class);
81
-        shortcutIntent.putExtra("LOCATION_PSEUDO_MAIL", location.getPseudoMail());
82
+        shortcutIntent.putExtra("LOCATION_PSEUDO_MAIL", _currentLocation.getPseudoMail());
82 83
         shortcutIntent.putExtra("COMMAND", command.toString());
83 84
         Intent.ShortcutIconResource iconResource = Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_command_bg);
84 85
 

+ 13
- 4
app/src/main/java/com/rthoni/camotion/ui/MainActivity.java 파일 보기

@@ -4,7 +4,6 @@ import android.content.Intent;
4 4
 import android.content.res.Configuration;
5 5
 import android.os.Bundle;
6 6
 import android.os.PersistableBundle;
7
-import android.provider.Settings;
8 7
 import android.support.design.widget.NavigationView;
9 8
 import android.support.v4.view.GravityCompat;
10 9
 import android.support.v4.widget.DrawerLayout;
@@ -23,19 +22,21 @@ import com.luticate.utils.business.LuPromise;
23 22
 import com.luticate.utils.business.LuRequest;
24 23
 import com.rthoni.camotion.R;
25 24
 import com.rthoni.camotion.business.CamotionBusiness;
25
+import com.rthoni.camotion.dbo.CommandDbo;
26 26
 import com.rthoni.camotion.dbo.LocationDbo;
27
+import com.rthoni.camotion.ui.dialogs.CommandExecDialog;
27 28
 import com.rthoni.camotion.ui.dialogs.LocationPickerDialog;
28 29
 import com.rthoni.camotion.ui.dialogs.LoginDialog;
30
+import com.rthoni.camotion.ui.fragments.CommandsFragment;
29 31
 import com.rthoni.camotion.ui.fragments.CamerasFragment;
30 32
 import com.rthoni.camotion.ui.fragments.CamotionFragment;
31
-import com.rthoni.camotion.ui.fragments.CommandsFragment;
32 33
 import com.rthoni.camotion.ui.fragments.SensorsFragment;
33 34
 
34 35
 import io.fabric.sdk.android.Fabric;
35 36
 import java.util.List;
36 37
 
37 38
 public class MainActivity extends AppCompatActivity
38
-        implements NavigationView.OnNavigationItemSelectedListener {
39
+        implements NavigationView.OnNavigationItemSelectedListener, CommandsFragment.OnCommandClickedInterface {
39 40
 
40 41
     private LuFullLoginDbo _fullLoginDbo = null;
41 42
     private LocationDbo _currentLocation = null;
@@ -212,7 +213,10 @@ public class MainActivity extends AppCompatActivity
212 213
         } */else {
213 214
             return;
214 215
         }
215
-        fragment.setCamotionDbo(_fullLoginDbo, _currentLocation);
216
+        Bundle args = new Bundle();
217
+        args.putString("CAMOTION_LOGIN_DBO", _fullLoginDbo.toString());
218
+        args.putString("CAMOTION_LOCATION_DBO", _currentLocation.toString());
219
+        fragment.setArguments(args);
216 220
         getFragmentManager().beginTransaction().replace(R.id.container, fragment).commit();
217 221
     }
218 222
 
@@ -247,4 +251,9 @@ public class MainActivity extends AppCompatActivity
247 251
     {
248 252
         super.onConfigurationChanged(newConfig);
249 253
     }
254
+
255
+    @Override
256
+    public void onCommandClicked(CommandDbo command) {
257
+        CommandExecDialog.showDialog(_currentLocation.getConfig(_fullLoginDbo.getLoginDbo()), this, command);
258
+    }
250 259
 }

+ 0
- 41
app/src/main/java/com/rthoni/camotion/ui/fragments/AbstractCommandsFragment.java 파일 보기

@@ -1,41 +0,0 @@
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.CommandsBusiness;
6
-import com.rthoni.camotion.dbo.CommandDbo;
7
-import com.rthoni.camotion.ui.views.CommandView;
8
-
9
-/**
10
- *
11
- * Created by robin on 11/29/15.
12
- */
13
-public abstract class AbstractCommandsFragment extends CamotionFragment<CommandDbo, CommandView> {
14
-
15
-    @Override
16
-    protected LuPromise<LuMultipleDbo<CommandDbo>> getLoadPagePromise(int page, int perPage, String query) {
17
-        return CommandsBusiness.getAll(_currentLocation.getConfig(_fullLoginDbo.getLoginDbo()), page, perPage)
18
-                .map(new LuPromise.LuConverter<CommandDbo.MultipleCommandDbo, LuMultipleDbo<CommandDbo>>() {
19
-                    @Override
20
-                    public LuMultipleDbo<CommandDbo> convert(CommandDbo.MultipleCommandDbo data) {
21
-                        return data;
22
-                    }
23
-                });
24
-    }
25
-
26
-    @Override
27
-    protected CommandView getDboView(final CommandDbo command) {
28
-        CommandView commandView = new CommandView(getActivity());
29
-        commandView.setCamotionDbo(_fullLoginDbo, _currentLocation);
30
-        commandView.setCommand(command);
31
-        commandView.setOnClickedListener(new LuPromise.LuConsumer<CommandDbo>() {
32
-            @Override
33
-            public void execute(CommandDbo command) {
34
-                onCommandClicked(command);
35
-            }
36
-        });
37
-        return commandView;
38
-    }
39
-
40
-    protected abstract void onCommandClicked(CommandDbo command);
41
-}

+ 23
- 4
app/src/main/java/com/rthoni/camotion/ui/fragments/CamotionFragment.java 파일 보기

@@ -1,5 +1,7 @@
1 1
 package com.rthoni.camotion.ui.fragments;
2 2
 
3
+import android.content.Context;
4
+import android.os.Bundle;
3 5
 import android.view.View;
4 6
 
5 7
 import com.luticate.auth.dbo.LuFullLoginDbo;
@@ -7,6 +9,8 @@ import com.luticate.utils.dbo.LuDbo;
7 9
 import com.luticate.utils.ui.fragments.ViewPaginationFragment;
8 10
 import com.rthoni.camotion.dbo.LocationDbo;
9 11
 
12
+import org.json.JSONException;
13
+
10 14
 /**
11 15
  * Created by robin on 12/3/15.
12 16
  */
@@ -14,9 +18,24 @@ public abstract class CamotionFragment<Dbo extends LuDbo, DboView extends View>
14 18
     protected LuFullLoginDbo _fullLoginDbo = null;
15 19
     protected LocationDbo _currentLocation = null;
16 20
 
17
-    public void setCamotionDbo(LuFullLoginDbo fullLoginDbo, LocationDbo currentLocation)
18
-    {
19
-        _fullLoginDbo = fullLoginDbo;
20
-        _currentLocation = currentLocation;
21
+    @Override
22
+    public void onAttach(Context context) {
23
+        super.onAttach(context);
24
+        try {
25
+            _fullLoginDbo = new LuFullLoginDbo();
26
+            _fullLoginDbo.fromString(getArguments().getString("CAMOTION_LOGIN_DBO"));
27
+
28
+            _currentLocation = new LocationDbo();
29
+            _currentLocation.fromString(getArguments().getString("CAMOTION_LOCATION_DBO"));
30
+        } catch (JSONException e) {
31
+            e.printStackTrace();
32
+        }
33
+    }
34
+
35
+    @Override
36
+    public void onDetach() {
37
+        super.onDetach();
38
+        _fullLoginDbo = null;
39
+        _currentLocation = null;
21 40
     }
22 41
 }

+ 51
- 4
app/src/main/java/com/rthoni/camotion/ui/fragments/CommandsFragment.java 파일 보기

@@ -1,16 +1,63 @@
1 1
 package com.rthoni.camotion.ui.fragments;
2 2
 
3
+import android.app.Activity;
4
+import android.content.Context;
5
+
6
+import com.luticate.utils.business.LuPromise;
7
+import com.luticate.utils.dbo.LuMultipleDbo;
8
+import com.rthoni.camotion.business.CommandsBusiness;
3 9
 import com.rthoni.camotion.dbo.CommandDbo;
4
-import com.rthoni.camotion.ui.dialogs.CommandExecDialog;
10
+import com.rthoni.camotion.ui.views.CommandView;
5 11
 
6 12
 /**
7 13
  *
8 14
  * Created by robin on 11/29/15.
9 15
  */
10
-public class CommandsFragment extends AbstractCommandsFragment {
16
+public class CommandsFragment extends CamotionFragment<CommandDbo, CommandView> {
17
+
18
+    public interface OnCommandClickedInterface {
19
+        void onCommandClicked(CommandDbo command);
20
+    }
21
+
22
+    private OnCommandClickedInterface onCommandClickedInterface;
23
+
24
+    @Override
25
+    public void onAttach(Context context) {
26
+        super.onAttach(context);
27
+
28
+        if (context instanceof Activity) {
29
+            onCommandClickedInterface = (OnCommandClickedInterface) context;
30
+        }
31
+    }
32
+
33
+    @Override
34
+    public void onDetach() {
35
+        super.onDetach();
36
+        onCommandClickedInterface = null;
37
+    }
38
+
39
+    @Override
40
+    protected LuPromise<LuMultipleDbo<CommandDbo>> getLoadPagePromise(int page, int perPage, String query) {
41
+        return CommandsBusiness.getAll(_currentLocation.getConfig(_fullLoginDbo.getLoginDbo()), page, perPage)
42
+                .map(new LuPromise.LuConverter<CommandDbo.MultipleCommandDbo, LuMultipleDbo<CommandDbo>>() {
43
+                    @Override
44
+                    public LuMultipleDbo<CommandDbo> convert(CommandDbo.MultipleCommandDbo data) {
45
+                        return data;
46
+                    }
47
+                });
48
+    }
11 49
 
12 50
     @Override
13
-    protected void onCommandClicked(CommandDbo command) {
14
-        CommandExecDialog.showDialog(_currentLocation.getConfig(_fullLoginDbo.getLoginDbo()), getActivity(), command);
51
+    protected CommandView getDboView(final CommandDbo command) {
52
+        CommandView commandView = new CommandView(getActivity());
53
+        commandView.setCamotionDbo(_fullLoginDbo, _currentLocation);
54
+        commandView.setCommand(command);
55
+        commandView.setOnClickedListener(new LuPromise.LuConsumer<CommandDbo>() {
56
+            @Override
57
+            public void execute(CommandDbo command) {
58
+                onCommandClickedInterface.onCommandClicked(command);
59
+            }
60
+        });
61
+        return commandView;
15 62
     }
16 63
 }

+ 2
- 2
luticateauth/src/main/java/com/luticate/auth/dbo/LuFullLoginDbo.java 파일 보기

@@ -53,9 +53,9 @@ public class LuFullLoginDbo extends LuDbo {
53 53
     public HashMap<String, Object> toArray() {
54 54
         HashMap<String, Object> array = new HashMap<>();
55 55
         array.put("LoginDbo", _loginDbo.toArray());
56
-        JSONArray permissions = new JSONArray();
56
+        List<HashMap<String, Object>> permissions = new Vector<>();
57 57
         for (LuPermissionDbo perm : _permissions) {
58
-            permissions.put(perm.toArray());
58
+            permissions.add(perm.toArray());
59 59
         }
60 60
         array.put("Permissions", permissions);
61 61
         return array;

+ 6
- 0
luticateutils/src/main/java/com/luticate/utils/dbo/LuDbo.java 파일 보기

@@ -14,6 +14,12 @@ public abstract class LuDbo {
14 14
 
15 15
     public abstract HashMap<String, Object> toArray();
16 16
 
17
+    public void fromString(String data) throws JSONException
18
+    {
19
+        JSONObject json = new JSONObject(data);
20
+        fromJson(json);
21
+    }
22
+
17 23
     public JSONObject toJson()
18 24
     {
19 25
         return new JSONObject(toArray());

Loading…
취소
저장