newsfeedlist manager

This commit is contained in:
gdlbo
2022-08-11 16:05:04 +03:00
parent 14cf129435
commit 5c26dd8ea4
5 changed files with 149 additions and 4 deletions
@@ -17,6 +17,7 @@ import static ru.vtosters.lite.utils.Preferences.getBoolValue;
import static ru.vtosters.lite.utils.Preferences.hasVerification;
import static ru.vtosters.lite.utils.Preferences.podcastcatalog;
import static ru.vtosters.lite.utils.Preferences.postsrecomm;
import static ru.vtosters.lite.utils.Preferences.preferences;
import static ru.vtosters.lite.utils.VTVerifications.isDeveloper;
import static ru.vtosters.lite.utils.VTVerifications.isPrometheus;
import static ru.vtosters.lite.utils.VTVerifications.isVerified;
@@ -373,11 +374,16 @@ public class JsonInjectors {
public static JSONArray newsfeedlist(JSONArray items) throws JSONException {
for (int j = 0; j < items.length(); j++) {
var list = items.optJSONObject(j);
var name = list.optString("id");
var id = list.optString("id");
var title = list.optString("title");
if (!name.equals("kpop") && !name.equals("foryou") && !name.equals("qazaqstan")) {
list.put("is_hidden", false).put("is_unavailable", false);
if (dev()) Log.d("NewsfeedListInj", "Unlocked " + name + " in newsfeed list");
if (!id.equals("kpop") && !id.equals("foryou") && !id.equals("qazaqstan") && !id.equals("podcasts")) {
preferences.edit().putString("newsfeedlist_title_" + id, title).apply();
if (!getBoolValue("newsfeedlist_" + id, false)) {
Log.d("NewsfeedList", "Added list " + id + " to feed");
list.put("is_hidden", false).put("is_unavailable", false);
if (dev()) Log.d("NewsfeedListInj", "Unlocked " + id + " in newsfeed list");
}
}
}
@@ -0,0 +1,70 @@
package ru.vtosters.lite.ui.components;
import static ru.vtosters.lite.ui.vkui.VBListBuilder.VBListItem;
import static ru.vtosters.lite.ui.vkui.VBListBuilder.buildListOf;
import static ru.vtosters.lite.utils.AndroidUtils.edit;
import static ru.vtosters.lite.utils.AndroidUtils.getDefaultPrefs;
import static ru.vtosters.lite.utils.AndroidUtils.sendToast;
import static ru.vtosters.lite.utils.Preferences.getBoolValue;
import android.app.Activity;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import ru.vtosters.lite.ui.vkui.VBottomSheetBuilder;
public class NewsfeedListManager{
public static int hideitems = 0;
public static void callEditorPopup(Activity activity){
List<VBListItem> list = new ArrayList<>();
for (Map.Entry<String, ?> entry : getDefaultPrefs().getAll().entrySet()) {
if (entry.getKey().startsWith("newsfeedlist_title_")) {
var boolname = entry.getKey().replace("newsfeedlist_title_", "newsfeedlist_");
var boolvalue = getBoolValue(boolname, false);
var title = entry.getValue().toString();
list.add(new VBListItem(boolname, title, boolvalue));
}
}
if (list.size() == 0) {
sendToast("Обновите ленту для получения списка доступных пунктов");
return;
}
VBottomSheetBuilder.show(activity, new VBottomSheetBuilder.VBSContent(
"Выберите пункты для скрытия",
buildListOf(activity, list),
new VBottomSheetBuilder.VBSContent.VBSButton(
"Сохранить",
() -> {
for (VBListItem item : list) {
edit().putBoolean(item.id, item.checked).commit();
sendToast("Для применения изменений обновите ленту");
if (item.checked) {
hideitems++;
edit().putInt("newsfeedlistitems", hideitems).commit();
} else if (hideitems == 0) {
edit().putInt("newsfeedlistitems", hideitems).commit();
}
}
}
)
));
}
public static void resetHideItems(){
hideitems = 0;
for (Map.Entry<String, ?> entry : getDefaultPrefs().getAll().entrySet()) {
if (entry.getKey().startsWith("newsfeedlist_")) {
getDefaultPrefs().edit().remove(entry.getKey()).commit();
}
}
sendToast("Сброшены пункты для скрытия");
}
}
@@ -15,6 +15,8 @@ import com.vk.navigation.Navigator;
import com.vk.newsfeed.NewsfeedSettingsFragment;
import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment;
import ru.vtosters.lite.ui.components.NewsfeedListManager;
public class FeedFragment extends MaterialPreferenceToolbarFragment {
@Override
public void onCreate(Bundle bundle) {
@@ -30,6 +32,15 @@ public class FeedFragment extends MaterialPreferenceToolbarFragment {
findPreference("spamfilters").setSummary(count(getPrefsValue("spamfilters")));
findPreference("sourcenamefilter").setSummary(count(getPrefsValue("sourcenamefilter")));
findPreference("linkfilter").setSummary(count(getPrefsValue("linkfilter")));
findPreference("newsfeedlistmanager").setOnPreferenceClickListener(preference -> {
NewsfeedListManager.callEditorPopup(getActivity());
return true;
});
findPreference("newsfeedlistmanager").setSummary("Скрыто " + NewsfeedListManager.hideitems + " лент новостей");
findPreference("newsfeedlistmanager_reset").setOnPreferenceClickListener(preference -> {
NewsfeedListManager.resetHideItems();
return true;
});
}
private String count(String text) {
@@ -0,0 +1,51 @@
package ru.vtosters.lite.ui.vkui;
import static ru.vtosters.lite.utils.AndroidUtils.dp2px;
import static ru.vtosters.lite.utils.ThemesUtils.getTextAttr;
import android.content.Context;
import android.util.TypedValue;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import androidx.appcompat.widget.AppCompatCheckBox;
import java.util.List;
public class VBListBuilder{
public static ViewGroup buildListOf(Context ctx, List<VBListItem> items){
LinearLayout mainView = new LinearLayout(ctx);
mainView.setOrientation(LinearLayout.VERTICAL);
mainView.setPadding(dp2px(8f), 0, dp2px(8f), 0);
for (VBListItem item : items) {
AppCompatCheckBox mcb = new AppCompatCheckBox(ctx, null);
mcb.setPadding(0, dp2px(8f), 0, dp2px(8f));
mcb.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14f);
mcb.setTextColor(getTextAttr());
mcb.setChecked(item.checked);
mcb.setText(item.title);
mcb.setOnCheckedChangeListener((buttonView, isChecked) -> {
item.checked = isChecked;
});
mainView.addView(mcb);
}
return mainView;
}
public static class VBListItem{
public String id;
public String title;
public boolean checked;
public VBListItem(String id, String title, boolean checked){
this.id = id;
this.title = title;
this.checked = checked;
}
}
}
+7
View File
@@ -118,5 +118,12 @@
android:key="feedcache"
android:summary="@string/feed_other_cache_summary"
android:title="@string/vtlfeedcache" />
<Preference
android:key="newsfeedlistmanager"
android:summary="Настройки списков новостей"
android:title="Списки новостей" />
<Preference
android:key="newsfeedlistmanager_reset"
android:title="Сбросить список новостей" />
</PreferenceCategory>
</PreferenceScreen>