ported presence activity to cardview

This commit is contained in:
Daniel Gultsch 2018-02-18 09:26:12 +01:00
parent d0e58330e9
commit 5ebcb1ae71
7 changed files with 148 additions and 190 deletions

View file

@ -1,6 +1,7 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import android.content.Intent; import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.util.Pair; import android.util.Pair;
@ -21,6 +22,7 @@ import android.widget.TextView;
import java.util.List; import java.util.List;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.ActivitySetPresenceBinding;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.ListItem; import eu.siacs.conversations.entities.ListItem;
import eu.siacs.conversations.entities.Presence; import eu.siacs.conversations.entities.Presence;
@ -33,12 +35,8 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis
protected Account mAccount; protected Account mAccount;
private List<PresenceTemplate> mTemplates; private List<PresenceTemplate> mTemplates;
//UI Elements private ActivitySetPresenceBinding binding;
protected ScrollView mScrollView;
protected EditText mStatusMessage;
protected Spinner mShowSpinner;
protected CheckBox mAllAccounts;
protected LinearLayout mTemplatesView;
private Pair<Integer, Intent> mPostponedActivityResult; private Pair<Integer, Intent> mPostponedActivityResult;
private Runnable onPresenceChanged = new Runnable() { private Runnable onPresenceChanged = new Runnable() {
@ -50,24 +48,13 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_presence); this.binding = DataBindingUtil.setContentView(this,R.layout.activity_set_presence);
mScrollView = (ScrollView) findViewById(R.id.scroll_view);
mShowSpinner = (Spinner) findViewById(R.id.presence_show);
ArrayAdapter adapter = ArrayAdapter.createFromResource(this, ArrayAdapter adapter = ArrayAdapter.createFromResource(this,
R.array.presence_show_options, R.array.presence_show_options,
R.layout.simple_list_item); R.layout.simple_list_item);
mShowSpinner.setAdapter(adapter); this.binding.presenceShow.setAdapter(adapter);
mShowSpinner.setSelection(1); this.binding.presenceShow.setSelection(1);
mStatusMessage = (EditText) findViewById(R.id.presence_status_message); this.binding.changePresence.setOnClickListener(v -> executeChangePresence());
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();
}
});
} }
@Override @Override
@ -105,8 +92,8 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis
private void executeChangePresence() { private void executeChangePresence() {
Presence.Status status = getStatusFromSpinner(); Presence.Status status = getStatusFromSpinner();
boolean allAccounts = mAllAccounts.isChecked(); boolean allAccounts = this.binding.allAccounts.isChecked();
String statusMessage = mStatusMessage.getText().toString().trim(); String statusMessage = this.binding.presenceStatusMessage.getText().toString().trim();
if (allAccounts && noAccountUsesPgp()) { if (allAccounts && noAccountUsesPgp()) {
xmppConnectionService.changeStatus(status, statusMessage); xmppConnectionService.changeStatus(status, statusMessage);
finish(); finish();
@ -122,7 +109,7 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis
} }
private Presence.Status getStatusFromSpinner() { private Presence.Status getStatusFromSpinner() {
switch (mShowSpinner.getSelectedItemPosition()) { switch (this.binding.presenceShow.getSelectedItemPosition()) {
case 0: case 0:
return Presence.Status.CHAT; return Presence.Status.CHAT;
case 2: case 2:
@ -139,19 +126,19 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis
private void setStatusInSpinner(Presence.Status status) { private void setStatusInSpinner(Presence.Status status) {
switch(status) { switch(status) {
case AWAY: case AWAY:
mShowSpinner.setSelection(2); this.binding.presenceShow.setSelection(2);
break; break;
case XA: case XA:
mShowSpinner.setSelection(3); this.binding.presenceShow.setSelection(3);
break; break;
case CHAT: case CHAT:
mShowSpinner.setSelection(0); this.binding.presenceShow.setSelection(0);
break; break;
case DND: case DND:
mShowSpinner.setSelection(4); this.binding.presenceShow.setSelection(4);
break; break;
default: default:
mShowSpinner.setSelection(1); this.binding.presenceShow.setSelection(1);
break; break;
} }
} }
@ -167,29 +154,29 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis
if (mAccount != null) { if (mAccount != null) {
setStatusInSpinner(mAccount.getPresenceStatus()); setStatusInSpinner(mAccount.getPresenceStatus());
String message = mAccount.getPresenceStatusMessage(); String message = mAccount.getPresenceStatusMessage();
if (mStatusMessage.getText().length() == 0 && message != null) { if (this.binding.presenceStatusMessage.getText().length() == 0 && message != null) {
mStatusMessage.append(message); this.binding.presenceStatusMessage.append(message);
} }
mTemplates = xmppConnectionService.getPresenceTemplates(mAccount); mTemplates = xmppConnectionService.getPresenceTemplates(mAccount);
if (this.mPostponedActivityResult != null) { if (this.mPostponedActivityResult != null) {
this.onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second); this.onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second);
} }
boolean e = noAccountUsesPgp(); boolean e = noAccountUsesPgp();
mAllAccounts.setEnabled(e); this.binding.allAccounts.setEnabled(e);
mAllAccounts.setTextColor(e ? getPrimaryTextColor() : getSecondaryTextColor()); this.binding.allAccounts.setTextColor(e ? getPrimaryTextColor() : getSecondaryTextColor());
} }
redrawTemplates(); redrawTemplates();
} }
private void redrawTemplates() { private void redrawTemplates() {
if (mTemplates == null || mTemplates.size() == 0) { if (mTemplates == null || mTemplates.size() == 0) {
mTemplatesView.setVisibility(View.GONE); this.binding.templatesCard.setVisibility(View.GONE);
} else { } else {
mTemplatesView.removeAllViews(); this.binding.templates.removeAllViews();
mTemplatesView.setVisibility(View.VISIBLE); this.binding.templatesCard.setVisibility(View.VISIBLE);
LayoutInflater inflater = getLayoutInflater(); LayoutInflater inflater = getLayoutInflater();
for (PresenceTemplate template : mTemplates) { 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); templateLayout.setTag(template);
setListItemBackgroundOnView(templateLayout); setListItemBackgroundOnView(templateLayout);
templateLayout.setOnClickListener(this); templateLayout.setOnClickListener(this);
@ -202,7 +189,7 @@ public class SetPresenceActivity extends XmppActivity implements View.OnClickLis
status.setText(tag.getName()); status.setText(tag.getName());
status.setBackgroundColor(tag.getColor()); status.setBackgroundColor(tag.getColor());
message.setText(template.getStatusMessage()); 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) { if (v.getId() == R.id.presence_template) {
setStatusInSpinner(template.getStatus()); setStatusInSpinner(template.getStatus());
mStatusMessage.getEditableText().clear(); this.binding.presenceStatusMessage.getEditableText().clear();
mStatusMessage.getEditableText().append(template.getStatusMessage()); this.binding.presenceStatusMessage.getEditableText().append(template.getStatusMessage());
new Handler().post(new Runnable() { new Handler().post(() -> this.binding.scrollView.smoothScrollTo(0,0));
@Override
public void run() {
mScrollView.smoothScrollTo(0,0);
}
});
} else if (v.getId() == R.id.delete_button) { } else if (v.getId() == R.id.delete_button) {
xmppConnectionService.databaseBackend.deletePresenceTemplate(template); xmppConnectionService.databaseBackend.deletePresenceTemplate(template);
mTemplates.remove(template); mTemplates.remove(template);

View file

@ -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>

View file

@ -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>

View file

@ -10,14 +10,17 @@
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_above="@+id/button_bar"> android:layout_above="@+id/button_bar">
<LinearLayout <android.support.v7.widget.CardView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_vertical_margin" android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin" android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin" android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin" android:layout_marginTop="@dimen/activity_vertical_margin">
android:background="?attr/infocard_border"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:padding="@dimen/infocard_padding"> android:padding="@dimen/infocard_padding">
@ -59,8 +62,8 @@
android:textColorHint="?attr/color_text_secondary" android:textColorHint="?attr/color_text_secondary"
android:textSize="?attr/TextSizeBody"/> android:textSize="?attr/TextSizeBody"/>
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView>
</ScrollView> </ScrollView>
<LinearLayout <LinearLayout

View file

@ -1,72 +1,86 @@
<?xml version="1.0" encoding="utf-8"?> <?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_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:background="?attr/color_background_secondary" android:background="?attr/color_background_secondary">
android:id="@+id/scroll_view">
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> 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 <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin" android:orientation="vertical"
android:layout_marginRight="@dimen/activity_horizontal_margin" android:padding="@dimen/infocard_padding">
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">
<EditText <EditText
android:id="@+id/presence_status_message"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" 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:layout_marginBottom="8dp"
android:textSize="?attr/TextSizeBody"/> android:hint="@string/status_message"
<Spinner android:inputType="textMultiLine"
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:textColor="?attr/color_text_primary" android:textColor="?attr/color_text_primary"
android:textSize="?attr/TextSizeBody"/> 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 <Button
android:id="@+id/change_presence" android:id="@+id/change_presence"
style="?android:attr/borderlessButtonStyle" style="?android:attr/borderlessButtonStyle"
android:layout_marginRight="-8dp"
android:layout_marginBottom="-8dp"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="right" android:layout_gravity="right"
android:layout_marginBottom="-8dp"
android:layout_marginRight="-8dp"
android:text="@string/change_presence" android:text="@string/change_presence"
android:textColor="@color/accent"/> android:textColor="@color/accent"/>
</LinearLayout> </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 <LinearLayout
android:id="@+id/templates" android:id="@+id/templates"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" 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:divider="?android:dividerHorizontal" android:padding="@dimen/infocard_padding"/>
android:showDividers="middle"> </android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
</layout>

View file

@ -14,7 +14,6 @@
<attr name="color_background_secondary" format="reference|color" /> <attr name="color_background_secondary" format="reference|color" />
<attr name="color_background_primary" 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_cancel_offline" format="reference"/>
<attr name="ic_send_location_offline" format="reference"/> <attr name="ic_send_location_offline" format="reference"/>
<attr name="ic_send_photo_offline" format="reference"/> <attr name="ic_send_photo_offline" format="reference"/>

View file

@ -21,7 +21,6 @@
<item name="IconSize">18sp</item> <item name="IconSize">18sp</item>
<item name="TextSizeHeadline">20sp</item> <item name="TextSizeHeadline">20sp</item>
<item type="reference" name="infocard_border">@drawable/infocard_border</item>
<item name="divider">@color/black12</item> <item name="divider">@color/black12</item>
<item type="reference" name="ic_send_cancel_offline">@drawable/ic_send_cancel_offline</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="IconSize">18sp</item>
<item name="TextSizeHeadline">20sp</item> <item name="TextSizeHeadline">20sp</item>
<item type="reference" name="infocard_border">@drawable/infocard_border_dark</item>
<item name="divider">@color/white12</item> <item name="divider">@color/white12</item>
<item type="reference" name="ic_send_cancel_offline">@drawable/ic_send_cancel_offline_white</item> <item type="reference" name="ic_send_cancel_offline">@drawable/ic_send_cancel_offline_white</item>