From 5452f6135cea8de8003d0df246aa84f2ee20a839 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 23 Jul 2022 22:10:03 +0200 Subject: [PATCH] cleanup --- .../github/libretube/activities/MainActivity.kt | 13 ------------- .../github/libretube/fragments/PlayerFragment.kt | 2 +- .../github/libretube/fragments/SearchFragment.kt | 2 +- .../com/github/libretube/util/HideKeyboard.kt | 16 ++++++++++++++++ 4 files changed, 18 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/com/github/libretube/util/HideKeyboard.kt diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index b4a01ebc2..f22d35ba5 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -1,7 +1,5 @@ package com.github.libretube.activities -import android.app.Activity -import android.content.Context import android.content.Intent import android.content.pm.ActivityInfo import android.content.res.Configuration @@ -15,13 +13,11 @@ import android.view.View import android.view.WindowInsets import android.view.WindowInsetsController import android.view.WindowManager -import android.view.inputmethod.InputMethodManager import android.widget.LinearLayout import androidx.appcompat.app.AppCompatActivity import androidx.constraintlayout.motion.widget.MotionLayout import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.os.bundleOf -import androidx.fragment.app.Fragment import androidx.navigation.NavController import androidx.navigation.findNavController import androidx.navigation.ui.setupWithNavController @@ -404,12 +400,3 @@ class MainActivity : AppCompatActivity() { } } } - -fun Fragment.hideKeyboard() { - view?.let { activity?.hideKeyboard(it) } -} - -fun Context.hideKeyboard(view: View) { - val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager - inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0) -} diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index 94d702010..a6cc9d0d1 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -38,7 +38,6 @@ import androidx.recyclerview.widget.LinearLayoutManager import com.github.libretube.Globals import com.github.libretube.R import com.github.libretube.activities.MainActivity -import com.github.libretube.activities.hideKeyboard import com.github.libretube.adapters.ChaptersAdapter import com.github.libretube.adapters.CommentsAdapter import com.github.libretube.adapters.TrendingAdapter @@ -65,6 +64,7 @@ import com.github.libretube.util.DescriptionAdapter import com.github.libretube.util.PlayerHelper import com.github.libretube.util.RetrofitInstance import com.github.libretube.util.formatShort +import com.github.libretube.util.hideKeyboard import com.google.android.exoplayer2.C import com.google.android.exoplayer2.DefaultLoadControl import com.google.android.exoplayer2.ExoPlayer diff --git a/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt b/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt index f1e670039..8b369e85d 100644 --- a/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/SearchFragment.kt @@ -20,7 +20,6 @@ import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import com.github.libretube.R -import com.github.libretube.activities.hideKeyboard import com.github.libretube.adapters.SearchAdapter import com.github.libretube.adapters.SearchHistoryAdapter import com.github.libretube.adapters.SearchSuggestionsAdapter @@ -28,6 +27,7 @@ import com.github.libretube.databinding.FragmentSearchBinding import com.github.libretube.preferences.PreferenceHelper import com.github.libretube.preferences.PreferenceKeys import com.github.libretube.util.RetrofitInstance +import com.github.libretube.util.hideKeyboard import com.google.android.material.dialog.MaterialAlertDialogBuilder import retrofit2.HttpException import java.io.IOException diff --git a/app/src/main/java/com/github/libretube/util/HideKeyboard.kt b/app/src/main/java/com/github/libretube/util/HideKeyboard.kt new file mode 100644 index 000000000..eab38fb28 --- /dev/null +++ b/app/src/main/java/com/github/libretube/util/HideKeyboard.kt @@ -0,0 +1,16 @@ +package com.github.libretube.util + +import android.app.Activity +import android.content.Context +import android.view.View +import android.view.inputmethod.InputMethodManager +import androidx.fragment.app.Fragment + +fun Fragment.hideKeyboard() { + view?.let { activity?.hideKeyboard(it) } +} + +fun Context.hideKeyboard(view: View) { + val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager + inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0) +}