Skip to content

Commit

Permalink
add utils and misc and viewbinding
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedebrahim96 committed Nov 23, 2021
1 parent b7ad179 commit 0f2fe56
Show file tree
Hide file tree
Showing 71 changed files with 2,442 additions and 484 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/ui.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
Expand Down
8 changes: 8 additions & 0 deletions .idea/misc.xml

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

9 changes: 9 additions & 0 deletions .idea/modules.xml

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

11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# Namshi-Customer
The Namshi shopping app is your no.1 fashion & beauty destination in Saudi Arabia, United Arab Emirates, Kuwait, Oman, Bahrain, Qatar & Iraq.
<h1 align="center">Namshi Customer</h1>
<img alt="Build Status" src="https://github.com/mohamedebrahim96/Namshi-Customer/workflows/Android%20CI/badge.svg"/>

<p align="center">
The Namshi shopping app is your no.1 fashion & beauty destination in Saudi Arabia, United Arab Emirates, Kuwait, Oman, Bahrain, Qatar & Iraq.
Enjoy online shopping with over 1,300 brands and more than 130,000 products across clothing, sportswear, footwear, accessories, beauty, fragrances, gift ideas and more.
Appreciate the advantages of on-the-go shopping online & use our easy filters to find exactly what you’ve been searching for, all in one online shopping destination.
</p>
</br>
43 changes: 34 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlinx-serialization'
id 'kotlin-parcelize'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'

}
apply from: "$rootDir/dependencies.gradle"

Expand All @@ -22,11 +24,11 @@ android {
arguments += ["room.schemaLocation" : "$projectDir/schemas".toString()]
}
}
javaCompileOptions {
annotationProcessorOptions {
arguments["dagger.hilt.disableModulesHaveInstallInCheck"] = "true"
}
}
// javaCompileOptions {
// annotationProcessorOptions {
// arguments["dagger.hilt.disableuiHaveInstallInCheck"] = "true"
// }
// }
}

buildTypes {
Expand All @@ -45,10 +47,17 @@ android {
jvmTarget = "11"
}

// kotlinOptions {
// jvmTarget = '1.8'
// }
buildFeatures {
dataBinding true
viewBinding = true
}

// buildFeatures {
// dataBinding true
// }

lintOptions {
abortOnError false
}
Expand All @@ -70,6 +79,9 @@ android {
kotlinOptions.freeCompilerArgs += ["-Xopt-in=kotlin.time.ExperimentalTime"]
kotlinOptions.freeCompilerArgs += ["-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"]
}
kapt {
correctErrorTypes true
}
}

dependencies {
Expand All @@ -85,9 +97,9 @@ dependencies {


// binding
implementation ("com.github.skydoves:bindables:$versions.bindablesVersion") {
exclude group: "com.google.android.material"
}
// implementation ("com.github.skydoves:bindables:$versions.bindablesVersion") {
// exclude group: "com.google.android.material"
// }

// coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$versions.coroutinesVersion"
Expand All @@ -108,6 +120,8 @@ dependencies {
implementation "com.squareup.retrofit2:converter-moshi:$versions.retrofitVersion"
implementation "com.squareup.okhttp3:logging-interceptor:$versions.okhttpVersion"
testImplementation "com.squareup.okhttp3:mockwebserver:$versions.okhttpVersion"
implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'
implementation 'com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0'

// moshi
implementation "com.squareup.moshi:moshi-kotlin:$versions.moshiVersion"
Expand Down Expand Up @@ -139,4 +153,15 @@ dependencies {
androidTestImplementation "androidx.test.espresso:espresso-core:$versions.espressoVersion"


implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'
implementation 'com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0'

//Serialization
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1"


//Rx
implementation 'io.reactivex.rxjava3:rxjava:3.0.13'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.namshi.customer
import androidx.lifecycle.Lifecycle
import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.namshi.customer.ui.details.DetailActivity
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Rule
Expand Down
11 changes: 4 additions & 7 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,29 @@
package="com.namshi.customer">

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

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

<application
android:name=".NamshiApp"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.NamshiCustomer"
tools:ignore="AllowBackup">
<activity
android:name=".ui.main.MainActivity"
android:exported="true"
android:screenOrientation="portrait">
android:screenOrientation="portrait"
android:theme="@style/Theme.NamshiCustomer.NoActionBar">
<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"
android:screenOrientation="portrait"

/>
</application>

</manifest>
43 changes: 42 additions & 1 deletion app/src/main/java/com/namshi/customer/NamshiApp.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.namshi.customer

import android.app.Application
import com.namshi.customer.misc.HyperlinkedDebugTree
import dagger.hilt.android.HiltAndroidApp
import io.reactivex.rxjava3.exceptions.UndeliverableException
import io.reactivex.rxjava3.plugins.RxJavaPlugins
import timber.log.Timber


/**
Expand All @@ -11,4 +15,41 @@ import dagger.hilt.android.HiltAndroidApp
*/

@HiltAndroidApp
class NamshiApp : Application()
class NamshiApp : Application(){
companion object {

@get:Synchronized
lateinit var instance: NamshiApp
private set
}


override fun onCreate() {
super.onCreate()
instance = this


initTimber()
initRxErrorHandler()
}

private fun initTimber() {
Timber.plant(HyperlinkedDebugTree())
}

private fun initRxErrorHandler() {
//to avoid crash when undelivered exception occurs in rxjava
RxJavaPlugins.setErrorHandler { e ->
if (e is UndeliverableException) {
// Merely log undeliverable exceptions
Timber.e(e)
} else {
// Forward all others to current thread's uncaught exception handler
Thread.currentThread().also { thread ->
thread.uncaughtExceptionHandler?.uncaughtException(thread, e)
}
}
}
}

}
94 changes: 94 additions & 0 deletions app/src/main/java/com/namshi/customer/base/BaseActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package com.namshi.customer.base

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.PersistableBundle
import androidx.annotation.TransitionRes
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import androidx.lifecycle.Lifecycle
import com.bumptech.glide.Glide
import com.namshi.customer.R
import io.reactivex.rxjava3.disposables.CompositeDisposable


abstract class BaseActivity : AppCompatActivity() {

protected val subscriptions = CompositeDisposable()
protected val handler = Handler(Looper.getMainLooper())


companion object {

}


override fun onPause() {
super.onPause()
Glide.get(this).clearMemory()
}

override fun onDestroy() {
subscriptions.clear()
super.onDestroy()
}

/**
* Adds fragment on current stack
* There are bunch of options which are self explanatory
*/
fun addFragment(
fragment: Fragment,
replace: Boolean = false, addToBackStack: Boolean = true,
tag: String = fragment.javaClass.simpleName,
fragmentManager: FragmentManager = supportFragmentManager,
containerId: Int = R.id.container,
) {

val transaction = fragmentManager.beginTransaction()

if (replace) {
transaction.replace(containerId, fragment, tag)
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
} else {
val oldFragment = getCurrentTopFragment(fragmentManager)
oldFragment?.let { transaction.setMaxLifecycle(it, Lifecycle.State.STARTED) }
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
//set maxLifecycle of CurrentTopFragment to STARTED, when fragment is being added only,
//No need to setMaxLifecycle when fragment is being replaced
transaction.add(containerId, fragment, tag)
}

if (addToBackStack)
transaction.addToBackStack(tag)

//this does not crash in case activity was not in correct state
transaction.commitAllowingStateLoss()
}

private fun getCurrentTopFragment(fragmentManager: FragmentManager): Fragment? {
try {
val stackCount = fragmentManager.backStackEntryCount
if (stackCount > 0) {
val backEntry = fragmentManager.getBackStackEntryAt(stackCount - 1)
return fragmentManager.findFragmentByTag(backEntry.name)
} else {
val fragments = fragmentManager.fragments
if (fragments.size > 0) {
for (f in fragments) {
if (f != null && !f.isHidden)
return f
}
}
}
return null
} catch (e: KotlinNullPointerException) {
return null
}
}

}
Loading

0 comments on commit 0f2fe56

Please sign in to comment.