aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-07-01 04:48:28 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-07-01 04:48:28 +0000
commit2d1e63d7223408cd1acbd4b02851acea2881dd52 (patch)
treee31571435a468bb4f11c1eadf798c4d9ad2bf7db
parentef953a72f73e6b11a5886678c2cd0424a4f5e9f8 (diff)
downloadinfinity-for-reddit-2d1e63d7223408cd1acbd4b02851acea2881dd52.tar
infinity-for-reddit-2d1e63d7223408cd1acbd4b02851acea2881dd52.tar.gz
infinity-for-reddit-2d1e63d7223408cd1acbd4b02851acea2881dd52.tar.bz2
infinity-for-reddit-2d1e63d7223408cd1acbd4b02851acea2881dd52.tar.lz
infinity-for-reddit-2d1e63d7223408cd1acbd4b02851acea2881dd52.tar.xz
infinity-for-reddit-2d1e63d7223408cd1acbd4b02851acea2881dd52.tar.zst
infinity-for-reddit-2d1e63d7223408cd1acbd4b02851acea2881dd52.zip
Suggest subreddits in go to subreddit dialog in MainActivity.
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java69
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java2
-rw-r--r--app/src/main/res/layout/dialog_go_to_thing_edit_text.xml47
3 files changed, 99 insertions, 19 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
index bcb42023..6549c44e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
@@ -9,6 +9,8 @@ import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
+import android.text.Editable;
+import android.text.TextWatcher;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
@@ -81,6 +83,8 @@ import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
import ml.docilealligator.infinityforreddit.account.AccountViewModel;
import ml.docilealligator.infinityforreddit.adapters.NavigationDrawerRecyclerViewAdapter;
+import ml.docilealligator.infinityforreddit.adapters.SubredditAutocompleteRecyclerViewAdapter;
+import ml.docilealligator.infinityforreddit.apis.RedditAPI;
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubscribedThings;
import ml.docilealligator.infinityforreddit.asynctasks.SwitchAccount;
import ml.docilealligator.infinityforreddit.asynctasks.SwitchToAnonymousMode;
@@ -106,15 +110,20 @@ import ml.docilealligator.infinityforreddit.multireddit.MultiRedditViewModel;
import ml.docilealligator.infinityforreddit.post.Post;
import ml.docilealligator.infinityforreddit.post.PostDataSource;
import ml.docilealligator.infinityforreddit.readpost.InsertReadPost;
+import ml.docilealligator.infinityforreddit.subreddit.ParseSubredditData;
import ml.docilealligator.infinityforreddit.subreddit.SubredditData;
import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditData;
import ml.docilealligator.infinityforreddit.subscribedsubreddit.SubscribedSubredditViewModel;
import ml.docilealligator.infinityforreddit.subscribeduser.SubscribedUserData;
import ml.docilealligator.infinityforreddit.user.FetchUserData;
import ml.docilealligator.infinityforreddit.user.UserData;
+import ml.docilealligator.infinityforreddit.utils.APIUtils;
import ml.docilealligator.infinityforreddit.utils.CustomThemeSharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.utils.Utils;
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
import retrofit2.Retrofit;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
@@ -215,6 +224,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
private SectionsPagerAdapter sectionsPagerAdapter;
private AppBarLayout.LayoutParams params;
private NavigationDrawerRecyclerViewAdapter adapter;
+ private Call<String> subredditAutocompleteCall;
private String mAccessToken;
private String mAccountName;
private boolean mFetchUserInfoSuccess = false;
@@ -1373,8 +1383,20 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
private void goToSubreddit() {
View rootView = getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, coordinatorLayout, false);
TextInputEditText thingEditText = rootView.findViewById(R.id.text_input_edit_text_go_to_thing_edit_text);
- thingEditText.requestFocus();
+ RecyclerView recyclerView = rootView.findViewById(R.id.recycler_view_go_to_thing_edit_text);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+ SubredditAutocompleteRecyclerViewAdapter adapter = new SubredditAutocompleteRecyclerViewAdapter(
+ this, mCustomThemeWrapper, subredditData -> {
+ if (imm != null) {
+ imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0);
+ }
+ Intent intent = new Intent(MainActivity.this, ViewSubredditDetailActivity.class);
+ intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditData.getName());
+ startActivity(intent);
+ });
+ recyclerView.setAdapter(adapter);
+
+ thingEditText.requestFocus();
if (imm != null) {
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
@@ -1390,6 +1412,51 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
return false;
});
+
+ boolean nsfw = mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false);
+ thingEditText.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+
+ }
+
+ @Override
+ public void afterTextChanged(Editable editable) {
+ if (subredditAutocompleteCall != null) {
+ subredditAutocompleteCall.cancel();
+ }
+ subredditAutocompleteCall = mOauthRetrofit.create(RedditAPI.class).subredditAutocomplete(APIUtils.getOAuthHeader(mAccessToken),
+ editable.toString(), nsfw);
+ subredditAutocompleteCall.enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ if (response.isSuccessful()) {
+ ParseSubredditData.parseSubredditListingData(response.body(), nsfw, new ParseSubredditData.ParseSubredditListingDataListener() {
+ @Override
+ public void onParseSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
+ adapter.setSubreddits(subredditData);
+ }
+
+ @Override
+ public void onParseSubredditListingDataFail() {
+
+ }
+ });
+ }
+ }
+
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+
+ }
+ });
+ }
+ });
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
.setTitle(R.string.go_to_subreddit)
.setView(rootView)
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java
index eaaf7d96..f88012b9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java
@@ -233,7 +233,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
})
.usePlugin(StrikethroughPlugin.create())
.usePlugin(MovementMethodPlugin.create(BetterLinkMovementMethod.linkify(Linkify.WEB_URLS, activity).setOnLinkLongClickListener((textView, url) -> {
- if (activity != null && !activity.isDestroyed() && !activity.isFinishing()) {
+ if (!activity.isDestroyed() && !activity.isFinishing()) {
UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, url);
diff --git a/app/src/main/res/layout/dialog_go_to_thing_edit_text.xml b/app/src/main/res/layout/dialog_go_to_thing_edit_text.xml
index 9c01d84d..707f4d55 100644
--- a/app/src/main/res/layout/dialog_go_to_thing_edit_text.xml
+++ b/app/src/main/res/layout/dialog_go_to_thing_edit_text.xml
@@ -1,25 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
-<com.google.android.material.textfield.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:paddingStart="16dp"
- android:paddingTop="8dp"
- android:paddingEnd="16dp"
- android:paddingBottom="8dp"
- app:boxStrokeColor="?attr/primaryTextColor"
- app:hintTextColor="?attr/primaryTextColor">
+ android:orientation="vertical">
- <com.google.android.material.textfield.TextInputEditText
- android:id="@+id/text_input_edit_text_go_to_thing_edit_text"
+ <com.google.android.material.textfield.TextInputLayout
+ style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:fontFamily="?attr/font_family"
- android:hint="@string/go_to_thing_hint"
- android:textColor="?attr/primaryTextColor"
- android:textSize="?attr/font_default"
- android:singleLine="true"
- android:imeOptions="actionDone"/>
+ android:paddingStart="16dp"
+ android:paddingTop="8dp"
+ android:paddingEnd="16dp"
+ android:paddingBottom="8dp"
+ app:boxStrokeColor="?attr/primaryTextColor"
+ app:hintTextColor="?attr/primaryTextColor">
-</com.google.android.material.textfield.TextInputLayout> \ No newline at end of file
+ <com.google.android.material.textfield.TextInputEditText
+ android:id="@+id/text_input_edit_text_go_to_thing_edit_text"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:fontFamily="?attr/font_family"
+ android:hint="@string/go_to_thing_hint"
+ android:textColor="?attr/primaryTextColor"
+ android:textSize="?attr/font_default"
+ android:singleLine="true"
+ android:imeOptions="actionDone"/>
+
+ </com.google.android.material.textfield.TextInputLayout>
+
+ <androidx.recyclerview.widget.RecyclerView
+ android:id="@+id/recycler_view_go_to_thing_edit_text"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
+
+</LinearLayout> \ No newline at end of file