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"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="50dp">
<View android:layout_width="match_parent"
android:background="@color/dashboard_divider"
android:layout_height="1dp"/>
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:paddingRight="12dp"
android:layout_height="match_parent">
<LinearLayout android:orientation="vertical"
android:layout_marginLeft="12dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:layout_height="match_parent">
<TextView android:id="@+id/plugin_name"
android:textColor="@color/dashboard_black"
android:ellipsize="end"
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>
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" />
<include layout="@layout/check_item_rel"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="12dp"
android:paddingBottom="4dp"
android:paddingRight="12dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="@+id/plugin_name"
android:layout_width="0dp"
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:gravity="center_vertical"
android:textColor="@color/dashboard_black" />
<include layout="@layout/check_item_rel" />
</LinearLayout>
<TextView
android:id="@+id/plugin_descr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="3" />
</LinearLayout>
</LinearLayout>

View file

@ -1,10 +1,18 @@
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.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -12,11 +20,6 @@ import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
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.
@ -24,6 +27,8 @@ import java.util.List;
public class DashPluginsFragment extends DashBaseFragment {
public static final String TAG = "DASH_PLUGINS_FRAGMENT";
private ArrayList<OsmandPlugin> showedPlugins;
private ArrayList<CompoundButton> checks;
@Override
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);
}
});
LinearLayout layout = (LinearLayout) view.findViewById(R.id.plugins);
addPlugins(inflater, layout);
return view;
}
@Override
public void onResume() {
super.onResume();
LinearLayout layout = (LinearLayout) getView().findViewById(R.id.plugins);
layout.removeAllViews();
addPlugins(layout);
for (int i = 0; i < checks.size(); i++) {
final CompoundButton ch = checks.get(i);
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;
LayoutInflater inflater = getActivity().getLayoutInflater();
List<OsmandPlugin> availablePlugins = OsmandPlugin.getAvailablePlugins();
List<OsmandPlugin> enabledPlugins = OsmandPlugin.getEnabledPlugins();
for (int i=0; i < availablePlugins.size(); i++){
if (i> 2){
List<OsmandPlugin> toShow = new ArrayList<OsmandPlugin>();
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;
}
}
for (int i = 0; i < showedPlugins.size(); i++) {
final OsmandPlugin plugin = availablePlugins.get(i);
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_descr)).setText(plugin.getDescription());
CompoundButton check = (CompoundButton) view.findViewById(R.id.check_item);
checks.add(check);
check.setChecked(enabledPlugins.contains(plugin));
check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
OsmandPlugin.enablePlugin(getMyApplication(),plugin, b);
}
});
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);
// 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);
}
}

View file

@ -1,7 +1,14 @@
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.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
@ -12,15 +19,6 @@ import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
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.