peterluo3131 commited on
Commit
120c455
·
1 Parent(s): ce1af5f

feature(#99): complete UI/UX that composes mail

Browse files
Android/app/src/main/java/com/matthaigh27/chatgptwrapper/ui/chat/view/widgets/chatwidget/mail/compose/ComposeMailWidget.kt ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package com.matthaigh27.chatgptwrapper.ui.chat.view.widgets.chatwidget.mail.compose
2
+
3
+ import android.content.Context
4
+ import android.util.AttributeSet
5
+ import android.view.KeyEvent
6
+ import android.view.LayoutInflater
7
+ import android.view.View
8
+ import android.view.ViewGroup
9
+ import android.widget.ImageView
10
+ import androidx.constraintlayout.widget.ConstraintLayout
11
+ import com.google.android.material.chip.Chip
12
+ import com.google.android.material.chip.ChipGroup
13
+ import com.google.android.material.textfield.TextInputLayout
14
+ import com.matthaigh27.chatgptwrapper.R
15
+ import com.matthaigh27.chatgptwrapper.ui.chat.view.interfaces.ChatMessageInterface
16
+ import com.matthaigh27.chatgptwrapper.utils.helpers.chat.MailHelper.isGmail
17
+
18
+ class ComposeMailWidget(
19
+ context: Context, attrs: AttributeSet? = null
20
+ ) : ConstraintLayout(context, attrs), View.OnClickListener {
21
+
22
+ private var context: Context
23
+ var callback: ChatMessageInterface? = null
24
+
25
+ private var edtMailTo: TextInputLayout
26
+ private var edtMailSubject: TextInputLayout
27
+ private var edtMailContent: TextInputLayout
28
+ private var mailChipGroup: ChipGroup
29
+ private var attachmentChipGroup: ChipGroup
30
+
31
+ init {
32
+ LayoutInflater.from(context).inflate(R.layout.widget_mail_compose, this, true)
33
+ this.context = context
34
+
35
+ layoutParams = LayoutParams(
36
+ ViewGroup.LayoutParams.MATCH_PARENT,
37
+ ViewGroup.LayoutParams.WRAP_CONTENT
38
+ )
39
+
40
+ this.setOnClickListener(this)
41
+ findViewById<ImageView>(R.id.btn_send).setOnClickListener(this)
42
+ findViewById<ImageView>(R.id.btn_send_cancel).setOnClickListener(this)
43
+ findViewById<ImageView>(R.id.btn_draft).setOnClickListener(this)
44
+ findViewById<ImageView>(R.id.btn_attachment).setOnClickListener(this)
45
+
46
+ mailChipGroup = findViewById(R.id.mail_chip_group)
47
+ attachmentChipGroup = findViewById(R.id.attachment_chip_group)
48
+ edtMailTo = findViewById(R.id.edt_mail_to)
49
+ edtMailSubject = findViewById(R.id.edt_mail_subject)
50
+ edtMailContent = findViewById(R.id.edt_mail_content)
51
+
52
+ edtMailTo.editText?.setOnKeyListener(View.OnKeyListener { _, keyCode, event ->
53
+ if (keyCode == KeyEvent.KEYCODE_ENTER && event.action == KeyEvent.ACTION_UP) {
54
+ // convert the text into a chip
55
+ createNewChip(edtMailTo.editText?.text.toString(), mailChipGroup)
56
+ // clear the text
57
+ edtMailTo.editText?.text?.clear()
58
+ return@OnKeyListener true
59
+ }
60
+ false
61
+ })
62
+ }
63
+
64
+ private fun createNewChip(chipText: String, chipGroup: ChipGroup) {
65
+ if (chipText.isNotEmpty() && isGmail(chipText)) {
66
+ val chip = Chip(context)
67
+ chip.text = chipText
68
+ chip.isCloseIconVisible = true
69
+
70
+ chip.setOnCloseIconClickListener { view ->
71
+ chipGroup.removeView(view)
72
+ }
73
+
74
+ chipGroup.addView(chip)
75
+ }
76
+ }
77
+
78
+ override fun onClick(view: View?) {
79
+
80
+ }
81
+ }
Android/app/src/main/java/com/matthaigh27/chatgptwrapper/utils/helpers/chat/MailHelper.kt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ package com.matthaigh27.chatgptwrapper.utils.helpers.chat
2
+
3
+ object MailHelper {
4
+ fun isGmail(email: String): Boolean {
5
+ return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches() && email.endsWith("@gmail.com")
6
+ }
7
+ }
Android/app/src/main/res/drawable/ic_attachment_48.xml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ <vector android:height="48dp" android:tint="#000000"
2
+ android:viewportHeight="24" android:viewportWidth="24"
3
+ android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
4
+ <path android:fillColor="@android:color/white" android:pathData="M2,12.5C2,9.46 4.46,7 7.5,7H18c2.21,0 4,1.79 4,4s-1.79,4 -4,4H9.5C8.12,15 7,13.88 7,12.5S8.12,10 9.5,10H17v2H9.41c-0.55,0 -0.55,1 0,1H18c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2H7.5C5.57,9 4,10.57 4,12.5S5.57,16 7.5,16H17v2H7.5C4.46,18 2,15.54 2,12.5z"/>
5
+ </vector>
Android/app/src/main/res/layout/activity_setting.xml CHANGED
@@ -53,7 +53,7 @@
53
 
54
  <com.google.android.material.textfield.TextInputLayout
55
  android:id="@+id/txt_uuid"
56
- style="@style/SettingEditText"
57
  android:layout_marginBottom="@dimen/spacing_tiny"
58
  android:enabled="false"
59
  android:hint="@string/label_setting_uuid">
@@ -66,7 +66,7 @@
66
 
67
  <com.google.android.material.textfield.TextInputLayout
68
  android:id="@+id/txt_openai_key"
69
- style="@style/SettingEditText"
70
  android:layout_marginBottom="@dimen/spacing_tiny"
71
  android:hint="@string/label_setting_openai_key">
72
 
@@ -78,7 +78,7 @@
78
 
79
  <com.google.android.material.textfield.TextInputLayout
80
  android:id="@+id/txt_pinecone_key"
81
- style="@style/SettingEditText"
82
  android:layout_marginBottom="@dimen/spacing_tiny"
83
  android:hint="@string/label_setting_pinecone_key">
84
 
@@ -90,7 +90,7 @@
90
 
91
  <com.google.android.material.textfield.TextInputLayout
92
  android:id="@+id/txt_pinecone_env"
93
- style="@style/SettingEditText"
94
  android:layout_marginBottom="@dimen/spacing_tiny"
95
  android:hint="@string/label_setting_pinecone_env">
96
 
@@ -102,7 +102,7 @@
102
 
103
  <com.google.android.material.textfield.TextInputLayout
104
  android:id="@+id/txt_firebase_key"
105
- style="@style/SettingEditText"
106
  android:hint="@string/label_setting_firebase_key"
107
  android:layout_marginBottom="@dimen/spacing_small">
108
 
@@ -118,7 +118,7 @@
118
 
119
  <com.google.android.material.textfield.TextInputLayout
120
  android:id="@+id/txt_temperature"
121
- style="@style/SettingEditText"
122
  android:layout_height="match_parent"
123
  android:hint="@string/label_setting_temperature">
124
 
 
53
 
54
  <com.google.android.material.textfield.TextInputLayout
55
  android:id="@+id/txt_uuid"
56
+ style="@style/CommonEditText"
57
  android:layout_marginBottom="@dimen/spacing_tiny"
58
  android:enabled="false"
59
  android:hint="@string/label_setting_uuid">
 
66
 
67
  <com.google.android.material.textfield.TextInputLayout
68
  android:id="@+id/txt_openai_key"
69
+ style="@style/CommonEditText"
70
  android:layout_marginBottom="@dimen/spacing_tiny"
71
  android:hint="@string/label_setting_openai_key">
72
 
 
78
 
79
  <com.google.android.material.textfield.TextInputLayout
80
  android:id="@+id/txt_pinecone_key"
81
+ style="@style/CommonEditText"
82
  android:layout_marginBottom="@dimen/spacing_tiny"
83
  android:hint="@string/label_setting_pinecone_key">
84
 
 
90
 
91
  <com.google.android.material.textfield.TextInputLayout
92
  android:id="@+id/txt_pinecone_env"
93
+ style="@style/CommonEditText"
94
  android:layout_marginBottom="@dimen/spacing_tiny"
95
  android:hint="@string/label_setting_pinecone_env">
96
 
 
102
 
103
  <com.google.android.material.textfield.TextInputLayout
104
  android:id="@+id/txt_firebase_key"
105
+ style="@style/CommonEditText"
106
  android:hint="@string/label_setting_firebase_key"
107
  android:layout_marginBottom="@dimen/spacing_small">
108
 
 
118
 
119
  <com.google.android.material.textfield.TextInputLayout
120
  android:id="@+id/txt_temperature"
121
+ style="@style/CommonEditText"
122
  android:layout_height="match_parent"
123
  android:hint="@string/label_setting_temperature">
124
 
Android/app/src/main/res/layout/widget_contact.xml CHANGED
@@ -45,6 +45,7 @@
45
  android:textColor="@color/color_accent"
46
  android:textSize="@dimen/font_normal"
47
  android:ellipsize="marquee"
 
48
  android:singleLine="true"
49
  android:marqueeRepeatLimit="marquee_forever"
50
  app:layout_constraintEnd_toEndOf="@+id/civ_avatar"
 
45
  android:textColor="@color/color_accent"
46
  android:textSize="@dimen/font_normal"
47
  android:ellipsize="marquee"
48
+ android:gravity="center"
49
  android:singleLine="true"
50
  android:marqueeRepeatLimit="marquee_forever"
51
  app:layout_constraintEnd_toEndOf="@+id/civ_avatar"
Android/app/src/main/res/layout/widget_mail_compose.xml ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+ xmlns:app="http://schemas.android.com/apk/res-auto"
4
+ android:layout_width="match_parent"
5
+ android:layout_height="wrap_content">
6
+
7
+ <androidx.cardview.widget.CardView
8
+ android:id="@+id/cv_mail_compose"
9
+ android:layout_width="match_parent"
10
+ android:layout_height="wrap_content"
11
+ app:cardBackgroundColor="@color/white"
12
+ app:cardCornerRadius="@dimen/radius_big"
13
+ app:cardPreventCornerOverlap="true"
14
+ app:cardUseCompatPadding="true"
15
+ app:layout_constraintTop_toTopOf="parent">
16
+
17
+ <LinearLayout
18
+ android:layout_width="match_parent"
19
+ android:layout_height="wrap_content"
20
+ android:orientation="vertical"
21
+ android:padding="@dimen/spacing_tiny">
22
+
23
+ <androidx.constraintlayout.widget.ConstraintLayout
24
+ android:layout_width="match_parent"
25
+ android:layout_height="wrap_content">
26
+
27
+ <TextView
28
+ android:id="@+id/txt_title"
29
+ android:layout_width="wrap_content"
30
+ android:layout_height="wrap_content"
31
+ android:text="@string/title_mail_compose"
32
+ android:textColor="@color/color_accent"
33
+ android:textSize="@dimen/font_big"
34
+ android:textStyle="bold"
35
+ app:layout_constraintBottom_toBottomOf="parent"
36
+ app:layout_constraintStart_toStartOf="parent"
37
+ app:layout_constraintTop_toTopOf="parent" />
38
+
39
+ <ImageView
40
+ android:id="@+id/btn_send"
41
+ android:layout_width="@dimen/size_button_normal"
42
+ android:layout_height="@dimen/size_button_normal"
43
+ android:padding="@dimen/spacing_tiny"
44
+ android:src="@drawable/ic_send"
45
+ app:layout_constraintBottom_toBottomOf="@+id/txt_title"
46
+ app:layout_constraintEnd_toEndOf="parent"
47
+ app:layout_constraintTop_toTopOf="@+id/txt_title"
48
+ app:tint="@color/color_accent" />
49
+
50
+ <ImageView
51
+ android:id="@+id/btn_attachment"
52
+ android:layout_width="@dimen/size_button_normal"
53
+ android:layout_height="@dimen/size_button_normal"
54
+ android:padding="@dimen/spacing_tiny"
55
+ android:src="@drawable/ic_attachment_48"
56
+ app:layout_constraintBottom_toBottomOf="@+id/txt_title"
57
+ app:layout_constraintEnd_toStartOf="@+id/btn_send"
58
+ app:layout_constraintTop_toTopOf="@+id/txt_title"
59
+ app:tint="@color/color_accent" />
60
+
61
+ <ImageView
62
+ android:id="@+id/btn_draft"
63
+ android:layout_width="@dimen/size_button_normal"
64
+ android:layout_height="@dimen/size_button_normal"
65
+ android:padding="@dimen/spacing_tiny"
66
+ android:src="@drawable/ic_drafts"
67
+ app:layout_constraintBottom_toBottomOf="@+id/txt_title"
68
+ app:layout_constraintEnd_toStartOf="@+id/btn_attachment"
69
+ app:layout_constraintTop_toTopOf="@+id/txt_title"
70
+ app:tint="@color/color_accent" />
71
+
72
+ <ImageView
73
+ android:id="@+id/btn_send_cancel"
74
+ android:layout_width="@dimen/size_button_normal"
75
+ android:layout_height="@dimen/size_button_normal"
76
+ android:padding="@dimen/spacing_tiny"
77
+ android:src="@drawable/ic_cancel_schedule_send"
78
+ app:layout_constraintBottom_toBottomOf="@+id/txt_title"
79
+ app:layout_constraintEnd_toStartOf="@+id/btn_draft"
80
+ app:layout_constraintTop_toTopOf="@+id/txt_title"
81
+ app:tint="@color/color_accent" />
82
+
83
+ </androidx.constraintlayout.widget.ConstraintLayout>
84
+
85
+ <View
86
+ style="@style/HorizontalDividerStyle"
87
+ android:layout_marginVertical="@dimen/spacing_tiny" />
88
+
89
+ <com.google.android.material.textfield.TextInputLayout
90
+ android:id="@+id/edt_mail_to"
91
+ style="@style/CommonEditText"
92
+ android:layout_marginBottom="@dimen/spacing_tiny"
93
+ android:hint="@string/text_mail_compose_to">
94
+
95
+ <com.google.android.material.textfield.TextInputEditText
96
+ android:layout_width="match_parent"
97
+ android:layout_height="wrap_content"
98
+ android:height="@dimen/height_edittext_normal"
99
+ android:singleLine="true"
100
+ android:textSize="@dimen/font_normal" />
101
+
102
+ <com.google.android.material.chip.ChipGroup
103
+ android:id="@+id/mail_chip_group"
104
+ android:layout_width="match_parent"
105
+ android:layout_height="match_parent"
106
+ app:chipSpacingHorizontal="@dimen/spacing_tiny" />
107
+
108
+ </com.google.android.material.textfield.TextInputLayout>
109
+
110
+ <com.google.android.material.textfield.TextInputLayout
111
+ android:id="@+id/edt_mail_subject"
112
+ style="@style/CommonEditText"
113
+ android:layout_marginBottom="@dimen/spacing_tiny"
114
+ android:hint="@string/text_mail_compose_subject">
115
+
116
+ <com.google.android.material.textfield.TextInputEditText
117
+ android:layout_width="match_parent"
118
+ android:layout_height="wrap_content"
119
+ android:textSize="@dimen/font_normal"
120
+ android:singleLine="true"
121
+ android:height="@dimen/height_edittext_normal"/>
122
+
123
+ </com.google.android.material.textfield.TextInputLayout>
124
+
125
+ <com.google.android.material.textfield.TextInputLayout
126
+ android:id="@+id/edt_mail_content"
127
+ style="@style/CommonEditText"
128
+ android:layout_marginBottom="@dimen/spacing_tiny"
129
+ android:hint="@string/text_mail_compose_content">
130
+
131
+ <com.google.android.material.textfield.TextInputEditText
132
+ android:layout_width="match_parent"
133
+ android:layout_height="wrap_content"
134
+ android:textSize="@dimen/font_normal"
135
+ android:minHeight="@dimen/height_edittext_normal"/>
136
+
137
+ </com.google.android.material.textfield.TextInputLayout>
138
+
139
+ <com.google.android.material.chip.ChipGroup
140
+ android:id="@+id/attachment_chip_group"
141
+ android:layout_width="match_parent"
142
+ android:layout_height="match_parent"
143
+ app:chipSpacingHorizontal="@dimen/spacing_tiny" />
144
+
145
+
146
+ </LinearLayout>
147
+
148
+ </androidx.cardview.widget.CardView>
149
+
150
+ </androidx.constraintlayout.widget.ConstraintLayout>
Android/app/src/main/res/layout/widget_schedule_alarm.xml CHANGED
@@ -57,7 +57,7 @@
57
 
58
  <com.google.android.material.textfield.TextInputLayout
59
  android:id="@+id/txt_label"
60
- style="@style/SettingEditText"
61
  android:layout_marginTop="@dimen/spacing_small"
62
  android:layout_marginBottom="@dimen/spacing_tiny"
63
  android:hint="label">
 
57
 
58
  <com.google.android.material.textfield.TextInputLayout
59
  android:id="@+id/txt_label"
60
+ style="@style/CommonEditText"
61
  android:layout_marginTop="@dimen/spacing_small"
62
  android:layout_marginBottom="@dimen/spacing_tiny"
63
  android:hint="label">
Android/app/src/main/res/values/dimen.xml CHANGED
@@ -4,8 +4,8 @@
4
  <dimen name="font_huge">24sp</dimen>
5
  <dimen name="font_large">18sp</dimen>
6
  <dimen name="font_big">16sp</dimen>
7
- <dimen name="font_normal">14sp</dimen>
8
- <dimen name="font_small">12sp</dimen>
9
  <dimen name="font_tiny">10sp</dimen>
10
 
11
  <!-- radius size -->
@@ -48,7 +48,7 @@
48
  <dimen name="size_elevation_big">8dp</dimen>
49
 
50
  <dimen name="height_edittext_tall">44dp</dimen>
51
- <dimen name="height_edittext_normal">38dp</dimen>
52
  <dimen name="height_edittext_short">30dp</dimen>
53
 
54
  <dimen name="icon_size_small">10dp</dimen>
 
4
  <dimen name="font_huge">24sp</dimen>
5
  <dimen name="font_large">18sp</dimen>
6
  <dimen name="font_big">16sp</dimen>
7
+ <dimen name="font_normal">13sp</dimen>
8
+ <dimen name="font_small">11sp</dimen>
9
  <dimen name="font_tiny">10sp</dimen>
10
 
11
  <!-- radius size -->
 
48
  <dimen name="size_elevation_big">8dp</dimen>
49
 
50
  <dimen name="height_edittext_tall">44dp</dimen>
51
+ <dimen name="height_edittext_normal">40dp</dimen>
52
  <dimen name="height_edittext_short">30dp</dimen>
53
 
54
  <dimen name="icon_size_small">10dp</dimen>
Android/app/src/main/res/values/strings.xml CHANGED
@@ -25,4 +25,10 @@
25
  <string name="label_setting_temperature">Temperature</string>
26
 
27
  <string name="text_setting_button_save">Save</string>
 
 
 
 
 
 
28
  </resources>
 
25
  <string name="label_setting_temperature">Temperature</string>
26
 
27
  <string name="text_setting_button_save">Save</string>
28
+
29
+ <string name="title_mail_compose">Compose</string>
30
+ <string name="text_mail_compose_to">To</string>
31
+ <string name="text_mail_compose_subject">Subject</string>
32
+ <string name="text_mail_compose_content">Content</string>
33
+
34
  </resources>
Android/app/src/main/res/values/styles.xml CHANGED
@@ -6,7 +6,7 @@
6
  <item name="colorAccent">@color/color_accent</item>
7
  </style>
8
 
9
- <style name="SettingEditText" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
10
  <item name="android:layout_width">match_parent</item>
11
  <item name="android:layout_height">wrap_content</item>
12
  <item name="boxStrokeWidth">@dimen/width_stroke_thin</item>
 
6
  <item name="colorAccent">@color/color_accent</item>
7
  </style>
8
 
9
+ <style name="CommonEditText" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
10
  <item name="android:layout_width">match_parent</item>
11
  <item name="android:layout_height">wrap_content</item>
12
  <item name="boxStrokeWidth">@dimen/width_stroke_thin</item>