|
|
|
@ -9,12 +9,15 @@ import androidx.core.app.ActivityOptionsCompat |
|
|
|
import androidx.core.view.isVisible |
|
|
|
import androidx.core.view.isVisible |
|
|
|
import androidx.interpolator.view.animation.FastOutSlowInInterpolator |
|
|
|
import androidx.interpolator.view.animation.FastOutSlowInInterpolator |
|
|
|
import com.android.billingclient.api.Purchase |
|
|
|
import com.android.billingclient.api.Purchase |
|
|
|
|
|
|
|
import com.google.android.material.badge.BadgeDrawable |
|
|
|
|
|
|
|
import com.google.android.material.badge.BadgeUtils |
|
|
|
import com.google.android.material.tabs.TabLayout |
|
|
|
import com.google.android.material.tabs.TabLayout |
|
|
|
import io.realm.RealmModel |
|
|
|
import io.realm.RealmModel |
|
|
|
import io.realm.RealmResults |
|
|
|
import io.realm.RealmResults |
|
|
|
import io.realm.Sort |
|
|
|
import io.realm.Sort |
|
|
|
import io.realm.kotlin.where |
|
|
|
import io.realm.kotlin.where |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
|
|
|
import net.pokeranalytics.android.api.BlogPostApi |
|
|
|
import net.pokeranalytics.android.databinding.FragmentFeedBinding |
|
|
|
import net.pokeranalytics.android.databinding.FragmentFeedBinding |
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
@ -25,6 +28,7 @@ import net.pokeranalytics.android.model.realm.handhistory.HandHistory |
|
|
|
import net.pokeranalytics.android.ui.activity.BillingActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.BillingActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.components.RequestCode |
|
|
|
import net.pokeranalytics.android.ui.activity.components.RequestCode |
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.extensions.openUrl |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.FilterableFragment |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.FilterableFragment |
|
|
|
import net.pokeranalytics.android.ui.modules.data.EditableDataActivity |
|
|
|
import net.pokeranalytics.android.ui.modules.data.EditableDataActivity |
|
|
|
import net.pokeranalytics.android.ui.modules.datalist.DataListActivity |
|
|
|
import net.pokeranalytics.android.ui.modules.datalist.DataListActivity |
|
|
|
@ -36,6 +40,7 @@ import net.pokeranalytics.android.ui.modules.session.SessionActivity |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager |
|
|
|
import net.pokeranalytics.android.ui.view.SmoothScrollLinearLayoutManager |
|
|
|
import net.pokeranalytics.android.util.Preferences |
|
|
|
import net.pokeranalytics.android.util.Preferences |
|
|
|
|
|
|
|
import net.pokeranalytics.android.util.URL |
|
|
|
import net.pokeranalytics.android.util.billing.AppGuard |
|
|
|
import net.pokeranalytics.android.util.billing.AppGuard |
|
|
|
import net.pokeranalytics.android.util.billing.PurchaseListener |
|
|
|
import net.pokeranalytics.android.util.billing.PurchaseListener |
|
|
|
import net.pokeranalytics.android.util.extensions.count |
|
|
|
import net.pokeranalytics.android.util.extensions.count |
|
|
|
@ -77,6 +82,8 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate, PurchaseLis |
|
|
|
private var selectedTransaction: Transaction? = null |
|
|
|
private var selectedTransaction: Transaction? = null |
|
|
|
private var selectedTransactionPosition: Int = -1 |
|
|
|
private var selectedTransactionPosition: Int = -1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var badgeDrawable: BadgeDrawable? = null |
|
|
|
|
|
|
|
|
|
|
|
override val observedEntities: List<Class<out RealmModel>> = |
|
|
|
override val observedEntities: List<Class<out RealmModel>> = |
|
|
|
listOf(Session::class.java, Transaction::class.java, HandHistory::class.java) |
|
|
|
listOf(Session::class.java, Transaction::class.java, HandHistory::class.java) |
|
|
|
|
|
|
|
|
|
|
|
@ -121,7 +128,6 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate, PurchaseLis |
|
|
|
if (v.id == R.id.menuRecyclerView) { |
|
|
|
if (v.id == R.id.menuRecyclerView) { |
|
|
|
activity?.menuInflater?.inflate(R.menu.menu_session, menu) |
|
|
|
activity?.menuInflater?.inflate(R.menu.menu_session, menu) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onRowLongClick(itemView: View, row: RowRepresentable, position: Int) { |
|
|
|
override fun onRowLongClick(itemView: View, row: RowRepresentable, position: Int) { |
|
|
|
@ -184,10 +190,6 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate, PurchaseLis |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onDestroy() { |
|
|
|
|
|
|
|
super.onDestroy() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onDestroyView() { |
|
|
|
override fun onDestroyView() { |
|
|
|
super.onDestroyView() |
|
|
|
super.onDestroyView() |
|
|
|
AppGuard.unregisterListener(this) |
|
|
|
AppGuard.unregisterListener(this) |
|
|
|
@ -268,6 +270,27 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate, PurchaseLis |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.view?.viewTreeObserver?.addOnGlobalLayoutListener { |
|
|
|
|
|
|
|
Timber.d(">>> addOnGlobalLayoutListener called") |
|
|
|
|
|
|
|
retrieveLatestBlogPosts() // attempt to retrieve blog tips on display |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
displayPostButton() |
|
|
|
|
|
|
|
binding.postButton.setOnClickListener { |
|
|
|
|
|
|
|
Preferences.setBlogTipsTapped(requireContext()) |
|
|
|
|
|
|
|
parentActivity?.openUrl(URL.BLOG_TIPS.value) |
|
|
|
|
|
|
|
displayPostButton() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.postButton.viewTreeObserver.addOnGlobalLayoutListener { |
|
|
|
|
|
|
|
val badgeDrawable = BadgeDrawable.create(requireContext()) |
|
|
|
|
|
|
|
BadgeUtils.attachBadgeDrawable(badgeDrawable, binding.postButton) |
|
|
|
|
|
|
|
// badgeDrawable.number = 2 |
|
|
|
|
|
|
|
badgeDrawable.horizontalOffset = 30 |
|
|
|
|
|
|
|
badgeDrawable.verticalOffset = 20 |
|
|
|
|
|
|
|
this.badgeDrawable = badgeDrawable |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Tabs |
|
|
|
// Tabs |
|
|
|
binding.tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { |
|
|
|
binding.tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { |
|
|
|
override fun onTabSelected(tab: TabLayout.Tab) { |
|
|
|
override fun onTabSelected(tab: TabLayout.Tab) { |
|
|
|
@ -379,9 +402,9 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate, PurchaseLis |
|
|
|
handHistoryFilter?.results() ?: run { getRealm().where<HandHistory>().findAll() } |
|
|
|
handHistoryFilter?.results() ?: run { getRealm().where<HandHistory>().findAll() } |
|
|
|
this.realmHandHistories = this.realmHandHistories.sort("date", Sort.DESCENDING) |
|
|
|
this.realmHandHistories = this.realmHandHistories.sort("date", Sort.DESCENDING) |
|
|
|
|
|
|
|
|
|
|
|
this.realmHandHistories.forEach { |
|
|
|
// this.realmHandHistories.forEach { |
|
|
|
Timber.d("date = ${it.date}, year=${it.year}, month = ${it.month}, day = ${it.dayOfMonth}") |
|
|
|
// Timber.d("date = ${it.date}, year=${it.year}, month = ${it.month}, day = ${it.dayOfMonth}") |
|
|
|
} |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
var hhDistinctDates = handHistoryFilter?.results("year", "month", "dayOfMonth") |
|
|
|
var hhDistinctDates = handHistoryFilter?.results("year", "month", "dayOfMonth") |
|
|
|
?: getRealm().where<HandHistory>().distinct("year", "month", "dayOfMonth").findAll() |
|
|
|
?: getRealm().where<HandHistory>().distinct("year", "month", "dayOfMonth").findAll() |
|
|
|
@ -557,4 +580,37 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate, PurchaseLis |
|
|
|
this.showSubscriptionButton() |
|
|
|
this.showSubscriptionButton() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun retrieveLatestBlogPosts() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val now = Date().time |
|
|
|
|
|
|
|
if (true) { |
|
|
|
|
|
|
|
// if (Preferences.getLastBlogTipsRetrievalDate(requireContext()) + 24 * 3600 * 1000 < now) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BlogPostApi.getLatestPosts(requireContext()) { posts -> |
|
|
|
|
|
|
|
Preferences.setLastBlogTipsRetrievalDate(now, requireContext()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var count = 0 |
|
|
|
|
|
|
|
if (posts.isNotEmpty()) { |
|
|
|
|
|
|
|
Preferences.setLatestRetrievedBlogPostId(posts.first().id, requireContext()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val id = Preferences.getLatestDisplayedBlogPostId(requireContext()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
count = posts.count { it.id > id } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
displayPostButton(count) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun displayPostButton(newCount: Int = 0) { |
|
|
|
|
|
|
|
var show = false |
|
|
|
|
|
|
|
if (Preferences.shouldShowBlogTips(requireContext()) && newCount > 0) { |
|
|
|
|
|
|
|
show = true |
|
|
|
|
|
|
|
this.badgeDrawable?.number = newCount |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.binding.postButton.isVisible = show |
|
|
|
|
|
|
|
this.badgeDrawable?.isVisible = show |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |