Skip to content

Commit

Permalink
UI tweaks to graph and quote detail
Browse files Browse the repository at this point in the history
  • Loading branch information
premnirmal committed Jun 16, 2022
1 parent b2f1046 commit b12a50e
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ fun Context.getStatusBarHeight(): Int {
return result
}

fun Context.getNavigationBarHeight(): Int {
val resourceId: Int = resources.getIdentifier(
"navigation_bar_height",
"dimen", "android"
)
return if (resourceId > 0) resources.getDimensionPixelSize(resourceId) else 0
}

fun Activity.dismissKeyboard() {
val view = currentFocus
if (view is TextView) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.github.premnirmal.ticker.news

import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.WindowInsets
import android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
import androidx.activity.viewModels
import com.github.mikephil.charting.animation.Easing
import com.github.mikephil.charting.charts.LineChart
Expand Down Expand Up @@ -44,19 +41,7 @@ class GraphActivity : BaseGraphActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Injector.appComponent.inject(this)
super.onCreate(savedInstanceState)
// Hide the status bar.
setContentView(R.layout.activity_graph)
if (Build.VERSION.SDK_INT >= 28) {
window.attributes.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.insetsController?.apply {
hide(WindowInsets.Type.statusBars())
hide(WindowInsets.Type.navigationBars())
}
} else {
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN
}
setupGraphView()
ticker = checkNotNull(intent.getStringExtra(TICKER))
viewModel.quote.observe(this) { quote ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.view.updateLayoutParams
import androidx.recyclerview.widget.RecyclerView
import com.github.premnirmal.ticker.getNavigationBarHeight
import com.github.premnirmal.ticker.network.data.NewsArticle
import com.github.premnirmal.ticker.news.NewsFeedAdapter.NewsClickListener
import com.github.premnirmal.tickerwidget.R
Expand Down Expand Up @@ -33,6 +35,13 @@ class NewsFeedAdapter(

override fun onBindViewHolder(holder: NewsFeedVH, position: Int) {
holder.update(newsList[position], listener)
holder.itemView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = if (position == itemCount - 1) {
holder.itemView.context.getNavigationBarHeight()
} else {
0
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import android.app.Activity
import android.content.Intent
import android.content.pm.ActivityInfo
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams
import androidx.lifecycle.asLiveData
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.StaggeredGridLayoutManager
Expand All @@ -24,6 +29,7 @@ import com.github.premnirmal.ticker.components.Injector
import com.github.premnirmal.ticker.formatChange
import com.github.premnirmal.ticker.formatChangePercent
import com.github.premnirmal.ticker.formatNumber
import com.github.premnirmal.ticker.getStatusBarHeight
import com.github.premnirmal.ticker.isNetworkOnline
import com.github.premnirmal.ticker.model.IHistoryProvider.Range
import com.github.premnirmal.ticker.network.data.NewsArticle
Expand All @@ -49,6 +55,7 @@ import kotlinx.android.synthetic.main.activity_quote_detail.change
import kotlinx.android.synthetic.main.activity_quote_detail.change_percent
import kotlinx.android.synthetic.main.activity_quote_detail.day_change
import kotlinx.android.synthetic.main.activity_quote_detail.equityValue
import kotlinx.android.synthetic.main.activity_quote_detail.fake_status_bar
import kotlinx.android.synthetic.main.activity_quote_detail.gradient
import kotlinx.android.synthetic.main.activity_quote_detail.graphView
import kotlinx.android.synthetic.main.activity_quote_detail.graph_container
Expand Down Expand Up @@ -113,6 +120,17 @@ class QuoteDetailActivity : BaseGraphActivity(), NewsFeedAdapter.NewsClickListen
graph_container.layoutParams.height = (resources.displayMetrics.widthPixels * 0.5625f).toInt()
graph_container.requestLayout()
}
ViewCompat.setOnApplyWindowInsetsListener(parentView) { _, insets ->
toolbar.updateLayoutParams<ViewGroup.MarginLayoutParams> {
this.topMargin = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top
}
insets
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
fake_status_bar.updateLayoutParams<ViewGroup.LayoutParams> {
height = getStatusBarHeight()
}
}
adapter = NewsFeedAdapter(this)
recycler_view.layoutManager = LinearLayoutManager(this)
recycler_view.addItemDecoration(
Expand Down
90 changes: 49 additions & 41 deletions app/src/main/res/layout-sw600dp-land/activity_quote_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/default_bg"
app:titleEnabled="false"
app:layout_scrollFlags="noScroll">
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/fake_status_bar"
android:background="@color/bg_toolbar"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="1"
/>
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
Expand Down Expand Up @@ -77,14 +86,53 @@
app:layout_constraintBottom_toTopOf="@id/price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/quote_details_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:textColor="@color/text_3"
android:textSize="@dimen/xlarge_text"
android:gravity="center"
app:layout_scrollFlags="scroll"
tools:text="Apple Inc."
/>

<ImageView
android:id="@+id/expand_graph"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/price"
android:contentDescription="@string/expand"
android:onClick="openGraph"
android:padding="8dp"
android:src="@drawable/ic_enlarge"
app:tint="@color/icon_tint"
/>

<FrameLayout
android:id="@+id/graph_container"
android:layout_width="match_parent"
android:layout_height="275dp"
android:padding="8dp"
app:layout_constraintTop_toBottomOf="@id/expand_graph"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
>
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/graphView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="20dp"
/>

</FrameLayout>

<TextView
app:layout_constraintTop_toBottomOf="@id/tickerName"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -106,7 +154,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/change_percent"
app:layout_constraintTop_toBottomOf="@id/price"
app:layout_constraintBottom_toTopOf="@id/expand_graph"
app:layout_constraintHorizontal_chainStyle="packed"
android:layout_margin="4dp"
android:layout_marginTop="@dimen/quote_details_margin"
Expand All @@ -128,45 +175,6 @@
tools:text="+2.02%"
/>

<ImageView
android:id="@+id/expand_graph"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/change_percent"
android:contentDescription="@string/expand"
android:onClick="openGraph"
android:padding="8dp"
android:src="@drawable/ic_enlarge"
app:tint="@color/icon_tint"
/>

<FrameLayout
android:id="@+id/graph_container"
android:layout_width="match_parent"
android:layout_height="200dp"
android:padding="8dp"
app:layout_constraintTop_toBottomOf="@id/expand_graph"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
>
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/graphView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="20dp"
/>

</FrameLayout>

<com.google.android.material.chip.ChipGroup
android:id="@+id/group_period"
android:layout_width="wrap_content"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/activity_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/quote_details_margin"
android:layout_marginBottom="?attr/actionBarSize"
app:singleLine="true"
app:singleSelection="true"
app:selectionRequired="true">
Expand Down
92 changes: 49 additions & 43 deletions app/src/main/res/layout/activity_quote_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/default_bg"
app:titleEnabled="false"
app:layout_scrollFlags="scroll">
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/fake_status_bar"
android:background="@color/bg_toolbar"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="1"
/>

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
Expand Down Expand Up @@ -57,14 +66,53 @@
app:layout_constraintBottom_toTopOf="@id/price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/quote_details_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:textColor="@color/text_3"
android:textSize="@dimen/xlarge_text"
android:gravity="center"
app:layout_scrollFlags="scroll"
tools:text="Apple Inc."
/>

<ImageView
android:id="@+id/expand_graph"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/price"
android:contentDescription="@string/expand"
android:onClick="openGraph"
android:padding="8dp"
android:src="@drawable/ic_enlarge"
app:tint="@color/icon_tint"
/>

<FrameLayout
android:id="@+id/graph_container"
android:layout_width="match_parent"
android:layout_height="200dp"
android:padding="8dp"
app:layout_constraintTop_toBottomOf="@id/expand_graph"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
>
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/graphView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="20dp"
/>

</FrameLayout>

<TextView
app:layout_constraintTop_toBottomOf="@id/tickerName"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -86,9 +134,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/change_percent"
app:layout_constraintTop_toBottomOf="@id/price"
app:layout_constraintBottom_toTopOf="@id/expand_graph"
app:layout_constraintHorizontal_chainStyle="packed"
android:layout_margin="4dp"
android:layout_marginTop="@dimen/quote_details_margin"
android:gravity="center"
android:padding="@dimen/quote_details_padding"
Expand All @@ -108,45 +154,6 @@
tools:text="+2.02%"
/>

<ImageView
android:id="@+id/expand_graph"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/change_percent"
android:contentDescription="@string/expand"
android:onClick="openGraph"
android:padding="8dp"
android:src="@drawable/ic_enlarge"
app:tint="@color/icon_tint"
/>

<FrameLayout
android:id="@+id/graph_container"
android:layout_width="match_parent"
android:layout_height="200dp"
android:padding="8dp"
app:layout_constraintTop_toBottomOf="@id/expand_graph"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
>
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/graphView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="20dp"
/>

</FrameLayout>

<com.google.android.material.chip.ChipGroup
android:id="@+id/group_period"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -211,7 +218,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/default_bg"
android:layout_marginTop="?attr/actionBarSize"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="1"
android:alpha="0.0" />
Expand Down
Loading

0 comments on commit b12a50e

Please sign in to comment.