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 08:09:22 -08:00
import org.thoughtcrime.securesms.devicelist.Device;
import org.thoughtcrime.securesms.util.DateUtils;
import java.util.Locale;
2019-07-24 12:30:23 +10:00
import network.loki.messenger.R;
public class DeviceListItem extends LinearLayout {
2019-11-20 09:50:40 +11: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 08:09:22 -08: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-20 09:50:40 +11:00
public String getDeviceId() {
return deviceId;
}
public String getDeviceName() {
return name.getText().toString();
}
2019-11-21 10:50:33 +11:00
public boolean hasDeviceName() {
return shortId.getVisibility() == VISIBLE;
}
}