Project

General

Profile

« Previous | Next » 

Revision 65bc1da3

Added by Leszek Koltunski over 1 year ago

Improve the way we display time in the Scores dialog

View differences:

src/main/java/org/distorted/dialogs/RubikDialogScoresPagerAdapter.java
66 66

  
67 67
///////////////////////////////////////////////////////////////////////////////////////////////////
68 68

  
69
  private void addSection(int tab, int level, int numLevels, final RubikDialogScoresView view, final String[] country, final String[] name, final float[] time)
69
  private void addSection(int tab, int level, int numLevels, final RubikDialogScoresView view, final String[] country, final String[] name, final int[] time)
70 70
    {
71 71
    String title = level==numLevels ?
72 72
                   mAct.getString(R.string.levelM) :
......
120 120

  
121 121
///////////////////////////////////////////////////////////////////////////////////////////////////
122 122

  
123
  public void receive(final String[][][] country, final String[][][] name, final float[][][] time)
123
  public void receive(final String[][][] country, final String[][][] name, final int[][][] time)
124 124
    {
125 125
    prepareView();
126 126
    int toDo=0;
src/main/java/org/distorted/dialogs/RubikDialogScoresView.java
9 9

  
10 10
package org.distorted.dialogs;
11 11

  
12
import android.annotation.SuppressLint;
13 12
import android.content.Context;
14 13
import android.content.res.Resources;
15 14
import androidx.fragment.app.FragmentActivity;
......
64 63

  
65 64
///////////////////////////////////////////////////////////////////////////////////////////////////
66 65

  
67
  @SuppressLint("DefaultLocale")
68
  LinearLayout createSection(FragmentActivity act, int tab, String title, int level, final String[] country, final String[] name, final float[] time)
66
  LinearLayout createSection(FragmentActivity act, int tab, String title, int level, final String[] country, final String[] name, final int[] time)
69 67
    {
70 68
    LinearLayout levelLayout = (LinearLayout)inflate(act, R.layout.dialog_scores_scramble_title, null);
71 69
    TextView text = levelLayout.findViewById(R.id.scoresScrambleTitle);
......
79 77
    RubikScores scores = RubikScores.getInstance();
80 78

  
81 79
    boolean inserted = false;
82
    long myRecordInMillis = scores.getRecord(tab, level);
83
    float myRecordInSeconds = (myRecordInMillis/10)/100.0f;
80
    int myRecordInMillis = scores.getRecord(tab, level);
81
    String myRecord = ( myRecordInMillis<RubikScores.NO_RECORD ) ? formatRecord(myRecordInMillis) : "??";
84 82
    String myName = scores.getName();
85 83
    if( myName.length()==0 ) myName = act.getString(R.string.you);
86 84
    int myCountryID = res.getIdentifier( scores.getCountry(), "drawable", packageName);
87
    String myRecord = ( myRecordInMillis<RubikScores.NO_RECORD ) ? String.format("%.2f", myRecordInSeconds) : "??";
88 85
    String theirTime;
89 86
    int theirCountryID;
90 87

  
......
97 94
      {
98 95
      if( name[j] != null )
99 96
        {
100
        if( myRecordInSeconds<time[j] && !inserted )
97
        if( myRecordInMillis<time[j] && !inserted )
101 98
          {
102 99
          inserted = true;
103 100
          View row = createRow(act, myCountryID, myName, myRecord, height, red);
......
110 107
          {
111 108
          if( equals ) inserted=true;
112 109
          theirCountryID = res.getIdentifier( country[j], "drawable", packageName);
113
          theirTime = String.format("%.2f", time[j]);
110
          theirTime = formatRecord(time[j]);
114 111
          View row = createRow(act, theirCountryID, name[j], theirTime, height, equals ? red:white);
115 112
          levelLayout.addView(row);
116 113
          }
......
126 123
    return levelLayout;
127 124
    }
128 125

  
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

  
128
  private String formatRecord(int time)
129
    {
130
    time /= 10;
131
    int millis = time%100;
132
    time /= 100;
133
    int seconds = time%60;
134
    int minutes = time/60;
135

  
136
    return minutes + (seconds<10 ? ":0" : ":") + seconds + (millis<10 ? ".0" : ".") + millis;
137
    }
138

  
129 139
///////////////////////////////////////////////////////////////////////////////////////////////////
130 140

  
131 141
  private View createRow(FragmentActivity act, int countryID, String name, String time, int height, int color)
src/main/java/org/distorted/external/RubikNetwork.java
39 39
  {
40 40
  public interface ScoresReceiver
41 41
    {
42
    void receive(String[][][] country, String[][][] name, float[][][] time);
42
    void receive(String[][][] country, String[][][] name, int[][][] time);
43 43
    void message(String mess);
44 44
    void error(String error);
45 45
    }
......
110 110

  
111 111
  private static String[][][] mCountry;
112 112
  private static String[][][] mName;
113
  private static float[][][] mTime;
113
  private static int[][][] mTime;
114 114
  private static int[][] mPlaces;
115 115

  
116 116
  private static RubikNetwork mThis;
......
130 130

  
131 131
    if( mCountry==null || newNum!=mNumObjects ) mCountry = new String[newNum][LEVELS_SHOWN+1][MAX_PLACES];
132 132
    if( mName==null    || newNum!=mNumObjects ) mName    = new String[newNum][LEVELS_SHOWN+1][MAX_PLACES];
133
    if( mTime==null    || newNum!=mNumObjects ) mTime    = new  float[newNum][LEVELS_SHOWN+1][MAX_PLACES];
133
    if( mTime==null    || newNum!=mNumObjects ) mTime    = new    int[newNum][LEVELS_SHOWN+1][MAX_PLACES];
134 134
    if( mPlaces==null  || newNum!=mNumObjects ) mPlaces  = new    int[newNum][LEVELS_SHOWN+1];
135 135

  
136 136
    if( mUpdates==null ) mUpdates = new RubikUpdates();
......
243 243

  
244 244
          mCountry[object][level][p] = country;
245 245
          mName   [object][level][p] = name;
246
          mTime   [object][level][p] = ((float)(time/10))/100.0f;
246
          mTime   [object][level][p] = time;
247 247
          }
248 248
        }
249 249
      }
src/main/java/org/distorted/external/RubikScores.java
37 37

  
38 38
  public static final int MAX_RECORD = 10;
39 39
  public static final int MULT = 1000000;
40
  public static final long NO_RECORD = Long.MAX_VALUE;
40
  public static final int NO_RECORD = Integer.MAX_VALUE;
41 41
  private static RubikScores mThis;
42 42

  
43 43
  private String mName, mCountry;
......
50 50

  
51 51
  private static class MapValue
52 52
    {
53
    long record;
53
    int record;
54 54
    boolean submitted;
55 55

  
56
    MapValue(long rec,int sub)
56
    MapValue(int rec,int sub)
57 57
      {
58 58
      record    = rec;
59 59
      submitted = sub!=0;
......
286 286

  
287 287
///////////////////////////////////////////////////////////////////////////////////////////////////
288 288

  
289
  public synchronized int setRecord(int object, int level, long record)
289
  public synchronized int setRecord(int object, int level, int record)
290 290
    {
291 291
    int key = mapKey(object,level);
292 292
    MapValue oldValue = mMap.get(key);
......
312 312

  
313 313
///////////////////////////////////////////////////////////////////////////////////////////////////
314 314

  
315
  public synchronized long getRecord(int object, int level)
315
  public synchronized int getRecord(int object, int level)
316 316
    {
317 317
    int key = mapKey(object,level);
318 318
    MapValue value = mMap.get(key);
......
420 420
  public synchronized void restorePreferences(SharedPreferences preferences)
421 421
    {
422 422
    String recordStr, subStr, nameStr, timeStr, submStr, errorStr="";
423
    int start, end, equals, comma, ordinal, subm;
424
    long time;
423
    int start, end, equals, comma, ordinal, subm, time;
425 424
    boolean thereWasError = false;
426 425
    int numObjects = RubikObjectList.getNumObjects();
427 426

  
......
453 452

  
454 453
          if( ordinal>=0 && ordinal<numObjects )
455 454
            {
456
            time = Long.parseLong(timeStr);
455
            time = Integer.parseInt(timeStr);
457 456
            subm = Integer.parseInt(submStr);
458 457

  
459 458
            if( subm>=0 && subm<=1 )
src/main/java/org/distorted/main/RubikActivity.java
75 75
    public static final float PATTERN_GROUP_TEXT  = 0.03f;
76 76
    public static final float PATTERN_CHILD_TEXT  = 0.02f;
77 77
    public static final float SCORES_LEVEL_TEXT   = 0.035f;
78
    public static final float SCORES_ITEM_TEXT    = 0.030f;
78
    public static final float SCORES_ITEM_TEXT    = 0.025f;
79 79
    public static final float TAB_WIDTH           = 0.066f;
80 80
    public static final float TAB_HEIGHT          = 0.066f;
81 81
    public static final float POPUP_PADDING       = 0.028f;
src/main/java/org/distorted/screens/RubikScreenSolving.java
186 186
    RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
187 187
    int object = RubikObjectList.getCurrObject();
188 188
    int level = play.getLevel()-1;
189
    return mScores.setRecord(object, level, mElapsed);
189
    return mScores.setRecord(object, level, (int)mElapsed);
190 190
    }
191 191

  
192 192
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/res/layout/dialog_scores_scramble_row.xml
31 31
        android:id="@+id/scoresScrambleRowTime"
32 32
        android:layout_width="match_parent"
33 33
        android:layout_height="match_parent"
34
        android:layout_weight="1.5"
34
        android:layout_weight="1.2"
35 35
        android:textSize="20sp"
36 36
        android:maxLines="1"
37 37
        android:gravity="end"
38 38
        android:background="@color/black"
39
        android:paddingEnd="5dp"
39
        android:paddingEnd="3dp"
40 40
        />
41 41
</LinearLayout>

Also available in: Unified diff