Split tabs layouts

Use separate layouts for the three tabs. This simplifies code and improves
maintainability.
This commit is contained in:
relan 2015-11-06 18:46:02 +03:00
parent 950854318b
commit 7fdcd706fd
8 changed files with 53 additions and 79 deletions

View File

@ -2,8 +2,7 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="match_parent">
<Spinner
android:id="@+id/category_spinner"
@ -19,21 +18,12 @@
android:layout_alignBottom="@id/category_spinner"
android:background="@color/fdroid_green" />
<!-- The empty app list message gets shown on the parent of the @android:id/list.
For the update/installed lists, this is not a problem as it is attached to the linear
layout the list is in. However here, it will end up in the relative layout which
causes sadness. This FrameLayout is here so that the empty message will get shown here. -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/category_spinner">
<ListView
style="@style/AppList"
android:layout_below="@id/category_spinner" />
<ListView
android:id="@android:id/list"
android:fastScrollEnabled="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<TextView
style="@style/AppListEmptyText"
android:text="@string/empty_available_app_list" />
</RelativeLayout>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
style="@style/AppList" />
<TextView
style="@style/AppListEmptyText"
android:text="@string/empty_can_update_app_list" />
</RelativeLayout>

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
android:gravity="center_vertical">
<TextView
android:id="@+id/text"
android:layout_gravity="center_horizontal"
android:textAlignment="center"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="20sp"
tools:text="No apps in this category.\n\nTry selecting a different category or updating your repositories to get a fresh list of apps." />
</LinearLayout>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
style="@style/AppList" />
<TextView
style="@style/AppListEmptyText"
android:text="@string/empty_installed_app_list" />
</RelativeLayout>

View File

@ -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

View File

@ -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<String> 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;

View File

@ -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);
}
}

View File

@ -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);
}
}