diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java index 87ae213b..46668abe 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java @@ -5,6 +5,7 @@ import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -13,7 +14,6 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.Switch; import android.widget.TextView; -import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -24,6 +24,8 @@ import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.snackbar.Snackbar; import com.r0adkll.slidr.Slidr; +import java.util.concurrent.Executor; + import javax.inject.Inject; import javax.inject.Named; @@ -84,6 +86,8 @@ public class EditMultiRedditActivity extends BaseActivity { SharedPreferences mCurrentAccountSharedPreferences; @Inject CustomThemeWrapper mCustomThemeWrapper; + @Inject + Executor mExecutor; private String mAccessToken; private String mAccountName; private MultiReddit multiReddit; @@ -114,12 +118,7 @@ public class EditMultiRedditActivity extends BaseActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); - mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); - - if (mAccessToken == null) { - Toast.makeText(this, R.string.logged_out, Toast.LENGTH_SHORT).show(); - finish(); - } + mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, "-"); if (savedInstanceState != null) { multiReddit = savedInstanceState.getParcelable(MULTI_REDDIT_STATE); @@ -133,22 +132,41 @@ public class EditMultiRedditActivity extends BaseActivity { private void bindView() { if (multiReddit == null) { - FetchMultiRedditInfo.fetchMultiRedditInfo(mRetrofit, mAccessToken, multipath, new FetchMultiRedditInfo.FetchMultiRedditInfoListener() { - @Override - public void success(MultiReddit multiReddit) { - EditMultiRedditActivity.this.multiReddit = multiReddit; - progressBar.setVisibility(View.GONE); - linearLayout.setVisibility(View.VISIBLE); - nameEditText.setText(multiReddit.getDisplayName()); - descriptionEditText.setText(multiReddit.getDescription()); - visibilitySwitch.setChecked(!multiReddit.getVisibility().equals("public")); - } + if (mAccessToken == null) { + FetchMultiRedditInfo.anonymousFetchMultiRedditInfo(mExecutor, new Handler(), + mRedditDataRoomDatabase, multipath, new FetchMultiRedditInfo.FetchMultiRedditInfoListener() { + @Override + public void success(MultiReddit multiReddit) { + EditMultiRedditActivity.this.multiReddit = multiReddit; + progressBar.setVisibility(View.GONE); + linearLayout.setVisibility(View.VISIBLE); + nameEditText.setText(multiReddit.getDisplayName()); + descriptionEditText.setText(multiReddit.getDescription()); + } - @Override - public void failed() { - Snackbar.make(coordinatorLayout, R.string.cannot_fetch_multireddit, Snackbar.LENGTH_SHORT).show(); - } - }); + @Override + public void failed() { + //Will not be called + } + }); + } else { + FetchMultiRedditInfo.fetchMultiRedditInfo(mRetrofit, mAccessToken, multipath, new FetchMultiRedditInfo.FetchMultiRedditInfoListener() { + @Override + public void success(MultiReddit multiReddit) { + EditMultiRedditActivity.this.multiReddit = multiReddit; + progressBar.setVisibility(View.GONE); + linearLayout.setVisibility(View.VISIBLE); + nameEditText.setText(multiReddit.getDisplayName()); + descriptionEditText.setText(multiReddit.getDescription()); + visibilitySwitch.setChecked(!multiReddit.getVisibility().equals("public")); + } + + @Override + public void failed() { + Snackbar.make(coordinatorLayout, R.string.cannot_fetch_multireddit, Snackbar.LENGTH_SHORT).show(); + } + }); + } } else { progressBar.setVisibility(View.GONE); linearLayout.setVisibility(View.VISIBLE); @@ -180,29 +198,41 @@ public class EditMultiRedditActivity extends BaseActivity { finish(); return true; } else if (itemId == R.id.action_save_edit_multi_reddit_activity) { - if (mAccountName == null || mAccessToken == null) { - Snackbar.make(coordinatorLayout, R.string.something_went_wrong, Snackbar.LENGTH_SHORT).show(); - return true; - } if (nameEditText.getText() == null || nameEditText.getText().toString().equals("")) { Snackbar.make(coordinatorLayout, R.string.no_multi_reddit_name, Snackbar.LENGTH_SHORT).show(); return true; } - String jsonModel = new MultiRedditJSONModel(nameEditText.getText().toString(), descriptionEditText.getText().toString(), - visibilitySwitch.isChecked(), multiReddit.getSubreddits()).createJSONModel(); - EditMultiReddit.editMultiReddit(mRetrofit, mAccessToken, multiReddit.getPath(), - jsonModel, new EditMultiReddit.EditMultiRedditListener() { - @Override - public void success() { - finish(); - } + if (mAccessToken == null) { + EditMultiReddit.anonymousEditMultiReddit(mExecutor, new Handler(), mRedditDataRoomDatabase, + multiReddit, new EditMultiReddit.EditMultiRedditListener() { + @Override + public void success() { + finish(); + } - @Override - public void failed() { - Snackbar.make(coordinatorLayout, R.string.edit_multi_reddit_failed, Snackbar.LENGTH_SHORT).show(); - } - }); + @Override + public void failed() { + //Will not be called + } + }); + } else { + String jsonModel = new MultiRedditJSONModel(nameEditText.getText().toString(), descriptionEditText.getText().toString(), + visibilitySwitch.isChecked(), multiReddit.getSubreddits()).createJSONModel(); + EditMultiReddit.editMultiReddit(mRetrofit, mAccessToken, multiReddit.getPath(), + jsonModel, new EditMultiReddit.EditMultiRedditListener() { + @Override + public void success() { + finish(); + } + + @Override + public void failed() { + Snackbar.make(coordinatorLayout, R.string.edit_multi_reddit_failed, Snackbar.LENGTH_SHORT).show(); + } + }); + } + return true; } return false; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/EditMultiReddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/EditMultiReddit.java index 36303b90..6efa6487 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/EditMultiReddit.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/EditMultiReddit.java @@ -1,10 +1,15 @@ package ml.docilealligator.infinityforreddit.multireddit; +import android.os.Handler; + import androidx.annotation.NonNull; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.Executor; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.utils.APIUtils; import retrofit2.Call; @@ -40,4 +45,19 @@ public class EditMultiReddit { } }); } + + public static void anonymousEditMultiReddit(Executor executor, Handler handler, + RedditDataRoomDatabase redditDataRoomDatabase, + MultiReddit multiReddit, + EditMultiRedditListener editMultiRedditListener) { + executor.execute(() -> { + redditDataRoomDatabase.multiRedditDao().insert(multiReddit); + ArrayList anonymousMultiredditSubreddits = new ArrayList<>(); + for (String s : multiReddit.getSubreddits()) { + anonymousMultiredditSubreddits.add(new AnonymousMultiredditSubreddit(multiReddit.getPath(), s)); + } + redditDataRoomDatabase.anonymousMultiredditSubredditDao().insertAll(anonymousMultiredditSubreddits); + handler.post(editMultiRedditListener::success); + }); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FetchMultiRedditInfo.java b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FetchMultiRedditInfo.java index 97d2a2d1..f867d530 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FetchMultiRedditInfo.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/FetchMultiRedditInfo.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit.multireddit; import android.os.AsyncTask; +import android.os.Handler; import androidx.annotation.NonNull; @@ -9,7 +10,9 @@ import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; +import java.util.concurrent.Executor; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.apis.RedditAPI; import ml.docilealligator.infinityforreddit.utils.JSONUtils; import ml.docilealligator.infinityforreddit.utils.APIUtils; @@ -44,6 +47,23 @@ public class FetchMultiRedditInfo { }); } + public static void anonymousFetchMultiRedditInfo(Executor executor, Handler handler, + RedditDataRoomDatabase redditDataRoomDatabase, + String multipath, + FetchMultiRedditInfoListener fetchMultiRedditInfoListener) { + executor.execute(() -> { + MultiReddit multiReddit = redditDataRoomDatabase.multiRedditDao().getMultiReddit(multipath, "-"); + ArrayList anonymousMultiredditSubreddits = + (ArrayList) redditDataRoomDatabase.anonymousMultiredditSubredditDao().getAllAnonymousMultiRedditSubreddits(multipath); + ArrayList subredditNames = new ArrayList<>(); + for (AnonymousMultiredditSubreddit a : anonymousMultiredditSubreddits) { + subredditNames.add(a.getSubredditName()); + } + multiReddit.setSubreddits(subredditNames); + handler.post(() -> fetchMultiRedditInfoListener.success(multiReddit)); + }); + } + private static class ParseMultiRedditInfoAsyncTask extends AsyncTask { private String response; 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 69721319..a5099e85 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiRedditDao.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/multireddit/MultiRedditDao.java @@ -22,8 +22,8 @@ public interface MultiRedditDao { @Query("SELECT * FROM multi_reddits WHERE username = :username AND is_favorite ORDER BY name COLLATE NOCASE ASC") LiveData> getAllFavoriteMultiReddits(String username); - @Query("SELECT * FROM multi_reddits WHERE name = :name AND username = :username COLLATE NOCASE LIMIT 1") - MultiReddit getMultiReddit(String name, String username); + @Query("SELECT * FROM multi_reddits WHERE path = :path AND username = :username COLLATE NOCASE LIMIT 1") + MultiReddit getMultiReddit(String path, String username); @Query("DELETE FROM multi_reddits WHERE name = :name AND username = :username") void deleteMultiReddit(String name, String username); diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 84008000..10b02874 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -505,7 +505,6 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "Kann dieses Multireddit nicht erstellen" "Dieses Multireddit existiert bereits" "Kann dieses Multireddit nicht bearbeiten" - "Du bist abgemeldet" "Löschen erfolgreich" "Löschen fehlgeschlagen" "Bist du sicher?" diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 85348c4e..58689b60 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -516,7 +516,6 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "Ocurrió un error creando este multireddit" "Este multireddit ya existe" "Ocurrió un error al editar el multireddit" - "Sesión cerrada" "Borrado satisfactoriamente" "Borrado fallido" "¿Seguro?" diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 52e7b9ca..176d913b 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -538,7 +538,6 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "Impossible de créer ce multireddit" "Ce multireddit existe déjà" "Impossible d'éditer ce multireddit" - "Vous êtes déconnectés" "Supprimé avec succès" "Supression échouée" "Êtes vous sûr ?" diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index 2bcdc1a3..34b7099d 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -528,7 +528,6 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "इस मल्टीरैडिट का निर्माण असफल " "यह मल्टीरैडिट पहले से उपलब्ध है " "इस मल्टीरैडिट का संपादन असफल " - "आप लाॅग्ड आउट हैं" "सफलतापूर्वक मिटाई गई " "मिटाना असफल " "क्या आप निश्चित हैं? " diff --git a/app/src/main/res/values-hr/strings.xml b/app/src/main/res/values-hr/strings.xml index 59bc16cd..a4906160 100644 --- a/app/src/main/res/values-hr/strings.xml +++ b/app/src/main/res/values-hr/strings.xml @@ -459,7 +459,6 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "Nije moguće stvoriti ovaj multireddit" "Ovaj multireddit već postoji" "Nije moguće urediti ovaj multireddit" - "Odjavljeni ste" "Brisanje uspješno" "Brisanje nije uspjelo" "Jeste li sigurni?" diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 6723f9fd..b6c9eada 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -483,7 +483,6 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "Nem lehet létrehozni ezt a multiredditet" "Ez a multireddit már létezik" "Nem lehet szerkeszteni ezt a multiredditet" - "Kijelentkeztél" "Törlés sikeres" "Törlés nem sikerült" "Biztos vagy benne?" diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 7ace4ce6..5324b6ac 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -492,7 +492,6 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "Impossibile creare questo multireddit" "Il multireddit esiste già" "Impossibile modificare questo multireddit" - "Non sei connesso" "Cancellazione riuscita" "Cancellazione fallita" "Sei sicuro?" diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 4f8ee954..fefb69b6 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -530,7 +530,6 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "このカスタムフィードを作成できませんでした" "このカスタムフィードは既に存在しています" "このカスタムフィードを編集できませんでした" - "ログアウト状態です" "削除が完了しました" "削除できませんでした" "よろしいですか?" diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 560d3acb..5f4702bc 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -485,7 +485,6 @@ Tik om opnieuw te proberen." "Kan deze multireddit niet maken" "Deze multireddit bestaat al" "Kan deze multireddit niet bewerken" - "Je bent uitgelogd" "Succesvol verwijderd" "Verwijderen mislukt" "Weet je het zeker?" diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 1d71bdff..aff2cfc6 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -484,7 +484,6 @@ Nie można zsynchronizować subskrypcji" "Nie można stworzyć tego multireddita" "Ten multireddit już istnieje" "Nie można edytować tego multireddita" - "Jesteś wylogowany" "Usunięto pomyślnie" "Nie udało się usunąć" "Jesteś pewny?" diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index bb29695b..1bcc851a 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -491,7 +491,6 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "Não foi possível criar este multireddit" "Este multireddit já existe" "Não foi possível editar este multireddit" - "Você está deslogado" "Excluído com sucesso" "Falha ao excluir" "Tem certeza?" diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 843bb357..2aa5d3da 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -484,7 +484,6 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "Não é possível criar este multireddit" "Este multireddit já existe" "Não é possível editar este multireddit" - "Não tem sessão iniciada" "Eliminado com sucesso" "Falha ao eliminar" "Tem a certeza?" diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 0dcfb2d3..4975a560 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -487,7 +487,6 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "Невозможно создать мультиреддит" "Мультиреддит уже существует" "Не удалось изменить мультиреддит" - "Вы вышли из системы" "Успешно удалено" "Ошибка удаления" "Вы уверены?" diff --git a/app/src/main/res/values-tr-rTR/strings.xml b/app/src/main/res/values-tr-rTR/strings.xml index c0902495..86ecfb0c 100644 --- a/app/src/main/res/values-tr-rTR/strings.xml +++ b/app/src/main/res/values-tr-rTR/strings.xml @@ -492,7 +492,6 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "Bu multireddit oluşturulamıyor" "Bu multireddit zaten var" "Bu multireddit düzenlenemez" - "Çıkış yaptınız" "Başarıyla silindi" "Silinemedi" "Emin misiniz?" diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 16638927..50815bbc 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -696,7 +696,6 @@ Не можливо створити цей мультиредит Такий мультиредит уже існує Не можливо змінити цей мультиредит - You are logged out Успішно видалено Не вдалося видалити Ви впевнені? diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index e5132454..c6544cd8 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -486,7 +486,6 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "Không thể tạo multireddit này" "Multireddit này đã tồn tại" "Không thể chỉnh sửa multireddit này" - "Bạn đã đăng xuất" "Xoá thành công" "Xoá thất bại" "Bạn có chắc không?" diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index e6335f9d..e91f6e33 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -491,7 +491,6 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "无法创建此聚合版块" "此聚合版块已存在" "无法编辑此聚合版块" - "您已退出" "删除成功" "删除失败" "您确定吗?" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c791b2dd..0a66d129 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -700,7 +700,6 @@ Cannot create this multireddit This multireddit already exists Cannot edit this multireddit - You are logged out Delete successfully Delete failed Are you sure?