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

@ -1,66 +1,69 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/color_background_secondary"> android:background="?attr/color_background_secondary">
<ScrollView <ScrollView
android:layout_width="fill_parent" android:layout_width="fill_parent"
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"
android:orientation="vertical"
android:padding="@dimen/infocard_padding">
<LinearLayout
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:passwordToggleDrawable="@drawable/visibility_toggle_drawable" android:orientation="vertical"
app:passwordToggleEnabled="true" android:padding="@dimen/infocard_padding">
app:passwordToggleTint="?attr/color_text_secondary">
<android.support.design.widget.TextInputEditText
android:id="@+id/current_password" <android.support.design.widget.TextInputLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentTop="true" app:passwordToggleDrawable="@drawable/visibility_toggle_drawable"
android:hint="@string/current_password" app:passwordToggleEnabled="true"
android:inputType="textPassword" app:passwordToggleTint="?attr/color_text_secondary">
android:textColor="?attr/color_text_primary"
android:textColorHint="?attr/color_text_secondary"
android:textSize="?attr/TextSizeBody" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout <android.support.design.widget.TextInputEditText
android:layout_width="match_parent" android:id="@+id/current_password"
android:layout_height="wrap_content" android:layout_width="match_parent"
app:passwordToggleDrawable="@drawable/visibility_toggle_drawable" android:layout_height="wrap_content"
app:passwordToggleEnabled="true" android:layout_alignParentTop="true"
app:passwordToggleTint="?attr/color_text_secondary"> android:hint="@string/current_password"
android:inputType="textPassword"
android:textColor="?attr/color_text_primary"
android:textColorHint="?attr/color_text_secondary"
android:textSize="?attr/TextSizeBody"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputEditText <android.support.design.widget.TextInputLayout
android:id="@+id/new_password"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentTop="true" app:passwordToggleDrawable="@drawable/visibility_toggle_drawable"
android:hint="@string/new_password" app:passwordToggleEnabled="true"
android:inputType="textPassword" app:passwordToggleTint="?attr/color_text_secondary">
android:textColor="?attr/color_text_primary"
android:textColorHint="?attr/color_text_secondary"
android:textSize="?attr/TextSizeBody" />
</android.support.design.widget.TextInputLayout>
</LinearLayout> <android.support.design.widget.TextInputEditText
android:id="@+id/new_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:hint="@string/new_password"
android:inputType="textPassword"
android:textColor="?attr/color_text_primary"
android:textColorHint="?attr/color_text_secondary"
android:textSize="?attr/TextSizeBody"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</ScrollView> </ScrollView>
<LinearLayout <LinearLayout
@ -77,14 +80,14 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/cancel" /> android:text="@string/cancel"/>
<View <View
android:layout_width="1dp" android:layout_width="1dp"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_marginBottom="7dp" android:layout_marginBottom="7dp"
android:layout_marginTop="7dp" android:layout_marginTop="7dp"
android:background="?attr/divider" /> android:background="?attr/divider"/>
<Button <Button
android:id="@+id/right_button" android:id="@+id/right_button"
@ -92,7 +95,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="@string/change_password" /> android:text="@string/change_password"/>
</LinearLayout> </LinearLayout>
</RelativeLayout> </RelativeLayout>

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">
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="?attr/color_background_secondary"
android:id="@+id/scroll_view">
<LinearLayout <ScrollView
android:id="@+id/scroll_view"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="fill_parent"
android:orientation="vertical"> android:background="?attr/color_background_secondary">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="fill_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">
<EditText
<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:inputType="textMultiLine" android:layout_marginBottom="@dimen/activity_vertical_margin"
android:hint="@string/status_message" android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:id="@+id/presence_status_message" android:layout_marginRight="@dimen/activity_horizontal_margin"
android:textColor="?attr/color_text_primary" android:layout_marginTop="@dimen/activity_vertical_margin">
android:layout_marginBottom="8dp"
android:textSize="?attr/TextSizeBody"/> <LinearLayout
<Spinner android:layout_width="match_parent"
android:layout_width="wrap_content" android:layout_height="wrap_content"
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:layout_marginBottom="8dp"
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_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_height="wrap_content"
android:id="@+id/presence_show" android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_gravity="center_horizontal"/> android:layout_marginLeft="@dimen/activity_horizontal_margin"
<CheckBox android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="16dp" android:layout_marginTop="@dimen/activity_vertical_margin">
android:layout_marginBottom="16dp"
android:layout_width="wrap_content" <LinearLayout
android:layout_height="wrap_content" android:id="@+id/templates"
android:text="@string/all_accounts_on_this_device" android:layout_width="match_parent"
android:id="@+id/all_accounts" android:layout_height="wrap_content"
android:textColor="?attr/color_text_primary" android:orientation="vertical"
android:textSize="?attr/TextSizeBody"/> android:padding="@dimen/infocard_padding"/>
<Button </android.support.v7.widget.CardView>
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:text="@string/change_presence"
android:textColor="@color/accent"/>
</LinearLayout> </LinearLayout>
<LinearLayout </ScrollView>
android:id="@+id/templates" </layout>
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>
</LinearLayout>
</ScrollView>

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>