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
users.filter{ user -> user.job == Job.Developer } | |
.map{ developer -> developer.birthDate.dayOfMonth } | |
.filter { birthDay -> birthDay <= 10 } | |
.min() |
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
users.filter{ it.job == Job.Developer } | |
.map{ it.birthDate.dayOfMonth } | |
.filter{ it <= 10 } | |
.min() |
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 Book(val title: String?, val publishYear: Int?) | |
fun displayBookDetails(book: Book) { | |
val title = book.title ?: | |
throw IllegalArgumentException("Title required") | |
val publishYear = book.publishYear ?: return | |
println("$title: $publishYear") | |
} |
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 Book(val title: String?, val publishYear: Int?) | |
fun displayBookDetails(book: Book) { | |
val title = book.title | |
if (title == null) | |
throw IllegalArgumentException("Title required") | |
val publishYear = book.publishYear | |
if (publishYear == null) return | |
println("$title: $publishYear") |
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
data class PathParts(val directory: String, val fileName: String) | |
fun splitPath(path: String) = | |
PathParts( | |
path.substringBeforeLast('/', ""), | |
path.substringAfterLast('/')) |
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
data class GetFile(val d: String, val n: String) | |
val pattern = Regex("(.+)/([^/]*)") | |
fun files(ph: String): PathParts { | |
val match = pattern.matchEntire(ph) | |
?: return PathParts("", ph) | |
return PathParts(match.groupValues[1], | |
match.groupValues[2]) |
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
def room_version = "2.2.6" | |
implementation "androidx.room:room-runtime:$room_version" | |
annotationProcessor "androidx.room:room-compiler:$room_version" |
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.content.Context; | |
import android.content.SharedPreferences; | |
public class ApplicationData { | |
private static final String APP_KEY = "android_course_key"; | |
// save a String value by key | |
public static void setStringValueInSharedPreferences(Context context, String key, String value) { | |
SharedPreferences sharedPreferences = context.getSharedPreferences(ApplicationData.APP_KEY, | |
Context.MODE_PRIVATE); |
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
// manifest add => <uses-permission android:name="android.permission.CAMERA" /> | |
import static android.Manifest.permission.CAMERA; | |
private static final int REQUEST_CODE_CAMERA = 23; | |
if (ContextCompat.checkSelfPermission(StylesActivity.this, CAMERA) != PackageManager.PERMISSION_GRANTED) { | |
// unhappy path | |
ActivityCompat.requestPermissions(StylesActivity.this, new String[]{CAMERA}, REQUEST_CODE_CAMERA); |
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
private void setupSwipeToRefresh() { | |
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { | |
@Override | |
public void onRefresh() { | |
// Make sure you call swipeRefreshLayout.setRefreshing(false) | |
// once the network request has completed successfully. | |
inbox(); | |
} | |
}); | |
// Configure the refreshing colors |