ported presence activity to cardview
This commit is contained in:
parent
d0e58330e9
commit
5ebcb1ae71
|
@ -1,6 +1,7 @@
|
|||
package eu.siacs.conversations.ui;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Pair;
|
||||
|
@ -21,6 +22,7 @@ import android.widget.TextView;
|
|||
import java.util.List;
|
||||
|
||||
import eu.siacs.conversations.R;
|
||||
import eu.siacs.conversations.databinding.ActivitySetPresenceBinding;
|
||||
import eu.siacs.conversations.entities.Account;
|
||||
import eu.siacs.conversations.entities.ListItem;
|
||||
import eu.siacs.conversations.entities.Presence;
|
||||
|
@ -33,12 +35,8 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis
|
|||
protected Account mAccount;
|
||||
private List<PresenceTemplate> mTemplates;
|
||||
|
||||
//UI Elements
|
||||
protected ScrollView mScrollView;
|
||||
protected EditText mStatusMessage;
|
||||
protected Spinner mShowSpinner;
|
||||
protected CheckBox mAllAccounts;
|
||||
protected LinearLayout mTemplatesView;
|
||||
private ActivitySetPresenceBinding binding;
|
||||
|
||||
private Pair<Integer, Intent> mPostponedActivityResult;
|
||||
|
||||
private Runnable onPresenceChanged = new Runnable() {
|
||||
|
@ -50,24 +48,13 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis
|
|||
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_set_presence);
|
||||
mScrollView = (ScrollView) findViewById(R.id.scroll_view);
|
||||
mShowSpinner = (Spinner) findViewById(R.id.presence_show);
|
||||
this.binding = DataBindingUtil.setContentView(this,R.layout.activity_set_presence);
|
||||
ArrayAdapter adapter = ArrayAdapter.createFromResource(this,
|
||||
R.array.presence_show_options,
|
||||
R.layout.simple_list_item);
|
||||
mShowSpinner.setAdapter(adapter);
|
||||
mShowSpinner.setSelection(1);
|
||||
mStatusMessage = (EditText) findViewById(R.id.presence_status_message);
|
||||
mAllAccounts = (CheckBox) findViewById(R.id.all_accounts);
|
||||
mTemplatesView = (LinearLayout) findViewById(R.id.templates);
|
||||
final Button changePresence = (Button) findViewById(R.id.change_presence);
|
||||
changePresence.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
executeChangePresence();
|
||||
}
|
||||
});
|
||||
this.binding.presenceShow.setAdapter(adapter);
|
||||
this.binding.presenceShow.setSelection(1);
|
||||
this.binding.changePresence.setOnClickListener(v -> executeChangePresence());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -105,8 +92,8 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis
|
|||
|
||||
private void executeChangePresence() {
|
||||
Presence.Status status = getStatusFromSpinner();
|
||||
boolean allAccounts = mAllAccounts.isChecked();
|
||||
String statusMessage = mStatusMessage.getText().toString().trim();
|
||||
boolean allAccounts = this.binding.allAccounts.isChecked();
|
||||
String statusMessage = this.binding.presenceStatusMessage.getText().toString().trim();
|
||||
if (allAccounts && noAccountUsesPgp()) {
|
||||
xmppConnectionService.changeStatus(status, statusMessage);
|
||||
finish();
|
||||
|
@ -122,7 +109,7 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis
|
|||
}
|
||||
|
||||
private Presence.Status getStatusFromSpinner() {
|
||||
switch (mShowSpinner.getSelectedItemPosition()) {
|
||||
switch (this.binding.presenceShow.getSelectedItemPosition()) {
|
||||
case 0:
|
||||
return Presence.Status.CHAT;
|
||||
case 2:
|
||||
|
@ -139,19 +126,19 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis
|
|||
private void setStatusInSpinner(Presence.Status status) {
|
||||
switch(status) {
|
||||
case AWAY:
|
||||
mShowSpinner.setSelection(2);
|
||||
this.binding.presenceShow.setSelection(2);
|
||||
break;
|
||||
case XA:
|
||||
mShowSpinner.setSelection(3);
|
||||
this.binding.presenceShow.setSelection(3);
|
||||
break;
|
||||
case CHAT:
|
||||
mShowSpinner.setSelection(0);
|
||||
this.binding.presenceShow.setSelection(0);
|
||||
break;
|
||||
case DND:
|
||||
mShowSpinner.setSelection(4);
|
||||
this.binding.presenceShow.setSelection(4);
|
||||
break;
|
||||
default:
|
||||
mShowSpinner.setSelection(1);
|
||||
this.binding.presenceShow.setSelection(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -167,29 +154,29 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis
|
|||
if (mAccount != null) {
|
||||
setStatusInSpinner(mAccount.getPresenceStatus());
|
||||
String message = mAccount.getPresenceStatusMessage();
|
||||
if (mStatusMessage.getText().length() == 0 && message != null) {
|
||||
mStatusMessage.append(message);
|
||||
if (this.binding.presenceStatusMessage.getText().length() == 0 && message != null) {
|
||||
this.binding.presenceStatusMessage.append(message);
|
||||
}
|
||||
mTemplates = xmppConnectionService.getPresenceTemplates(mAccount);
|
||||
if (this.mPostponedActivityResult != null) {
|
||||
this.onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second);
|
||||
}
|
||||
boolean e = noAccountUsesPgp();
|
||||
mAllAccounts.setEnabled(e);
|
||||
mAllAccounts.setTextColor(e ? getPrimaryTextColor() : getSecondaryTextColor());
|
||||
this.binding.allAccounts.setEnabled(e);
|
||||
this.binding.allAccounts.setTextColor(e ? getPrimaryTextColor() : getSecondaryTextColor());
|
||||
}
|
||||
redrawTemplates();
|
||||
}
|
||||
|
||||
private void redrawTemplates() {
|
||||
if (mTemplates == null || mTemplates.size() == 0) {
|
||||
mTemplatesView.setVisibility(View.GONE);
|
||||
this.binding.templatesCard.setVisibility(View.GONE);
|
||||
} else {
|
||||
mTemplatesView.removeAllViews();
|
||||
mTemplatesView.setVisibility(View.VISIBLE);
|
||||
this.binding.templates.removeAllViews();
|
||||
this.binding.templatesCard.setVisibility(View.VISIBLE);
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
for (PresenceTemplate template : mTemplates) {
|
||||
View templateLayout = inflater.inflate(R.layout.presence_template, mTemplatesView, false);
|
||||
View templateLayout = inflater.inflate(R.layout.presence_template, this.binding.templates, false);
|
||||
templateLayout.setTag(template);
|
||||
setListItemBackgroundOnView(templateLayout);
|
||||
templateLayout.setOnClickListener(this);
|
||||
|
@ -202,7 +189,7 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis
|
|||
status.setText(tag.getName());
|
||||
status.setBackgroundColor(tag.getColor());
|
||||
message.setText(template.getStatusMessage());
|
||||
mTemplatesView.addView(templateLayout);
|
||||
this.binding.templates.addView(templateLayout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -215,14 +202,9 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis
|
|||
}
|
||||
if (v.getId() == R.id.presence_template) {
|
||||
setStatusInSpinner(template.getStatus());
|
||||
mStatusMessage.getEditableText().clear();
|
||||
mStatusMessage.getEditableText().append(template.getStatusMessage());
|
||||
new Handler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mScrollView.smoothScrollTo(0,0);
|
||||
}
|
||||
});
|
||||
this.binding.presenceStatusMessage.getEditableText().clear();
|
||||
this.binding.presenceStatusMessage.getEditableText().append(template.getStatusMessage());
|
||||
new Handler().post(() -> this.binding.scrollView.smoothScrollTo(0,0));
|
||||
} else if (v.getId() == R.id.delete_button) {
|
||||
xmppConnectionService.databaseBackend.deletePresenceTemplate(template);
|
||||
mTemplates.remove(template);
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<solid android:color="@color/grey50" />
|
||||
|
||||
<corners android:radius="2dp" />
|
||||
|
||||
<stroke
|
||||
android:width="0.5dp"
|
||||
android:color="@color/black12" >
|
||||
</stroke>
|
||||
|
||||
<padding
|
||||
android:bottom="0dp"
|
||||
android:left="0dp"
|
||||
android:right="0dp"
|
||||
android:top="0dp" />
|
||||
|
||||
</shape>
|
|
@ -1,19 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<solid android:color="@color/grey800" />
|
||||
|
||||
<corners android:radius="2dp" />
|
||||
|
||||
<stroke
|
||||
android:width="0.5dp"
|
||||
android:color="@color/grey900" >
|
||||
</stroke>
|
||||
|
||||
<padding
|
||||
android:bottom="0dp"
|
||||
android:left="0dp"
|
||||
android:right="0dp"
|
||||
android:top="0dp" />
|
||||
|
||||
</shape>
|
|
@ -10,14 +10,17 @@
|
|||
android:layout_height="fill_parent"
|
||||
android:layout_above="@+id/button_bar">
|
||||
|
||||
<LinearLayout
|
||||
<android.support.v7.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/activity_vertical_margin"
|
||||
android:layout_marginLeft="@dimen/activity_horizontal_margin"
|
||||
android:layout_marginRight="@dimen/activity_horizontal_margin"
|
||||
android:layout_marginTop="@dimen/activity_vertical_margin"
|
||||
android:background="?attr/infocard_border"
|
||||
android:layout_marginTop="@dimen/activity_vertical_margin">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/infocard_padding">
|
||||
|
||||
|
@ -59,8 +62,8 @@
|
|||
android:textColorHint="?attr/color_text_secondary"
|
||||
android:textSize="?attr/TextSizeBody"/>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
</ScrollView>
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
@ -1,72 +1,86 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/scroll_view"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:background="?attr/color_background_secondary"
|
||||
android:id="@+id/scroll_view">
|
||||
android:background="?attr/color_background_secondary">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/activity_vertical_margin"
|
||||
android:layout_marginLeft="@dimen/activity_horizontal_margin"
|
||||
android:layout_marginRight="@dimen/activity_horizontal_margin"
|
||||
android:layout_marginTop="@dimen/activity_vertical_margin">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/activity_horizontal_margin"
|
||||
android:layout_marginRight="@dimen/activity_horizontal_margin"
|
||||
android:layout_marginTop="@dimen/activity_vertical_margin"
|
||||
android:layout_marginBottom="@dimen/activity_vertical_margin"
|
||||
android:background="?attr/infocard_border"
|
||||
android:padding="@dimen/infocard_padding"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/infocard_padding">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/presence_status_message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textMultiLine"
|
||||
android:hint="@string/status_message"
|
||||
android:id="@+id/presence_status_message"
|
||||
android:textColor="?attr/color_text_primary"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:textSize="?attr/TextSizeBody"/>
|
||||
<Spinner
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/presence_show"
|
||||
android:layout_gravity="center_horizontal"/>
|
||||
<CheckBox
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/all_accounts_on_this_device"
|
||||
android:id="@+id/all_accounts"
|
||||
android:hint="@string/status_message"
|
||||
android:inputType="textMultiLine"
|
||||
android:textColor="?attr/color_text_primary"
|
||||
android:textSize="?attr/TextSizeBody"/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/presence_show"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"/>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/all_accounts"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/all_accounts_on_this_device"
|
||||
android:textColor="?attr/color_text_primary"
|
||||
android:textSize="?attr/TextSizeBody"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/change_presence"
|
||||
style="?android:attr/borderlessButtonStyle"
|
||||
android:layout_marginRight="-8dp"
|
||||
android:layout_marginBottom="-8dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginBottom="-8dp"
|
||||
android:layout_marginRight="-8dp"
|
||||
android:text="@string/change_presence"
|
||||
android:textColor="@color/accent"/>
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:id="@+id/templates_card"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/activity_vertical_margin"
|
||||
android:layout_marginLeft="@dimen/activity_horizontal_margin"
|
||||
android:layout_marginRight="@dimen/activity_horizontal_margin"
|
||||
android:layout_marginTop="@dimen/activity_vertical_margin">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/templates"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/activity_horizontal_margin"
|
||||
android:layout_marginRight="@dimen/activity_horizontal_margin"
|
||||
android:layout_marginTop="@dimen/activity_vertical_margin"
|
||||
android:layout_marginBottom="@dimen/activity_vertical_margin"
|
||||
android:background="?attr/infocard_border"
|
||||
android:padding="@dimen/infocard_padding"
|
||||
android:orientation="vertical"
|
||||
android:divider="?android:dividerHorizontal"
|
||||
android:showDividers="middle">
|
||||
</LinearLayout>
|
||||
android:padding="@dimen/infocard_padding"/>
|
||||
</android.support.v7.widget.CardView>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</layout>
|
|
@ -14,7 +14,6 @@
|
|||
<attr name="color_background_secondary" format="reference|color" />
|
||||
<attr name="color_background_primary" format="reference|color" />
|
||||
|
||||
<attr name="infocard_border" format="reference"/>
|
||||
<attr name="ic_send_cancel_offline" format="reference"/>
|
||||
<attr name="ic_send_location_offline" format="reference"/>
|
||||
<attr name="ic_send_photo_offline" format="reference"/>
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
<item name="IconSize">18sp</item>
|
||||
<item name="TextSizeHeadline">20sp</item>
|
||||
|
||||
<item type="reference" name="infocard_border">@drawable/infocard_border</item>
|
||||
<item name="divider">@color/black12</item>
|
||||
|
||||
<item type="reference" name="ic_send_cancel_offline">@drawable/ic_send_cancel_offline</item>
|
||||
|
@ -101,7 +100,6 @@
|
|||
<item name="IconSize">18sp</item>
|
||||
<item name="TextSizeHeadline">20sp</item>
|
||||
|
||||
<item type="reference" name="infocard_border">@drawable/infocard_border_dark</item>
|
||||
<item name="divider">@color/white12</item>
|
||||
|
||||
<item type="reference" name="ic_send_cancel_offline">@drawable/ic_send_cancel_offline_white</item>
|
||||
|
|
Loading…
Reference in a new issue