Api call time out setting
Completed switching between fragments on home with theme switching and language switching Language switch live data Home fragment background switching w.r.t. to time. Icon settings on home fragment
This commit is contained in:
@@ -9,6 +9,7 @@ import android.widget.TextView
|
||||
import androidx.cardview.widget.CardView
|
||||
import com.woka.R
|
||||
import com.woka.utils.toast
|
||||
import org.w3c.dom.Text
|
||||
|
||||
class BottomNavigation: FrameLayout {
|
||||
|
||||
@@ -25,7 +26,6 @@ class BottomNavigation: FrameLayout {
|
||||
}
|
||||
|
||||
private var selectedItem = HOME
|
||||
|
||||
fun getSelectedTab() = selectedItem
|
||||
|
||||
// colors
|
||||
@@ -43,6 +43,8 @@ class BottomNavigation: FrameLayout {
|
||||
private var myListImg: ImageView? = null
|
||||
private var myListTxt: TextView? = null
|
||||
|
||||
private var exploreWokaTxt: TextView? = null
|
||||
|
||||
init {
|
||||
val view = inflate(context, R.layout.layout_bottom_nav, this)
|
||||
|
||||
@@ -56,6 +58,10 @@ class BottomNavigation: FrameLayout {
|
||||
myListImg = view.findViewById(R.id.my_list_img_bn)
|
||||
myListTxt = view.findViewById(R.id.my_list_txt_bn)
|
||||
|
||||
exploreWokaTxt = view.findViewById(R.id.explore_woka_txt_bn)
|
||||
|
||||
initTitles()
|
||||
|
||||
clickEvents()
|
||||
}
|
||||
|
||||
@@ -106,6 +112,12 @@ class BottomNavigation: FrameLayout {
|
||||
selectedItem = tab
|
||||
}
|
||||
|
||||
fun initTitles(){
|
||||
homeTxt?.text = context.getString(R.string.home)
|
||||
myListTxt?.text = context.getString(R.string.my_list)
|
||||
exploreWokaTxt?.text = context.getString(R.string.explore_woka)
|
||||
}
|
||||
|
||||
interface OnBottomTabSelectListener{
|
||||
fun onBottomTabSelected(tab: Int)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.woka.home
|
||||
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View.GONE
|
||||
import android.view.View.VISIBLE
|
||||
import android.view.WindowManager
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.GravityCompat
|
||||
@@ -29,8 +31,11 @@ import com.woka.utils.LOCALE_ENGLISH
|
||||
import com.woka.utils.LOCALE_HINDI
|
||||
import com.woka.utils.TAG
|
||||
import com.woka.utils.WokaBaseActivity
|
||||
import com.woka.utils.changeLocale
|
||||
|
||||
class HomeActivity : WokaBaseActivity(), Observer<ApiResult<UserDataResponse>>, BottomNavigation.OnBottomTabSelectListener {
|
||||
class HomeActivity : WokaBaseActivity(),
|
||||
Observer<ApiResult<UserDataResponse>>,
|
||||
BottomNavigation.OnBottomTabSelectListener {
|
||||
|
||||
private lateinit var binding: ActivityHomeBinding
|
||||
|
||||
@@ -47,6 +52,9 @@ class HomeActivity : WokaBaseActivity(), Observer<ApiResult<UserDataResponse>>,
|
||||
insets
|
||||
}
|
||||
|
||||
window?.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
|
||||
window?.statusBarColor = Color.parseColor("#55cffe")
|
||||
|
||||
viewModel = ViewModelProvider(this)[HomeViewModel::class.java]
|
||||
|
||||
userPrefs?.userLiveData?.observe(this, this)
|
||||
@@ -70,6 +78,12 @@ class HomeActivity : WokaBaseActivity(), Observer<ApiResult<UserDataResponse>>,
|
||||
sbVersion.text = versionName
|
||||
|
||||
bottomNav.setOnBottomTabSelectListener(this@HomeActivity)
|
||||
bottomNav.selectTab(viewModel.selectedBottomTab)
|
||||
}
|
||||
|
||||
viewModel.localeChangeLiveData.observe(this){
|
||||
// locale has changed
|
||||
binding.bottomNav.initTitles()
|
||||
}
|
||||
|
||||
selectTheme(userPrefs?.appTheme?: Theme.THEME_ONE, true)
|
||||
@@ -123,8 +137,10 @@ class HomeActivity : WokaBaseActivity(), Observer<ApiResult<UserDataResponse>>,
|
||||
|
||||
userPrefs?.appTheme = theme
|
||||
|
||||
binding.homeDrawer.closeDrawer(GravityCompat.END)
|
||||
binding.bottomNav.selectTab(HOME)
|
||||
if (!init) {
|
||||
binding.homeDrawer.closeDrawer(GravityCompat.END)
|
||||
binding.bottomNav.selectTab(HOME)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,6 +165,12 @@ class HomeActivity : WokaBaseActivity(), Observer<ApiResult<UserDataResponse>>,
|
||||
}
|
||||
|
||||
userPrefs?.appLanguage = locale
|
||||
changeLocale(locale)
|
||||
|
||||
if (!init){
|
||||
binding.homeDrawer.closeDrawer(GravityCompat.END)
|
||||
viewModel.sendLocaleChangeEvent(locale)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -176,6 +198,8 @@ class HomeActivity : WokaBaseActivity(), Observer<ApiResult<UserDataResponse>>,
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.selectedBottomTab = tab
|
||||
}
|
||||
|
||||
// observer for userdata changes
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
package com.woka.home
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.woka.home.BottomNavigation.Companion.HOME
|
||||
|
||||
class HomeViewModel: ViewModel()
|
||||
class HomeViewModel: ViewModel(){
|
||||
|
||||
var selectedBottomTab: Int = HOME
|
||||
|
||||
private val _localeChangeLiveData = MutableLiveData<String>()
|
||||
val localeChangeLiveData: LiveData<String>
|
||||
get() = _localeChangeLiveData
|
||||
|
||||
fun sendLocaleChangeEvent(locale: String){
|
||||
_localeChangeLiveData.postValue(locale)
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,104 @@
|
||||
package com.woka.home.fragments
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.Intent.ACTION_TIME_TICK
|
||||
import android.content.IntentFilter
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.woka.R
|
||||
import com.woka.databinding.FragmentHome1Binding
|
||||
import com.woka.utils.toast
|
||||
import java.util.Calendar
|
||||
|
||||
class Home1Fragment : Fragment() {
|
||||
|
||||
enum class TimePeriod{
|
||||
MORNING,
|
||||
AFTERNOON,
|
||||
EVENING,
|
||||
NIGHT;
|
||||
|
||||
companion object{
|
||||
fun getCurrentTimePeriod(): TimePeriod{
|
||||
val cal = Calendar.getInstance()
|
||||
val hrs = cal.get(Calendar.HOUR_OF_DAY)
|
||||
|
||||
return when (hrs) {
|
||||
in 6..10 -> MORNING
|
||||
in 11..15 -> AFTERNOON
|
||||
in 16..19 -> EVENING
|
||||
else -> NIGHT
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var binding: FragmentHome1Binding
|
||||
|
||||
private var currentBackground: TimePeriod? = null
|
||||
private var minuteReceiver: BroadcastReceiver? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
binding = FragmentHome1Binding.inflate(inflater, container, false)
|
||||
|
||||
updateBackground()
|
||||
|
||||
minuteReceiver = object : BroadcastReceiver(){
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
// this function is called every minute
|
||||
updateBackground()
|
||||
}
|
||||
}
|
||||
|
||||
activity?.registerReceiver(minuteReceiver, IntentFilter(ACTION_TIME_TICK))
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
activity?.unregisterReceiver(minuteReceiver)
|
||||
}
|
||||
|
||||
private fun updateBackground(){
|
||||
toast("Background updated")
|
||||
val timePeriod = TimePeriod.getCurrentTimePeriod()
|
||||
if (currentBackground != timePeriod){
|
||||
// time period has changed
|
||||
activity?.let {
|
||||
binding.root.background = when(timePeriod){
|
||||
TimePeriod.MORNING -> {
|
||||
it.window.statusBarColor = ContextCompat.getColor(it, R.color.morning_status)
|
||||
ContextCompat.getDrawable(it, R.drawable.morning_bg)
|
||||
}
|
||||
TimePeriod.AFTERNOON -> {
|
||||
it.window.statusBarColor = ContextCompat.getColor(it, R.color.afternoon_status)
|
||||
ContextCompat.getDrawable(it, R.drawable.afternoon_bg)
|
||||
}
|
||||
TimePeriod.EVENING -> {
|
||||
it.window.statusBarColor = ContextCompat.getColor(it, R.color.evening_status)
|
||||
ContextCompat.getDrawable(it, R.drawable.evening_bg)
|
||||
}
|
||||
TimePeriod.NIGHT -> {
|
||||
it.window.statusBarColor = ContextCompat.getColor(it, R.color.night_status)
|
||||
ContextCompat.getDrawable(it, R.drawable.night_bg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentBackground = timePeriod
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun newInstance() = Home1Fragment()
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import retrofit2.Response
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import java.net.UnknownHostException
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
object RetrofitHelper {
|
||||
|
||||
@@ -51,6 +52,8 @@ object RetrofitHelper {
|
||||
chain.proceed(request.build())
|
||||
})
|
||||
|
||||
clientBuilder.callTimeout(10, TimeUnit.SECONDS)
|
||||
|
||||
retrofit = Retrofit.Builder()
|
||||
.baseUrl(BuildConfig.WOKA_STAGINNG_BASE_URL)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
|
||||
Reference in New Issue
Block a user