-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow deck selection in statistics screen
A Spinner was introduced in the statistics screen which can be used by the user to change the current selected deck and also trigger a reload of the statistics UI.
- Loading branch information
1 parent
5c8919f
commit d8106cb
Showing
7 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
AnkiDroid/src/main/java/com/ichi2/anki/StatisticsActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright (c) 2024 Ashish Yadav <mailtoashish693@gmail.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License as published by the Free Software | ||
* Foundation; either version 3 of the License, or (at your option) any later | ||
* version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
* PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.ichi2.anki | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.commit | ||
import com.ichi2.anki.dialogs.DeckSelectionDialog | ||
import com.ichi2.anki.pages.Statistics | ||
import com.ichi2.libanki.Collection | ||
|
||
/** | ||
* Shows the statistics for the current selected deck and offers the possibility of changing the deck. | ||
* | ||
* Note: uses `configChanges="orientation|screenSize"` to avoid activity recreations as it doesn't | ||
* play well with the embedded WebView. | ||
* | ||
* @see Statistics | ||
*/ | ||
class StatisticsActivity : | ||
AnkiActivity(), | ||
DeckSelectionDialog.DeckSelectionListener { | ||
|
||
private lateinit var deckSpinnerSelection: DeckSpinnerSelection | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
if (showedActivityFailedScreen(savedInstanceState)) { | ||
return | ||
} | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_statistics) | ||
if (savedInstanceState == null) { | ||
supportFragmentManager.commit { | ||
replace( | ||
R.id.fragment_container, | ||
Statistics.newInstance(path = "graphs", title = getString(R.string.statistics)), | ||
STATS_FRAGMENT_TAG | ||
) | ||
} | ||
} | ||
startLoadingCollection() | ||
} | ||
|
||
override fun onCollectionLoaded(col: Collection) { | ||
super.onCollectionLoaded(col) | ||
deckSpinnerSelection = DeckSpinnerSelection( | ||
this, | ||
findViewById(R.id.deck_selector), | ||
showAllDecks = false, | ||
alwaysShowDefault = false, | ||
showFilteredDecks = false | ||
) | ||
deckSpinnerSelection.initializeStatsBarDeckSpinner(col) | ||
launchCatchingTask { | ||
deckSpinnerSelection.selectDeckById(col.decks.selected(), true) | ||
} | ||
} | ||
|
||
override fun onDeckSelected(deck: DeckSelectionDialog.SelectableDeck?) { | ||
if (deck == null) return | ||
(supportFragmentManager.findFragmentByTag(STATS_FRAGMENT_TAG) as? Statistics)?.webView?.reload() | ||
launchCatchingTask { | ||
deckSpinnerSelection.selectDeckById(deck.deckId, true) | ||
} | ||
} | ||
|
||
companion object { | ||
private const val STATS_FRAGMENT_TAG = "stats_fragment_tag" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".StatisticsActivity"> | ||
|
||
<FrameLayout | ||
android:id="@+id/deck_selector_layout" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:minHeight="?attr/listPreferredItemHeightSmall" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
android:paddingHorizontal="8dp" | ||
android:background="?attr/currentDeckBackground" | ||
android:paddingTop="8dp" | ||
app:layout_constraintStart_toStartOf="parent"> | ||
|
||
<Spinner | ||
android:id="@+id/deck_selector" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"/> | ||
</FrameLayout> | ||
|
||
<androidx.fragment.app.FragmentContainerView | ||
android:id="@+id/fragment_container" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
app:layout_constraintBottom_toTopOf="@id/deck_selector_layout" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters