aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-08-12 09:20:33 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-08-12 09:20:33 +0000
commitb1b3642ca8ceb159282dc684be2d75afa4b37a91 (patch)
tree9a3705247f903aed74c158c9ffb3f56f0a1b5e19
parent4df18af91447d7fcd9768f0b5a8f71974f826280 (diff)
downloadinfinity-for-reddit-b1b3642ca8ceb159282dc684be2d75afa4b37a91.tar
infinity-for-reddit-b1b3642ca8ceb159282dc684be2d75afa4b37a91.tar.gz
infinity-for-reddit-b1b3642ca8ceb159282dc684be2d75afa4b37a91.tar.bz2
infinity-for-reddit-b1b3642ca8ceb159282dc684be2d75afa4b37a91.tar.lz
infinity-for-reddit-b1b3642ca8ceb159282dc684be2d75afa4b37a91.tar.xz
infinity-for-reddit-b1b3642ca8ceb159282dc684be2d75afa4b37a91.tar.zst
infinity-for-reddit-b1b3642ca8ceb159282dc684be2d75afa4b37a91.zip
Deleting and editing posts are now available.
-rw-r--r--.idea/caches/build_file_checksums.serbin533 -> 533 bytes
-rw-r--r--.idea/caches/gradle_models.serbin263220 -> 263220 bytes
-rw-r--r--app/src/main/AndroidManifest.xml5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/DeleteThing.java38
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/EditPostActivity.java127
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java107
-rw-r--r--app/src/main/res/layout/activity_edit_post.xml64
-rw-r--r--app/src/main/res/layout/activity_post_image.xml4
-rw-r--r--app/src/main/res/layout/activity_post_link.xml4
-rw-r--r--app/src/main/res/layout/activity_post_text.xml4
-rw-r--r--app/src/main/res/layout/activity_post_video.xml4
-rw-r--r--app/src/main/res/layout/activity_view_user_detail.xml2
-rw-r--r--app/src/main/res/layout/item_comment.xml4
-rw-r--r--app/src/main/res/layout/item_load_more_comments_placeholder.xml2
-rw-r--r--app/src/main/res/layout/item_post.xml4
-rw-r--r--app/src/main/res/layout/item_post_detail.xml6
-rw-r--r--app/src/main/res/layout/item_subreddit_listing.xml2
-rw-r--r--app/src/main/res/layout/item_user_listing.xml2
-rw-r--r--app/src/main/res/menu/edit_post_activity.xml10
-rw-r--r--app/src/main/res/menu/view_post_detail_activity.xml14
-rw-r--r--app/src/main/res/values-night/colors.xml2
-rw-r--r--app/src/main/res/values/colors.xml2
-rw-r--r--app/src/main/res/values/strings.xml11
-rw-r--r--app/src/main/res/values/styles.xml13
27 files changed, 392 insertions, 44 deletions
diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser
index 5002094d..9e3da5a9 100644
--- a/.idea/caches/build_file_checksums.ser
+++ b/.idea/caches/build_file_checksums.ser
Binary files differ
diff --git a/.idea/caches/gradle_models.ser b/.idea/caches/gradle_models.ser
index 5400a4ac..7dc82bdb 100644
--- a/.idea/caches/gradle_models.ser
+++ b/.idea/caches/gradle_models.ser
Binary files differ
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index e85143cb..d8853f50 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -20,6 +20,11 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
+ <activity
+ android:name=".EditPostActivity"
+ android:parentActivityName=".MainActivity"
+ android:theme="@style/AppTheme.NoActionBar"
+ android:windowSoftInputMode="adjustResize" />
<service
android:name=".SubmitPostService"
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index 39616ae6..d77f2397 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -31,4 +31,5 @@ interface AppComponent {
void inject(SearchSubredditsResultActivity searchSubredditsResultActivity);
void inject(FollowedUsersListingFragment followedUsersListingFragment);
void inject(SubredditSelectionActivity subredditSelectionActivity);
+ void inject(EditPostActivity editPostActivity);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java
index 9a7fa962..e2fd34b5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingRecyclerViewAdapter.java
@@ -48,7 +48,7 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, R
mOauthRetrofit = oauthRetrofit;
mAccessToken = accessToken;
mRetryLoadingMoreCallback = retryLoadingMoreCallback;
- mTextColorPrimaryDark = mContext.getResources().getColor(R.color.textColorPrimaryDark);
+ mTextColorPrimaryDark = mContext.getResources().getColor(R.color.colorPrimaryDarkDayNightTheme);
mColorAccent = mContext.getResources().getColor(R.color.colorAccent);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/DeleteThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/DeleteThing.java
new file mode 100644
index 00000000..e755e51f
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/DeleteThing.java
@@ -0,0 +1,38 @@
+package ml.docilealligator.infinityforreddit;
+
+import androidx.annotation.NonNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+import retrofit2.Retrofit;
+
+class DeleteThing {
+ interface DeleteThingListener {
+ void deleteSuccess();
+ void deleteFailed();
+ }
+
+ static void delete(Retrofit oauthRetrofit, String fullname, String accessToken, DeleteThingListener deleteThingListener) {
+ Map<String, String> params = new HashMap<>();
+ params.put(RedditUtils.ID_KEY, fullname);
+ oauthRetrofit.create(RedditAPI.class).delete(RedditUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ if(response.isSuccessful()) {
+ deleteThingListener.deleteSuccess();
+ } else {
+ deleteThingListener.deleteFailed();
+ }
+ }
+
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ deleteThingListener.deleteFailed();
+ }
+ });
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/EditPostActivity.java
new file mode 100644
index 00000000..7213522a
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/EditPostActivity.java
@@ -0,0 +1,127 @@
+package ml.docilealligator.infinityforreddit;
+
+import android.content.Intent;
+import android.content.res.Configuration;
+import android.os.Build;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.Window;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.widget.Toolbar;
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
+import androidx.core.content.ContextCompat;
+
+import com.google.android.material.snackbar.Snackbar;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+import retrofit2.Retrofit;
+
+public class EditPostActivity extends AppCompatActivity {
+
+ static final String EXTRA_TITLE = "ET";
+ static final String EXTRA_CONTENT = "EC";
+ static final String EXTRA_FULLNAME = "EF";
+ static final String EXTRA_ACCESS_TOKEN = "EAT";
+
+ @BindView(R.id.coordinator_layout_edit_post_activity) CoordinatorLayout coordinatorLayout;
+ @BindView(R.id.toolbar_edit_post_activity) Toolbar toolbar;
+ @BindView(R.id.post_title_text_view_edit_post_activity) TextView titleTextView;
+ @BindView(R.id.post_text_content_edit_text_edit_post_activity) EditText contentEditText;
+
+ private String mFullName;
+ private String mAccessToken;
+ private boolean isSubmitting = false;
+
+ @Inject
+ @Named("oauth")
+ Retrofit mOauthRetrofit;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_edit_post);
+
+ ButterKnife.bind(this);
+
+ ((Infinity) getApplication()).getAppComponent().inject(this);
+
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ Window window = getWindow();
+ if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) {
+ window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
+ }
+ window.setNavigationBarColor(ContextCompat.getColor(this, R.color.navBarColor));
+ }
+
+ setSupportActionBar(toolbar);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+
+ mFullName = getIntent().getExtras().getString(EXTRA_FULLNAME);
+ mAccessToken = getIntent().getExtras().getString(EXTRA_ACCESS_TOKEN);
+ titleTextView.setText(getIntent().getExtras().getString(EXTRA_TITLE));
+ contentEditText.setText(getIntent().getExtras().getString(EXTRA_CONTENT));
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.edit_post_activity, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
+ if(item.getItemId() == R.id.action_send_edit_post_activity) {
+ if(!isSubmitting) {
+ isSubmitting = true;
+
+ Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_SHORT).show();
+
+ Map<String, String> params = new HashMap<>();
+ params.put(RedditUtils.THING_ID_KEY, mFullName);
+ params.put(RedditUtils.TEXT_KEY, contentEditText.getText().toString());
+
+ mOauthRetrofit.create(RedditAPI.class)
+ .editPostOrComment(RedditUtils.getOAuthHeader(mAccessToken), params)
+ .enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ isSubmitting = false;
+ Toast.makeText(EditPostActivity.this, R.string.edit_success, Toast.LENGTH_SHORT).show();
+ Intent returnIntent = new Intent();
+ setResult(RESULT_OK, returnIntent);
+ finish();
+ }
+
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ isSubmitting = false;
+ Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
+ }
+ });
+
+ }
+ return true;
+ } else if(item.getItemId() == android.R.id.home) {
+ finish();
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
index c669d14a..0b71a15a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
@@ -279,7 +279,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
.into(((DataViewHolder) holder).iconGifImageView);
}
- ((DataViewHolder) holder).nameTextView.setTextColor(mContext.getResources().getColor(R.color.textColorPrimaryDark));
+ ((DataViewHolder) holder).nameTextView.setTextColor(mContext.getResources().getColor(R.color.colorPrimaryDarkDayNightTheme));
((DataViewHolder) holder).nameTextView.setText(authorPrefixed);
((DataViewHolder) holder).iconNameLinearLayout.setOnClickListener(view -> {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index 4be80aa7..ad65fe4f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -29,6 +29,7 @@ import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.evernote.android.state.State;
import com.google.android.material.appbar.AppBarLayout;
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
import com.livefront.bridge.Bridge;
@@ -57,8 +58,11 @@ public class ViewPostDetailActivity extends AppCompatActivity {
static final String EXTRA_POST_LIST_POSITION = "EPLI";
static final String EXTRA_POST_ID = "EPI";
+ private static final int EDIT_POST_REQUEST_CODE = 2;
+
private RequestManager mGlide;
private Locale mLocale;
+ private Menu mMenu;
private int orientation;
private int postListPosition = -1;
@@ -68,6 +72,8 @@ public class ViewPostDetailActivity extends AppCompatActivity {
@State
String mAccessToken;
@State
+ String mAccountName;
+ @State
Post mPost;
@State
boolean isLoadingMoreChildren = false;
@@ -164,7 +170,6 @@ public class ViewPostDetailActivity extends AppCompatActivity {
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) {
mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
-
showToast = true;
}
}
@@ -197,6 +202,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
mNullAccessToken = true;
} else {
mAccessToken = account.getAccessToken();
+ mAccountName = account.getUsername();
}
bindView();
@@ -209,9 +215,14 @@ public class ViewPostDetailActivity extends AppCompatActivity {
}
if(mPost == null) {
- mProgressBar.setVisibility(View.VISIBLE);
fetchPostAndCommentsById(getIntent().getExtras().getString(EXTRA_POST_ID));
} else {
+ if(mMenu != null && mPost.getAuthor().equals(mAccountName)) {
+ if(mPost.getPostType() == Post.TEXT_TYPE) {
+ mMenu.findItem(R.id.action_edit_view_post_detail_activity).setVisible(true);
+ }
+ mMenu.findItem(R.id.action_delete_view_post_detail_activity).setVisible(true);
+ }
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mPost,
mPost.getSubredditNamePrefixed(), mLocale, mLoadSubredditIconAsyncTask,
@@ -236,7 +247,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
} else {
if(isRefreshing) {
isRefreshing = false;
- refresh();
+ refresh(false);
} else {
mAdapter.addComments(comments, hasMoreChildren);
if(isLoadingMoreChildren) {
@@ -271,6 +282,13 @@ public class ViewPostDetailActivity extends AppCompatActivity {
public void onParsePostSuccess(Post post) {
mPost = post;
+ if(mMenu != null && mPost.getAuthor().equals(mAccountName)) {
+ if(mPost.getPostType() == Post.TEXT_TYPE) {
+ mMenu.findItem(R.id.action_edit_view_post_detail_activity).setVisible(true);
+ }
+ mMenu.findItem(R.id.action_delete_view_post_detail_activity).setVisible(true);
+ }
+
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mPost,
mPost.getSubredditNamePrefixed(), mLocale, mLoadSubredditIconAsyncTask,
@@ -410,7 +428,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
});
}
- private void refresh() {
+ private void refresh(boolean onlyRefreshPost) {
if(!isRefreshing) {
isRefreshing = true;
mChildrenStartingIndex = 0;
@@ -418,7 +436,9 @@ public class ViewPostDetailActivity extends AppCompatActivity {
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
mGlide.clear(mFetchPostInfoImageView);
- fetchComments();
+ if(!onlyRefreshPost) {
+ fetchComments();
+ }
Retrofit retrofit;
if(mAccessToken == null) {
@@ -438,11 +458,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
@Override
public void fetchPostFailed() {
- if(showToast) {
- Toast.makeText(ViewPostDetailActivity.this, R.string.refresh_post_failed, Toast.LENGTH_SHORT).show();
- } else {
- Snackbar.make(mCoordinatorLayout, R.string.refresh_post_failed, Snackbar.LENGTH_SHORT);
- }
+ showErrorMessage(R.string.refresh_post_failed);
isRefreshing = false;
}
});
@@ -457,6 +473,14 @@ public class ViewPostDetailActivity extends AppCompatActivity {
mGlide.load(R.drawable.load_post_error_indicator).into(mFetchPostInfoImageView);
}
+ private void showErrorMessage(int resId) {
+ if(showToast) {
+ Toast.makeText(ViewPostDetailActivity.this, resId, Toast.LENGTH_SHORT).show();
+ } else {
+ Snackbar.make(mCoordinatorLayout, resId, Snackbar.LENGTH_SHORT);
+ }
+ }
+
@Subscribe
public void onPostUpdateEvent(PostUpdateEventToDetailActivity event) {
if(mPost.getId().equals(event.postId)) {
@@ -468,6 +492,13 @@ public class ViewPostDetailActivity extends AppCompatActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.view_post_detail_activity, menu);
+ mMenu = menu;
+ if(mPost != null && mPost.getAuthor().equals(mAccountName)) {
+ if(mPost.getPostType() == Post.TEXT_TYPE) {
+ menu.findItem(R.id.action_edit_view_post_detail_activity).setVisible(true);
+ }
+ menu.findItem(R.id.action_delete_view_post_detail_activity).setVisible(true);
+ }
return true;
}
@@ -475,7 +506,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.action_refresh_view_post_detail_activity:
- refresh();
+ refresh(false);
return true;
case R.id.action_comment_view_post_detail_activity:
if(mAccessToken == null) {
@@ -490,6 +521,34 @@ public class ViewPostDetailActivity extends AppCompatActivity {
intent.putExtra(CommentActivity.EXTRA_IS_REPLYING_KEY, false);
startActivityForResult(intent, WRITE_COMMENT_REQUEST_CODE);
return true;
+ case R.id.action_edit_view_post_detail_activity:
+ Intent editPostItent = new Intent(this, EditPostActivity.class);
+ editPostItent.putExtra(EditPostActivity.EXTRA_ACCESS_TOKEN, mAccessToken);
+ editPostItent.putExtra(EditPostActivity.EXTRA_FULLNAME, mPost.getFullName());
+ editPostItent.putExtra(EditPostActivity.EXTRA_TITLE, mPost.getTitle());
+ editPostItent.putExtra(EditPostActivity.EXTRA_CONTENT, mPost.getSelfText());
+ startActivityForResult(editPostItent, EDIT_POST_REQUEST_CODE);
+ return true;
+ case R.id.action_delete_view_post_detail_activity:
+ new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.delete_this_post)
+ .setMessage(R.string.are_you_sure)
+ .setPositiveButton(R.string.delete, (dialogInterface, i)
+ -> DeleteThing.delete(mOauthRetrofit, mPost.getFullName(), mAccessToken, new DeleteThing.DeleteThingListener() {
+ @Override
+ public void deleteSuccess() {
+ Toast.makeText(ViewPostDetailActivity.this, R.string.delete_post_success, Toast.LENGTH_SHORT).show();
+ finish();
+ }
+
+ @Override
+ public void deleteFailed() {
+ showErrorMessage(R.string.delete_post_failed);
+ }
+ }))
+ .setNegativeButton(R.string.cancel, null)
+ .show();
+ return true;
case android.R.id.home:
onBackPressed();
return true;
@@ -500,18 +559,24 @@ public class ViewPostDetailActivity extends AppCompatActivity {
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
- if(data != null && resultCode == RESULT_OK && requestCode == WRITE_COMMENT_REQUEST_CODE) {
- if(data.hasExtra(EXTRA_COMMENT_DATA_KEY)) {
- CommentData comment = data.getExtras().getParcelable(EXTRA_COMMENT_DATA_KEY);
- if(comment.getDepth() == 0) {
- mAdapter.addComment(comment);
+ if(requestCode == WRITE_COMMENT_REQUEST_CODE) {
+ if(data != null && resultCode == RESULT_OK) {
+ if(data.hasExtra(EXTRA_COMMENT_DATA_KEY)) {
+ CommentData comment = data.getExtras().getParcelable(EXTRA_COMMENT_DATA_KEY);
+ if(comment.getDepth() == 0) {
+ mAdapter.addComment(comment);
+ } else {
+ String parentFullname = data.getExtras().getString(CommentActivity.EXTRA_PARENT_FULLNAME_KEY);
+ int parentPosition = data.getExtras().getInt(CommentActivity.EXTRA_PARENT_POSITION_KEY);
+ mAdapter.addChildComment(comment, parentFullname, parentPosition);
+ }
} else {
- String parentFullname = data.getExtras().getString(CommentActivity.EXTRA_PARENT_FULLNAME_KEY);
- int parentPosition = data.getExtras().getInt(CommentActivity.EXTRA_PARENT_POSITION_KEY);
- mAdapter.addChildComment(comment, parentFullname, parentPosition);
+ Toast.makeText(this, R.string.send_comment_failed, Toast.LENGTH_SHORT).show();
}
- } else {
- Toast.makeText(this, R.string.send_comment_failed, Toast.LENGTH_SHORT).show();
+ }
+ } else if(requestCode == EDIT_POST_REQUEST_CODE) {
+ if(resultCode == RESULT_OK) {
+ refresh(true);
}
}
}
diff --git a/app/src/main/res/layout/activity_edit_post.xml b/app/src/main/res/layout/activity_edit_post.xml
new file mode 100644
index 00000000..e95ba34c
--- /dev/null
+++ b/app/src/main/res/layout/activity_edit_post.xml
@@ -0,0 +1,64 @@
+<?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_edit_post_activity"
+ tools:context=".EditPostActivity">
+
+ <com.google.android.material.appbar.AppBarLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:theme="@style/AppTheme.AppBarOverlay">
+
+ <androidx.appcompat.widget.Toolbar
+ android:id="@+id/toolbar_edit_post_activity"
+ android:layout_width="match_parent"
+ android:layout_height="?attr/actionBarSize"
+ app:popupTheme="@style/AppTheme.PopupOverlay"
+ app:navigationIcon="?attr/homeAsUpIndicator" />
+
+ </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">
+
+ <TextView
+ android:id="@+id/post_title_text_view_edit_post_activity"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="top"
+ android:padding="16dp"
+ android:textSize="18sp"
+ android:textColor="@color/primaryTextColor" />
+
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="1dp"
+ android:background="@color/dividerColor" />
+
+ <EditText
+ android:id="@+id/post_text_content_edit_text_edit_post_activity"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="top"
+ android:padding="16dp"
+ android:hint="@string/post_text_content_hint"
+ android:inputType="textCapSentences|textMultiLine"
+ android:textSize="18sp"
+ android:background="#00000000"
+ android:textColor="@color/primaryTextColor" />
+
+ </LinearLayout>
+
+ </androidx.core.widget.NestedScrollView>
+
+</androidx.coordinatorlayout.widget.CoordinatorLayout> \ No newline at end of file
diff --git a/app/src/main/res/layout/activity_post_image.xml b/app/src/main/res/layout/activity_post_image.xml
index 8410242b..2ea9b68b 100644
--- a/app/src/main/res/layout/activity_post_image.xml
+++ b/app/src/main/res/layout/activity_post_image.xml
@@ -87,7 +87,7 @@
android:textColor="@color/primaryTextColor"
android:visibility="gone"
app:lib_setRadius="3dp"
- app:lib_setRoundedBorderColor="@color/textColorPrimaryDark"
+ app:lib_setRoundedBorderColor="@color/colorPrimaryDarkDayNightTheme"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
@@ -100,7 +100,7 @@
android:text="@string/spoiler"
android:textColor="@color/primaryTextColor"
app:lib_setRadius="3dp"
- app:lib_setRoundedBorderColor="@color/textColorPrimaryDark"
+ app:lib_setRoundedBorderColor="@color/colorPrimaryDarkDayNightTheme"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
diff --git a/app/src/main/res/layout/activity_post_link.xml b/app/src/main/res/layout/activity_post_link.xml
index 77aba190..9de49a9e 100644
--- a/app/src/main/res/layout/activity_post_link.xml
+++ b/app/src/main/res/layout/activity_post_link.xml
@@ -87,7 +87,7 @@
android:textColor="@color/primaryTextColor"
android:visibility="gone"
app:lib_setRadius="3dp"
- app:lib_setRoundedBorderColor="@color/textColorPrimaryDark"
+ app:lib_setRoundedBorderColor="@color/colorPrimaryDarkDayNightTheme"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
@@ -100,7 +100,7 @@
android:text="@string/spoiler"
android:textColor="@color/primaryTextColor"
app:lib_setRadius="3dp"
- app:lib_setRoundedBorderColor="@color/textColorPrimaryDark"
+ app:lib_setRoundedBorderColor="@color/colorPrimaryDarkDayNightTheme"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
diff --git a/app/src/main/res/layout/activity_post_text.xml b/app/src/main/res/layout/activity_post_text.xml
index 6380d3d2..b9798901 100644
--- a/app/src/main/res/layout/activity_post_text.xml
+++ b/app/src/main/res/layout/activity_post_text.xml
@@ -87,7 +87,7 @@
android:textColor="@color/primaryTextColor"
android:visibility="gone"
app:lib_setRadius="3dp"
- app:lib_setRoundedBorderColor="@color/textColorPrimaryDark"
+ app:lib_setRoundedBorderColor="@color/colorPrimaryDarkDayNightTheme"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
@@ -100,7 +100,7 @@
android:text="@string/spoiler"
android:textColor="@color/primaryTextColor"
app:lib_setRadius="3dp"
- app:lib_setRoundedBorderColor="@color/textColorPrimaryDark"
+ app:lib_setRoundedBorderColor="@color/colorPrimaryDarkDayNightTheme"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
diff --git a/app/src/main/res/layout/activity_post_video.xml b/app/src/main/res/layout/activity_post_video.xml
index 3dcce96d..512f0304 100644
--- a/app/src/main/res/layout/activity_post_video.xml
+++ b/app/src/main/res/layout/activity_post_video.xml
@@ -87,7 +87,7 @@
android:textColor="@color/primaryTextColor"
android:visibility="gone"
app:lib_setRadius="3dp"
- app:lib_setRoundedBorderColor="@color/textColorPrimaryDark"
+ app:lib_setRoundedBorderColor="@color/colorPrimaryDarkDayNightTheme"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
@@ -100,7 +100,7 @@
android:text="@string/spoiler"
android:textColor="@color/primaryTextColor"
app:lib_setRadius="3dp"
- app:lib_setRoundedBorderColor="@color/textColorPrimaryDark"
+ app:lib_setRoundedBorderColor="@color/colorPrimaryDarkDayNightTheme"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
diff --git a/app/src/main/res/layout/activity_view_user_detail.xml b/app/src/main/res/layout/activity_view_user_detail.xml
index c85a76cb..7917e45a 100644
--- a/app/src/main/res/layout/activity_view_user_detail.xml
+++ b/app/src/main/res/layout/activity_view_user_detail.xml
@@ -64,7 +64,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textSize="18sp"
- android:textColor="@color/textColorPrimaryDark"
+ android:textColor="@color/colorPrimaryDarkDayNightTheme"
android:layout_gravity="center_horizontal"/>
<TextView
diff --git a/app/src/main/res/layout/item_comment.xml b/app/src/main/res/layout/item_comment.xml
index 973b4b44..82281e14 100644
--- a/app/src/main/res/layout/item_comment.xml
+++ b/app/src/main/res/layout/item_comment.xml
@@ -9,7 +9,7 @@
android:id="@+id/vertical_block_item_post_comment"
android:layout_width="wrap_content"
android:layout_height="match_parent"
- android:background="@color/textColorPrimaryDark"/>
+ android:background="@color/colorPrimaryDarkDayNightTheme"/>
<LinearLayout
android:layout_width="match_parent"
@@ -30,7 +30,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="16dp"
- android:textColor="@color/textColorPrimaryDark"/>
+ android:textColor="@color/colorPrimaryDarkDayNightTheme"/>
<TextView
android:id="@+id/comment_time_text_view_item_post_comment"
diff --git a/app/src/main/res/layout/item_load_more_comments_placeholder.xml b/app/src/main/res/layout/item_load_more_comments_placeholder.xml
index 9979a6fe..0d967b27 100644
--- a/app/src/main/res/layout/item_load_more_comments_placeholder.xml
+++ b/app/src/main/res/layout/item_load_more_comments_placeholder.xml
@@ -8,7 +8,7 @@
android:id="@+id/vertical_block_item_load_more_comments"
android:layout_width="wrap_content"
android:layout_height="match_parent"
- android:background="@color/textColorPrimaryDark" />
+ android:background="@color/colorPrimaryDarkDayNightTheme" />
<TextView
android:id="@+id/placeholder_text_view_item_load_more_comments"
diff --git a/app/src/main/res/layout/item_post.xml b/app/src/main/res/layout/item_post.xml
index 640f6c3f..4c536025 100644
--- a/app/src/main/res/layout/item_post.xml
+++ b/app/src/main/res/layout/item_post.xml
@@ -161,7 +161,7 @@
android:padding="4dp"
android:visibility="gone"
app:lib_setRadius="3dp"
- app:lib_setRoundedBorderColor="@color/textColorPrimaryDark"
+ app:lib_setRoundedBorderColor="@color/colorPrimaryDarkDayNightTheme"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
@@ -176,7 +176,7 @@
android:padding="4dp"
android:visibility="gone"
app:lib_setRadius="3dp"
- app:lib_setRoundedBorderColor="@color/textColorPrimaryDark"
+ app:lib_setRoundedBorderColor="@color/colorPrimaryDarkDayNightTheme"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
diff --git a/app/src/main/res/layout/item_post_detail.xml b/app/src/main/res/layout/item_post_detail.xml
index 4b75b2c0..a1fc7776 100644
--- a/app/src/main/res/layout/item_post_detail.xml
+++ b/app/src/main/res/layout/item_post_detail.xml
@@ -45,7 +45,7 @@
android:layout_alignParentBottom="true"
android:layout_below="@id/subreddit_text_view_item_post_detail"
android:layout_toEndOf="@id/icon_gif_image_view_item_post_detail"
- android:textColor="@color/textColorPrimaryDark" />
+ android:textColor="@color/colorPrimaryDarkDayNightTheme" />
</RelativeLayout>
@@ -161,7 +161,7 @@
android:padding="4dp"
android:visibility="gone"
app:lib_setRadius="3dp"
- app:lib_setRoundedBorderColor="@color/textColorPrimaryDark"
+ app:lib_setRoundedBorderColor="@color/colorPrimaryDarkDayNightTheme"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
@@ -176,7 +176,7 @@
android:padding="4dp"
android:visibility="gone"
app:lib_setRadius="3dp"
- app:lib_setRoundedBorderColor="@color/textColorPrimaryDark"
+ app:lib_setRoundedBorderColor="@color/colorPrimaryDarkDayNightTheme"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
diff --git a/app/src/main/res/layout/item_subreddit_listing.xml b/app/src/main/res/layout/item_subreddit_listing.xml
index 52409bfb..369f34fb 100644
--- a/app/src/main/res/layout/item_subreddit_listing.xml
+++ b/app/src/main/res/layout/item_subreddit_listing.xml
@@ -35,7 +35,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/baseline_add_white_24"
- android:tint="@color/textColorPrimaryDark"
+ android:tint="@color/colorPrimaryDarkDayNightTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
diff --git a/app/src/main/res/layout/item_user_listing.xml b/app/src/main/res/layout/item_user_listing.xml
index 04b16bdc..bdf5436f 100644
--- a/app/src/main/res/layout/item_user_listing.xml
+++ b/app/src/main/res/layout/item_user_listing.xml
@@ -35,7 +35,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/baseline_add_white_24"
- android:tint="@color/textColorPrimaryDark"
+ android:tint="@color/colorPrimaryDarkDayNightTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
diff --git a/app/src/main/res/menu/edit_post_activity.xml b/app/src/main/res/menu/edit_post_activity.xml
new file mode 100644
index 00000000..270d7664
--- /dev/null
+++ b/app/src/main/res/menu/edit_post_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_edit_post_activity"
+ android:orderInCategory="1"
+ android:title="@string/action_send"
+ android:icon="@drawable/ic_send_white_24dp"
+ app:showAsAction="ifRoom" />
+</menu> \ No newline at end of file
diff --git a/app/src/main/res/menu/view_post_detail_activity.xml b/app/src/main/res/menu/view_post_detail_activity.xml
index f5b327d8..76e2db37 100644
--- a/app/src/main/res/menu/view_post_detail_activity.xml
+++ b/app/src/main/res/menu/view_post_detail_activity.xml
@@ -13,4 +13,18 @@
android:orderInCategory="2"
android:title="@string/action_refresh"
app:showAsAction="never" />
+
+ <item
+ android:id="@+id/action_edit_view_post_detail_activity"
+ android:orderInCategory="3"
+ android:title="@string/action_edit_post"
+ app:showAsAction="never"
+ android:visible="false" />
+
+ <item
+ android:id="@+id/action_delete_view_post_detail_activity"
+ android:orderInCategory="3"
+ android:title="@string/action_delete_post"
+ app:showAsAction="never"
+ android:visible="false" />
</menu> \ No newline at end of file
diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml
index 8d932a36..ddb63e21 100644
--- a/app/src/main/res/values-night/colors.xml
+++ b/app/src/main/res/values-night/colors.xml
@@ -12,7 +12,7 @@
<color name="primaryTextColor">#FFFFFF</color>
- <color name="textColorPrimaryDark">#1E88E5</color>
+ <color name="colorPrimaryDarkDayNightTheme">#1E88E5</color>
<color name="circularProgressBarBackground">#242424</color>
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 9d88ac4f..bf91858c 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -12,7 +12,7 @@
<color name="primaryTextColor">#000000</color>
- <color name="textColorPrimaryDark">@color/colorPrimaryDark</color>
+ <color name="colorPrimaryDarkDayNightTheme">@color/colorPrimaryDark</color>
<color name="circularProgressBarBackground">#FFFFFF</color>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index f76c1e66..392ffc9b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -24,6 +24,8 @@
<string name="action_stop_lazy_mode">Stop Lazy Mode</string>
<string name="action_send">Send</string>
<string name="action_sort">Sort</string>
+ <string name="action_edit_post">Edit Post</string>
+ <string name="action_delete_post">Delete Post</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>
@@ -178,4 +180,13 @@
<string name="log_out">Log out</string>
<string name="press_here_to_login">Press here to login</string>
<string name="login_first">Login first</string>
+
+ <string name="delete_this_post">Delete This Post</string>
+ <string name="are_you_sure">Are you sure?</string>
+ <string name="delete">Delete</string>
+ <string name="cancel">Cancel</string>
+ <string name="delete_post_success">Delete successfully</string>
+ <string name="delete_post_failed">Delete failed</string>
+
+ <string name="edit_success">Edit Successful</string>
</resources>
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 75f23b15..0b20ce0e 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -46,5 +46,18 @@
<item name="tabBackground">?attr/selectableItemBackground</item>
<item name="tabSelectedTextColor">@android:color/white</item>
</style>
+
+ <style name="MaterialAlertDialogTheme" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
+ <item name="buttonBarPositiveButtonStyle">@style/MaterialAlertDialogPositiveButtonStyle</item>
+ <item name="buttonBarNegativeButtonStyle">@style/MaterialAlertDialogNegativeButtonStyle</item>
+ </style>
+
+ <style name="MaterialAlertDialogPositiveButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
+ <item name="android:textColor">@color/colorAccent</item>
+ </style>
+
+ <style name="MaterialAlertDialogNegativeButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
+ <item name="android:textColor">@color/primaryTextColor</item>
+ </style>
</resources>