-
Notifications
You must be signed in to change notification settings - Fork 1
UI widgets and stock exchange #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Kruna1Pate1
wants to merge
2
commits into
develop
Choose a base branch
from
feature/ui-widgets-and-stock-exchange
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.krunal.demo | ||
|
|
||
| import android.app.Application | ||
| import com.krunal.demo.uicomponents.helpers.PreferenceHelper | ||
|
|
||
| class DemoApplication: Application() { | ||
|
|
||
| override fun onCreate() { | ||
| super.onCreate() | ||
|
|
||
| instance = this | ||
|
|
||
| /** | ||
| * Initialize [PreferenceHelper] | ||
| */ | ||
| PreferenceHelper.initialize(applicationContext) | ||
| } | ||
|
|
||
| companion object { | ||
| lateinit var instance: Application | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
Demo/app/src/main/java/com/krunal/demo/UIComponentsActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.krunal.demo | ||
|
|
||
| import android.os.Bundle | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen | ||
| import com.krunal.demo.uicomponents.ButtonFragment | ||
| import com.krunal.demo.uicomponents.CoordinatorLayoutFragment | ||
| import com.krunal.demo.uicomponents.ThemeFragment | ||
| import com.krunal.demo.uicomponents.cardscreen.CardFragment | ||
| import com.krunal.demo.uicomponents.helpers.ThemeHelper | ||
|
|
||
| class UIComponentsActivity : AppCompatActivity() { | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| installSplashScreen() | ||
| setupTheme() | ||
| setContentView(R.layout.activity_uicomponents) | ||
| setupFragment() | ||
| } | ||
|
|
||
| private fun setupTheme() { | ||
| setTheme(ThemeHelper.getThemeResource(ThemeHelper.getThemeAccent())) | ||
| } | ||
|
|
||
| private fun setupFragment() { | ||
| supportFragmentManager.beginTransaction() | ||
| .replace(R.id.uiComponentsFragment, CoordinatorLayoutFragment()) | ||
| .commit() | ||
| } | ||
| } |
95 changes: 95 additions & 0 deletions
95
Demo/app/src/main/java/com/krunal/demo/stackexchange/StackExchangeActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package com.krunal.demo.stackexchange | ||
|
|
||
| import android.graphics.Color | ||
| import android.os.Bundle | ||
| import android.view.ViewTreeObserver.OnGlobalLayoutListener | ||
| import androidx.activity.viewModels | ||
| import androidx.appcompat.app.AppCompatActivity | ||
| import androidx.fragment.app.Fragment | ||
| import androidx.lifecycle.lifecycleScope | ||
| import com.google.android.material.badge.BadgeDrawable | ||
| import com.google.android.material.badge.BadgeUtils | ||
| import com.google.android.material.badge.ExperimentalBadgeUtils | ||
| import com.krunal.demo.R | ||
| import com.krunal.demo.databinding.ActivityStackExchangeBinding | ||
| import com.krunal.demo.stackexchange.exchange.ExchangeFragment | ||
| import com.krunal.demo.stackexchange.market.MarketFragment | ||
| import com.krunal.demo.stackexchange.wallet.WalletFragment | ||
| import com.krunal.demo.uicomponents.extentions.getThemeColor | ||
| import kotlinx.coroutines.flow.collectLatest | ||
| import kotlinx.coroutines.launch | ||
|
|
||
|
|
||
| class StackExchangeActivity : AppCompatActivity() { | ||
|
|
||
| private lateinit var binding: ActivityStackExchangeBinding | ||
| private val viewModel: StackExchangeActivityViewModel by viewModels() | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| binding = ActivityStackExchangeBinding.inflate(layoutInflater) | ||
| setContentView(binding.root) | ||
| binding.viewModel = viewModel | ||
| setupUI() | ||
| setupBottomNavigation() | ||
| } | ||
|
|
||
| private fun setupUI() { | ||
|
|
||
| setupAppBar() | ||
|
|
||
| binding.apply { | ||
| fabExchange.setOnClickListener { | ||
| bottomNavigation.selectedItemId = R.id.actionExchange | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @androidx.annotation.OptIn(ExperimentalBadgeUtils::class) | ||
| private fun setupAppBar() { | ||
| setSupportActionBar(binding.toolbar) | ||
| val badge = BadgeDrawable.create(this).apply { | ||
| badgeTextColor = getThemeColor(com.google.android.material.R.attr.colorOnSecondary) | ||
| backgroundColor = getThemeColor(com.google.android.material.R.attr.colorSecondary) | ||
| } | ||
|
|
||
| binding.notificationView.apply { | ||
| clipToOutline = false | ||
| bringToFront() | ||
| viewTreeObserver.addOnGlobalLayoutListener { | ||
| BadgeUtils.attachBadgeDrawable( | ||
| badge, | ||
| binding.notificationView | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| lifecycleScope.launch { | ||
| viewModel.notificationCount.collectLatest { | ||
| if (it == 0) { | ||
| badge.isVisible = false | ||
| } else { | ||
| badge.number = it | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun setupBottomNavigation() { | ||
| changeFragment(MarketFragment()) | ||
|
|
||
| binding.bottomNavigation.setOnItemSelectedListener { menuItem -> | ||
| val fragment = when (menuItem.itemId) { | ||
| R.id.actionMarket -> MarketFragment() | ||
| R.id.actionExchange -> ExchangeFragment() | ||
| else -> WalletFragment() | ||
| } | ||
| changeFragment(fragment) | ||
| return@setOnItemSelectedListener true | ||
| } | ||
| } | ||
|
|
||
| private fun changeFragment(fragment: Fragment) { | ||
| supportFragmentManager.beginTransaction().replace(R.id.fragmentContainer, fragment).commit() | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
Demo/app/src/main/java/com/krunal/demo/stackexchange/StackExchangeActivityViewModel.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.krunal.demo.stackexchange | ||
|
|
||
| import androidx.lifecycle.ViewModel | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import kotlinx.coroutines.flow.StateFlow | ||
|
|
||
| class StackExchangeActivityViewModel : ViewModel() { | ||
|
|
||
| private val _notificationCount: MutableStateFlow<Int> = MutableStateFlow(6) | ||
| val notificationCount: StateFlow<Int> = _notificationCount | ||
| } |
40 changes: 40 additions & 0 deletions
40
Demo/app/src/main/java/com/krunal/demo/stackexchange/adapters/PortfolioAdapter.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package com.krunal.demo.stackexchange.adapters | ||
|
|
||
| import android.annotation.SuppressLint | ||
| import android.view.LayoutInflater | ||
| import android.view.ViewGroup | ||
| import androidx.recyclerview.widget.RecyclerView | ||
| import com.krunal.demo.databinding.ItemPortfolioBinding | ||
| import com.krunal.demo.stackexchange.models.ShareDetails | ||
|
|
||
| class PortfolioAdapter : RecyclerView.Adapter<PortfolioAdapter.PortfolioViewHolder>() { | ||
|
|
||
| private val shareDetailsList: MutableList<ShareDetails> = mutableListOf() | ||
|
|
||
| class PortfolioViewHolder(private val binding: ItemPortfolioBinding) : | ||
| RecyclerView.ViewHolder(binding.root) { | ||
|
|
||
| fun bind(shareDetails: ShareDetails) { | ||
| binding.shareDetails = shareDetails | ||
| } | ||
| } | ||
|
|
||
| override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PortfolioViewHolder { | ||
| val layoutInflater = LayoutInflater.from(parent.context) | ||
| val binding = ItemPortfolioBinding.inflate(layoutInflater, parent, false) | ||
| return PortfolioViewHolder(binding) | ||
| } | ||
|
|
||
| override fun getItemCount(): Int = shareDetailsList.count() | ||
|
|
||
| override fun onBindViewHolder(holder: PortfolioViewHolder, position: Int) { | ||
| holder.bind(shareDetailsList[position]) | ||
| } | ||
|
|
||
| @SuppressLint("NotifyDataSetChanged") | ||
| fun submitList(list: List<ShareDetails>) { | ||
| shareDetailsList.clear() | ||
| shareDetailsList.addAll(list) | ||
| notifyDataSetChanged() | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
Demo/app/src/main/java/com/krunal/demo/stackexchange/adapters/ShareDetailsAdapter.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package com.krunal.demo.stackexchange.adapters | ||
|
|
||
| import android.annotation.SuppressLint | ||
| import android.view.LayoutInflater | ||
| import android.view.ViewGroup | ||
| import androidx.recyclerview.widget.RecyclerView | ||
| import com.krunal.demo.databinding.ItemShareDetailsBinding | ||
| import com.krunal.demo.stackexchange.models.ShareDetails | ||
|
|
||
| class ShareDetailsAdapter : RecyclerView.Adapter<ShareDetailsAdapter.ShareDetailsViewHolder>() { | ||
|
|
||
| private val shareDetailsList: MutableList<ShareDetails> = mutableListOf() | ||
|
|
||
| class ShareDetailsViewHolder(private val binding: ItemShareDetailsBinding) : | ||
| RecyclerView.ViewHolder(binding.root) { | ||
|
|
||
| fun bind(shareDetails: ShareDetails) { | ||
| binding.shareDetails = shareDetails | ||
| } | ||
| } | ||
|
|
||
| override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ShareDetailsViewHolder { | ||
| val layoutInflater = LayoutInflater.from(parent.context) | ||
| val binding = ItemShareDetailsBinding.inflate(layoutInflater, parent, false) | ||
| return ShareDetailsViewHolder(binding) | ||
| } | ||
|
|
||
| override fun getItemCount(): Int = shareDetailsList.count() | ||
|
|
||
| override fun onBindViewHolder(holder: ShareDetailsViewHolder, position: Int) { | ||
| holder.bind(shareDetailsList[position]) | ||
| } | ||
|
|
||
| @SuppressLint("NotifyDataSetChanged") | ||
| fun submitList(list: List<ShareDetails>) { | ||
| shareDetailsList.clear() | ||
| shareDetailsList.addAll(list) | ||
| notifyDataSetChanged() | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 AIReviewRadar The code changes look good. However, it is recommended to add a newline at the end of the file to follow standard conventions. |
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 AIReviewRadar
The changes in this patch look good.
However, it would be better to add a comment explaining the purpose of
binding.mainViewModel = viewModelfor future developers who may work on this code.Other than that, I don't see any issues with this patch.
Please add a comment explaining the purpose of
binding.mainViewModel = viewModel.