aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-02-18 11:28:35 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-02-18 11:28:35 +0000
commita28d022cde3d2d6e0f00f937acfcefb653e1199d (patch)
tree67f83f35461352eadd05460aa83d216ef7123802 /app/src/main/java
parentbc043c442f4069157cf608e1b71d9c3ab3d0389e (diff)
downloadinfinity-for-reddit-a28d022cde3d2d6e0f00f937acfcefb653e1199d.tar
infinity-for-reddit-a28d022cde3d2d6e0f00f937acfcefb653e1199d.tar.gz
infinity-for-reddit-a28d022cde3d2d6e0f00f937acfcefb653e1199d.tar.bz2
infinity-for-reddit-a28d022cde3d2d6e0f00f937acfcefb653e1199d.tar.lz
infinity-for-reddit-a28d022cde3d2d6e0f00f937acfcefb653e1199d.tar.xz
infinity-for-reddit-a28d022cde3d2d6e0f00f937acfcefb653e1199d.tar.zst
infinity-for-reddit-a28d022cde3d2d6e0f00f937acfcefb653e1199d.zip
Deleting multireddit is now available.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java27
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteMultiredditInDatabaseAsyncTask.java37
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/CreateMultiReddit.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/DeleteMultiReddit.java41
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditDao.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/ParseMultiReddit.java23
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java4
7 files changed, 111 insertions, 28 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java
index 47c0f280..220984c9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java
@@ -20,6 +20,7 @@ import androidx.fragment.app.Fragment;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import javax.inject.Inject;
import javax.inject.Named;
@@ -34,6 +35,7 @@ import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment
import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.MultiReddit.DeleteMultiReddit;
import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit;
import ml.docilealligator.infinityforreddit.Post.PostDataSource;
import ml.docilealligator.infinityforreddit.R;
@@ -260,6 +262,31 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
case R.id.action_change_post_layout_view_multi_reddit_detail_activity:
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true;
+ case R.id.action_delte_view_multi_reddit_detail_activity:
+ new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.delete)
+ .setMessage(R.string.delete_multi_reddit_dialog_message)
+ .setPositiveButton(R.string.delete, (dialogInterface, i)
+ -> {
+ DeleteMultiReddit.deleteMultiReddit(mOauthRetrofit, mRedditDataRoomDatabase,
+ mAccessToken, mAccountName, multiPath, new DeleteMultiReddit.DeleteMultiRedditListener() {
+ @Override
+ public void success() {
+ Toast.makeText(ViewMultiRedditDetailActivity.this,
+ R.string.delete_multi_reddit_success, Toast.LENGTH_SHORT).show();
+ finish();
+ }
+
+ @Override
+ public void failed() {
+ Toast.makeText(ViewMultiRedditDetailActivity.this,
+ R.string.delete_multi_reddit_failed, Toast.LENGTH_SHORT).show();
+ }
+ });
+ })
+ .setNegativeButton(R.string.cancel, null)
+ .show();
+ return true;
}
return false;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteMultiredditInDatabaseAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteMultiredditInDatabaseAsyncTask.java
new file mode 100644
index 00000000..14805c9c
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteMultiredditInDatabaseAsyncTask.java
@@ -0,0 +1,37 @@
+package ml.docilealligator.infinityforreddit.AsyncTask;
+
+import android.os.AsyncTask;
+
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+
+public class DeleteMultiredditInDatabaseAsyncTask extends AsyncTask<Void, Void, Void> {
+ public interface DeleteMultiredditInDatabaseAsyncTaskListener {
+ void success();
+ }
+
+ private RedditDataRoomDatabase redditDataRoomDatabase;
+ private String accountName;
+ private String multipath;
+ private DeleteMultiredditInDatabaseAsyncTaskListener deleteMultiredditInDatabaseAsyncTaskListener;
+
+ public DeleteMultiredditInDatabaseAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase,
+ String accountName, String multipath,
+ DeleteMultiredditInDatabaseAsyncTaskListener deleteMultiredditInDatabaseAsyncTaskListener) {
+ this.redditDataRoomDatabase = redditDataRoomDatabase;
+ this.accountName = accountName;
+ this.multipath = multipath;
+ this.deleteMultiredditInDatabaseAsyncTaskListener = deleteMultiredditInDatabaseAsyncTaskListener;
+ }
+
+ @Override
+ protected Void doInBackground(Void... voids) {
+ redditDataRoomDatabase.multiRedditDao().deleteMultiReddit(multipath, accountName);
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ super.onPostExecute(aVoid);
+ deleteMultiredditInDatabaseAsyncTaskListener.success();
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/CreateMultiReddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/CreateMultiReddit.java
index ec741466..aa6bf468 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/CreateMultiReddit.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/CreateMultiReddit.java
@@ -1,7 +1,5 @@
package ml.docilealligator.infinityforreddit.MultiReddit;
-import android.util.Log;
-
import androidx.annotation.NonNull;
import java.util.HashMap;
@@ -36,7 +34,6 @@ public class CreateMultiReddit {
new ParseMultiReddit.ParseMultiRedditListener() {
@Override
public void success() {
- Log.i("asfasfas", response.body());
createMultiRedditListener.success();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/DeleteMultiReddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/DeleteMultiReddit.java
new file mode 100644
index 00000000..070f6944
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/DeleteMultiReddit.java
@@ -0,0 +1,41 @@
+package ml.docilealligator.infinityforreddit.MultiReddit;
+
+import androidx.annotation.NonNull;
+
+import ml.docilealligator.infinityforreddit.AsyncTask.DeleteMultiredditInDatabaseAsyncTask;
+import ml.docilealligator.infinityforreddit.RedditAPI;
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.Utils.RedditUtils;
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+import retrofit2.Retrofit;
+
+public class DeleteMultiReddit {
+ public interface DeleteMultiRedditListener {
+ void success();
+ void failed();
+ }
+
+ public static void deleteMultiReddit(Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase,
+ String accessToken, String accountName, String multipath,
+ DeleteMultiRedditListener deleteMultiRedditListener) {
+ oauthRetrofit.create(RedditAPI.class).deleteMultiReddit(RedditUtils.getOAuthHeader(accessToken),
+ multipath).enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ if (response.isSuccessful()) {
+ new DeleteMultiredditInDatabaseAsyncTask(redditDataRoomDatabase, accountName, multipath,
+ deleteMultiRedditListener::success).execute();
+ } else {
+ deleteMultiRedditListener.failed();
+ }
+ }
+
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ deleteMultiRedditListener.failed();
+ }
+ });
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditDao.java
index 7d3654c8..198e610e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditDao.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditDao.java
@@ -25,8 +25,8 @@ public interface MultiRedditDao {
@Query("SELECT * FROM multi_reddits WHERE name = :name AND username = :username COLLATE NOCASE LIMIT 1")
MultiReddit getMultiReddit(String name, String username);
- @Query("DELETE FROM multi_reddits WHERE name = :name AND username = :username")
- void deleteMultiReddit(String name, String username);
+ @Query("DELETE FROM multi_reddits WHERE path = :multipath AND username = :username")
+ void deleteMultiReddit(String multipath, String username);
@Query("DELETE FROM multi_reddits WHERE username = :username")
void deleteAllUserMultiReddits(String username);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/ParseMultiReddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/ParseMultiReddit.java
index 63964ecc..6d0d3740 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/ParseMultiReddit.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/ParseMultiReddit.java
@@ -81,29 +81,6 @@ public class ParseMultiReddit {
if (!parseFailed) {
for (int i = 0; i < arrayResponse.length(); i++) {
try {
- /*String displayName = singleMultiReddit.getString(JSONUtils.DISPLAY_NAME);
- String name = singleMultiReddit.getString(JSONUtils.NAME_KEY);
- String description = singleMultiReddit.getString(JSONUtils.DESCRIPTION_HTML_KEY);
- int nSubscribers = singleMultiReddit.getInt(JSONUtils.NUM_SUBSCRIBERS_KEY);
- String copiedFrom = singleMultiReddit.getString(JSONUtils.COPIED_FROM_KEY);
- String iconUrl = singleMultiReddit.getString(JSONUtils.ICON_URL_KEY);
- long createdUTC = singleMultiReddit.getLong(JSONUtils.CREATED_UTC_KEY);
- String visibility = singleMultiReddit.getString(JSONUtils.VISIBILITY_KEY);
- boolean over18 = singleMultiReddit.getBoolean(JSONUtils.OVER_18_KEY);
- String path = singleMultiReddit.getString(JSONUtils.PATH_KEY);
- String owner = singleMultiReddit.getString(JSONUtils.OWNER_KEY);
- boolean isSubscriber = singleMultiReddit.getBoolean(JSONUtils.IS_SUBSCRIBER_KEY);
- boolean isFavorited = singleMultiReddit.getBoolean(JSONUtils.IS_FAVORITED_KEY);
-
- JSONArray subredditsArray = singleMultiReddit.getJSONArray(JSONUtils.SUBREDDITS_KEY);
- ArrayList<String> subreddits = new ArrayList<>();
- for (int j = 0; j < subredditsArray.length(); j++) {
- subreddits.add(subredditsArray.getJSONObject(j).getString(JSONUtils.NAME_KEY));
- }
-
- MultiReddit multiReddit = new MultiReddit(path, displayName, name, description, copiedFrom,
- iconUrl, visibility, owner, nSubscribers, createdUTC, over18, isSubscriber,
- isFavorited, subreddits);*/
multiReddits.add(parseMultiReddit(arrayResponse.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY)));
} catch (JSONException e) {
e.printStackTrace();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java
index 19ca23c4..e25fba92 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java
@@ -5,6 +5,7 @@ import java.util.Map;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;
+import retrofit2.http.DELETE;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
@@ -292,4 +293,7 @@ public interface RedditAPI {
@FormUrlEncoded
@POST("/api/multi/multipath")
Call<String> createMultiReddit(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params);
+
+ @DELETE("/api/multi/multipath")
+ Call<String> deleteMultiReddit(@HeaderMap Map<String, String> headers, @Query("multipath") String multipath);
}