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 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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 @@ -34,6 +34,7 @@ import android.webkit.URLUtil
import android.widget.Button
import android.widget.ProgressBar
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
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,6 +114,8 @@ 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)
// Added the downloadFromAnkiWeb button (Text)
downloadFromAnkiWeb = view.findViewById(R.id.download_from_ankiWeb)

val fileToBeDownloaded = arguments?.getSerializableCompat<DownloadFile>(DOWNLOAD_FILE)!!
downloadManager = (activity as SharedDecksActivity).downloadManager
Expand All @@ -128,6 +132,20 @@ class SharedDecksDownloadFragment : Fragment(R.layout.fragment_shared_decks_down
openDownloadedDeck(context)
}

// Added the click listener for downloadfromAnkiWeb button
disconnect821 marked this conversation as resolved.
Show resolved Hide resolved
downloadFromAnkiWeb.setOnClickListener {
Timber.i("Download from AnkiWeb clicked which would lead to AnkiWeb site to download deck manually")
disconnect821 marked this conversation as resolved.
Show resolved Hide resolved
downloadManager.remove(downloadId)
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(fileToBeDownloaded.url))
disconnect821 marked this conversation as resolved.
Show resolved Hide resolved
disconnect821 marked this conversation as resolved.
Show resolved Hide resolved
try {
startActivity(browserIntent)
parentFragmentManager.popBackStack()
disconnect821 marked this conversation as resolved.
Show resolved Hide resolved
} catch (e: ActivityNotFoundException) {
Timber.i(e, "No Browser is selected")
disconnect821 marked this conversation as resolved.
Show resolved Hide resolved
Toast.makeText(requireContext(), "Can't Open file", Toast.LENGTH_SHORT).show()
disconnect821 marked this conversation as resolved.
Show resolved Hide resolved
}
}

tryAgainButton.setOnClickListener {
Timber.i("Try again button clicked, retry downloading of deck")
downloadManager.remove(downloadId)
Expand Down Expand Up @@ -474,6 +492,8 @@ 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
// Making downloadFromAnkiWeb button visible
disconnect821 marked this conversation as resolved.
Show resolved Hide resolved
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
16 changes: 16 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,22 @@
app:layout_constraintTop_toBottomOf="@id/download_progress"
android:visibility="gone" />

<com.ichi2.ui.FixedTextView
android:id="@+id/download_from_ankiWeb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:gravity="center"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:text="@string/download_deck_from_AnkiWeb"
android:textSize="15sp"
app:layout_constraintBottom_toTopOf="@id/try_again_deck_download"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/download_progress"
app:layout_constraintVertical_bias="0.958" />
Copy link
Member

Choose a reason for hiding this comment

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

Probably not what you want. Can you represent this another way?

Copy link
Author

Choose a reason for hiding this comment

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

Replaced TextView with Button and updated constraints accordingly.

Screenshot_20241105_181729_AnkiDroid


<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
Loading