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.os.Bundle | |
import android.view.LayoutInflater | |
import android.view.ViewGroup | |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.platform.ComposeView | |
import androidx.fragment.app.Fragment | |
import com.google.android.material.transition.MaterialSharedAxis | |
abstract class ComposeFragment: Fragment() { |
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
Kebijakan Privasi Turvl | |
Dengan mendownload aplikasi turvl anda otomatis tunduk dengan kebijakan privasi Turvl. | |
Turvl saat ini masih dalam tahap mengembangan, kami menggunakan data dummy ( bukan data sebenarnya ) | |
yang diambil dari berbagai sumber di internet guna keperluan presentasi / demo. | |
Selama masih dalam tahap pengembangan kami belum menggunakan data anda. | |
Kebijakan ini dapat berubah sewaktu-waktu, anda dapat mengecek secara berkala |
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
class StateAdapter(private val retry: () -> Unit) : LoadStateAdapter<StateAdapter.LoadStateViewHolder>() { | |
override fun onBindViewHolder(holder: LoadStateViewHolder, loadState: LoadState) { | |
holder.bind(loadState) | |
} | |
override fun onCreateViewHolder(parent: ViewGroup, loadState: LoadState): LoadStateViewHolder { | |
return LoadStateViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_load_state, parent, false), retry) | |
} |
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
class MainViewModel(private val repository: MainRepository = MainRepository()): ViewModel() { | |
fun movieList() = repository.getMovie().cachedIn(viewModelScope) | |
} |
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
class MainRepository { | |
fun getMovie(): Flow<PagingData<ResponseModel.MovieModel>> { | |
val moviePagingConfig = PagingConfig(pageSize = 10) | |
val moviePagingFactory= { MoviePagingSource() } | |
return Pager(config = moviePagingConfig , pagingSourceFactory = moviePagingFactory).flow | |
} |
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
class MoviePagingSource(private val service: MovieServices = MovieServiceBuilder.build()) : PagingSource<Int, ResponseModel.MovieModel>() { | |
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, ResponseModel.MovieModel> { | |
val pagePosition = params.key ?: STARTING_PAGE_INDEX | |
return try { | |
val data = service.getMovie(API_KEY, LANGUAGE, pagePosition).movieList //using retrofit | |
val prevKey = if (pagePosition == STARTING_PAGE_INDEX) null else pagePosition - 1 |
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
lifecycleScope.launch { | |
NetworkInfo().checkConnection(this@MainActivity).collect { connected -> | |
if (connected){ | |
//make some magic | |
} | |
} | |
} |
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
class NetworkInfo { | |
@Suppress("DEPRECATION") | |
@ExperimentalCoroutinesApi | |
fun checkConnection(context: Context) = callbackFlow{ | |
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | |
val networkRequest = NetworkRequest.Builder() | |
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR) |
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
................. | |
val timeLeft: LiveData<Int> get() = _timeLeft | |
private val _timeLeft = MutableLiveData(60) | |
private val countDownTimer = flow { | |
for (timeLeftOnTimer in 60 downTo 0){ | |
emit(timeLeftOnTimer) | |
delay(1000) | |
} | |
} |
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
........ | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
viewModel = ViewModelProvider(this)[MainViewModel::class.java] | |
tapMeButton = findViewById(R.id.tapMeButton) | |
gameScoreTextView = findViewById(R.id.gameScoreTextView) | |
timeLeftTextView = findViewById(R.id.timeLeftTextView) |
NewerOlder