Procházet zdrojové kódy

Rename Task to Func

Guy Carmeli před 6 roky
rodič
revize
a402f603d4

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

@@ -4,4 +4,12 @@ public class Functions {
4 4
     public interface Unit<T> {
5 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 Zobrazit soubor

@@ -1,5 +0,0 @@
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 Zobrazit soubor

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

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

@@ -9,6 +9,7 @@ import android.view.ViewParent;
9 9
 
10 10
 import com.facebook.react.views.view.ReactViewBackgroundDrawable;
11 11
 import com.reactnativenavigation.react.ReactView;
12
+import com.reactnativenavigation.utils.Functions.Func1;
12 13
 
13 14
 import java.util.ArrayList;
14 15
 import java.util.List;
@@ -90,7 +91,7 @@ public class ViewUtils {
90 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 95
         ReactView parent = findParentReactView(child.getParent());
95 96
         if (parent != null) {
96 97
             task.run(parent);

+ 5
- 5
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java Zobrazit soubor

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

@@ -9,9 +9,9 @@ import android.util.Log;
9 9
 import com.reactnativenavigation.R;
10 10
 import com.reactnativenavigation.parse.params.Button;
11 11
 import com.reactnativenavigation.react.Constants;
12
+import com.reactnativenavigation.utils.Functions.Func1;
12 13
 import com.reactnativenavigation.utils.ImageLoader;
13 14
 import com.reactnativenavigation.utils.ImageLoadingListenerAdapter;
14
-import com.reactnativenavigation.utils.Task;
15 15
 
16 16
 public class NavigationIconResolver {
17 17
 
@@ -23,7 +23,7 @@ public class NavigationIconResolver {
23 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 27
         if (button.icon.hasValue()) {
28 28
             imageLoader.loadIcon(context, button.icon.get(), new ImageLoadingListenerAdapter() {
29 29
                 @Override

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

@@ -13,7 +13,7 @@ import com.reactnativenavigation.presentation.Presenter;
13 13
 import com.reactnativenavigation.react.EventEmitter;
14 14
 import com.reactnativenavigation.utils.CommandListener;
15 15
 import com.reactnativenavigation.utils.CompatUtils;
16
-import com.reactnativenavigation.utils.Task;
16
+import com.reactnativenavigation.utils.Functions.Func1;
17 17
 import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
18 18
 import com.reactnativenavigation.viewcontrollers.ParentController;
19 19
 import com.reactnativenavigation.viewcontrollers.ViewController;
@@ -207,7 +207,7 @@ public class Navigator extends ParentController {
207 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 211
         ViewController from = findController(fromId);
212 212
         if (from != null) {
213 213
             if (from instanceof StackController) {

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

@@ -7,7 +7,7 @@ import android.view.View;
7 7
 
8 8
 import com.reactnativenavigation.parse.Options;
9 9
 import com.reactnativenavigation.presentation.Presenter;
10
-import com.reactnativenavigation.utils.Task;
10
+import com.reactnativenavigation.utils.Functions.Func1;
11 11
 import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
12 12
 import com.reactnativenavigation.viewcontrollers.ParentController;
13 13
 import com.reactnativenavigation.viewcontrollers.ViewController;
@@ -103,7 +103,7 @@ public class TopTabsController extends ParentController<TopTabsViewPager> {
103 103
         getView().switchToTab(index);
104 104
     }
105 105
 
106
-    private void performOnCurrentTab(Task<ViewController> task) {
106
+    private void performOnCurrentTab(Func1<ViewController> task) {
107 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 Zobrazit soubor

@@ -7,7 +7,7 @@ import android.widget.TextView;
7 7
 
8 8
 import com.reactnativenavigation.parse.params.Colour;
9 9
 import com.reactnativenavigation.parse.params.Number;
10
-import com.reactnativenavigation.utils.Task;
10
+import com.reactnativenavigation.utils.Functions.Func1;
11 11
 import com.reactnativenavigation.utils.ViewUtils;
12 12
 
13 13
 class TopTabsStyleHelper {
@@ -44,7 +44,7 @@ class TopTabsStyleHelper {
44 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 48
         TextView title = ViewUtils.findChildByClass(getTabView(tabIndex), TextView.class);
49 49
         if (title != null) {
50 50
             action.run(title);

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

@@ -10,8 +10,8 @@ import com.reactnativenavigation.parse.params.Button;
10 10
 import com.reactnativenavigation.parse.params.Colour;
11 11
 import com.reactnativenavigation.parse.params.Text;
12 12
 import com.reactnativenavigation.react.Constants;
13
+import com.reactnativenavigation.utils.Functions.Func1;
13 14
 import com.reactnativenavigation.utils.ImageLoader;
14
-import com.reactnativenavigation.utils.Task;
15 15
 
16 16
 import org.junit.Test;
17 17
 
@@ -36,7 +36,7 @@ public class NavigationIconResolverTest extends BaseTest {
36 36
 
37 37
     @Test
38 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 40
             @Override
41 41
             public void run(Drawable icon) {
42 42
 
@@ -49,7 +49,7 @@ public class NavigationIconResolverTest extends BaseTest {
49 49
 
50 50
     @Test
51 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 53
             @Override
54 54
             public void run(Drawable param) {
55 55