From 7fdcd706fd1ef5ab91e67b166528e898e8916d0e Mon Sep 17 00:00:00 2001 From: relan Date: Fri, 6 Nov 2015 18:46:02 +0300 Subject: [PATCH] Split tabs layouts Use separate layouts for the three tabs. This simplifies code and improves maintainability. --- F-Droid/res/layout/available_app_list.xml | 24 ++++++------------- F-Droid/res/layout/can_update_app_list.xml | 14 +++++++++++ F-Droid/res/layout/empty_app_list.xml | 19 --------------- F-Droid/res/layout/installed_app_list.xml | 14 +++++++++++ .../views/fragments/AppListFragment.java | 24 ------------------- .../fragments/AvailableAppsFragment.java | 9 ------- .../fragments/CanUpdateAppsFragment.java | 14 +++++++---- .../fragments/InstalledAppsFragment.java | 14 +++++++---- 8 files changed, 53 insertions(+), 79 deletions(-) create mode 100644 F-Droid/res/layout/can_update_app_list.xml delete mode 100644 F-Droid/res/layout/empty_app_list.xml create mode 100644 F-Droid/res/layout/installed_app_list.xml diff --git a/F-Droid/res/layout/available_app_list.xml b/F-Droid/res/layout/available_app_list.xml index 90cab4432..166a71897 100644 --- a/F-Droid/res/layout/available_app_list.xml +++ b/F-Droid/res/layout/available_app_list.xml @@ -2,8 +2,7 @@ + android:layout_height="match_parent"> - - + - - - + diff --git a/F-Droid/res/layout/can_update_app_list.xml b/F-Droid/res/layout/can_update_app_list.xml new file mode 100644 index 000000000..fa7557058 --- /dev/null +++ b/F-Droid/res/layout/can_update_app_list.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/F-Droid/res/layout/empty_app_list.xml b/F-Droid/res/layout/empty_app_list.xml deleted file mode 100644 index d43cbe496..000000000 --- a/F-Droid/res/layout/empty_app_list.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/F-Droid/res/layout/installed_app_list.xml b/F-Droid/res/layout/installed_app_list.xml new file mode 100644 index 000000000..869380928 --- /dev/null +++ b/F-Droid/res/layout/installed_app_list.xml @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/F-Droid/src/org/fdroid/fdroid/views/fragments/AppListFragment.java b/F-Droid/src/org/fdroid/fdroid/views/fragments/AppListFragment.java index 597d3f972..bd4548de7 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/fragments/AppListFragment.java +++ b/F-Droid/src/org/fdroid/fdroid/views/fragments/AppListFragment.java @@ -6,19 +6,15 @@ import android.content.SharedPreferences; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; -import android.support.annotation.Nullable; import android.support.v4.app.ListFragment; import android.support.v4.app.LoaderManager; import android.support.v4.content.CursorLoader; import android.support.v4.content.Loader; import android.view.View; -import android.view.ViewGroup; import android.widget.AdapterView; -import android.widget.TextView; import org.fdroid.fdroid.AppDetails; import org.fdroid.fdroid.Preferences; -import org.fdroid.fdroid.R; import org.fdroid.fdroid.UpdateService; import org.fdroid.fdroid.Utils; import org.fdroid.fdroid.data.App; @@ -62,17 +58,6 @@ public abstract class AppListFragment extends ListFragment implements protected abstract Uri getDataUri(); - /** - * Depending on the subclass, a different message may be desired. For example, in the main list - * of apps, might want to say "No apps for this category, how about you try...", while the - * "Update" tab may wish to say "Congratulations, all your apps are up to date." - * - * In the future, this may want to return a view instead of a string. That would allow nice - * visual graphics helping to show the message. - */ - @Nullable - protected abstract String getEmptyMessage(); - @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); @@ -80,16 +65,7 @@ public abstract class AppListFragment extends ListFragment implements // Can't do this in the onCreate view, because "onCreateView" which // returns the list view is "called between onCreate and // onActivityCreated" according to the docs. - getListView().setFastScrollEnabled(true); getListView().setOnItemClickListener(this); - - String emptyMessage = getEmptyMessage(); - if (emptyMessage != null) { - View emptyView = getLayoutInflater(savedInstanceState).inflate(R.layout.empty_app_list, null); - ((TextView) emptyView.findViewById(R.id.text)).setText(emptyMessage); - ((ViewGroup) getListView().getParent()).addView(emptyView); // Needs to be added to this parent or it doesn't show. - getListView().setEmptyView(emptyView); - } } @Override diff --git a/F-Droid/src/org/fdroid/fdroid/views/fragments/AvailableAppsFragment.java b/F-Droid/src/org/fdroid/fdroid/views/fragments/AvailableAppsFragment.java index 7f67acc74..f7c1fa94e 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/fragments/AvailableAppsFragment.java +++ b/F-Droid/src/org/fdroid/fdroid/views/fragments/AvailableAppsFragment.java @@ -14,7 +14,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; -import android.widget.ListView; import android.widget.Spinner; import org.fdroid.fdroid.Preferences; @@ -62,11 +61,6 @@ public class AvailableAppsFragment extends AppListFragment implements return adapter; } - @Override - protected String getEmptyMessage() { - return getActivity().getString(R.string.empty_available_app_list); - } - private class CategoryObserver extends ContentObserver { private final ArrayAdapter adapter; @@ -154,9 +148,6 @@ public class AvailableAppsFragment extends AppListFragment implements View view = inflater.inflate(R.layout.available_app_list, container, false); setupCategorySpinner((Spinner) view.findViewById(R.id.category_spinner)); - - ((ListView) view.findViewById(android.R.id.list)).setOnItemClickListener(this); - defaultCategory = AppProvider.Helper.getCategoryWhatsNew(getActivity()); return view; diff --git a/F-Droid/src/org/fdroid/fdroid/views/fragments/CanUpdateAppsFragment.java b/F-Droid/src/org/fdroid/fdroid/views/fragments/CanUpdateAppsFragment.java index 87a180d63..e767077b9 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/fragments/CanUpdateAppsFragment.java +++ b/F-Droid/src/org/fdroid/fdroid/views/fragments/CanUpdateAppsFragment.java @@ -1,6 +1,10 @@ package org.fdroid.fdroid.views.fragments; import android.net.Uri; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; import org.fdroid.fdroid.R; import org.fdroid.fdroid.data.AppProvider; @@ -19,14 +23,14 @@ public class CanUpdateAppsFragment extends AppListFragment { return getString(R.string.tab_updates); } - @Override - protected String getEmptyMessage() { - return getActivity().getString(R.string.empty_can_update_app_list); - } - @Override protected Uri getDataUri() { return AppProvider.getCanUpdateUri(); } + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.can_update_app_list, container, false); + } + } diff --git a/F-Droid/src/org/fdroid/fdroid/views/fragments/InstalledAppsFragment.java b/F-Droid/src/org/fdroid/fdroid/views/fragments/InstalledAppsFragment.java index 24c3a95bc..d5078b80f 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/fragments/InstalledAppsFragment.java +++ b/F-Droid/src/org/fdroid/fdroid/views/fragments/InstalledAppsFragment.java @@ -1,6 +1,10 @@ package org.fdroid.fdroid.views.fragments; import android.net.Uri; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; import org.fdroid.fdroid.R; import org.fdroid.fdroid.data.AppProvider; @@ -14,11 +18,6 @@ public class InstalledAppsFragment extends AppListFragment { return new InstalledAppListAdapter(getActivity(), null); } - @Override - protected String getEmptyMessage() { - return getActivity().getString(R.string.empty_installed_app_list); - } - @Override protected String getFromTitle() { return getString(R.string.tab_installed_apps); @@ -29,4 +28,9 @@ public class InstalledAppsFragment extends AppListFragment { return AppProvider.getInstalledUri(); } + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + return inflater.inflate(R.layout.installed_app_list, container, false); + } + }