mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-29 20:37:12 +01:00
Suggest subreddits in go to subreddit dialog in MainActivity.
This commit is contained in:
parent
ef953a72f7
commit
2d1e63d722
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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>
|
||||
<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>
|
Loading…
Reference in New Issue
Block a user