move noInternetActivity

This commit is contained in:
Bnyro 2022-07-01 16:44:14 +02:00
parent afd71c7c54
commit 920a920f10
5 changed files with 51 additions and 27 deletions

View File

@ -24,8 +24,10 @@
<activity
android:name=".util.Player"
android:configChanges="orientation|screenSize"
android:exported="false"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
android:exported="false" />
<activity
android:name=".NoInternetActivity"
android:label="@string/noInternet"/>
<activity
android:name=".SettingsActivity"
android:label="@string/settings" />

View File

@ -19,8 +19,6 @@ import android.view.WindowInsets
import android.view.WindowInsetsController
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import android.widget.Button
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
@ -50,7 +48,6 @@ class MainActivity : AppCompatActivity() {
lateinit var binding: ActivityMainBinding
private lateinit var bottomNavigationView: BottomNavigationView
private lateinit var toolbar: Toolbar
lateinit var navController: NavController
override fun onCreate(savedInstanceState: Bundle?) {
@ -70,14 +67,8 @@ class MainActivity : AppCompatActivity() {
// show noInternet Activity if no internet available on app startup
if (!isNetworkAvailable(this)) {
setContentView(R.layout.activity_nointernet)
findViewById<Button>(R.id.retry_button).setOnClickListener {
recreate()
}
findViewById<ImageView>(R.id.noInternet_settingsImageView).setOnClickListener {
val intent = Intent(this, SettingsActivity::class.java)
startActivity(intent)
}
val noInternetIntent = Intent(this, NoInternetActivity::class.java)
startActivity(noInternetIntent)
} else {
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
@ -286,7 +277,6 @@ class MainActivity : AppCompatActivity() {
navController.popBackStack()
}
} catch (e: Exception) {
// try catch to prevent nointernet activity to crash
try {
navController.popBackStack()
moveTaskToBack(true)
@ -364,10 +354,6 @@ fun Fragment.hideKeyboard() {
view?.let { activity?.hideKeyboard(it) }
}
fun Activity.hideKeyboard() {
hideKeyboard(currentFocus ?: View(this))
}
fun Context.hideKeyboard(view: View) {
val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)

View File

@ -0,0 +1,31 @@
package com.github.libretube
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.github.libretube.databinding.ActivityNointernetBinding
import com.github.libretube.util.ThemeHelper
import com.google.android.material.color.DynamicColors
class NoInternetActivity : AppCompatActivity() {
private lateinit var binding: ActivityNointernetBinding
override fun onCreate(savedInstanceState: Bundle?) {
DynamicColors.applyToActivityIfAvailable(this)
super.onCreate(savedInstanceState)
binding = ActivityNointernetBinding.inflate(layoutInflater)
binding.retryButton.setOnClickListener {
ThemeHelper.restartMainActivity(this)
}
binding.noInternetSettingsImageView.setOnClickListener {
val intent = Intent(this, SettingsActivity::class.java)
startActivity(intent)
}
setContentView(binding.root)
}
override fun onBackPressed() {
finishAffinity()
super.onBackPressed()
}
}

View File

@ -13,6 +13,9 @@ import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.MainActivity
import com.github.libretube.R
import com.github.libretube.databinding.ChannelSearchRowBinding
import com.github.libretube.databinding.PlaylistSearchRowBinding
import com.github.libretube.databinding.VideoSearchRowBinding
import com.github.libretube.dialogs.PlaylistOptionsDialog
import com.github.libretube.dialogs.VideoOptionsDialog
import com.github.libretube.fragments.PlayerFragment
@ -37,15 +40,15 @@ class SearchAdapter(
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchViewHolder {
val layout = when (viewType) {
0 -> R.layout.video_search_row
1 -> R.layout.channel_search_row
2 -> R.layout.playlist_search_row
val layoutInflater = LayoutInflater.from(parent.context)
val binding = when (viewType) {
0 -> VideoSearchRowBinding.inflate(layoutInflater, parent, false)
1 -> ChannelSearchRowBinding.inflate(layoutInflater, parent, false)
2 -> PlaylistSearchRowBinding.inflate(layoutInflater, parent, false)
else -> throw IllegalArgumentException("Invalid type")
}
val layoutInflater = LayoutInflater.from(parent.context)
val cell = layoutInflater.inflate(layout, parent, false)
return SearchViewHolder(cell, childFragmentManager)
return SearchViewHolder(binding.root, childFragmentManager)
}
override fun onBindViewHolder(holder: SearchViewHolder, position: Int) {

View File

@ -6,10 +6,12 @@
<ImageView
android:id="@+id/noInternet_settingsImageView"
android:layout_width="30dp"
android:layout_height="30dp"
android:padding="3dp"
android:layout_width="33dp"
android:layout_height="33dp"
android:layout_margin="16dp"
android:src="@drawable/ic_settings"
android:background="?attr/selectableItemBackgroundBorderless"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />