diff --git a/src/main/java/ru/touchin/roboswag/components/navigation/SimpleActionBarDrawerToggle.java b/src/main/java/ru/touchin/roboswag/components/navigation/SimpleActionBarDrawerToggle.java index 423fc98..e2d88f6 100644 --- a/src/main/java/ru/touchin/roboswag/components/navigation/SimpleActionBarDrawerToggle.java +++ b/src/main/java/ru/touchin/roboswag/components/navigation/SimpleActionBarDrawerToggle.java @@ -29,6 +29,7 @@ import android.view.MenuItem; import android.view.View; import ru.touchin.roboswag.components.navigation.activities.BaseActivity; +import ru.touchin.roboswag.components.utils.UiUtils; /** * Created by Gavriil Sitnikov on 11/03/16. @@ -206,7 +207,7 @@ public class SimpleActionBarDrawerToggle extends ActionBarDrawerToggle @Override public void onDrawerClosed(@NonNull final View view) { if (isInvalidateOptionsMenuSupported) { - activity.supportInvalidateOptionsMenu(); + activity.invalidateOptionsMenu(); } } @@ -221,9 +222,9 @@ public class SimpleActionBarDrawerToggle extends ActionBarDrawerToggle @Override public void onDrawerOpened(@NonNull final View drawerView) { - activity.hideSoftInput(); + UiUtils.OfViews.hideSoftInput(activity); if (isInvalidateOptionsMenuSupported) { - activity.supportInvalidateOptionsMenu(); + activity.invalidateOptionsMenu(); } } @@ -245,4 +246,4 @@ public class SimpleActionBarDrawerToggle extends ActionBarDrawerToggle super.onDrawerSlide(drawerView, this.slideOffset); } -} \ No newline at end of file +} diff --git a/src/main/java/ru/touchin/roboswag/components/navigation/activities/BaseActivity.java b/src/main/java/ru/touchin/roboswag/components/navigation/activities/BaseActivity.java index 762d926..974fa46 100644 --- a/src/main/java/ru/touchin/roboswag/components/navigation/activities/BaseActivity.java +++ b/src/main/java/ru/touchin/roboswag/components/navigation/activities/BaseActivity.java @@ -19,21 +19,14 @@ package ru.touchin.roboswag.components.navigation.activities; -import android.app.Activity; import android.content.Intent; -import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.support.annotation.ColorInt; -import android.support.annotation.ColorRes; -import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.v4.content.ContextCompat; +import android.support.v4.util.ArraySet; import android.support.v7.app.AppCompatActivity; -import android.view.View; -import android.view.inputmethod.InputMethodManager; -import java.util.ArrayList; +import java.util.Set; import ru.touchin.roboswag.components.utils.UiUtils; import ru.touchin.roboswag.core.log.Lc; @@ -45,7 +38,7 @@ import ru.touchin.roboswag.core.log.Lc; public abstract class BaseActivity extends AppCompatActivity { @NonNull - private final ArrayList onBackPressedListeners = new ArrayList<>(); + private final Set onBackPressedListeners = new ArraySet<>(); @Override protected void onCreate(@Nullable final Bundle savedInstanceState) { @@ -101,59 +94,6 @@ public abstract class BaseActivity extends AppCompatActivity { super.onDestroy(); } - /** - * Hides device keyboard that is showing over {@link Activity}. - * Do NOT use it if keyboard is over {@link android.app.Dialog} - it won't work as they have different {@link Activity#getWindow()}. - */ - public void hideSoftInput() { - if (getCurrentFocus() == null) { - return; - } - final InputMethodManager inputManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); - inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); - getWindow().getDecorView().requestFocus(); - } - - /** - * Shows device keyboard over {@link Activity} and focuses {@link View}. - * Do NOT use it if keyboard is over {@link android.app.Dialog} - it won't work as they have different {@link Activity#getWindow()}. - * Do NOT use it if you are not sure that view is already added on screen. - * Better use it onStart of element if view is part of it or onConfigureNavigation if view is part of navigation. - * - * @param view View to get focus for input from keyboard. - */ - public void showSoftInput(@NonNull final View view) { - view.requestFocus(); - final InputMethodManager inputManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); - inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); - } - - /** - * Return the color value associated with a particular resource ID. - * Starting in {@link android.os.Build.VERSION_CODES#M}, the returned - * color will be styled for the specified Context's theme. - * - * @param resId The resource id to search for data; - * @return int A single color value in the form 0xAARRGGBB. - */ - @ColorInt - public int getColorCompat(@ColorRes final int resId) { - return ContextCompat.getColor(this, resId); - } - - /** - * Returns a drawable object associated with a particular resource ID. - * Starting in {@link android.os.Build.VERSION_CODES#LOLLIPOP}, the - * returned drawable will be styled for the specified Context's theme. - * - * @param resId The resource id to search for data; - * @return Drawable An object that can be used to draw this resource. - */ - @Nullable - public Drawable getDrawableCompat(@DrawableRes final int resId) { - return ContextCompat.getDrawable(this, resId); - } - public void addOnBackPressedListener(@NonNull final OnBackPressedListener onBackPressedListener) { onBackPressedListeners.add(onBackPressedListener); } @@ -169,12 +109,7 @@ public abstract class BaseActivity extends AppCompatActivity { return; } } - - if (getSupportFragmentManager().getBackStackEntryCount() <= 1) { - supportFinishAfterTransition(); - } else { - getSupportFragmentManager().popBackStack(); - } + super.onBackPressed(); } /* diff --git a/src/main/java/ru/touchin/roboswag/components/navigation/fragments/ViewControllerFragment.java b/src/main/java/ru/touchin/roboswag/components/navigation/fragments/ViewControllerFragment.java index 91e4c87..68f9be0 100644 --- a/src/main/java/ru/touchin/roboswag/components/navigation/fragments/ViewControllerFragment.java +++ b/src/main/java/ru/touchin/roboswag/components/navigation/fragments/ViewControllerFragment.java @@ -51,7 +51,7 @@ import ru.touchin.roboswag.core.utils.ShouldNotHappenException; * @param Type of object which is representing it's fragment state; * @param Type of {@link FragmentActivity} where fragment could be attached to. */ -public class ViewControllerFragment extends ViewFragment { +public class ViewControllerFragment extends ViewFragment { private static final String VIEW_CONTROLLER_CLASS_EXTRA = "VIEW_CONTROLLER_CLASS_EXTRA"; private static final String VIEW_CONTROLLER_STATE_EXTRA = "VIEW_CONTROLLER_STATE_EXTRA"; @@ -105,7 +105,7 @@ public class ViewControllerFragment, TState>> viewControllerClass; + private Class, TState>> viewControllerClass; private TState state; @Nullable private ActivityResult pendingActivityResult; @@ -127,7 +127,7 @@ public class ViewControllerFragment, TState>>) + viewControllerClass = (Class, TState>>) getArguments().getSerializable(VIEW_CONTROLLER_CLASS_EXTRA); state = savedInstanceState != null ? savedInstanceState.getParcelable(VIEW_CONTROLLER_STATE_EXTRA) diff --git a/src/main/java/ru/touchin/roboswag/components/navigation/viewcontrollers/DefaultViewController.kt b/src/main/java/ru/touchin/roboswag/components/navigation/viewcontrollers/DefaultViewController.kt index 41326ba..6b5014b 100644 --- a/src/main/java/ru/touchin/roboswag/components/navigation/viewcontrollers/DefaultViewController.kt +++ b/src/main/java/ru/touchin/roboswag/components/navigation/viewcontrollers/DefaultViewController.kt @@ -10,7 +10,7 @@ abstract class DefaultViewController, TState>( +) : ViewController, TState>( creationContext, savedInstanceState ) { diff --git a/src/main/java/ru/touchin/roboswag/components/navigation/viewcontrollers/ViewController.java b/src/main/java/ru/touchin/roboswag/components/navigation/viewcontrollers/ViewController.java index ab3a618..42ecaf5 100644 --- a/src/main/java/ru/touchin/roboswag/components/navigation/viewcontrollers/ViewController.java +++ b/src/main/java/ru/touchin/roboswag/components/navigation/viewcontrollers/ViewController.java @@ -51,7 +51,7 @@ import ru.touchin.roboswag.core.log.Lc; */ public class ViewController< TActivity extends FragmentActivity, - TFragment extends ViewControllerFragment, + TFragment extends ViewControllerFragment, TState extends Parcelable> implements LifecycleOwner { @NonNull @@ -276,7 +276,7 @@ public class ViewController< * Callback from parent fragment. */ public void onActivityResult(final int requestCode, final int resultCode, @Nullable final Intent data) { - UiUtils.UI_LIFECYCLE_LC_GROUP.i(Lc.getCodePoint(this)); + // do nothing } /** diff --git a/src/main/java/ru/touchin/roboswag/components/navigation/viewcontrollers/ViewControllerNavigation.kt b/src/main/java/ru/touchin/roboswag/components/navigation/viewcontrollers/ViewControllerNavigation.kt index dde03c9..103c9f7 100644 --- a/src/main/java/ru/touchin/roboswag/components/navigation/viewcontrollers/ViewControllerNavigation.kt +++ b/src/main/java/ru/touchin/roboswag/components/navigation/viewcontrollers/ViewControllerNavigation.kt @@ -54,7 +54,7 @@ open class ViewControllerNavigation( * @param TState Type of state of fragment. */ fun pushViewController( - viewControllerClass: Class, TState>>, + viewControllerClass: Class, TState>>, state: TState, addToStack: Boolean = true, transactionSetup: ((FragmentTransaction) -> Unit)? = null @@ -82,7 +82,7 @@ open class ViewControllerNavigation( * @param TTargetFragment Type of target fragment. */ fun pushViewControllerForResult( - viewControllerClass: Class, TState>>, + viewControllerClass: Class, TState>>, state: TState, targetFragment: TTargetFragment, targetRequestCode: Int, @@ -109,7 +109,7 @@ open class ViewControllerNavigation( * @param TState Type of state of fragment. */ fun setViewControllerAsTop( - viewControllerClass: Class, TState>>, + viewControllerClass: Class, TState>>, state: TState, transactionSetup: ((FragmentTransaction) -> Unit)? = null ) { @@ -134,7 +134,7 @@ open class ViewControllerNavigation( * @param TState Type of state of fragment. */ fun setInitialViewController( - viewControllerClass: Class, TState>>, + viewControllerClass: Class, TState>>, state: TState, transactionSetup: ((FragmentTransaction) -> Unit)? = null ) { diff --git a/src/main/java/ru/touchin/roboswag/components/utils/UiUtils.java b/src/main/java/ru/touchin/roboswag/components/utils/UiUtils.java index 985e9e2..9343d00 100644 --- a/src/main/java/ru/touchin/roboswag/components/utils/UiUtils.java +++ b/src/main/java/ru/touchin/roboswag/components/utils/UiUtils.java @@ -41,6 +41,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; import io.reactivex.functions.Action; import io.reactivex.functions.Consumer; @@ -307,6 +308,42 @@ public final class UiUtils { } } + /** + * Hides device keyboard for target activity. + */ + public static void hideSoftInput(@NonNull final Activity activity) { + final View focusedView = activity.getCurrentFocus(); + if (focusedView != null) { + hideSoftInput(focusedView); + } + } + + /** + * Hides device keyboard for target view. + */ + public static void hideSoftInput(@NonNull final View view) { + view.clearFocus(); + final InputMethodManager inputManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + if (inputManager != null) { + inputManager.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } + + /** + * Shows device keyboard over {@link Activity} and focuses {@link View}. + * Do NOT use it if keyboard is over {@link android.app.Dialog} - it won't work as they have different {@link Activity#getWindow()}. + * Do NOT use it if you are not sure that view is already added on screen. + * + * @param view View to get focus for input from keyboard. + */ + public static void showSoftInput(@NonNull final View view) { + view.requestFocus(); + final InputMethodManager inputManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + if (inputManager != null) { + inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); + } + } + private OfViews() { }