WIP: Refactoring fragments to handle click events themselves.
This commit is contained in:
parent
4eda47df4b
commit
ff4ba92376
@ -604,7 +604,7 @@ public class FDroid extends FragmentActivity implements OnItemClickListener,
|
||||
// http://stackoverflow.com/a/13684505
|
||||
ViewGroup group = (ViewGroup)fragment.getView();
|
||||
AppListView view = (AppListView)group.getChildAt(0);
|
||||
final DB.App app = (DB.App)view.getAppList(). getAdapter().getItem(arg2);
|
||||
final DB.App app = (DB.App)view.getAppList().getAdapter().getItem(arg2);
|
||||
|
||||
Intent intent = new Intent(this, AppDetails.class);
|
||||
intent.putExtra("appid", app.id);
|
||||
|
@ -26,9 +26,9 @@ public class AppListFragmentPageAdapter extends FragmentPagerAdapter {
|
||||
public AppListFragmentPageAdapter(FDroid parent) {
|
||||
super(parent.getSupportFragmentManager());
|
||||
this.parent = parent;
|
||||
fragments[0] = new AvailableAppsFragment();
|
||||
fragments[1] = new InstalledAppsFragment();
|
||||
fragments[2] = new CanUpdateAppsFragment();
|
||||
fragments[0] = new AvailableAppsFragment().setAppListAdapter(parent.getAvailableAdapter());
|
||||
fragments[1] = new InstalledAppsFragment().setAppListAdapter(parent.getInstalledAdapter());
|
||||
fragments[2] = new CanUpdateAppsFragment().setAppListAdapter(parent.getCanUpdateAdapter()).;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,80 +0,0 @@
|
||||
package org.fdroid.fdroid.views;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Spinner;
|
||||
import org.fdroid.fdroid.AppListAdapter;
|
||||
import org.fdroid.fdroid.FDroid;
|
||||
import org.fdroid.fdroid.R;
|
||||
|
||||
/**
|
||||
* Provides functionality to create the three lists of applications
|
||||
* required for the FDroid activity.
|
||||
*/
|
||||
public class AppListViewFactory {
|
||||
|
||||
private FDroid parent;
|
||||
|
||||
public AppListViewFactory(FDroid parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public AppListView createAvailableView() {
|
||||
AppListView view = new AppListView(parent);
|
||||
view.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
Spinner spinner = new Spinner(parent);
|
||||
// Giving it an ID lets the default save/restore state
|
||||
// functionality do its stuff.
|
||||
spinner.setId(R.id.categorySpinner);
|
||||
spinner.setAdapter(parent.getCategoriesAdapter());
|
||||
spinner.setOnItemSelectedListener(parent);
|
||||
|
||||
view.addView(
|
||||
spinner,
|
||||
new ViewGroup.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
ListView list = createAppListView(parent.getAvailableAdapter());
|
||||
view.setAppList(list);
|
||||
view.addView(
|
||||
list,
|
||||
new ViewGroup.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.MATCH_PARENT));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
public AppListView createInstalledView() {
|
||||
return createPlainAppList(parent.getInstalledAdapter());
|
||||
}
|
||||
|
||||
public AppListView createCanUpdateView() {
|
||||
return createPlainAppList(parent.getCanUpdateAdapter());
|
||||
}
|
||||
|
||||
protected AppListView createPlainAppList(AppListAdapter adapter) {
|
||||
AppListView view = new AppListView(parent);
|
||||
ListView list = createAppListView(adapter);
|
||||
view.addView(
|
||||
list,
|
||||
new ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
view.setAppList(list);
|
||||
return view;
|
||||
}
|
||||
|
||||
protected ListView createAppListView(AppListAdapter adapter) {
|
||||
ListView list = new ListView(parent);
|
||||
list.setFastScrollEnabled(true);
|
||||
list.setOnItemClickListener(parent);
|
||||
list.setAdapter(adapter);
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,43 @@
|
||||
package org.fdroid.fdroid.views.fragments;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
import org.fdroid.fdroid.FDroid;
|
||||
import org.fdroid.fdroid.views.AppListViewFactory;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
import org.fdroid.fdroid.AppListAdapter;
|
||||
import org.fdroid.fdroid.views.AppListView;
|
||||
|
||||
public class AppListFragment extends Fragment {
|
||||
abstract class AppListFragment extends Fragment implements AdapterView.OnItemClickListener {
|
||||
|
||||
protected AppListViewFactory getViewFactory() {
|
||||
FDroid parent = (FDroid)getActivity();
|
||||
return new AppListViewFactory(parent);
|
||||
private AppListAdapter appListAdapter;
|
||||
|
||||
public AppListAdapter getAppListAdapter() {
|
||||
return appListAdapter;
|
||||
}
|
||||
|
||||
public AppListFragment setAppListAdapter(AppListAdapter adapter) {
|
||||
appListAdapter = adapter;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected AppListView createPlainAppList(AppListAdapter adapter) {
|
||||
AppListView view = new AppListView(getActivity());
|
||||
ListView list = createAppListView(adapter);
|
||||
view.addView(
|
||||
list,
|
||||
new ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
view.setAppList(list);
|
||||
return view;
|
||||
}
|
||||
|
||||
protected ListView createAppListView(AppListAdapter adapter) {
|
||||
ListView list = new ListView(getActivity());
|
||||
list.setFastScrollEnabled(true);
|
||||
list.setOnItemClickListener(this);
|
||||
list.setAdapter(adapter);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,70 @@ import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.*;
|
||||
import org.fdroid.fdroid.R;
|
||||
import org.fdroid.fdroid.views.AppListView;
|
||||
|
||||
public class AvailableAppsFragment extends AppListFragment {
|
||||
public class AvailableAppsFragment extends AppListFragment implements AdapterView.OnItemSelectedListener {
|
||||
|
||||
private ArrayAdapter<String> categoriesAdapter;
|
||||
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return getViewFactory().createAvailableView();
|
||||
AppListView view = new AppListView(getActivity());
|
||||
view.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
Spinner spinner = new Spinner(getActivity());
|
||||
// Giving it an ID lets the default save/restore state
|
||||
// functionality do its stuff.
|
||||
spinner.setId(R.id.categorySpinner);
|
||||
spinner.setAdapter(getCategoriesAdapter());
|
||||
spinner.setOnItemSelectedListener(this);
|
||||
|
||||
view.addView(
|
||||
spinner,
|
||||
new ViewGroup.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
ListView list = createAppListView(getAppListAdapter());
|
||||
view.setAppList(list);
|
||||
view.addView(
|
||||
list,
|
||||
new ViewGroup.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.MATCH_PARENT));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
}
|
||||
|
||||
public ArrayAdapter<String> getCategoriesAdapter() {
|
||||
return categoriesAdapter;
|
||||
}
|
||||
|
||||
public void setCategoriesAdapter(ArrayAdapter<String> categoriesAdapter) {
|
||||
this.categoriesAdapter = categoriesAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,16 @@ import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
|
||||
public class CanUpdateAppsFragment extends AppListFragment {
|
||||
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return getViewFactory().createCanUpdateView();
|
||||
return createPlainAppList(getAppListAdapter());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,16 @@ import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
|
||||
public class InstalledAppsFragment extends AppListFragment {
|
||||
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return getViewFactory().createInstalledView();
|
||||
return createPlainAppList(getAppListAdapter());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user