mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-28 11:58:23 +01:00
Prepare to add composing private message feature.
This commit is contained in:
parent
ba2a219168
commit
40fd7bf40f
@ -87,6 +87,10 @@ dependencies {
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
implementation 'me.zhanghai.android.fastscroll:library:1.1.2'
|
||||
implementation "com.thefuntasty.hauler:core:3.1.0"
|
||||
// androidX startup for auto-init
|
||||
implementation "androidx.startup:startup-runtime:1.0.0-alpha01"
|
||||
//crashy
|
||||
implementation 'com.github.CraZyLegenD:Crashy:1.0.3'
|
||||
|
||||
def toroVersion = '3.7.0.2010003'
|
||||
implementation "im.ene.toro3:toro:$toroVersion"
|
||||
|
@ -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" />
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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()) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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, "");
|
||||
|
98
app/src/main/res/layout/activity_send_private_message.xml
Normal file
98
app/src/main/res/layout/activity_send_private_message.xml
Normal file
@ -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>
|
10
app/src/main/res/menu/send_private_message_activity.xml
Normal file
10
app/src/main/res/menu/send_private_message_activity.xml
Normal file
@ -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>
|
@ -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>
|
||||
|
@ -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>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user