在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):yongjhih/kotlin-extensions开源软件地址(OpenSource Url):https://github.com/yongjhih/kotlin-extensions开源编程语言(OpenSource Language):Kotlin 99.1%开源软件介绍(OpenSource Introduction):kotlin-extensionsUsageDatabaseBefore: db.beginTransaction();
try {
db.delete("users", "first_name = ?", new String[] { "Andrew" });
db.setTransactionSuccessful();
} finally {
db.endTransaction()
} or Databases.from(db).inTransaction(it -> {
it.delete("users", "first_name = ?", new String[] { "Andrew" });
}); After: db.inTransation {
delete("users", "first_name = ?", arrayOf("Andrew"))
} Before: String firstName = cursor.getString(cursor.getColumnIndexOrThrow("first_name")); After: val firstName = cursor.getString("first_name"); Before: String firstName = null;
int firstNameColumnIndex = cursor.getColumnIndexOrThrow("first_name");
if (!cursor.isNull(firstNameColumnIndex)) {
firstName = cursor.getString(firstNameColumnIndex);
}
firstNameView.setText(firstName != null ? firstName : "Andrew"); After: val firstName = cursor.getStringOrNull("first_name")
firstNameView.setText(firstName ?: "Andrew") SharedPreferencesBefore: SharePreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharePreferences.Editor editor = prefs.edit();
editor.putString("name", "Andrew Chen");
editor.putInt("age", 18, 14);
editor.apply(); After: User(context).edit {
name = "Andrew Chen"
age = "18"
}
public class User(context: Context) : Preferences(context) {
var name: String by Preference()
var age: Int by Preference(default = 14)
} or User user = User(context)
user.name = "Andrew Chen"
user.age = 18
user.apply() Bonus - SharedPreferences Extension:Before: SharedPreferences.Editor editor = prefs.edit();
editor.putString("first_name", "Andrew");
editor.putString("last_name", "Chen");
editor.remove("age");
editor.apply(); or SharedPreferencesUtils.from(prefs).apply(editor -> {
editor.putString("first_name", "Andrew");
editor.putString("last_name", "Chen");
editor.remove("age");
}); After: prefs.edit {
putString("first_name", "Andrew")
putString("last_name", "Chen")
remove("age")
} System ServicesBefore: NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); After: val notificationManager = context.getNotificationManager() NotificationBefore: Notification notification = new NotificationCompat.Builder(context)
.setContentTitle("Hello")
.setSubText("World")
.build(); After: val notification = Notification.build(context) {
setContentTitle("Hello")
setSubText("World")
} QueryMathImport from MichaelRocks/MathExtensions.kt ThreeTen Backport (JSR-310)LocalDateTime.now().toDate() new Date().toLocalDateTime() Viewview.fadeOut() view.fadeIn() for (view in views.children()) if (view in views) {
// ..
} views += view views -= view views.forEach {} views.filter {} MiscInstallationjitpack: repositories {
// ...
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.github.yongjhih.kotlin-extensions:kotlinx-android-sharedpreferences:-SNAPSHOT'
compile 'com.github.yongjhih.kotlin-extensions:kotlinx-android-database:-SNAPSHOT'
compile 'com.github.yongjhih.kotlin-extensions:kotlinx-android-system-services:-SNAPSHOT'
compile 'com.github.yongjhih.kotlin-extensions:kotlinx-android-notification:-SNAPSHOT'
compile 'com.github.yongjhih.kotlin-extensions:kotlinx-math:-SNAPSHOT'
compile 'com.github.yongjhih.kotlin-extensions:kotlinx-threetenbp:-SNAPSHOT'
compile 'com.github.yongjhih.kotlin-extensions:kotlinx-android-view:-SNAPSHOT'
} jcenter (not ready yet): dependencies {
compile 'com.infstory:kotlinx-android-sharedpreferences:1.0.0'
compile 'com.infstory:kotlinx-android-database:1.0.0'
compile 'com.infstory:kotlinx-android-system-services:1.0.0'
compile 'com.infstory:kotlinx-android-notification:1.0.0'
compile 'com.infstory:kotlinx-math:1.0.0'
compile 'com.infstory:kotlinx-android-view:1.0.0'
} License
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论