Skip to content

Commit d36536f

Browse files
committed
Bug fixes and added Activity and task count
1 parent 1153a2a commit d36536f

14 files changed

+248
-21
lines changed

.idea/misc.xml

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/ncs/o2/UI/MainActivity.kt

+16-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import com.ncs.o2.Domain.Utility.ExtensionsUtil.invisible
5050
import com.ncs.o2.Domain.Utility.ExtensionsUtil.isNull
5151
import com.ncs.o2.Domain.Utility.ExtensionsUtil.performHapticFeedback
5252
import com.ncs.o2.Domain.Utility.ExtensionsUtil.rotate180
53+
import com.ncs.o2.Domain.Utility.ExtensionsUtil.runDelayed
5354
import com.ncs.o2.Domain.Utility.ExtensionsUtil.setOnClickThrottleBounceListener
5455
import com.ncs.o2.Domain.Utility.ExtensionsUtil.visible
5556
import com.ncs.o2.Domain.Utility.GlobalUtils
@@ -140,7 +141,6 @@ class MainActivity : AppCompatActivity(), ProjectCallback, SegmentSelectionBotto
140141
binding.gioActionbar.offlineIndicator.gone()
141142

142143
}
143-
144144
binding.gioActionbar.offlineIndicator.setOnClickThrottleBounceListener {
145145
easyElements.twoBtnDialog("Offline Mode Active", msg = "As network is not available, offline mode is active, things may not be in sync with server","Check Network","Cancel",{
146146
networkChangeReceiver.retryNetworkCheck()
@@ -168,10 +168,12 @@ class MainActivity : AppCompatActivity(), ProjectCallback, SegmentSelectionBotto
168168
// Hide keyboard at startup
169169
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
170170
setContentView(binding.root)
171-
172171
PrefManager.initialize(this)
173172
setUpInitilisations()
173+
174+
174175
}
176+
175177
private fun setUpInitilisations(){
176178
manageViews()
177179
setUpViews()
@@ -189,6 +191,7 @@ class MainActivity : AppCompatActivity(), ProjectCallback, SegmentSelectionBotto
189191
Log.d("projectSegments",PrefManager.getProjectSegments(project).toString())
190192
}
191193
}
194+
192195
private fun manageViews(){
193196
if (PrefManager.getcurrentsegment()== "Select Segment") {
194197
binding.placeholderText.visible()
@@ -283,6 +286,7 @@ class MainActivity : AppCompatActivity(), ProjectCallback, SegmentSelectionBotto
283286
val intentFilter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)
284287
registerReceiver(networkChangeReceiver, intentFilter)
285288
setNotificationCountOnActionBar()
289+
setUpInitilisations()
286290
}
287291

288292

@@ -494,9 +498,13 @@ class MainActivity : AppCompatActivity(), ProjectCallback, SegmentSelectionBotto
494498
override fun onSegmentSelected(segmentName: String) {
495499

496500
// Handle segment selection
501+
binding.gioActionbar.tabLayout.gone()
497502
binding.gioActionbar.titleTv.text = segmentName
498503
segmentText.value = segmentName
499504
viewModel.updateCurrentSegment(segmentName)
505+
runDelayed(1000){
506+
binding.gioActionbar.tabLayout.visible()
507+
}
500508
if (segmentName=="Select Segment"){
501509
binding.gioActionbar.tabLayout.gone()
502510
binding.gioActionbar.searchCont.gone()
@@ -900,7 +908,10 @@ class MainActivity : AppCompatActivity(), ProjectCallback, SegmentSelectionBotto
900908
val intent =
901909
Intent(this@MainActivity, TaskDetailActivity::class.java)
902910
intent.putExtra("task_id", taskId)
911+
intent.putExtra("type", "shareTask")
912+
903913
startActivity(intent)
914+
finish()
904915
overridePendingTransition(
905916
R.anim.slide_in_left,
906917
R.anim.slide_out_left
@@ -957,7 +968,10 @@ class MainActivity : AppCompatActivity(), ProjectCallback, SegmentSelectionBotto
957968
val intent =
958969
Intent(this@MainActivity, TaskDetailActivity::class.java)
959970
intent.putExtra("task_id", taskId)
971+
intent.putExtra("type", "shareTask")
972+
960973
startActivity(intent)
974+
finish()
961975
overridePendingTransition(
962976
R.anim.slide_in_left,
963977
R.anim.slide_out_left

app/src/main/java/com/ncs/o2/UI/Tasks/TaskPage/TaskDetailActivity.kt

+14-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class TaskDetailActivity : AppCompatActivity(), TaskDetailsFragment.ViewVisibili
3636
ActivityTaskDetailBinding.inflate(layoutInflater)
3737
}
3838
lateinit var taskId:String
39+
var type: String? =null
3940
var index:String?=null
4041
lateinit var isworkspace:String
4142
var users:MutableList<UserInMessage> = mutableListOf()
@@ -53,6 +54,12 @@ class TaskDetailActivity : AppCompatActivity(), TaskDetailsFragment.ViewVisibili
5354
registerReceiver(networkChangeReceiver, intentFilter)
5455

5556
taskId = intent.getStringExtra("task_id")!!
57+
val _type=intent.getStringExtra("type")
58+
59+
if (_type!=null){
60+
type=_type
61+
}
62+
5663
val _index= intent.getStringExtra("index")
5764
if (_index!=null){
5865
index=_index
@@ -77,9 +84,14 @@ class TaskDetailActivity : AppCompatActivity(), TaskDetailsFragment.ViewVisibili
7784

7885
@Deprecated("Deprecated in Java")
7986
override fun onBackPressed() {
80-
//startActivity(Intent(this@TaskDetailActivity, MainActivity::class.java))
8187
super.onBackPressed()
82-
overridePendingTransition(R.anim.slide_in_right, me.shouheng.utils.R.anim.slide_out_right)
88+
if (type=="shareTask" ){
89+
startActivity(Intent(this@TaskDetailActivity, MainActivity::class.java))
90+
overridePendingTransition(R.anim.slide_in_right, me.shouheng.utils.R.anim.slide_out_right)
91+
}
92+
else{
93+
overridePendingTransition(R.anim.slide_in_right, me.shouheng.utils.R.anim.slide_out_right)
94+
}
8395

8496
}
8597
private fun setActionbar() {

app/src/main/java/com/ncs/o2/UI/Tasks/TaskPage/TasksDetailsHolderFragment.kt

+66-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
package com.ncs.o2.UI.Tasks.TaskPage
22

33
import android.os.Bundle
4+
import android.util.Log
45
import android.view.LayoutInflater
56
import android.view.View
67
import android.view.ViewGroup
8+
import android.widget.ImageView
9+
import android.widget.LinearLayout
10+
import android.widget.TextView
11+
import androidx.constraintlayout.widget.ConstraintLayout
12+
import androidx.core.content.ContextCompat
713
import androidx.fragment.app.Fragment
14+
import androidx.viewpager2.widget.ViewPager2
815
import com.google.android.material.tabs.TabLayoutMediator
916
import com.ncs.o2.Data.Room.MessageRepository.MessageDatabase
1017
import com.ncs.o2.Domain.Models.Message
18+
import com.ncs.o2.Domain.Utility.ExtensionsUtil.gone
19+
import com.ncs.o2.Domain.Utility.ExtensionsUtil.visible
1120
import com.ncs.o2.HelperClasses.PrefManager
21+
import com.ncs.o2.R
1222
import com.ncs.o2.UI.UIComponents.Adapters.TaskDetailsViewPagerAdpater
23+
import com.ncs.o2.UI.UIComponents.Adapters.TaskSectionViewPagerAdapter
1324
import com.ncs.o2.databinding.FragmentTasksDetailsHolderBinding
1425
import dagger.hilt.android.AndroidEntryPoint
1526
import kotlinx.coroutines.CoroutineScope
1627
import kotlinx.coroutines.Dispatchers
1728
import kotlinx.coroutines.launch
29+
import kotlinx.coroutines.sync.withLock
1830
import kotlinx.coroutines.withContext
1931
import javax.inject.Inject
2032

@@ -57,29 +69,75 @@ class TasksDetailsHolderFragment : Fragment() {
5769
private fun setUpTabsLayout() {
5870

5971

72+
val viewPager2 = binding.viewPager2
73+
val adapter = TaskDetailsViewPagerAdpater(this, 3)
74+
viewPager2.adapter = adapter
75+
76+
val tabLayout = activityBinding.binding.tabLayout
77+
tabLayout.removeAllTabs()
78+
79+
val tabLayoutMediator = TabLayoutMediator(tabLayout, viewPager2) { tab, position ->
80+
val customTabView = LayoutInflater.from(tabLayout.context).inflate(R.layout.tab_item, null)
81+
val tabText: TextView = customTabView.findViewById(R.id.tabText)
82+
val iconCount: TextView = customTabView.findViewById(R.id.iconCount)
83+
val countParent: ConstraintLayout = customTabView.findViewById(R.id.count)
6084

61-
TabLayoutMediator(
62-
activityBinding.binding.tabLayout, binding.viewPager2
63-
) { tab, position ->
85+
updateTabColors(viewPager2.currentItem)
86+
87+
viewPager2.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
88+
override fun onPageSelected(position: Int) {
89+
updateTabColors(position)
90+
}
91+
})
6492
when(position){
65-
0-> tab.text="Details"
93+
0-> {
94+
countParent.gone()
95+
tabText.text = "Details"
96+
}
6697
1-> {
6798
CoroutineScope(Dispatchers.IO).launch {
6899
val messages=db.messagesDao().getMessagesForTask(PrefManager.getcurrentProject(),activityBinding.taskId)
69100
withContext(Dispatchers.Main){
70101
if (messages.isEmpty()){
71-
tab.text="Activity"
102+
countParent.gone()
103+
tabText.text = "Activity"
72104
}
73105
else{
74-
tab.text="Activity (${messages.size})"
106+
countParent.visible()
107+
tabText.text = "Activity"
108+
iconCount.text=messages.size.toString()
75109
}
76110
}
77111
}
78112

79113
}
80-
2-> tab.text="Checklist"
114+
2-> {
115+
countParent.gone()
116+
tabText.text = "Checklist"
117+
}
118+
}
119+
tab.customView = customTabView
120+
}
121+
122+
tabLayoutMediator.attach()
123+
124+
}
125+
fun updateTabColors(selectedPosition: Int) {
126+
val selectedColor = ContextCompat.getColor(activityBinding.binding.tabLayout.context, R.color.selected_tab_color)
127+
val unselectedColor = ContextCompat.getColor(activityBinding.binding.tabLayout.context, R.color.unselected_tab_color)
128+
129+
for (i in 0 until activityBinding.binding.tabLayout.tabCount) {
130+
val tab = activityBinding.binding.tabLayout.getTabAt(i)
131+
val tabText = tab?.customView?.findViewById<TextView>(R.id.tabText)
132+
val tabIconBg = tab?.customView?.findViewById<LinearLayout>(R.id.tabIcon)
133+
134+
if (tab != null && tabText != null && tabIconBg != null) {
135+
val color = if (i == selectedPosition) selectedColor else unselectedColor
136+
val drawable=if (i == selectedPosition) R.drawable.tab_selected__icon_bg else R.drawable.tab_unselected_icon_bg
137+
tabText.setTextColor(color)
138+
tabIconBg.setBackgroundDrawable(resources.getDrawable(drawable))
81139
}
82-
}.attach()
140+
}
83141
}
84142

85143
}

app/src/main/java/com/ncs/o2/UI/Tasks/TasksHolderFragment.kt

+56-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ import android.util.Log
55
import android.view.LayoutInflater
66
import android.view.View
77
import android.view.ViewGroup
8+
import android.widget.ImageView
9+
import android.widget.LinearLayout
10+
import android.widget.TextView
811
import androidx.activity.OnBackPressedCallback
12+
import androidx.constraintlayout.widget.ConstraintLayout
13+
import androidx.core.content.ContextCompat
914
import androidx.fragment.app.Fragment
1015
import androidx.fragment.app.viewModels
1116
import androidx.recyclerview.widget.LinearLayoutManager
1217
import androidx.recyclerview.widget.RecyclerView
18+
import androidx.viewpager2.widget.ViewPager2
1319
import com.google.android.material.tabs.TabLayoutMediator
1420
import com.ncs.o2.Constants.SwitchFunctions
1521
import com.ncs.o2.Data.Room.TasksRepository.TasksDatabase
@@ -18,8 +24,10 @@ import com.ncs.o2.Domain.Models.Task
1824
import com.ncs.o2.Domain.Models.TaskItem
1925
import com.ncs.o2.Domain.Repositories.FirestoreRepository
2026
import com.ncs.o2.Domain.Utility.ExtensionsUtil.gone
27+
import com.ncs.o2.Domain.Utility.ExtensionsUtil.setBackgroundDrawable
2128
import com.ncs.o2.Domain.Utility.ExtensionsUtil.visible
2229
import com.ncs.o2.HelperClasses.PrefManager
30+
import com.ncs.o2.R
2331
import com.ncs.o2.UI.MainActivity
2432
import com.ncs.o2.UI.Tasks.Sections.TaskSectionFragment
2533
import com.ncs.o2.UI.Tasks.Sections.TaskSectionViewModel
@@ -132,9 +140,27 @@ class TasksHolderFragment : Fragment(),SegmentSelectionBottomSheet.sendSectionsL
132140

133141
private fun setUpTabsLayout(list: MutableList<String>) {
134142
Log.d("sectionslist", list.toString())
135-
TabLayoutMediator(
136-
activityBinding.gioActionbar.tabLayout, binding.viewPager2
137-
) { tab, position ->
143+
144+
val viewPager2 = binding.viewPager2
145+
val adapter = TaskSectionViewPagerAdapter(this, list.size, list)
146+
viewPager2.adapter = adapter
147+
148+
val tabLayout = activityBinding.gioActionbar.tabLayout
149+
tabLayout.removeAllTabs()
150+
151+
val tabLayoutMediator = TabLayoutMediator(tabLayout, viewPager2) { tab, position ->
152+
val customTabView = LayoutInflater.from(tabLayout.context).inflate(R.layout.tab_item, null)
153+
val tabText: TextView = customTabView.findViewById(R.id.tabText)
154+
val iconCount: TextView = customTabView.findViewById(R.id.iconCount)
155+
val countParent: ConstraintLayout = customTabView.findViewById(R.id.count)
156+
157+
updateTabColors(viewPager2.currentItem)
158+
159+
viewPager2.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
160+
override fun onPageSelected(position: Int) {
161+
updateTabColors(position)
162+
}
163+
})
138164
if (position < list.size && position !in processedPositions) {
139165
Log.d("sectionslist", "current position is $position")
140166

@@ -151,9 +177,12 @@ class TasksHolderFragment : Fragment(),SegmentSelectionBottomSheet.sendSectionsL
151177

152178
withContext(Dispatchers.Main) {
153179
if (tasks.isEmpty()) {
154-
tab.text = list[currentPosition]
180+
countParent.gone()
181+
tabText.text = list[position]
155182
} else {
156-
tab.text = "${list[currentPosition]} (${tasks.size})"
183+
countParent.visible()
184+
tabText.text = list[position]
185+
iconCount.text=tasks.size.toString()
157186
}
158187
}
159188

@@ -162,10 +191,31 @@ class TasksHolderFragment : Fragment(),SegmentSelectionBottomSheet.sendSectionsL
162191
}
163192
}
164193
}
165-
}.attach()
194+
tab.customView = customTabView
195+
}
196+
197+
tabLayoutMediator.attach()
198+
199+
166200
}
167201

202+
fun updateTabColors(selectedPosition: Int) {
203+
val selectedColor = ContextCompat.getColor(activityBinding.gioActionbar.tabLayout.context, R.color.selected_tab_color)
204+
val unselectedColor = ContextCompat.getColor(activityBinding.gioActionbar.tabLayout.context, R.color.unselected_tab_color)
205+
206+
for (i in 0 until activityBinding.gioActionbar.tabLayout.tabCount) {
207+
val tab = activityBinding.gioActionbar.tabLayout.getTabAt(i)
208+
val tabText = tab?.customView?.findViewById<TextView>(R.id.tabText)
209+
val tabIconBg = tab?.customView?.findViewById<LinearLayout>(R.id.tabIcon)
168210

211+
if (tab != null && tabText != null && tabIconBg != null) {
212+
val color = if (i == selectedPosition) selectedColor else unselectedColor
213+
val drawable=if (i == selectedPosition) R.drawable.tab_selected__icon_bg else R.drawable.tab_unselected_icon_bg
214+
tabText.setTextColor(color)
215+
tabIconBg.setBackgroundDrawable(resources.getDrawable(drawable))
216+
}
217+
}
218+
}
169219

170220
override fun sendSectionsList(list: MutableList<String>) {
171221
sectionsList.clear()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="@color/primary"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2z"/>
5+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="@color/account"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2z"/>
5+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:color="@color/primary" android:state_selected="true" />
4+
<item android:color="@color/account" />
5+
</selector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:drawable="@drawable/baseline_circle_primary_24" android:state_selected="true" />
4+
<item android:drawable="@drawable/baseline_circle_unselected_24" />
5+
</selector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="oval">
4+
<solid android:color="@color/primary"/>
5+
<corners android:radius="5sp"/>
6+
</shape>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="oval">
4+
<solid android:color="@color/account"/>
5+
<corners android:radius="5sp"/>
6+
</shape>

0 commit comments

Comments
 (0)