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
/** | |
* 同じtagのDialogFragmentの存在チェックを実施し、ない場合に限り表示する | |
* | |
* @tag タグ名でチェックするため、一意の値を指定してください | |
*/ | |
fun DialogFragment.showIfNotAdded(fragmentManager: FragmentManager, tag: String) { | |
if ((fragmentManager.findFragmentByTag(tag) as? DialogFragment)?.dialog == null) { | |
showNow(fragmentManager, tag) | |
} | |
} |
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
import androidx.compose.foundation.lazy.LazyListState | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.getValue | |
import androidx.compose.runtime.mutableStateOf | |
import androidx.compose.runtime.remember | |
import androidx.compose.runtime.setValue | |
import kotlin.math.abs | |
enum class ScrollDirection { | |
FORWARD, BACKWARD, IDLE, |
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
/** | |
* Eventに値が流れてきていないことをAssertする | |
*/ | |
suspend fun <T> FlowTurbine<T>.assertAwaitItemIsNotReceived() { | |
try { | |
awaitItem() | |
Assert.fail("Expected no event was received in time") | |
} catch (e: TimeoutCancellationException) { | |
// SharedFlowに値が流れてこないと[TimeoutCancellationException]が発生するため、それを正とする | |
} |
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
import android.view.ViewGroup | |
import com.google.android.material.tabs.TabLayout | |
/** | |
* Tab表示が画面に収まる場合と収まらない場合とでTab mode指定を切り替える | |
* | |
* Tabサイズが画面に収まる場合は[TabLayout.MODE_FIXED] | |
* Tabサイズが画面に収まらない場合は[TabLayout.MODE_SCROLLABLE] | |
*/ | |
fun TabLayout.adjustTabMode() { |
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
/** | |
* BottomSheetDialogを全画面表示する | |
*/ | |
fun BottomSheetDialogFragment.fullScreen() { | |
dialog?.setOnShowListener { dialog -> | |
val d = dialog as BottomSheetDialog | |
val bottomSheet = | |
d.findViewById<FrameLayout>(R.id.design_bottom_sheet) ?: return@setOnShowListener | |
bottomSheet.layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT | |
val screenHeight = Resources.getSystem().displayMetrics.heightPixels |
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
import androidx.compose.foundation.layout.Arrangement | |
import androidx.compose.foundation.layout.Column | |
import androidx.compose.foundation.layout.fillMaxSize | |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.Alignment | |
import androidx.compose.ui.Modifier | |
@Composable | |
fun Center( | |
modifier: Modifier = Modifier, |
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
fun main(args: Array<String>) { | |
when (val r1 = getUser()) { | |
is Result.Success -> { | |
when (val r2 = login(r1.data)) { | |
is Result.Success -> { | |
when (val r3 = setupSomething()) { | |
is Result.Success -> { | |
println("Success") | |
} |
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
import android.view.HapticFeedbackConstants | |
import android.view.MotionEvent | |
import android.view.View | |
/** | |
* Viewへのタップイベントに対してHaptic feedbackするヘルパー | |
*/ | |
class HapticOnTapHelper : HapticOnTouchHelper { | |
override fun onTouch(v: View, e: MotionEvent): Boolean { | |
val isHandled = v.onTouchEvent(e) |
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
fun Fragment.performHapticFeedback(effectId: Int) { | |
val vibrator = requireContext().getSystemService(Context.VIBRATOR_SERVICE) as Vibrator | |
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { | |
vibrator.vibrate(VibrationEffect.createPredefined(effectId)) | |
} | |
} |
NewerOlder