|
1 | 1 | package net.qiujuer.powerback.ankey.ui.activity; |
2 | 2 |
|
| 3 | +import android.content.Context; |
| 4 | +import android.content.Intent; |
3 | 5 | import android.os.Bundle; |
| 6 | +import android.text.Editable; |
| 7 | +import android.text.Selection; |
| 8 | +import android.text.TextUtils; |
| 9 | +import android.view.View; |
4 | 10 |
|
| 11 | +import net.qiujuer.genius.ui.widget.EditText; |
5 | 12 | import net.qiujuer.powerback.ankey.R; |
6 | | -import net.qiujuer.powerback.ankey.ui.SuperBackActivity; |
| 13 | +import net.qiujuer.powerback.ankey.model.AppModel; |
| 14 | +import net.qiujuer.powerback.ankey.presenter.EditPresenter; |
| 15 | +import net.qiujuer.powerback.ankey.presenter.view.EditView; |
7 | 16 |
|
8 | | -public class EditActivity extends SuperBackActivity { |
| 17 | +import java.util.UUID; |
| 18 | + |
| 19 | +/** |
| 20 | + * Created by qiujuer |
| 21 | + */ |
| 22 | +public class EditActivity extends CreateActivity implements EditView { |
| 23 | + private static final String KEY_INFO_ID = "info_id"; |
| 24 | + private EditPresenter mPresenter; |
| 25 | + private UUID mId; |
| 26 | + |
| 27 | + public static void show(Context context, UUID id) { |
| 28 | + Intent intent = new Intent(context, EditActivity.class); |
| 29 | + intent.putExtra(KEY_INFO_ID, id.toString()); |
| 30 | + context.startActivity(intent); |
| 31 | + } |
9 | 32 |
|
10 | 33 | @Override |
11 | 34 | protected void onCreate(Bundle savedInstanceState) { |
12 | 35 | super.onCreate(savedInstanceState); |
13 | | - setContentView(R.layout.activity_edit); |
| 36 | + |
| 37 | + if (initId()) |
| 38 | + mPresenter.load(); |
| 39 | + else |
| 40 | + finish(); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + protected void initPresenter() { |
| 45 | + mPresenter = new EditPresenter(this); |
| 46 | + } |
| 47 | + |
| 48 | + private boolean initId() { |
| 49 | + Intent intent = getIntent(); |
| 50 | + String id = intent.getStringExtra(KEY_INFO_ID); |
| 51 | + if (TextUtils.isEmpty(id)) |
| 52 | + return false; |
| 53 | + try { |
| 54 | + mId = UUID.fromString(id); |
| 55 | + } catch (Exception e) { |
| 56 | + e.printStackTrace(); |
| 57 | + return false; |
| 58 | + } |
| 59 | + return (mId != AppModel.EMPTY_ID); |
| 60 | + } |
| 61 | + |
| 62 | + private void setEnterText(int id, String value) { |
| 63 | + if (TextUtils.isEmpty(value)) |
| 64 | + return; |
| 65 | + EditText text = ((EditText) findViewById(id)); |
| 66 | + if (text != null) { |
| 67 | + text.requestFocus(); |
| 68 | + text.setText(value); |
| 69 | + |
| 70 | + Editable editable = text.getText(); |
| 71 | + Selection.setSelection(editable, editable.length()); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + |
| 76 | + @Override |
| 77 | + public void onClick(View v) { |
| 78 | + EditPresenter presenter = mPresenter; |
| 79 | + if (presenter == null) |
| 80 | + return; |
| 81 | + if (v.getId() == R.id.action_submit) { |
| 82 | + mPresenter.submit(); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public void setDescription(String value) { |
| 88 | + setEnterText(R.id.edit_description, value); |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public void setPassword(String value) { |
| 93 | + setEnterText(R.id.edit_password, value); |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public void setUsername(String value) { |
| 98 | + setEnterText(R.id.edit_username, value); |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + public void setSite(String value) { |
| 103 | + setEnterText(R.id.edit_site, value); |
| 104 | + } |
| 105 | + |
| 106 | + @Override |
| 107 | + public void setEmail(String value) { |
| 108 | + setEnterText(R.id.edit_email, value); |
| 109 | + } |
| 110 | + |
| 111 | + @Override |
| 112 | + public void setQQ(String value) { |
| 113 | + setEnterText(R.id.edit_qq, value); |
| 114 | + } |
| 115 | + |
| 116 | + @Override |
| 117 | + public void setCall(String value) { |
| 118 | + setEnterText(R.id.edit_call, value); |
| 119 | + } |
| 120 | + |
| 121 | + @Override |
| 122 | + public void setRemarks(String value) { |
| 123 | + setEnterText(R.id.edit_remark, value); |
| 124 | + } |
| 125 | + |
| 126 | + @Override |
| 127 | + public void setColor(int color) { |
| 128 | + |
| 129 | + } |
| 130 | + |
| 131 | + @Override |
| 132 | + public UUID getInfoId() { |
| 133 | + return mId; |
| 134 | + } |
| 135 | + |
| 136 | + @Override |
| 137 | + public Context getContext() { |
| 138 | + return this; |
14 | 139 | } |
15 | 140 | } |
0 commit comments