ViewHolder.context extension, ViewController startActivity methods
This commit is contained in:
parent
b64452b086
commit
9508946b5a
|
|
@ -1,5 +1,6 @@
|
|||
package ru.touchin.roboswag.components.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.support.annotation.ColorInt
|
||||
|
|
@ -13,15 +14,18 @@ import android.view.View
|
|||
|
||||
fun <T : View> RecyclerView.ViewHolder.findViewById(@IdRes resId: Int): T = itemView.findViewById(resId)
|
||||
|
||||
fun RecyclerView.ViewHolder.getText(@StringRes resId: Int): CharSequence = itemView.context.getText(resId)
|
||||
val RecyclerView.ViewHolder.context: Context
|
||||
get() = itemView.context
|
||||
|
||||
fun RecyclerView.ViewHolder.getString(@StringRes resId: Int): String = itemView.context.getString(resId)
|
||||
fun RecyclerView.ViewHolder.getText(@StringRes resId: Int): CharSequence = context.getText(resId)
|
||||
|
||||
fun RecyclerView.ViewHolder.getString(@StringRes resId: Int, vararg args: Any): String = itemView.context.getString(resId, args)
|
||||
fun RecyclerView.ViewHolder.getString(@StringRes resId: Int): String = context.getString(resId)
|
||||
|
||||
fun RecyclerView.ViewHolder.getString(@StringRes resId: Int, vararg args: Any): String = context.getString(resId, args)
|
||||
|
||||
@ColorInt
|
||||
fun RecyclerView.ViewHolder.getColor(@ColorRes resId: Int): Int = ContextCompat.getColor(itemView.context, resId)
|
||||
fun RecyclerView.ViewHolder.getColor(@ColorRes resId: Int): Int = ContextCompat.getColor(context, resId)
|
||||
|
||||
fun RecyclerView.ViewHolder.getColorStateList(@ColorRes resId: Int): ColorStateList? = ContextCompat.getColorStateList(itemView.context, resId)
|
||||
fun RecyclerView.ViewHolder.getColorStateList(@ColorRes resId: Int): ColorStateList? = ContextCompat.getColorStateList(context, resId)
|
||||
|
||||
fun RecyclerView.ViewHolder.getDrawable(@DrawableRes resId: Int): Drawable? = ContextCompat.getDrawable(itemView.context, resId)
|
||||
fun RecyclerView.ViewHolder.getDrawable(@DrawableRes resId: Int): Drawable? = ContextCompat.getDrawable(context, resId)
|
||||
|
|
|
|||
|
|
@ -94,16 +94,6 @@ public class ViewController<
|
|||
return activity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns state from fragment.
|
||||
*
|
||||
* @return Returns state.
|
||||
*/
|
||||
@NonNull
|
||||
public final TState getState() {
|
||||
return fragment.getState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns fragment where {@link ViewController} could be.
|
||||
*
|
||||
|
|
@ -114,6 +104,16 @@ public class ViewController<
|
|||
return fragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns state from fragment.
|
||||
*
|
||||
* @return Returns state.
|
||||
*/
|
||||
@NonNull
|
||||
protected final TState getState() {
|
||||
return fragment.getState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns view instantiated in {@link #getFragment()} fragment attached to {@link #getActivity()} activity.
|
||||
* Use it to inflate your views into at construction of this {@link ViewController}.
|
||||
|
|
@ -121,7 +121,7 @@ public class ViewController<
|
|||
* @return Returns view.
|
||||
*/
|
||||
@NonNull
|
||||
public final ViewGroup getContainer() {
|
||||
protected final ViewGroup getContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
|
|
@ -131,7 +131,7 @@ public class ViewController<
|
|||
*
|
||||
* @param layoutResId Resource ID to be inflated.
|
||||
*/
|
||||
public final void setContentView(@LayoutRes final int layoutResId) {
|
||||
protected final void setContentView(@LayoutRes final int layoutResId) {
|
||||
if (getContainer().getChildCount() > 0) {
|
||||
getContainer().removeAllViews();
|
||||
}
|
||||
|
|
@ -144,7 +144,7 @@ public class ViewController<
|
|||
*
|
||||
* @param view The desired content to display.
|
||||
*/
|
||||
public final void setContentView(@NonNull final View view) {
|
||||
protected final void setContentView(@NonNull final View view) {
|
||||
setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
}
|
||||
|
||||
|
|
@ -155,7 +155,7 @@ public class ViewController<
|
|||
* @param view The desired content to display;
|
||||
* @param layoutParams Layout parameters for the view.
|
||||
*/
|
||||
public final void setContentView(@NonNull final View view, @NonNull final ViewGroup.LayoutParams layoutParams) {
|
||||
protected final void setContentView(@NonNull final View view, @NonNull final ViewGroup.LayoutParams layoutParams) {
|
||||
if (getContainer().getChildCount() > 0) {
|
||||
getContainer().removeAllViews();
|
||||
}
|
||||
|
|
@ -250,6 +250,14 @@ public class ViewController<
|
|||
return ContextCompat.getDrawable(activity, resId);
|
||||
}
|
||||
|
||||
public final void startActivity(@NonNull final Intent intent) {
|
||||
fragment.startActivity(intent);
|
||||
}
|
||||
|
||||
public final void startActivityForResult(@NonNull final Intent intent, final int requestCode) {
|
||||
fragment.startActivityForResult(intent, requestCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls when activity configuring ActionBar, Toolbar, Sidebar etc.
|
||||
* If it will be called or not depends on {@link Fragment#hasOptionsMenu()} and {@link Fragment#isMenuVisible()}.
|
||||
|
|
|
|||
Loading…
Reference in New Issue