aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/AndroidManifest.xml8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/API/RedditAPI.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SendPrivateMessageActivity.java123
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Comment/SendComment.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Message/ComposeMessage.java58
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/APIUtils.java3
-rw-r--r--app/src/main/res/layout/activity_send_private_message.xml98
-rw-r--r--app/src/main/res/menu/send_private_message_activity.xml10
-rw-r--r--app/src/main/res/menu/view_user_detail_activity.xml6
-rw-r--r--app/src/main/res/values/strings.xml5
12 files changed, 323 insertions, 5 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index d92c8ba0..4d30b837 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -23,13 +23,19 @@
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:replace="android:label">
+ <activity android:name=".Activity.SendPrivateMessageActivity"
+ android:label="@string/send_private_message_activity_label"
+ android:parentActivityName=".Activity.MainActivity"
+ android:theme="@style/AppTheme.NoActionBar"
+ android:windowSoftInputMode="adjustResize" />
<service
android:name=".Service.DownloadRedditVideoService"
android:enabled="true"
android:exported="false" />
- <activity android:name=".Activity.ViewPrivateMessagesActivity"
+ <activity
+ android:name=".Activity.ViewPrivateMessagesActivity"
android:parentActivityName=".Activity.MainActivity"
android:theme="@style/AppTheme.Slidable"
android:windowSoftInputMode="adjustResize" />
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/API/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/API/RedditAPI.java
index fd6e71c7..fbfdd32a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/API/RedditAPI.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/API/RedditAPI.java
@@ -308,4 +308,8 @@ public interface RedditAPI {
@FormUrlEncoded
@POST("/api/report")
Call<String> report(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params);
+
+ @FormUrlEncoded
+ @POST("/api/compose")
+ Call<String> composePrivateMessage(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SendPrivateMessageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SendPrivateMessageActivity.java
new file mode 100644
index 00000000..9fa56478
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SendPrivateMessageActivity.java
@@ -0,0 +1,123 @@
+package ml.docilealligator.infinityforreddit.Activity;
+
+import android.content.SharedPreferences;
+import android.os.Build;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.EditText;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.widget.Toolbar;
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
+
+import com.google.android.material.appbar.AppBarLayout;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import retrofit2.Retrofit;
+
+public class SendPrivateMessageActivity extends BaseActivity {
+ public static final String EXTRA_RECIPIENT_USERNAME = "ERU";
+ @BindView(R.id.coordinator_layout_send_private_message_activity)
+ CoordinatorLayout coordinatorLayout;
+ @BindView(R.id.appbar_layout_send_private_message_activity)
+ AppBarLayout appBarLayout;
+ @BindView(R.id.toolbar_send_private_message_activity)
+ Toolbar toolbar;
+ @BindView(R.id.username_edit_text_send_private_message_activity)
+ EditText usernameEditText;
+ @BindView(R.id.divider_1_send_private_message_activity)
+ View divider1;
+ @BindView(R.id.subjet_edit_text_send_private_message_activity)
+ EditText subjectEditText;
+ @BindView(R.id.divider_2_send_private_message_activity)
+ View divider2;
+ @BindView(R.id.content_edit_text_send_private_message_activity)
+ EditText messageEditText;
+ @Inject
+ @Named("oauth")
+ Retrofit mOauthRetrofit;
+ @Inject
+ RedditDataRoomDatabase mRedditDataRoomDatabase;
+ @Inject
+ @Named("default")
+ SharedPreferences mSharedPreferences;
+ @Inject
+ CustomThemeWrapper mCustomThemeWrapper;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ ((Infinity) getApplication()).getAppComponent().inject(this);
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_send_private_message);
+
+ ButterKnife.bind(this);
+
+ applyCustomTheme();
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
+ addOnOffsetChangedListener(appBarLayout);
+ }
+
+ setSupportActionBar(toolbar);
+
+ String username = getIntent().getStringExtra(EXTRA_RECIPIENT_USERNAME);
+ if (username != null) {
+ usernameEditText.setText(username);
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.send_private_message_activity, menu);
+ applyMenuItemTheme(menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ finish();
+ return true;
+ } else if (item.getItemId() == R.id.action_send_send_private_message_activity) {
+
+ }
+ return false;
+ }
+
+ @Override
+ protected SharedPreferences getDefaultSharedPreferences() {
+ return mSharedPreferences;
+ }
+
+ @Override
+ protected CustomThemeWrapper getCustomThemeWrapper() {
+ return mCustomThemeWrapper;
+ }
+
+ @Override
+ protected void applyCustomTheme() {
+ coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
+ applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
+ int primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
+ usernameEditText.setTextColor(primaryTextColor);
+ subjectEditText.setTextColor(primaryTextColor);
+ messageEditText.setTextColor(primaryTextColor);
+ int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor();
+ usernameEditText.setHintTextColor(secondaryTextColor);
+ subjectEditText.setHintTextColor(secondaryTextColor);
+ messageEditText.setHintTextColor(secondaryTextColor);
+ int dividerColor = mCustomThemeWrapper.getDividerColor();
+ divider1.setBackgroundColor(dividerColor);
+ divider2.setBackgroundColor(dividerColor);
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
index 30891f38..04847b7f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
@@ -652,6 +652,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
Toast.makeText(this, R.string.no_app, Toast.LENGTH_SHORT).show();
}
return true;
+ case R.id.action_send_private_message_view_user_detail_activity:
+ Intent pmIntent = new Intent(this, SendPrivateMessageActivity.class);
+ pmIntent.putExtra(SendPrivateMessageActivity.EXTRA_RECIPIENT_USERNAME, username);
+ startActivity(pmIntent);
+ return true;
}
return false;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index db9b4ddb..6bbc049a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -27,6 +27,7 @@ import ml.docilealligator.infinityforreddit.Activity.SearchActivity;
import ml.docilealligator.infinityforreddit.Activity.SearchResultActivity;
import ml.docilealligator.infinityforreddit.Activity.SearchSubredditsResultActivity;
import ml.docilealligator.infinityforreddit.Activity.SelectedSubredditsActivity;
+import ml.docilealligator.infinityforreddit.Activity.SendPrivateMessageActivity;
import ml.docilealligator.infinityforreddit.Activity.SettingsActivity;
import ml.docilealligator.infinityforreddit.Activity.SubredditMultiselectionActivity;
import ml.docilealligator.infinityforreddit.Activity.SubredditSelectionActivity;
@@ -179,4 +180,6 @@ public interface AppComponent {
void inject(InboxFragment inboxFragment);
void inject(ViewPrivateMessagesActivity viewPrivateMessagesActivity);
+
+ void inject(SendPrivateMessageActivity sendPrivateMessageActivity);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Comment/SendComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Comment/SendComment.java
index 1ce8fac5..6991364f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Comment/SendComment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Comment/SendComment.java
@@ -19,17 +19,14 @@ public class SendComment {
public static void sendComment(String commentMarkdown, String thingFullname, int parentDepth,
Locale locale, Retrofit oauthRetrofit, String accessToken,
SendCommentListener sendCommentListener) {
- RedditAPI api = oauthRetrofit.create(RedditAPI.class);
Map<String, String> headers = APIUtils.getOAuthHeader(accessToken);
Map<String, String> params = new HashMap<>();
params.put(APIUtils.API_TYPE_KEY, "json");
params.put(APIUtils.RETURN_RTJSON_KEY, "true");
params.put(APIUtils.TEXT_KEY, commentMarkdown);
params.put(APIUtils.THING_ID_KEY, thingFullname);
- api.sendCommentOrReplyToMessage(headers, params);
- Call<String> sendCommentCall = api.sendCommentOrReplyToMessage(headers, params);
- sendCommentCall.enqueue(new Callback<String>() {
+ oauthRetrofit.create(RedditAPI.class).sendCommentOrReplyToMessage(headers, params).enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if (response.isSuccessful()) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Message/ComposeMessage.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Message/ComposeMessage.java
new file mode 100644
index 00000000..f0697a57
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Message/ComposeMessage.java
@@ -0,0 +1,58 @@
+package ml.docilealligator.infinityforreddit.Message;
+
+import androidx.annotation.NonNull;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import ml.docilealligator.infinityforreddit.API.RedditAPI;
+import ml.docilealligator.infinityforreddit.Utils.APIUtils;
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+import retrofit2.Retrofit;
+
+public class ComposeMessage {
+ public static void composeMessage(Retrofit oauthRetrofit, String accessToken, Locale locale, String username,
+ String subject, String message, ComposeMessageListener composeMessageListener) {
+ Map<String, String> headers = APIUtils.getOAuthHeader(accessToken);
+ Map<String, String> params = new HashMap<>();
+ params.put(APIUtils.API_TYPE_KEY, "json");
+ params.put(APIUtils.SUBJECT_KEY, subject);
+ params.put(APIUtils.TEXT_KEY, message);
+ params.put(APIUtils.TO_KEY, username);
+
+ oauthRetrofit.create(RedditAPI.class).composePrivateMessage(headers, params).enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ if (response.isSuccessful()) {
+ ParseMessage.parseRepliedMessage(response.body(), locale,
+ new ParseMessage.ParseSentMessageAsyncTaskListener() {
+ @Override
+ public void parseSuccess(Message message) {
+ composeMessageListener.composeMessageSuccess(message);
+ }
+
+ @Override
+ public void parseFailed(String errorMessage) {
+ composeMessageListener.composeMessageFailed(errorMessage);
+ }
+ });
+ } else {
+ composeMessageListener.composeMessageFailed(response.message());
+ }
+ }
+
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ composeMessageListener.composeMessageFailed(t.getMessage());
+ }
+ });
+ }
+
+ public interface ComposeMessageListener {
+ void composeMessageSuccess(Message message);
+ void composeMessageFailed(String errorMessage);
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/APIUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/APIUtils.java
index 89b85bbe..1b00e57a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/APIUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/APIUtils.java
@@ -92,6 +92,9 @@ public class APIUtils {
public static final String REASON_KEY = "reason";
+ public static final String SUBJECT_KEY = "subject";
+ public static final String TO_KEY = "to";
+
public static Map<String, String> getHttpBasicAuthHeader() {
Map<String, String> params = new HashMap<>();
String credentials = String.format("%s:%s", APIUtils.CLIENT_ID, "");
diff --git a/app/src/main/res/layout/activity_send_private_message.xml b/app/src/main/res/layout/activity_send_private_message.xml
new file mode 100644
index 00000000..3938e90d
--- /dev/null
+++ b/app/src/main/res/layout/activity_send_private_message.xml
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:id="@+id/coordinator_layout_send_private_message_activity"
+ tools:context=".Activity.SendPrivateMessageActivity">
+
+ <com.google.android.material.appbar.AppBarLayout
+ android:id="@+id/appbar_layout_send_private_message_activity"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:theme="@style/AppTheme.AppBarOverlay">
+
+ <androidx.appcompat.widget.Toolbar
+ android:id="@+id/toolbar_send_private_message_activity"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?attr/actionBarSize"
+ app:navigationIcon="?attr/homeAsUpIndicator"
+ app:popupTheme="@style/AppTheme.PopupOverlay" />
+
+ </com.google.android.material.appbar.AppBarLayout>
+
+ <androidx.core.widget.NestedScrollView
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:layout_behavior="@string/appbar_scrolling_view_behavior">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <EditText
+ android:id="@+id/username_edit_text_send_private_message_activity"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#00000000"
+ android:gravity="top"
+ android:hint="@string/send_message_username_hint"
+ android:inputType="textCapSentences|textMultiLine"
+ android:paddingTop="16dp"
+ android:paddingStart="16dp"
+ android:paddingEnd="16dp"
+ android:paddingBottom="16dp"
+ android:textColor="?attr/primaryTextColor"
+ android:textSize="?attr/content_font_18"
+ android:fontFamily="?attr/content_font_family" />
+
+ <View
+ android:id="@+id/divider_1_send_private_message_activity"
+ android:layout_width="match_parent"
+ android:layout_height="1dp"
+ android:layout_marginBottom="16dp" />
+
+ <EditText
+ android:id="@+id/subjet_edit_text_send_private_message_activity"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#00000000"
+ android:gravity="top"
+ android:hint="@string/send_message_subject_hint"
+ android:inputType="textCapSentences|textMultiLine"
+ android:paddingStart="16dp"
+ android:paddingEnd="16dp"
+ android:paddingBottom="16dp"
+ android:textColor="?attr/primaryTextColor"
+ android:textSize="?attr/content_font_18"
+ android:fontFamily="?attr/content_font_family" />
+
+ <View
+ android:id="@+id/divider_2_send_private_message_activity"
+ android:layout_width="match_parent"
+ android:layout_height="1dp"
+ android:layout_marginBottom="16dp" />
+
+ <EditText
+ android:id="@+id/content_edit_text_send_private_message_activity"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#00000000"
+ android:gravity="top"
+ android:hint="@string/send_message_content_hint"
+ android:inputType="textCapSentences|textMultiLine"
+ android:paddingStart="16dp"
+ android:paddingEnd="16dp"
+ android:paddingBottom="16dp"
+ android:textColor="?attr/primaryTextColor"
+ android:textSize="?attr/content_font_18"
+ android:fontFamily="?attr/content_font_family" />
+
+ </LinearLayout>
+
+ </androidx.core.widget.NestedScrollView>
+
+</androidx.coordinatorlayout.widget.CoordinatorLayout> \ No newline at end of file
diff --git a/app/src/main/res/menu/send_private_message_activity.xml b/app/src/main/res/menu/send_private_message_activity.xml
new file mode 100644
index 00000000..ba7f4a4f
--- /dev/null
+++ b/app/src/main/res/menu/send_private_message_activity.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+ <item
+ android:id="@+id/action_send_send_private_message_activity"
+ android:orderInCategory="1"
+ android:title="@string/action_send"
+ android:icon="@drawable/ic_send_toolbar_24dp"
+ app:showAsAction="ifRoom" />
+</menu> \ No newline at end of file
diff --git a/app/src/main/res/menu/view_user_detail_activity.xml b/app/src/main/res/menu/view_user_detail_activity.xml
index 18c3ef16..50170f31 100644
--- a/app/src/main/res/menu/view_user_detail_activity.xml
+++ b/app/src/main/res/menu/view_user_detail_activity.xml
@@ -37,4 +37,10 @@
android:orderInCategory="6"
android:title="@string/action_share"
app:showAsAction="never" />
+
+ <item
+ android:id="@+id/action_send_private_message_view_user_detail_activity"
+ android:orderInCategory="6"
+ android:title="@string/action_send_private_message"
+ app:showAsAction="never" />
</menu>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 72f64124..9a7ed547 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -28,6 +28,7 @@
<string name="report_activity_label">Report</string>
<string name="view_imgur_media_activity_image_label">Image %1$d/%2$d</string>
<string name="view_imgur_media_activity_video_label">Video %1$d/%2$d</string>
+ <string name="send_private_message_activity_label">Send PM</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
@@ -63,6 +64,7 @@
<string name="action_report">Report</string>
<string name="action_see_removed">See Removed</string>
<string name="action_set_wallpaper">Set as Wallpaper</string>
+ <string name="action_send_private_message">Send Private Message</string>
<string name="parse_json_response_error">Error occurred when parsing the JSON response</string>
<string name="retrieve_token_error">Error Retrieving the token</string>
@@ -152,6 +154,9 @@
<string name="send_comment_failed">Could not send this comment</string>
<string name="parse_sent_comment_failed">The comment is sent but unable to get the sent comment</string>
+ <string name="send_message_username_hint">User</string>
+ <string name="send_message_subject_hint">Subject</string>
+ <string name="send_message_content_hint">Message</string>
<string name="reply_message_failed">Could not reply to this message</string>
<string name="error_getting_message">Error getting this message</string>