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
| /** | |
| * Return true if email format valid | |
| * Return false if email format not valid | |
| */ | |
| fun validateEmail(email: String): Boolean { | |
| return Patterns.EMAIL_ADDRESS.matcher(email).matches() | |
| } |
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
| class MainActivity : AppCompatActivity() { | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| ... | |
| } | |
| override fun onCreateOptionsMenu(menu: Menu): Boolean { | |
| ... | |
| } | |
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.ahr.newsapp.data.local.room | |
| import androidx.lifecycle.LiveData | |
| import androidx.room.* | |
| import com.dicoding.newsapp.data.local.entity.NewsEntity | |
| @Dao | |
| interface NewsDao { | |
| @Query("SELECT EXISTS(SELECT * FROM news WHERE title = :title)") | |
| fun isNewsBookmarked(title: String): LiveData<Boolean> |
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.ahr.newsapp | |
| import kotlinx.coroutines.Dispatchers | |
| import kotlinx.coroutines.ExperimentalCoroutinesApi | |
| import kotlinx.coroutines.test.TestDispatcher | |
| import kotlinx.coroutines.test.UnconfinedTestDispatcher | |
| import kotlinx.coroutines.test.resetMain | |
| import kotlinx.coroutines.test.setMain | |
| import org.junit.rules.TestWatcher | |
| import org.junit.runner.Description |
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.ahr.newsapp.data | |
| sealed class Result<out R> private constructor() { | |
| data class Success<out T>(val data: T) : Result<T>() | |
| data class Error(val error: String) : Result<Nothing>() | |
| object Loading : Result<Nothing>() | |
| } |
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.ahr.newsapp | |
| import androidx.annotation.VisibleForTesting | |
| import androidx.lifecycle.LiveData | |
| import androidx.lifecycle.Observer | |
| import java.util.concurrent.CountDownLatch | |
| import java.util.concurrent.TimeUnit | |
| import java.util.concurrent.TimeoutException | |
| @Suppress("UNCHECKED_CAST") |
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 reduceFileImage(file: File): File { | |
| val bitmap = BitmapFactory.decodeFile(file.path) | |
| var compressQuality = 100 | |
| var streamLength: Int | |
| do { | |
| val bmpStream = ByteArrayOutputStream() | |
| bitmap.compress(CompressFormat.JPEG, compressQuality, bmpStream) | |
| val bmpPicByteArray = bmpStream.toByteArray() | |
| streamLength = bmpPicByteArray.size | |
| compressQuality -= 5 |
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
| class MainActivity : AppCompatActivity() { | |
| private lateinit var binding: ActivityMainBinding | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| binding = ActivityMainBinding.inflate(layoutInflater) | |
| setContentView(binding.root) | |
| binding.galleryButton.setOnClickListener { startGallery() } |
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
| class MainActivity : AppCompatActivity() { | |
| private lateinit var root: ConstraintLayout | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| setContentView(R.layout.activity_main) | |
| root = findViewById(R.id.root) | |
NewerOlder