This file contains hidden or 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
| //rvList is my recyclerview | |
| binding.rvList.isNestedScrollingEnabled = false |
This file contains hidden or 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
| private fun popToFragmentBeforeKnownFragment(fragment: Fragment) { | |
| if (!lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) | |
| return | |
| val isPopped = supportFragmentManager.popBackStackImmediate(fragment::class.simpleName, | |
| FragmentManager.POP_BACK_STACK_INCLUSIVE) | |
| if (!isPopped) | |
| throw UnsupportedOperationException("Specified fragment does not exist in backstack") | |
| } |
This file contains hidden or 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
| private fun moveBackXTimes(numOfTimes : Int) { | |
| if (!lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) | |
| return | |
| val backStackCount = supportFragmentManager.backStackEntryCount | |
| if (numOfTimes >= backStackCount) { | |
| throw UnsupportedOperationException("Number of times specified $numOfTimes is greater" + | |
| " than the backstackEntryCount") | |
| } |
This file contains hidden or 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
| private fun createArtificialBackStack() { | |
| if (!lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) | |
| return | |
| supportFragmentManager.beginTransaction() | |
| .replace(R.id.app_container, HomeFragment.newInstance(), HomeFragment::class.simpleName) | |
| .addToBackStack(HomeFragment::class.simpleName) | |
| .setReorderingAllowed(true) | |
| .commit() |
This file contains hidden or 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
| private fun popToKnownFragment(fragment : Fragment) { | |
| if (!lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) | |
| return | |
| val isPopped = supportFragmentManager.popBackStackImmediate(fragment::class.simpleName, 0) | |
| if (!isPopped) { | |
| // code inside here is only executed because fragment transaction didnt happen because | |
| // the fragment above does not exist in the backstack or it was added with a different tag. | |
| // Since this fragment must be shown, add a new instance of it | |
| supportFragmentManager.beginTransaction() |
This file contains hidden or 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
| private fun moveBackOneTime() { | |
| if (!lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) | |
| return | |
| supportFragmentManager.popBackStack() | |
| } |
This file contains hidden or 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
| package com.nezspencer.test | |
| import android.os.Bundle | |
| import android.support.annotation.NonNull | |
| import android.support.v7.app.AppCompatActivity | |
| import android.text.Editable | |
| import android.text.TextUtils | |
| import android.text.TextWatcher | |
| import android.widget.EditText | |
| import java.text.NumberFormat |
This file contains hidden or 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
| private fun getNewCursorPosition(digitCountToRightOfCursor : Int, numberString : String) : Int{ | |
| var position = 0 | |
| var c = digitCountToRightOfCursor | |
| for (i in numberString.reversed()) { | |
| if (c == 0) | |
| break | |
| if (i.isDigit()) | |
| c -- | |
| position ++ |
This file contains hidden or 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
| override fun onSuccess(){ | |
| if(lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) { | |
| //safe to perform fragment transaction | |
| } | |
| } |
This file contains hidden or 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
| @Override | |
| fun onSuccess(){ | |
| if(lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) { | |
| //perform action here | |
| } | |
| } |