Skip to content

Commit c3a0525

Browse files
committed
Some refactoring, added bundle delegate
1 parent e4fbb2a commit c3a0525

17 files changed

Lines changed: 73 additions & 110 deletions

File tree

app/src/main/kotlin/io/armcha/ribble/App.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import com.squareup.leakcanary.LeakCanary
77
import io.armcha.ribble.di.component.ApplicationComponent
88
import io.armcha.ribble.di.component.DaggerApplicationComponent
99
import io.armcha.ribble.di.module.ApplicationModule
10-
import io.armcha.ribble.presentation.utils.extensions.nonSafeLazy
10+
import io.armcha.ribble.presentation.utils.extensions.unSafeLazy
1111

1212
/**
1313
* Created by Chatikyan on 29.07.2017.
1414
*/
1515
class App : Application() {
1616

17-
val applicationComponent: ApplicationComponent by nonSafeLazy {
17+
val applicationComponent: ApplicationComponent by unSafeLazy {
1818
DaggerApplicationComponent.builder()
1919
.applicationModule(ApplicationModule(this))
2020
.build()

app/src/main/kotlin/io/armcha/ribble/data/pref/Preferences.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import android.content.Context
66
import android.content.SharedPreferences
77
import io.armcha.ribble.data.network.ApiConstants
88
import io.armcha.ribble.presentation.utils.extensions.emptyString
9-
import io.armcha.ribble.presentation.utils.extensions.nonSafeLazy
9+
import io.armcha.ribble.presentation.utils.extensions.unSafeLazy
1010
import javax.inject.Inject
1111
import javax.inject.Singleton
1212

@@ -21,7 +21,7 @@ class Preferences @Inject constructor(app: Application) {
2121
private val USER_LOGGED_IN = "user_logged_in"
2222
private val USER_TOKEN = "user_token"
2323

24-
private val sharedPreferences by nonSafeLazy {
24+
private val sharedPreferences by unSafeLazy {
2525
app.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE)
2626
}
2727
val isUserLoggedIn

app/src/main/kotlin/io/armcha/ribble/presentation/base_mvp/base/BaseActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import io.armcha.ribble.di.module.ActivityModule
1111
import io.armcha.ribble.presentation.navigation.Navigator
1212
import io.armcha.ribble.presentation.utils.S
1313
import io.armcha.ribble.presentation.utils.extensions.emptyString
14-
import io.armcha.ribble.presentation.utils.extensions.nonSafeLazy
14+
import io.armcha.ribble.presentation.utils.extensions.unSafeLazy
1515
import io.armcha.ribble.presentation.widget.MaterialDialog
1616
import javax.inject.Inject
1717

@@ -26,7 +26,7 @@ abstract class BaseActivity<V : BaseContract.View, P : BaseContract.Presenter<V>
2626

2727
private var dialog: MaterialDialog? = null
2828

29-
val activityComponent: ActivityComponent by nonSafeLazy {
29+
val activityComponent: ActivityComponent by unSafeLazy {
3030
getAppComponent().plus(ActivityModule(this))
3131
}
3232

app/src/main/kotlin/io/armcha/ribble/presentation/screen/shot_detail/ShotDetailFragment.kt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package io.armcha.ribble.presentation.screen.shot_detail
33

44
import android.animation.StateListAnimator
55
import android.annotation.SuppressLint
6-
import android.content.Context
76
import android.os.Bundle
87
import android.support.design.widget.AppBarLayout
98
import android.support.v7.widget.LinearLayoutManager
@@ -17,6 +16,7 @@ import io.armcha.ribble.presentation.base_mvp.base.BaseFragment
1716
import io.armcha.ribble.presentation.utils.C
1817
import io.armcha.ribble.presentation.utils.L
1918
import io.armcha.ribble.presentation.utils.S
19+
import io.armcha.ribble.presentation.utils.delegates.args
2020
import io.armcha.ribble.presentation.utils.extensions.*
2121
import io.armcha.ribble.presentation.utils.glide.TransformationType
2222
import io.armcha.ribble.presentation.utils.glide.load
@@ -29,9 +29,7 @@ import javax.inject.Inject
2929
class ShotDetailFragment : BaseFragment<ShotDetailContract.View, ShotDetailContract.Presenter>(), ShotDetailContract.View {
3030

3131
companion object {
32-
const val SHOT_EXTRA_KEY = "shot_extra_key"
33-
34-
fun getBundle(shot: Shot?) = Bundle().apply { putParcelable(SHOT_EXTRA_KEY, shot) }
32+
fun getBundle(shot: Shot?) = Bundle().apply { putParcelable("shot", shot) }
3533
}
3634

3735
private val items = intArrayOf(R.drawable.heart_full, R.drawable.eye, R.drawable.bucket)
@@ -40,7 +38,8 @@ class ShotDetailFragment : BaseFragment<ShotDetailContract.View, ShotDetailContr
4038
protected lateinit var shotDetailPresenter: ShotDetailPresenter
4139

4240
private var recyclerAdapter: RibbleAdapter<Comment>? = null
43-
private lateinit var shot: Shot
41+
42+
val shot: Shot by args()
4443

4544
override fun injectDependencies() {
4645
activityComponent.inject(this)
@@ -50,11 +49,6 @@ class ShotDetailFragment : BaseFragment<ShotDetailContract.View, ShotDetailContr
5049

5150
override fun initPresenter() = shotDetailPresenter
5251

53-
override fun onAttach(context: Context?) {
54-
super.onAttach(context)
55-
shot = this extraWithKey SHOT_EXTRA_KEY
56-
}
57-
5852
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
5953
super.onViewCreated(view, savedInstanceState)
6054
setUpViews()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package io.armcha.ribble.presentation.utils.delegates
2+
3+
import android.support.v4.app.Fragment
4+
import io.armcha.ribble.presentation.utils.extensions.isNull
5+
import kotlin.properties.ReadOnlyProperty
6+
import kotlin.reflect.KProperty
7+
8+
/**
9+
* Created by Chatikyan on 30.09.2017.
10+
*/
11+
12+
13+
inline fun <reified VALUE> Fragment.args() = object : ReadOnlyProperty<Fragment, VALUE> {
14+
15+
private var value: VALUE? = null
16+
17+
override fun getValue(thisRef: Fragment, property: KProperty<*>): VALUE {
18+
if (value.isNull) {
19+
value = arguments[property.name] as VALUE
20+
}
21+
return value!!
22+
}
23+
}
24+
25+

app/src/main/kotlin/io/armcha/ribble/presentation/utils/extensions/BundleDelegate.kt

Lines changed: 0 additions & 34 deletions
This file was deleted.

app/src/main/kotlin/io/armcha/ribble/presentation/utils/extensions/CommonEx.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@ import android.annotation.SuppressLint
44
import android.annotation.TargetApi
55
import android.content.Context
66
import android.os.Build
7-
import android.os.Bundle
87
import android.os.Handler
9-
import android.os.Parcelable
108
import android.support.v4.app.Fragment
119
import android.support.v4.content.ContextCompat
1210
import android.text.Html
1311
import android.text.Spanned
1412
import android.widget.Toast
1513
import io.armcha.ribble.App
16-
import io.armcha.ribble.presentation.base_mvp.base.BaseFragment
17-
import io.armcha.ribble.presentation.base_mvp.base.BasePresenter
1814
import io.armcha.ribble.presentation.utils.Experimental
19-
import java.io.Serializable
20-
import kotlin.properties.ReadWriteProperty
21-
import kotlin.reflect.KProperty
2215

2316

2417
/**
@@ -83,10 +76,17 @@ fun Int.toPx(context: Context): Int {
8376
return (this * density).toInt()
8477
}
8578

86-
fun <T> nonSafeLazy(initializer: () -> T): Lazy<T> {
79+
fun <T> unSafeLazy(initializer: () -> T): Lazy<T> {
8780
return lazy(LazyThreadSafetyMode.NONE) {
8881
initializer()
8982
}
9083
}
9184

9285
fun Int.isZero(): Boolean = this == 0
86+
87+
inline fun <F, S> doubleWith(first: F, second: S, runWith: F.(S) -> Unit) {
88+
first.runWith(second)
89+
}
90+
91+
val Any?.isNull: Boolean
92+
get() = this == null

app/src/main/kotlin/io/armcha/ribble/presentation/widget/AnimatedImageView.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ import android.util.AttributeSet
88
* Created by Chatikyan on 16.02.2017.
99
*/
1010

11-
class AnimatedImageView : AppCompatImageView, AnimatedView {
12-
13-
constructor(context: Context) : super(context)
14-
15-
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
11+
class AnimatedImageView(context: Context, attrs: AttributeSet? = null)
12+
: AppCompatImageView(context, attrs), AnimatedView {
1613

1714
fun setAnimatedImage(newImage: Int, startDelay: Long = 0L) {
1815
changeImage(newImage, startDelay)

app/src/main/kotlin/io/armcha/ribble/presentation/widget/AnimatedTextView.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
package io.armcha.ribble.presentation.widget
22

33
import android.content.Context
4+
import android.support.v7.widget.AppCompatImageView
45
import android.support.v7.widget.AppCompatTextView
56
import android.util.AttributeSet
67

78
/**
89
* Created by Chatikyan on 16.02.2017.
910
*/
1011

11-
class AnimatedTextView : AppCompatTextView, AnimatedView {
12-
13-
constructor(context: Context) : super(context)
14-
15-
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
12+
class AnimatedTextView (context: Context, attrs: AttributeSet? = null)
13+
: AppCompatTextView(context, attrs), AnimatedView {
1614

1715
fun setAnimatedText(text: CharSequence, startDelay: Long = 0L) {
1816
changeText(text, startDelay)

app/src/main/kotlin/io/armcha/ribble/presentation/widget/ArcView.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import android.view.View
77
import io.armcha.ribble.R
88
import io.armcha.ribble.presentation.utils.extensions.takeColor
99

10-
class ArcView constructor(context: Context, attrs: AttributeSet) : View(context, attrs) {
10+
class ArcView constructor(context: Context, attrs: AttributeSet? = null) : View(context, attrs) {
1111

1212
private val SHADOW_OFFSET = 15F
1313
private val START_ANGLE = 270F
@@ -31,16 +31,16 @@ class ArcView constructor(context: Context, attrs: AttributeSet) : View(context,
3131
}
3232

3333
override fun onDraw(canvas: Canvas) {
34-
val width = width.toFloat() - SHADOW_OFFSET
35-
val height = height.toFloat() - SHADOW_OFFSET
36-
rect.set(width / arcStartPoint, SHADOW_OFFSET, width, height)
37-
with(path) {
38-
val halfWidth = width / 2
39-
lineTo(halfWidth + halfWidth / arcStartPoint, SHADOW_OFFSET)
40-
addArc(rect, START_ANGLE, SWEEP_ANGLE)
41-
lineTo(0F, height)
42-
lineTo(0F, SHADOW_OFFSET)
43-
}
44-
canvas.drawPath(path, paint)
34+
val width = width.toFloat() - SHADOW_OFFSET
35+
val height = height.toFloat() - SHADOW_OFFSET
36+
rect.set(width / arcStartPoint, SHADOW_OFFSET, width, height)
37+
with(path) {
38+
val halfWidth = width / 2
39+
lineTo(halfWidth + halfWidth / arcStartPoint, SHADOW_OFFSET)
40+
addArc(rect, START_ANGLE, SWEEP_ANGLE)
41+
lineTo(0F, height)
42+
lineTo(0F, SHADOW_OFFSET)
43+
}
44+
canvas.drawPath(path, paint)
4545
}
4646
}

0 commit comments

Comments
 (0)