From 6b08ece02c1d64a230048ca76a4264f30d9b9de8 Mon Sep 17 00:00:00 2001 From: EdipoSouza Date: Tue, 27 Dec 2016 01:08:06 -0300 Subject: [PATCH 01/17] Change app launcher name to TESL Tracker. Add notification icon. Fix recyclerView not add crash --- app/src/main/AndroidManifest.xml | 9 ++++++++- .../ui/cards/CardsFragment.kt | 4 ++-- .../ui/cards/tabs/CardsAllFragment.kt | 2 +- .../ui/cards/tabs/CardsCollectionFragment.kt | 4 ++-- app/src/main/res/drawable-nodpi/ic_legend.png | Bin 0 -> 18956 bytes app/src/main/res/layout/activity_dash.xml | 2 +- app/src/main/res/layout/activity_new_deck.xml | 2 +- app/src/main/res/values/strings.xml | 3 ++- 8 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 app/src/main/res/drawable-nodpi/ic_legend.png diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1112fcd..699fa08 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -57,10 +57,17 @@ android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> + + + + - \ No newline at end of file diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/CardsFragment.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/CardsFragment.kt index 0ec63ed..0bc991c 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/CardsFragment.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/CardsFragment.kt @@ -41,7 +41,7 @@ class CardsFragment : BaseFragment(), SearchView.OnQueryTextListener { val title = when (position) { 1 -> R.string.tab_cards_collection 2 -> R.string.tab_cards_favorites - else -> R.string.app_name + else -> R.string.app_name_full } activity.toolbar_title?.setText(title) BottomSheetBehavior.from(activity.collection_statistics).state = BottomSheetBehavior.STATE_COLLAPSED @@ -80,7 +80,7 @@ class CardsFragment : BaseFragment(), SearchView.OnQueryTextListener { override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) - activity.toolbar_title.setText(R.string.app_name) + activity.toolbar_title.setText(R.string.app_name_full) activity.dash_tab_layout.setupWithViewPager(cards_view_pager) } diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsAllFragment.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsAllFragment.kt index 108b044..2be7c0a 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsAllFragment.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsAllFragment.kt @@ -183,7 +183,7 @@ open class CardsAllFragment : BaseFragment() { open fun showCards() { cardsAdapter.showCards(filteredCards()) - cards_recycler_view.scrollToPosition(0) + cards_recycler_view?.scrollToPosition(0) } fun updateCardsList() { diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsCollectionFragment.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsCollectionFragment.kt index 2a1df56..3f82d44 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsCollectionFragment.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsCollectionFragment.kt @@ -105,9 +105,9 @@ class CardsCollectionFragment : CardsAllFragment() { privateInteractor.getUserCollection(setFilter, currentAttr) { val userCards = it val slots = cards.map { CardSlot(it, userCards[it.shortName] ?: 0L) } - cards_recycler_view.itemAnimator = ScaleInAnimator() + cards_recycler_view?.itemAnimator = ScaleInAnimator() cardsCollectionAdapter.showCards(slots as ArrayList) - cards_recycler_view.scrollToPosition(0) + cards_recycler_view?.scrollToPosition(0) } } diff --git a/app/src/main/res/drawable-nodpi/ic_legend.png b/app/src/main/res/drawable-nodpi/ic_legend.png new file mode 100644 index 0000000000000000000000000000000000000000..83d3d829cf6b187be5bb502919a654ff281c09f8 GI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/src/main/res/layout/activity_new_deck.xml b/app/src/main/res/layout/activity_new_deck.xml index 9c61c3b..c86cc74 100644 --- a/app/src/main/res/layout/activity_new_deck.xml +++ b/app/src/main/res/layout/activity_new_deck.xml @@ -54,7 +54,7 @@ android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="@android:color/white" android:textStyle="bold" - tools:text="@string/app_name" /> + tools:text="@string/app_name_full" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 17e827d..66ed6df 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,5 +1,6 @@ - TES Legends Tracker + TESL Tracker + TES Legends Tracker ca-app-pub-7881623561544201/7976661172 360x80 ca-app-pub-7881623561544201/1511325179 From 184db6c69a77aabba36ed57684183d64dbd986e9 Mon Sep 17 00:00:00 2001 From: EdipoSouza Date: Tue, 27 Dec 2016 15:31:49 -0300 Subject: [PATCH 02/17] Collection statistics collapsed bottom sheet showed dynamically --- .../teslesgendstracker/ui/DashActivity.kt | 40 ++++++++++++++--- .../teslesgendstracker/ui/base/Commands.kt | 2 + .../ui/cards/CardsFragment.kt | 25 +++++++---- .../ui/cards/tabs/CardsAllFragment.kt | 7 ++- .../ui/cards/tabs/CardsCollectionFragment.kt | 43 ++++++------------- .../ui/widget/CollectionStatistics.kt | 5 +++ app/src/main/res/drawable/ic_statistics.xml | 4 -- .../main/res/drawable/ic_statistics_svg.xml | 10 ----- app/src/main/res/layout/activity_card.xml | 2 +- app/src/main/res/layout/activity_dash.xml | 10 +++++ app/src/main/res/layout/activity_deck.xml | 2 +- app/src/main/res/layout/fragment_cards.xml | 8 ---- .../layout/widget_collection_statistics.xml | 4 +- .../main/res/menu/menu_cards_collection.xml | 18 -------- app/src/main/res/values/dimens.xml | 6 ++- 15 files changed, 90 insertions(+), 96 deletions(-) delete mode 100644 app/src/main/res/drawable/ic_statistics.xml delete mode 100644 app/src/main/res/drawable/ic_statistics_svg.xml delete mode 100644 app/src/main/res/menu/menu_cards_collection.xml diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DashActivity.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DashActivity.kt index ca84f83..bd97b42 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DashActivity.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DashActivity.kt @@ -18,6 +18,7 @@ import com.ediposouza.teslesgendstracker.interactor.PrivateInteractor import com.ediposouza.teslesgendstracker.interactor.PublicInteractor import com.ediposouza.teslesgendstracker.ui.base.BaseActivity import com.ediposouza.teslesgendstracker.ui.base.CmdShowTabs +import com.ediposouza.teslesgendstracker.ui.base.CmdUpdateRarityMagikaFiltersPosition import com.ediposouza.teslesgendstracker.ui.base.CmdUpdateRarityMagikaFiltersVisibility import com.ediposouza.teslesgendstracker.ui.cards.CardsFragment import com.ediposouza.teslesgendstracker.ui.cards.CmdFilterMagika @@ -26,7 +27,6 @@ import com.ediposouza.teslesgendstracker.ui.decks.DecksFragment import com.ediposouza.teslesgendstracker.ui.utils.CircleTransform import com.google.firebase.auth.FirebaseAuth import kotlinx.android.synthetic.main.activity_dash.* -import kotlinx.android.synthetic.main.fragment_cards.* import kotlinx.android.synthetic.main.navigation_drawer_header.view.* import org.greenrobot.eventbus.Subscribe import org.jetbrains.anko.doAsync @@ -38,6 +38,9 @@ class DashActivity : BaseActivity(), val publicInteractor = PublicInteractor() val privateInteractor = PrivateInteractor() + var filterGreatMargin = false + val statisticsSheetBehavior by lazy { BottomSheetBehavior.from(collection_statistics) } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_dash) @@ -64,7 +67,11 @@ class DashActivity : BaseActivity(), updateCollectionStatistics() } } - BottomSheetBehavior.from(collection_statistics).state = BottomSheetBehavior.STATE_COLLAPSED + with(statisticsSheetBehavior) { + if (state == BottomSheetBehavior.STATE_EXPANDED) { + state = BottomSheetBehavior.STATE_COLLAPSED + } + } } } @@ -79,9 +86,8 @@ class DashActivity : BaseActivity(), } override fun onBackPressed() { - val statisticsBottomSheet = BottomSheetBehavior.from(collection_statistics) - if (statisticsBottomSheet.state == BottomSheetBehavior.STATE_EXPANDED) { - statisticsBottomSheet.state = BottomSheetBehavior.STATE_COLLAPSED + if (statisticsSheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED) { + statisticsSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED return } if (dash_drawer_layout.isDrawerOpen(Gravity.START)) { @@ -110,6 +116,7 @@ class DashActivity : BaseActivity(), } fun showFragment(frag: Fragment): Boolean { + statisticsSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN supportFragmentManager.beginTransaction() .replace(R.id.dash_content, frag) .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out) @@ -156,10 +163,29 @@ class DashActivity : BaseActivity(), } @Subscribe - fun onCmdUpdateRarityMagikaFilters(update: CmdUpdateRarityMagikaFiltersVisibility) { + fun onCmdUpdateRarityMagikaFiltersPosition(update: CmdUpdateRarityMagikaFiltersPosition) { + filterGreatMargin = update.high + val filterMagikaLP = dash_filter_magika.layoutParams as CoordinatorLayout.LayoutParams + val filterRarityLP = dash_filter_rarity.layoutParams as CoordinatorLayout.LayoutParams + val endMargin = if (filterGreatMargin) R.dimen.filter_great_margin_bottom else R.dimen.large_margin + with(ValueAnimator.ofInt(filterMagikaLP.bottomMargin, resources.getDimensionPixelSize(endMargin))) { + duration = DateUtils.SECOND_IN_MILLIS + addUpdateListener { + filterRarityLP.bottomMargin = it.animatedValue as Int + filterMagikaLP.bottomMargin = it.animatedValue as Int + dash_filter_magika.layoutParams = filterMagikaLP + dash_filter_rarity.layoutParams = filterRarityLP + } + start() + } + } + + @Subscribe + fun onCmdUpdateRarityMagikaFiltersVisibility(update: CmdUpdateRarityMagikaFiltersVisibility) { + val margin = if (filterGreatMargin) R.dimen.filter_great_margin_bottom else R.dimen.large_margin val filterMagikaLP = dash_filter_magika.layoutParams as CoordinatorLayout.LayoutParams val filterRarityLP = dash_filter_rarity.layoutParams as CoordinatorLayout.LayoutParams - val showBottomMargin = resources.getDimensionPixelSize(R.dimen.large_margin) + val showBottomMargin = resources.getDimensionPixelSize(margin) val hideBottomMargin = -resources.getDimensionPixelSize(R.dimen.filter_hide_height) if (update.show && filterMagikaLP.bottomMargin == showBottomMargin || !update.show && filterMagikaLP.bottomMargin == hideBottomMargin) { diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/base/Commands.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/base/Commands.kt index 16ec9ba..d030f7f 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/base/Commands.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/base/Commands.kt @@ -23,6 +23,8 @@ data class CmdShowCardsByAttr(val attr: Attribute) data class CmdShowDecksByClasses(val classes: List) +data class CmdUpdateRarityMagikaFiltersPosition(val high: Boolean) + data class CmdUpdateRarityMagikaFiltersVisibility(val show: Boolean) class CmdShowSnackbarMsg private constructor(type: Long) { diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/CardsFragment.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/CardsFragment.kt index 0bc991c..5c48659 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/CardsFragment.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/CardsFragment.kt @@ -17,10 +17,8 @@ import com.ediposouza.teslesgendstracker.R import com.ediposouza.teslesgendstracker.data.Attribute import com.ediposouza.teslesgendstracker.inflate import com.ediposouza.teslesgendstracker.manager.MetricsManager -import com.ediposouza.teslesgendstracker.ui.base.BaseFragment -import com.ediposouza.teslesgendstracker.ui.base.CmdShowCardsByAttr -import com.ediposouza.teslesgendstracker.ui.base.CmdShowTabs -import com.ediposouza.teslesgendstracker.ui.base.CmdUpdateRarityMagikaFiltersVisibility +import com.ediposouza.teslesgendstracker.toogleExpanded +import com.ediposouza.teslesgendstracker.ui.base.* import com.ediposouza.teslesgendstracker.ui.cards.tabs.CardsAllFragment import com.ediposouza.teslesgendstracker.ui.cards.tabs.CardsCollectionFragment import com.ediposouza.teslesgendstracker.ui.cards.tabs.CardsFavoritesFragment @@ -36,6 +34,8 @@ class CardsFragment : BaseFragment(), SearchView.OnQueryTextListener { val handler = Handler() val trackSearch = Runnable { MetricsManager.trackSearch(query ?: "") } + val statisticsSheetBehavior by lazy { BottomSheetBehavior.from(activity.collection_statistics) } + val pageChange = object : ViewPager.SimpleOnPageChangeListener() { override fun onPageSelected(position: Int) { val title = when (position) { @@ -44,16 +44,19 @@ class CardsFragment : BaseFragment(), SearchView.OnQueryTextListener { else -> R.string.app_name_full } activity.toolbar_title?.setText(title) - BottomSheetBehavior.from(activity.collection_statistics).state = BottomSheetBehavior.STATE_COLLAPSED + (cards_view_pager.adapter as CardsPageAdapter).getItem(position).updateCardsList() + if (position == 1) { + statisticsSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED + activity.collection_statistics.updateStatistics() + } else { + statisticsSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN + } + eventBus.post(CmdUpdateRarityMagikaFiltersPosition(position == 1)) MetricsManager.trackScreen(when (position) { 0 -> MetricScreen.SCREEN_CARDS_ALL() 1 -> MetricScreen.SCREEN_CARDS_COLLECTION() else -> MetricScreen.SCREEN_CARDS_FAVORED() }) - (cards_view_pager.adapter as CardsPageAdapter).getItem(position).updateCardsList() - if (position == 1) { - collection_statistics.updateStatistics() - } } } @@ -66,6 +69,10 @@ class CardsFragment : BaseFragment(), SearchView.OnQueryTextListener { super.onViewCreated(view, savedInstanceState) setHasOptionsMenu(true) activity.dash_navigation_view.setCheckedItem(R.id.menu_cards) + activity.collection_statistics.setOnClickListener { + statisticsSheetBehavior.toogleExpanded() + } + statisticsSheetBehavior.state = BottomSheetBehavior.STATE_HIDDEN cards_view_pager.adapter = CardsPageAdapter(context, childFragmentManager) cards_view_pager.addOnPageChangeListener(pageChange) attr_filter.filterClick = { diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsAllFragment.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsAllFragment.kt index 2be7c0a..12a1668 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsAllFragment.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsAllFragment.kt @@ -53,6 +53,8 @@ open class CardsAllFragment : BaseFragment() { val privateInteractor: PrivateInteractor by lazy { PrivateInteractor() } val transitionName: String by lazy { getString(R.string.card_transition_name) } + open protected val isCardsCollection: Boolean = false + open val cardsAdapter by lazy { val gridLayoutManager = cards_recycler_view.layoutManager as GridLayoutManager CardsAllAdapter(ADS_EACH_ITEMS, gridLayoutManager, R.layout.itemlist_card_ads, R.dimen.card_height, @@ -68,16 +70,13 @@ open class CardsAllFragment : BaseFragment() { resources.getDimensionPixelSize(R.dimen.card_margin), true) } - init { - setHasOptionsMenu(true) - } - override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { return container?.inflate(R.layout.fragment_cards_list) } override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + setHasOptionsMenu(true) configRecycleView() } diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsCollectionFragment.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsCollectionFragment.kt index 3f82d44..f238556 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsCollectionFragment.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsCollectionFragment.kt @@ -7,16 +7,20 @@ import android.support.v4.content.ContextCompat import android.support.v7.util.DiffUtil import android.support.v7.widget.GridLayoutManager import android.support.v7.widget.RecyclerView -import android.view.* -import com.ediposouza.teslesgendstracker.* +import android.view.MenuItem +import android.view.View +import android.view.ViewGroup +import com.ediposouza.teslesgendstracker.MetricAction +import com.ediposouza.teslesgendstracker.MetricScreen +import com.ediposouza.teslesgendstracker.R import com.ediposouza.teslesgendstracker.data.Card import com.ediposouza.teslesgendstracker.data.CardSlot +import com.ediposouza.teslesgendstracker.inflate import com.ediposouza.teslesgendstracker.manager.MetricsManager import com.ediposouza.teslesgendstracker.ui.base.BaseAdsAdapter import com.ediposouza.teslesgendstracker.ui.utils.SimpleDiffCallback import jp.wasabeef.recyclerview.animators.ScaleInAnimator import kotlinx.android.synthetic.main.activity_dash.* -import kotlinx.android.synthetic.main.fragment_cards.* import kotlinx.android.synthetic.main.fragment_cards_list.* import kotlinx.android.synthetic.main.itemlist_card_collection.view.* import java.util.* @@ -26,8 +30,10 @@ import java.util.* */ class CardsCollectionFragment : CardsAllFragment() { - private val view_statistics by lazy { activity.collection_statistics } - private val statisticsSheetBehavior by lazy { + override val isCardsCollection: Boolean = true + + val view_statistics by lazy { activity.collection_statistics } + val statisticsSheetBehavior by lazy { BottomSheetBehavior.from(view_statistics) } @@ -47,10 +53,9 @@ class CardsCollectionFragment : CardsAllFragment() { override fun onStateChanged(bottomSheet: View, newState: Int) { val expanded = newState == BottomSheetBehavior.STATE_EXPANDED || newState == BottomSheetBehavior.STATE_SETTLING - activity.dash_filter_rarity.visibility = if (expanded) View.INVISIBLE else View.VISIBLE - activity.dash_filter_magika.visibility = if (expanded) View.INVISIBLE else View.VISIBLE if (expanded) { - activity.collection_statistics.scrollToTop() + view_statistics?.scrollToTop() + view_statistics?.updateStatistics() } when (newState) { BottomSheetBehavior.STATE_EXPANDED -> { @@ -66,31 +71,11 @@ class CardsCollectionFragment : CardsAllFragment() { override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - setHasOptionsMenu(true) - view_statistics.setOnClickListener { - statisticsSheetBehavior.toogleExpanded() - } statisticsSheetBehavior.setBottomSheetCallback(sheetBehaviorCallback) } - override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) { - menu?.clear() - inflater?.inflate(R.menu.menu_sets, menu) - inflater?.inflate(R.menu.menu_cards_collection, menu) - super.onCreateOptionsMenu(menu, inflater) - } - override fun onOptionsItemSelected(item: MenuItem?): Boolean { - when (item?.itemId) { - R.id.menu_statistics -> { - view_statistics?.updateStatistics() - statisticsSheetBehavior.toogleExpanded() - return true - } - else -> { - BottomSheetBehavior.from(activity.collection_statistics).state = BottomSheetBehavior.STATE_COLLAPSED - } - } + BottomSheetBehavior.from(view_statistics).state = BottomSheetBehavior.STATE_COLLAPSED return super.onOptionsItemSelected(item) } diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/CollectionStatistics.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/CollectionStatistics.kt index 1d7d651..57a2a53 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/CollectionStatistics.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/CollectionStatistics.kt @@ -3,6 +3,7 @@ package com.ediposouza.teslesgendstracker.ui.widget import android.content.Context import android.os.Build import android.util.AttributeSet +import android.view.MotionEvent import android.widget.FrameLayout import com.ediposouza.teslesgendstracker.R import com.ediposouza.teslesgendstracker.data.Attribute @@ -37,6 +38,10 @@ class CollectionStatistics(ctx: Context?, attrs: AttributeSet?, defStyleAttr: In constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) { } + override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean { + return true + } + fun scrollToTop() { collection_statistics_container.smoothScrollTo(0, 0) } diff --git a/app/src/main/res/drawable/ic_statistics.xml b/app/src/main/res/drawable/ic_statistics.xml deleted file mode 100644 index 77fab7d..0000000 --- a/app/src/main/res/drawable/ic_statistics.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/app/src/main/res/drawable/ic_statistics_svg.xml b/app/src/main/res/drawable/ic_statistics_svg.xml deleted file mode 100644 index 2936299..0000000 --- a/app/src/main/res/drawable/ic_statistics_svg.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - diff --git a/app/src/main/res/layout/activity_card.xml b/app/src/main/res/layout/activity_card.xml index 25828b3..d85510b 100644 --- a/app/src/main/res/layout/activity_card.xml +++ b/app/src/main/res/layout/activity_card.xml @@ -49,7 +49,7 @@ android:elevation="@dimen/cardview_default_elevation" android:foreground="?attr/selectableItemBackground" app:behavior_hideable="true" - app:behavior_peekHeight="@dimen/card_bottom_sheet_peek_heigth" + app:behavior_peekHeight="@dimen/card_bottom_sheet_peek_height" app:layout_behavior="@string/bottom_sheet_behavior"> + + diff --git a/app/src/main/res/layout/activity_deck.xml b/app/src/main/res/layout/activity_deck.xml index 0374ba6..319f696 100644 --- a/app/src/main/res/layout/activity_deck.xml +++ b/app/src/main/res/layout/activity_deck.xml @@ -133,7 +133,7 @@ android:elevation="@dimen/cardview_default_elevation" android:foreground="?attr/selectableItemBackground" app:behavior_hideable="true" - app:behavior_peekHeight="@dimen/card_bottom_sheet_peek_heigth" + app:behavior_peekHeight="@dimen/card_bottom_sheet_peek_height" app:layout_behavior="@string/bottom_sheet_behavior"> - - \ No newline at end of file diff --git a/app/src/main/res/layout/widget_collection_statistics.xml b/app/src/main/res/layout/widget_collection_statistics.xml index 209b1e5..df188cd 100644 --- a/app/src/main/res/layout/widget_collection_statistics.xml +++ b/app/src/main/res/layout/widget_collection_statistics.xml @@ -1,14 +1,12 @@ - diff --git a/app/src/main/res/menu/menu_cards_collection.xml b/app/src/main/res/menu/menu_cards_collection.xml deleted file mode 100644 index adb321b..0000000 --- a/app/src/main/res/menu/menu_cards_collection.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 6557e59..7b763ea 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -31,18 +31,20 @@ @dimen/default_margin 56dp + 42dp 260dp 48dp @dimen/small_margin 48dp @dimen/default_margin 4dp - @dimen/default_margin + 32dp + @dimen/medium_margin 24dp @dimen/status_bar_height - 88dp + 88dp @dimen/navigation_bar_height From 3ac1dcd77a95df25f240e854b3a682124dc00765 Mon Sep 17 00:00:00 2001 From: EdipoSouza Date: Tue, 27 Dec 2016 16:26:09 -0300 Subject: [PATCH 03/17] Card list sorted with cost and name. Deck card list sorted. ScrollTo when new card is added. Slide Animation when add and remove --- .../teslesgendstracker/data/Card.kt | 7 +++- .../teslesgendstracker/data/General.kt | 6 +++- .../interactor/PublicInteractor.kt | 2 +- .../ui/cards/CardsFragment.kt | 2 +- .../ui/decks/widget/DeckList.kt | 35 ++++++++++++------- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/Card.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/Card.kt index 465ab6a..f716dd8 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/Card.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/Card.kt @@ -262,7 +262,7 @@ data class Card( val arenaTier: CardArenaTier, val evolves: Boolean -) : Parcelable { +) : Comparable, Parcelable { private val CARD_BACK = "card_back.png" private val CARD_PATH = "Cards" @@ -314,4 +314,9 @@ data class Card( dest?.writeInt(arenaTier.ordinal) dest?.writeInt((if (evolves) 1 else 0)) } + + override fun compareTo(other: Card): Int { + val compareCost = cost.compareTo(other.cost) + return if (compareCost != 0) compareCost else name.compareTo(other.name) + } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/General.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/General.kt index 25bfa21..7886f55 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/General.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/General.kt @@ -8,7 +8,11 @@ data class CardSlot( val card: Card, val qtd: Long -) +) : Comparable { + + override fun compareTo(other: CardSlot): Int = card.compareTo(other.card) + +} data class Patch( diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/PublicInteractor.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/PublicInteractor.kt index 0b2bdba..1c70ed4 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/PublicInteractor.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/PublicInteractor.kt @@ -17,7 +17,7 @@ class PublicInteractor() : BaseInteractor() { private val KEY_DECK_VIEWS = "views" fun getCards(set: CardSet?, attr: Attribute, onSuccess: (List) -> Unit) { - val onFinalSuccess: (List) -> Unit = { onSuccess(it.sortedBy(Card::cost)) } + val onFinalSuccess: (List) -> Unit = { onSuccess(it.sorted()) } getListFromSets(set, attr, onFinalSuccess) { set, attr, onEachSuccess -> val node_attr = attr.name.toLowerCase() database.child(NODE_CARDS).child(set.db).child(node_attr).orderByChild(KEY_CARD_COST) diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/CardsFragment.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/CardsFragment.kt index 5c48659..7e85119 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/CardsFragment.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/CardsFragment.kt @@ -99,8 +99,8 @@ class CardsFragment : BaseFragment(), SearchView.OnQueryTextListener { override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) { menu?.clear() - inflater?.inflate(R.menu.menu_sets, menu) inflater?.inflate(R.menu.menu_search, menu) + inflater?.inflate(R.menu.menu_sets, menu) with(MenuItemCompat.getActionView(menu?.findItem(R.id.menu_search)) as SearchView) { queryHint = getString(R.string.search_hint) setOnQueryTextListener(this@CardsFragment) diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/widget/DeckList.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/widget/DeckList.kt index 62b0a4c..c656a52 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/widget/DeckList.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/widget/DeckList.kt @@ -19,11 +19,13 @@ import com.ediposouza.teslesgendstracker.interactor.PrivateInteractor import com.ediposouza.teslesgendstracker.interactor.PublicInteractor import com.ediposouza.teslesgendstracker.ui.CardActivity import com.ediposouza.teslesgendstracker.ui.decks.CmdRemAttr +import jp.wasabeef.recyclerview.animators.SlideInLeftAnimator import kotlinx.android.synthetic.main.itemlist_decklist_slot.view.* import kotlinx.android.synthetic.main.widget_decklist.view.* import org.greenrobot.eventbus.EventBus import org.jetbrains.anko.doAsync import org.jetbrains.anko.runOnUiThread +import java.util.* /** * Created by EdipoSouza on 11/2/16. @@ -44,13 +46,14 @@ class DeckList(ctx: Context?, attrs: AttributeSet?, defStyleAttr: Int) : } val deckListAdapter by lazy { - DeckListAdapter(itemClick = { view, card -> - if (editMode) { - remCard(card) - } else { - showExpandedCard(card, view) - } - }) { + DeckListAdapter({ index -> decklist_recycle_view.scrollToPosition(index) }, + itemClick = { view, card -> + if (editMode) { + remCard(card) + } else { + showExpandedCard(card, view) + } + }) { view, card -> showExpandedCard(card, view) true @@ -60,6 +63,7 @@ class DeckList(ctx: Context?, attrs: AttributeSet?, defStyleAttr: Int) : init { inflate(context, R.layout.widget_decklist, this) decklist_recycle_view.adapter = deckListAdapter + decklist_recycle_view.itemAnimator = SlideInLeftAnimator() decklist_recycle_view.layoutManager = LinearLayoutManager(context) decklist_recycle_view.setHasFixedSize(true) if (isInEditMode) { @@ -114,7 +118,8 @@ class DeckList(ctx: Context?, attrs: AttributeSet?, defStyleAttr: Int) : } -class DeckListAdapter(val itemClick: (View, Card) -> Unit, val itemLongClick: (View, Card) -> Boolean) : RecyclerView.Adapter() { +class DeckListAdapter(val onAdd: (Int) -> Unit, val itemClick: (View, Card) -> Unit, + val itemLongClick: (View, Card) -> Boolean) : RecyclerView.Adapter() { private val items = arrayListOf() private var missingCards: List = listOf() @@ -133,7 +138,7 @@ class DeckListAdapter(val itemClick: (View, Card) -> Unit, val itemLongClick: (V fun showDeck(cards: List) { items.clear() - items.addAll(cards) + items.addAll(cards.sorted()) notifyDataSetChanged() } @@ -145,12 +150,17 @@ class DeckListAdapter(val itemClick: (View, Card) -> Unit, val itemLongClick: (V fun addCard(card: Card) { val cardSlot = items.find { it.card == card } if (cardSlot == null) { - items.add(CardSlot(card, 1)) - notifyDataSetChanged() + val newCardSlot = CardSlot(card, 1) + items.add(newCardSlot) + Collections.sort(items) + val newCardIndex = items.indexOf(newCardSlot) + onAdd(newCardIndex) + notifyItemInserted(newCardIndex) } else { val newQtd = if (cardSlot.qtd < 3) cardSlot.qtd.inc() else 3 val cardIndex = items.indexOf(cardSlot) items[cardIndex] = CardSlot(card, if (card.unique) 1 else newQtd) + onAdd(cardIndex) notifyItemChanged(cardIndex) } } @@ -160,8 +170,9 @@ class DeckListAdapter(val itemClick: (View, Card) -> Unit, val itemLongClick: (V if (cardSlot != null) { val newQtd = cardSlot.qtd.dec() if (newQtd <= 0) { + val cardRemovedIndex = items.indexOf(cardSlot) items.remove(cardSlot) - notifyDataSetChanged() + notifyItemRemoved(cardRemovedIndex) notifyCardRemoved(card) } else { val cardIndex = items.indexOf(cardSlot) From d1ee28cb40b5077f85f8495aafae7f7847546457 Mon Sep 17 00:00:00 2001 From: EdipoSouza Date: Thu, 29 Dec 2016 00:32:20 -0200 Subject: [PATCH 04/17] Comment deck support (Add and Remove) --- app/src/main/AndroidManifest.xml | 3 +- .../interactor/PrivateInteractor.kt | 13 +- .../teslesgendstracker/ui/DeckActivity.kt | 177 ++++++++++++++++-- .../ui/base/BaseActivity.kt | 35 ++-- .../ui/widget/InsetFrameLayout.kt | 32 ++++ app/src/main/res/drawable/ic_delete_red.xml | 4 + .../main/res/drawable/ic_delete_red_svg.xml | 10 + app/src/main/res/drawable/ic_send.xml | 4 + app/src/main/res/drawable/ic_send_svg.xml | 10 + app/src/main/res/layout/activity_deck.xml | 56 +++++- .../main/res/layout/itemlist_deck_comment.xml | 49 +++-- app/src/main/res/values/dimens.xml | 3 +- app/src/main/res/values/strings.xml | 6 + build.gradle | 4 +- 14 files changed, 348 insertions(+), 58 deletions(-) create mode 100644 app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/InsetFrameLayout.kt create mode 100644 app/src/main/res/drawable/ic_delete_red.xml create mode 100644 app/src/main/res/drawable/ic_delete_red_svg.xml create mode 100644 app/src/main/res/drawable/ic_send.xml create mode 100644 app/src/main/res/drawable/ic_send_svg.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 699fa08..5adb704 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -40,7 +40,8 @@ android:screenOrientation="portrait" /> + android:screenOrientation="portrait" + android:windowSoftInputMode="adjustPan" /> Unit)? = null, onSuccess: () -> Unit) { + fun addDeckComment(deck: Deck, msg: String, onError: ((e: Exception?) -> Unit)? = null, + onSuccess: (comment: DeckComment) -> Unit) { dbUser()?.apply { with(if (deck.private) child(NODE_DECKS).child(NODE_DECKS_PRIVATE) else dbDecks.child(NODE_DECKS_PUBLIC)) { val comment = DeckParser.toNewCommentMap(getUserID(), msg) with(child(deck.id).child(KEY_DECK_COMMENTS)) { - child(push().key).setValue(comment).addOnCompleteListener({ + val commentKey = push().key + child(commentKey).setValue(comment).addOnCompleteListener({ Timber.d(it.toString()) - if (it.isSuccessful) onSuccess.invoke() else onError?.invoke(it.exception) + if (it.isSuccessful) { + onSuccess.invoke(DeckComment(commentKey, getUserID(), msg, LocalDateTime.now())) + } else + onError?.invoke(it.exception) }) } } } } - fun remDeckComment(deck: Deck, commentId: String, msg: String, onError: ((e: Exception?) -> Unit)? = null, onSuccess: () -> Unit) { + fun remDeckComment(deck: Deck, commentId: String, onError: ((e: Exception?) -> Unit)? = null, onSuccess: () -> Unit) { dbUser()?.apply { with(if (deck.private) child(NODE_DECKS).child(NODE_DECKS_PRIVATE) else dbDecks.child(NODE_DECKS_PUBLIC)) { child(deck.id).child(KEY_DECK_COMMENTS).child(commentId).removeValue().addOnCompleteListener({ diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DeckActivity.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DeckActivity.kt index 2b19856..7f356c8 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DeckActivity.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DeckActivity.kt @@ -3,28 +3,34 @@ package com.ediposouza.teslesgendstracker.ui import android.app.Activity import android.content.Context import android.content.Intent +import android.graphics.Rect import android.os.Build import android.os.Bundle import android.support.design.widget.BottomSheetBehavior import android.support.design.widget.CollapsingToolbarLayout import android.support.v4.app.ActivityCompat import android.support.v4.content.ContextCompat +import android.support.v7.widget.DividerItemDecoration +import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView import android.view.Menu import android.view.MenuItem import android.view.View +import android.view.ViewGroup import com.bumptech.glide.Glide -import com.ediposouza.teslesgendstracker.MetricScreen -import com.ediposouza.teslesgendstracker.R -import com.ediposouza.teslesgendstracker.TIME_PATTERN +import com.ediposouza.teslesgendstracker.* import com.ediposouza.teslesgendstracker.data.Deck +import com.ediposouza.teslesgendstracker.data.DeckComment import com.ediposouza.teslesgendstracker.interactor.PrivateInteractor import com.ediposouza.teslesgendstracker.interactor.PublicInteractor import com.ediposouza.teslesgendstracker.manager.MetricsManager -import com.ediposouza.teslesgendstracker.toogleExpanded import com.ediposouza.teslesgendstracker.ui.base.BaseActivity import com.ediposouza.teslesgendstracker.ui.utils.CircleTransform +import com.google.firebase.auth.FirebaseAuth +import jp.wasabeef.recyclerview.animators.SlideInLeftAnimator import kotlinx.android.synthetic.main.activity_deck.* import kotlinx.android.synthetic.main.include_deck_info.* +import kotlinx.android.synthetic.main.itemlist_deck_comment.view.* import org.jetbrains.anko.alert import org.jetbrains.anko.doAsync import org.jetbrains.anko.intentFor @@ -32,8 +38,9 @@ import org.jetbrains.anko.toast import org.threeten.bp.format.DateTimeFormatter import timber.log.Timber import java.text.NumberFormat +import java.util.* -class DeckActivity() : BaseActivity() { +class DeckActivity : BaseActivity() { companion object { @@ -49,10 +56,12 @@ class DeckActivity() : BaseActivity() { } + val publicInteractor by lazy { PublicInteractor() } + val privateInteractor by lazy { PrivateInteractor() } + val numberInstance by lazy { NumberFormat.getNumberInstance() } val deck by lazy { intent.getParcelableExtra(EXTRA_DECK) } val deckOwned by lazy { intent.getBooleanExtra(EXTRA_OWNED, false) } - val numberInstance by lazy { NumberFormat.getNumberInstance() } - val privateInteractor by lazy { PrivateInteractor() } + val commentsSheetBehavior by lazy { BottomSheetBehavior.from(deck_bottom_sheet) } var favorite: Boolean = false var like: Boolean = false @@ -69,7 +78,6 @@ class DeckActivity() : BaseActivity() { favorite = intent.getBooleanExtra(EXTRA_FAVORITE, false) like = intent.getBooleanExtra(EXTRA_LIKE, false) - val sheetBehavior = BottomSheetBehavior.from(deck_bottom_sheet) deck_fab_favorite.setOnClickListener { privateInteractor.setUserDeckFavorite(deck, !favorite) { favorite = !favorite @@ -77,7 +85,7 @@ class DeckActivity() : BaseActivity() { setResult(Activity.RESULT_OK, Intent()) } } - deck_bottom_sheet.setOnClickListener { sheetBehavior.toogleExpanded() } + deck_bottom_sheet.setOnClickListener { commentsSheetBehavior.toogleExpanded() } updateFavoriteItem() loadDeckInfo() setResult(Activity.RESULT_CANCELED, Intent()) @@ -86,15 +94,36 @@ class DeckActivity() : BaseActivity() { override fun onPostCreate(savedInstanceState: Bundle?) { super.onPostCreate(savedInstanceState) supportActionBar?.setDisplayHomeAsUpEnabled(true) + deck_comment_send?.setOnClickListener { + if (deck_comment_new.text.toString().length < 4) { + alert(getString(R.string.deck_comment_size_error)) { + okButton { } + setTheme(R.style.AppDialog) + }.show() + } else { + PrivateInteractor().addDeckComment(deck, deck_comment_new.text.toString()) { + deck_comment_new.setText("") + addComment(it) + } + } + } + onKeyboardVisibilityChange = { + deck_comment_recycle_view.requestLayout() + } + if (!App.hasUserLogged) { + deck_comment_new?.isEnabled = false + deck_comment_send?.isEnabled = false + deck_comment_new?.hint = getText(R.string.deck_comment_new_hint_anonymous) + } doAsync { calculateMissingSoul(deck, privateInteractor) - PublicInteractor().getPatches { + publicInteractor.getPatches { val patch = it.find { it.uidDate == deck.patch } runOnUiThread { deck_details_patch.text = patch?.desc ?: "" } } - PublicInteractor().getUserInfo(deck.owner) { + publicInteractor.getUserInfo(deck.owner) { val ownerUser = it runOnUiThread { deck_details_create_by.text = ownerUser.name @@ -108,6 +137,14 @@ class DeckActivity() : BaseActivity() { MetricsManager.trackScreen(MetricScreen.SCREEN_DECK_DETAILS()) } + override fun onBackPressed() { + if (commentsSheetBehavior.state == BottomSheetBehavior.STATE_EXPANDED) { + commentsSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED + } else { + super.onBackPressed() + } + } + override fun onCreateOptionsMenu(menu: Menu?): Boolean { menuInflater.inflate(if (deckOwned) R.menu.menu_deck_owned else R.menu.menu_deck, menu) menuLike = menu?.findItem(R.id.menu_like) @@ -167,23 +204,50 @@ class DeckActivity() : BaseActivity() { deck_class_cover.setImageResource(deck.cls.imageRes) deck_class_attr1.setImageResource(deck.cls.attr1.imageRes) deck_class_attr2.setImageResource(deck.cls.attr2.imageRes) - deck_comment_qtd.text = numberInstance.format(deck.comments.size) deck_details_type.text = deck.type.name.toLowerCase().capitalize() deck_details_views.text = numberInstance.format(deck.views) deck_details_likes.text = numberInstance.format(deck.likes.size) deck_details_soul_cost.text = numberInstance.format(deck.cost) deck_details_create_at.text = deck.createdAt.toLocalDate().toString() + val updateDate = deck.updatedAt.toLocalDate() val updateTime = deck.updatedAt.toLocalTime().format(DateTimeFormatter.ofPattern(TIME_PATTERN)) - val updateText = "${deck.updatedAt.toLocalDate()} $updateTime" - deck_details_update_at.text = updateText + deck_details_update_at.text = getString(R.string.deck_details_last_update_format, updateDate, updateTime) deck_details_cardlist.showDeck(deck) + configDeckComments() } - fun calculateMissingSoul(deck: Deck, interactor: PrivateInteractor) { + private fun configDeckComments() { + with(deck_comment_recycle_view) { + adapter = DeckCommentAdapter(deck.comments, publicInteractor) { + privateInteractor.remDeckComment(deck, it) { + remComment(it) + } + } + layoutManager = object : LinearLayoutManager(this@DeckActivity) { + override fun setMeasuredDimension(childrenBounds: Rect, wSpec: Int, hSpec: Int) { + val maxHeight = resources.displayMetrics.heightPixels * getVisiblePercent() + with(childrenBounds) { + set(left, top, right, if (bottom < maxHeight) bottom else maxHeight.toInt()) + } + super.setMeasuredDimension(childrenBounds, wSpec, hSpec) + } + + private fun getVisiblePercent(): Float { + Timber.d("Keyboard visible: " + keyboardVisible) + return if (keyboardVisible) 0.2f else 0.6f + } + } + itemAnimator = SlideInLeftAnimator() + addItemDecoration(DividerItemDecoration(this@DeckActivity, DividerItemDecoration.VERTICAL)) + } + deck_comment_qtd.text = numberInstance.format(deck.comments.size) + } + + fun calculateMissingSoul(deck: Deck, privateInteractor: PrivateInteractor) { with(deck_details_soul_missing) { visibility = View.INVISIBLE deck_details_soul_missing_loading.visibility = View.VISIBLE - interactor.getMissingCards(deck, { deck_details_soul_missing_loading.visibility = View.VISIBLE }) { + privateInteractor.getMissingCards(deck, { deck_details_soul_missing_loading.visibility = View.VISIBLE }) { deck_details_soul_missing_loading.visibility = View.GONE val missingSoul = it.map { it.qtd * it.rarity.soulCost }.sum() Timber.d("Missing %d", missingSoul) @@ -194,4 +258,83 @@ class DeckActivity() : BaseActivity() { } } -} + private fun addComment(it: DeckComment) { + (deck_comment_recycle_view.adapter as DeckCommentAdapter).add(it) + deck_comment_recycle_view.scrollToPosition(0) + deck_comment_qtd.text = deck_comment_recycle_view.adapter.itemCount.toString() + deck_comment_recycle_view.requestLayout() + setResult(Activity.RESULT_OK, Intent()) + } + + private fun remComment(commentId: String) { + (deck_comment_recycle_view.adapter as DeckCommentAdapter).rem(commentId) + deck_comment_qtd.text = deck_comment_recycle_view.adapter.itemCount.toString() + deck_comment_recycle_view.requestLayout() + setResult(Activity.RESULT_OK, Intent()) + } + + class DeckCommentAdapter(val items: List, val publicInteractor: PublicInteractor, + val onRemComment: (commentId: String) -> Unit) : RecyclerView.Adapter() { + + init { + sortDeckComments() + } + + override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): DeckCommentViewHolder { + return DeckCommentViewHolder(parent?.inflate(R.layout.itemlist_deck_comment), onRemComment) + } + + override fun onBindViewHolder(holder: DeckCommentViewHolder?, position: Int) { + holder?.bind(items[position], publicInteractor) + } + + override fun getItemCount() = items.size + + fun add(deckComment: DeckComment) { + (items as ArrayList).add(0, deckComment) + notifyItemInserted(0) + } + + fun rem(commentId: String) { + val deckComment = items.find { it.id == commentId } + val deckCommentIndex = items.indexOf(deckComment) + (items as ArrayList).remove(deckComment) + notifyItemRemoved(deckCommentIndex) + } + + private fun sortDeckComments() { + Collections.sort(items, { dc1, dc2 -> dc2.date.compareTo(dc1.date) }) + } + + } + + class DeckCommentViewHolder(view: View?, val onRemComment: (commentId: String) -> Unit) : RecyclerView.ViewHolder(view) { + + fun bind(comment: DeckComment, publicInteractor: PublicInteractor) { + val timeFormatter = DateTimeFormatter.ofPattern("HH:mm") + itemView.deck_comment_msg.text = comment.comment + itemView.deck_comment_date.text = itemView.context.getString(R.string.deck_comment_date_format, + comment.date.toLocalDate(), comment.date.toLocalTime().format(timeFormatter)) + doAsync { + publicInteractor.getUserInfo(comment.owner) { + val ownerUser = it + itemView.post { + itemView.deck_comment_owner.text = ownerUser.name + with(itemView.deck_comment_delete) { + val owner = comment.owner == FirebaseAuth.getInstance().currentUser?.uid + visibility = if (owner) View.VISIBLE else View.GONE + setOnClickListener { onRemComment(comment.id) } + } + Glide.with(itemView.context) + .load(ownerUser.photoUrl) + .fallback(R.drawable.ic_user) + .transform(CircleTransform(itemView.context)) + .into(itemView.deck_comment_owner_photo) + } + } + } + } + + } + +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/base/BaseActivity.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/base/BaseActivity.kt index 53f8fa5..15e58ec 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/base/BaseActivity.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/base/BaseActivity.kt @@ -1,6 +1,7 @@ package com.ediposouza.teslesgendstracker.ui.base import android.content.Intent +import android.graphics.Rect import android.os.Bundle import android.support.design.widget.Snackbar import android.support.v7.app.AlertDialog @@ -21,6 +22,7 @@ import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.GoogleAuthProvider import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe +import org.jetbrains.anko.contentView import org.jetbrains.anko.toast import timber.log.Timber @@ -29,8 +31,6 @@ import timber.log.Timber */ open class BaseActivity : AppCompatActivity(), GoogleApiClient.OnConnectionFailedListener, FirebaseAuth.AuthStateListener { - protected val eventBus by lazy { EventBus.getDefault() } - private val RC_SIGN_IN: Int = 235 private var loading: AlertDialog? = null @@ -38,6 +38,10 @@ open class BaseActivity : AppCompatActivity(), GoogleApiClient.OnConnectionFaile private var googleApiClient: GoogleApiClient? = null private val firebaseAuth by lazy { FirebaseAuth.getInstance() } + protected var keyboardVisible = false + protected val eventBus by lazy { EventBus.getDefault() } + protected var onKeyboardVisibilityChange: (() -> Unit)? = null + public override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -51,19 +55,20 @@ open class BaseActivity : AppCompatActivity(), GoogleApiClient.OnConnectionFaile .build() } - override fun onDestroy() { - MetricsManager.flush() - super.onDestroy() - } - - override fun onConnectionFailed(p0: ConnectionResult) { - } - override fun onPostCreate(savedInstanceState: Bundle?) { super.onPostCreate(savedInstanceState) setSupportActionBar(findViewById(R.id.toolbar) as Toolbar?) supportActionBar?.title = "" supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_back) + contentView?.viewTreeObserver?.addOnGlobalLayoutListener({ + val r = Rect() + contentView?.getWindowVisibleDisplayFrame(r) + val screenHeight = contentView?.rootView?.height ?: 0 + // r.bottom is the position above soft keypad or device button. if keypad is shown, the r.bottom is smaller than that before. + val keypadHeight = screenHeight - r.bottom + keyboardVisible = keypadHeight > (screenHeight * 0.15) // 0.15 ratio is perhaps enough to determine keypad height. + onKeyboardVisibilityChange?.invoke() + }) } override fun onStart() { @@ -86,6 +91,11 @@ open class BaseActivity : AppCompatActivity(), GoogleApiClient.OnConnectionFaile firebaseAuth.removeAuthStateListener(this) } + override fun onDestroy() { + MetricsManager.flush() + super.onDestroy() + } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == RC_SIGN_IN) { @@ -99,6 +109,9 @@ open class BaseActivity : AppCompatActivity(), GoogleApiClient.OnConnectionFaile } } + override fun onConnectionFailed(p0: ConnectionResult) { + } + override fun onAuthStateChanged(firebaseAuth: FirebaseAuth) { val currentUser = firebaseAuth.currentUser if (currentUser != null) { @@ -112,7 +125,7 @@ open class BaseActivity : AppCompatActivity(), GoogleApiClient.OnConnectionFaile } } - fun firebaseAuthWithGoogle(acct: GoogleSignInAccount?) { + private fun firebaseAuthWithGoogle(acct: GoogleSignInAccount?) { Timber.d("firebaseAuthWithGoogle:" + acct?.id) showLoading() val credential = GoogleAuthProvider.getCredential(acct?.idToken, null) diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/InsetFrameLayout.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/InsetFrameLayout.kt new file mode 100644 index 0000000..d02d93e --- /dev/null +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/InsetFrameLayout.kt @@ -0,0 +1,32 @@ +package com.ediposouza.teslesgendstracker.ui.widget + +import android.content.Context +import android.os.Build.VERSION +import android.os.Build.VERSION_CODES +import android.util.AttributeSet +import android.view.WindowInsets +import android.widget.FrameLayout + +/** + * Created by EdipoSouza on 12/28/16. + */ +class InsetFrameLayout(ctx: Context?, attrs: AttributeSet?, defStyleAttr: Int) : + FrameLayout(ctx, attrs, defStyleAttr) { + + private val mInsets = IntArray(4) + + constructor(ctx: Context?) : this(ctx, null, 0) + + constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) + + override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets { + if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { + mInsets[0] = insets.systemWindowInsetLeft + mInsets[1] = insets.systemWindowInsetTop + mInsets[2] = insets.systemWindowInsetRight + return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, 0, 0, insets.systemWindowInsetBottom)) + } else { + return insets + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_delete_red.xml b/app/src/main/res/drawable/ic_delete_red.xml new file mode 100644 index 0000000..7d3c2b4 --- /dev/null +++ b/app/src/main/res/drawable/ic_delete_red.xml @@ -0,0 +1,4 @@ + + + + diff --git a/app/src/main/res/drawable/ic_delete_red_svg.xml b/app/src/main/res/drawable/ic_delete_red_svg.xml new file mode 100644 index 0000000..17928bd --- /dev/null +++ b/app/src/main/res/drawable/ic_delete_red_svg.xml @@ -0,0 +1,10 @@ + + + + diff --git a/app/src/main/res/drawable/ic_send.xml b/app/src/main/res/drawable/ic_send.xml new file mode 100644 index 0000000..e96cb7f --- /dev/null +++ b/app/src/main/res/drawable/ic_send.xml @@ -0,0 +1,4 @@ + + + + diff --git a/app/src/main/res/drawable/ic_send_svg.xml b/app/src/main/res/drawable/ic_send_svg.xml new file mode 100644 index 0000000..6dcc835 --- /dev/null +++ b/app/src/main/res/drawable/ic_send_svg.xml @@ -0,0 +1,10 @@ + + + + diff --git a/app/src/main/res/layout/activity_deck.xml b/app/src/main/res/layout/activity_deck.xml index 319f696..7f28735 100644 --- a/app/src/main/res/layout/activity_deck.xml +++ b/app/src/main/res/layout/activity_deck.xml @@ -1,16 +1,17 @@ - + tools:paddingBottom="@dimen/navigation_bar_height"> @@ -90,9 +91,9 @@ android:id="@+id/deck_details_create_by_photo" android:layout_width="@dimen/size_small" android:layout_height="@dimen/size_small" - android:layout_marginStart="@dimen/large_margin" android:layout_alignBottom="@id/deck_class_attr2" android:layout_marginBottom="@dimen/nano_margin" + android:layout_marginStart="@dimen/large_margin" android:layout_toEndOf="@id/deck_class_attr2" android:src="@drawable/ic_user" /> @@ -101,9 +102,9 @@ style="@style/DeckInfoItem" android:layout_width="wrap_content" android:layout_height="@dimen/size_small" - android:layout_marginStart="@dimen/default_margin" android:layout_alignTop="@id/deck_class_attr2" android:layout_marginBottom="@dimen/default_margin" + android:layout_marginStart="@dimen/default_margin" android:layout_toEndOf="@id/deck_details_create_by_photo" tools:text="Édipo Souza" /> @@ -131,6 +132,7 @@ android:layout_marginStart="@dimen/large_margin" android:clickable="true" android:elevation="@dimen/cardview_default_elevation" + android:fitsSystemWindows="false" android:foreground="?attr/selectableItemBackground" app:behavior_hideable="true" app:behavior_peekHeight="@dimen/card_bottom_sheet_peek_height" @@ -140,13 +142,23 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/default_margin" - android:paddingBottom="@dimen/card_bottom_sheet_margin_bottom"> + tools:paddingBottom="@dimen/card_bottom_sheet_margin_bottom"> + + + android:layout_margin="@dimen/default_margin" + android:fadeScrollbars="false" + android:scrollbarSize="@dimen/small_margin" + android:scrollbarThumbVertical="@drawable/scrollbar_thumb" + android:scrollbars="vertical" + app:layoutManager="LinearLayoutManager" + tools:listitem="@layout/itemlist_deck_comment" /> + + + + @@ -186,4 +224,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/itemlist_deck_comment.xml b/app/src/main/res/layout/itemlist_deck_comment.xml index 6065130..969d50d 100644 --- a/app/src/main/res/layout/itemlist_deck_comment.xml +++ b/app/src/main/res/layout/itemlist_deck_comment.xml @@ -2,41 +2,64 @@ + + + tools:text="Édipo da Silva Souza" + tools:textColor="@android:color/white" /> + android:maxLines="5" + android:textColor="@color/primary_text_dark" + tools:text="Amazing deck with some awesome features that I never expected" + tools:textColor="@android:color/white" /> + tools:text="10/11/2016\n18h35" + tools:textColor="@android:color/white" /> + + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 7b763ea..252f79d 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -44,7 +44,7 @@ 24dp @dimen/status_bar_height - 88dp + 40dp @dimen/navigation_bar_height @@ -56,6 +56,7 @@ 140dp 32dp + 56dp 32dp 16dp 12dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 66ed6df..f1b7bc5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -70,7 +70,13 @@ Create by Create at Last update + %1$s at %2$s Deck deleted! + Comments + Your comment! + Your comment! (Need login) + Message is too short! + %1$s\n%2$s deck_transition deck_name_transition deck_cover_transition diff --git a/build.gradle b/build.gradle index d29a8ee..dda222b 100644 --- a/build.gradle +++ b/build.gradle @@ -5,8 +5,8 @@ buildscript { appVersionName = "0.2.1" appVersionCode = 3 - kotlin_version = "1.0.5-3" - prepareRelease = true + kotlin_version = "1.0.6" + prepareRelease = false } repositories { From 69d506aed952811ee00572879ebc4f2876c58c18 Mon Sep 17 00:00:00 2001 From: EdipoSouza Date: Thu, 29 Dec 2016 00:58:25 -0200 Subject: [PATCH 05/17] Make Adapters and ViewHolders class as InnerClass. Changed scrollbarFadeDuration="0" to fadeScrollbars="false". Fix some Lint warnings from inspect --- .../teslesgendstracker/MetricsConstants.kt | 2 +- .../teslesgendstracker/data/Card.kt | 6 +- .../teslesgendstracker/data/Deck.kt | 2 +- .../interactor/BaseInteractor.kt | 11 +- .../interactor/FirebaseParsers.kt | 4 +- .../interactor/PrivateInteractor.kt | 2 +- .../interactor/PublicInteractor.kt | 2 +- .../teslesgendstracker/ui/CardActivity.kt | 2 +- .../teslesgendstracker/ui/DashActivity.kt | 5 +- .../teslesgendstracker/ui/DeckActivity.kt | 7 +- .../ui/base/BaseActivity.kt | 2 +- .../ui/base/BaseFragment.kt | 2 +- .../ui/cards/CardsFragment.kt | 45 ++-- .../ui/cards/tabs/CardsAllFragment.kt | 70 +++--- .../ui/cards/tabs/CardsCollectionFragment.kt | 111 ++++----- .../ui/decks/DecksFragment.kt | 44 ++-- .../ui/decks/new/NewDeckCardsListFragment.kt | 3 +- .../ui/decks/tabs/DecksPublicFragment.kt | 134 +++++------ .../ui/decks/widget/DeckList.kt | 218 +++++++++--------- .../ui/decks/widget/MagikaCosts.kt | 8 +- .../ui/utils/AutoHideBehaviour.kt | 5 +- .../ui/widget/CollectionStatistics.kt | 6 +- .../ui/widget/CollectionStatisticsAttr.kt | 6 +- .../ui/widget/NestedCoordinatorLayout.kt | 12 +- .../ui/widget/filter/FilterAttr.kt | 6 +- .../ui/widget/filter/FilterAttrLockable.kt | 6 +- .../ui/widget/filter/FilterMagika.kt | 6 +- .../ui/widget/filter/FilterRarity.kt | 6 +- app/src/main/res/drawable/xml_switch.xml | 2 +- app/src/main/res/layout/activity_new_deck.xml | 2 +- .../main/res/layout/fragment_cards_list.xml | 2 +- .../main/res/layout/fragment_decks_list.xml | 2 +- .../res/layout/fragment_decks_list_owner.xml | 2 +- .../layout/widget_collection_statistics.xml | 2 +- app/src/main/res/layout/widget_decklist.xml | 2 +- app/src/main/res/values/styles.xml | 2 +- 36 files changed, 363 insertions(+), 386 deletions(-) diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/MetricsConstants.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/MetricsConstants.kt index cfdaaae..70ec9ad 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/MetricsConstants.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/MetricsConstants.kt @@ -3,7 +3,7 @@ package com.ediposouza.teslesgendstracker /** * Created by ediposouza on 08/12/16. */ -abstract class MetricsConstants() { +abstract class MetricsConstants { companion object { diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/Card.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/Card.kt index f716dd8..e501f53 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/Card.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/Card.kt @@ -90,7 +90,7 @@ enum class CardRarity(val color: Int, val soulCost: Int, @IntegerRes val imageRe } -enum class CardType() { +enum class CardType { ACTION, CREATURE, @@ -175,7 +175,7 @@ enum class CardRace(val desc: String) { } } -enum class CardKeyword() { +enum class CardKeyword { ACTIVATE, BREAKTHROUGH, @@ -205,7 +205,7 @@ enum class CardKeyword() { } } -enum class CardArenaTier() { +enum class CardArenaTier { TERRIBLE, POOR, diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/Deck.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/Deck.kt index 4e2f084..837c860 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/Deck.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/data/Deck.kt @@ -5,7 +5,7 @@ import android.os.Parcelable import org.threeten.bp.LocalDateTime import java.util.* -enum class DeckType() { +enum class DeckType { AGGRO, ARENA, diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/BaseInteractor.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/BaseInteractor.kt index aae2355..493e153 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/BaseInteractor.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/BaseInteractor.kt @@ -2,12 +2,13 @@ package com.ediposouza.teslesgendstracker.interactor import com.ediposouza.teslesgendstracker.data.Attribute import com.ediposouza.teslesgendstracker.data.CardSet +import com.google.firebase.database.DatabaseReference import com.google.firebase.database.FirebaseDatabase /** * Created by ediposouza on 01/11/16. */ -open class BaseInteractor() { +open class BaseInteractor { companion object { @@ -26,11 +27,9 @@ open class BaseInteractor() { protected val KEY_DECK_CLASS = "cls" protected val KEY_DECK_UPDATE_AT = "updatedAt" - protected val database by lazy { FirebaseDatabase.getInstance().reference } - - protected val dbDecks by lazy { database.child(NODE_DECKS) } - - protected val dbUsers by lazy { database.child(NODE_USERS) } + protected val database: DatabaseReference by lazy { FirebaseDatabase.getInstance().reference } + protected val dbDecks: DatabaseReference by lazy { database.child(NODE_DECKS) } + protected val dbUsers: DatabaseReference by lazy { database.child(NODE_USERS) } fun getListFromSets(set: CardSet?, onSuccess: (List) -> Unit, getFromSet: (set: CardSet, onSuccess: (List) -> Unit) -> Unit) { diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/FirebaseParsers.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/FirebaseParsers.kt index 0ade3fc..aa89908 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/FirebaseParsers.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/FirebaseParsers.kt @@ -4,7 +4,7 @@ import com.ediposouza.teslesgendstracker.data.* import com.ediposouza.teslesgendstracker.toIntSafely import org.threeten.bp.LocalDateTime -class CardParser() { +class CardParser { val name: String = "" val rarity: String = "" @@ -107,7 +107,7 @@ class DeckParser( } -class PatchParser() { +class PatchParser { val desc: String = "" diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/PrivateInteractor.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/PrivateInteractor.kt index fb6dc9b..f2754f3 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/PrivateInteractor.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/PrivateInteractor.kt @@ -15,7 +15,7 @@ import java.util.* /** * Created by ediposouza on 01/11/16. */ -class PrivateInteractor() : BaseInteractor() { +class PrivateInteractor : BaseInteractor() { private val NODE_DECKS_PRIVATE = "private" private val NODE_FAVORITE = "favorite" diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/PublicInteractor.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/PublicInteractor.kt index 1c70ed4..778ff9d 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/PublicInteractor.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/interactor/PublicInteractor.kt @@ -9,7 +9,7 @@ import timber.log.Timber /** * Created by ediposouza on 01/11/16. */ -class PublicInteractor() : BaseInteractor() { +class PublicInteractor : BaseInteractor() { private val NODE_PATCHES = "patches" diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/CardActivity.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/CardActivity.kt index bfbfec1..c990811 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/CardActivity.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/CardActivity.kt @@ -31,7 +31,7 @@ class CardActivity : BaseActivity() { } - val card by lazy { intent.getParcelableExtra(EXTRA_CARD) } + val card: Card by lazy { intent.getParcelableExtra(EXTRA_CARD) } var favorite: Boolean = false override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DashActivity.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DashActivity.kt index bd97b42..744f167 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DashActivity.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DashActivity.kt @@ -25,6 +25,7 @@ import com.ediposouza.teslesgendstracker.ui.cards.CmdFilterMagika import com.ediposouza.teslesgendstracker.ui.cards.CmdFilterRarity import com.ediposouza.teslesgendstracker.ui.decks.DecksFragment import com.ediposouza.teslesgendstracker.ui.utils.CircleTransform +import com.ediposouza.teslesgendstracker.ui.widget.CollectionStatistics import com.google.firebase.auth.FirebaseAuth import kotlinx.android.synthetic.main.activity_dash.* import kotlinx.android.synthetic.main.navigation_drawer_header.view.* @@ -39,7 +40,9 @@ class DashActivity : BaseActivity(), val privateInteractor = PrivateInteractor() var filterGreatMargin = false - val statisticsSheetBehavior by lazy { BottomSheetBehavior.from(collection_statistics) } + val statisticsSheetBehavior: BottomSheetBehavior by lazy { + BottomSheetBehavior.from(collection_statistics) + } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DeckActivity.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DeckActivity.kt index 7f356c8..f6c9082 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DeckActivity.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/DeckActivity.kt @@ -10,6 +10,7 @@ import android.support.design.widget.BottomSheetBehavior import android.support.design.widget.CollapsingToolbarLayout import android.support.v4.app.ActivityCompat import android.support.v4.content.ContextCompat +import android.support.v7.widget.CardView import android.support.v7.widget.DividerItemDecoration import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView @@ -58,10 +59,10 @@ class DeckActivity : BaseActivity() { val publicInteractor by lazy { PublicInteractor() } val privateInteractor by lazy { PrivateInteractor() } - val numberInstance by lazy { NumberFormat.getNumberInstance() } - val deck by lazy { intent.getParcelableExtra(EXTRA_DECK) } val deckOwned by lazy { intent.getBooleanExtra(EXTRA_OWNED, false) } - val commentsSheetBehavior by lazy { BottomSheetBehavior.from(deck_bottom_sheet) } + val deck: Deck by lazy { intent.getParcelableExtra(EXTRA_DECK) } + val numberInstance: NumberFormat by lazy { NumberFormat.getNumberInstance() } + val commentsSheetBehavior: BottomSheetBehavior by lazy { BottomSheetBehavior.from(deck_bottom_sheet) } var favorite: Boolean = false var like: Boolean = false diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/base/BaseActivity.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/base/BaseActivity.kt index 15e58ec..c8fc5c4 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/base/BaseActivity.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/base/BaseActivity.kt @@ -39,7 +39,7 @@ open class BaseActivity : AppCompatActivity(), GoogleApiClient.OnConnectionFaile private val firebaseAuth by lazy { FirebaseAuth.getInstance() } protected var keyboardVisible = false - protected val eventBus by lazy { EventBus.getDefault() } + protected val eventBus: EventBus by lazy { EventBus.getDefault() } protected var onKeyboardVisibilityChange: (() -> Unit)? = null public override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/base/BaseFragment.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/base/BaseFragment.kt index f2f8b40..f11d558 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/base/BaseFragment.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/base/BaseFragment.kt @@ -11,7 +11,7 @@ import timber.log.Timber open class BaseFragment : Fragment() { - protected val eventBus by lazy { EventBus.getDefault() } + protected val eventBus: EventBus by lazy { EventBus.getDefault() } protected var fragmentSelected: Boolean = false diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/CardsFragment.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/CardsFragment.kt index 7e85119..aa220ce 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/CardsFragment.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/CardsFragment.kt @@ -22,6 +22,7 @@ import com.ediposouza.teslesgendstracker.ui.base.* import com.ediposouza.teslesgendstracker.ui.cards.tabs.CardsAllFragment import com.ediposouza.teslesgendstracker.ui.cards.tabs.CardsCollectionFragment import com.ediposouza.teslesgendstracker.ui.cards.tabs.CardsFavoritesFragment +import com.ediposouza.teslesgendstracker.ui.widget.CollectionStatistics import kotlinx.android.synthetic.main.activity_dash.* import kotlinx.android.synthetic.main.fragment_cards.* @@ -34,7 +35,9 @@ class CardsFragment : BaseFragment(), SearchView.OnQueryTextListener { val handler = Handler() val trackSearch = Runnable { MetricsManager.trackSearch(query ?: "") } - val statisticsSheetBehavior by lazy { BottomSheetBehavior.from(activity.collection_statistics) } + val statisticsSheetBehavior: BottomSheetBehavior by lazy { + BottomSheetBehavior.from(activity.collection_statistics) + } val pageChange = object : ViewPager.SimpleOnPageChangeListener() { override fun onPageSelected(position: Int) { @@ -125,33 +128,29 @@ class CardsFragment : BaseFragment(), SearchView.OnQueryTextListener { return true } -} - -class CardsPageAdapter(ctx: Context, fm: FragmentManager) : FragmentStatePagerAdapter(fm) { + class CardsPageAdapter(ctx: Context, fm: FragmentManager) : FragmentStatePagerAdapter(fm) { - var titles: Array - val cardsCollectionFragment by lazy { CardsCollectionFragment() } - val cardsFavoritesFragment by lazy { CardsFavoritesFragment() } - val cardsAllFragment by lazy { CardsAllFragment() } + var titles: Array = ctx.resources.getStringArray(R.array.cards_tabs) + val cardsCollectionFragment by lazy { CardsCollectionFragment() } + val cardsFavoritesFragment by lazy { CardsFavoritesFragment() } + val cardsAllFragment by lazy { CardsAllFragment() } - init { - titles = ctx.resources.getStringArray(R.array.cards_tabs) - } + override fun getItem(position: Int): CardsAllFragment { + return when (position) { + 1 -> cardsCollectionFragment + 2 -> cardsFavoritesFragment + else -> cardsAllFragment + } + } - override fun getItem(position: Int): CardsAllFragment { - return when (position) { - 1 -> cardsCollectionFragment - 2 -> cardsFavoritesFragment - else -> cardsAllFragment + override fun getCount(): Int { + return titles.size } - } - override fun getCount(): Int { - return titles.size - } + override fun getPageTitle(position: Int): CharSequence { + return titles[position] + } - override fun getPageTitle(position: Int): CharSequence { - return titles[position] } -} \ No newline at end of file +} diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsAllFragment.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsAllFragment.kt index 12a1668..6c1d648 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsAllFragment.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsAllFragment.kt @@ -237,50 +237,50 @@ open class CardsAllFragment : BaseFragment() { ActivityOptionsCompat.makeSceneTransitionAnimation(activity, view, transitionName).toBundle()) } -} + class CardsAllAdapter(adsEachItems: Int, layoutManager: GridLayoutManager, @LayoutRes adsLayout: Int, + @DimenRes val cardHeight: Int, val itemClick: (View, Card) -> Unit, + val itemLongClick: (View, Card) -> Boolean) : BaseAdsAdapter(adsEachItems, layoutManager, adsLayout) { -class CardsAllAdapter(adsEachItems: Int, layoutManager: GridLayoutManager, @LayoutRes adsLayout: Int, - @DimenRes val cardHeight: Int, val itemClick: (View, Card) -> Unit, - val itemLongClick: (View, Card) -> Boolean) : BaseAdsAdapter(adsEachItems, layoutManager, adsLayout) { + var items: List = ArrayList() - var items: List = ArrayList() + override fun onCreateDefaultViewHolder(parent: ViewGroup): RecyclerView.ViewHolder { + return CardsAllViewHolder(parent.inflate(R.layout.itemlist_card), cardHeight, itemClick, itemLongClick) + } - override fun onCreateDefaultViewHolder(parent: ViewGroup): RecyclerView.ViewHolder { - return CardsAllViewHolder(parent.inflate(R.layout.itemlist_card), cardHeight, itemClick, itemLongClick) - } + override fun onBindDefaultViewHolder(holder: RecyclerView.ViewHolder?, position: Int) { + (holder as CardsAllViewHolder).bind(items[position]) + } - override fun onBindDefaultViewHolder(holder: RecyclerView.ViewHolder?, position: Int) { - (holder as CardsAllViewHolder).bind(items[position]) + override fun getDefaultItemCount(): Int = items.size + + fun showCards(cards: List) { + val oldItems = items + items = cards + if (items.isEmpty() || items.minus(oldItems).isEmpty()) { + notifyDataSetChanged() + return + } + DiffUtil.calculateDiff(SimpleDiffCallback(items, oldItems) { oldItem, newItem -> + oldItem.shortName == newItem.shortName + }).dispatchUpdatesTo(this) + } } - override fun getDefaultItemCount(): Int = items.size + class CardsAllViewHolder(val view: View, @DimenRes val cardHeight: Int, val itemClick: (View, Card) -> Unit, + val itemLongClick: (View, Card) -> Boolean) : RecyclerView.ViewHolder(view) { - fun showCards(cards: List) { - val oldItems = items - items = cards - if (items.isEmpty() || items.minus(oldItems).isEmpty()) { - notifyDataSetChanged() - return + init { + val cardLayoutParams = itemView.card_all_image.layoutParams + cardLayoutParams.height = itemView.context.resources.getDimensionPixelSize(cardHeight) + itemView.card_all_image.layoutParams = cardLayoutParams } - DiffUtil.calculateDiff(SimpleDiffCallback(items, oldItems) { oldItem, newItem -> - oldItem.shortName == newItem.shortName - }).dispatchUpdatesTo(this) - } -} - -class CardsAllViewHolder(val view: View, @DimenRes val cardHeight: Int, val itemClick: (View, Card) -> Unit, - val itemLongClick: (View, Card) -> Boolean) : RecyclerView.ViewHolder(view) { - init { - val cardLayoutParams = itemView.card_all_image.layoutParams - cardLayoutParams.height = itemView.context.resources.getDimensionPixelSize(cardHeight) - itemView.card_all_image.layoutParams = cardLayoutParams - } + fun bind(card: Card) { + itemView.setOnClickListener { itemClick(itemView.card_all_image, card) } + itemView.setOnLongClickListener { itemLongClick(itemView.card_all_image, card) } + itemView.card_all_image.setImageBitmap(card.imageBitmap(itemView.context)) + } - fun bind(card: Card) { - itemView.setOnClickListener { itemClick(itemView.card_all_image, card) } - itemView.setOnLongClickListener { itemLongClick(itemView.card_all_image, card) } - itemView.card_all_image.setImageBitmap(card.imageBitmap(itemView.context)) } -} \ No newline at end of file +} diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsCollectionFragment.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsCollectionFragment.kt index f238556..c945a87 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsCollectionFragment.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/cards/tabs/CardsCollectionFragment.kt @@ -19,6 +19,7 @@ import com.ediposouza.teslesgendstracker.inflate import com.ediposouza.teslesgendstracker.manager.MetricsManager import com.ediposouza.teslesgendstracker.ui.base.BaseAdsAdapter import com.ediposouza.teslesgendstracker.ui.utils.SimpleDiffCallback +import com.ediposouza.teslesgendstracker.ui.widget.CollectionStatistics import jp.wasabeef.recyclerview.animators.ScaleInAnimator import kotlinx.android.synthetic.main.activity_dash.* import kotlinx.android.synthetic.main.fragment_cards_list.* @@ -32,8 +33,8 @@ class CardsCollectionFragment : CardsAllFragment() { override val isCardsCollection: Boolean = true - val view_statistics by lazy { activity.collection_statistics } - val statisticsSheetBehavior by lazy { + val view_statistics: CollectionStatistics by lazy { activity.collection_statistics } + val statisticsSheetBehavior: BottomSheetBehavior by lazy { BottomSheetBehavior.from(view_statistics) } @@ -54,8 +55,8 @@ class CardsCollectionFragment : CardsAllFragment() { val expanded = newState == BottomSheetBehavior.STATE_EXPANDED || newState == BottomSheetBehavior.STATE_SETTLING if (expanded) { - view_statistics?.scrollToTop() - view_statistics?.updateStatistics() + view_statistics.scrollToTop() + view_statistics.updateStatistics() } when (newState) { BottomSheetBehavior.STATE_EXPANDED -> { @@ -102,72 +103,72 @@ class CardsCollectionFragment : CardsAllFragment() { privateInteractor.setUserCardQtd(cardSlot.card, finalQtd) { cards_recycler_view?.itemAnimator = null cardsCollectionAdapter.updateSlot(cardSlot, finalQtd) - view_statistics?.updateStatistics(currentAttr) + view_statistics.updateStatistics(currentAttr) MetricsManager.trackAction(MetricAction.ACTION_COLLECTION_CARD_QTD_CHANGE(), finalQtd.toString()) } } -} - -class CardsCollectionAdapter(adsEachItems: Int, layoutManager: GridLayoutManager, - @LayoutRes adsLayout: Int, val itemClick: (CardSlot) -> Unit, - val itemLongClick: (View, Card) -> Boolean) : BaseAdsAdapter(adsEachItems, layoutManager, adsLayout) { + class CardsCollectionAdapter(adsEachItems: Int, layoutManager: GridLayoutManager, + @LayoutRes adsLayout: Int, val itemClick: (CardSlot) -> Unit, + val itemLongClick: (View, Card) -> Boolean) : BaseAdsAdapter(adsEachItems, layoutManager, adsLayout) { - var items: ArrayList = ArrayList() + var items: ArrayList = ArrayList() - override fun onCreateDefaultViewHolder(parent: ViewGroup): RecyclerView.ViewHolder { - return CardsCollectionViewHolder(parent.inflate(R.layout.itemlist_card_collection), itemClick, itemLongClick) - } + override fun onCreateDefaultViewHolder(parent: ViewGroup): RecyclerView.ViewHolder { + return CardsCollectionViewHolder(parent.inflate(R.layout.itemlist_card_collection), itemClick, itemLongClick) + } - override fun onBindDefaultViewHolder(holder: RecyclerView.ViewHolder?, position: Int) { - (holder as CardsCollectionViewHolder).bind(items[position]) - } + override fun onBindDefaultViewHolder(holder: RecyclerView.ViewHolder?, position: Int) { + (holder as CardsCollectionViewHolder).bind(items[position]) + } - override fun getDefaultItemCount(): Int = items.size + override fun getDefaultItemCount(): Int = items.size - fun showCards(cardSlots: ArrayList) { - val oldItems = items - items = cardSlots - if (items.isEmpty() || items.minus(oldItems).isEmpty()) { - notifyDataSetChanged() - return + fun showCards(cardSlots: ArrayList) { + val oldItems = items + items = cardSlots + if (items.isEmpty() || items.minus(oldItems).isEmpty()) { + notifyDataSetChanged() + return + } + DiffUtil.calculateDiff(SimpleDiffCallback(items, oldItems) { oldItem, newItem -> + oldItem.card.shortName == newItem.card.shortName + }).dispatchUpdatesTo(this) } - DiffUtil.calculateDiff(SimpleDiffCallback(items, oldItems) { oldItem, newItem -> - oldItem.card.shortName == newItem.card.shortName - }).dispatchUpdatesTo(this) - } - fun updateSlot(cardSlot: CardSlot, newQtd: Long) { - val slotIndex = items.indexOf(cardSlot) - if (slotIndex > -1) { - items[slotIndex] = CardSlot(cardSlot.card, newQtd) - notifyItemChanged(slotIndex + getAdsQtdBeforeDefaultPosition(slotIndex)) + fun updateSlot(cardSlot: CardSlot, newQtd: Long) { + val slotIndex = items.indexOf(cardSlot) + if (slotIndex > -1) { + items[slotIndex] = CardSlot(cardSlot.card, newQtd) + notifyItemChanged(slotIndex + getAdsQtdBeforeDefaultPosition(slotIndex)) + } } - } -} + } -class CardsCollectionViewHolder(val view: View, val itemClick: (CardSlot) -> Unit, - val itemLongClick: (View, Card) -> Boolean) : RecyclerView.ViewHolder(view) { + class CardsCollectionViewHolder(val view: View, val itemClick: (CardSlot) -> Unit, + val itemLongClick: (View, Card) -> Boolean) : RecyclerView.ViewHolder(view) { - fun bind(cardSlot: CardSlot) { - itemView.setOnClickListener { itemClick(cardSlot) } - itemView.setOnLongClickListener { - itemLongClick(itemView.card_collection_image, cardSlot.card) - } - itemView.card_collection_image.setImageBitmap(cardSlot.card.imageBitmap(itemView.context)) - if (cardSlot.qtd == 0L) { - val color = ContextCompat.getColor(itemView.context, R.color.card_zero_qtd) - itemView.card_collection_image.setColorFilter(color) - } else { - itemView.card_collection_image.clearColorFilter() + fun bind(cardSlot: CardSlot) { + itemView.setOnClickListener { itemClick(cardSlot) } + itemView.setOnLongClickListener { + itemLongClick(itemView.card_collection_image, cardSlot.card) + } + itemView.card_collection_image.setImageBitmap(cardSlot.card.imageBitmap(itemView.context)) + if (cardSlot.qtd == 0L) { + val color = ContextCompat.getColor(itemView.context, R.color.card_zero_qtd) + itemView.card_collection_image.setColorFilter(color) + } else { + itemView.card_collection_image.clearColorFilter() + } + itemView.card_collection_qtd.setImageResource(when (cardSlot.qtd) { + 0L -> R.drawable.ic_qtd_zero + 2L -> R.drawable.ic_qtd_two + else -> R.drawable.ic_qtd_three + }) + itemView.card_collection_qtd.visibility = if (cardSlot.qtd == 1L) View.GONE else View.VISIBLE } - itemView.card_collection_qtd.setImageResource(when (cardSlot.qtd) { - 0L -> R.drawable.ic_qtd_zero - 2L -> R.drawable.ic_qtd_two - else -> R.drawable.ic_qtd_three - }) - itemView.card_collection_qtd.visibility = if (cardSlot.qtd == 1L) View.GONE else View.VISIBLE + } -} \ No newline at end of file +} diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/DecksFragment.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/DecksFragment.kt index 24c796a..3f27eb9 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/DecksFragment.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/DecksFragment.kt @@ -127,33 +127,29 @@ class DecksFragment : BaseFragment(), SearchView.OnQueryTextListener { eventBus.post(CmdShowDecksByClasses(classesToShow)) } -} - -class DecksPageAdapter(ctx: Context, fm: FragmentManager) : FragmentStatePagerAdapter(fm) { - - var titles: Array - val decksPublicFragment by lazy { DecksPublicFragment() } - val decksMyFragment by lazy { DecksOwnerFragment() } - val decksSavedFragment by lazy { DecksFavoritedFragment() } - - init { - titles = ctx.resources.getStringArray(R.array.decks_tabs) - } + class DecksPageAdapter(ctx: Context, fm: FragmentManager) : FragmentStatePagerAdapter(fm) { + + var titles: Array = ctx.resources.getStringArray(R.array.decks_tabs) + val decksPublicFragment by lazy { DecksPublicFragment() } + val decksMyFragment by lazy { DecksOwnerFragment() } + val decksSavedFragment by lazy { DecksFavoritedFragment() } + + override fun getItem(position: Int): BaseFragment { + return when (position) { + 1 -> decksMyFragment + 2 -> decksSavedFragment + else -> decksPublicFragment + } + } - override fun getItem(position: Int): BaseFragment { - return when (position) { - 1 -> decksMyFragment - 2 -> decksSavedFragment - else -> decksPublicFragment + override fun getCount(): Int { + return titles.size } - } - override fun getCount(): Int { - return titles.size - } + override fun getPageTitle(position: Int): CharSequence { + return titles[position] + } - override fun getPageTitle(position: Int): CharSequence { - return titles[position] } -} \ No newline at end of file +} diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/new/NewDeckCardsListFragment.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/new/NewDeckCardsListFragment.kt index f30419d..53cb4d0 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/new/NewDeckCardsListFragment.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/new/NewDeckCardsListFragment.kt @@ -4,14 +4,13 @@ import android.support.v7.widget.GridLayoutManager import android.view.View import com.ediposouza.teslesgendstracker.R import com.ediposouza.teslesgendstracker.data.Card -import com.ediposouza.teslesgendstracker.ui.cards.tabs.CardsAllAdapter import com.ediposouza.teslesgendstracker.ui.cards.tabs.CardsAllFragment import com.ediposouza.teslesgendstracker.ui.decks.CmdAddCard import com.ediposouza.teslesgendstracker.ui.utils.GridSpacingItemDecoration import kotlinx.android.synthetic.main.fragment_cards_list.* import org.greenrobot.eventbus.EventBus -class NewDeckCardsListFragment() : CardsAllFragment() { +class NewDeckCardsListFragment : CardsAllFragment() { override val ADS_EACH_ITEMS = 20 //after 10 lines override val CARDS_PER_ROW = 2 diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/tabs/DecksPublicFragment.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/tabs/DecksPublicFragment.kt index 68557cc..2291790 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/tabs/DecksPublicFragment.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/tabs/DecksPublicFragment.kt @@ -129,89 +129,89 @@ open class DecksPublicFragment : BaseFragment() { open fun getDecks(cls: Class?, last: Boolean) { publicInteractor.getPublicDecks(cls, { it.forEach { Timber.d("Public: %s", it.toString()) } - decksAdapter.showDecks(it, last) + decksAdapter.showDecks(it.sortedByDescending(Deck::updatedAt), last) }) } -} + class DecksAllAdapter(adsEachItems: Int, @LayoutRes adsLayout: Int, val itemClick: (View, Deck) -> Unit, + val itemLongClick: (View, Deck) -> Boolean) : BaseAdsAdapter(adsEachItems, adsLayout) { -class DecksAllAdapter(adsEachItems: Int, @LayoutRes adsLayout: Int, val itemClick: (View, Deck) -> Unit, - val itemLongClick: (View, Deck) -> Boolean) : BaseAdsAdapter(adsEachItems, adsLayout) { + val privateInteractor = PrivateInteractor() - val privateInteractor = PrivateInteractor() + var items: List = listOf() + var newItems: ArrayList = ArrayList() - var items: List = listOf() - var newItems: ArrayList = ArrayList() - - override fun onCreateDefaultViewHolder(parent: ViewGroup): RecyclerView.ViewHolder { - return DecksAllViewHolder(parent.inflate(R.layout.itemlist_deck), itemClick, itemLongClick) - } - - override fun onBindDefaultViewHolder(holder: RecyclerView.ViewHolder?, position: Int) { - val deck = items[position] - (holder as DecksAllViewHolder).bind(deck, privateInteractor) - } + override fun onCreateDefaultViewHolder(parent: ViewGroup): RecyclerView.ViewHolder { + return DecksAllViewHolder(parent.inflate(R.layout.itemlist_deck), itemClick, itemLongClick) + } - override fun getDefaultItemCount(): Int = items.size + override fun onBindDefaultViewHolder(holder: RecyclerView.ViewHolder?, position: Int) { + val deck = items[position] + (holder as DecksAllViewHolder).bind(deck, privateInteractor) + } - fun clearItems() { - newItems.clear() - } + override fun getDefaultItemCount(): Int = items.size - fun showDecks(decks: List, last: Boolean) { - newItems.addAll(decks) - if (!last) { - return + fun clearItems() { + newItems.clear() } - Collections.sort(newItems, { d1, d2 -> d2.updatedAt.compareTo(d1.updatedAt) }) - val oldItems = items - items = newItems - if (items.isEmpty() || items.minus(oldItems).isEmpty()) { - notifyDataSetChanged() - return + + fun showDecks(decks: List, last: Boolean) { + newItems.addAll(decks) + if (!last) { + return + } + Collections.sort(newItems, { d1, d2 -> d2.updatedAt.compareTo(d1.updatedAt) }) + val oldItems = items + items = newItems + if (items.isEmpty() || items.minus(oldItems).isEmpty()) { + notifyDataSetChanged() + return + } + DiffUtil.calculateDiff(SimpleDiffCallback(items, oldItems) { oldItem, newItem -> + oldItem.id == newItem.id + }).dispatchUpdatesTo(this) } - DiffUtil.calculateDiff(SimpleDiffCallback(items, oldItems) { oldItem, newItem -> - oldItem.id == newItem.id - }).dispatchUpdatesTo(this) - } -} - -class DecksAllViewHolder(val view: View, val itemClick: (View, Deck) -> Unit, - val itemLongClick: (View, Deck) -> Boolean) : RecyclerView.ViewHolder(view) { - - fun bind(deck: Deck, privateInteractor: PrivateInteractor) { - itemView.setOnClickListener { itemClick(itemView, deck) } - itemView.setOnLongClickListener { itemLongClick(itemView, deck) } - itemView.deck_cover.setImageResource(deck.cls.imageRes) - itemView.deck_private.layoutParams.width = if (deck.private) ViewGroup.LayoutParams.WRAP_CONTENT else 0 - itemView.deck_name.text = deck.name - itemView.deck_attr1.setImageResource(deck.cls.attr1.imageRes) - itemView.deck_attr2.setImageResource(deck.cls.attr2.imageRes) - itemView.deck_type.text = deck.type.name.toLowerCase().capitalize() - itemView.deck_date.setCompoundDrawablesWithIntrinsicBounds(if (deck.updates.isEmpty()) - R.drawable.ic_create_at else R.drawable.ic_updated_at, 0, 0, 0) - itemView.deck_date.text = deck.updatedAt.toLocalDate().toString() - val numberInstance = NumberFormat.getNumberInstance() - itemView.deck_soul_cost.text = numberInstance.format(deck.cost) - itemView.deck_comments.text = numberInstance.format(deck.comments.size) - itemView.deck_likes.text = numberInstance.format(deck.likes.size) - itemView.deck_views.text = numberInstance.format(deck.views) - calculateMissingSoul(deck, privateInteractor) } - fun calculateMissingSoul(deck: Deck, interactor: PrivateInteractor) { - with(itemView.deck_soul_missing) { - visibility = View.INVISIBLE - itemView.deck_soul_missing_loading.visibility = View.VISIBLE - interactor.getMissingCards(deck, { itemView.deck_soul_missing_loading.visibility = View.VISIBLE }) { - itemView.deck_soul_missing_loading.visibility = View.GONE - val missingSoul = it.map { it.qtd * it.rarity.soulCost }.sum() - Timber.d("Missing %d", missingSoul) - text = NumberFormat.getNumberInstance().format(missingSoul) - visibility = View.VISIBLE + class DecksAllViewHolder(val view: View, val itemClick: (View, Deck) -> Unit, + val itemLongClick: (View, Deck) -> Boolean) : RecyclerView.ViewHolder(view) { + + fun bind(deck: Deck, privateInteractor: PrivateInteractor) { + itemView.setOnClickListener { itemClick(itemView, deck) } + itemView.setOnLongClickListener { itemLongClick(itemView, deck) } + itemView.deck_cover.setImageResource(deck.cls.imageRes) + itemView.deck_private.layoutParams.width = if (deck.private) ViewGroup.LayoutParams.WRAP_CONTENT else 0 + itemView.deck_name.text = deck.name + itemView.deck_attr1.setImageResource(deck.cls.attr1.imageRes) + itemView.deck_attr2.setImageResource(deck.cls.attr2.imageRes) + itemView.deck_type.text = deck.type.name.toLowerCase().capitalize() + itemView.deck_date.setCompoundDrawablesWithIntrinsicBounds(if (deck.updates.isEmpty()) + R.drawable.ic_create_at else R.drawable.ic_updated_at, 0, 0, 0) + itemView.deck_date.text = deck.updatedAt.toLocalDate().toString() + val numberInstance = NumberFormat.getNumberInstance() + itemView.deck_soul_cost.text = numberInstance.format(deck.cost) + itemView.deck_comments.text = numberInstance.format(deck.comments.size) + itemView.deck_likes.text = numberInstance.format(deck.likes.size) + itemView.deck_views.text = numberInstance.format(deck.views) + calculateMissingSoul(deck, privateInteractor) + } + + fun calculateMissingSoul(deck: Deck, interactor: PrivateInteractor) { + with(itemView.deck_soul_missing) { + visibility = View.INVISIBLE + itemView.deck_soul_missing_loading.visibility = View.VISIBLE + interactor.getMissingCards(deck, { itemView.deck_soul_missing_loading.visibility = View.VISIBLE }) { + itemView.deck_soul_missing_loading.visibility = View.GONE + val missingSoul = it.map { it.qtd * it.rarity.soulCost }.sum() + Timber.d("Missing %d", missingSoul) + text = NumberFormat.getNumberInstance().format(missingSoul) + visibility = View.VISIBLE + } } } + } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/widget/DeckList.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/widget/DeckList.kt index c656a52..b16fde7 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/widget/DeckList.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/widget/DeckList.kt @@ -75,11 +75,9 @@ class DeckList(ctx: Context?, attrs: AttributeSet?, defStyleAttr: Int) : } } - constructor(ctx: Context?) : this(ctx, null, 0) { - } + constructor(ctx: Context?) : this(ctx, null, 0) - constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) { - } + constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) fun showDeck(deck: Deck) { doAsync { @@ -116,133 +114,133 @@ class DeckList(ctx: Context?, attrs: AttributeSet?, defStyleAttr: Int) : return deckListAdapter.getCards() } -} + class DeckListAdapter(val onAdd: (Int) -> Unit, val itemClick: (View, Card) -> Unit, + val itemLongClick: (View, Card) -> Boolean) : RecyclerView.Adapter() { -class DeckListAdapter(val onAdd: (Int) -> Unit, val itemClick: (View, Card) -> Unit, - val itemLongClick: (View, Card) -> Boolean) : RecyclerView.Adapter() { + private val items = arrayListOf() + private var missingCards: List = listOf() - private val items = arrayListOf() - private var missingCards: List = listOf() - - override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): DeckListViewHolder { - return DeckListViewHolder(parent?.inflate(R.layout.itemlist_decklist_slot), itemClick, itemLongClick) - } - - override fun onBindViewHolder(holder: DeckListViewHolder?, position: Int) { - val cardSlot = items[position] - val cardMissing = missingCards.find { it.shortName == cardSlot.card.shortName } - holder?.bind(cardSlot, cardMissing?.qtd ?: 0) - } + override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): DeckListViewHolder { + return DeckListViewHolder(parent?.inflate(R.layout.itemlist_decklist_slot), itemClick, itemLongClick) + } - override fun getItemCount(): Int = items.size + override fun onBindViewHolder(holder: DeckListViewHolder?, position: Int) { + val cardSlot = items[position] + val cardMissing = missingCards.find { it.shortName == cardSlot.card.shortName } + holder?.bind(cardSlot, cardMissing?.qtd ?: 0) + } - fun showDeck(cards: List) { - items.clear() - items.addAll(cards.sorted()) - notifyDataSetChanged() - } + override fun getItemCount(): Int = items.size - fun showMissingCards(missingCards: List) { - this.missingCards = missingCards - notifyDataSetChanged() - } + fun showDeck(cards: List) { + items.clear() + items.addAll(cards.sorted()) + notifyDataSetChanged() + } - fun addCard(card: Card) { - val cardSlot = items.find { it.card == card } - if (cardSlot == null) { - val newCardSlot = CardSlot(card, 1) - items.add(newCardSlot) - Collections.sort(items) - val newCardIndex = items.indexOf(newCardSlot) - onAdd(newCardIndex) - notifyItemInserted(newCardIndex) - } else { - val newQtd = if (cardSlot.qtd < 3) cardSlot.qtd.inc() else 3 - val cardIndex = items.indexOf(cardSlot) - items[cardIndex] = CardSlot(card, if (card.unique) 1 else newQtd) - onAdd(cardIndex) - notifyItemChanged(cardIndex) + fun showMissingCards(missingCards: List) { + this.missingCards = missingCards + notifyDataSetChanged() } - } - fun remCard(card: Card) { - val cardSlot = items.find { it.card == card } - if (cardSlot != null) { - val newQtd = cardSlot.qtd.dec() - if (newQtd <= 0) { - val cardRemovedIndex = items.indexOf(cardSlot) - items.remove(cardSlot) - notifyItemRemoved(cardRemovedIndex) - notifyCardRemoved(card) + fun addCard(card: Card) { + val cardSlot = items.find { it.card == card } + if (cardSlot == null) { + val newCardSlot = CardSlot(card, 1) + items.add(newCardSlot) + Collections.sort(items) + val newCardIndex = items.indexOf(newCardSlot) + onAdd(newCardIndex) + notifyItemInserted(newCardIndex) } else { + val newQtd = if (cardSlot.qtd < 3) cardSlot.qtd.inc() else 3 val cardIndex = items.indexOf(cardSlot) - items[cardIndex] = CardSlot(card, newQtd) + items[cardIndex] = CardSlot(card, if (card.unique) 1 else newQtd) + onAdd(cardIndex) notifyItemChanged(cardIndex) } } - } - private fun notifyCardRemoved(card: Card) { - when { - card.attr == Attribute.DUAL && items.filter { it.card.attr == card.dualAttr1 }.isEmpty() -> { - EventBus.getDefault().post(CmdRemAttr(card.dualAttr1)) - } - card.attr == Attribute.DUAL && items.filter { it.card.attr == card.dualAttr2 }.isEmpty() -> { - EventBus.getDefault().post(CmdRemAttr(card.dualAttr2)) - } - items.filter { it.card.dualAttr1 == card.attr || it.card.dualAttr2 == card.attr }.isEmpty() -> { - EventBus.getDefault().post(CmdRemAttr(card.attr)) + fun remCard(card: Card) { + val cardSlot = items.find { it.card == card } + if (cardSlot != null) { + val newQtd = cardSlot.qtd.dec() + if (newQtd <= 0) { + val cardRemovedIndex = items.indexOf(cardSlot) + items.remove(cardSlot) + notifyItemRemoved(cardRemovedIndex) + notifyCardRemoved(card) + } else { + val cardIndex = items.indexOf(cardSlot) + items[cardIndex] = CardSlot(card, newQtd) + notifyItemChanged(cardIndex) + } } } - } - fun getCards(): List { - return items - } + private fun notifyCardRemoved(card: Card) { + when { + card.attr == Attribute.DUAL && items.filter { it.card.attr == card.dualAttr1 }.isEmpty() -> { + EventBus.getDefault().post(CmdRemAttr(card.dualAttr1)) + } + card.attr == Attribute.DUAL && items.filter { it.card.attr == card.dualAttr2 }.isEmpty() -> { + EventBus.getDefault().post(CmdRemAttr(card.dualAttr2)) + } + items.filter { it.card.dualAttr1 == card.attr || it.card.dualAttr2 == card.attr }.isEmpty() -> { + EventBus.getDefault().post(CmdRemAttr(card.attr)) + } + } + } -} + fun getCards(): List { + return items + } -class DeckListViewHolder(view: View?, val itemClick: (View, Card) -> Unit, - val itemLongClick: (View, Card) -> Boolean) : RecyclerView.ViewHolder(view) { - - fun bind(slot: CardSlot, missingQtd: Long) { - itemView.setOnClickListener { itemClick.invoke(itemView.deckslot_card_image, slot.card) } - itemView.setOnLongClickListener { itemLongClick.invoke(itemView.deckslot_card_image, slot.card) } - itemView.deckslot_card_image.setImageBitmap(getCroppedCardImage(slot)) - itemView.decl_slot_card_name.text = slot.card.name - itemView.deckslot_card_rarity.setImageResource(slot.card.rarity.imageRes) - itemView.deckslot_card_magika.setImageResource(when (slot.card.cost) { - 0 -> R.drawable.ic_magika_0 - 1 -> R.drawable.ic_magika_1 - 2 -> R.drawable.ic_magika_2 - 3 -> R.drawable.ic_magika_3 - 4 -> R.drawable.ic_magika_4 - 5 -> R.drawable.ic_magika_5 - 6 -> R.drawable.ic_magika_6 - else -> R.drawable.ic_magika_7plus - }) - itemView.deckslot_card_qtd.text = slot.qtd.toString() - itemView.deckslot_card_qtd.visibility = if (slot.qtd > 0) View.VISIBLE else View.INVISIBLE - itemView.deckslot_card_qtd_layout.visibility = if (slot.qtd > 0) View.VISIBLE else View.INVISIBLE - itemView.deckslot_card_qtd_missing.text = "-$missingQtd" - itemView.deckslot_card_qtd_missing.visibility = if (missingQtd > 0) View.VISIBLE else View.INVISIBLE } - private fun getCroppedCardImage(slot: CardSlot): Bitmap { - val resources = itemView.resources - var cardBitmap: Bitmap - try { - cardBitmap = slot.card.imageBitmap(itemView.context) - } catch (e: Exception) { - cardBitmap = BitmapFactory.decodeResource(resources, R.drawable.card) + class DeckListViewHolder(view: View?, val itemClick: (View, Card) -> Unit, + val itemLongClick: (View, Card) -> Boolean) : RecyclerView.ViewHolder(view) { + + fun bind(slot: CardSlot, missingQtd: Long) { + itemView.setOnClickListener { itemClick.invoke(itemView.deckslot_card_image, slot.card) } + itemView.setOnLongClickListener { itemLongClick.invoke(itemView.deckslot_card_image, slot.card) } + itemView.deckslot_card_image.setImageBitmap(getCroppedCardImage(slot)) + itemView.decl_slot_card_name.text = slot.card.name + itemView.deckslot_card_rarity.setImageResource(slot.card.rarity.imageRes) + itemView.deckslot_card_magika.setImageResource(when (slot.card.cost) { + 0 -> R.drawable.ic_magika_0 + 1 -> R.drawable.ic_magika_1 + 2 -> R.drawable.ic_magika_2 + 3 -> R.drawable.ic_magika_3 + 4 -> R.drawable.ic_magika_4 + 5 -> R.drawable.ic_magika_5 + 6 -> R.drawable.ic_magika_6 + else -> R.drawable.ic_magika_7plus + }) + itemView.deckslot_card_qtd.text = slot.qtd.toString() + itemView.deckslot_card_qtd.visibility = if (slot.qtd > 0) View.VISIBLE else View.INVISIBLE + itemView.deckslot_card_qtd_layout.visibility = if (slot.qtd > 0) View.VISIBLE else View.INVISIBLE + itemView.deckslot_card_qtd_missing.text = "-$missingQtd" + itemView.deckslot_card_qtd_missing.visibility = if (missingQtd > 0) View.VISIBLE else View.INVISIBLE + } + + private fun getCroppedCardImage(slot: CardSlot): Bitmap { + val resources = itemView.resources + var cardBitmap: Bitmap + try { + cardBitmap = slot.card.imageBitmap(itemView.context) + } catch (e: Exception) { + cardBitmap = BitmapFactory.decodeResource(resources, R.drawable.card) + } + val bmpWidth = cardBitmap.width + val bmpHeight = cardBitmap.height + val leftCropMargin = resources.getInteger(R.integer.decklist_slot_cover_left_crop_margin) + val rightCropMargin = resources.getInteger(R.integer.decklist_slot_cover_right_crop_margin) + val cropWidth = bmpWidth - leftCropMargin - rightCropMargin + val cropeBitmap = Bitmap.createBitmap(cardBitmap, leftCropMargin, 0, cropWidth, bmpHeight * 2 / 3) + return cropeBitmap } - val bmpWidth = cardBitmap.width - val bmpHeight = cardBitmap.height - val leftCropMargin = resources.getInteger(R.integer.decklist_slot_cover_left_crop_margin) - val rightCropMargin = resources.getInteger(R.integer.decklist_slot_cover_right_crop_margin) - val cropWidth = bmpWidth - leftCropMargin - rightCropMargin - val cropeBitmap = Bitmap.createBitmap(cardBitmap, leftCropMargin, 0, cropWidth, bmpHeight * 2 / 3) - return cropeBitmap + } -} \ No newline at end of file +} diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/widget/MagikaCosts.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/widget/MagikaCosts.kt index e9d5504..efbe49c 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/widget/MagikaCosts.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/decks/widget/MagikaCosts.kt @@ -1,4 +1,4 @@ -package com.ediposouza.teslesgendstracker.ui.widget.filter +package com.ediposouza.teslesgendstracker.ui.decks.widget import android.content.Context import android.util.AttributeSet @@ -71,11 +71,9 @@ class MagikaCosts(ctx: Context?, attrs: AttributeSet?, defStyleAttr: Int) : } } - constructor(ctx: Context?) : this(ctx, null, 0) { - } + constructor(ctx: Context?) : this(ctx, null, 0) - constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) { - } + constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) fun updateCosts(cards: List) { magikaCost0Qtd = cards.filter { it.card.cost == 0 }.sumBy { it.qtd.toInt() } diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/utils/AutoHideBehaviour.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/utils/AutoHideBehaviour.kt index cd4adc2..d1110db 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/utils/AutoHideBehaviour.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/utils/AutoHideBehaviour.kt @@ -15,10 +15,9 @@ import org.greenrobot.eventbus.EventBus class AutoHideBehaviour(context: Context?, attrs: AttributeSet?) : CoordinatorLayout.Behavior(context, attrs) { - val eventBus by lazy { EventBus.getDefault() } + val eventBus: EventBus by lazy { EventBus.getDefault() } - constructor() : this(null, null) { - } + constructor() : this(null, null) override fun onStartNestedScroll(coordinatorLayout: CoordinatorLayout, child: View, directTargetChild: View, target: View, nestedScrollAxes: Int): Boolean { diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/CollectionStatistics.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/CollectionStatistics.kt index 57a2a53..14c35f8 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/CollectionStatistics.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/CollectionStatistics.kt @@ -32,11 +32,9 @@ class CollectionStatistics(ctx: Context?, attrs: AttributeSet?, defStyleAttr: In } } - constructor(ctx: Context?) : this(ctx, null, 0) { - } + constructor(ctx: Context?) : this(ctx, null, 0) - constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) { - } + constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean { return true diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/CollectionStatisticsAttr.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/CollectionStatisticsAttr.kt index 054c330..e3dc7fa 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/CollectionStatisticsAttr.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/CollectionStatisticsAttr.kt @@ -32,11 +32,9 @@ class CollectionStatisticsAttr(ctx: Context?, attrs: AttributeSet?, defStyleAttr } } - constructor(ctx: Context?) : this(ctx, null, 0) { - } + constructor(ctx: Context?) : this(ctx, null, 0) - constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) { - } + constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) fun setCommon(owned: Long, total: Long) { attr_statistics_common.text = context.getString(R.string.statistics_rarity, owned, total) diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/NestedCoordinatorLayout.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/NestedCoordinatorLayout.kt index 24829f0..18a716c 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/NestedCoordinatorLayout.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/NestedCoordinatorLayout.kt @@ -15,16 +15,12 @@ import android.view.View /** * Created by ediposouza on 1/22/16. */ -class NestedCoordinatorLayout : CoordinatorLayout, NestedScrollingParent { +class NestedCoordinatorLayout(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : + CoordinatorLayout(context, attrs, defStyleAttr), NestedScrollingParent { - constructor(context: Context) : super(context) { - } - - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { - } + constructor(context: Context) : this(context, null, 0) - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { - } + constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0) override fun onStartNestedScroll(child: View, target: View, nestedScrollAxes: Int): Boolean { parentCoordinatorLayout.onStartNestedScroll(child, target, nestedScrollAxes) diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/filter/FilterAttr.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/filter/FilterAttr.kt index c07aed9..36362e8 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/filter/FilterAttr.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/filter/FilterAttr.kt @@ -47,11 +47,9 @@ open class FilterAttr(ctx: Context?, attrs: AttributeSet?, defStyleAttr: Int) : } } - constructor(ctx: Context?) : this(ctx, null, 0) { - } + constructor(ctx: Context?) : this(ctx, null, 0) - constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) { - } + constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) open protected fun attrClick(attr: Attribute, lockable: Boolean) { filterClick?.invoke(attr) diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/filter/FilterAttrLockable.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/filter/FilterAttrLockable.kt index 247fa92..2f3a470 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/filter/FilterAttrLockable.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/filter/FilterAttrLockable.kt @@ -20,11 +20,9 @@ class FilterAttrLockable(ctx: Context?, attrs: AttributeSet?, defStyleAttr: Int) var onAttrLock: ((Attribute, Attribute) -> Unit)? = null var onAttrUnlock: (() -> Unit)? = null - constructor(ctx: Context?) : this(ctx, null, 0) { - } + constructor(ctx: Context?) : this(ctx, null, 0) - constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) { - } + constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) override fun attrClick(attr: Attribute, lockable: Boolean) { if (isLocked() && isAttrBasic(attr) && lockable) { diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/filter/FilterMagika.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/filter/FilterMagika.kt index 72e0110..8d23cce 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/filter/FilterMagika.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/filter/FilterMagika.kt @@ -40,11 +40,9 @@ class FilterMagika(ctx: Context?, attrs: AttributeSet?, defStyleAttr: Int) : } } - constructor(ctx: Context?) : this(ctx, null, 0) { - } + constructor(ctx: Context?) : this(ctx, null, 0) - constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) { - } + constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) private fun magikaClick(magika: Int) { filterClick?.invoke(magika) diff --git a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/filter/FilterRarity.kt b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/filter/FilterRarity.kt index a55a2e6..2cd33a9 100644 --- a/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/filter/FilterRarity.kt +++ b/app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/widget/filter/FilterRarity.kt @@ -44,11 +44,9 @@ class FilterRarity(ctx: Context?, attrs: AttributeSet?, defStyleAttr: Int) : } } - constructor(ctx: Context?) : this(ctx, null, 0) { - } + constructor(ctx: Context?) : this(ctx, null, 0) - constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) { - } + constructor(ctx: Context?, attrs: AttributeSet) : this(ctx, attrs, 0) private fun expand() { with(rootView) { diff --git a/app/src/main/res/drawable/xml_switch.xml b/app/src/main/res/drawable/xml_switch.xml index 11f4645..5d504f5 100644 --- a/app/src/main/res/drawable/xml_switch.xml +++ b/app/src/main/res/drawable/xml_switch.xml @@ -1,5 +1,5 @@ -> + diff --git a/app/src/main/res/layout/activity_new_deck.xml b/app/src/main/res/layout/activity_new_deck.xml index c86cc74..f91d132 100644 --- a/app/src/main/res/layout/activity_new_deck.xml +++ b/app/src/main/res/layout/activity_new_deck.xml @@ -109,7 +109,7 @@ android:text="0" android:textColor="@android:color/white" /> - diff --git a/app/src/main/res/layout/widget_collection_statistics.xml b/app/src/main/res/layout/widget_collection_statistics.xml index df188cd..3ea8969 100644 --- a/app/src/main/res/layout/widget_collection_statistics.xml +++ b/app/src/main/res/layout/widget_collection_statistics.xml @@ -14,7 +14,7 @@ android:id="@+id/collection_statistics_container" android:layout_width="match_parent" android:layout_height="match_parent" - android:scrollbarFadeDuration="0" + android:fadeScrollbars="false" android:scrollbars="vertical"> @color/primary_text_dark - +