-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
66 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/ethosa/ktc/utils/IOFragmentBackPressed.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.ethosa.ktc.utils | ||
|
||
import android.view.KeyEvent | ||
import android.view.View | ||
import androidx.fragment.app.Fragment | ||
|
||
/** | ||
* Provides interface which includes onBackPressed function. | ||
*/ | ||
abstract class IOFragmentBackPressed : Fragment() { | ||
/** | ||
* onBackPressed function should be called only when | ||
* user press on back button | ||
*/ | ||
abstract fun onBackPressed(): Boolean | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
view?.isFocusableInTouchMode = true | ||
view?.requestFocus() | ||
view?.setOnKeyListener(View.OnKeyListener { _, keyCode, event -> | ||
if (event.action == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) | ||
// return true if at branches | ||
return@OnKeyListener onBackPressed() | ||
return@OnKeyListener false | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters