mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Merge pull request #189 from Bnyro/nowifi
Added a NoInternet Activity if no internet on app startup
This commit is contained in:
commit
a9c4cedfbf
@ -5,6 +5,8 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
import android.net.NetworkInfo
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
@ -13,6 +15,7 @@ import android.os.Handler
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
|
import android.widget.Button
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.appcompat.widget.Toolbar
|
import androidx.appcompat.widget.Toolbar
|
||||||
@ -57,63 +60,76 @@ class MainActivity : AppCompatActivity() {
|
|||||||
Locale.setDefault(locale)
|
Locale.setDefault(locale)
|
||||||
res.updateConfiguration(conf, dm)
|
res.updateConfiguration(conf, dm)
|
||||||
}
|
}
|
||||||
setContentView(R.layout.activity_main)
|
|
||||||
when (sharedPreferences.getString("theme_togglee", "A")!!) {
|
when (sharedPreferences.getString("theme_togglee", "A")!!) {
|
||||||
"A" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
"A" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||||
"L" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
"L" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||||
"D" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
"D" -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||||
}
|
}
|
||||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
|
||||||
|
|
||||||
bottomNavigationView = findViewById(R.id.bottomNav)
|
val connectivityManager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
navController = findNavController(R.id.fragment)
|
val networkInfo=connectivityManager.activeNetworkInfo
|
||||||
bottomNavigationView.setupWithNavController(navController)
|
val isConnected = networkInfo != null && networkInfo.isConnected
|
||||||
|
|
||||||
bottomNavigationView.setOnItemSelectedListener {
|
if (isConnected == false) {
|
||||||
when(it.itemId){
|
setContentView(R.layout.activity_nointernet)
|
||||||
R.id.home2 -> {
|
findViewById<Button>(R.id.retry_button).setOnClickListener() {
|
||||||
navController.backQueue.clear()
|
recreate()
|
||||||
navController.navigate(R.id.home2)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.subscriptions -> {
|
|
||||||
//navController.backQueue.clear()
|
|
||||||
navController.navigate(R.id.subscriptions)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
R.id.library -> {
|
|
||||||
//navController.backQueue.clear()
|
|
||||||
navController.navigate(R.id.library)
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
false
|
} else {
|
||||||
}
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
toolbar = findViewById(R.id.toolbar)
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||||
val hexColor = String.format("#%06X", 0xFFFFFF and 0xcc322d)
|
|
||||||
val appName = HtmlCompat.fromHtml(
|
|
||||||
"Libre<span style='color:$hexColor';>Tube</span>",
|
|
||||||
HtmlCompat.FROM_HTML_MODE_COMPACT
|
|
||||||
)
|
|
||||||
toolbar.title= appName
|
|
||||||
|
|
||||||
toolbar.setNavigationOnClickListener{
|
bottomNavigationView = findViewById(R.id.bottomNav)
|
||||||
//settings fragment stuff
|
navController = findNavController(R.id.fragment)
|
||||||
navController.navigate(R.id.settings)
|
bottomNavigationView.setupWithNavController(navController)
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
toolbar.setOnMenuItemClickListener{
|
bottomNavigationView.setOnItemSelectedListener {
|
||||||
when (it.itemId){
|
when (it.itemId) {
|
||||||
R.id.action_search -> {
|
R.id.home2 -> {
|
||||||
navController.navigate(R.id.searchFragment)
|
navController.backQueue.clear()
|
||||||
true
|
navController.navigate(R.id.home2)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
R.id.subscriptions -> {
|
||||||
|
//navController.backQueue.clear()
|
||||||
|
navController.navigate(R.id.subscriptions)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
R.id.library -> {
|
||||||
|
//navController.backQueue.clear()
|
||||||
|
navController.navigate(R.id.library)
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
|
toolbar = findViewById(R.id.toolbar)
|
||||||
|
val hexColor = String.format("#%06X", 0xFFFFFF and 0xcc322d)
|
||||||
|
val appName = HtmlCompat.fromHtml(
|
||||||
|
"Libre<span style='color:$hexColor';>Tube</span>",
|
||||||
|
HtmlCompat.FROM_HTML_MODE_COMPACT
|
||||||
|
)
|
||||||
|
toolbar.title = appName
|
||||||
|
|
||||||
|
toolbar.setNavigationOnClickListener {
|
||||||
|
//settings fragment stuff
|
||||||
|
navController.navigate(R.id.settings)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
toolbar.setOnMenuItemClickListener {
|
||||||
|
when (it.itemId) {
|
||||||
|
R.id.action_search -> {
|
||||||
|
navController.navigate(R.id.searchFragment)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
app/src/main/res/drawable/ic_wifi_off.xml
Normal file
10
app/src/main/res/drawable/ic_wifi_off.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M22.99,9C19.15,5.16 13.8,3.76 8.84,4.78l2.52,2.52c3.47,-0.17 6.99,1.05 9.63,3.7l2,-2zM18.99,13c-1.29,-1.29 -2.84,-2.13 -4.49,-2.56l3.53,3.53 0.96,-0.97zM2,3.05L5.07,6.1C3.6,6.82 2.22,7.78 1,9l1.99,2c1.24,-1.24 2.67,-2.16 4.2,-2.77l2.24,2.24C7.81,10.89 6.27,11.73 5,13v0.01L6.99,15c1.36,-1.36 3.14,-2.04 4.92,-2.06L18.98,20l1.27,-1.26L3.29,1.79 2,3.05zM9,17l3,3 3,-3c-1.65,-1.66 -4.34,-1.66 -6,0z"/>
|
||||||
|
</vector>
|
37
app/src/main/res/layout/activity_nointernet.xml
Normal file
37
app/src/main/res/layout/activity_nointernet.xml
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?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">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/noInternet_imageView"
|
||||||
|
android:layout_width="200dp"
|
||||||
|
android:layout_height="200dp"
|
||||||
|
android:layout_marginTop="-50dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:srcCompat="@drawable/ic_wifi_off" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/textView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/noInternet"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/noInternet_imageView" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/retry_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:text="@string/retry"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/textView" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -63,5 +63,7 @@
|
|||||||
<string name="lightTheme">Light Theme</string>
|
<string name="lightTheme">Light Theme</string>
|
||||||
<string name="darkTheme">Dark Theme</string>
|
<string name="darkTheme">Dark Theme</string>
|
||||||
<string name="subscribers">%1$s subscribers</string>
|
<string name="subscribers">%1$s subscribers</string>
|
||||||
|
<string name="noInternet">No Internet Connection</string>
|
||||||
|
<string name="retry">Retry</string>
|
||||||
<string name="comments">Comments</string>
|
<string name="comments">Comments</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user