|
|
|
|
@ -11,11 +11,25 @@ import net.pokeranalytics.android.BuildConfig |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.calculus.NewPerformanceListener |
|
|
|
|
import net.pokeranalytics.android.databinding.ActivityHomeBinding |
|
|
|
|
import net.pokeranalytics.android.model.filter.Query |
|
|
|
|
import net.pokeranalytics.android.model.filter.QueryCondition |
|
|
|
|
import net.pokeranalytics.android.model.realm.Currency |
|
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
|
import net.pokeranalytics.android.ui.activity.components.BaseActivity |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.HomePagerAdapter |
|
|
|
|
import net.pokeranalytics.android.util.Preferences |
|
|
|
|
import net.pokeranalytics.android.util.billing.AppGuard |
|
|
|
|
|
|
|
|
|
import net.pokeranalytics.android.util.extensions.findAll |
|
|
|
|
import net.pokeranalytics.android.util.extensions.isSameMonth |
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
enum class Tab(var identifier: Int) { |
|
|
|
|
HISTORY(0), |
|
|
|
|
STATS(1), |
|
|
|
|
CALENDAR(2), |
|
|
|
|
REPORTS(3), |
|
|
|
|
SETTINGS(4) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class HomeActivity : BaseActivity(), NewPerformanceListener { |
|
|
|
|
|
|
|
|
|
@ -31,21 +45,26 @@ class HomeActivity : BaseActivity(), NewPerformanceListener { |
|
|
|
|
private var homePagerAdapter: HomePagerAdapter? = null |
|
|
|
|
|
|
|
|
|
private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item -> |
|
|
|
|
|
|
|
|
|
if (binding.viewPager.currentItem == Tab.REPORTS.identifier) { |
|
|
|
|
this.paApplication.reportWhistleBlower?.clearNotifications() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
when (item.itemId) { |
|
|
|
|
R.id.navigation_history -> { |
|
|
|
|
displayFragment(0) |
|
|
|
|
displayFragment(Tab.HISTORY) |
|
|
|
|
} |
|
|
|
|
R.id.navigation_stats -> { |
|
|
|
|
displayFragment(1) |
|
|
|
|
displayFragment(Tab.STATS) |
|
|
|
|
} |
|
|
|
|
R.id.navigation_calendar -> { |
|
|
|
|
displayFragment(2) |
|
|
|
|
displayFragment(Tab.CALENDAR) |
|
|
|
|
} |
|
|
|
|
R.id.navigation_reports -> { |
|
|
|
|
displayFragment(3) |
|
|
|
|
displayFragment(Tab.REPORTS) |
|
|
|
|
} |
|
|
|
|
R.id.navigation_settings -> { |
|
|
|
|
displayFragment(4) |
|
|
|
|
displayFragment(Tab.SETTINGS) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
binding.navigation.getOrCreateBadge(item.itemId).isVisible = false |
|
|
|
|
@ -56,6 +75,7 @@ class HomeActivity : BaseActivity(), NewPerformanceListener { |
|
|
|
|
super.onResume() |
|
|
|
|
AppGuard.requestPurchasesUpdate() |
|
|
|
|
this.homePagerAdapter?.activityResumed() |
|
|
|
|
lookForCalendarBadge() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private lateinit var binding: ActivityHomeBinding |
|
|
|
|
@ -132,13 +152,52 @@ class HomeActivity : BaseActivity(), NewPerformanceListener { |
|
|
|
|
/** |
|
|
|
|
* Display a new fragment |
|
|
|
|
*/ |
|
|
|
|
private fun displayFragment(index: Int) { |
|
|
|
|
binding.viewPager.setCurrentItem(index, false) |
|
|
|
|
private fun displayFragment(tab: Tab) { |
|
|
|
|
binding.viewPager.setCurrentItem(tab.identifier, false) |
|
|
|
|
this.homePagerAdapter?.tabSelected(tab) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun newBestPerformanceHandler() { |
|
|
|
|
binding.navigation.getOrCreateBadge(R.id.navigation_reports).isVisible = true |
|
|
|
|
binding.navigation.getOrCreateBadge(R.id.navigation_reports).number = 1 |
|
|
|
|
|
|
|
|
|
if (Preferences.showInAppBadges(this)) { |
|
|
|
|
binding.navigation.getOrCreateBadge(R.id.navigation_reports).isVisible = true |
|
|
|
|
binding.navigation.getOrCreateBadge(R.id.navigation_reports).number = 1 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun lookForCalendarBadge() { |
|
|
|
|
|
|
|
|
|
if (!Preferences.showInAppBadges(this)) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val date = Preferences.lastCalendarBadgeDate(this) |
|
|
|
|
|
|
|
|
|
val cal = Calendar.getInstance() |
|
|
|
|
val lastCheck = Calendar.getInstance().apply { timeInMillis = date } |
|
|
|
|
|
|
|
|
|
if (!cal.isSameMonth(lastCheck)) { |
|
|
|
|
lookForSessionsLastMonth() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun lookForSessionsLastMonth() { |
|
|
|
|
|
|
|
|
|
val cal = Calendar.getInstance() |
|
|
|
|
cal.add(Calendar.MONTH, -1) |
|
|
|
|
|
|
|
|
|
val month = QueryCondition.AnyMonthOfYear(cal.get(Calendar.MONTH)) |
|
|
|
|
val year = QueryCondition.AnyYear(cal.get(Calendar.YEAR)) |
|
|
|
|
val query = Query(month, year) |
|
|
|
|
|
|
|
|
|
val sessions = getRealm().findAll<Session>(query) |
|
|
|
|
if (sessions.isNotEmpty()) { |
|
|
|
|
binding.navigation.getOrCreateBadge(R.id.navigation_calendar).isVisible = true |
|
|
|
|
binding.navigation.getOrCreateBadge(R.id.navigation_calendar).number = 1 |
|
|
|
|
Preferences.setLastCalendarBadgeDate(this, Date().time) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|