Update plugin fragment

This commit is contained in:
Victor Shcherb 2014-12-09 01:13:58 +01:00
parent 86a8753559
commit a796fc36bc
3 changed files with 103 additions and 64 deletions

View file

@ -1,35 +1,47 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/dashboard_divider" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:paddingLeft="12dp"
android:layout_height="50dp"> android:paddingBottom="4dp"
<View android:layout_width="match_parent" android:paddingRight="12dp" >
android:background="@color/dashboard_divider"
android:layout_height="1dp"/> <LinearLayout
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingRight="12dp" android:layout_gravity="center_vertical"
android:layout_height="match_parent"> android:orientation="horizontal" >
<LinearLayout android:orientation="vertical"
android:layout_marginLeft="12dp" <TextView
android:id="@+id/plugin_name"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_weight="1" android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:ellipsize="end"
android:lines="1"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_height="match_parent"> android:gravity="center_vertical"
<TextView android:id="@+id/plugin_name" android:textColor="@color/dashboard_black" />
android:textColor="@color/dashboard_black"
android:ellipsize="end" <include layout="@layout/check_item_rel" />
android:lines="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/plugin_descr"
android:ellipsize="end"
android:lines="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout> </LinearLayout>
<include layout="@layout/check_item_rel"/> <TextView
android:id="@+id/plugin_descr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="3" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -1,10 +1,18 @@
package net.osmand.plus.dashboard; package net.osmand.plus.dashboard;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.development.OsmandDevelopmentPlugin;
import net.osmand.plus.helpers.FontCache;
import android.content.Intent; import android.content.Intent;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -12,11 +20,6 @@ import android.widget.Button;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.helpers.FontCache;
import java.util.List;
/** /**
* Created by Denis on 21.11.2014. * Created by Denis on 21.11.2014.
@ -24,6 +27,8 @@ import java.util.List;
public class DashPluginsFragment extends DashBaseFragment { public class DashPluginsFragment extends DashBaseFragment {
public static final String TAG = "DASH_PLUGINS_FRAGMENT"; public static final String TAG = "DASH_PLUGINS_FRAGMENT";
private ArrayList<OsmandPlugin> showedPlugins;
private ArrayList<CompoundButton> checks;
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -37,43 +42,67 @@ public class DashPluginsFragment extends DashBaseFragment {
startActivityForResult(new Intent(getActivity(), getMyApplication().getAppCustomization().getPluginsActivity()), 1); startActivityForResult(new Intent(getActivity(), getMyApplication().getAppCustomization().getPluginsActivity()), 1);
} }
}); });
LinearLayout layout = (LinearLayout) view.findViewById(R.id.plugins);
addPlugins(inflater, layout);
return view; return view;
} }
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
LinearLayout layout = (LinearLayout) getView().findViewById(R.id.plugins); for (int i = 0; i < checks.size(); i++) {
layout.removeAllViews(); final CompoundButton ch = checks.get(i);
addPlugins(layout); final OsmandPlugin o = showedPlugins.get(i);
ch.setOnCheckedChangeListener(null);
ch.setChecked(OsmandPlugin.getEnabledPlugins().contains(o));
ch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
OsmandPlugin.enablePlugin(getMyApplication(), o, b);
}
});
} }
private void addPlugins(View parent){ }
private void addPlugins(LayoutInflater inflater, View parent) {
LinearLayout layout = (LinearLayout) parent; LinearLayout layout = (LinearLayout) parent;
LayoutInflater inflater = getActivity().getLayoutInflater();
List<OsmandPlugin> availablePlugins = OsmandPlugin.getAvailablePlugins(); List<OsmandPlugin> availablePlugins = OsmandPlugin.getAvailablePlugins();
List<OsmandPlugin> enabledPlugins = OsmandPlugin.getEnabledPlugins(); List<OsmandPlugin> enabledPlugins = OsmandPlugin.getEnabledPlugins();
for (int i=0; i < availablePlugins.size(); i++){ List<OsmandPlugin> toShow = new ArrayList<OsmandPlugin>();
if (i> 2){ showedPlugins = new ArrayList<OsmandPlugin>();
checks = new ArrayList<CompoundButton>();
for(OsmandPlugin o : availablePlugins) {
if(!(o instanceof OsmandDevelopmentPlugin)) {
if(enabledPlugins.contains(o)) {
showedPlugins.add(o);
} else{
toShow.add(o);
}
}
}
Collections.shuffle(toShow, new Random(System.currentTimeMillis()));
while (!toShow.isEmpty()) {
showedPlugins.add(toShow.remove(0));
if (showedPlugins.size() > 2) {
break; break;
} }
}
for (int i = 0; i < showedPlugins.size(); i++) {
final OsmandPlugin plugin = availablePlugins.get(i); final OsmandPlugin plugin = availablePlugins.get(i);
View view = inflater.inflate(R.layout.dash_plugin_item, null, false); View view = inflater.inflate(R.layout.dash_plugin_item, null, false);
((TextView) view.findViewById(R.id.plugin_name)).setText(plugin.getName()); ((TextView) view.findViewById(R.id.plugin_name)).setText(plugin.getName());
((TextView) view.findViewById(R.id.plugin_descr)).setText(plugin.getDescription()); ((TextView) view.findViewById(R.id.plugin_descr)).setText(plugin.getDescription());
CompoundButton check = (CompoundButton) view.findViewById(R.id.check_item); CompoundButton check = (CompoundButton) view.findViewById(R.id.check_item);
checks.add(check);
check.setChecked(enabledPlugins.contains(plugin)); check.setChecked(enabledPlugins.contains(plugin));
check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources()
@Override // .getDisplayMetrics());
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { // LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, height);
OsmandPlugin.enablePlugin(getMyApplication(),plugin, b); // view.setLayoutParams(lp);
}
});
int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics());
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, height);
view.setLayoutParams(lp);
layout.addView(view); layout.addView(view);
} }
} }

View file

@ -1,7 +1,14 @@
package net.osmand.plus.dashboard; package net.osmand.plus.dashboard;
import java.util.ArrayList;
import java.util.List;
import net.osmand.plus.R;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.BaseDownloadActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.IndexItem;
import android.content.Intent; import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -12,15 +19,6 @@ import android.widget.ImageButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.plus.R;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.BaseDownloadActivity;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadEntry;
import net.osmand.plus.download.IndexItem;
import java.util.ArrayList;
import java.util.List;
/** /**
* Created by Denis on 21.11.2014. * Created by Denis on 21.11.2014.