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

Add go to downloads button in home if there is no connection #1438

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -45,6 +45,7 @@ import com.lagradost.cloudstream3.ui.settings.Globals.TV
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
import com.lagradost.cloudstream3.utils.AppContextUtils.filterProviderByPreferredMedia
import com.lagradost.cloudstream3.utils.AppContextUtils.getApiProviderLangSettings
import com.lagradost.cloudstream3.utils.AppContextUtils.isNetworkAvailable
import com.lagradost.cloudstream3.utils.AppContextUtils.isRecyclerScrollable
import com.lagradost.cloudstream3.utils.AppContextUtils.loadSearchResult
import com.lagradost.cloudstream3.utils.AppContextUtils.ownHide
Expand All @@ -56,6 +57,7 @@ import com.lagradost.cloudstream3.utils.Event
import com.lagradost.cloudstream3.utils.SubtitleHelper.getFlagFromIso
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
import com.lagradost.cloudstream3.utils.UIHelper.getSpanCount
import com.lagradost.cloudstream3.utils.UIHelper.navigate
import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIconsAndNoStringRes
import java.util.*

Expand Down Expand Up @@ -590,7 +592,16 @@ class HomeFragment : Fragment() {

is Resource.Failure -> {
homeLoadingShimmer.stopShimmer()
resultErrorText.text = data.errorString
var errorString = data.errorString
if (context?.isNetworkAvailable() == false) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just use isNetworkError or extend the Resource.Failure and check the exception type of the error. This is because isNetworkAvailable is not always correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That actually seems to be more inaccurate though. IE if DNS fails but you actually have connection it is the same error as it is a network error, whereas what I currently use does it only if device has no service.

errorString = getString(R.string.no_internet_connection)
homeReloadConnectionOpenInBrowser.isVisible = false
homeReloadConnectionGoToDownloads.isVisible = true
homeReloadConnectionGoToDownloads.setOnClickListener {
activity.navigate(R.id.navigation_downloads)
}
}
resultErrorText.text = errorString
homeReloadConnectionerror.setOnClickListener(apiChangeClickListener)
homeReloadConnectionOpenInBrowser.setOnClickListener { view ->
val validAPIs = apis//.filter { api -> api.hasMainPage }
Expand Down Expand Up @@ -677,4 +688,4 @@ class HomeFragment : Fragment() {
}
}*/
}
}
}
13 changes: 13 additions & 0 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@
android:text="@string/result_open_in_browser"
app:icon="@drawable/ic_baseline_public_24" />

<com.google.android.material.button.MaterialButton
android:id="@+id/home_reload_connection_go_to_downloads"
style="@style/BlackButton"

android:layout_width="wrap_content"

android:layout_gravity="center"
android:layout_margin="5dp"
android:minWidth="200dp"
android:text="@string/result_go_to_downloads"
android:visibility="gone"
app:icon="@drawable/netflix_download" />

<TextView
android:id="@+id/result_error_text"
android:layout_width="match_parent"
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -821,5 +821,9 @@
<string name="show">Show</string>
<string name="dont_show">Don\'t Show</string>
<string name="subs_edge_size">Edge Size</string>
<!--confirm exit dialog-->
</resources>
<string name="result_go_to_downloads">Go to Downloads</string>
<string name="no_internet_connection">
No internet connection.
\n\nPlease connect to the internet and try again or watch your downloads while you are offline.
</string>
</resources>
Loading