-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
637df4d
commit dcce63d
Showing
68 changed files
with
1,280 additions
and
118 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
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,6 @@ | ||
package foodapp.com.foodapp | ||
|
||
object AppConstants { | ||
|
||
val BASE_URL = "http://www.json-generator.com/api/json/get/" | ||
} |
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,24 @@ | ||
package foodapp.com.foodapp | ||
|
||
enum class ErrorType(val icon: Int, val title: Int, val subtitle: Int) { | ||
|
||
CONNECTION_ERROR( | ||
R.drawable.ic_svg_network_error, | ||
R.string.inv_connection_error_title, | ||
R.string.inv_connection_error_subtitle), | ||
|
||
TIMEOUT_ERROR( | ||
R.drawable.ic_svg_network_error, | ||
R.string.inv_timeout_error_title, | ||
R.string.inv_timeout_error_subtitle), | ||
|
||
SERVER_ERROR( | ||
R.drawable.ic_svg_network_error, | ||
R.string.inv_generic_error_title, | ||
R.string.inv_generic_error_subtitle), | ||
|
||
CLIENT_ERROR( | ||
R.drawable.ic_svg_network_error, | ||
R.string.inv_generic_error_title, | ||
R.string.inv_generic_error_subtitle) | ||
} |
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,30 @@ | ||
package foodapp.com.foodapp | ||
|
||
import android.app.Activity | ||
import android.app.Application | ||
import dagger.android.AndroidInjector | ||
import dagger.android.DispatchingAndroidInjector | ||
import dagger.android.HasActivityInjector | ||
import foodapp.com.foodapp.di.DaggerAppComponent | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
class FoodApp : Application(), HasActivityInjector { | ||
|
||
@Inject | ||
lateinit var mDispatchingAndroidActivityInjector: DispatchingAndroidInjector<Activity> | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
DaggerAppComponent.builder().create(this).inject(this) | ||
|
||
if (BuildConfig.DEBUG) { | ||
Timber.plant(Timber.DebugTree()) | ||
} | ||
} | ||
|
||
override fun activityInjector(): AndroidInjector<Activity>? { | ||
return mDispatchingAndroidActivityInjector | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
app/src/main/java/foodapp/com/foodapp/base/BasePresenter.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,45 @@ | ||
package foodapp.com.foodapp.base; | ||
|
||
import foodapp.com.data.shared.utils.ErrorUtils | ||
import foodapp.com.foodapp.ErrorType | ||
import timber.log.Timber | ||
|
||
open class BasePresenter<V : MvpView> : MvpPresenter<V> { | ||
|
||
private var mMvpView: V? = null | ||
|
||
val mvpView: V? | ||
get() { | ||
checkViewAttached() | ||
return mMvpView | ||
} | ||
|
||
private val isViewAttached: Boolean | ||
get() = mMvpView != null | ||
|
||
override fun onAttach(mvpView: V) { | ||
mMvpView = mvpView | ||
} | ||
|
||
override fun onDetach() { | ||
mMvpView = null | ||
} | ||
|
||
private fun checkViewAttached() { | ||
if (!isViewAttached) { | ||
Timber.e("Please call Presenter.onAttach(MvpView) before requesting data to the Presenter") | ||
} | ||
} | ||
|
||
fun handleError(throwable: Throwable) { | ||
if (ErrorUtils.isConnectionError(throwable)) { | ||
mvpView!!.onError(ErrorType.CONNECTION_ERROR) | ||
} else if (ErrorUtils.isTimeOut(throwable)) { | ||
mvpView!!.onError(ErrorType.TIMEOUT_ERROR) | ||
} else if (ErrorUtils.isServerError(throwable)) { | ||
mvpView!!.onError(ErrorType.SERVER_ERROR) | ||
} else if (ErrorUtils.isClientError(throwable)) { | ||
mvpView!!.onError(ErrorType.CLIENT_ERROR) | ||
} | ||
} | ||
} |
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,7 @@ | ||
package foodapp.com.foodapp.base | ||
|
||
interface MvpPresenter<V : MvpView> { | ||
fun onAttach(mvpView: V) | ||
|
||
fun onDetach() | ||
} |
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,13 @@ | ||
package foodapp.com.foodapp.base; | ||
|
||
import foodapp.com.foodapp.ErrorType | ||
|
||
interface MvpView { | ||
|
||
fun showLoading() | ||
|
||
fun hideLoading() | ||
|
||
fun onError(type: ErrorType) | ||
|
||
} |
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
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
13 changes: 13 additions & 0 deletions
13
app/src/main/java/foodapp/com/foodapp/di/ActivityBindingModule.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,13 @@ | ||
package foodapp.com.foodapp.di | ||
|
||
import dagger.Module | ||
import dagger.android.ContributesAndroidInjector | ||
import foodapp.com.foodapp.foods.ui.FoodListActivity | ||
import foodapp.com.foodapp.foods.ui.FoodListActivityModule | ||
|
||
@Module | ||
abstract class ActivityBindingModule { | ||
|
||
@ContributesAndroidInjector(modules = [(FoodListActivityModule::class)]) | ||
abstract fun foodListActivity(): FoodListActivity | ||
} |
Oops, something went wrong.