Skip to content

Instantly share code, notes, and snippets.

@dingbuoyi
dingbuoyi / Three types of State LiveData
Last active October 19, 2021 06:34
四种不同的方法封装带网络状态的LiveData
// 实现一
# 状态类
sealed class Resource<T>(
val data: T? = null,
val errorCode: Int? = null
) {
class Success<T>(data: T) : Resource<T>(data)
class Loading<T>(data: T? = null) : Resource<T>(data)
class DataError<T>(errorCode: Int?) : Resource<T>(null, errorCode)
var c = Calendar.getInstance()
c.timeInMillis = System.currentTimeMillis()
val hour = c.get(Calendar.HOUR_OF_DAY)
val minute = c.get(Calendar.MINUTE)
TimePickerDialog(context, TimePickerDialog.OnTimeSetListener { _, _, _ ->
}, hour, minute, true).show()
public static String converTime(long timestamp) {
long currentSeconds = getFixedCurrentTime() / 1000;
long timeGap = currentSeconds - timestamp / 1000;// 与现在时间相差秒数
String timeStr = null;
if (timeGap > 24 * 60 * 60 * 365) {// 1天以上
// timeStr = timeGap / (24 * 60 * 60) + "天前";
timeStr = new SimpleDateFormat("yyyy年MM月dd日").format(new Date(timestamp));
} else if (timeGap > 24 * 60 * 60) {
timeStr = new SimpleDateFormat("MM月dd日").format(new Date(timestamp));
if (timeStr.startsWith("0")) {
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/block_user_btn"
android:orderInCategory="90"
android:title="@string/ls_profile_button_block"
app:actionViewClass="android.widget.TextView"
app:showAsAction="never" />
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{emailAddress});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
emailIntent.putExtra(Intent.EXTRA_TEXT, emailContent);
if (emailIntent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(Intent.createChooser(emailIntent, "Send email ..."));
} else {
if (emailClientNotInstalledCallback != null) {
emailClientNotInstalledCallback.handle();
adb push /Users/dean/Documents/flirten2/flirten2-android/flirten/app/app-integration-release.apk /sdcard/Download
private static boolean hasNavBar(Context context) {
Resources res = context.getResources();
int resourceId = res.getIdentifier("config_showNavigationBar", "bool", "android");
if (resourceId != 0) {
boolean hasNav = res.getBoolean(resourceId);
// check override flag
String sNavBarOverride = getNavBarOverride();
if ("1".equals(sNavBarOverride)) {
hasNav = false;
} else if ("0".equals(sNavBarOverride)) {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_activity_custom_ui_3);
addFragment(android.R.id.content,
DiamondsWalletFragment.newInstance(),
"DiamondsWalletFragment");
}
protected void addFragment(int containerViewId,
<com.rey.material.widget.Spinner
android:id="@+id/speciality"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/job_layout"
android:layout_marginLeft="@dimen/profile_detail_common_margin"
android:layout_marginRight="@dimen/profile_detail_common_margin"
android:layout_marginTop="20dp"
android:minWidth="128dp"
app:spn_arrowSize="0dp" />
nextBtn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
nextBtn.setBackgroundResource(R.drawable.gender_next_btn_selected);
} else if (event.getAction() == MotionEvent.ACTION_UP) {
callback.nextBtnClick();
}
return false;
}