commit 1c90c64a3860a90e527fdb08c97d7190eedabbc0
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Mon Mar 16 23:53:22 2020 +0000

    Incorporate myRecords into the Scores dialog.

diff --git a/src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java b/src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java
index 82248c69..b21744a3 100644
--- a/src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java
+++ b/src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java
@@ -45,19 +45,19 @@ class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresD
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void receive(final String[][][] country, final String[][][] name, final String[][][] time)
+  public void receive(final String[][][] country, final String[][][] name, final float[][][] time)
     {
     prepareView();
 
     int c = mViewPager.getCurrentItem();
 
-    addPage(mViews[c],country[c],name[c],time[c]);
+    addPage(c, mViews[c],country[c],name[c],time[c]);
 
     for(int i=0; i<mNumTabs; i++)
       {
       if( i==c ) continue;
 
-      addPage(mViews[i],country[i],name[i],time[i]);
+      addPage(i, mViews[i],country[i],name[i],time[i]);
       }
     }
 
@@ -88,11 +88,11 @@ class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresD
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private void addPage(final RubikDialogScoresView view, final String[][] country, final String[][] name, final String[][] time)
+  private void addPage(int tab, final RubikDialogScoresView view, final String[][] country, final String[][] name, final float[][] time)
     {
     for(int i=0; i<MAX_SCRAMBLE; i++)
       {
-      final LinearLayout section = view.createSection(mAct, i, country[i], name[i], time[i]);
+      final LinearLayout section = view.createSection(mAct, tab, i, country[i], name[i], time[i]);
 
       mAct.runOnUiThread(new Runnable()
         {
diff --git a/src/main/java/org/distorted/dialog/RubikDialogScoresView.java b/src/main/java/org/distorted/dialog/RubikDialogScoresView.java
index df107583..e21ed49d 100644
--- a/src/main/java/org/distorted/dialog/RubikDialogScoresView.java
+++ b/src/main/java/org/distorted/dialog/RubikDialogScoresView.java
@@ -30,6 +30,9 @@ import android.widget.LinearLayout;
 import android.widget.TextView;
 
 import org.distorted.magic.R;
+import org.distorted.object.RubikObjectList;
+import org.distorted.scores.RubikScores;
+
 import static org.distorted.scores.RubikScoresDownloader.MAX_PLACES;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -64,7 +67,7 @@ public class RubikDialogScoresView extends FrameLayout
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  LinearLayout createSection(FragmentActivity act, int scramble, final String[] country, final String[] name, final String[] time)
+  LinearLayout createSection(FragmentActivity act, int tab, int scramble, final String[] country, final String[] name, final float[] time)
     {
     LinearLayout level = (LinearLayout)inflate(act, R.layout.dialog_scores_scramble_title, null);
     TextView text = level.findViewById(R.id.scoresScrambleTitle);
@@ -73,29 +76,68 @@ public class RubikDialogScoresView extends FrameLayout
     Resources res = act.getResources();
     String packageName = act.getPackageName();
 
-    for(int j=0; j<MAX_PLACES; j++)
-      {
-      if( name[j] != null )
-        {
-        View row = inflate(act, R.layout.dialog_scores_scramble_row, null);
-
-        ImageView imgCoun = row.findViewById(R.id.scoresScrambleRowCountry);
-        TextView textName = row.findViewById(R.id.scoresScrambleRowName);
-        TextView textTime = row.findViewById(R.id.scoresScrambleRowTime);
+    int object = RubikObjectList.unpackObject(tab);
+    int size   = RubikObjectList.unpackSize(tab);
+    RubikScores scores = RubikScores.getInstance();
 
-        int resID = res.getIdentifier( country[j], "drawable", packageName);
+    boolean inserted = false;
+    long myRecordInSeconds = scores.getRecord(object, size, scramble);
+    String myName = scores.getName();
+    int myCountryID = scores.getCountryID();
+    String myRecord = ( myRecordInSeconds<RubikScores.NO_RECORD ) ? Float.toString((myRecordInSeconds/100)/10.0f) : "??";
+    String theirTime;
+    int theirCountryID;
 
-        imgCoun.setImageResource(resID!=0 ? resID : R.drawable.unk);
-        textName.setText(name[j]);
-        textTime.setText(time[j]);
+    int white = res.getColor(R.color.white);
+    int red   = res.getColor(R.color.red);
 
+    for(int j=0; j<MAX_PLACES-1; j++)
+      {
+      if( name[j] != null )
+        {
+        if( myRecordInSeconds<time[j] && !inserted )
+          {
+          inserted = true;
+          View row = createRow(act, myCountryID, myName, myRecord, red);
+          level.addView(row);
+          }
+
+        theirCountryID = res.getIdentifier( country[j], "drawable", packageName);
+        theirTime = Float.toString(time[j]);
+        View row = createRow(act, theirCountryID, name[j], theirTime, white);
         level.addView(row);
         }
       }
 
+    if( !inserted )
+      {
+      View row = createRow(act, myCountryID, myName, myRecord, red);
+      level.addView(row);
+      }
+
     return level;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private View createRow(FragmentActivity act, int countryID, String name, String time, int color)
+    {
+    View row = inflate(act, R.layout.dialog_scores_scramble_row, null);
+
+    ImageView imgCoun = row.findViewById(R.id.scoresScrambleRowCountry);
+    TextView textName = row.findViewById(R.id.scoresScrambleRowName);
+    TextView textTime = row.findViewById(R.id.scoresScrambleRowTime);
+
+    imgCoun.setImageResource(countryID!=0 ? countryID : R.drawable.unk);
+    textName.setText(name);
+    textTime.setText(time);
+
+    textName.setTextColor(color);
+    textTime.setTextColor(color);
+
+    return row;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // needs to run on UI thread
 
diff --git a/src/main/java/org/distorted/scores/RubikScores.java b/src/main/java/org/distorted/scores/RubikScores.java
index bd68f6ea..f5b8a0c9 100644
--- a/src/main/java/org/distorted/scores/RubikScores.java
+++ b/src/main/java/org/distorted/scores/RubikScores.java
@@ -20,6 +20,8 @@
 package org.distorted.scores;
 
 import android.content.SharedPreferences;
+
+import org.distorted.magic.R;
 import org.distorted.object.RubikObjectList;
 
 import static org.distorted.object.RubikObjectList.MAX_SIZE;
@@ -31,7 +33,7 @@ import static org.distorted.uistate.RubikStatePlay.MAX_SCRAMBLE;
 
 public class RubikScores
   {
-  private static final long NO_RECORD = Integer.MAX_VALUE;
+  public static final long NO_RECORD = Long.MAX_VALUE;
   private static RubikScores mThis;
 
   private long[][][] mRecords;
@@ -39,6 +41,7 @@ public class RubikScores
   private boolean mNameIsVerified;
   private int mNumRuns;
   private int mNumPlays;
+  private int mCountryID;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -53,10 +56,11 @@ public class RubikScores
           mRecords[i][j][k] = NO_RECORD;
           }
 
-    mName = "";
+    mName = "YOU";
     mNameIsVerified = false;
     mNumPlays= -1;
     mNumRuns = -1;
+    mCountryID = R.drawable.unk;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -116,7 +120,8 @@ public class RubikScores
     {
     String recordStr, subStr, nameStr, sizeStr, timeStr;
     int start, end, equals, underscore;
-    int object, size, time;
+    int object, size;
+    long time;
 
     for(int scramble=0; scramble<MAX_SCRAMBLE; scramble++)
       {
@@ -143,13 +148,13 @@ public class RubikScores
 
           object = RubikObjectList.getOrdinal(nameStr);
           size   = RubikObjectList.getSize(object,Integer.parseInt(sizeStr));
-          time   = Integer.parseInt(timeStr);
+          time   = Long.parseLong(timeStr);
 
           if( object>=0 && object< NUM_OBJECTS && size>=0 && size<MAX_SIZE )
             {
             mRecords[object][size][scramble] = time;
 
-            if( time<Integer.MAX_VALUE )
+            if( time<NO_RECORD )
               {
               android.util.Log.e("solv", "Set record for: object="+object+" size="+size+" scramble="+scramble+" time: "+time);
               }
@@ -162,7 +167,7 @@ public class RubikScores
         }
       }
 
-    mName           = preferences.getString("scores_name"  , "");
+    mName           = preferences.getString("scores_name"  , "YOU" );
     mNameIsVerified = preferences.getBoolean("scores_isVerified", false);
     mNumPlays       = preferences.getInt("scores_numPlays", 0);
     mNumRuns        = preferences.getInt("scores_numRuns" , 0);
@@ -199,6 +204,7 @@ public class RubikScores
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
+// TODO
 
   public void setName(String newName)
     {
@@ -206,19 +212,28 @@ public class RubikScores
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
+// TODO
 
   public void verifyName()
     {
     mNameIsVerified = true;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// TODO
+
+  public void setCountry(int country)
+    {
+    mCountryID = country;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public long getRecord(int object, int size, int scramble)
     {
     int maxsize = RubikObjectList.getObject(object).getSizes().length;
 
-    if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && scramble>=1 && scramble<=MAX_SCRAMBLE )
+    if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && scramble>=0 && scramble<MAX_SCRAMBLE )
       {
       return mRecords[object][size][scramble];
       }
@@ -227,6 +242,15 @@ public class RubikScores
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
+// TODO
+
+  public boolean isVerified()
+    {
+    return mNameIsVerified;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// TODO
 
   public int getNumPlays()
     {
@@ -249,8 +273,8 @@ public class RubikScores
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public boolean isVerified()
+  public int getCountryID()
     {
-    return mNameIsVerified;
+    return mCountryID;
     }
   }
diff --git a/src/main/java/org/distorted/scores/RubikScoresDownloader.java b/src/main/java/org/distorted/scores/RubikScoresDownloader.java
index 1d81e012..3e8ed227 100644
--- a/src/main/java/org/distorted/scores/RubikScoresDownloader.java
+++ b/src/main/java/org/distorted/scores/RubikScoresDownloader.java
@@ -34,7 +34,7 @@ public class RubikScoresDownloader implements Runnable
   {
   public interface Receiver
     {
-    void receive(String[][][] country, String[][][] name, String[][][] time);
+    void receive(String[][][] country, String[][][] name, float[][][] time);
     void exception(String exception);
     }
 
@@ -91,7 +91,7 @@ public class RubikScoresDownloader implements Runnable
   private static String mScores = "";
   private static String[][][] mCountry = new String[mTotal][MAX_SCRAMBLE][MAX_PLACES];
   private static String[][][] mName    = new String[mTotal][MAX_SCRAMBLE][MAX_PLACES];
-  private static String[][][] mTime    = new String[mTotal][MAX_SCRAMBLE][MAX_PLACES];
+  private static  float[][][] mTime    = new  float[mTotal][MAX_SCRAMBLE][MAX_PLACES];
 
   private static int[][] mPlaces = new int[mTotal][MAX_SCRAMBLE];
 
@@ -138,7 +138,6 @@ public class RubikScoresDownloader implements Runnable
         String name    = row.substring(s3+1, s4);
         int time       = Integer.parseInt( row.substring(s4+1,s5) );
         String country = row.substring(s5+1, s6);
-        String realTime= String.valueOf(time/10.0f);
 
         if(level>=0 && level<MAX_SCRAMBLE && place>=0 && place<MAX_PLACES)
           {
@@ -149,7 +148,7 @@ public class RubikScoresDownloader implements Runnable
 
           mCountry[size][level][place] = country;
           mName   [size][level][place] = name;
-          mTime   [size][level][place] = realTime;
+          mTime   [size][level][place] = ((float)time)/10.0f;
           }
         }
       }
diff --git a/src/main/res/layout/dialog_scores_scramble_row.xml b/src/main/res/layout/dialog_scores_scramble_row.xml
index 88031674..5cb98bda 100644
--- a/src/main/res/layout/dialog_scores_scramble_row.xml
+++ b/src/main/res/layout/dialog_scores_scramble_row.xml
@@ -12,9 +12,9 @@
         android:layout_height="match_parent"
         android:layout_weight="1.5"
         android:textSize="20sp"
-        android:gravity="left"
+        android:gravity="start"
         android:background="@color/black"
-        android:paddingLeft="0dp"/>
+        android:paddingStart="0dp"/>
 
     <TextView
         android:id="@+id/scoresScrambleRowName"
@@ -22,7 +22,7 @@
         android:layout_height="match_parent"
         android:layout_weight="1"
         android:textSize="20sp"
-        android:gravity="left"
+        android:gravity="start"
         android:background="@color/black"
         />
 
@@ -32,8 +32,8 @@
         android:layout_height="match_parent"
         android:layout_weight="1.5"
         android:textSize="20sp"
-        android:gravity="right"
+        android:gravity="end"
         android:background="@color/black"
-        android:paddingRight="5dp"
+        android:paddingEnd="5dp"
         />
 </LinearLayout>
diff --git a/src/main/res/values/colors.xml b/src/main/res/values/colors.xml
index d264d8a0..3c3c974c 100644
--- a/src/main/res/values/colors.xml
+++ b/src/main/res/values/colors.xml
@@ -6,4 +6,5 @@
     <color name="red">#ffff0000</color>
     <color name="grey">#ff333333</color>
     <color name="black">#ff010101</color>
+    <color name="white">#ffffffff</color>
 </resources>
