diff --git a/app/src/main/kotlin/io/armcha/ribble/App.kt b/app/src/main/kotlin/io/armcha/ribble/App.kt index 3e88ab5..b7ba2f2 100644 --- a/app/src/main/kotlin/io/armcha/ribble/App.kt +++ b/app/src/main/kotlin/io/armcha/ribble/App.kt @@ -7,14 +7,14 @@ import com.squareup.leakcanary.LeakCanary import io.armcha.ribble.di.component.ApplicationComponent import io.armcha.ribble.di.component.DaggerApplicationComponent import io.armcha.ribble.di.module.ApplicationModule -import io.armcha.ribble.presentation.utils.extensions.nonSafeLazy +import io.armcha.ribble.presentation.utils.extensions.unSafeLazy /** * Created by Chatikyan on 29.07.2017. */ class App : Application() { - val applicationComponent: ApplicationComponent by nonSafeLazy { + val applicationComponent: ApplicationComponent by unSafeLazy { DaggerApplicationComponent.builder() .applicationModule(ApplicationModule(this)) .build() diff --git a/app/src/main/kotlin/io/armcha/ribble/data/pref/Preferences.kt b/app/src/main/kotlin/io/armcha/ribble/data/pref/Preferences.kt index 4159f6c..e10ec06 100644 --- a/app/src/main/kotlin/io/armcha/ribble/data/pref/Preferences.kt +++ b/app/src/main/kotlin/io/armcha/ribble/data/pref/Preferences.kt @@ -6,7 +6,7 @@ import android.content.Context import android.content.SharedPreferences import io.armcha.ribble.data.network.ApiConstants import io.armcha.ribble.presentation.utils.extensions.emptyString -import io.armcha.ribble.presentation.utils.extensions.nonSafeLazy +import io.armcha.ribble.presentation.utils.extensions.unSafeLazy import javax.inject.Inject import javax.inject.Singleton @@ -21,7 +21,7 @@ class Preferences @Inject constructor(app: Application) { private val USER_LOGGED_IN = "user_logged_in" private val USER_TOKEN = "user_token" - private val sharedPreferences by nonSafeLazy { + private val sharedPreferences by unSafeLazy { app.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE) } val isUserLoggedIn diff --git a/app/src/main/kotlin/io/armcha/ribble/presentation/base_mvp/base/BaseActivity.kt b/app/src/main/kotlin/io/armcha/ribble/presentation/base_mvp/base/BaseActivity.kt index 5bd0d4d..73cf56c 100644 --- a/app/src/main/kotlin/io/armcha/ribble/presentation/base_mvp/base/BaseActivity.kt +++ b/app/src/main/kotlin/io/armcha/ribble/presentation/base_mvp/base/BaseActivity.kt @@ -11,7 +11,7 @@ import io.armcha.ribble.di.module.ActivityModule import io.armcha.ribble.presentation.navigation.Navigator import io.armcha.ribble.presentation.utils.S import io.armcha.ribble.presentation.utils.extensions.emptyString -import io.armcha.ribble.presentation.utils.extensions.nonSafeLazy +import io.armcha.ribble.presentation.utils.extensions.unSafeLazy import io.armcha.ribble.presentation.widget.MaterialDialog import javax.inject.Inject @@ -26,7 +26,7 @@ abstract class BaseActivity private var dialog: MaterialDialog? = null - val activityComponent: ActivityComponent by nonSafeLazy { + val activityComponent: ActivityComponent by unSafeLazy { getAppComponent().plus(ActivityModule(this)) } diff --git a/app/src/main/kotlin/io/armcha/ribble/presentation/screen/shot_detail/ShotDetailFragment.kt b/app/src/main/kotlin/io/armcha/ribble/presentation/screen/shot_detail/ShotDetailFragment.kt index 7fed8cc..645cb0a 100644 --- a/app/src/main/kotlin/io/armcha/ribble/presentation/screen/shot_detail/ShotDetailFragment.kt +++ b/app/src/main/kotlin/io/armcha/ribble/presentation/screen/shot_detail/ShotDetailFragment.kt @@ -3,7 +3,6 @@ package io.armcha.ribble.presentation.screen.shot_detail import android.animation.StateListAnimator import android.annotation.SuppressLint -import android.content.Context import android.os.Bundle import android.support.design.widget.AppBarLayout import android.support.v7.widget.LinearLayoutManager @@ -17,6 +16,7 @@ import io.armcha.ribble.presentation.base_mvp.base.BaseFragment import io.armcha.ribble.presentation.utils.C import io.armcha.ribble.presentation.utils.L import io.armcha.ribble.presentation.utils.S +import io.armcha.ribble.presentation.utils.delegates.args import io.armcha.ribble.presentation.utils.extensions.* import io.armcha.ribble.presentation.utils.glide.TransformationType import io.armcha.ribble.presentation.utils.glide.load @@ -29,9 +29,7 @@ import javax.inject.Inject class ShotDetailFragment : BaseFragment(), ShotDetailContract.View { companion object { - const val SHOT_EXTRA_KEY = "shot_extra_key" - - fun getBundle(shot: Shot?) = Bundle().apply { putParcelable(SHOT_EXTRA_KEY, shot) } + fun getBundle(shot: Shot?) = Bundle().apply { putParcelable("shot", shot) } } private val items = intArrayOf(R.drawable.heart_full, R.drawable.eye, R.drawable.bucket) @@ -40,7 +38,8 @@ class ShotDetailFragment : BaseFragment? = null - private lateinit var shot: Shot + + val shot: Shot by args() override fun injectDependencies() { activityComponent.inject(this) @@ -50,11 +49,6 @@ class ShotDetailFragment : BaseFragment Fragment.args() = object : ReadOnlyProperty { + + private var value: VALUE? = null + + override fun getValue(thisRef: Fragment, property: KProperty<*>): VALUE { + if (value.isNull) { + value = arguments[property.name] as VALUE + } + return value!! + } +} + + diff --git a/app/src/main/kotlin/io/armcha/ribble/presentation/utils/extensions/BundleDelegate.kt b/app/src/main/kotlin/io/armcha/ribble/presentation/utils/extensions/BundleDelegate.kt deleted file mode 100644 index 81c1f48..0000000 --- a/app/src/main/kotlin/io/armcha/ribble/presentation/utils/extensions/BundleDelegate.kt +++ /dev/null @@ -1,34 +0,0 @@ -package io.armcha.ribble.presentation.utils.extensions - -import android.os.Parcelable -import android.support.v4.app.Fragment -import java.io.Serializable -import kotlin.properties.ReadWriteProperty -import kotlin.reflect.KProperty - -/** - * Created by Chatikyan on 30.09.2017. - */ -object BundleDelegate { - - inline fun arguments(): ReadWriteProperty { - return object : ReadWriteProperty { - override fun getValue(thisRef: Fragment, property: KProperty<*>) - = thisRef.arguments[property.name] as V - - override fun setValue(thisRef: Fragment, property: KProperty<*>, value: V) { - val key = property.name - val arg = thisRef.arguments - when (value) { - is Int -> arg.putInt(key, value) - is Long -> arg.putLong(key, value) - is String -> arg.putString(key, value) - is Boolean -> arg.putBoolean(key, value) - is Parcelable -> arg.putParcelable(key, value) - is Serializable -> arg.putSerializable(key, value) - else -> throw UnsupportedOperationException("${property} type not supported yet!!!") - } - } - } - } -} \ No newline at end of file diff --git a/app/src/main/kotlin/io/armcha/ribble/presentation/utils/extensions/CommonEx.kt b/app/src/main/kotlin/io/armcha/ribble/presentation/utils/extensions/CommonEx.kt index 691086b..afe4020 100644 --- a/app/src/main/kotlin/io/armcha/ribble/presentation/utils/extensions/CommonEx.kt +++ b/app/src/main/kotlin/io/armcha/ribble/presentation/utils/extensions/CommonEx.kt @@ -4,21 +4,14 @@ import android.annotation.SuppressLint import android.annotation.TargetApi import android.content.Context import android.os.Build -import android.os.Bundle import android.os.Handler -import android.os.Parcelable import android.support.v4.app.Fragment import android.support.v4.content.ContextCompat import android.text.Html import android.text.Spanned import android.widget.Toast import io.armcha.ribble.App -import io.armcha.ribble.presentation.base_mvp.base.BaseFragment -import io.armcha.ribble.presentation.base_mvp.base.BasePresenter import io.armcha.ribble.presentation.utils.Experimental -import java.io.Serializable -import kotlin.properties.ReadWriteProperty -import kotlin.reflect.KProperty /** @@ -83,10 +76,17 @@ fun Int.toPx(context: Context): Int { return (this * density).toInt() } -fun nonSafeLazy(initializer: () -> T): Lazy { +fun unSafeLazy(initializer: () -> T): Lazy { return lazy(LazyThreadSafetyMode.NONE) { initializer() } } fun Int.isZero(): Boolean = this == 0 + +inline fun doubleWith(first: F, second: S, runWith: F.(S) -> Unit) { + first.runWith(second) +} + +val Any?.isNull: Boolean + get() = this == null \ No newline at end of file diff --git a/app/src/main/kotlin/io/armcha/ribble/presentation/widget/AnimatedImageView.kt b/app/src/main/kotlin/io/armcha/ribble/presentation/widget/AnimatedImageView.kt index 18f0adb..09a5cc1 100644 --- a/app/src/main/kotlin/io/armcha/ribble/presentation/widget/AnimatedImageView.kt +++ b/app/src/main/kotlin/io/armcha/ribble/presentation/widget/AnimatedImageView.kt @@ -8,11 +8,8 @@ import android.util.AttributeSet * Created by Chatikyan on 16.02.2017. */ -class AnimatedImageView : AppCompatImageView, AnimatedView { - - constructor(context: Context) : super(context) - - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) +class AnimatedImageView(context: Context, attrs: AttributeSet? = null) + : AppCompatImageView(context, attrs), AnimatedView { fun setAnimatedImage(newImage: Int, startDelay: Long = 0L) { changeImage(newImage, startDelay) diff --git a/app/src/main/kotlin/io/armcha/ribble/presentation/widget/AnimatedTextView.kt b/app/src/main/kotlin/io/armcha/ribble/presentation/widget/AnimatedTextView.kt index bb66b4c..975c877 100644 --- a/app/src/main/kotlin/io/armcha/ribble/presentation/widget/AnimatedTextView.kt +++ b/app/src/main/kotlin/io/armcha/ribble/presentation/widget/AnimatedTextView.kt @@ -1,6 +1,7 @@ package io.armcha.ribble.presentation.widget import android.content.Context +import android.support.v7.widget.AppCompatImageView import android.support.v7.widget.AppCompatTextView import android.util.AttributeSet @@ -8,11 +9,8 @@ import android.util.AttributeSet * Created by Chatikyan on 16.02.2017. */ -class AnimatedTextView : AppCompatTextView, AnimatedView { - - constructor(context: Context) : super(context) - - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) +class AnimatedTextView (context: Context, attrs: AttributeSet? = null) + : AppCompatTextView(context, attrs), AnimatedView { fun setAnimatedText(text: CharSequence, startDelay: Long = 0L) { changeText(text, startDelay) diff --git a/app/src/main/kotlin/io/armcha/ribble/presentation/widget/ArcView.kt b/app/src/main/kotlin/io/armcha/ribble/presentation/widget/ArcView.kt index 5ec3d8c..589e94a 100644 --- a/app/src/main/kotlin/io/armcha/ribble/presentation/widget/ArcView.kt +++ b/app/src/main/kotlin/io/armcha/ribble/presentation/widget/ArcView.kt @@ -7,7 +7,7 @@ import android.view.View import io.armcha.ribble.R import io.armcha.ribble.presentation.utils.extensions.takeColor -class ArcView constructor(context: Context, attrs: AttributeSet) : View(context, attrs) { +class ArcView constructor(context: Context, attrs: AttributeSet? = null) : View(context, attrs) { private val SHADOW_OFFSET = 15F private val START_ANGLE = 270F @@ -31,16 +31,16 @@ class ArcView constructor(context: Context, attrs: AttributeSet) : View(context, } override fun onDraw(canvas: Canvas) { - val width = width.toFloat() - SHADOW_OFFSET - val height = height.toFloat() - SHADOW_OFFSET - rect.set(width / arcStartPoint, SHADOW_OFFSET, width, height) - with(path) { - val halfWidth = width / 2 - lineTo(halfWidth + halfWidth / arcStartPoint, SHADOW_OFFSET) - addArc(rect, START_ANGLE, SWEEP_ANGLE) - lineTo(0F, height) - lineTo(0F, SHADOW_OFFSET) - } - canvas.drawPath(path, paint) + val width = width.toFloat() - SHADOW_OFFSET + val height = height.toFloat() - SHADOW_OFFSET + rect.set(width / arcStartPoint, SHADOW_OFFSET, width, height) + with(path) { + val halfWidth = width / 2 + lineTo(halfWidth + halfWidth / arcStartPoint, SHADOW_OFFSET) + addArc(rect, START_ANGLE, SWEEP_ANGLE) + lineTo(0F, height) + lineTo(0F, SHADOW_OFFSET) + } + canvas.drawPath(path, paint) } } diff --git a/app/src/main/kotlin/io/armcha/ribble/presentation/widget/CircleLinedImageView.kt b/app/src/main/kotlin/io/armcha/ribble/presentation/widget/CircleLinedImageView.kt index ff03fbb..25d6118 100644 --- a/app/src/main/kotlin/io/armcha/ribble/presentation/widget/CircleLinedImageView.kt +++ b/app/src/main/kotlin/io/armcha/ribble/presentation/widget/CircleLinedImageView.kt @@ -6,23 +6,19 @@ import android.graphics.Color import android.graphics.Paint import android.support.v7.widget.AppCompatImageView import android.util.AttributeSet -import io.armcha.ribble.R import io.armcha.ribble.presentation.utils.extensions.toPx /** * Created by Chatikyan on 27.08.2017. */ -class CircleLinedImageView : AppCompatImageView { +class CircleLinedImageView(context: Context, attrs: AttributeSet? = null) + : AppCompatImageView(context, attrs) { private val LINE_WIDTH = 3F private val paint = Paint(Paint.ANTI_ALIAS_FLAG) private var padding = 17 - constructor(context: Context) : super(context) - - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) - init { with(paint) { color = Color.LTGRAY diff --git a/app/src/main/kotlin/io/armcha/ribble/presentation/widget/CircleProgressView.kt b/app/src/main/kotlin/io/armcha/ribble/presentation/widget/CircleProgressView.kt index 6d18c61..6eef2b1 100644 --- a/app/src/main/kotlin/io/armcha/ribble/presentation/widget/CircleProgressView.kt +++ b/app/src/main/kotlin/io/armcha/ribble/presentation/widget/CircleProgressView.kt @@ -20,7 +20,7 @@ import io.armcha.ribble.presentation.utils.extensions.show /** * Created by Chatikyan on 04.09.2017. */ -class CircleProgressView : View, Animatable { +class CircleProgressView(context: Context, attrs: AttributeSet) : View(context, attrs), Animatable { private val MAX_VALUE = 360F private val END_VALUE = 280F @@ -53,10 +53,6 @@ class CircleProgressView : View, Animatable { } get() = resources.getDimension(field).toInt() - constructor(context: Context) : super(context) - - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) - init { if (!isInEditMode) hide() diff --git a/app/src/main/kotlin/io/armcha/ribble/presentation/widget/GridRecyclerView.kt b/app/src/main/kotlin/io/armcha/ribble/presentation/widget/GridRecyclerView.kt index f3dff78..77c08f0 100644 --- a/app/src/main/kotlin/io/armcha/ribble/presentation/widget/GridRecyclerView.kt +++ b/app/src/main/kotlin/io/armcha/ribble/presentation/widget/GridRecyclerView.kt @@ -12,11 +12,7 @@ import android.view.animation.GridLayoutAnimationController /** * Created by Chatikyan on 17.09.2017. */ -class GridRecyclerView : RecyclerView { - - constructor(context: Context) : super(context) - - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) +class GridRecyclerView (context: Context, attrs: AttributeSet) : RecyclerView(context, attrs) { override fun attachLayoutAnimationParameters(child: View, params: ViewGroup.LayoutParams, index: Int, count: Int) { diff --git a/app/src/main/kotlin/io/armcha/ribble/presentation/widget/MaterialDialog.kt b/app/src/main/kotlin/io/armcha/ribble/presentation/widget/MaterialDialog.kt index 630cd96..3651690 100644 --- a/app/src/main/kotlin/io/armcha/ribble/presentation/widget/MaterialDialog.kt +++ b/app/src/main/kotlin/io/armcha/ribble/presentation/widget/MaterialDialog.kt @@ -10,7 +10,7 @@ import android.widget.Button import android.widget.TextView import io.armcha.ribble.R import io.armcha.ribble.presentation.utils.AnimationUtils -import io.armcha.ribble.presentation.utils.extensions.nonSafeLazy +import io.armcha.ribble.presentation.utils.extensions.unSafeLazy import io.armcha.ribble.presentation.utils.extensions.onClick import io.armcha.ribble.presentation.utils.extensions.scale import kotlinx.android.synthetic.main.dialog_item.* @@ -20,13 +20,13 @@ import kotlinx.android.synthetic.main.dialog_item.* */ class MaterialDialog(context: Context) : Dialog(context, R.style.MaterialDialogSheet) { - private val titleText by nonSafeLazy { + private val titleText by unSafeLazy { findViewById(R.id.title) } - private val messageText by nonSafeLazy { + private val messageText by unSafeLazy { findViewById(R.id.message) } - private val positiveButton by nonSafeLazy { + private val positiveButton by unSafeLazy { findViewById