• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

yongjhih/kotlin-extensions: kotlin-android-extensions

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

yongjhih/kotlin-extensions

开源软件地址(OpenSource Url):

https://github.com/yongjhih/kotlin-extensions

开源编程语言(OpenSource Language):

Kotlin 99.1%

开源软件介绍(OpenSource Introduction):

kotlin-extensions

JitPack javadoc Build Status Join the chat at https://gitter.im/yongjhih/kotlin-android-extensions Kotlin

Usage

Database

Before:

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")

SharedPreferences

Before:

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 Services

Before:

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

After:

val notificationManager = context.getNotificationManager()

Notification

Before:

Notification notification = new NotificationCompat.Builder(context)
  .setContentTitle("Hello")
  .setSubText("World")
  .build();

After:

val notification = Notification.build(context) {
  setContentTitle("Hello")
  setSubText("World")
}

Query

Math

Import from MichaelRocks/MathExtensions.kt

ThreeTen Backport (JSR-310)

LocalDateTime.now().toDate()
new Date().toLocalDateTime()

View

view.fadeOut()
view.fadeIn()
for (view in views.children())
if (view in views) {
  // ..
}
views += view
views -= view
views.forEach {}
views.filter {}

Misc

Installation

jitpack:

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

Copyright 2015 8tory, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
ojsheikh/unicode-latex: A visual studio code extension to insert Unicode symbols ...发布时间:2022-07-09
下一篇:
clinyong/latex-szu发布时间:2022-07-09
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap