mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 04:37:25 +01:00
Send Private messages from ViewUserDetailActivity
This commit is contained in:
parent
bae68d4a99
commit
0e31e40ef1
@ -181,7 +181,7 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
|
||||
if (i == EditorInfo.IME_ACTION_DONE) {
|
||||
Utils.hideKeyboard(this);
|
||||
Intent pmIntent = new Intent(this, SendPrivateMessageActivity.class);
|
||||
pmIntent.putExtra(SendPrivateMessageActivity.EXTRA_RECIPIENT_USERNAME, thingEditText.getText().toString());
|
||||
//pmIntent.putExtra(SendPrivateMessageActivity.EXTRA_RECIPIENT_USERNAME, thingEditText.getText().toString());
|
||||
startActivity(pmIntent);
|
||||
return true;
|
||||
}
|
||||
@ -194,7 +194,7 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
|
||||
-> {
|
||||
Utils.hideKeyboard(this);
|
||||
Intent pmIntent = new Intent(this, SendPrivateMessageActivity.class);
|
||||
pmIntent.putExtra(SendPrivateMessageActivity.EXTRA_RECIPIENT_USERNAME, thingEditText.getText().toString());
|
||||
//pmIntent.putExtra(SendPrivateMessageActivity.EXTRA_RECIPIENT_USERNAME, thingEditText.getText().toString());
|
||||
startActivity(pmIntent);
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
@ -331,7 +331,7 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
|
||||
if (resultCode == RESULT_OK && requestCode == SEARCH_USER_REQUEST_CODE && data != null) {
|
||||
String username = data.getStringExtra(SearchActivity.EXTRA_RETURN_USER_NAME);
|
||||
Intent intent = new Intent(this, SendPrivateMessageActivity.class);
|
||||
intent.putExtra(SendPrivateMessageActivity.EXTRA_RECIPIENT_USERNAME, username);
|
||||
//intent.putExtra(SendPrivateMessageActivity.EXTRA_RECIPIENT_USERNAME, username);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,13 @@
|
||||
package eu.toldi.infinityforlemmy.activities;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.MediaStore;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@ -10,12 +15,20 @@ import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
@ -23,13 +36,24 @@ import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.UploadImageEnabledActivity;
|
||||
import eu.toldi.infinityforlemmy.UploadedImage;
|
||||
import eu.toldi.infinityforlemmy.adapters.MarkdownBottomBarRecyclerViewAdapter;
|
||||
import eu.toldi.infinityforlemmy.bottomsheetfragments.UploadedImagesBottomSheetFragment;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.message.ComposeMessage;
|
||||
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
|
||||
import eu.toldi.infinityforlemmy.privatemessage.LemmyPrivateMessageAPI;
|
||||
import eu.toldi.infinityforlemmy.privatemessage.PrivateMessage;
|
||||
import eu.toldi.infinityforlemmy.user.BasicUserInfo;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import retrofit2.Retrofit;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
|
||||
public class SendPrivateMessageActivity extends BaseActivity {
|
||||
public static final String EXTRA_RECIPIENT_USERNAME = "ERU";
|
||||
public class SendPrivateMessageActivity extends BaseActivity implements UploadImageEnabledActivity {
|
||||
public static final String EXTRA_RECIPIENT_USER_INFO = "ERUI";
|
||||
|
||||
private static final int PICK_IMAGE_REQUEST_CODE = 100;
|
||||
private static final int CAPTURE_IMAGE_REQUEST_CODE = 200;
|
||||
@BindView(R.id.coordinator_layout_send_private_message_activity)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@BindView(R.id.appbar_layout_send_private_message_activity)
|
||||
@ -40,15 +64,20 @@ public class SendPrivateMessageActivity extends BaseActivity {
|
||||
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;
|
||||
|
||||
@BindView(R.id.markdown_bottom_bar_recycler_view_send_private_message_activity)
|
||||
RecyclerView markdownBottomBarRecyclerView;
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
@Named("no_oauth")
|
||||
RetrofitHolder mRetrofit;
|
||||
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
|
||||
@Inject
|
||||
@Named("default")
|
||||
SharedPreferences mSharedPreferences;
|
||||
@ -57,9 +86,18 @@ public class SendPrivateMessageActivity extends BaseActivity {
|
||||
SharedPreferences mCurrentAccountSharedPreferences;
|
||||
@Inject
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
|
||||
@Inject
|
||||
LemmyPrivateMessageAPI mLemmyPrivateMessageAPI;
|
||||
private String mAccessToken;
|
||||
|
||||
private BasicUserInfo mRecipientBasicUserInfo;
|
||||
private boolean isSubmitting = false;
|
||||
|
||||
private ArrayList<UploadedImage> uploadedImages = new ArrayList<>();
|
||||
|
||||
private Uri capturedImageUri;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
((Infinity) getApplication()).getAppComponent().inject(this);
|
||||
@ -77,14 +115,66 @@ public class SendPrivateMessageActivity extends BaseActivity {
|
||||
addOnOffsetChangedListener(appBarLayout);
|
||||
}
|
||||
|
||||
MarkdownBottomBarRecyclerViewAdapter adapter = new MarkdownBottomBarRecyclerViewAdapter(
|
||||
mCustomThemeWrapper, new MarkdownBottomBarRecyclerViewAdapter.ItemClickListener() {
|
||||
@Override
|
||||
public void onClick(int item) {
|
||||
MarkdownBottomBarRecyclerViewAdapter.bindEditTextWithItemClickListener(
|
||||
SendPrivateMessageActivity.this, messageEditText, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUploadImage() {
|
||||
Utils.hideKeyboard(SendPrivateMessageActivity.this);
|
||||
UploadedImagesBottomSheetFragment fragment = new UploadedImagesBottomSheetFragment();
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putParcelableArrayList(UploadedImagesBottomSheetFragment.EXTRA_UPLOADED_IMAGES,
|
||||
uploadedImages);
|
||||
fragment.setArguments(arguments);
|
||||
fragment.show(getSupportFragmentManager(), fragment.getTag());
|
||||
}
|
||||
});
|
||||
|
||||
markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManagerBugFixed(this,
|
||||
LinearLayoutManagerBugFixed.HORIZONTAL, false));
|
||||
markdownBottomBarRecyclerView.setAdapter(adapter);
|
||||
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
String username = getIntent().getStringExtra(EXTRA_RECIPIENT_USERNAME);
|
||||
if (username != null) {
|
||||
usernameEditText.setText(username);
|
||||
if (savedInstanceState != null) {
|
||||
mRecipientBasicUserInfo = savedInstanceState.getParcelable(EXTRA_RECIPIENT_USER_INFO);
|
||||
} else {
|
||||
mRecipientBasicUserInfo = getIntent().getParcelableExtra(EXTRA_RECIPIENT_USER_INFO);
|
||||
}
|
||||
|
||||
if (mRecipientBasicUserInfo != null) {
|
||||
usernameEditText.setText(mRecipientBasicUserInfo.getQualifiedName());
|
||||
usernameEditText.setEnabled(false);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (requestCode == PICK_IMAGE_REQUEST_CODE) {
|
||||
if (data == null) {
|
||||
Toast.makeText(SendPrivateMessageActivity.this, R.string.error_getting_image, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, messageEditText, coordinatorLayout, data.getData(), uploadedImages);
|
||||
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, messageEditText, coordinatorLayout, capturedImageUri, uploadedImages);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -108,12 +198,6 @@ public class SendPrivateMessageActivity extends BaseActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (subjectEditText.getText() == null || subjectEditText.getText().toString().equals("")) {
|
||||
isSubmitting = false;
|
||||
Snackbar.make(coordinatorLayout, R.string.message_subject_required, Snackbar.LENGTH_LONG).show();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (messageEditText.getText() == null || messageEditText.getText().toString().equals("")) {
|
||||
isSubmitting = false;
|
||||
Snackbar.make(coordinatorLayout, R.string.message_content_required, Snackbar.LENGTH_LONG).show();
|
||||
@ -125,11 +209,9 @@ public class SendPrivateMessageActivity extends BaseActivity {
|
||||
Snackbar sendingSnackbar = Snackbar.make(coordinatorLayout, R.string.sending_message, Snackbar.LENGTH_INDEFINITE);
|
||||
sendingSnackbar.show();
|
||||
|
||||
ComposeMessage.composeMessage(mOauthRetrofit, mAccessToken, getResources().getConfiguration().locale,
|
||||
usernameEditText.getText().toString(), subjectEditText.getText().toString(),
|
||||
messageEditText.getText().toString(), new ComposeMessage.ComposeMessageListener() {
|
||||
mLemmyPrivateMessageAPI.sendPrivateMessage(mAccessToken, mRecipientBasicUserInfo.getId(), messageEditText.getText().toString(), new LemmyPrivateMessageAPI.PrivateMessageSentListener() {
|
||||
@Override
|
||||
public void composeMessageSuccess() {
|
||||
public void onPrivateMessageSentSuccess(@NonNull PrivateMessage privateMessage) {
|
||||
isSubmitting = false;
|
||||
item.setEnabled(true);
|
||||
item.getIcon().setAlpha(255);
|
||||
@ -138,17 +220,13 @@ public class SendPrivateMessageActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void composeMessageFailed(String errorMessage) {
|
||||
public void onPrivateMessageSentError() {
|
||||
isSubmitting = false;
|
||||
sendingSnackbar.dismiss();
|
||||
item.setEnabled(true);
|
||||
item.getIcon().setAlpha(255);
|
||||
|
||||
if (errorMessage == null || errorMessage.equals("")) {
|
||||
Snackbar.make(coordinatorLayout, R.string.send_message_failed, Snackbar.LENGTH_LONG).show();
|
||||
} else {
|
||||
Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -159,6 +237,7 @@ public class SendPrivateMessageActivity extends BaseActivity {
|
||||
@Override
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(EXTRA_RECIPIENT_USER_INFO, mRecipientBasicUserInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -177,19 +256,49 @@ public class SendPrivateMessageActivity extends BaseActivity {
|
||||
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, 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);
|
||||
if (typeface != null) {
|
||||
usernameEditText.setTypeface(typeface);
|
||||
subjectEditText.setTypeface(typeface);
|
||||
messageEditText.setTypeface(typeface);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadImage() {
|
||||
Intent intent = new Intent();
|
||||
intent.setType("image/*");
|
||||
intent.setAction(Intent.ACTION_GET_CONTENT);
|
||||
startActivityForResult(Intent.createChooser(intent,
|
||||
getResources().getString(R.string.select_from_gallery)), PICK_IMAGE_REQUEST_CODE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void captureImage() {
|
||||
Intent pictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
try {
|
||||
capturedImageUri = FileProvider.getUriForFile(this, "eu.toldi.infinityforlemmy.provider",
|
||||
File.createTempFile("captured_image", ".jpg", getExternalFilesDir(Environment.DIRECTORY_PICTURES)));
|
||||
pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri);
|
||||
startActivityForResult(pictureIntent, CAPTURE_IMAGE_REQUEST_CODE);
|
||||
} catch (IOException ex) {
|
||||
Toast.makeText(this, R.string.error_creating_temp_file, Toast.LENGTH_SHORT).show();
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(this, R.string.no_camera_available, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertImageUrl(UploadedImage uploadedImage) {
|
||||
int start = Math.max(messageEditText.getSelectionStart(), 0);
|
||||
int end = Math.max(messageEditText.getSelectionEnd(), 0);
|
||||
messageEditText.getText().replace(Math.min(start, end), Math.max(start, end),
|
||||
"![" + uploadedImage.imageName + "](" + uploadedImage.imageUrl + ")",
|
||||
0, "![]()".length() + uploadedImage.imageName.length() + uploadedImage.imageUrl.length());
|
||||
}
|
||||
}
|
@ -1227,8 +1227,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
}
|
||||
return true;
|
||||
} else if (itemId == R.id.action_contact_mods_view_subreddit_detail_activity) {
|
||||
Intent intent = new Intent(this, SendPrivateMessageActivity.class);
|
||||
intent.putExtra(SendPrivateMessageActivity.EXTRA_RECIPIENT_USERNAME, "r/" + communityName);
|
||||
/* Intent intent = new Intent(this, SendPrivateMessageActivity.class);
|
||||
intent.putExtra(SendPrivateMessageActivity.EXTRA_RECIPIENT_USERNAME, "r/" + communityName);*/
|
||||
//startActivity(intent);
|
||||
return true;
|
||||
} else if (itemId == R.id.block_community_view_subreddit_detail_activity) {
|
||||
|
@ -108,6 +108,7 @@ import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
|
||||
import eu.toldi.infinityforlemmy.subreddit.ParseSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.user.BasicUserInfo;
|
||||
import eu.toldi.infinityforlemmy.user.BlockUser;
|
||||
import eu.toldi.infinityforlemmy.user.FetchUserData;
|
||||
import eu.toldi.infinityforlemmy.user.UserDao;
|
||||
@ -1268,7 +1269,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
}
|
||||
|
||||
Intent pmIntent = new Intent(this, SendPrivateMessageActivity.class);
|
||||
pmIntent.putExtra(SendPrivateMessageActivity.EXTRA_RECIPIENT_USERNAME, username);
|
||||
pmIntent.putExtra(SendPrivateMessageActivity.EXTRA_RECIPIENT_USER_INFO, new BasicUserInfo(mUserData.getId(), username, qualifiedName, mUserData.getAvatar(), mUserData.getDisplayName()));
|
||||
startActivity(pmIntent);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_add_to_post_filter_view_user_detail_activity) {
|
||||
|
@ -23,11 +23,17 @@
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
@ -38,16 +44,16 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#00000000"
|
||||
android:fontFamily="?attr/content_font_family"
|
||||
android:gravity="top"
|
||||
android:hint="@string/send_message_username_hint"
|
||||
android:inputType="textCapSentences|textMultiLine"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="?attr/content_font_18"
|
||||
android:fontFamily="?attr/content_font_family" />
|
||||
android:textSize="?attr/content_font_18" />
|
||||
|
||||
<View
|
||||
android:id="@+id/divider_1_send_private_message_activity"
|
||||
@ -55,22 +61,6 @@
|
||||
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:maxLength="100"
|
||||
android:fontFamily="?attr/content_font_family" />
|
||||
|
||||
<View
|
||||
android:id="@+id/divider_2_send_private_message_activity"
|
||||
android:layout_width="match_parent"
|
||||
@ -82,6 +72,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#00000000"
|
||||
android:fontFamily="?attr/content_font_family"
|
||||
android:gravity="top"
|
||||
android:hint="@string/send_message_content_hint"
|
||||
android:inputType="textCapSentences|textMultiLine"
|
||||
@ -89,11 +80,18 @@
|
||||
android:paddingEnd="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="?attr/content_font_18"
|
||||
android:fontFamily="?attr/content_font_family" />
|
||||
android:textSize="?attr/content_font_18" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/markdown_bottom_bar_recycler_view_send_private_message_activity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:scrollbars="horizontal"
|
||||
android:layout_gravity="bottom" />
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
Loading…
Reference in New Issue
Block a user