-
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
7 changed files
with
549 additions
and
558 deletions.
There are no files selected for viewing
87 changes: 0 additions & 87 deletions
87
app/src/main/java/com/cradle/neptune/view/ui/reading/BaseFragment.java
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
app/src/main/java/com/cradle/neptune/view/ui/reading/BaseFragment.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,81 @@ | ||
package com.cradle.neptune.view.ui.reading | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import android.view.inputmethod.InputMethodManager | ||
import androidx.fragment.app.Fragment | ||
import com.cradle.neptune.manager.ReadingManager | ||
import com.cradle.neptune.viewmodel.PatientReadingViewModel | ||
|
||
/** | ||
* Base class for other ReadingFragments | ||
* - Observer | ||
* - Shared access to Reading object | ||
* | ||
* | ||
* Activities that contain fragments derived from this class must implement the | ||
* [MyFragmentInteractionListener] interface to handle interaction events. | ||
* Use the newInstance() factory method to create an instance of derived fragment. | ||
*/ | ||
abstract class BaseFragment : Fragment() { | ||
@JvmField | ||
protected var TAG = BaseFragment::class.java.name | ||
@JvmField | ||
protected var activityCallbackListener: MyFragmentInteractionListener? = null | ||
@JvmField | ||
protected var viewModel: PatientReadingViewModel? = null | ||
@JvmField | ||
protected var readingManager: ReadingManager? = null | ||
|
||
/* | ||
Keyboard support | ||
*/ | ||
fun hideKeyboard() { | ||
// SOURCE: https://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard | ||
if (this.activity == null) { | ||
return | ||
} | ||
val context = context | ||
val view = this.requireActivity().currentFocus | ||
if (view != null) { | ||
val imm = | ||
requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager | ||
imm.hideSoftInputFromWindow(view.windowToken, 0) | ||
} | ||
} | ||
|
||
/* | ||
Observer | ||
*/ | ||
override fun onAttach(context: Context) { | ||
Log.d(TAG, "TRACE -- onAttach(): hash" + toString()) | ||
super.onAttach(context) | ||
|
||
// ensure callback functions are implemented. | ||
if (context !is MyFragmentInteractionListener) { | ||
throw RuntimeException( | ||
context.toString() | ||
+ " must implement MyFragmentInteractionListener" | ||
) | ||
} | ||
activityCallbackListener = context | ||
viewModel = activityCallbackListener!!.viewModel | ||
readingManager = activityCallbackListener!!.readingManager | ||
} | ||
|
||
override fun onDetach() { | ||
Log.d(TAG, "TRACE -- onDetatch(): hash" + toString()) | ||
super.onDetach() | ||
activityCallbackListener = null | ||
} | ||
|
||
/** | ||
* Called by ReadingActivity when fragment is just being displayed (navigated to) | ||
*/ | ||
abstract fun onMyBeingDisplayed() | ||
|
||
/** | ||
* Called by ReadingActivity after fragment has been navigated away from (hidden) | ||
*/ | ||
abstract fun onMyBeingHidden(): Boolean | ||
} |
Oops, something went wrong.