-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from mohamedebrahim96/dev
add architecture components
- Loading branch information
Showing
25 changed files
with
667 additions
and
47 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/namshi/customer/binding/RecyclerViewBinding.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.namshi.customer.binding | ||
|
||
import androidx.databinding.BindingAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.skydoves.bindables.BindingListAdapter | ||
import com.skydoves.whatif.whatIfNotNullAs | ||
|
||
|
||
/** | ||
* Created by @mohamedebrahim96 on 18,November,2021 | ||
* ShopiniWorld, Inc | ||
* [email protected] | ||
*/ | ||
object RecyclerViewBinding { | ||
|
||
@JvmStatic | ||
@BindingAdapter("adapter") | ||
fun bindAdapter(view: RecyclerView, adapter: RecyclerView.Adapter<*>) { | ||
view.adapter = adapter.apply { | ||
stateRestorationPolicy = RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY | ||
} | ||
} | ||
|
||
@JvmStatic | ||
@BindingAdapter("submitList") | ||
fun bindSubmitList(view: RecyclerView, itemList: List<Any>?) { | ||
view.adapter.whatIfNotNullAs<BindingListAdapter<Any, *>> { adapter -> | ||
adapter.submitList(itemList) | ||
} | ||
} | ||
|
||
|
||
} |
49 changes: 49 additions & 0 deletions
49
app/src/main/java/com/namshi/customer/binding/ViewBinding.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.namshi.customer.binding | ||
|
||
import android.view.View | ||
import android.widget.Toast | ||
import androidx.appcompat.widget.AppCompatImageView | ||
import androidx.databinding.BindingAdapter | ||
import com.bumptech.glide.Glide | ||
import com.github.florent37.glidepalette.BitmapPalette | ||
import com.github.florent37.glidepalette.GlidePalette | ||
import com.skydoves.whatif.whatIfNotNullOrEmpty | ||
|
||
|
||
/** | ||
* Created by @mohamedebrahim96 on 18,November,2021 | ||
* ShopiniWorld, Inc | ||
* [email protected] | ||
*/ | ||
object ViewBinding { | ||
|
||
@JvmStatic | ||
@BindingAdapter("toast") | ||
fun bindToast(view: View, text: String?) { | ||
text.whatIfNotNullOrEmpty { | ||
Toast.makeText(view.context, it, Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
|
||
@JvmStatic | ||
@BindingAdapter("loadImage") | ||
fun bindLoadImage(view: AppCompatImageView, url: String) { | ||
Glide.with(view.context) | ||
.load(url) | ||
.listener( | ||
GlidePalette.with(url) | ||
.use(BitmapPalette.Profile.MUTED_LIGHT) | ||
.crossfade(true) | ||
).into(view) | ||
} | ||
|
||
@JvmStatic | ||
@BindingAdapter("gone") | ||
fun bindGone(view: View, shouldBeGone: Boolean) { | ||
view.visibility = if (shouldBeGone) { | ||
View.GONE | ||
} else { | ||
View.VISIBLE | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/namshi/customer/di/DispatcherModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.namshi.customer.di | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.Dispatchers | ||
import javax.inject.Singleton | ||
|
||
|
||
/** | ||
* Created by @mohamedebrahim96 on 18,November,2021 | ||
* ShopiniWorld, Inc | ||
* [email protected] | ||
*/ | ||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object DispatcherModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideIODispatcher(): CoroutineDispatcher { | ||
return Dispatchers.IO | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.namshi.customer.di | ||
|
||
import com.namshi.customer.network.HttpRequestInterceptor | ||
import com.namshi.customer.network.NamshiClient | ||
import com.namshi.customer.network.NamshiService | ||
import com.namshi.customer.utils.Constants | ||
import com.skydoves.sandwich.coroutines.CoroutinesResponseCallAdapterFactory | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import okhttp3.OkHttpClient | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.moshi.MoshiConverterFactory | ||
import javax.inject.Singleton | ||
|
||
|
||
/** | ||
* Created by @mohamedebrahim96 on 18,November,2021 | ||
* ShopiniWorld, Inc | ||
* [email protected] | ||
*/ | ||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object NetworkModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideOkHttpClient(): OkHttpClient { | ||
return OkHttpClient.Builder() | ||
.addInterceptor(HttpRequestInterceptor()) | ||
.build() | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit { | ||
return Retrofit.Builder() | ||
.client(okHttpClient) | ||
.baseUrl(Constants.BASE_URL) | ||
.addConverterFactory(MoshiConverterFactory.create()) | ||
.addCallAdapterFactory(CoroutinesResponseCallAdapterFactory.create()) | ||
.build() | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideNamshiService(retrofit: Retrofit): NamshiService { | ||
return retrofit.create(NamshiService::class.java) | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideNamshiClient(namshiService: NamshiService): NamshiClient { | ||
return NamshiClient(namshiService) | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/namshi/customer/di/RepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.namshi.customer.di | ||
|
||
import com.namshi.customer.network.NamshiClient | ||
import com.namshi.customer.repository.MainRepository | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.components.ViewModelComponent | ||
import dagger.hilt.android.scopes.ViewModelScoped | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
|
||
|
||
/** | ||
* Created by @mohamedebrahim96 on 18,November,2021 | ||
* ShopiniWorld, Inc | ||
* [email protected] | ||
*/ | ||
@Module | ||
@InstallIn(ViewModelComponent::class) | ||
object RepositoryModule { | ||
@Provides | ||
@ViewModelScoped | ||
fun provideMainRepository( | ||
namshiClient: NamshiClient, | ||
coroutineDispatcher: CoroutineDispatcher | ||
): MainRepository { | ||
return MainRepository(namshiClient, coroutineDispatcher) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
app/src/main/java/com/namshi/customer/model/NamshiResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.namshi.customer.model | ||
|
||
import android.os.Parcelable | ||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
import kotlinx.parcelize.Parcelize | ||
|
||
|
||
/** | ||
* Created by @mohamedebrahim96 on 18,November,2021 | ||
* ShopiniWorld, Inc | ||
* [email protected] | ||
*/ | ||
@Parcelize | ||
@JsonClass(generateAdapter = true) | ||
data class NamshiResponse( | ||
@field:Json(name = "content") val content: List<Content> | ||
) : Parcelable { | ||
@Parcelize | ||
@JsonClass(generateAdapter = true) | ||
data class Content( | ||
@field:Json(name = "type") var type: String, | ||
@field:Json(name = "cols") var cols: Int?, | ||
@field:Json(name = "images") var images: List<Images>? | ||
) : Parcelable { | ||
@Parcelize | ||
@JsonClass(generateAdapter = true) | ||
data class Images( | ||
@field:Json(name = "url") var url: String, | ||
@field:Json(name = "width") var width: Int, | ||
@field:Json(name = "height") var height: Int, | ||
@field:Json(name = "format") var format: String | ||
) : Parcelable | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/namshi/customer/network/HttpRequestInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.namshi.customer.network | ||
|
||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
import timber.log.Timber | ||
|
||
|
||
/** | ||
* Created by @mohamedebrahim96 on 18,November,2021 | ||
* ShopiniWorld, Inc | ||
* [email protected] | ||
*/ | ||
class HttpRequestInterceptor : Interceptor { | ||
override fun intercept(chain: Interceptor.Chain): Response { | ||
val originalRequest = chain.request() | ||
val request = originalRequest.newBuilder().url(originalRequest.url).build() | ||
Timber.d(request.toString()) | ||
return chain.proceed(request) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/namshi/customer/network/NamshiClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.namshi.customer.network | ||
|
||
import com.namshi.customer.model.NamshiResponse | ||
import com.skydoves.sandwich.ApiResponse | ||
import javax.inject.Inject | ||
|
||
|
||
/** | ||
* Created by @mohamedebrahim96 on 18,November,2021 | ||
* ShopiniWorld, Inc | ||
* [email protected] | ||
*/ | ||
class NamshiClient @Inject constructor( | ||
private val namshiService: NamshiService | ||
) { | ||
|
||
suspend fun fetchHomeList(): ApiResponse<NamshiResponse> = | ||
namshiService.fetchHomeList() | ||
} |
Oops, something went wrong.