commit 7aff6aa7351e039013053b770deeb7de5faaf138
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Wed Feb 19 16:43:17 2020 +0000

    Improvement for Downloader. Remove as much knowledge from it as possible.

diff --git a/src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java b/src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java
index b72c3f11..e4f11751 100644
--- a/src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java
+++ b/src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java
@@ -41,7 +41,7 @@ class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresD
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void receive(final int[][][] country, final String[][][] name, final String[][][] time)
+  public void receive(final String[][][] country, final String[][][] name, final String[][][] time)
     {
     prepareView();
 
@@ -74,7 +74,7 @@ class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresD
       });
     try
       {
-      Thread.sleep(200);
+      Thread.sleep(150);
       }
     catch( InterruptedException ie)
       {
@@ -84,7 +84,7 @@ class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresD
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private void addPage(final RubikDialogScoresView view, final int[][] country, final String[][] name, final String[][] time)
+  private void addPage(final RubikDialogScoresView view, final String[][] country, final String[][] name, final String[][] time)
     {
     for(int i=0; i<RubikStatePlay.MAX_SCRAMBLE; i++)
       {
@@ -101,7 +101,7 @@ class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresD
 
       try
         {
-        Thread.sleep(60);
+        Thread.sleep(50);
         }
       catch( InterruptedException ie)
         {
@@ -162,7 +162,7 @@ class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresD
     if( allCreated )
       {
       RubikScoresDownloader downloader = new RubikScoresDownloader();
-      downloader.download(this, mAct.getResources(), mAct.getPackageName());
+      downloader.download(this);
       }
 
     return mViews[position];
diff --git a/src/main/java/org/distorted/dialog/RubikDialogScoresView.java b/src/main/java/org/distorted/dialog/RubikDialogScoresView.java
index 2b6095a6..f372f4bc 100644
--- a/src/main/java/org/distorted/dialog/RubikDialogScoresView.java
+++ b/src/main/java/org/distorted/dialog/RubikDialogScoresView.java
@@ -20,6 +20,7 @@
 package org.distorted.dialog;
 
 import android.content.Context;
+import android.content.res.Resources;
 import android.support.v4.app.FragmentActivity;
 import android.util.AttributeSet;
 import android.view.View;
@@ -63,13 +64,40 @@ public class RubikDialogScoresView extends FrameLayout
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  void exception(final String exce)
+  LinearLayout createSection(FragmentActivity act, int scramble, final String[] country, final String[] name, final String[] time)
     {
-    TextView text = findViewById(R.id.downloading_text);
-    text.setText(exce);
+    LinearLayout level = (LinearLayout)inflate(act, R.layout.dialog_scores_scramble_title, null);
+    TextView text = level.findViewById(R.id.scoresScrambleTitle);
+    text.setText(act.getString(R.string.sc_placeholder,(scramble+1)));
+
+    Resources res = act.getResources();
+    String packageName = act.getPackageName();
+
+    for(int j = 0; j< RubikScoresDownloader.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 resID = res.getIdentifier( country[j], "drawable", packageName);
+
+        imgCoun.setImageResource(resID!=0 ? resID : R.drawable.unk);
+        textName.setText(name[j]);
+        textTime.setText(time[j]);
+
+        level.addView(row);
+        }
+      }
+
+    return level;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
+// needs to run on UI thread
 
   void prepareView(FragmentActivity act)
     {
@@ -81,6 +109,7 @@ public class RubikDialogScoresView extends FrameLayout
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
+// needs to run on UI thread
 
   void addSection(LinearLayout section)
     {
@@ -88,31 +117,11 @@ public class RubikDialogScoresView extends FrameLayout
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
+// needs to run on UI thread
 
-  LinearLayout createSection(FragmentActivity act, int scramble, final int[] country, final String[] name, final String[] time)
+  void exception(final String exce)
     {
-    LinearLayout level = (LinearLayout)inflate(act, R.layout.dialog_scores_scramble_title, null);
-    TextView text = level.findViewById(R.id.scoresScrambleTitle);
-    text.setText(act.getString(R.string.sc_placeholder,(scramble+1)));
-
-    for(int j = 0; j< RubikScoresDownloader.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);
-
-        imgCoun.setImageResource(country[j]);
-        textName.setText(name[j]);
-        textTime.setText(time[j]);
-
-        level.addView(row);
-        }
-      }
-
-    return level;
+    TextView text = findViewById(R.id.downloading_text);
+    text.setText(exce);
     }
   }
diff --git a/src/main/java/org/distorted/network/RubikScoresDownloader.java b/src/main/java/org/distorted/network/RubikScoresDownloader.java
index 0d9be293..45497111 100644
--- a/src/main/java/org/distorted/network/RubikScoresDownloader.java
+++ b/src/main/java/org/distorted/network/RubikScoresDownloader.java
@@ -19,16 +19,15 @@
 
 package org.distorted.network;
 
-import android.content.res.Resources;
-
 import java.io.InputStream;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.UnknownHostException;
 
 import org.distorted.magic.R;
-import org.distorted.object.RubikObject;
-import org.distorted.uistate.RubikStatePlay;
+
+import static org.distorted.object.RubikObject.LENGTH;
+import static org.distorted.uistate.RubikStatePlay.MAX_SCRAMBLE;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -36,7 +35,7 @@ public class RubikScoresDownloader implements Runnable
   {
   public interface Receiver
     {
-    void receive(int[][][] country, String[][][] name, String[][][] time);
+    void receive(String[][][] country, String[][][] name, String[][][] time);
     void exception(String exception);
     }
 
@@ -86,13 +85,11 @@ public class RubikScoresDownloader implements Runnable
   private static boolean mRunning = false;
   private static int mMode = IDLE;
   private static Receiver mReceiver;
-  private static Resources mResources;
-  private static String mPackageName;
 
   private static String mScores = "";
-  private static int[][][] mCountry = new int   [RubikObject.LENGTH][RubikStatePlay.MAX_SCRAMBLE][MAX_PLACES];
-  private static String[][][] mName = new String[RubikObject.LENGTH][RubikStatePlay.MAX_SCRAMBLE][MAX_PLACES];
-  private static String[][][] mTime = new String[RubikObject.LENGTH][RubikStatePlay.MAX_SCRAMBLE][MAX_PLACES];
+  private static String[][][] mCountry = new String[LENGTH][MAX_SCRAMBLE][MAX_PLACES];
+  private static String[][][] mName    = new String[LENGTH][MAX_SCRAMBLE][MAX_PLACES];
+  private static String[][][] mTime    = new String[LENGTH][MAX_SCRAMBLE][MAX_PLACES];
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -124,7 +121,7 @@ public class RubikScoresDownloader implements Runnable
       {
       int size = Integer.valueOf( row.substring(0,s1) );
 
-      if( size>=0 && size< RubikObject.LENGTH )
+      if( size>=0 && size<LENGTH )
         {
         int level      = Integer.valueOf( row.substring(s1+1,s2) );
         int place      = Integer.valueOf( row.substring(s2+1,s3) );
@@ -133,12 +130,11 @@ public class RubikScoresDownloader implements Runnable
         String country = row.substring(s5+1, s6);
         String realTime= String.valueOf(time/10.0f);
 
-        if(level>=0 && level<RubikStatePlay.MAX_SCRAMBLE && place>=0 && place<MAX_PLACES)
+        if(level>=0 && level<MAX_SCRAMBLE && place>=0 && place<MAX_PLACES)
           {
-          int resID = mResources.getIdentifier( country, "drawable", mPackageName);
-          mCountry[size][level][place] = resID!=0 ? resID: R.drawable.unk;
-          mName[size][level][place]    = name;
-          mTime[size][level][place]    = realTime;
+          mCountry[size][level][place] = country;
+          mName   [size][level][place] = name;
+          mTime   [size][level][place] = realTime;
           }
         }
       }
@@ -185,11 +181,13 @@ public class RubikScoresDownloader implements Runnable
 
   private boolean doDownload()
     {
-    String veri = "distored";
-    String name = URLencode(veri);
+    // TODO
     int numRuns = 1;
+    String veri = "distored";
+    // END
     String version = R.string.app_version+"d";
-    String message=URL+"/download.cgi?n="+name+"&r="+numRuns+"&e="+version;
+
+    String message=URL+"/download.cgi?n="+URLencode(veri)+"&r="+numRuns+"&e="+version;
 
     try
       {
@@ -285,13 +283,10 @@ public class RubikScoresDownloader implements Runnable
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  public void download(Receiver receiver, Resources resources, String packageName)
+  public void download(Receiver receiver)
     {
     mReceiver = receiver;
-    mResources= resources;
-    mPackageName = packageName;
     mMode = DOWNLOAD;
-
     Thread networkThrd = new Thread(this);
     networkThrd.start();
     }
