support for removing temp targets from GUI

This commit is contained in:
Milos Kozak 2017-01-16 23:23:20 +01:00
parent 8c38090031
commit 218190e92f
5 changed files with 76 additions and 5 deletions

View file

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View file

@ -974,7 +974,25 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbAdd(intent, data.toString(), NewExtendedBolusDialog.class);
DbLogger.dbAdd(intent, data.toString(), ConfigBuilderPlugin.class);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void removeCareportalEntryFromNS(String _id) {
try {
Context context = MainApp.instance().getApplicationContext();
Bundle bundle = new Bundle();
bundle.putString("action", "dbRemove");
bundle.putString("collection", "treatments");
bundle.putString("_id", _id);
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbRemove(intent, _id, ConfigBuilderPlugin.class);
} catch (Exception e) {
e.printStackTrace();
}

View file

@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Paint;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
@ -18,8 +19,10 @@ import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.j256.ormlite.dao.Dao;
import com.squareup.otto.Subscribe;
import java.sql.SQLException;
import java.util.List;
import info.nightscout.androidaps.MainApp;
@ -79,7 +82,8 @@ public class TempTargetRangeFragment extends Fragment implements View.OnClickLis
holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.colorInProgress));
else
holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.cardColorBackground));
}
holder.remove.setTag(tempTarget);
}
@Override
public int getItemCount() {
@ -91,13 +95,14 @@ public class TempTargetRangeFragment extends Fragment implements View.OnClickLis
super.onAttachedToRecyclerView(recyclerView);
}
public static class TempTargetsViewHolder extends RecyclerView.ViewHolder {
public static class TempTargetsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
CardView cv;
TextView date;
TextView duration;
TextView low;
TextView high;
TextView reason;
TextView remove;
LinearLayout dateLinearLayout;
TempTargetsViewHolder(View itemView) {
@ -108,8 +113,32 @@ public class TempTargetRangeFragment extends Fragment implements View.OnClickLis
low = (TextView) itemView.findViewById(R.id.temptargetrange_low);
high = (TextView) itemView.findViewById(R.id.temptargetrange_high);
reason = (TextView) itemView.findViewById(R.id.temptargetrange_reason);
remove = (TextView) itemView.findViewById(R.id.temptargetrange_remove);
remove.setOnClickListener(this);
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
dateLinearLayout = (LinearLayout) itemView.findViewById(R.id.temptargetrange_datelinearlayout);
}
@Override
public void onClick(View v) {
TempTarget tempTarget = (TempTarget) v.getTag();
switch (v.getId()) {
case R.id.temptargetrange_remove:
String _id = tempTarget._id;
if (_id != null && !_id.equals("")) {
MainApp.getConfigBuilder().removeCareportalEntryFromNS(_id);
try {
Dao<TempTarget, Long> daoTempTargets = MainApp.getDbHelper().getDaoTempTargets();
daoTempTargets.delete(tempTarget);
MainApp.bus().post(new EventTempTargetRangeChange());
} catch (SQLException e) {
e.printStackTrace();
}
}
break;
}
}
}
}

View file

@ -26,4 +26,14 @@ public class DbLogger {
} else if (Config.logNSUpload)
log.debug("DBADD dbAdd " + q.size() + " receivers " + data);
}
public static void dbRemove(Intent intent, String data, Class sender) {
Logger log = LoggerFactory.getLogger(sender);
List<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(intent, 0);
if (q.size() < 1) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(),MainApp.sResources.getString(R.string.nsclientnotinstalled));
log.error("DBREMOVE No receivers");
} else if (Config.logNSUpload)
log.debug("DBREMOVE dbRemove " + q.size() + " receivers " + data);
}
}

View file

@ -89,10 +89,15 @@
android:layout_height="wrap_content"
android:layout_gravity="top"
android:paddingLeft="10dp"
android:paddingRight="5dp"
android:text="@string/reason"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:text=":" />
<TextView
android:id="@+id/temptargetrange_reason"
android:layout_width="wrap_content"
@ -100,8 +105,17 @@
android:layout_gravity="center_vertical"
android:paddingRight="10dp"
android:text="Activity"
android:layout_weight="1"
android:textStyle="bold" />
<TextView
android:text="@string/overview_quickwizard_item_remove_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/temptargetrange_remove"
android:textAlignment="viewEnd"
android:textColor="@android:color/holo_orange_light" />
</LinearLayout>
</LinearLayout>