diff --git a/app/build.gradle b/app/build.gradle index 6e5042c..c9768a3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -53,6 +53,9 @@ // AndroidDesignSupportLibrary implementation "com.android.support:design:26.1.0" + // CardView + implementation "com.android.support:cardview-v7:26.1.0" + // Android Architecture Components for Lifecycles, LiveData, and ViewModel implementation "android.arch.lifecycle:runtime:1.0.3" implementation "android.arch.lifecycle:extensions:1.0.0-rc1" diff --git a/app/src/main/kotlin/jackall/moncalc/db/QuestRecordRealmHelper.kt b/app/src/main/kotlin/jackall/moncalc/db/QuestRecordRealmHelper.kt index 78ba960..e24377d 100644 --- a/app/src/main/kotlin/jackall/moncalc/db/QuestRecordRealmHelper.kt +++ b/app/src/main/kotlin/jackall/moncalc/db/QuestRecordRealmHelper.kt @@ -2,6 +2,7 @@ import io.realm.RealmResults import jackall.moncalc.vo.QuestRecord +import java.util.* /** * Created by matsumoto_k on 2017/11/03. @@ -71,10 +72,56 @@ } fun getAllSpecialPercent(): Float { - return (realm.where(QuestRecord::class.java).sum("specialCount").toFloat() / realm.where(QuestRecord::class.java).sum("dropCount").toFloat()) * 100 + return (realm.where(QuestRecord::class.java).sum("specialCount").toFloat() / realm.where(QuestRecord::class.java).findAll().count()) * 100 } fun getSpecialPercent(templeId: Int): Float { return (realm.where(QuestRecord::class.java).equalTo("templeId", templeId).sum("specialCount").toFloat() / realm.where(QuestRecord::class.java).equalTo("templeId", templeId).sum("dropCount").toFloat()) * 100 } + + fun getTodayCount(): Int { + val yesterday = Calendar.getInstance().apply { add(Calendar.DATE, -1) } + return realm.where(QuestRecord::class.java).greaterThan("createAt", yesterday.time).findAll().count() + } + + fun getTodaySpecialCount(): Int { + val yesterday = Calendar.getInstance().apply { add(Calendar.DATE, -1) } + val results = realm.where(QuestRecord::class.java).greaterThan("createAt", yesterday.time).lessThan("drops.gradeId", 3).findAll() + var count = 0 + results.forEach { + it.drops.forEach { + if (it.gradeId < 3) + count++ + } + } + return count + } + + fun getTodayDropCount(): Int { + val weekAgo = Calendar.getInstance().apply { add(Calendar.DATE, -1) } + return realm.where(QuestRecord::class.java).greaterThan("createAt", weekAgo.time).sum("dropCount").toInt() + } + + fun getWeekCount(): Int { + val weekAgo = Calendar.getInstance().apply { add(Calendar.DATE, -7) } + return realm.where(QuestRecord::class.java).greaterThan("createAt", weekAgo.time).findAll().count() + } + + fun getWeekSpecialCount(): Int { + val weekAgo = Calendar.getInstance().apply { add(Calendar.DATE, -7) } + val results = realm.where(QuestRecord::class.java).greaterThan("createAt", weekAgo.time).lessThan("drops.gradeId", 3).findAll() + var count = 0 + results.forEach { + it.drops.forEach { + if (it.gradeId < 3) + count++ + } + } + return count + } + + fun getWeekDropCount(): Int { + val yesterday = Calendar.getInstance().apply { add(Calendar.DATE, -7) } + return realm.where(QuestRecord::class.java).greaterThan("createAt", yesterday.time).sum("dropCount").toInt() + } } \ No newline at end of file diff --git a/app/src/main/kotlin/jackall/moncalc/fragment/HistoryFragment.kt b/app/src/main/kotlin/jackall/moncalc/fragment/HistoryFragment.kt index 391e4b7..ad815e7 100644 --- a/app/src/main/kotlin/jackall/moncalc/fragment/HistoryFragment.kt +++ b/app/src/main/kotlin/jackall/moncalc/fragment/HistoryFragment.kt @@ -4,22 +4,19 @@ import android.databinding.DataBindingUtil import android.os.Bundle import android.support.v4.app.Fragment -import android.support.v7.widget.DefaultItemAnimator -import android.support.v7.widget.LinearLayoutManager import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import jackall.moncalc.R import jackall.moncalc.adapter.HistoryRecyclerAdapter import jackall.moncalc.databinding.FragmentHistoryBinding -import kotlinx.android.synthetic.main.fragment_history.view.* /** * Created by matsumoto_k on 2017/11/03. */ class HistoryFragment : Fragment() { lateinit var binding: FragmentHistoryBinding - val historyViewModel by lazy { ViewModelProviders.of(this, jackall.moncalc.viewmodel.HistoryViewModel.Factory(adapter)).get(jackall.moncalc.viewmodel.HistoryViewModel::class.java) } + val historyViewModel by lazy { ViewModelProviders.of(this, jackall.moncalc.viewmodel.HistoryViewModel.Factory()).get(jackall.moncalc.viewmodel.HistoryViewModel::class.java) } val adapter by lazy { HistoryRecyclerAdapter(activity) } override fun onCreate(savedInstanceState: Bundle?) { @@ -31,10 +28,10 @@ binding.historyViewModel = historyViewModel lifecycle.addObserver(historyViewModel) - binding.root.history_recycler_view.setHasFixedSize(true) - binding.root.history_recycler_view.layoutManager = LinearLayoutManager(activity) - (binding.root.history_recycler_view.itemAnimator as DefaultItemAnimator).supportsChangeAnimations = false - binding.root.history_recycler_view.adapter = adapter +// binding.root.history_recycler_view.setHasFixedSize(true) +// binding.root.history_recycler_view.layoutManager = LinearLayoutManager(activity) +// (binding.root.history_recycler_view.itemAnimator as DefaultItemAnimator).supportsChangeAnimations = false +// binding.root.history_recycler_view.adapter = adapter return binding.root } diff --git a/app/src/main/kotlin/jackall/moncalc/viewmodel/HistoryViewModel.kt b/app/src/main/kotlin/jackall/moncalc/viewmodel/HistoryViewModel.kt index a815e07..b23edf5 100644 --- a/app/src/main/kotlin/jackall/moncalc/viewmodel/HistoryViewModel.kt +++ b/app/src/main/kotlin/jackall/moncalc/viewmodel/HistoryViewModel.kt @@ -2,32 +2,43 @@ import android.arch.lifecycle.ViewModel import android.arch.lifecycle.ViewModelProvider -import android.databinding.ObservableBoolean -import jackall.moncalc.adapter.HistoryRecyclerAdapter +import android.databinding.ObservableField import jackall.moncalc.db.MonstDataRealmHelper import jackall.moncalc.db.QuestRecordRealmHelper -import jackall.moncalc.vo.Fruit -import jackall.moncalc.vo.Grade -import jackall.moncalc.vo.HistoryItem -import jackall.moncalc.vo.Temple /** * Created by matsumoto_k on 2017/11/03. */ -class HistoryViewModel(val adapter: HistoryRecyclerAdapter) : LifecycleViewModel() { +class HistoryViewModel() : LifecycleViewModel() { val questRealmHelper = QuestRecordRealmHelper() val monstDataRealmHelper = MonstDataRealmHelper() - val refreshLayoutLoading = ObservableBoolean(true) - val hisotoryItems = ArrayList() + val todayTempleCount = ObservableField() + val todayDrop = ObservableField() + val todaySpecialDrop = ObservableField() + val todaySpecialPercent = ObservableField() + val weekTempleCount = ObservableField() + val weekDrop = ObservableField() + val weekSpecialDrop = ObservableField() + val weekSpecialPercent = ObservableField() +// val refreshLayoutLoading = ObservableBoolean(true) +// val hisotoryItems = ArrayList() init { - onRefresh() + todayTempleCount.set(questRealmHelper.getTodayCount().toString()) + todayDrop.set(questRealmHelper.getTodayDropCount().toString()) + todaySpecialDrop.set(questRealmHelper.getTodaySpecialCount().toString()) + todaySpecialPercent.set("${String.format("%.1f", (questRealmHelper.getTodaySpecialCount().toFloat() / questRealmHelper.getTodayCount().toFloat()) * 100)}%") + weekTempleCount.set(questRealmHelper.getWeekCount().toString()) + weekDrop.set(questRealmHelper.getWeekDropCount().toString()) + weekSpecialDrop.set(questRealmHelper.getWeekSpecialCount().toString()) + weekSpecialPercent.set("${String.format("%.1f", (questRealmHelper.getWeekSpecialCount().toFloat() / questRealmHelper.getWeekCount().toFloat()) * 100)}%") +// onRefresh() } - fun onRefresh() { - refreshLayoutLoading.set(true) - hisotoryItems.clear() +// fun onRefresh() { +// refreshLayoutLoading.set(true) +// hisotoryItems.clear() // questRealmHelper.findAll().sortedByDescending { it.createAt }.forEach { // hisotoryItems.add( // HistoryItem(templeName = monstDataRealmHelper.findNameById(Temple::class.java, it.templeId), @@ -36,9 +47,9 @@ // createAt = it.createAt) // ) // } - adapter.setItemAndRefresh(hisotoryItems) - refreshLayoutLoading.set(false) - } +// adapter.setItemAndRefresh(hisotoryItems) +// refreshLayoutLoading.set(false) +// } override fun onDestroy() { super.onDestroy() @@ -46,9 +57,9 @@ questRealmHelper.close() } - class Factory(val adapter: HistoryRecyclerAdapter) : ViewModelProvider.NewInstanceFactory() { + class Factory() : ViewModelProvider.NewInstanceFactory() { override fun create(modelClass: Class): T { - return jackall.moncalc.viewmodel.HistoryViewModel(adapter) as T + return jackall.moncalc.viewmodel.HistoryViewModel() as T } } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_history.xml b/app/src/main/res/layout/fragment_history.xml index e962ba4..194f3d8 100644 --- a/app/src/main/res/layout/fragment_history.xml +++ b/app/src/main/res/layout/fragment_history.xml @@ -11,18 +11,288 @@ + android:layout_height="match_parent" + android:background="#ffffff"> - + android:layout_height="wrap_content" + android:layout_marginEnd="8dp" + android:layout_marginStart="8dp" + android:layout_marginTop="8dp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> - - + android:layout_height="match_parent"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 77572a0..f9de342 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -4,4 +4,7 @@ 72dp 48dp 48dp + 12dp + 12dp + 24dp \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 92ee9ca..d292f7f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -9,4 +9,10 @@ 履歴 神殿解析 わくわく解析 + 過去24時間の詳細データ + 今日 + 今週 + 今月 + わくわくの実 + 神殿