commit bc511ea5f56327b3a1b63fe2f3d5f3c2d0826ca1
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Mar 20 23:06:06 2020 +0000

    Add the 'New Record' dialog.

diff --git a/src/main/java/org/distorted/dialog/RubikDialogNewRecord.java b/src/main/java/org/distorted/dialog/RubikDialogNewRecord.java
new file mode 100644
index 00000000..57b53867
--- /dev/null
+++ b/src/main/java/org/distorted/dialog/RubikDialogNewRecord.java
@@ -0,0 +1,110 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2020 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Magic Cube.                                                              //
+//                                                                                               //
+// Magic Cube is free software: you can redistribute it and/or modify                            //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Magic Cube is distributed in the hope that it will be useful,                                 //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.dialog;
+
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v4.app.FragmentActivity;
+import android.support.v7.app.AlertDialog;
+import android.support.v7.app.AppCompatDialogFragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.TextView;
+
+import org.distorted.magic.R;
+import org.distorted.magic.RubikActivity;
+import org.distorted.scores.RubikScoresDownloader;
+import org.distorted.uistate.RubikState;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class RubikDialogNewRecord extends AppCompatDialogFragment
+  {
+  @Override
+  public void onStart()
+    {
+    super.onStart();
+
+    Window window = getDialog().getWindow();
+    window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
+                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
+    window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  @NonNull
+  @Override
+  public Dialog onCreateDialog(Bundle savedInstanceState)
+    {
+    FragmentActivity act = getActivity();
+    LayoutInflater inflater = act.getLayoutInflater();
+    AlertDialog.Builder builder = new AlertDialog.Builder(act);
+
+    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
+    tv.setText(R.string.new_record);
+    builder.setCustomTitle(tv);
+
+    builder.setCancelable(true);
+    builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
+      {
+      @Override
+      public void onClick(DialogInterface dialog, int which)
+        {
+        RubikScoresDownloader downloader = RubikScoresDownloader.getInstance();
+        downloader.submit();
+        RubikActivity act = (RubikActivity)getActivity();
+        RubikState.switchState(act,RubikState.PLAY);
+        }
+      });
+    builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener()
+      {
+      @Override
+      public void onClick(DialogInterface dialog, int which)
+        {
+        RubikActivity act = (RubikActivity)getActivity();
+        RubikState.switchState(act,RubikState.PLAY);
+        }
+      });
+
+    Bundle args = getArguments();
+    long time;
+
+    try
+      {
+      time = args.getLong("time");
+      }
+    catch(Exception e)
+      {
+      time = 0;
+      }
+
+    final View view = inflater.inflate(R.layout.dialog_new_record, null);
+    TextView text = view.findViewById(R.id.new_record_time);
+    text.setText(getString(R.string.ti_placeholder, (time/100)/10.0f));
+    builder.setView(view);
+
+    return builder.create();
+    }
+  }
diff --git a/src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java b/src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java
index b21744a3..12cc7796 100644
--- a/src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java
+++ b/src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java
@@ -167,7 +167,7 @@ class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresD
     if( allCreated )
       {
       RubikScores scores = RubikScores.getInstance();
-      RubikScoresDownloader downloader = new RubikScoresDownloader();
+      RubikScoresDownloader downloader = RubikScoresDownloader.getInstance();
       downloader.download( this, scores.getName(), mAct.getString(R.string.app_version), scores.getNumRuns() );
       }
 
diff --git a/src/main/java/org/distorted/magic/RubikRenderer.java b/src/main/java/org/distorted/magic/RubikRenderer.java
index 47d98416..b40d1f27 100644
--- a/src/main/java/org/distorted/magic/RubikRenderer.java
+++ b/src/main/java/org/distorted/magic/RubikRenderer.java
@@ -23,6 +23,7 @@ import android.content.SharedPreferences;
 import android.opengl.GLSurfaceView;
 import android.os.Bundle;
 
+import org.distorted.dialog.RubikDialogNewRecord;
 import org.distorted.dialog.RubikDialogSolved;
 import org.distorted.effect.BaseEffect;
 import org.distorted.library.effect.VertexEffectSink;
@@ -403,22 +404,18 @@ public class RubikRenderer implements GLSurfaceView.Renderer, EffectListener
              if( RubikState.getCurrentState()==RubikState.SOLV )
                {
                final RubikActivity act = (RubikActivity)mView.getContext();
+               Bundle bundle = new Bundle();
+               bundle.putLong("time", mNewRecord );
 
                if( mIsNewRecord )
                  {
-                 RubikDialogSolved dialog = new RubikDialogSolved();
-
-                 Bundle bundle = new Bundle();
-                 bundle.putLong("time", mNewRecord );
+                 RubikDialogNewRecord dialog = new RubikDialogNewRecord();
                  dialog.setArguments(bundle);
                  dialog.show( act.getSupportFragmentManager(), null);
                  }
                else
                  {
                  RubikDialogSolved dialog = new RubikDialogSolved();
-
-                 Bundle bundle = new Bundle();
-                 bundle.putLong("time", mNewRecord );
                  dialog.setArguments(bundle);
                  dialog.show( act.getSupportFragmentManager(), null);
                  }
diff --git a/src/main/java/org/distorted/scores/RubikScoresDownloader.java b/src/main/java/org/distorted/scores/RubikScoresDownloader.java
index a623b01d..2d040ebc 100644
--- a/src/main/java/org/distorted/scores/RubikScoresDownloader.java
+++ b/src/main/java/org/distorted/scores/RubikScoresDownloader.java
@@ -92,6 +92,7 @@ public class RubikScoresDownloader implements Runnable
   private static  float[][][] mTime    = new  float[mTotal][MAX_SCRAMBLE][MAX_PLACES];
 
   private static int[][] mPlaces = new int[mTotal][MAX_SCRAMBLE];
+  private static RubikScoresDownloader mThis;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -292,6 +293,13 @@ public class RubikScoresDownloader implements Runnable
       }
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private RubikScoresDownloader()
+    {
+
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // PUBLIC API
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -301,6 +309,18 @@ public class RubikScoresDownloader implements Runnable
     mRunning = false;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static RubikScoresDownloader getInstance()
+    {
+    if( mThis==null )
+      {
+      mThis = new RubikScoresDownloader();
+      }
+
+    return mThis;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public void download(Receiver receiver, String userName, String version, int numRuns)
@@ -314,4 +334,13 @@ public class RubikScoresDownloader implements Runnable
     Thread networkThrd = new Thread(this);
     networkThrd.start();
     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public void submit()
+    {
+    mMode = SUBMIT;
+
+    android.util.Log.e("downloader", "submitting!");
+    }
 }
\ No newline at end of file
diff --git a/src/main/res/layout/dialog_new_record.xml b/src/main/res/layout/dialog_new_record.xml
new file mode 100644
index 00000000..4fe71f2a
--- /dev/null
+++ b/src/main/res/layout/dialog_new_record.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:gravity="center_horizontal"
+    android:orientation="vertical">
+
+    <LinearLayout
+        android:layout_width="fill_parent"
+        android:layout_height="fill_parent"
+        android:gravity="center|fill_horizontal"
+        android:layout_marginLeft="10dp"
+        android:layout_marginRight="10dp"
+        android:layout_marginTop="0dp"
+        android:background="@color/grey"
+        android:orientation="vertical">
+
+        <TextView
+            android:id="@+id/new_record_time"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:gravity="center"
+            android:textSize="24sp"
+            android:layout_marginTop="10dp"
+            android:layout_marginLeft="10dp"
+            android:layout_marginRight="10dp"
+            android:layout_marginBottom="10dp"/>
+
+         <TextView
+            android:id="@+id/new_record_submit"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:gravity="center"
+            android:textSize="24sp"
+            android:layout_marginTop="10dp"
+            android:layout_marginLeft="10dp"
+            android:layout_marginRight="10dp"
+            android:layout_marginBottom="10dp"
+            android:text="@string/new_record_submit"/>/>
+
+    </LinearLayout>
+</LinearLayout>
\ No newline at end of file
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 3a1a9bf6..a6062d85 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -10,9 +10,13 @@
     <string name="scores">High Scores</string>
     <string name="about">About</string>
     <string name="solved">Solved</string>
+    <string name="new_record">New Record</string>
+    <string name="new_record_submit">Do you want to submit it to High Scores?</string>
     <string name="back">Back</string>
     <string name="save">SAVE</string>
     <string name="ok">OK</string>
+    <string name="yes">YES</string>
+    <string name="no">NO</string>
     <string name="ready">Ready?</string>
     <string name="sizechange_effect">Size Change Effect</string>
     <string name="solve_effect">Solve Effect</string>
