Skip to content

Commit

Permalink
Theming and colour updates
Browse files Browse the repository at this point in the history
  • Loading branch information
premnirmal committed Jul 22, 2022
1 parent 937f856 commit 1008b62
Show file tree
Hide file tree
Showing 32 changed files with 212 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.github.mikephil.charting.data.LineData
import com.github.mikephil.charting.data.LineDataSet
import com.github.premnirmal.ticker.model.IHistoryProvider.Range
import com.github.premnirmal.ticker.network.data.DataPoint
import com.github.premnirmal.ticker.network.data.Quote
import com.github.premnirmal.ticker.ui.DateAxisFormatter
import com.github.premnirmal.ticker.ui.HourAxisFormatter
import com.github.premnirmal.ticker.ui.MultilineXAxisRenderer
Expand Down Expand Up @@ -53,7 +54,7 @@ abstract class BaseGraphActivity<T : ViewBinding> : BaseActivity<T>() {
graphView.marker = TextMarkerView(this)
}

protected fun loadGraph(ticker: String) {
protected fun loadGraph(ticker: String, quote: Quote) {
val graphView: LineChart = findViewById(R.id.graphView)
if (dataPoints == null || dataPoints!!.isEmpty()) {
onNoGraphData(graphView)
Expand All @@ -66,10 +67,10 @@ abstract class BaseGraphActivity<T : ViewBinding> : BaseActivity<T>() {
val series = LineDataSet(dataPoints, ticker)
series.setDrawHorizontalHighlightIndicator(false)
series.setDrawValues(false)
val colorAccent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
ContextCompat.getColor(this, android.R.color.system_accent1_600)
val colorAccent = if (quote.changeInPercent >= 0) {
ContextCompat.getColor(this, R.color.positive_green_dark)
} else {
ContextCompat.getColor(this, R.color.accent_fallback)
ContextCompat.getColor(this, R.color.negative_red)
}
series.setDrawFilled(true)
series.color = colorAccent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class GraphActivity : BaseGraphActivity<ActivityGraphBinding>() {
this.quote = quote
binding.tickerName.text = ticker
binding.desc.text = quote.name
}
viewModel.data.observe(this) { data ->
dataPoints = data
loadGraph(ticker)
viewModel.data.observe(this) { data ->
dataPoints = data
loadGraph(ticker, quote)
}
}
viewModel.error.observe(this) {
showErrorAndFinish()
Expand All @@ -66,8 +66,6 @@ class GraphActivity : BaseGraphActivity<ActivityGraphBinding>() {
super.onStart()
if (dataPoints == null) {
fetchGraphData()
} else {
loadGraph(ticker)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ class QuoteDetailActivity : BaseGraphActivity<ActivityQuoteDetailBinding>(), New
quote = result.data
fetchNewsAndChartData()
setupQuoteUi()
viewModel.data.observe(this) { data ->
dataPoints = data
loadGraph(ticker, quote)
}
} else {
InAppMessage.showMessage(binding.parentView, R.string.error_fetching_stock, error = true)
binding.progress.visibility = View.GONE
Expand All @@ -134,10 +138,6 @@ class QuoteDetailActivity : BaseGraphActivity<ActivityQuoteDetailBinding>(), New
viewModel.details.asLiveData().observe(this) {
quoteDetailsAdapter.submitList(it)
}
viewModel.data.observe(this) { data ->
dataPoints = data
loadGraph(ticker)
}
viewModel.fetchQuoteInRealTime(ticker)
viewModel.dataFetchError.observe(this) {
binding.progress.visibility = View.GONE
Expand Down Expand Up @@ -424,8 +424,6 @@ class QuoteDetailActivity : BaseGraphActivity<ActivityQuoteDetailBinding>(), New
}
if (dataPoints == null) {
fetchData()
} else {
loadGraph(ticker)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.github.premnirmal.ticker.portfolio

import android.annotation.SuppressLint
import android.content.res.Resources.Theme
import android.util.TypedValue
import android.view.View
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.github.premnirmal.ticker.network.data.Quote
import com.github.premnirmal.ticker.portfolio.drag_drop.ItemTouchHelperViewHolder
import com.github.premnirmal.tickerwidget.R
import com.github.premnirmal.tickerwidget.R.color
import com.github.premnirmal.tickerwidget.databinding.ItemPositionBinding
import com.github.premnirmal.tickerwidget.databinding.ItemStockBinding
import com.robinhood.ticker.TickerUtils
Expand All @@ -19,9 +20,14 @@ import com.robinhood.ticker.TickerView
*/
abstract class PortfolioVH(itemView: View) : RecyclerView.ViewHolder(itemView), ItemTouchHelperViewHolder {

protected val positiveColor: Int = ContextCompat.getColor(itemView.context, color.positive_green)
protected val negativeColor: Int = ContextCompat.getColor(itemView.context, color.negative_red)
protected val neutralColor: Int = ContextCompat.getColor(itemView.context, color.text_1)
protected val positiveColor: Int = ContextCompat.getColor(itemView.context, R.color.positive_green)
protected val negativeColor: Int = ContextCompat.getColor(itemView.context, R.color.negative_red)
protected val neutralColor: Int by lazy {
val typedValue = TypedValue()
val theme: Theme = itemView.context.theme
theme.resolveAttribute(com.google.android.material.R.attr.colorOnSurfaceVariant, typedValue, true)
ContextCompat.getColor(itemView.context, typedValue.data)
}

@Throws(Exception::class) protected abstract fun updateView(quote: Quote, color: Int)

Expand Down
10 changes: 5 additions & 5 deletions app/src/main/res/layout-land/activity_quote_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
android:layout_marginTop="@dimen/activity_vertical_margin"
android:gravity="center"
app:layout_scrollFlags="scroll"
android:textColor="@color/text_3"
android:textColor="?attr/colorOnSurface"
tools:text="Apple Inc."
/>

Expand Down Expand Up @@ -118,7 +118,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/quote_details_margin"
android:textAppearance="@style/TextAppearance.StocksWidget.TitleLarge"
android:textColor="@color/text_2"
android:textColor="?attr/colorOnSurfaceVariant"
android:gravity="center"
tools:text="$132.99"/>

Expand Down Expand Up @@ -297,15 +297,15 @@
android:layout_marginBottom="2dp"
android:gravity="center"
tools:text="3"
android:textColor="@color/text_1"
android:textColor="?attr/colorOnSurfaceVariant"
style="@style/Widget.StocksWidget.TextView.TitleMedium"
android:textAppearance="@style/TextAppearance.StocksWidget.TitleMedium"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shares"
android:textColor="@color/text_3"
android:textColor="?attr/colorOnSurface"
/>

</LinearLayout>
Expand All @@ -325,7 +325,7 @@
android:gravity="center"
android:textSize="@dimen/xlarge_text"
tools:text="$2,400.00"
android:textColor="@color/text_1"
android:textColor="?attr/colorOnSurfaceVariant"
android:textAppearance="@style/TextAppearance.StocksWidget.TickerBold"
/>
<TextView
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout-sw600dp-land/activity_alerts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
android:background="@color/error_red"
android:gravity="center"
android:padding="@dimen/activity_horizontal_margin"
android:textColor="@color/snackbar_text"
android:textColor="?attr/colorOnSurface"
android:text="@string/alerts_disabled"
android:visibility="gone"
tools:visibility="visible"
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/res/layout-sw600dp-land/activity_quote_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:textColor="@color/text_3"
android:textColor="?attr/colorOnSurface"
android:gravity="center"
app:layout_scrollFlags="scroll"
tools:text="Apple Inc."
Expand Down Expand Up @@ -137,7 +137,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/quote_details_margin"
android:textAppearance="@style/TextAppearance.StocksWidget.TitleLarge"
android:textColor="@color/text_2"
android:textColor="?attr/colorOnSurfaceVariant"
android:gravity="center"
tools:text="$132.99"/>

Expand Down Expand Up @@ -300,15 +300,15 @@
android:gravity="center"
android:textSize="@dimen/xlarge_text"
tools:text="3"
android:textColor="@color/text_1"
android:textColor="?attr/colorOnSurfaceVariant"
style="@style/Widget.StocksWidget.TextView.TitleMedium"
android:textAppearance="@style/TextAppearance.StocksWidget.TitleMedium"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shares"
android:textColor="@color/text_3"
android:textColor="?attr/colorOnSurface"
/>

</LinearLayout>
Expand All @@ -328,7 +328,7 @@
android:gravity="center"
android:textSize="@dimen/xlarge_text"
tools:text="$2,400.00"
android:textColor="@color/text_1"
android:textColor="?attr/colorOnSurfaceVariant"
android:textAppearance="@style/TextAppearance.StocksWidget.TickerBold"
/>
<TextView
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_alerts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
android:background="@color/error_red"
android:gravity="center"
android:padding="@dimen/activity_horizontal_margin"
android:textColor="@color/snackbar_text"
android:textColor="?attr/colorOnSurface"
android:text="@string/alerts_disabled"
android:visibility="gone"
tools:visibility="visible"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_notes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
android:padding="8dp"
android:scrollbarSize="4dp"
android:scrollbars="vertical"
android:textColor="@color/text_1"
android:textColor="?attr/colorOnSurfaceVariant"
android:textSize="@dimen/large_text"
android:cursorVisible="true"
/>
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/res/layout/activity_quote_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:textColor="@color/text_2"
android:textColor="?attr/colorOnSurfaceVariant"
android:gravity="center"
app:layout_scrollFlags="scroll"
tools:text="Apple Inc."
Expand Down Expand Up @@ -123,7 +123,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/quote_details_margin"
android:textAppearance="@style/TextAppearance.StocksWidget.TitleLarge"
android:textColor="@color/text_2"
android:textColor="?attr/colorOnSurfaceVariant"
android:gravity="center"
tools:text="$132.99"/>

Expand Down Expand Up @@ -304,15 +304,15 @@
android:layout_marginBottom="2dp"
android:gravity="center"
tools:text="3"
android:textColor="@color/text_1"
android:textColor="?attr/colorOnSurfaceVariant"
style="@style/Widget.StocksWidget.TextView.TitleMedium"
android:textAppearance="@style/TextAppearance.StocksWidget.TitleMedium"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shares"
android:textColor="@color/text_3"
android:textColor="?attr/colorOnSurface"
/>

</LinearLayout>
Expand All @@ -331,14 +331,14 @@
android:layout_marginBottom="2dp"
android:gravity="center"
tools:text="$2,400.00"
android:textColor="@color/text_1"
android:textColor="?attr/colorOnSurfaceVariant"
android:textAppearance="@style/TextAppearance.StocksWidget.TickerBold"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/equity_value"
android:textColor="@color/text_3"
android:textColor="?attr/colorOnSurface"
/>

</LinearLayout>
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"

>

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
Expand Down Expand Up @@ -52,7 +51,7 @@
android:gravity="center_vertical"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginStart="16dp"
android:textColor="@color/text_1"
android:textColor="?attr/colorOnSurfaceVariant"
android:textSize="@dimen/text_size"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="1.0"
Expand All @@ -66,8 +65,8 @@
app:tabIndicatorHeight="2dp"
app:tabMode="fixed"
app:tabTextAppearance="@style/TabTextAppearence"
app:tabSelectedTextColor="@color/tab_text_selected"
app:tabTextColor="@color/tab_text"
app:tabSelectedTextColor="?attr/colorOnSurface"
app:tabTextColor="?attr/colorOnSurfaceVariant"
android:layout_gravity="bottom"
android:gravity="bottom"
app:layout_collapseMode="none"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/fragment_portfolio.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:autoStart="false"
android:inAnimation="@android:anim/fade_in"
android:outAnimation="@android:anim/fade_out"
android:background="?attr/colorSurface"
>

<TextView
Expand All @@ -16,7 +17,7 @@
android:gravity="center"
android:text="@string/no_symbols"
style="@style/Widget.StocksWidget.TextView.FetchError"
android:textAppearance="@style/TextAppearance.StocksWidget.FetchError"
android:textAppearance="@style/TextAppearance.StocksWidget.FetchError"
/>

<androidx.recyclerview.widget.RecyclerView
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:background="?attr/colorSurface"
>

<com.google.android.material.appbar.AppBarLayout
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/child_fragment_container"
android:background="?attr/colorSurface"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_widget_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:layout_height="match_parent"
android:scrollbars="none"
android:id="@+id/scroll_view"
android:background="?attr/colorSurface"
>

<LinearLayout
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/item_news.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
android:layout_marginBottom="4dp"
android:maxLines="2"
android:ellipsize="end"
android:textColor="@color/text_4"
android:textColor="?attr/colorOnSurface"
tools:text="Stock market rises!"
style="@style/Widget.StocksWidget.TextView.BodyMedium"
android:textAppearance="@style/TextAppearance.StocksWidget.BodyMedium"
Expand All @@ -61,7 +61,7 @@
android:ellipsize="end"
android:maxLines="2"
tools:text="Lorem ipsum"
android:textColor="@color/text_3"
android:textColor="?attr/colorOnSurface"
style="@style/Widget.StocksWidget.TextView.BodyLightSmall"
android:textAppearance="@style/TextAppearance.StocksWidget.BodyLightSmall"
/>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/layout_holdings_popup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:textColor="@color/text_1"
android:textColor="?attr/colorOnSurfaceVariant"
android:textSize="@dimen/medium_text"
app:layout_constraintTop_toTopOf="parent"
tools:text="$100"
Expand Down
Loading

0 comments on commit 1008b62

Please sign in to comment.