-
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.
- Loading branch information
1 parent
b7ad179
commit 0f2fe56
Showing
71 changed files
with
2,442 additions
and
484 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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> |
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
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
94 changes: 94 additions & 0 deletions
94
app/src/main/java/com/namshi/customer/base/BaseActivity.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,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 | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.