Skip to content

Commit

Permalink
Broadcast autosort and update nav bar colour
Browse files Browse the repository at this point in the history
  • Loading branch information
premnirmal committed Feb 4, 2022
1 parent 98e436c commit af4b5e7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.view.ViewGroup
import android.widget.PopupMenu
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.ItemTouchHelper
import com.github.premnirmal.ticker.analytics.ClickEvent
import com.github.premnirmal.ticker.base.BaseFragment
Expand All @@ -24,6 +25,7 @@ import com.github.premnirmal.ticker.ui.SpacingDecoration
import com.github.premnirmal.tickerwidget.R
import kotlinx.android.synthetic.main.fragment_portfolio.stockList
import kotlinx.android.synthetic.main.fragment_portfolio.view_flipper
import kotlinx.coroutines.launch

/**
* Created by premnirmal on 2/25/16.
Expand Down Expand Up @@ -137,6 +139,11 @@ class PortfolioFragment : BaseFragment(), ChildFragment, QuoteClickListener, OnS
viewModel.portfolio.observe(viewLifecycleOwner) {
update()
}
lifecycleScope.launch {
widgetData.autoSortEnabled.collect {
update()
}
}
}

override fun onResume() {
Expand Down Expand Up @@ -175,17 +182,16 @@ class PortfolioFragment : BaseFragment(), ChildFragment, QuoteClickListener, OnS
parent.onDragStarted()
val widgetData = viewModel.dataForWidgetId(widgetId)
if (widgetData.autoSortEnabled()) {
widgetData.setAutoSort(false)
update()
viewModel.broadcastUpdateWidget(widgetId)
InAppMessage.showMessage(requireActivity(), R.string.autosort_disabled)
} else {
itemTouchHelper?.startDrag(viewHolder)
}
itemTouchHelper?.startDrag(viewHolder)
}

override fun onStopDrag() {
parent.onDragEnded()
val widgetData = viewModel.dataForWidgetId(widgetId)
widgetData.setAutoSort(false)
viewModel.broadcastUpdateWidget(widgetId)
}

override fun setData(bundle: Bundle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ class SettingsFragment : PreferenceFragmentCompat(), ChildFragment,
widgetData.setAutoSort(newValue as Boolean)
true
}
lifecycleScope.launch {
widgetData.autoSortEnabled.collect {
autoSortPref.isChecked = it
}
}
}

run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ class WidgetSettingsFragment : BaseFragment(), ChildFragment, OnClickListener {
updatePreview(widgetData)
}
}
lifecycleScope.launch {
widgetData.autoSortEnabled.collect {
setting_autosort_checkbox.isChecked = it
}
}
}

override fun onClick(v: View) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import com.github.premnirmal.ticker.components.Injector
import com.github.premnirmal.ticker.model.IStocksProvider
import com.github.premnirmal.ticker.network.data.Quote
import com.github.premnirmal.tickerwidget.R
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import javax.inject.Inject

class WidgetData {
Expand Down Expand Up @@ -52,6 +54,9 @@ class WidgetData {
val widgetId: Int
private val tickerList: MutableList<String>
private val preferences: SharedPreferences
private val _autoSortEnabled = MutableStateFlow<Boolean>(false)
val autoSortEnabled: StateFlow<Boolean>
get() = _autoSortEnabled

constructor(
position: Int,
Expand All @@ -73,6 +78,7 @@ class WidgetData {
)
}
save()
_autoSortEnabled.value = autoSortEnabled()
}

constructor(
Expand Down Expand Up @@ -228,6 +234,7 @@ class WidgetData {
preferences.edit()
.putBoolean(AUTOSORT, autoSort)
.apply()
_autoSortEnabled.value = autoSort
}

fun hideHeader(): Boolean = preferences.getBoolean(HIDE_HEADER, false)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<color name="positive_green_dark">#009900</color>
<color name="disabled_grey">#98545454</color>
<color name="unselected_grey">#ffbdbdbd</color>
<color name="nav_bar_bg">#2f2f2f</color>
<color name="nav_bar_bg">@color/default_bg</color>
<color name="nav_bar_bg_2">@color/card_bg</color>
<color name="bottom_bar_bg">@color/card_bg</color>
<color name="actionbar_title_text">#ffffff</color>
Expand Down
4 changes: 2 additions & 2 deletions app/version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
versionName=3.9.766
versionCode=300900766
versionName=3.9.767
versionCode=300900767

0 comments on commit af4b5e7

Please sign in to comment.