Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manual-Download-link #17351

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import androidx.core.content.FileProvider
import androidx.fragment.app.Fragment
import com.ichi2.anki.SharedDecksActivity.Companion.DOWNLOAD_FILE
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.anki.utils.openUrl
import com.ichi2.compat.CompatHelper.Companion.getSerializableCompat
import com.ichi2.compat.CompatHelper.Companion.registerReceiverCompat
import com.ichi2.utils.ImportUtils
Expand Down Expand Up @@ -71,6 +72,7 @@ class SharedDecksDownloadFragment : Fragment(R.layout.fragment_shared_decks_down
private lateinit var downloadPercentageText: TextView
private lateinit var downloadProgressBar: ProgressBar
private lateinit var checkNetworkInfoText: TextView
private lateinit var downloadFromAnkiWeb: TextView

/**
* Android's DownloadManager - Used here to manage the functionality of downloading decks, one
Expand Down Expand Up @@ -112,12 +114,12 @@ class SharedDecksDownloadFragment : Fragment(R.layout.fragment_shared_decks_down
importDeckButton = view.findViewById(R.id.import_shared_deck_button)
tryAgainButton = view.findViewById(R.id.try_again_deck_download)
checkNetworkInfoText = view.findViewById(R.id.check_network_info_text)
downloadFromAnkiWeb = view.findViewById(R.id.download_from_ankiWeb)

val fileToBeDownloaded = arguments?.getSerializableCompat<DownloadFile>(DOWNLOAD_FILE)!!
downloadManager = (activity as SharedDecksActivity).downloadManager

downloadFile(fileToBeDownloaded)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you remove this line? That's not wrong, but I admit I'd have not expected to see changes in part of the code you didn't touch.

cancelButton.setOnClickListener {
Timber.i("Cancel download button clicked which would lead to showing of confirmation dialog")
showCancelConfirmationDialog()
Expand All @@ -128,12 +130,33 @@ class SharedDecksDownloadFragment : Fragment(R.layout.fragment_shared_decks_down
openDownloadedDeck(context)
}

downloadFromAnkiWeb.setOnClickListener {
Timber.i("'Download from AnkiWeb' clicked")
downloadManager.remove(downloadId)
openUrl(getDeckPageUri(fileToBeDownloaded.url))
parentFragmentManager.popBackStack()
}

tryAgainButton.setOnClickListener {
Timber.i("Try again button clicked, retry downloading of deck")
downloadManager.remove(downloadId)
downloadFile(fileToBeDownloaded)
cancelButton.visibility = View.VISIBLE
tryAgainButton.visibility = View.GONE
downloadFromAnkiWeb.visibility = View.GONE
}
}

private fun getDeckPageUri(orgUrl: String): Uri {
val deckIdRegex = "download-deck/(\\d+)".toRegex()
disconnect821 marked this conversation as resolved.
Show resolved Hide resolved
val matchResult = deckIdRegex.find(orgUrl)

val deckId = matchResult?.groups?.get(1)?.value

return if (deckId != null) {
Uri.parse("https://ankiweb.net/shared/info/$deckId")
} else {
Uri.parse(resources.getString(R.string.shared_decks_url))
}
}

Expand Down Expand Up @@ -474,6 +497,7 @@ class SharedDecksDownloadFragment : Fragment(R.layout.fragment_shared_decks_down
context?.let { showThemedToast(it, R.string.something_wrong, false) }
// Update UI if download could not be successful
tryAgainButton.visibility = View.VISIBLE
downloadFromAnkiWeb.visibility = View.VISIBLE
disconnect821 marked this conversation as resolved.
Show resolved Hide resolved
cancelButton.visibility = View.GONE
downloadPercentageText.text = getString(R.string.download_failed)
downloadProgressBar.progress = DOWNLOAD_STARTED_PROGRESS_PERCENTAGE.toInt()
Expand Down
17 changes: 17 additions & 0 deletions AnkiDroid/src/main/res/layout/fragment_shared_decks_download.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@
app:layout_constraintTop_toBottomOf="@id/download_progress"
android:visibility="gone" />

<android.widget.Button
android:id="@+id/download_from_ankiWeb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/download_deck_from_AnkiWeb"
android:background="@color/material_blue_500"
android:textColor="@color/white"
android:padding="8dp"
android:layout_marginBottom="24dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/try_again_deck_download"
android:visibility="gone"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't see on the gif, but I'd expect this to either be a material 'text button', or be underline so a user knows it's a link

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot_20241111_171505_AnkiDroid

Updated the button to use the Material text button.

/>

<android.widget.Button
android:id="@+id/cancel_shared_decks_download"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions AnkiDroid/src/main/res/values/02-strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
<string name="percentage">%s%%</string>

<string name="download_deck">Download deck</string>
<string name="download_deck_from_AnkiWeb">Download deck from AnkiWeb</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not fan of this phrasing to be honest. I can't imagine that the average user would know what ankiweb is. And even if they knew, how does it differ from what they did? After all, we were already on ankiweb website

<string name="try_again">Try Again</string>
<string name="cancel_download">Cancel download</string>
<string name="cancel_download_question_title">Cancel download?</string>
Expand Down