mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-04-19 22:37:09 -04:00
[app] Hard-code category for nightly builds
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.fdroid.fdroid.views.categories;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.fdroid.database.AppOverviewItem;
|
||||
@@ -7,7 +8,9 @@ import org.fdroid.database.Category;
|
||||
import org.fdroid.database.FDroidDatabase;
|
||||
import org.fdroid.fdroid.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -49,7 +52,7 @@ public class CategoryAdapter extends ListAdapter<Category, CategoryController> {
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull CategoryController holder, int position) {
|
||||
Category category = getItem(position);
|
||||
holder.bindModel(category, liveData.get(category));
|
||||
holder.bindModel(category, liveData.get(category), this::onNoApps);
|
||||
}
|
||||
|
||||
public void setCategories(@NonNull List<Category> categories) {
|
||||
@@ -62,4 +65,17 @@ public class CategoryAdapter extends ListAdapter<Category, CategoryController> {
|
||||
}
|
||||
}
|
||||
|
||||
private void onNoApps(Category category) {
|
||||
ArrayList<Category> categories = new ArrayList<>(getCurrentList());
|
||||
Iterator<Category> itr = categories.iterator();
|
||||
while (itr.hasNext()) {
|
||||
Category c = itr.next();
|
||||
if (c.getId().equals(category.getId())) {
|
||||
Log.d("CategoryAdapter", "Removing " + category.getId() + " without apps.");
|
||||
itr.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
submitList(categories);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.os.LocaleListCompat;
|
||||
import androidx.core.util.Consumer;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.Observer;
|
||||
@@ -88,7 +89,8 @@ public class CategoryController extends RecyclerView.ViewHolder {
|
||||
return categoryNameId == 0 ? categoryName : context.getString(categoryNameId);
|
||||
}
|
||||
|
||||
void bindModel(@NonNull Category category, LiveData<List<AppOverviewItem>> liveData) {
|
||||
void bindModel(@NonNull Category category, LiveData<List<AppOverviewItem>> liveData,
|
||||
Consumer<Category> onNoApps) {
|
||||
loadAppItems(liveData);
|
||||
currentCategory = category;
|
||||
|
||||
@@ -98,7 +100,7 @@ public class CategoryController extends RecyclerView.ViewHolder {
|
||||
heading.setContentDescription(activity.getString(R.string.tts_category_name, categoryName));
|
||||
|
||||
viewAll.setVisibility(View.INVISIBLE);
|
||||
loadNumAppsInCategory();
|
||||
loadNumAppsInCategory(onNoApps);
|
||||
|
||||
@ColorInt int backgroundColour = getBackgroundColour(activity, category.getId());
|
||||
background.setBackgroundColor(backgroundColour);
|
||||
@@ -139,12 +141,12 @@ public class CategoryController extends RecyclerView.ViewHolder {
|
||||
});
|
||||
}
|
||||
|
||||
private void loadNumAppsInCategory() {
|
||||
private void loadNumAppsInCategory(Consumer<Category> onNoApps) {
|
||||
if (disposable != null) disposable.dispose();
|
||||
disposable = Single.fromCallable(() -> db.getAppDao().getNumberOfAppsInCategory(currentCategory.getId()))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::setNumAppsInCategory);
|
||||
.subscribe((numApps) -> setNumAppsInCategory(numApps, onNoApps));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,13 +181,17 @@ public class CategoryController extends RecyclerView.ViewHolder {
|
||||
return Color.HSVToColor(hsv);
|
||||
}
|
||||
|
||||
private void setNumAppsInCategory(int numAppsInCategory) {
|
||||
viewAll.setVisibility(View.VISIBLE);
|
||||
Resources r = activity.getResources();
|
||||
viewAll.setText(r.getQuantityString(R.plurals.button_view_all_apps_in_category, numAppsInCategory,
|
||||
numAppsInCategory));
|
||||
viewAll.setContentDescription(r.getQuantityString(R.plurals.tts_view_all_in_category, numAppsInCategory,
|
||||
numAppsInCategory, currentCategory));
|
||||
private void setNumAppsInCategory(int numAppsInCategory, Consumer<Category> onNoApps) {
|
||||
if (numAppsInCategory == 0) {
|
||||
onNoApps.accept(currentCategory);
|
||||
} else {
|
||||
viewAll.setVisibility(View.VISIBLE);
|
||||
Resources r = activity.getResources();
|
||||
viewAll.setText(r.getQuantityString(R.plurals.button_view_all_apps_in_category, numAppsInCategory,
|
||||
numAppsInCategory));
|
||||
viewAll.setContentDescription(r.getQuantityString(R.plurals.tts_view_all_in_category, numAppsInCategory,
|
||||
numAppsInCategory, currentCategory));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
|
||||
@@ -18,8 +18,10 @@ import org.fdroid.fdroid.panic.HidingManager;
|
||||
import org.fdroid.fdroid.views.apps.AppListActivity;
|
||||
import org.fdroid.fdroid.views.categories.CategoryAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.os.LocaleListCompat;
|
||||
@@ -38,10 +40,12 @@ class CategoriesViewBinder implements Observer<List<Category>> {
|
||||
public static final String TAG = "CategoriesViewBinder";
|
||||
|
||||
private final CategoryAdapter categoryAdapter;
|
||||
private final AppCompatActivity activity;
|
||||
private final TextView emptyState;
|
||||
private final RecyclerView categoriesList;
|
||||
|
||||
CategoriesViewBinder(final AppCompatActivity activity, FrameLayout parent) {
|
||||
this.activity = activity;
|
||||
FDroidDatabase db = DBHelper.getDb(activity);
|
||||
Transformations.distinctUntilChanged(db.getRepositoryDao().getLiveCategories()).observe(activity, this);
|
||||
|
||||
@@ -100,7 +104,11 @@ class CategoriesViewBinder implements Observer<List<Category>> {
|
||||
if (name2 == null) name2 = o2.getId();
|
||||
return name1.compareToIgnoreCase(name2);
|
||||
});
|
||||
categoryAdapter.setCategories(categories);
|
||||
// TODO force-adding nightly category here can be removed once fdroidserver LTS supports defining categories
|
||||
ArrayList<Category> c = new ArrayList<>(categories);
|
||||
Map<String, String> name = Collections.singletonMap("en-US", activity.getString(R.string.category_Nightly));
|
||||
c.add(new Category(42L, "nightly", Collections.emptyMap(), name, Collections.emptyMap()));
|
||||
categoryAdapter.setCategories(c);
|
||||
|
||||
if (categoryAdapter.getItemCount() == 0) {
|
||||
emptyState.setVisibility(View.VISIBLE);
|
||||
|
||||
@@ -479,6 +479,7 @@ This often occurs with apps installed via Google Play or other sources, if they
|
||||
<string tools:ignore="UnusedResources" name="category_Theming">Theming</string>
|
||||
<string tools:ignore="UnusedResources" name="category_Time">Time</string>
|
||||
<string tools:ignore="UnusedResources" name="category_Writing">Writing</string>
|
||||
<string tools:ignore="UnusedResources" name="category_Nightly">Nightly Builds</string>
|
||||
|
||||
<plurals name="button_view_all_apps_in_category">
|
||||
<item quantity="one">View %d</item>
|
||||
|
||||
Reference in New Issue
Block a user