getRequest(@NonNull ActionArgs args);
144 |
145 | }
146 |
--------------------------------------------------------------------------------
/actionhandler/src/main/java/com/drextended/actionhandler/action/SingleActionFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandler.action;
18 |
19 | import androidx.annotation.NonNull;
20 | import androidx.annotation.Nullable;
21 |
22 | /**
23 | * Used by ActionHandler for lazy instantiating actions.
24 | */
25 | public interface SingleActionFactory {
26 |
27 | /**
28 | * Called when ActionHandler have not had the action to handle given actionType yet.
29 | * When ActionHandler already have the action for the actionType, this method will not be called
30 | *
31 | * @param actionType the actionType to handle
32 | * @return action which can handle given action type
33 | */
34 | @Nullable
35 | Action provideAction(@NonNull String actionType);
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/actionhandler/src/main/java/com/drextended/actionhandler/action/SingleActionFactoryAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandler.action;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | /**
22 | * Adapter for use {@link SingleActionFactory} as {@link ActionFactory}
23 | */
24 | public class SingleActionFactoryAdapter implements ActionFactory {
25 |
26 | private final SingleActionFactory mFactory;
27 |
28 | public SingleActionFactoryAdapter(@NonNull SingleActionFactory factory) {
29 | mFactory = factory;
30 | }
31 |
32 | @Override
33 | public Action[] provideActions(@NonNull String actionType) {
34 | Action action = mFactory.provideAction(actionType);
35 | return action == null ? null : new Action[]{action};
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/actionhandler/src/main/java/com/drextended/actionhandler/listener/ActionCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandler.listener;
18 |
19 | import androidx.annotation.NonNull;
20 | import androidx.annotation.Nullable;
21 |
22 | import com.drextended.actionhandler.ActionArgs;
23 | import com.drextended.actionhandler.ActionParams;
24 | import com.drextended.actionhandler.action.Action;
25 |
26 | /**
27 | * One interface for all listeners and interceptors.
28 | */
29 | public interface ActionCallback extends ActionInterceptor, ActionFireInterceptor,
30 | OnActionFiredListener, OnActionDismissListener, OnActionErrorListener {
31 |
32 | abstract class SimpleActionCallback implements ActionCallback {
33 |
34 | /**
35 | * @inheritDocs
36 | */
37 | @Override
38 | public boolean onInterceptActionFire(@NonNull ActionParams actionParams, @Nullable String actionType, @NonNull Action action) {
39 | return false;
40 | }
41 |
42 | /**
43 | * @inheritDocs
44 | */
45 | @Override
46 | public boolean onInterceptAction(@NonNull ActionParams params) {
47 | return false;
48 | }
49 |
50 | /**
51 | * @inheritDocs
52 | */
53 | @Override
54 | public void onActionDismiss(@NonNull ActionArgs args, @Nullable String reason) {
55 | }
56 |
57 | /**
58 | * @inheritDocs
59 | */
60 | @Override
61 | public void onActionError(@NonNull ActionArgs args, @Nullable Throwable throwable) {
62 | }
63 |
64 | /**
65 | * @inheritDocs
66 | */
67 | @Override
68 | public void onActionFired(@NonNull ActionArgs args, @Nullable Object result) {
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/actionhandler/src/main/java/com/drextended/actionhandler/listener/ActionClickListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandler.listener;
18 |
19 | import android.view.View;
20 |
21 | import androidx.annotation.NonNull;
22 | import androidx.annotation.Nullable;
23 |
24 | /**
25 | * Interface definition for a callback to be invoked when a view with an action is clicked.
26 | */
27 | public interface ActionClickListener {
28 | /**
29 | * Called when a view with an action is clicked.
30 | *
31 | * @param view The view that was clicked.
32 | * @param actionType The action type, which appointed to the view
33 | * @param model The model, which appointed to the view and should be handled
34 | * @param actionTag The tag, which can be used to distinct click source or etc.
35 | */
36 | void onActionClick(
37 | @NonNull final View view,
38 | @Nullable final String actionType,
39 | @Nullable final Object model,
40 | @Nullable final Object actionTag
41 | );
42 | }
43 |
--------------------------------------------------------------------------------
/actionhandler/src/main/java/com/drextended/actionhandler/listener/ActionFireInterceptor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandler.listener;
18 |
19 | import androidx.annotation.NonNull;
20 | import androidx.annotation.Nullable;
21 |
22 | import com.drextended.actionhandler.ActionPair;
23 | import com.drextended.actionhandler.ActionParams;
24 | import com.drextended.actionhandler.action.Action;
25 |
26 | /**
27 | * Interface definition for a callback to be invoked right before specific action will be fired.
28 | * If {@link #onInterceptActionFire(ActionParams, String, Action)} return true
29 | * then this action will not be fired.
30 | */
31 | public interface ActionFireInterceptor {
32 | /**
33 | * Called right before specific action will be fired
34 | * If return true then this action will not be fired.
35 | *
36 | * @param actionParams The action params, which appointed to the view
37 | * @param actionType The action type, which is prepared to fire.
38 | * May be different from actionParams.actionType
39 | * when intercepted actionItem in CompositeAction
40 | * or when actionType of fired action is null that match to any
41 | * @param action The action, which is prepared to fire.
42 | * @return true for intercept the action, false to handle the action in normal way.
43 | */
44 | boolean onInterceptActionFire(
45 | @NonNull ActionParams actionParams,
46 | @Nullable String actionType,
47 | @NonNull Action action
48 | );
49 | }
50 |
--------------------------------------------------------------------------------
/actionhandler/src/main/java/com/drextended/actionhandler/listener/ActionInterceptor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandler.listener;
18 |
19 | import androidx.annotation.NonNull;
20 |
21 | import com.drextended.actionhandler.ActionParams;
22 |
23 | /**
24 | * Interface definition for a callback to be invoked after a view with an action is clicked
25 | * and before action type handling started. If {@link #onInterceptAction(ActionParams)} return true
26 | * then this action type will not be handled.
27 | */
28 | public interface ActionInterceptor {
29 | /**
30 | * Called after a view with an action is clicked
31 | * and before action handling started. If return true then this action will not be handled.
32 | *
33 | * @param params The actionParams
34 | * @return true for intercept the action, false to handle the action in normal way.
35 | */
36 | boolean onInterceptAction(@NonNull ActionParams params);
37 | }
38 |
--------------------------------------------------------------------------------
/actionhandler/src/main/java/com/drextended/actionhandler/listener/OnActionDismissListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandler.listener;
18 |
19 | import androidx.annotation.NonNull;
20 | import androidx.annotation.Nullable;
21 |
22 | import com.drextended.actionhandler.ActionArgs;
23 |
24 | /**
25 | * Interface definition for a callback to be invoked when an action was dismissed.
26 | */
27 | public interface OnActionDismissListener {
28 |
29 | /**
30 | * Called when error occurred while an action is executing.
31 | *
32 | * @param args The action params, which appointed to the view
33 | * and actual fired action type
34 | * @param reason The reason to dismiss
35 | */
36 | void onActionDismiss(
37 | @NonNull ActionArgs args,
38 | @Nullable String reason
39 | );
40 | }
41 |
--------------------------------------------------------------------------------
/actionhandler/src/main/java/com/drextended/actionhandler/listener/OnActionErrorListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandler.listener;
18 |
19 | import androidx.annotation.NonNull;
20 | import androidx.annotation.Nullable;
21 |
22 | import com.drextended.actionhandler.ActionArgs;
23 |
24 | /**
25 | * Interface definition for a callback to be invoked when an action is executed with error.
26 | */
27 | public interface OnActionErrorListener {
28 |
29 | /**
30 | * Called when error occurred while an action is executing.
31 | *
32 | * @param args The action params, which appointed to the view and actually actionType
33 | * @param throwable The error
34 | */
35 | void onActionError(
36 | @NonNull ActionArgs args,
37 | @Nullable Throwable throwable
38 | );
39 | }
40 |
--------------------------------------------------------------------------------
/actionhandler/src/main/java/com/drextended/actionhandler/listener/OnActionFiredListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandler.listener;
18 |
19 | import androidx.annotation.NonNull;
20 | import androidx.annotation.Nullable;
21 |
22 | import com.drextended.actionhandler.ActionArgs;
23 |
24 | /**
25 | * Interface definition for a callback to be invoked when an action is executed successfully.
26 | */
27 | public interface OnActionFiredListener {
28 |
29 | /**
30 | * Called after an action is executed successfully.
31 | *
32 | * @param args The action params, which used while firing action
33 | * @param result The result of action
34 | */
35 | void onActionFired(
36 | @NonNull ActionArgs args,
37 | @Nullable Object result
38 | );
39 | }
40 |
--------------------------------------------------------------------------------
/actionhandler/src/main/java/com/drextended/actionhandler/util/AUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandler.util;
18 |
19 | import android.app.Activity;
20 | import android.app.Dialog;
21 | import android.content.Context;
22 | import android.content.ContextWrapper;
23 | import android.os.Build;
24 |
25 | import androidx.annotation.Nullable;
26 |
27 | public class AUtils {
28 |
29 |
30 | public static Activity getAliveActivity(@Nullable final Context context) {
31 | if (context != null) {
32 | Context baseContext = context;
33 | while (!(baseContext instanceof Activity) && baseContext instanceof ContextWrapper) {
34 | baseContext = ((ContextWrapper) baseContext).getBaseContext();
35 | }
36 | if (baseContext instanceof Activity) {
37 | Activity activity = (Activity) baseContext;
38 | if (isAlive(activity) && !activity.isFinishing()) {
39 | return activity;
40 | }
41 | }
42 | }
43 | return null;
44 | }
45 |
46 | public static Activity getActivity(@Nullable final Context context) {
47 | if (context != null) {
48 | Context baseContext = context;
49 | while (!(baseContext instanceof Activity) && baseContext instanceof ContextWrapper) {
50 | baseContext = ((ContextWrapper) baseContext).getBaseContext();
51 | }
52 | if (baseContext instanceof Activity) {
53 | return (Activity) baseContext;
54 | }
55 | }
56 | return null;
57 | }
58 |
59 | public static boolean isAlive(Dialog dialog) {
60 | return dialog != null && isAlive(getActivity(dialog.getContext()));
61 | }
62 |
63 | public static boolean isAlive(final Activity activity) {
64 | if (activity == null) return false;
65 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
66 | return !activity.isDestroyed();
67 | }
68 | return true;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/actionhandler/src/main/java/com/drextended/actionhandler/util/AcceptCondition.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandler.util;
18 |
19 | /**
20 | * Provides interface to implement condition for checking whether model is accepted
21 | * Created by roman.donchenko on 22.02.2017.
22 | */
23 |
24 | public interface AcceptCondition {
25 | boolean isModelAccepted(Object model);
26 | }
27 |
--------------------------------------------------------------------------------
/actionhandler/src/main/java/com/drextended/actionhandler/util/Converters.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandler.util;
18 |
19 | import android.view.View;
20 |
21 | import androidx.databinding.BindingAdapter;
22 |
23 | import com.drextended.actionhandler.listener.ActionClickListener;
24 |
25 | /**
26 | * Helper class for collect all data binding adapters in one place
27 | */
28 | public class Converters {
29 |
30 | /**
31 | * Binding adapter to assign an action to a view using android data binding approach.
32 | * Sample:
33 | *
34 | * <Button
35 | * android:layout_width="wrap_content"
36 | * android:layout_height="wrap_content"
37 | *
38 | * android:actionHandler="@{someActionHandler}"
39 | * android:actionType='@{"send_message"}'
40 | * android:actionTypeLongClick='@{"show_menu"}'
41 | * android:model="@{user}"
42 | * android:modelLongClick="@{userSettings}"
43 | * android:actionTag='@{"analytics_tag_1"}'
44 | *
45 | * android:text="@string/my_button_text"/>
46 | *
47 | *
48 | * @param view The View to bind an action
49 | * @param actionHandler The action handler which will handle an action
50 | * @param actionType The action type, which will be handled on view clicked
51 | * @param actionTypeLongClick The action type, which will be handled on view long clicked
52 | * @param model The model which will be handled
53 | * @param modelLongClick The model which will be handled for long click. If null, {@code model} will be used
54 | * @param actionTag The tag. CAn be used to distinct click source
55 | */
56 | @BindingAdapter(
57 | value = {
58 | "actionHandler",
59 | "actionType",
60 | "actionTypeLongClick",
61 | "model",
62 | "modelLongClick",
63 | "actionTag"
64 | },
65 | requireAll = false
66 | )
67 | public static void setActionHandler(
68 | final View view,
69 | final ActionClickListener actionHandler,
70 | final String actionType,
71 | final String actionTypeLongClick,
72 | final Object model,
73 | final Object modelLongClick,
74 | final Object actionTag
75 | ) {
76 | if (actionHandler != null) {
77 | ViewOnActionClickListener clickListener = new ViewOnActionClickListener(
78 | actionHandler,
79 | actionType,
80 | actionTypeLongClick,
81 | model,
82 | modelLongClick == null ? model : modelLongClick,
83 | actionTag
84 | );
85 | if (actionType != null) view.setOnClickListener(clickListener);
86 | if (actionTypeLongClick != null) view.setOnLongClickListener(clickListener);
87 | } else {
88 | if (actionType != null) view.setOnClickListener(null);
89 | if (actionTypeLongClick != null) view.setOnLongClickListener(null);
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/actionhandler/src/main/java/com/drextended/actionhandler/util/DebounceHelper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandler.util;
18 |
19 | import java.util.HashMap;
20 | import java.util.concurrent.locks.ReentrantReadWriteLock;
21 |
22 | /**
23 | * Helper to handle debounce time
24 | * Created on 25.07.2017.
25 | */
26 |
27 | public class DebounceHelper {
28 | private final HashMap mDebounceMap = new HashMap<>();
29 | private final ReentrantReadWriteLock mLock = new ReentrantReadWriteLock();
30 |
31 | /**
32 | * Check if time "debounceMillis" elapsed since last timer reset by call {@link #resetTime}
33 | * or {@link #checkTimeAndResetIfElapsed(String, long)}
34 | *
35 | * @param tag the tag
36 | * @param debounceMillis the debounce time for defined tag
37 | * @return true if debounce time has been elapsed since last call, false otherwise
38 | */
39 | public boolean checkTimeElapsed(String tag, long debounceMillis) {
40 | mLock.readLock().lock();
41 | Long lastCallMillis = this.mDebounceMap.get(tag);
42 | mLock.readLock().unlock();
43 | long nowMillis = System.currentTimeMillis();
44 | return lastCallMillis == null
45 | || nowMillis - lastCallMillis > debounceMillis;
46 | }
47 |
48 | /**
49 | * Reset timer for specific tag
50 | *
51 | * @param tag the tag
52 | */
53 | public void resetTime(String tag){
54 | mLock.writeLock().lock();
55 | this.mDebounceMap.put(tag, System.currentTimeMillis());
56 | mLock.writeLock().unlock();
57 | }
58 |
59 | /**
60 | * Check if time "debounceMillis" elapsed since last timer reset by call {@link #resetTime}
61 | * or {@link #checkTimeAndResetIfElapsed(String, long)}
62 | *
63 | * @param tag the tag
64 | * @param debounceMillis the debounce time for defined tag
65 | * @return true if debounce time has been elapsed since last call, false otherwise
66 | */
67 | public boolean checkTimeAndResetIfElapsed(String tag, long debounceMillis) {
68 | mLock.readLock().lock();
69 | Long lastCallMillis = this.mDebounceMap.get(tag);
70 | mLock.readLock().unlock();
71 | long nowMillis = System.currentTimeMillis();
72 | if(lastCallMillis == null || nowMillis - lastCallMillis > debounceMillis) {
73 | mLock.writeLock().lock();
74 | this.mDebounceMap.put(tag, nowMillis);
75 | mLock.writeLock().unlock();
76 | return true;
77 | }
78 | return false;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/actionhandler/src/main/java/com/drextended/actionhandler/util/ProgressBarController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandler.util;
18 |
19 | import android.app.Activity;
20 | import android.app.Application;
21 | import android.app.ProgressDialog;
22 | import android.content.Context;
23 | import android.os.Bundle;
24 | import android.view.Window;
25 |
26 | import androidx.annotation.NonNull;
27 |
28 | import java.util.ArrayList;
29 | import java.util.List;
30 | import java.util.Map;
31 | import java.util.WeakHashMap;
32 |
33 | /**
34 | * This class used to show progress bar for asynchronous requests
35 | */
36 | public class ProgressBarController {
37 | public static final String DEFAULT_TAG = "default_tag";
38 |
39 | private static final Object sLock = new Object();
40 | private static Application.ActivityLifecycleCallbacks sLifecycleCallbacks;
41 | private static WeakHashMap sDialogs = new WeakHashMap<>();
42 |
43 | /**
44 | * Call this before first call of {@link #showProgressDialog}
45 | *
46 | * @param app application
47 | */
48 | public static void init(Application app) {
49 | if (sLifecycleCallbacks != null) {
50 | app.unregisterActivityLifecycleCallbacks(sLifecycleCallbacks);
51 | }
52 | sLifecycleCallbacks = new OnDestroyActivityCallback() {
53 | @Override
54 | public void onActivityDestroyed(Activity activity) {
55 | final int hashCode = activity.hashCode();
56 | synchronized (sLock) {
57 | final List dialogs = findDialogs(hashCode);
58 | for (ProgressDialog dialog : dialogs) {
59 | dialog.dismiss();
60 | sDialogs.remove(dialog);
61 | }
62 | }
63 | }
64 | };
65 | app.registerActivityLifecycleCallbacks(sLifecycleCallbacks);
66 | }
67 |
68 | /**
69 | * Hides all dialogs and unregisters activity lifecycle callbacks
70 | *
71 | * @param app application instance
72 | */
73 | public static void release(Application app) {
74 | if (sLifecycleCallbacks != null) {
75 | app.unregisterActivityLifecycleCallbacks(sLifecycleCallbacks);
76 | }
77 | hideProgressDialogsAll();
78 | }
79 |
80 | /**
81 | * Shows default progress dialog without any message
82 | *
83 | * @param context context
84 | */
85 | public static void showProgressDialog(final Context context) {
86 | showProgressDialog(context, DEFAULT_TAG, null);
87 | }
88 |
89 | /**
90 | * Shows default dialog with a message
91 | *
92 | * @param context context
93 | * @param message the message to show in a dialog
94 | */
95 | public static void showProgressDialog(final Context context, final String message) {
96 | showProgressDialog(context, DEFAULT_TAG, message);
97 | }
98 |
99 | /**
100 | * Shows a new dialog with a message for each different tag.
101 | *
102 | * @param context context
103 | * @param tag the tag for determining specific dialog
104 | * @param message the message to show in a dialog
105 | */
106 | public static void showProgressDialog(final Context context, String tag, final String message) {
107 | final Activity activity = AUtils.getActivity(context);
108 | if (!AUtils.isAlive(activity) || activity.isFinishing()) return;
109 | if (tag == null) tag = DEFAULT_TAG;
110 | ProgressDialog dialog;
111 | synchronized (sLock) {
112 | dialog = findDialog(tag);
113 |
114 | if (!AUtils.isAlive(dialog)) {
115 | if (dialog != null) sDialogs.remove(dialog);
116 | dialog = new ProgressDialog(context);
117 | dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
118 | dialog.setCancelable(false);
119 | sDialogs.put(dialog, new Tag(tag, activity.hashCode()));
120 | }
121 | }
122 | dialog.setMessage(message);
123 | dialog.show();
124 | }
125 |
126 | /**
127 | * Hide default dialog
128 | */
129 | public static void hideProgressDialog() {
130 | hideProgressDialog(DEFAULT_TAG);
131 | }
132 |
133 | /**
134 | * Hide dialog with specific tag
135 | *
136 | * @param tag the tag to determine specific dialog
137 | */
138 | public static void hideProgressDialog(String tag) {
139 | if (tag == null) return;
140 | synchronized (sLock) {
141 | ProgressDialog dialog = findDialog(tag);
142 | if (dialog != null) {
143 | if (AUtils.isAlive(dialog) && dialog.isShowing()) dialog.dismiss();
144 | sDialogs.remove(dialog);
145 | }
146 | }
147 | }
148 |
149 | /**
150 | * Hide all dialogs
151 | */
152 | public static void hideProgressDialogsAll() {
153 | synchronized (sLock) {
154 | for (ProgressDialog dialog : sDialogs.keySet()) {
155 | if (AUtils.isAlive(dialog) && dialog.isShowing()) dialog.dismiss();
156 | }
157 | sDialogs.clear();
158 | }
159 | }
160 |
161 | private static ProgressDialog findDialog(@NonNull String tag) {
162 | for (Map.Entry entry : sDialogs.entrySet()) {
163 | if (tag.equals(entry.getValue().tag)) {
164 | return entry.getKey();
165 | }
166 | }
167 | return null;
168 | }
169 |
170 | private static List findDialogs(long activityHashcode) {
171 | List result = new ArrayList<>();
172 | for (Map.Entry entry : sDialogs.entrySet()) {
173 | if (activityHashcode == entry.getValue().activityHashcode) {
174 | result.add(entry.getKey());
175 | }
176 | }
177 | return result;
178 | }
179 |
180 | private static class Tag {
181 | final String tag;
182 | final long activityHashcode;
183 |
184 | private Tag(String tag, long activityHashcode) {
185 | this.tag = tag;
186 | this.activityHashcode = activityHashcode;
187 | }
188 | }
189 |
190 | private static abstract class OnDestroyActivityCallback implements Application.ActivityLifecycleCallbacks {
191 | @Override
192 | public void onActivityCreated(Activity activity, Bundle bundle) {
193 | }
194 |
195 | @Override
196 | public void onActivityStarted(Activity activity) {
197 | }
198 |
199 | @Override
200 | public void onActivityResumed(Activity activity) {
201 | }
202 |
203 | @Override
204 | public void onActivityPaused(Activity activity) {
205 | }
206 |
207 | @Override
208 | public void onActivityStopped(Activity activity) {
209 | }
210 |
211 | @Override
212 | public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {
213 | }
214 | }
215 | }
216 |
--------------------------------------------------------------------------------
/actionhandler/src/main/java/com/drextended/actionhandler/util/ViewOnActionClickListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandler.util;
18 |
19 | import android.view.View;
20 |
21 | import androidx.annotation.NonNull;
22 | import androidx.annotation.Nullable;
23 |
24 | import com.drextended.actionhandler.listener.ActionClickListener;
25 |
26 | public class ViewOnActionClickListener implements View.OnClickListener, View.OnLongClickListener {
27 |
28 | @NonNull
29 | private final ActionClickListener actionHandler;
30 | @Nullable
31 | private final String actionType;
32 | @Nullable
33 | private final String actionTypeLongClick;
34 | @Nullable
35 | private final Object model;
36 | @Nullable
37 | private final Object modelLongClick;
38 | @Nullable
39 | private final Object actionTypeTag;
40 |
41 | public ViewOnActionClickListener(
42 | @NonNull ActionClickListener actionHandler,
43 | @Nullable String actionType,
44 | @Nullable String actionTypeLongClick,
45 | @Nullable Object model,
46 | @Nullable Object modelLongClick,
47 | @Nullable Object actionTypeTag
48 | ) {
49 |
50 | this.actionHandler = actionHandler;
51 | this.actionType = actionType;
52 | this.actionTypeLongClick = actionTypeLongClick;
53 | this.model = model;
54 | this.modelLongClick = modelLongClick;
55 | this.actionTypeTag = actionTypeTag;
56 | }
57 |
58 | public ViewOnActionClickListener(
59 | @NonNull ActionClickListener actionHandler,
60 | @Nullable Object model,
61 | @Nullable String actionType
62 | ) {
63 | this(actionHandler, actionType, actionType, model, model, null);
64 | }
65 |
66 | public ViewOnActionClickListener(
67 | @NonNull ActionClickListener actionHandler,
68 | @Nullable Object model,
69 | @Nullable String actionType,
70 | @Nullable String actionTypeLongClick
71 | ) {
72 | this(actionHandler, actionType, actionTypeLongClick, model, model, null);
73 | }
74 |
75 | @Override
76 | public void onClick(View v) {
77 | if (actionType != null) {
78 | actionHandler.onActionClick(v, actionType, model, actionTypeTag);
79 | }
80 | }
81 |
82 | @Override
83 | public boolean onLongClick(View v) {
84 | if (actionTypeLongClick != null) {
85 | actionHandler.onActionClick(v, actionTypeLongClick, modelLongClick, actionTypeTag);
86 | return true;
87 | }
88 | return false;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/actionhandler/src/main/res/layout/item_menu_composit_action.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
24 |
34 |
35 |
51 |
--------------------------------------------------------------------------------
/actionhandler/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/actionhandler/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Wait please…
3 |
4 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext {
3 | compileSdkVersion = 28
4 | targetSdkVersion = 28
5 |
6 | kotlin_version = '1.3.31'
7 |
8 | x_appcompat_version = '1.0.2'
9 | x_annotation_version = '1.1.0'
10 |
11 | rxjava2_version = '2.2.10'
12 | rxandroid_version = '2.1.1'
13 |
14 | }
15 | repositories {
16 | google()
17 | jcenter()
18 | }
19 | dependencies {
20 | classpath 'com.android.tools.build:gradle:3.5.0-beta04'
21 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
22 | classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4" //1.7.2
23 | classpath "com.github.dcendents:android-maven-gradle-plugin:2.1" //1.4.1
24 | }
25 | }
26 |
27 | allprojects {
28 | repositories {
29 | google()
30 | jcenter()
31 | }
32 | }
33 |
34 | task clean(type: Delete) {
35 | delete rootProject.buildDir
36 | }
37 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | android.databinding.enableV2=true
2 | android.useAndroidX=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drstranges/ActionHandler/5ee1c61883e5e9e5039522788324a57fd51ac71e/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Jun 22 13:52:34 EEST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/samples/databinding/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/samples/databinding/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.compileSdkVersion
5 |
6 | dataBinding {
7 | enabled = true
8 | }
9 |
10 | defaultConfig {
11 | applicationId "com.example.databinding"
12 | minSdkVersion 21
13 | targetSdkVersion rootProject.ext.targetSdkVersion
14 | versionCode 1
15 | versionName "1.0"
16 |
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | lintOptions {
25 | abortOnError false
26 | }
27 | compileOptions {
28 | sourceCompatibility 1.8
29 | targetCompatibility 1.8
30 | }
31 | }
32 |
33 | dependencies {
34 | implementation project(path: ':actionhandler')
35 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
36 |
37 | implementation "androidx.annotation:annotation:$x_annotation_version"
38 | implementation "androidx.appcompat:appcompat:$x_appcompat_version"
39 | implementation "io.reactivex.rxjava2:rxjava:$rxjava2_version"
40 | implementation "io.reactivex.rxjava2:rxandroid:$rxandroid_version"
41 | }
42 |
--------------------------------------------------------------------------------
/samples/databinding/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android_Env\android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
21 |
22 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/java/com/drextended/databinding/ActionType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.databinding;
18 |
19 | public class ActionType {
20 | public static final String OPEN_NEW_SCREEN = "open_new_screen";
21 | public static final String FIRE_ACTION = "fire_action";
22 | public static final String FIRE_DIALOG_ACTION = "fire_dialog_action";
23 | public static final String FIRE_REQUEST_ACTION = "fire_request_action";
24 | public static final String FIRE_RX_REQUEST_ACTION = "fire_rx_request_action";
25 | public static final String FIRE_COMPOSITE_ACTION = "composite_action";
26 | }
27 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/java/com/drextended/databinding/action/OpenSecondActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.databinding.action;
18 |
19 | import android.app.Activity;
20 | import android.content.ActivityNotFoundException;
21 | import android.content.Context;
22 | import android.content.ContextWrapper;
23 | import android.content.Intent;
24 |
25 | import androidx.annotation.NonNull;
26 | import androidx.annotation.Nullable;
27 | import androidx.core.app.ActivityOptionsCompat;
28 | import android.view.View;
29 |
30 | import com.drextended.actionhandler.ActionArgs;
31 | import com.drextended.actionhandler.action.IntentAction;
32 | import com.drextended.databinding.view.SecondActivity;
33 |
34 |
35 | public class OpenSecondActivity extends IntentAction {
36 | @Override
37 | public boolean isModelAccepted(Object model) {
38 | return model instanceof String;
39 | }
40 |
41 | @Nullable
42 | @Override
43 | public Intent getIntent(@NonNull ActionArgs args) {
44 | return SecondActivity.getIntent(args.params.getViewOrAppContext(), args.params.getModel(String.class));
45 | }
46 |
47 | @Override
48 | protected void startActivity(@NonNull Context context, @NonNull Intent intent, @NonNull ActionArgs args) throws ActivityNotFoundException {
49 | ActivityOptionsCompat transition = prepareTransition(args);
50 | if (transition != null) {
51 | context.startActivity(intent, transition.toBundle());
52 | } else {
53 | super.startActivity(context, intent, args);
54 | }
55 | }
56 |
57 | private ActivityOptionsCompat prepareTransition(@NonNull ActionArgs args) {
58 | View view = args.params.tryGetView();
59 | Activity activity = args.params.tryGetActivity();
60 |
61 | if (activity == null || view == null) return null;
62 | return ActivityOptionsCompat
63 | .makeSceneTransitionAnimation(activity, view, SecondActivity.TRANSITION_NAME);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/java/com/drextended/databinding/action/SampleRequestAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.databinding.action;
18 |
19 | import android.app.Activity;
20 | import android.os.Handler;
21 | import android.widget.Toast;
22 |
23 | import androidx.annotation.NonNull;
24 | import androidx.annotation.Nullable;
25 |
26 | import com.drextended.actionhandler.ActionArgs;
27 | import com.drextended.actionhandler.ActionParams;
28 | import com.drextended.actionhandler.action.RequestAction;
29 | import com.drextended.databinding.R;
30 |
31 | public class SampleRequestAction extends RequestAction {
32 |
33 | private int mCount;
34 |
35 | public SampleRequestAction() {
36 | super(true, true);
37 | }
38 |
39 | @Override
40 | public boolean isModelAccepted(Object model) {
41 | return model instanceof String;
42 | }
43 |
44 | @Override
45 | protected String getDialogMessage(@NonNull ActionParams params) {
46 | return params.appContext.getString(R.string.action_request_dialog_message, params.model);
47 | }
48 |
49 | @Override
50 | protected void onMakeRequest(@NonNull ActionArgs args) {
51 | final Handler handler = new Handler();
52 | handler.postDelayed(() -> {
53 | Activity activity = args.params.tryGetActivity();
54 | if (activity != null && (activity.isFinishing() || activity.isDestroyed())) return;
55 | if (mCount++ % 3 == 0) {
56 | onResponseError(args, new Exception("Test Error!:) Just repeat this request!"));
57 | } else {
58 | onResponseSuccess(args, "Request has been done successfully");
59 | }
60 | }, 3000);
61 | }
62 |
63 | @Override
64 | protected void onResponseSuccess(@NonNull ActionArgs args, @Nullable String response) {
65 | super.onResponseSuccess(args, response);
66 | Toast.makeText(args.params.appContext, response, Toast.LENGTH_SHORT).show();
67 | }
68 |
69 | @Override
70 | protected void onResponseError(@NonNull ActionArgs args, @NonNull Throwable e) {
71 | super.onResponseError(args, e);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/java/com/drextended/databinding/action/SampleRxRequestAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.databinding.action;
18 |
19 | import android.content.Context;
20 |
21 | import androidx.annotation.NonNull;
22 | import androidx.annotation.Nullable;
23 | import android.view.View;
24 | import android.widget.Toast;
25 |
26 | import com.drextended.actionhandler.ActionArgs;
27 | import com.drextended.actionhandler.ActionParams;
28 | import com.drextended.actionhandler.action.RxRequestAction;
29 | import com.drextended.databinding.R;
30 |
31 | import java.util.concurrent.TimeUnit;
32 |
33 | import io.reactivex.Maybe;
34 | import io.reactivex.MaybeSource;
35 | import io.reactivex.functions.Function;
36 |
37 | public class SampleRxRequestAction extends RxRequestAction {
38 |
39 | private int mCount;
40 |
41 | public SampleRxRequestAction() {
42 | super(true, true);
43 | }
44 |
45 | @Nullable
46 | @Override
47 | protected Maybe getRequest(@NonNull ActionArgs args) {
48 | if (mCount++ % 3 == 0) {
49 | return Maybe.just("")
50 | .delay(2000, TimeUnit.MILLISECONDS)
51 | .flatMap(s -> Maybe.error(new Throwable("Request has failed")));
52 | } else {
53 | return Maybe.just("Request has been done successfully")
54 | .delay(2000, TimeUnit.MILLISECONDS);
55 | }
56 | }
57 |
58 | @Override
59 | public boolean isModelAccepted(Object model) {
60 | return model instanceof String;
61 | }
62 |
63 | @Override
64 | protected String getDialogMessage(@NonNull ActionParams params) {
65 | return params.appContext.getString(R.string.action_request_dialog_message, params.model);
66 | }
67 |
68 | @Override
69 | protected void onResponseSuccess(@NonNull ActionArgs args, @Nullable String response) {
70 | super.onResponseSuccess(args, response);
71 | Toast.makeText(args.params.appContext, response, Toast.LENGTH_SHORT).show();
72 | }
73 |
74 | @Override
75 | protected void onResponseError(@NonNull ActionArgs args, @NonNull Throwable e) {
76 | super.onResponseError(args, e);
77 | Toast.makeText(args.params.appContext, e.getMessage(), Toast.LENGTH_SHORT).show();
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/java/com/drextended/databinding/action/ShowToastAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.databinding.action;
18 |
19 | import android.content.Context;
20 | import android.widget.Toast;
21 |
22 | import androidx.annotation.NonNull;
23 |
24 | import com.drextended.actionhandler.ActionArgs;
25 | import com.drextended.actionhandler.action.BaseAction;
26 | import com.drextended.databinding.R;
27 |
28 | public class ShowToastAction extends BaseAction {
29 |
30 | @Override
31 | public boolean isModelAccepted(Object model) {
32 | return model instanceof String;
33 | }
34 |
35 | @Override
36 | public void onFireAction(@NonNull ActionArgs args) {
37 | Context appContext = args.params.appContext;
38 |
39 | Toast.makeText(
40 | appContext,
41 | appContext.getString(R.string.toast_message, args.params.model),
42 | Toast.LENGTH_SHORT
43 | ).show();
44 |
45 | notifyOnActionFired(args);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/java/com/drextended/databinding/action/SimpleAnimationAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.databinding.action;
18 |
19 | import android.animation.ObjectAnimator;
20 | import android.view.View;
21 |
22 | import androidx.annotation.NonNull;
23 |
24 | import com.drextended.actionhandler.ActionArgs;
25 | import com.drextended.actionhandler.action.BaseAction;
26 |
27 | public class SimpleAnimationAction extends BaseAction {
28 |
29 | @Override
30 | public boolean isModelAccepted(Object model) {
31 | return true;
32 | }
33 |
34 | @Override
35 | public void onFireAction(@NonNull ActionArgs args) {
36 | View view = args.params.tryGetView();
37 | if (view == null) {
38 | notifyOnActionDismiss(args, "No view");
39 | return;
40 | }
41 | ObjectAnimator
42 | .ofFloat(view, "translationX", 0, 25, -25, 25, -25, 15, -15, 6, -6, 0)
43 | .setDuration(200)
44 | .start();
45 | notifyOnActionFired(args);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/java/com/drextended/databinding/action/TrackAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.databinding.action;
18 |
19 | import android.content.Context;
20 |
21 | import androidx.annotation.NonNull;
22 | import androidx.annotation.Nullable;
23 | import android.util.Log;
24 | import android.view.View;
25 |
26 | import com.drextended.actionhandler.ActionArgs;
27 | import com.drextended.actionhandler.action.Action;
28 |
29 | public class TrackAction implements Action {
30 |
31 | @Override
32 | public boolean isModelAccepted(Object model) {
33 | return true;
34 | }
35 |
36 | @Override
37 | public void onFireAction(@NonNull ActionArgs args) {
38 | Log.d("tagTrackAction", "onFireAction: " + args.fireActionType + ", model: " + args.params.model);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/java/com/drextended/databinding/view/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.databinding.view;
18 |
19 | import androidx.databinding.DataBindingUtil;
20 | import android.os.Bundle;
21 | import androidx.appcompat.app.AppCompatActivity;
22 | import android.widget.Toast;
23 |
24 | import com.drextended.databinding.R;
25 | import com.drextended.databinding.databinding.ActivityMainBinding;
26 | import com.drextended.databinding.viewmodel.MainActivityViewModel;
27 |
28 | public class MainActivity extends AppCompatActivity implements MainActivityViewModel.Callback {
29 |
30 | private MainActivityViewModel mViewModel;
31 | @SuppressWarnings("FieldCanBeLocal")
32 | private ActivityMainBinding mBinding;
33 |
34 | @Override
35 | protected void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 |
38 | mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
39 | mViewModel = new MainActivityViewModel(this, this);
40 | mBinding.setViewModel(mViewModel);
41 | }
42 |
43 | @Override
44 | protected void onSaveInstanceState(Bundle outState) {
45 | super.onSaveInstanceState(outState);
46 | mViewModel.onSaveInstanceState(outState);
47 | }
48 |
49 | @Override
50 | protected void onRestoreInstanceState(Bundle savedInstanceState) {
51 | super.onRestoreInstanceState(savedInstanceState);
52 | mViewModel.onRestoreInstanceState(savedInstanceState);
53 | }
54 |
55 | @Override
56 | public void showMessage(String message) {
57 | Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/java/com/drextended/databinding/view/SecondActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.databinding.view;
18 |
19 | import android.content.Context;
20 | import android.content.Intent;
21 | import android.os.Bundle;
22 | import androidx.appcompat.app.AppCompatActivity;
23 | import android.view.MenuItem;
24 |
25 | import com.drextended.databinding.R;
26 |
27 |
28 | public class SecondActivity extends AppCompatActivity {
29 |
30 | private static final String ARG_TITLE = "arg_title";
31 | public static final String TRANSITION_NAME = "transition_name";
32 | private String mTitle;
33 |
34 | public static Intent getIntent(Context context, String title) {
35 | final Intent intent = new Intent(context, SecondActivity.class);
36 | intent.putExtra(ARG_TITLE, title);
37 | return intent;
38 | }
39 |
40 | private void initArgs() {
41 | final Bundle args = getIntent().getExtras();
42 | if (args != null) mTitle = args.getString(ARG_TITLE);
43 | }
44 |
45 | @Override
46 | protected void onCreate(Bundle savedInstanceState) {
47 | super.onCreate(savedInstanceState);
48 | setContentView(R.layout.activity_second);
49 | initArgs();
50 | setTitle(mTitle);
51 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
52 | }
53 |
54 | @Override
55 | public boolean onOptionsItemSelected(MenuItem item) {
56 | // Respond to the action bar's Up/Home button
57 | if (item.getItemId() == android.R.id.home) {
58 | supportFinishAfterTransition();
59 | return true;
60 | }
61 | return super.onOptionsItemSelected(item);
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/java/com/drextended/databinding/viewmodel/BaseViewModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.databinding.viewmodel;
18 |
19 | import android.content.Context;
20 | import androidx.annotation.StringRes;
21 |
22 | public class BaseViewModel {
23 | private Context mContext;
24 |
25 | public BaseViewModel(Context context) {
26 | mContext = context;
27 | }
28 |
29 | public Context getContext() {
30 | return mContext;
31 | }
32 |
33 | public String getString(@StringRes int resId) {
34 | return mContext.getString(resId);
35 | }
36 |
37 | public void onDestroy() {
38 | mContext = null;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/java/com/drextended/databinding/viewmodel/MainActivityViewModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.databinding.viewmodel;
18 |
19 | import android.content.Context;
20 | import android.os.Bundle;
21 |
22 | import androidx.annotation.NonNull;
23 | import androidx.annotation.Nullable;
24 | import androidx.databinding.ObservableField;
25 |
26 | import com.drextended.actionhandler.ActionArgs;
27 | import com.drextended.actionhandler.ActionHandler;
28 | import com.drextended.actionhandler.ActionParams;
29 | import com.drextended.actionhandler.action.Action;
30 | import com.drextended.actionhandler.action.CompositeAction;
31 | import com.drextended.actionhandler.action.CompositeAction.ActionItem;
32 | import com.drextended.actionhandler.action.DialogAction;
33 | import com.drextended.actionhandler.action.SingleActionFactory;
34 | import com.drextended.actionhandler.listener.ActionCallback;
35 | import com.drextended.databinding.ActionType;
36 | import com.drextended.databinding.R;
37 | import com.drextended.databinding.action.OpenSecondActivity;
38 | import com.drextended.databinding.action.SampleRequestAction;
39 | import com.drextended.databinding.action.SampleRxRequestAction;
40 | import com.drextended.databinding.action.ShowToastAction;
41 | import com.drextended.databinding.action.SimpleAnimationAction;
42 | import com.drextended.databinding.action.TrackAction;
43 |
44 | /**
45 | * Created on 15.06.2016.
46 | */
47 |
48 | public class MainActivityViewModel extends BaseViewModel implements ActionCallback {
49 |
50 | private static final String EXTRA_LAST_ACTION_TEXT = "EXTRA_LAST_ACTION_TEXT";
51 |
52 | public ObservableField lastActionText = new ObservableField<>();
53 | public ObservableField model = new ObservableField<>();
54 | public ActionHandler actionHandler;
55 |
56 | private int mClickCount;
57 | private Callback mCallback;
58 |
59 | public MainActivityViewModel(Context context, Callback callback) {
60 | super(context);
61 | mCallback = callback != null ? callback : Callback.EMPTY_CALLBACK;
62 | actionHandler = buildActionHandler();
63 | refreshModel();
64 | }
65 |
66 | private void refreshModel() {
67 | model.set("Model (" + System.currentTimeMillis() + ")");
68 | }
69 |
70 | private ActionHandler buildActionHandler() {
71 |
72 | final ShowToastAction showToastAction = new ShowToastAction();
73 |
74 | return new ActionHandler.Builder()
75 | .addAction(null, new SimpleAnimationAction()) // Applied for any actionType
76 | .addAction(null, new TrackAction()) // Applied for any actionType
77 | .addAction(ActionType.FIRE_ACTION, showToastAction)
78 | .withFactory(new SingleActionFactory() {
79 | @Nullable
80 | @Override
81 | public Action provideAction(@NonNull String actionType) {
82 | switch (actionType) {
83 | case ActionType.OPEN_NEW_SCREEN:
84 | return new OpenSecondActivity();
85 | case ActionType.FIRE_DIALOG_ACTION:
86 | return DialogAction.wrap(getString(R.string.action_dialog_message), showToastAction);
87 | case ActionType.FIRE_REQUEST_ACTION:
88 | return new SampleRequestAction();
89 | case ActionType.FIRE_COMPOSITE_ACTION:
90 | return buildMenuAction(showToastAction);
91 | }
92 | return null;
93 | }
94 | })
95 | .addCallback(this)
96 | .setDefaultDebounce(1000)
97 | .setDebounce(2000, ActionType.FIRE_ACTION)
98 | .build();
99 | }
100 |
101 | private Action buildMenuAction(ShowToastAction showToastAction) {
102 | CompositeAction menuAction = new CompositeAction<>((
103 | context, model) -> "Title (" + model + ")",
104 | true,
105 | true,
106 | new ActionItem<>(ActionType.OPEN_NEW_SCREEN, new OpenSecondActivity(), R.drawable.ic_touch_app_black_24dp, 0,
107 | (context, model) -> {
108 | // There you can return any title for menu item using some fields from model
109 | return context.getString(R.string.fire_intent_action);
110 | }),
111 | new ActionItem(ActionType.FIRE_ACTION, showToastAction, R.drawable.ic_announcement_black_24dp, R.color.greenLight, R.string.fire_simple_action),
112 | new ActionItem(ActionType.FIRE_DIALOG_ACTION, DialogAction.wrap(getString(R.string.action_dialog_message), showToastAction), R.drawable.ic_announcement_black_24dp, R.color.amber, R.string.fire_dialog_action),
113 | new ActionItem(ActionType.FIRE_REQUEST_ACTION, new SampleRequestAction() {
114 | @Override
115 | public boolean isModelAccepted(Object model) {
116 | return super.isModelAccepted(model) && mClickCount % 3 == 0;
117 | }
118 | }, R.drawable.ic_cloud_upload_black_24dp, R.color.red, R.string.fire_request_action),
119 | new ActionItem(ActionType.FIRE_RX_REQUEST_ACTION, new SampleRxRequestAction(), 0, 0, R.string.fire_rx_request_action)
120 | );
121 | menuAction.setShowAsPopupMenuEnabled(false);
122 | return menuAction;
123 | }
124 |
125 | @Override
126 | public boolean onInterceptAction(@NonNull ActionParams params) {
127 | switch (params.actionType) {
128 | case ActionType.OPEN_NEW_SCREEN:
129 | case ActionType.FIRE_ACTION:
130 | final boolean consumed = mClickCount++ % 7 == 0;
131 | if (consumed) {
132 | mCallback.showMessage(getString(R.string.message_action_intercepted));
133 | }
134 | return consumed;
135 | // case ActionType.FIRE_ACTION:
136 | // case ActionType.FIRE_DIALOG_ACTION:
137 | // case ActionType.FIRE_REQUEST_ACTION:
138 | }
139 | return false;
140 | }
141 |
142 | @Override
143 | public boolean onInterceptActionFire(@NonNull ActionParams actionParams, @Nullable String actionType, @NonNull Action action) {
144 | return false;
145 | }
146 |
147 | @Override
148 | public void onActionFired(@NonNull ActionArgs args, @Nullable Object result) {
149 | switch (args.params.actionType) {
150 | case ActionType.OPEN_NEW_SCREEN:
151 | lastActionText.set("Intent Action");
152 | break;
153 | case ActionType.FIRE_ACTION:
154 | lastActionText.set("Simple Action");
155 | break;
156 | case ActionType.FIRE_DIALOG_ACTION:
157 | lastActionText.set("Dialog Action");
158 | break;
159 | case ActionType.FIRE_REQUEST_ACTION:
160 | lastActionText.set("Request Action");
161 | break;
162 | }
163 | }
164 |
165 | @Override
166 | public void onActionError(@NonNull ActionArgs args, @Nullable Throwable throwable) {
167 | mCallback.showMessage("TestError: " + (throwable != null ? throwable.getMessage() : null));
168 | }
169 |
170 | @Override
171 | public void onActionDismiss(@NonNull ActionArgs args, @Nullable String reason) {
172 | mCallback.showMessage("Action dismissed. Reason: " + reason);
173 | }
174 |
175 | public void onSaveInstanceState(Bundle outState) {
176 | outState.putString(EXTRA_LAST_ACTION_TEXT, lastActionText.get());
177 | }
178 |
179 | public void onRestoreInstanceState(Bundle savedInstanceState) {
180 | lastActionText.set(savedInstanceState.getString(EXTRA_LAST_ACTION_TEXT));
181 | }
182 |
183 | @Override
184 | public void onDestroy() {
185 | super.onDestroy();
186 | actionHandler.cancelAll();
187 | }
188 |
189 | public interface Callback {
190 |
191 | void showMessage(String message);
192 |
193 | Callback EMPTY_CALLBACK = message -> { };
194 | }
195 | }
196 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/res/drawable/ic_announcement_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/res/drawable/ic_cloud_upload_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/res/drawable/ic_touch_app_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
20 |
21 |
22 |
23 |
24 |
25 |
28 |
29 |
30 |
37 |
38 |
43 |
44 |
48 |
49 |
58 |
59 |
66 |
67 |
74 |
75 |
82 |
83 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/res/layout/activity_second.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
28 |
29 |
40 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drstranges/ActionHandler/5ee1c61883e5e9e5039522788324a57fd51ac71e/samples/databinding/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/databinding/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drstranges/ActionHandler/5ee1c61883e5e9e5039522788324a57fd51ac71e/samples/databinding/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/databinding/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drstranges/ActionHandler/5ee1c61883e5e9e5039522788324a57fd51ac71e/samples/databinding/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/databinding/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drstranges/ActionHandler/5ee1c61883e5e9e5039522788324a57fd51ac71e/samples/databinding/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/databinding/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drstranges/ActionHandler/5ee1c61883e5e9e5039522788324a57fd51ac71e/samples/databinding/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/databinding/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
21 | 64dp
22 |
23 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | #3F51B5
20 | #303F9F
21 | #FF4081
22 |
23 | #EF5451
24 | #FFAB00
25 | #009D55
26 |
27 |
28 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 | 16dp
20 | 16dp
21 |
22 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ActionHandler
3 | Second Activity
4 | Action Fired! Model: %1$s
5 | Fire Intent Action
6 | Fire Simple Action
7 | Fire Dialog Action
8 | Fire Request Action
9 | Fire RxJava Request Action
10 | Oops. Action has ben intercepted!) Try one more time!)
11 | This is the dialog action message
12 | Are you sure? Model: %1$s
13 | Last successful action: %1$s
14 | Fire composite action
15 |
16 |
--------------------------------------------------------------------------------
/samples/databinding/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/samples/simple-handling/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/samples/simple-handling/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.compileSdkVersion
5 |
6 | dataBinding{
7 | enabled = false
8 | }
9 |
10 | defaultConfig {
11 | applicationId "com.drextended.actionhandler"
12 | minSdkVersion 21
13 | targetSdkVersion rootProject.ext.targetSdkVersion
14 | versionCode 1
15 | versionName "1.0"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | lintOptions {
24 | abortOnError false
25 | }
26 | compileOptions {
27 | sourceCompatibility 1.8
28 | targetCompatibility 1.8
29 | }
30 | }
31 |
32 | dependencies {
33 | implementation project(path: ':actionhandler')
34 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
35 |
36 | implementation "androidx.annotation:annotation:$x_annotation_version"
37 | implementation "androidx.appcompat:appcompat:$x_appcompat_version"
38 | implementation "io.reactivex.rxjava2:rxjava:$rxjava2_version"
39 | implementation "io.reactivex.rxjava2:rxandroid:$rxandroid_version"
40 | }
41 |
--------------------------------------------------------------------------------
/samples/simple-handling/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android_Env\android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/java/com/drextended/actionhandlersample/ActionType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandlersample;
18 |
19 | public class ActionType {
20 | public static final String OPEN_NEW_SCREEN = "open_new_screen";
21 | public static final String FIRE_ACTION = "fire_action";
22 | public static final String FIRE_DIALOG_ACTION = "fire_dialog_action";
23 | public static final String FIRE_REQUEST_ACTION = "fire_request_action";
24 | public static final String FIRE_COMPOSITE_ACTION = "composite_action";
25 | }
26 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/java/com/drextended/actionhandlersample/action/OpenSecondActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandlersample.action;
18 |
19 | import android.app.Activity;
20 | import android.content.ActivityNotFoundException;
21 | import android.content.Context;
22 | import android.content.Intent;
23 |
24 | import androidx.annotation.NonNull;
25 | import androidx.annotation.Nullable;
26 | import androidx.core.app.ActivityOptionsCompat;
27 | import android.view.View;
28 |
29 | import com.drextended.actionhandler.ActionArgs;
30 | import com.drextended.actionhandler.action.IntentAction;
31 | import com.drextended.actionhandlersample.activity.SecondActivity;
32 |
33 |
34 | public class OpenSecondActivity extends IntentAction {
35 | @Override
36 | public boolean isModelAccepted(Object model) {
37 | return model instanceof String;
38 | }
39 |
40 |
41 | @Nullable
42 | @Override
43 | public Intent getIntent(@NonNull ActionArgs args) {
44 | return SecondActivity.getIntent(args.params.getViewOrAppContext(), args.params.getModel(String.class));
45 | }
46 |
47 | @Override
48 | protected void startActivity(@NonNull Context context, @NonNull Intent intent, @NonNull ActionArgs args) throws ActivityNotFoundException {
49 | ActivityOptionsCompat transition = prepareTransition(args);
50 | if (transition != null) {
51 | context.startActivity(intent, transition.toBundle());
52 | } else {
53 | super.startActivity(context, intent, args);
54 | }
55 | }
56 |
57 | private ActivityOptionsCompat prepareTransition(@NonNull ActionArgs args) {
58 | View view = args.params.tryGetView();
59 | Activity activity = args.params.tryGetActivity();
60 |
61 | if (activity == null || view == null) return null;
62 | return ActivityOptionsCompat
63 | .makeSceneTransitionAnimation(activity, view, SecondActivity.TRANSITION_NAME);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/java/com/drextended/actionhandlersample/action/SampleRequestAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandlersample.action;
18 |
19 | import android.app.Activity;
20 | import android.content.Context;
21 | import android.os.Handler;
22 | import android.view.View;
23 | import android.widget.Toast;
24 |
25 | import androidx.annotation.NonNull;
26 | import androidx.annotation.Nullable;
27 |
28 | import com.drextended.actionhandler.ActionArgs;
29 | import com.drextended.actionhandler.ActionParams;
30 | import com.drextended.actionhandler.action.RequestAction;
31 | import com.drextended.actionhandlersample.R;
32 |
33 | public class SampleRequestAction extends RequestAction {
34 |
35 | private int mCount;
36 |
37 | public SampleRequestAction() {
38 | super(true, true);
39 | }
40 |
41 | @Override
42 | public boolean isModelAccepted(Object model) {
43 | return model instanceof String;
44 | }
45 |
46 | @Override
47 | protected String getDialogMessage(@NonNull ActionParams params) {
48 | return params.appContext.getString(R.string.action_request_dialog_message, params.model);
49 | }
50 |
51 | @Override
52 | protected void onMakeRequest(@NonNull ActionArgs args) {
53 | final Handler handler = new Handler();
54 | handler.postDelayed(() -> {
55 | Activity activity = args.params.tryGetActivity();
56 | if (activity != null && (activity.isFinishing() || activity.isDestroyed())) return;
57 | if (mCount++ % 3 == 0) {
58 | onResponseError(args, new Exception("Test Error!:) Just repeat this request!"));
59 | } else {
60 | onResponseSuccess(args, "Request has been done successfully");
61 | }
62 | }, 3000);
63 | }
64 |
65 | @Override
66 | protected void onResponseSuccess(@NonNull ActionArgs args, @Nullable String response) {
67 | super.onResponseSuccess(args, response);
68 | Toast.makeText(args.params.appContext, response, Toast.LENGTH_SHORT).show();
69 | }
70 |
71 | @Override
72 | protected void onResponseError(@NonNull ActionArgs args, @NonNull Throwable e) {
73 | super.onResponseError(args, e);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/java/com/drextended/actionhandlersample/action/ShowToastAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandlersample.action;
18 |
19 | import android.content.Context;
20 | import android.widget.Toast;
21 |
22 | import androidx.annotation.NonNull;
23 |
24 | import com.drextended.actionhandler.ActionArgs;
25 | import com.drextended.actionhandler.action.BaseAction;
26 | import com.drextended.actionhandlersample.R;
27 |
28 | public class ShowToastAction extends BaseAction {
29 |
30 | @Override
31 | public boolean isModelAccepted(Object model) {
32 | return model instanceof String;
33 | }
34 |
35 | @Override
36 | public void onFireAction(@NonNull ActionArgs args) {
37 | Context appContext = args.params.appContext;
38 |
39 | Toast.makeText(
40 | appContext,
41 | appContext.getString(R.string.toast_message, args.params.model),
42 | Toast.LENGTH_SHORT
43 | ).show();
44 |
45 | notifyOnActionFired(args);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/java/com/drextended/actionhandlersample/action/SimpleAnimationAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandlersample.action;
18 |
19 | import android.animation.ObjectAnimator;
20 | import android.content.Context;
21 |
22 | import androidx.annotation.NonNull;
23 | import androidx.annotation.Nullable;
24 | import android.view.View;
25 |
26 | import com.drextended.actionhandler.ActionArgs;
27 | import com.drextended.actionhandler.action.Action;
28 | import com.drextended.actionhandler.action.BaseAction;
29 |
30 | public class SimpleAnimationAction extends BaseAction {
31 |
32 | @Override
33 | public boolean isModelAccepted(Object model) {
34 | return true;
35 | }
36 |
37 | @Override
38 | public void onFireAction(@NonNull ActionArgs args) {
39 | View view = args.params.tryGetView();
40 | if (view == null) {
41 | notifyOnActionDismiss(args, "No view");
42 | return;
43 | }
44 | ObjectAnimator
45 | .ofFloat(view, "translationX", 0, 25, -25, 25, -25, 15, -15, 6, -6, 0)
46 | .setDuration(200)
47 | .start();
48 | notifyOnActionFired(args);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/java/com/drextended/actionhandlersample/action/TrackAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandlersample.action;
18 |
19 | import android.util.Log;
20 |
21 | import androidx.annotation.NonNull;
22 |
23 | import com.drextended.actionhandler.ActionArgs;
24 | import com.drextended.actionhandler.action.Action;
25 |
26 | public class TrackAction implements Action {
27 |
28 | @Override
29 | public boolean isModelAccepted(Object model) {
30 | return true;
31 | }
32 |
33 | @Override
34 | public void onFireAction(@NonNull ActionArgs args) {
35 | Log.d("tagTrackAction", "onFireAction: " + args.fireActionType + ", model: " + args.params.model);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/java/com/drextended/actionhandlersample/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandlersample.activity;
18 |
19 | import android.os.Bundle;
20 | import android.widget.TextView;
21 | import android.widget.Toast;
22 |
23 | import androidx.annotation.NonNull;
24 | import androidx.annotation.Nullable;
25 | import androidx.appcompat.app.AppCompatActivity;
26 |
27 | import com.drextended.actionhandler.ActionArgs;
28 | import com.drextended.actionhandler.ActionHandler;
29 | import com.drextended.actionhandler.ActionParams;
30 | import com.drextended.actionhandler.action.CompositeAction;
31 | import com.drextended.actionhandler.action.CompositeAction.ActionItem;
32 | import com.drextended.actionhandler.action.DialogAction;
33 | import com.drextended.actionhandler.listener.ActionInterceptor;
34 | import com.drextended.actionhandler.listener.OnActionDismissListener;
35 | import com.drextended.actionhandler.listener.OnActionErrorListener;
36 | import com.drextended.actionhandler.listener.OnActionFiredListener;
37 | import com.drextended.actionhandler.util.ViewOnActionClickListener;
38 | import com.drextended.actionhandlersample.ActionType;
39 | import com.drextended.actionhandlersample.R;
40 | import com.drextended.actionhandlersample.action.OpenSecondActivity;
41 | import com.drextended.actionhandlersample.action.SampleRequestAction;
42 | import com.drextended.actionhandlersample.action.ShowToastAction;
43 | import com.drextended.actionhandlersample.action.SimpleAnimationAction;
44 | import com.drextended.actionhandlersample.action.TrackAction;
45 |
46 | public class MainActivity extends AppCompatActivity implements OnActionFiredListener, ActionInterceptor, OnActionErrorListener, OnActionDismissListener {
47 |
48 | private static final String EXTRA_LAST_ACTION_TEXT = "EXTRA_LAST_ACTION_TEXT";
49 |
50 | private TextView mLabelView;
51 | private ActionHandler mActionHandler;
52 | private int mClickCount;
53 |
54 | @Override
55 | protected void onCreate(Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 | setContentView(R.layout.activity_main);
58 |
59 | ShowToastAction showToastAction = new ShowToastAction();
60 | mActionHandler = new ActionHandler.Builder()
61 | .addAction(null, new SimpleAnimationAction()) // Applied for any actionType
62 | .addAction(null, new TrackAction()) // Applied for any actionType
63 | .addAction(ActionType.OPEN_NEW_SCREEN, new OpenSecondActivity())
64 | // .addAction(ActionType.OPEN_NEW_SCREEN, IntentAction.from(SecondActivity.getIntent(this, null)))
65 | .addAction(ActionType.FIRE_ACTION, showToastAction)
66 | .addAction(ActionType.FIRE_DIALOG_ACTION, DialogAction.wrap(getString(R.string.action_dialog_message), showToastAction))
67 | .addAction(ActionType.FIRE_REQUEST_ACTION, new SampleRequestAction())
68 | .addAction(ActionType.FIRE_COMPOSITE_ACTION,
69 | new CompositeAction<>((ctx, model) -> "Title (" + model + ")",
70 | new ActionItem(ActionType.OPEN_NEW_SCREEN, new OpenSecondActivity(), R.drawable.ic_touch_app_black_24dp, 0, R.string.fire_intent_action),
71 | new ActionItem(ActionType.FIRE_ACTION, showToastAction, R.drawable.ic_announcement_black_24dp, R.color.greenLight, R.string.fire_simple_action),
72 | new ActionItem(ActionType.FIRE_DIALOG_ACTION, DialogAction.wrap(getString(R.string.action_dialog_message), showToastAction), R.drawable.ic_announcement_black_24dp, R.color.amber, R.string.fire_dialog_action),
73 | new ActionItem(ActionType.FIRE_REQUEST_ACTION, new SampleRequestAction(), R.drawable.ic_cloud_upload_black_24dp, R.color.red, R.string.fire_request_action)
74 | ))
75 | .addActionInterceptor(this)
76 | .addActionFiredListener(this)
77 | .addActionErrorListener(this)
78 | .addActionDismissListener(this)
79 | .build();
80 |
81 | initView();
82 | }
83 |
84 | private void initView() {
85 | mLabelView = findViewById(R.id.label);
86 |
87 | findViewById(R.id.button1).setOnClickListener(
88 | v -> mActionHandler.onActionClick(v, ActionType.OPEN_NEW_SCREEN, getSampleModel(), null)
89 | );
90 |
91 | findViewById(R.id.button2).setOnClickListener(
92 | new ViewOnActionClickListener(mActionHandler, getSampleModel(), ActionType.FIRE_ACTION)
93 | );
94 |
95 | findViewById(R.id.button3).setOnClickListener(
96 | new ViewOnActionClickListener(mActionHandler, getSampleModel(), ActionType.FIRE_DIALOG_ACTION)
97 | );
98 |
99 | findViewById(R.id.button4).setOnClickListener(
100 | new ViewOnActionClickListener(mActionHandler, getSampleModel(), ActionType.FIRE_REQUEST_ACTION)
101 | );
102 |
103 | findViewById(R.id.button5).setOnClickListener(
104 | new ViewOnActionClickListener(mActionHandler, getSampleModel(), ActionType.FIRE_COMPOSITE_ACTION)
105 | );
106 |
107 | findViewById(R.id.button5).setOnLongClickListener(
108 | new ViewOnActionClickListener(mActionHandler, getSampleModel(), ActionType.FIRE_DIALOG_ACTION)
109 | );
110 | }
111 |
112 | @NonNull
113 | private String getSampleModel() {
114 | return "Time (" + System.currentTimeMillis() + ")";
115 | }
116 |
117 | @Override
118 | public boolean onInterceptAction(@NonNull ActionParams params) {
119 | switch (params.actionType) {
120 | case ActionType.OPEN_NEW_SCREEN:
121 | final boolean consumed = mClickCount++ % 7 == 0;
122 | if (consumed) {
123 | Toast.makeText(getApplicationContext(), R.string.message_action_intercepted, Toast.LENGTH_SHORT).show();
124 | }
125 | return consumed;
126 | // case ActionType.FIRE_ACTION:
127 | // case ActionType.FIRE_DIALOG_ACTION:
128 | // case ActionType.FIRE_REQUEST_ACTION:
129 | }
130 | return false;
131 | }
132 |
133 | @Override
134 | public void onActionFired(@NonNull ActionArgs args, @Nullable Object result) {
135 | if (args.fireActionType == null) return;
136 | switch (args.fireActionType) {
137 | case ActionType.OPEN_NEW_SCREEN:
138 | setLastActionText("Intent Action");
139 | break;
140 | case ActionType.FIRE_ACTION:
141 | setLastActionText("Simple Action");
142 | break;
143 | case ActionType.FIRE_DIALOG_ACTION:
144 | setLastActionText("Dialog Action");
145 | break;
146 | case ActionType.FIRE_REQUEST_ACTION:
147 | setLastActionText("Request Action");
148 | break;
149 | }
150 | }
151 |
152 | @Override
153 | public void onActionError(@NonNull ActionArgs args, @Nullable Throwable throwable) {
154 | Toast.makeText(
155 | this,
156 | throwable == null ? "Error" : throwable.getMessage(),
157 | Toast.LENGTH_SHORT
158 | ).show();
159 | }
160 |
161 | @Override
162 | public void onActionDismiss(@NonNull ActionArgs args, @Nullable String reason) {
163 | Toast.makeText(this, "Action dismissed. Reason: " + reason, Toast.LENGTH_SHORT).show();
164 | }
165 |
166 | private void setLastActionText(String label) {
167 | mLabelView.setText(getString(R.string.last_action_label, label));
168 | }
169 |
170 | @Override
171 | protected void onSaveInstanceState(Bundle outState) {
172 | super.onSaveInstanceState(outState);
173 | outState.putString(EXTRA_LAST_ACTION_TEXT, mLabelView.getText().toString());
174 | }
175 |
176 | @Override
177 | protected void onRestoreInstanceState(Bundle savedInstanceState) {
178 | super.onRestoreInstanceState(savedInstanceState);
179 | setLastActionText(savedInstanceState.getString(EXTRA_LAST_ACTION_TEXT));
180 | }
181 |
182 | @Override
183 | protected void onDestroy() {
184 | mActionHandler.cancelAll();
185 | super.onDestroy();
186 | }
187 | }
188 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/java/com/drextended/actionhandlersample/activity/SecondActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright Roman Donchenko. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.drextended.actionhandlersample.activity;
18 |
19 | import android.content.Context;
20 | import android.content.Intent;
21 | import android.os.Bundle;
22 | import androidx.appcompat.app.AppCompatActivity;
23 | import android.view.MenuItem;
24 |
25 | import com.drextended.actionhandlersample.R;
26 |
27 | public class SecondActivity extends AppCompatActivity {
28 |
29 | private static final String ARG_TITLE = "arg_title";
30 | public static final String TRANSITION_NAME = "transition_name";
31 | private String mTitle;
32 |
33 | public static Intent getIntent(Context context, String title) {
34 | final Intent intent = new Intent(context, SecondActivity.class);
35 | intent.putExtra(ARG_TITLE, title);
36 | return intent;
37 | }
38 |
39 | private void initArgs() {
40 | final Bundle args = getIntent().getExtras();
41 | if (args != null) mTitle = args.getString(ARG_TITLE);
42 | }
43 |
44 | @Override
45 | protected void onCreate(Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 | setContentView(R.layout.activity_second);
48 | initArgs();
49 | setTitle(mTitle);
50 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
51 | }
52 |
53 | @Override
54 | public boolean onOptionsItemSelected(MenuItem item) {
55 | // Respond to the action bar's Up/Home button
56 | if (item.getItemId() == android.R.id.home) {
57 | supportFinishAfterTransition();
58 | return true;
59 | }
60 | return super.onOptionsItemSelected(item);
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/res/drawable/ic_announcement_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/res/drawable/ic_cloud_upload_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/res/drawable/ic_touch_app_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
27 |
28 |
33 |
34 |
38 |
39 |
45 |
46 |
51 |
52 |
57 |
58 |
63 |
64 |
69 |
70 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/res/layout/activity_second.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
28 |
29 |
39 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drstranges/ActionHandler/5ee1c61883e5e9e5039522788324a57fd51ac71e/samples/simple-handling/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drstranges/ActionHandler/5ee1c61883e5e9e5039522788324a57fd51ac71e/samples/simple-handling/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drstranges/ActionHandler/5ee1c61883e5e9e5039522788324a57fd51ac71e/samples/simple-handling/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drstranges/ActionHandler/5ee1c61883e5e9e5039522788324a57fd51ac71e/samples/simple-handling/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/drstranges/ActionHandler/5ee1c61883e5e9e5039522788324a57fd51ac71e/samples/simple-handling/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #EF5451
8 | #FFAB00
9 | #009D55
10 |
11 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ActionHandler
3 | Second Activity
4 | Action Fired! Model: %1$s
5 | Fire Intent Action
6 | Fire Simple Action
7 | Fire Dialog Action
8 | Fire Request Action
9 | Oops. Action has ben intercepted!) Try one more time!)
10 | This is the dialog action message
11 | Are you sure? Model: %1$s
12 | Last successful action: %1$s
13 | Fire composite action
14 |
15 |
--------------------------------------------------------------------------------
/samples/simple-handling/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':actionhandler', ':samples:simple-handling', ':samples:databinding'
2 |
--------------------------------------------------------------------------------