From 817cac300276874a953558a19dd5fc241cf3d39c Mon Sep 17 00:00:00 2001 From: relan Date: Fri, 6 Nov 2015 09:27:03 +0300 Subject: [PATCH 1/7] Remove dead code in CanUpdateAppsFragment Remove unused layout creation code. If needed, it can be re-added later as an XML resource which is a much more maintainable way to define layouts. --- .../fragments/CanUpdateAppsFragment.java | 130 ------------------ 1 file changed, 130 deletions(-) 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 88224092e..87a180d63 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/fragments/CanUpdateAppsFragment.java +++ b/F-Droid/src/org/fdroid/fdroid/views/fragments/CanUpdateAppsFragment.java @@ -1,38 +1,14 @@ package org.fdroid.fdroid.views.fragments; -import android.content.Context; import android.net.Uri; -import android.os.Bundle; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.FrameLayout; -import android.widget.LinearLayout; -import android.widget.ListView; -import android.widget.ProgressBar; -import android.widget.TextView; import org.fdroid.fdroid.R; import org.fdroid.fdroid.data.AppProvider; -import org.fdroid.fdroid.installer.Installer; import org.fdroid.fdroid.views.AppListAdapter; import org.fdroid.fdroid.views.CanUpdateAppListAdapter; public class CanUpdateAppsFragment extends AppListFragment { - // copied from ListFragment - static final int INTERNAL_EMPTY_ID = 0x00ff0001; - static final int INTERNAL_PROGRESS_CONTAINER_ID = 0x00ff0002; - static final int INTERNAL_LIST_CONTAINER_ID = 0x00ff0003; - // added for update button - static final int UPDATE_ALL_BUTTON_ID = 0x00ff0004; - - private Button mUpdateAllButton; - private Installer mInstaller; - @Override protected AppListAdapter getAppListAdapter() { return new CanUpdateAppListAdapter(getActivity(), null); @@ -53,110 +29,4 @@ public class CanUpdateAppsFragment extends AppListFragment { return AppProvider.getCanUpdateUri(); } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - mInstaller = Installer.getActivityInstaller(getActivity(), getActivity().getPackageManager(), null); - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - mUpdateAllButton.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - // TODO - - } - }); - } - - // TODO: not really called again after coming back from preference - @Override - public void onResume() { - super.onResume(); - - if (mInstaller.supportsUnattendedOperations()) { -// mUpdateAllButton.setVisibility(View.VISIBLE); - mUpdateAllButton.setVisibility(View.GONE); - } else { - mUpdateAllButton.setVisibility(View.GONE); - } - } - - /** - * Copied from ListFragment and added Button on top of list. We do not use a - * custom layout here, because this breaks the progress bar functionality of - * ListFragment. - */ - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final Context context = getActivity(); - - FrameLayout root = new FrameLayout(context); - - // ------------------------------------------------------------------ - - LinearLayout pframe = new LinearLayout(context); - pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID); - pframe.setOrientation(LinearLayout.VERTICAL); - pframe.setVisibility(View.GONE); - pframe.setGravity(Gravity.CENTER); - - ProgressBar progress = new ProgressBar(context, null, - android.R.attr.progressBarStyleLarge); - pframe.addView(progress, new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); - - root.addView(pframe, new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - - // ------------------------------------------------------------------ - - FrameLayout lframe = new FrameLayout(context); - lframe.setId(INTERNAL_LIST_CONTAINER_ID); - - TextView tv = new TextView(getActivity()); - tv.setId(INTERNAL_EMPTY_ID); - tv.setGravity(Gravity.CENTER); - lframe.addView(tv, new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - - // Added update all button - LinearLayout linearLayout = new LinearLayout(context); - linearLayout.setOrientation(LinearLayout.VERTICAL); - - mUpdateAllButton = new Button(context); - mUpdateAllButton.setId(UPDATE_ALL_BUTTON_ID); - mUpdateAllButton.setText(R.string.update_all); - mUpdateAllButton.setCompoundDrawablesWithIntrinsicBounds( - getResources().getDrawable(R.drawable.ic_refresh_white), null, null, null); - mUpdateAllButton.setVisibility(View.GONE); - - linearLayout.addView(mUpdateAllButton, new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); - - ListView lv = new ListView(getActivity()); - lv.setId(android.R.id.list); - lv.setDrawSelectorOnTop(false); - linearLayout.addView(lv, new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - - lframe.addView(linearLayout, new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - - root.addView(lframe, new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - - // ------------------------------------------------------------------ - - root.setLayoutParams(new FrameLayout.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - - return root; - } - } From 080527bf2efc4a4739fc0474f9e54f1d115b6b59 Mon Sep 17 00:00:00 2001 From: relan Date: Fri, 6 Nov 2015 10:31:26 +0300 Subject: [PATCH 2/7] Remove ThemeableListFragment Not sure why it was added initially but now it appears to be unneeded: the support library does everything right and the lists are themed properly without any hacks. --- .../views/fragments/AppListFragment.java | 3 +- .../fragments/ThemeableListFragment.java | 73 ------------------- 2 files changed, 2 insertions(+), 74 deletions(-) delete mode 100644 F-Droid/src/org/fdroid/fdroid/views/fragments/ThemeableListFragment.java 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 8c60daf94..597d3f972 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/fragments/AppListFragment.java +++ b/F-Droid/src/org/fdroid/fdroid/views/fragments/AppListFragment.java @@ -7,6 +7,7 @@ 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; @@ -24,7 +25,7 @@ import org.fdroid.fdroid.data.App; import org.fdroid.fdroid.data.AppProvider; import org.fdroid.fdroid.views.AppListAdapter; -public abstract class AppListFragment extends ThemeableListFragment implements +public abstract class AppListFragment extends ListFragment implements AdapterView.OnItemClickListener, Preferences.ChangeListener, LoaderManager.LoaderCallbacks { diff --git a/F-Droid/src/org/fdroid/fdroid/views/fragments/ThemeableListFragment.java b/F-Droid/src/org/fdroid/fdroid/views/fragments/ThemeableListFragment.java deleted file mode 100644 index e348d564f..000000000 --- a/F-Droid/src/org/fdroid/fdroid/views/fragments/ThemeableListFragment.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.fdroid.fdroid.views.fragments; - -import android.content.Context; -import android.os.Bundle; -import android.support.v4.app.ListFragment; -import android.view.ContextThemeWrapper; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ListView; - -import org.fdroid.fdroid.R; - -public abstract class ThemeableListFragment extends ListFragment { - - protected int getThemeStyle() { - return 0; - } - - protected int getHeaderLayout() { - return 0; - } - - protected View getHeaderView() { - return headerView; - } - - private View headerView; - - private View getHeaderView(LayoutInflater inflater, ViewGroup container) { - if (getHeaderLayout() == 0) { - return null; - } - if (headerView == null) { - headerView = inflater.inflate(getHeaderLayout(), null, false); - } - return headerView; - } - - private LayoutInflater getThemedInflater(Context context) { - Context c = (getThemeStyle() == 0) ? context : new ContextThemeWrapper(context, getThemeStyle()); - return (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - } - - /** - * Normally we'd just let the baseclass ListFrament.onCreateView() from the support library do its magic. - * However, it doesn't allow us to theme it. That is, it always passes getActivity() into the constructor - * of widgets. We are more interested in a ContextThemeWrapper, so that the widgets get appropriately - * themed. In order to get it working, we need to work around android bug 21742 as well - * (https://code.google.com/p/android/issues/detail?id=21742). - */ - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - - LayoutInflater themedInflater = getThemedInflater(inflater.getContext()); - - View view = themedInflater.inflate(R.layout.list_content, container, false); - - View headerView = getHeaderView(themedInflater, container); - if (headerView != null) { - ListView listView = (ListView) view.findViewById(android.R.id.list); - listView.addHeaderView(headerView); - } - - // Workaround for https://code.google.com/p/android/issues/detail?id=21742 - view.findViewById(android.R.id.empty).setId(0x00ff0001); - view.findViewById(R.id.progressContainer).setId(0x00ff0002); - view.findViewById(android.R.id.progress).setId(0x00ff0003); - - return view; - } - -} From 950854318b1e10cfdc5c01bfe0d928eff0cf7a05 Mon Sep 17 00:00:00 2001 From: relan Date: Fri, 6 Nov 2015 18:44:23 +0300 Subject: [PATCH 3/7] Add styles for app list and empty text Those styles will be used in the three layouts that will define the look of the fragments. --- F-Droid/res/values/styles.xml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/F-Droid/res/values/styles.xml b/F-Droid/res/values/styles.xml index 49f12431d..8308c08d9 100644 --- a/F-Droid/res/values/styles.xml +++ b/F-Droid/res/values/styles.xml @@ -61,6 +61,22 @@ + + +