Skip to content

Commit

Permalink
Merge pull request #3 from mohamedebrahim96/dev
Browse files Browse the repository at this point in the history
add architecture components
  • Loading branch information
mohamedebrahim96 authored Nov 18, 2021
2 parents 205060d + b693d27 commit e9006f8
Show file tree
Hide file tree
Showing 25 changed files with 667 additions and 47 deletions.
4 changes: 3 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 42 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,25 @@ plugins {
apply from: "$rootDir/dependencies.gradle"

android {
compileSdk 31

compileSdkVersion versions.compileSdk
defaultConfig {
applicationId "com.namshi.customer"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"

minSdkVersion versions.minSdk
targetSdkVersion versions.compileSdk
versionCode versions.versionCode
versionName versions.versionName
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments += ["room.schemaLocation" : "$projectDir/schemas".toString()]
}
}
javaCompileOptions {
annotationProcessorOptions {
arguments["dagger.hilt.disableModulesHaveInstallInCheck"] = "true"
}
}
}

buildTypes {
Expand Down Expand Up @@ -64,6 +73,9 @@ android {
}

dependencies {
// android supports
implementation "com.google.android.material:material:$versions.materialVersion"
implementation "androidx.constraintlayout:constraintlayout:$versions.constraintVersion"

// architecture components
implementation "androidx.fragment:fragment-ktx:$versions.fragmentVersion"
Expand All @@ -88,6 +100,29 @@ dependencies {
androidTestImplementation "com.google.dagger:hilt-android-testing:$versions.hiltCoreVersion"
kaptAndroidTest "com.google.dagger:hilt-compiler:$versions.hiltCoreVersion"

// network
implementation "com.github.skydoves:sandwich:$versions.sandwichVersion"
implementation "com.squareup.retrofit2:retrofit:$versions.retrofitVersion"
implementation "com.squareup.retrofit2:converter-moshi:$versions.retrofitVersion"
implementation "com.squareup.okhttp3:logging-interceptor:$versions.okhttpVersion"
testImplementation "com.squareup.okhttp3:mockwebserver:$versions.okhttpVersion"

// moshi
implementation "com.squareup.moshi:moshi-kotlin:$versions.moshiVersion"
kapt "com.squareup.moshi:moshi-kotlin-codegen:$versions.moshiVersion"

// debugging
implementation "com.jakewharton.timber:timber:$versions.timberVersion"

// whatIf
implementation "com.github.skydoves:whatif:$versions.whatIfVersion"


// glide
implementation "com.github.bumptech.glide:glide:$versions.glideVersion"
implementation "com.github.florent37:glidepalette:$versions.glidePaletteVersion"
kapt "com.github.bumptech.glide:compiler:$versions.glideVersion"


implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.namshi.customer">

<uses-permission android:name="android.permission.INTERNET" />


<application
android:name=".NamshiApp"
android:allowBackup="false"
Expand All @@ -14,14 +17,19 @@
tools:ignore="AllowBackup">
<activity
android:name=".ui.main.MainActivity"
android:exported="true">
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ui.details.DetailActivity" />
<activity
android:name=".ui.details.DetailActivity"
android:screenOrientation="portrait"

/>
</application>

</manifest>
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 app/src/main/java/com/namshi/customer/binding/ViewBinding.kt
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 app/src/main/java/com/namshi/customer/di/DispatcherModule.kt
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
}
}
58 changes: 58 additions & 0 deletions app/src/main/java/com/namshi/customer/di/NetworkModule.kt
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 app/src/main/java/com/namshi/customer/di/RepositoryModule.kt
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 app/src/main/java/com/namshi/customer/model/NamshiResponse.kt
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
}
}
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 app/src/main/java/com/namshi/customer/network/NamshiClient.kt
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()
}
Loading

0 comments on commit e9006f8

Please sign in to comment.