Browse Source

Rename Task to Func

Guy Carmeli 6 years ago
parent
commit
a402f603d4

+ 8
- 0
lib/android/app/src/main/java/com/reactnativenavigation/utils/Functions.java View File

4
     public interface Unit<T> {
4
     public interface Unit<T> {
5
         T get();
5
         T get();
6
     }
6
     }
7
+
8
+    public interface Func {
9
+        void run();
10
+    }
11
+
12
+    public interface Func1<T> {
13
+        void run(T param);
14
+    }
7
 }
15
 }

+ 0
- 5
lib/android/app/src/main/java/com/reactnativenavigation/utils/Task.java View File

1
-package com.reactnativenavigation.utils;
2
-
3
-public interface Task<T> {
4
-    void run(T param);
5
-}

+ 13
- 3
lib/android/app/src/main/java/com/reactnativenavigation/utils/Time.java View File

4
 
4
 
5
 import java.util.HashMap;
5
 import java.util.HashMap;
6
 import java.util.Map;
6
 import java.util.Map;
7
+import java.util.concurrent.atomic.AtomicInteger;
7
 
8
 
8
 @SuppressWarnings("WeakerAccess")
9
 @SuppressWarnings("WeakerAccess")
9
 public class Time {
10
 public class Time {
10
     private static Map<String, Long> tagsToStartTime = new HashMap<>();
11
     private static Map<String, Long> tagsToStartTime = new HashMap<>();
11
     private static Now now = new Now();
12
     private static Now now = new Now();
13
+    private static AtomicInteger count = new AtomicInteger();
12
 
14
 
13
     public static <T> T log(String tag, Functions.Unit<T> unit) {
15
     public static <T> T log(String tag, Functions.Unit<T> unit) {
14
-        log(tag);
16
+        int idx = count.incrementAndGet();
17
+        log(tag + idx);
15
         T t = unit.get();
18
         T t = unit.get();
16
-        log(tag);
19
+        log(tag + idx);
17
         return t;
20
         return t;
18
     }
21
     }
19
 
22
 
23
+    public static void log(String tag, Functions.Func task) {
24
+        int idx = count.incrementAndGet();
25
+        log(tag + idx);
26
+        task.run();
27
+        log(tag + idx);
28
+    }
29
+
20
     public static void log(String tag) {
30
     public static void log(String tag) {
21
         if (tagsToStartTime.containsKey(tag)) {
31
         if (tagsToStartTime.containsKey(tag)) {
22
             Log.i(tag, "Elapsed: " + (now() - time(tag)));
32
             Log.i(tag, "Elapsed: " + (now() - time(tag)));
23
         } else {
33
         } else {
24
-            Log.i(tag, "logging start");
34
+            Log.v(tag, "logging start");
25
         }
35
         }
26
         tagsToStartTime.put(tag, now());
36
         tagsToStartTime.put(tag, now());
27
     }
37
     }

+ 2
- 1
lib/android/app/src/main/java/com/reactnativenavigation/utils/ViewUtils.java View File

9
 
9
 
10
 import com.facebook.react.views.view.ReactViewBackgroundDrawable;
10
 import com.facebook.react.views.view.ReactViewBackgroundDrawable;
11
 import com.reactnativenavigation.react.ReactView;
11
 import com.reactnativenavigation.react.ReactView;
12
+import com.reactnativenavigation.utils.Functions.Func1;
12
 
13
 
13
 import java.util.ArrayList;
14
 import java.util.ArrayList;
14
 import java.util.List;
15
 import java.util.List;
90
         return view.getLayoutParams().height < 0 ? view.getHeight() : view.getLayoutParams().height;
91
         return view.getLayoutParams().height < 0 ? view.getHeight() : view.getLayoutParams().height;
91
     }
92
     }
92
 
93
 
93
-    public static void performOnParentReactView(View child, Task<ReactView> task) {
94
+    public static void performOnParentReactView(View child, Func1<ReactView> task) {
94
         ReactView parent = findParentReactView(child.getParent());
95
         ReactView parent = findParentReactView(child.getParent());
95
         if (parent != null) {
96
         if (parent != null) {
96
             task.run(parent);
97
             task.run(parent);

+ 5
- 5
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java View File

16
 import com.reactnativenavigation.parse.params.NullBool;
16
 import com.reactnativenavigation.parse.params.NullBool;
17
 import com.reactnativenavigation.presentation.FabPresenter;
17
 import com.reactnativenavigation.presentation.FabPresenter;
18
 import com.reactnativenavigation.utils.CommandListener;
18
 import com.reactnativenavigation.utils.CommandListener;
19
+import com.reactnativenavigation.utils.Functions.Func1;
19
 import com.reactnativenavigation.utils.StringUtils;
20
 import com.reactnativenavigation.utils.StringUtils;
20
-import com.reactnativenavigation.utils.Task;
21
 import com.reactnativenavigation.utils.UiThread;
21
 import com.reactnativenavigation.utils.UiThread;
22
 import com.reactnativenavigation.utils.UiUtils;
22
 import com.reactnativenavigation.utils.UiUtils;
23
 import com.reactnativenavigation.viewcontrollers.stack.StackController;
23
 import com.reactnativenavigation.viewcontrollers.stack.StackController;
126
         return activity;
126
         return activity;
127
     }
127
     }
128
 
128
 
129
-    protected void performOnParentController(Task<ParentController> task) {
129
+    protected void performOnParentController(Func1<ParentController> task) {
130
         if (parentController != null) task.run(parentController);
130
         if (parentController != null) task.run(parentController);
131
     }
131
     }
132
 
132
 
139
         this.parentController = parentController;
139
         this.parentController = parentController;
140
     }
140
     }
141
 
141
 
142
-    public void performOnParentStack(Task<StackController> task) {
142
+    public void performOnParentStack(Func1<StackController> task) {
143
         if (parentController instanceof StackController) {
143
         if (parentController instanceof StackController) {
144
             task.run((StackController) parentController);
144
             task.run((StackController) parentController);
145
         } else if (this instanceof StackController) {
145
         } else if (this instanceof StackController) {
270
 
270
 
271
     }
271
     }
272
 
272
 
273
-    void runOnPreDraw(Task<T> task) {
273
+    void runOnPreDraw(Func1<T> task) {
274
         UiUtils.runOnPreDrawOnce(getView(), () -> task.run(getView()));
274
         UiUtils.runOnPreDrawOnce(getView(), () -> task.run(getView()));
275
     }
275
     }
276
 
276
 
291
         );
291
         );
292
     }
292
     }
293
 
293
 
294
-    void applyOnController(ViewController controller, Task<ViewController> task) {
294
+    void applyOnController(ViewController controller, Func1<ViewController> task) {
295
         if (controller != null) task.run(controller);
295
         if (controller != null) task.run(controller);
296
     }
296
     }
297
 
297
 

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/button/NavigationIconResolver.java View File

9
 import com.reactnativenavigation.R;
9
 import com.reactnativenavigation.R;
10
 import com.reactnativenavigation.parse.params.Button;
10
 import com.reactnativenavigation.parse.params.Button;
11
 import com.reactnativenavigation.react.Constants;
11
 import com.reactnativenavigation.react.Constants;
12
+import com.reactnativenavigation.utils.Functions.Func1;
12
 import com.reactnativenavigation.utils.ImageLoader;
13
 import com.reactnativenavigation.utils.ImageLoader;
13
 import com.reactnativenavigation.utils.ImageLoadingListenerAdapter;
14
 import com.reactnativenavigation.utils.ImageLoadingListenerAdapter;
14
-import com.reactnativenavigation.utils.Task;
15
 
15
 
16
 public class NavigationIconResolver {
16
 public class NavigationIconResolver {
17
 
17
 
23
         this.imageLoader = imageLoader;
23
         this.imageLoader = imageLoader;
24
     }
24
     }
25
 
25
 
26
-    public void resolve(Button button, Task<Drawable> onSuccess) {
26
+    public void resolve(Button button, Func1<Drawable> onSuccess) {
27
         if (button.icon.hasValue()) {
27
         if (button.icon.hasValue()) {
28
             imageLoader.loadIcon(context, button.icon.get(), new ImageLoadingListenerAdapter() {
28
             imageLoader.loadIcon(context, button.icon.get(), new ImageLoadingListenerAdapter() {
29
                 @Override
29
                 @Override

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/navigator/Navigator.java View File

13
 import com.reactnativenavigation.react.EventEmitter;
13
 import com.reactnativenavigation.react.EventEmitter;
14
 import com.reactnativenavigation.utils.CommandListener;
14
 import com.reactnativenavigation.utils.CommandListener;
15
 import com.reactnativenavigation.utils.CompatUtils;
15
 import com.reactnativenavigation.utils.CompatUtils;
16
-import com.reactnativenavigation.utils.Task;
16
+import com.reactnativenavigation.utils.Functions.Func1;
17
 import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
17
 import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
18
 import com.reactnativenavigation.viewcontrollers.ParentController;
18
 import com.reactnativenavigation.viewcontrollers.ParentController;
19
 import com.reactnativenavigation.viewcontrollers.ViewController;
19
 import com.reactnativenavigation.viewcontrollers.ViewController;
207
         return controllerById;
207
         return controllerById;
208
     }
208
     }
209
 
209
 
210
-    private void applyOnStack(String fromId, CommandListener listener, Task<StackController> task) {
210
+    private void applyOnStack(String fromId, CommandListener listener, Func1<StackController> task) {
211
         ViewController from = findController(fromId);
211
         ViewController from = findController(fromId);
212
         if (from != null) {
212
         if (from != null) {
213
             if (from instanceof StackController) {
213
             if (from instanceof StackController) {

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/toptabs/TopTabsController.java View File

7
 
7
 
8
 import com.reactnativenavigation.parse.Options;
8
 import com.reactnativenavigation.parse.Options;
9
 import com.reactnativenavigation.presentation.Presenter;
9
 import com.reactnativenavigation.presentation.Presenter;
10
-import com.reactnativenavigation.utils.Task;
10
+import com.reactnativenavigation.utils.Functions.Func1;
11
 import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
11
 import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
12
 import com.reactnativenavigation.viewcontrollers.ParentController;
12
 import com.reactnativenavigation.viewcontrollers.ParentController;
13
 import com.reactnativenavigation.viewcontrollers.ViewController;
13
 import com.reactnativenavigation.viewcontrollers.ViewController;
103
         getView().switchToTab(index);
103
         getView().switchToTab(index);
104
     }
104
     }
105
 
105
 
106
-    private void performOnCurrentTab(Task<ViewController> task) {
106
+    private void performOnCurrentTab(Func1<ViewController> task) {
107
         task.run(tabs.get(getView().getCurrentItem()));
107
         task.run(tabs.get(getView().getCurrentItem()));
108
     }
108
     }
109
 }
109
 }

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/views/toptabs/TopTabsStyleHelper.java View File

7
 
7
 
8
 import com.reactnativenavigation.parse.params.Colour;
8
 import com.reactnativenavigation.parse.params.Colour;
9
 import com.reactnativenavigation.parse.params.Number;
9
 import com.reactnativenavigation.parse.params.Number;
10
-import com.reactnativenavigation.utils.Task;
10
+import com.reactnativenavigation.utils.Functions.Func1;
11
 import com.reactnativenavigation.utils.ViewUtils;
11
 import com.reactnativenavigation.utils.ViewUtils;
12
 
12
 
13
 class TopTabsStyleHelper {
13
 class TopTabsStyleHelper {
44
         applyOnTabTitle(tabIndex, (title) -> title.setTypeface(fontFamily));
44
         applyOnTabTitle(tabIndex, (title) -> title.setTypeface(fontFamily));
45
     }
45
     }
46
 
46
 
47
-    private void applyOnTabTitle(int tabIndex, Task<TextView> action) {
47
+    private void applyOnTabTitle(int tabIndex, Func1<TextView> action) {
48
         TextView title = ViewUtils.findChildByClass(getTabView(tabIndex), TextView.class);
48
         TextView title = ViewUtils.findChildByClass(getTabView(tabIndex), TextView.class);
49
         if (title != null) {
49
         if (title != null) {
50
             action.run(title);
50
             action.run(title);

+ 3
- 3
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/button/NavigationIconResolverTest.java View File

10
 import com.reactnativenavigation.parse.params.Colour;
10
 import com.reactnativenavigation.parse.params.Colour;
11
 import com.reactnativenavigation.parse.params.Text;
11
 import com.reactnativenavigation.parse.params.Text;
12
 import com.reactnativenavigation.react.Constants;
12
 import com.reactnativenavigation.react.Constants;
13
+import com.reactnativenavigation.utils.Functions.Func1;
13
 import com.reactnativenavigation.utils.ImageLoader;
14
 import com.reactnativenavigation.utils.ImageLoader;
14
-import com.reactnativenavigation.utils.Task;
15
 
15
 
16
 import org.junit.Test;
16
 import org.junit.Test;
17
 
17
 
36
 
36
 
37
     @Test
37
     @Test
38
     public void create_iconButton() {
38
     public void create_iconButton() {
39
-        @SuppressWarnings("Convert2Lambda") Task<Drawable> onSuccess = spy(new Task<Drawable>() {
39
+        @SuppressWarnings("Convert2Lambda") Func1<Drawable> onSuccess = spy(new Func1<Drawable>() {
40
             @Override
40
             @Override
41
             public void run(Drawable icon) {
41
             public void run(Drawable icon) {
42
 
42
 
49
 
49
 
50
     @Test
50
     @Test
51
     public void create_backButton() {
51
     public void create_backButton() {
52
-        @SuppressWarnings("Convert2Lambda") Task<Drawable> onSuccess = spy(new Task<Drawable>() {
52
+        @SuppressWarnings("Convert2Lambda") Func1<Drawable> onSuccess = spy(new Func1<Drawable>() {
53
             @Override
53
             @Override
54
             public void run(Drawable param) {
54
             public void run(Drawable param) {
55
 
55