session-android/src/org/thoughtcrime/securesms/DeviceListItem.java

58 lines
1.4 KiB
Java
Raw Normal View History

package org.thoughtcrime.securesms;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;
2018-12-19 16:09:22 +00:00
import org.thoughtcrime.securesms.devicelist.Device;
import org.thoughtcrime.securesms.util.DateUtils;
import java.util.Locale;
2019-07-24 02:30:23 +00:00
import network.loki.messenger.R;
public class DeviceListItem extends LinearLayout {
2019-11-19 22:50:40 +00:00
private String deviceId;
private TextView name;
private TextView shortId;
public DeviceListItem(Context context) {
super(context);
}
public DeviceListItem(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void onFinishInflate() {
super.onFinishInflate();
this.name = (TextView) findViewById(R.id.name);
this.shortId = (TextView) findViewById(R.id.shortId);
}
2018-12-19 16:09:22 +00:00
public void set(Device deviceInfo, Locale locale) {
this.deviceId = deviceInfo.getId();
boolean hasName = !TextUtils.isEmpty(deviceInfo.getName());
this.name.setText(hasName ? deviceInfo.getName() : deviceInfo.getShortId());
this.shortId.setText(deviceInfo.getShortId());
this.shortId.setVisibility(hasName ? VISIBLE : GONE);
}
2019-11-19 22:50:40 +00:00
public String getDeviceId() {
return deviceId;
}
public String getDeviceName() {
return name.getText().toString();
}
2019-11-20 23:50:33 +00:00
public boolean hasDeviceName() {
return shortId.getVisibility() == VISIBLE;
}
}