Skip to content

Commit 94a1070

Browse files
committed
Profile Editor: fix for split/delete buttons on smaller screens
1 parent 662d218 commit 94a1070

File tree

2 files changed

+37
-32
lines changed

2 files changed

+37
-32
lines changed

app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/ProfileEditor.java

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
import android.content.Intent;
88
import android.graphics.Color;
99
import android.graphics.Point;
10+
import android.os.Build;
1011
import android.os.Bundle;
1112
import android.support.v7.app.AppCompatActivity;
1213
import android.support.v7.widget.DefaultItemAnimator;
1314
import android.support.v7.widget.LinearLayoutManager;
1415
import android.support.v7.widget.RecyclerView;
16+
import android.util.DisplayMetrics;
1517
import android.util.Log;
1618
import android.view.View;
1719
import android.widget.Button;
@@ -93,8 +95,8 @@ protected void onCreate(Bundle savedInstanceState) {
9395
adjustallSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
9496
@Override
9597
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
96-
adjustmentFactor=1+((progress-25)*0.02);
97-
adjustPercentage.setText(JoH.qs(adjustmentFactor*100,0)+"%");
98+
adjustmentFactor = 1 + ((progress - 25) * 0.02);
99+
adjustPercentage.setText(JoH.qs(adjustmentFactor * 100, 0) + "%");
98100
}
99101

100102
@Override
@@ -115,7 +117,6 @@ public void onStopTrackingTouch(SeekBar seekBar) {
115117
});
116118

117119

118-
119120
recyclerView = (RecyclerView) findViewById(R.id.profile_recycler_view);
120121

121122
mAdapter = new ProfileAdapter(this, profileItemList, doMgdl);
@@ -141,7 +142,7 @@ public void onStopTrackingTouch(SeekBar seekBar) {
141142
@Override
142143
public void onChanged() {
143144
super.onChanged();
144-
// Log.d(TAG, "onChanged");
145+
// Log.d(TAG, "onChanged");
145146

146147
}
147148

@@ -179,10 +180,19 @@ public void onItemRangeChanged(final int positionStart, int itemCount, Object pa
179180
// split or delete
180181
} else if (payload.toString().equals("long-split")) {
181182

183+
final DisplayMetrics dm = new DisplayMetrics();
184+
getWindowManager().getDefaultDisplay().getMetrics(dm);
185+
final int screen_width = dm.widthPixels;
186+
final int screen_height = dm.heightPixels;
187+
boolean small_screen = false;
188+
// smaller screens or lower version don't seem to play well with long dialog button names
189+
if ((screen_width < 720) || (screen_height < 720) || ((Build.VERSION.SDK_INT < Build.VERSION_CODES.M)))
190+
small_screen = true;
191+
182192
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);
183193
alertDialogBuilder.setMessage(R.string.split_delete_or_do_nothing);
184194

185-
alertDialogBuilder.setPositiveButton(R.string.split_this_block_in_two, new DialogInterface.OnClickListener() {
195+
alertDialogBuilder.setPositiveButton(small_screen ? getString(R.string.split) : getString(R.string.split_this_block_in_two), new DialogInterface.OnClickListener() {
186196
@Override
187197
public void onClick(DialogInterface arg0, int arg1) {
188198

@@ -203,7 +213,7 @@ public void onClick(DialogInterface arg0, int arg1) {
203213
}
204214
});
205215
if (profileItemList.size() > 1) {
206-
alertDialogBuilder.setNeutralButton(R.string.delete_this_time_block, new DialogInterface.OnClickListener() {
216+
alertDialogBuilder.setNeutralButton(small_screen ? getString(R.string.delete) : getString(R.string.delete_this_time_block), new DialogInterface.OnClickListener() {
207217
@Override
208218
public void onClick(DialogInterface dialog, int which) {
209219
profileItemList.remove(positionStart);
@@ -212,7 +222,7 @@ public void onClick(DialogInterface dialog, int which) {
212222
});
213223
}
214224

215-
alertDialogBuilder.setNegativeButton(R.string.cancel_do_nothing, new DialogInterface.OnClickListener() {
225+
alertDialogBuilder.setNegativeButton(small_screen ? getString(R.string.cancel) : getString(R.string.cancel_do_nothing), new DialogInterface.OnClickListener() {
216226
@Override
217227
public void onClick(DialogInterface dialog, int which) {
218228

@@ -227,7 +237,6 @@ public void onClick(DialogInterface dialog, int which) {
227237
}
228238

229239

230-
231240
}
232241
});
233242

@@ -260,49 +269,44 @@ public void onPause() {
260269
}
261270
}
262271

263-
private static void updateAdjustmentFactor(double factor)
264-
{
265-
adjustmentFactor=factor;
272+
private static void updateAdjustmentFactor(double factor) {
273+
adjustmentFactor = factor;
266274
adjustPercentage.setText(JoH.qs(adjustmentFactor * 100, 0) + "%");
267275

268-
int position = (int)((adjustmentFactor-1) /0.02 )+25;
276+
int position = (int) ((adjustmentFactor - 1) / 0.02) + 25;
269277
adjustallSeekBar.setProgress(position > 0 ? position : 0);
270278

271279
}
272280

273281
private void saveData(boolean for_real) {
274282
final Gson gson = new GsonBuilder()
275283
.excludeFieldsWithoutExposeAnnotation()
276-
//.registerTypeAdapter(Date.class, new DateTypeAdapter())
284+
//.registerTypeAdapter(Date.class, new DateTypeAdapter())
277285
.serializeSpecialFloatingPointValues()
278286
.create();
279287

280288
final List<ProfileItem> profileItemListTmp = new ArrayList<>();
281289

282290

283-
if (!for_real)
284-
{
285-
Log.d(TAG,"Saving for real with adjustment factor: "+adjustmentFactor);
291+
if (!for_real) {
292+
Log.d(TAG, "Saving for real with adjustment factor: " + adjustmentFactor);
286293
// save working set clean of adjustment factor to avoid stacking
287-
for (ProfileItem item : profileItemList)
288-
{
294+
for (ProfileItem item : profileItemList) {
289295
profileItemListTmp.add(item.clone());
290296
}
291297

292-
for (ProfileItem item : profileItemListTmp)
293-
{
294-
item.carb_ratio = item.carb_ratio/adjustmentFactor;
295-
item.sensitivity = item.sensitivity*adjustmentFactor;
296-
}
298+
for (ProfileItem item : profileItemListTmp) {
299+
item.carb_ratio = item.carb_ratio / adjustmentFactor;
300+
item.sensitivity = item.sensitivity * adjustmentFactor;
301+
}
297302

298303
} else {
299304
// for real save
300305
profileItemListTmp.addAll(profileItemList); // no need to clone
301306

302-
for (ProfileItem item : profileItemListTmp)
303-
{
307+
for (ProfileItem item : profileItemListTmp) {
304308
item.carb_ratio = Math.round(item.carb_ratio); // round to nearest g
305-
item.sensitivity = (double)(Math.round(item.sensitivity*10))/10;
309+
item.sensitivity = (double) (Math.round(item.sensitivity * 10)) / 10;
306310
}
307311
}
308312

@@ -312,7 +316,7 @@ private void saveData(boolean for_real) {
312316
Home.setPreferencesString("saved_profile_list_json", data);
313317
Home.setPreferencesString("saved_profile_list_json_working", "");
314318
Log.d(TAG, "Saved final data");
315-
UserError.Log.uel(TAG,"Saved Treatment Profile data, timeblocks:"+profileItemListTmp.size());
319+
UserError.Log.uel(TAG, "Saved Treatment Profile data, timeblocks:" + profileItemListTmp.size());
316320
updateAdjustmentFactor(1.0); // reset it
317321
dataChanged = true;
318322
Profile.invalidateProfile();
@@ -341,7 +345,7 @@ public void profileSaveButton(View myview) {
341345

342346
public void profileUndoButton(View myview) {
343347
clearWorkingData();
344-
adjustmentFactor=1;
348+
adjustmentFactor = 1;
345349
adjustallSeekBar.setProgress(25);
346350
profileItemList.clear();
347351
// we must preserve the existing object reference used by the adapter
@@ -394,10 +398,9 @@ public static List<ProfileItem> loadData(boolean buttons) {
394398
ProfileItem[] restored = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().fromJson(data, ProfileItem[].class);
395399
if (restored != null) {
396400
// process adjustment factor
397-
for (ProfileItem item : restored)
398-
{
399-
item.carb_ratio = item.carb_ratio*adjustmentFactor;
400-
item.sensitivity = item.sensitivity/adjustmentFactor;
401+
for (ProfileItem item : restored) {
402+
item.carb_ratio = item.carb_ratio * adjustmentFactor;
403+
item.sensitivity = item.sensitivity / adjustmentFactor;
401404
}
402405
Collections.addAll(myprofileItemList, restored);
403406
}

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,5 +505,7 @@
505505
<string name="install_pebble_apps">Install Pebble Apps</string>
506506
<string name="sliding_24_hour_window_summary">Use last 24 hours instead of time since midnight for statistics.</string>
507507
<string name="sliding_24_hour_window">Sliding Window</string>
508+
<string name="split">Split</string>
509+
<string name="delete">Delete</string>
508510

509511
</resources>

0 commit comments

Comments
 (0)