Browse Source

Moved show/hide keyboard extensions to views

Vadik Sirekanyan 7 năm trước cách đây
mục cha
commit
17c44a194d

+ 0 - 13
app/src/main/java/com/sirekanyan/knigopis/common/extensions/Activity.kt

@@ -1,7 +1,6 @@
 package com.sirekanyan.knigopis.common.extensions
 
 import android.app.Activity
-import android.view.View
 import android.view.ViewGroup
 import com.sirekanyan.knigopis.App
 
@@ -9,15 +8,3 @@ val Activity.app get() = application as App
 
 fun Activity.getRootView(): ViewGroup =
     findViewById(android.R.id.content)
-
-fun Activity.showKeyboard(view: View) {
-    if (view.requestFocus()) {
-        systemInputMethodManager.showSoftInput(view, 0)
-    }
-}
-
-fun Activity.hideKeyboard() {
-    currentFocus?.let { view ->
-        systemInputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
-    }
-}

+ 13 - 1
app/src/main/java/com/sirekanyan/knigopis/common/extensions/View.kt

@@ -57,4 +57,16 @@ fun View.startCollapseAnimation() {
     animate().alpha(0f).setDuration(200)
         .setInterpolator(FastOutLinearInInterpolator())
         .scaleX(0f).scaleY(0f)
-}
+}
+
+fun View.showKeyboard(view: View) {
+    if (view.requestFocus()) {
+        context.systemInputMethodManager.showSoftInput(view, 0)
+    }
+}
+
+fun View.hideKeyboard() {
+    findFocus()?.let { view ->
+        context.systemInputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
+    }
+}

+ 1 - 1
app/src/main/java/com/sirekanyan/knigopis/feature/book/BookActivity.kt

@@ -86,7 +86,7 @@ class BookActivity : BaseActivity() {
         toolbar.setOnMenuItemClickListener { saveMenuItem ->
             when (saveMenuItem.itemId) {
                 R.id.option_save_book -> {
-                    hideKeyboard()
+                    getRootView().hideKeyboard()
                     if (progressSeekBar.progress == MAX_BOOK_PRIORITY) {
                         repository.saveBook(
                             bookId,