Skip to content

Commit 751b140

Browse files
committed
Code refactoring
1 parent 65226f2 commit 751b140

File tree

124 files changed

+1691
-713
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+1691
-713
lines changed

androidApp/build.gradle.kts

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import src.main.java.toInt
33
plugins {
44
id("com.android.application")
55
kotlin("android")
6+
id("kotlin-kapt")
67
}
78

89
android {
@@ -17,6 +18,7 @@ android {
1718
}
1819
buildFeatures {
1920
compose = true
21+
dataBinding = true
2022
}
2123
composeOptions {
2224
kotlinCompilerExtensionVersion = libs.versions.composeCompiler.get()
@@ -35,7 +37,6 @@ android {
3537

3638
dependencies {
3739
implementation(project(":shared"))
38-
debugImplementation(project(":sharedMock"))
3940
implementation(libs.composeUi)
4041
implementation(libs.composeUiTooling)
4142
implementation(libs.composeUiToolingPreview)
@@ -44,4 +45,12 @@ dependencies {
4445
implementation(libs.composeActivity)
4546
implementation(libs.viewModelKtx)
4647
implementation(libs.liveDataKtx)
48+
implementation(libs.appCompat)
49+
implementation(libs.materialUi)
50+
implementation(libs.constraintLayout)
51+
implementation(libs.recyclerview)
52+
implementation(libs.swipeRefreshLayout)
53+
implementation(libs.lottie)
54+
implementation(libs.shimmer)
55+
implementation(libs.glide)
4756
}
+13-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<uses-permission android:name="android.permission.INTERNET"/>
36

47
<application
8+
android:name="com.mecofarid.trending.app.TrendingApplication"
59
android:allowBackup="false"
6-
android:supportsRtl="true"
7-
android:theme="@style/AppTheme">
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="@string/app_name"
12+
android:roundIcon="@mipmap/ic_launcher_round"
13+
android:theme="@style/Theme.Trending"
14+
tools:targetApi="33">
815
<activity
916
android:name="com.mecofarid.trending.MainActivity"
1017
android:exported="true">
1118
<intent-filter>
1219
<action android:name="android.intent.action.MAIN" />
20+
1321
<category android:name="android.intent.category.LAUNCHER" />
1422
</intent-filter>
1523
</activity>
1624
</application>
17-
</manifest>
25+
26+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,21 @@
11
package com.mecofarid.trending
22

33
import android.os.Bundle
4-
import androidx.activity.ComponentActivity
5-
import androidx.activity.compose.setContent
6-
import androidx.compose.foundation.isSystemInDarkTheme
7-
import androidx.compose.foundation.layout.fillMaxSize
8-
import androidx.compose.foundation.shape.RoundedCornerShape
4+
import androidx.appcompat.app.AppCompatActivity
95
import androidx.compose.material.*
10-
import androidx.compose.runtime.Composable
11-
import androidx.compose.ui.Modifier
12-
import androidx.compose.ui.graphics.Color
13-
import androidx.compose.ui.text.TextStyle
14-
import androidx.compose.ui.text.font.FontFamily
15-
import androidx.compose.ui.text.font.FontWeight
16-
import androidx.compose.ui.tooling.preview.Preview
17-
import androidx.compose.ui.unit.dp
18-
import androidx.compose.ui.unit.sp
6+
import androidx.databinding.DataBindingUtil
7+
import com.mecofarid.trending.android.R
8+
import com.mecofarid.trending.common.ui.ext.replaceFragment
9+
import com.mecofarid.trending.ui.trending.view.TrendingFragment
1910

20-
@Composable
21-
fun MyApplicationTheme(
22-
darkTheme: Boolean = isSystemInDarkTheme(),
23-
content: @Composable () -> Unit
24-
) {
25-
val colors = if (darkTheme) {
26-
darkColors(
27-
primary = Color(0xFFBB86FC),
28-
primaryVariant = Color(0xFF3700B3),
29-
secondary = Color(0xFF03DAC5)
30-
)
31-
} else {
32-
lightColors(
33-
primary = Color(0xFF6200EE),
34-
primaryVariant = Color(0xFF3700B3),
35-
secondary = Color(0xFF03DAC5)
36-
)
37-
}
38-
val typography = Typography(
39-
body1 = TextStyle(
40-
fontFamily = FontFamily.Default,
41-
fontWeight = FontWeight.Normal,
42-
fontSize = 16.sp
43-
)
44-
)
45-
val shapes = Shapes(
46-
small = RoundedCornerShape(4.dp),
47-
medium = RoundedCornerShape(4.dp),
48-
large = RoundedCornerShape(0.dp)
49-
)
50-
51-
MaterialTheme(
52-
colors = colors,
53-
typography = typography,
54-
shapes = shapes,
55-
content = content
56-
)
57-
}
58-
59-
class MainActivity : ComponentActivity() {
60-
override fun onCreate(savedInstanceState: Bundle?) {
61-
super.onCreate(savedInstanceState)
62-
setContent {
63-
MyApplicationTheme {
64-
Surface(
65-
modifier = Modifier.fillMaxSize(),
66-
color = MaterialTheme.colors.background
67-
) {
68-
Greeting("Heyye")
69-
}
70-
}
71-
}
72-
}
73-
}
74-
75-
@Composable
76-
fun Greeting(text: String) {
77-
Text(text = text)
78-
}
79-
80-
@Preview
81-
@Composable
82-
fun DefaultPreview() {
83-
MyApplicationTheme {
84-
Greeting("Hello, Android!")
85-
}
86-
}
11+
class MainActivity: AppCompatActivity() {
12+
// private val binding: ActivityMainBinding by lazy { DataBindingUtil.setContentView(this, R.layout.activity_main) }
13+
// override fun onCreate(savedInstanceState: Bundle?) {
14+
// super.onCreate(savedInstanceState)
15+
// addTrendingScreen()
16+
// }
17+
//
18+
// private fun addTrendingScreen(){
19+
// replaceFragment(TrendingFragment(), binding.coninerid)
20+
// }
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.mecofarid.trending.app
2+
3+
import android.app.Application
4+
import com.mecofarid.trending.domain.di.AppComponent
5+
import com.mecofarid.trending.domain.features.trending.RepoComponent
6+
7+
private const val DB_NAME = "repo.db"
8+
9+
class AppModule(application: Application): AppComponent {
10+
11+
// private val dbComponent by lazy {
12+
// Room.databaseBuilder(
13+
// application,
14+
// DbRoomModule::class.java,
15+
// DB_NAME
16+
// ).build()
17+
// }
18+
// private val networkComponent by lazy {
19+
// val json = Json{
20+
// ignoreUnknownKeys = true
21+
// }
22+
// NetworkRetrofitModule(KotlinxJsonConverter(json))
23+
// }
24+
//
25+
// private val module by lazy {
26+
// RepoModule(dbComponent, networkComponent)
27+
// }
28+
override fun repoComponent(): RepoComponent = TODO() //module
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.mecofarid.trending.app
2+
3+
import android.app.Application
4+
import com.mecofarid.trending.domain.di.AppComponent
5+
import com.mecofarid.trending.domain.features.trending.RepoComponent
6+
7+
class TrendingApplication: Application(), AppComponent {
8+
private val internalAppComponent by lazy { AppModule(this) }
9+
10+
override fun repoComponent(): RepoComponent = internalAppComponent.repoComponent()
11+
}
12+
13+
fun Application.appComponent() = this as AppComponent
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.mecofarid.trending.common.ui.binding
2+
3+
import android.widget.ImageView
4+
import androidx.annotation.DrawableRes
5+
import androidx.databinding.BindingAdapter
6+
import com.bumptech.glide.Glide
7+
import com.mecofarid.trending.android.R
8+
9+
@BindingAdapter(value = ["imageUrl", "placeholderResId"], requireAll = false)
10+
fun setImageUrl(view: ImageView, url: String?, @DrawableRes placeholder: Int?){
11+
val placeholderResId = placeholder ?: R.drawable.circle_placeholder_bg
12+
Glide.with(view)
13+
.load(url)
14+
.placeholder(placeholderResId)
15+
.circleCrop()
16+
.into(view)
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.mecofarid.trending.common.ui.binding
2+
3+
import androidx.annotation.DrawableRes
4+
import androidx.core.content.res.ResourcesCompat
5+
import androidx.databinding.BindingAdapter
6+
import androidx.recyclerview.widget.DividerItemDecoration
7+
import androidx.recyclerview.widget.RecyclerView
8+
import com.mecofarid.trending.android.R
9+
10+
@BindingAdapter(value = ["dividerOrientation", "dividerDrawable"], requireAll = false)
11+
fun setDividerDecoration(view: RecyclerView, dividerOrientation: Int?, @DrawableRes dividerDrawableResId: Int?){
12+
val context = view.context
13+
val orientation = dividerOrientation ?: DividerItemDecoration.VERTICAL
14+
val drawableResId = dividerDrawableResId ?: R.drawable.divider_bg
15+
val divider = DividerItemDecoration(context, orientation)
16+
val drawable = ResourcesCompat.getDrawable(context.resources, drawableResId, context.theme)!!
17+
divider.setDrawable(drawable)
18+
view.addItemDecoration(divider)
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.mecofarid.trending.common.ui.binding
2+
3+
import androidx.databinding.BindingAdapter
4+
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
5+
import com.mecofarid.trending.domain.features.trending.ui.UiState
6+
7+
@BindingAdapter("enablePullRefresh")
8+
fun enablePullRefresh(view: SwipeRefreshLayout, state: UiState) {
9+
view.isEnabled = state !is UiState.Loading
10+
view.isRefreshing = false
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.mecofarid.trending.common.ui.binding
2+
3+
import android.view.View
4+
import androidx.core.view.isVisible
5+
import androidx.databinding.BindingAdapter
6+
7+
@BindingAdapter("visible")
8+
fun isVisible(view: View, visible: Boolean){
9+
view.isVisible = visible
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.mecofarid.trending.common.ui.ext
2+
3+
import androidx.fragment.app.Fragment
4+
import androidx.fragment.app.FragmentActivity
5+
6+
fun FragmentActivity.replaceFragment(fragment: Fragment, containerId: Int){
7+
supportFragmentManager
8+
.beginTransaction()
9+
.replace(containerId, fragment)
10+
.addToBackStack(null)
11+
.commit()
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.mecofarid.trending.common.ui.widget
2+
3+
import android.content.Context
4+
import android.content.res.TypedArray
5+
import android.graphics.drawable.Drawable
6+
import android.util.AttributeSet
7+
import com.google.android.material.textview.MaterialTextView
8+
import com.mecofarid.trending.android.R
9+
import kotlin.math.max
10+
11+
private const val START_DRAWABLE = 0
12+
private const val UNDEFINED_DRAWABLE_SIZE = -1
13+
14+
class IconizedTextView(context: Context, attrs: AttributeSet?) : MaterialTextView(context, attrs) {
15+
16+
init {
17+
val styleSet = context.obtainStyledAttributes(attrs, R.styleable.IconizedTextView)
18+
updateDrawables(styleSet)
19+
styleSet.recycle()
20+
}
21+
22+
private fun updateDrawables(styleSet: TypedArray) {
23+
val startDrawable = getModifiedDrawable(drawablePosition = START_DRAWABLE, styleSet)
24+
setCompoundDrawables(startDrawable, null, null, null)
25+
}
26+
27+
private fun getModifiedDrawable(drawablePosition: Int, styleSet: TypedArray): Drawable? =
28+
compoundDrawables[drawablePosition]?.apply {
29+
val drawableSize = styleSet.getDimensionPixelSize(
30+
R.styleable.IconizedTextView_drawableStartSize,
31+
UNDEFINED_DRAWABLE_SIZE
32+
)
33+
val size = getScaledSize(drawableSize)
34+
setBounds(0, 0, size.width, size.height)
35+
}
36+
37+
// We take defined drawable size as max size to scale the drawable's actual dimensions
38+
private fun Drawable.getScaledSize(drawableSize: Int): Size {
39+
val height = intrinsicHeight
40+
val width = intrinsicWidth
41+
42+
if (drawableSize == UNDEFINED_DRAWABLE_SIZE)
43+
return Size(height, width)
44+
45+
val ratio: Float = max(height, width).toFloat() / drawableSize
46+
return Size(height = (height / ratio).toInt(), width = (width / ratio).toInt())
47+
}
48+
49+
private data class Size(val height: Int, val width: Int)
50+
}

androidApp/src/main/java/com/mecofarid/trending/ui/repo/TrendingViewModel.kt

-10
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.mecofarid.trending.ui.trending
2+
3+
import androidx.lifecycle.ViewModel
4+
import androidx.lifecycle.asLiveData
5+
import androidx.lifecycle.viewmodel.initializer
6+
import androidx.lifecycle.viewmodel.viewModelFactory
7+
import com.mecofarid.trending.common.ui.store.StoreViewModel
8+
import com.mecofarid.trending.domain.features.trending.domain.interactor.GetTrendingInteractor
9+
import com.mecofarid.trending.domain.features.trending.ui.TrendingStore
10+
11+
class TrendingViewModel(
12+
repoInteractor: GetTrendingInteractor
13+
): StoreViewModel<TrendingStore>, ViewModel() {
14+
override val store: TrendingStore = TrendingStore(repoInteractor)
15+
val uiState = store.uiState.asLiveData()
16+
17+
companion object {
18+
fun factory(repoInteractor: GetTrendingInteractor) = viewModelFactory {
19+
initializer {
20+
TrendingViewModel(repoInteractor)
21+
}
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)