Project

General

Profile

« Previous | Next » 

Revision 63dd19c4

Added by Leszek Koltunski almost 3 years ago

Progress downloading updates.

View differences:

src/main/java/org/distorted/main/RubikRenderer.java
136 136

  
137 137
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
138 138

  
139
      if( !BuildConfig.DEBUG && !mDebugSent )
139
      if( /*!BuildConfig.DEBUG &&*/ !mDebugSent )
140 140
        {
141 141
        mDebugSent= true;
142 142
        RubikNetwork network = RubikNetwork.getInstance();
src/main/java/org/distorted/network/RubikNetwork.java
52 52
    void error(String error);
53 53
    }
54 54

  
55
  public interface Updatee
56
    {
57
    void receiveUpdate(RubikUpdates update);
58
    void errorUpdate();
59
    }
60

  
55 61
  public static final int MAX_PLACES = 10;
56 62

  
57 63
  private static final int DOWNLOAD   = 0;
......
65 71
  private static final int REND_POWER = 2;
66 72
  private static final int REND_OTHER = 3;
67 73

  
74
  private static final int DEBUG_NOT_YET = 0;
75
  private static final int DEBUG_RUNNING = 1;
76
  private static final int DEBUG_SUCCESS = 2;
77
  private static final int DEBUG_FAILURE = 3;
78

  
68 79
  private final String[] hex = {
69 80
    "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07",
70 81
    "%08", "%09", "%0a", "%0b", "%0c", "%0d", "%0e", "%0f",
......
110 121
  private static boolean mRunning = false;
111 122
  private static int mMode = IDLE;
112 123
  private static Receiver mReceiver;
124
  private static Updatee mUpdatee;
113 125
  private static String mVersion;
114
  private static String mDebug;
126
  private static String mSuspicious;
115 127
  private static int mNumObjects;
116 128
  private static RubikUpdates mUpdates;
129
  private static int mDebugState;
117 130

  
118 131
///////////////////////////////////////////////////////////////////////////////////////////////////
119 132

  
......
396 409

  
397 410
      String updates = answer.toString();
398 411
      mUpdates.parse(updates);
412
      if( mUpdatee!=null ) mUpdatee.receiveUpdate(mUpdates);
413
      mDebugState = DEBUG_SUCCESS;
399 414
      }
400 415
    catch( final Exception e )
401 416
      {
402
      // ignore
417
      if( mUpdatee!=null ) mUpdatee.errorUpdate();
418
      mDebugState = DEBUG_FAILURE;
403 419
      }
404 420
    }
405 421

  
......
486 502
    {
487 503
    RubikScores scores = RubikScores.getInstance();
488 504
    int deviceID= scores.getDeviceID();
489
    String debug = URLencode(mDebug);
505
    String suspicious = URLencode(mSuspicious);
490 506

  
491 507
    String url="https://distorted.org/magic/cgi-bin/suspicious.cgi";
492
    url += "?i="+deviceID+"&d="+debug;
508
    url += "?i="+deviceID+"&d="+suspicious;
493 509

  
494 510
    return url;
495 511
    }
......
699 715

  
700 716
  public void debug(AppCompatActivity act)
701 717
    {
718
    mDebugState = DEBUG_RUNNING;
702 719
    start(null, act, DEBUG);
703 720
    }
704 721

  
705 722
///////////////////////////////////////////////////////////////////////////////////////////////////
706 723

  
707
  public void suspicious(AppCompatActivity act, String debug)
724
  public void suspicious(AppCompatActivity act, String suspicious)
708 725
    {
709
    mDebug = debug;
726
    mSuspicious = suspicious;
710 727
    start(null, act, SUSPICIOUS);
711 728
    }
729

  
730
///////////////////////////////////////////////////////////////////////////////////////////////////
731
// Yes it can happen that the second Updatee registers before we sent an update to the first one
732
// and, as a result, the update never gets sent to the first one. This is not a problem (now, when
733
// there are only two updatees - the RubikStatePlay and the UpdateDialog)
734
//
735
// Yes, there is also a remote possibility that the two threads executing this function and executing
736
// the sendDebug() get swapped exactly in unlucky moment and the update never gets to the updatee.
737
// We don't care about such remote possibility, then the app simply would signal that there are no
738
// updates available.
739

  
740
  public void signUpForUpdates(Updatee updatee)
741
    {
742
         if( mDebugState==DEBUG_SUCCESS ) updatee.receiveUpdate(mUpdates);
743
    else if( mDebugState==DEBUG_FAILURE ) updatee.errorUpdate();
744
    else mUpdatee = updatee;
745
    }
712 746
}
src/main/java/org/distorted/network/RubikUpdates.java
140 140
        if( elements.length>=3 ) parseLine(elements);
141 141
        }
142 142
      }
143
    }
144

  
145
///////////////////////////////////////////////////////////////////////////////////////////////////
143 146

  
147
  public void showDebug()
148
    {
144 149
    android.util.Log.e("D", "url: "+mUrl);
145 150
    android.util.Log.e("D", "new objects: "+debug(mNewObjects));
146 151
    android.util.Log.e("D", "new extras : "+debug(mNewExtras ));
147 152
    android.util.Log.e("D", "upd objects: "+debug(mUpdObjects));
148 153
    android.util.Log.e("D", "upd extras : "+debug(mUpdExtras ));
149 154
    }
150

  
151 155
}
src/main/java/org/distorted/screens/RubikScreenPlay.java
35 35
import android.widget.LinearLayout;
36 36
import android.widget.PopupWindow;
37 37

  
38
import org.distorted.network.RubikNetwork;
39
import org.distorted.network.RubikUpdates;
38 40
import org.distorted.objectlib.main.ObjectControl;
39 41

  
40 42
import org.distorted.main.R;
......
53 55

  
54 56
///////////////////////////////////////////////////////////////////////////////////////////////////
55 57

  
56
public class RubikScreenPlay extends RubikScreenBase
58
public class RubikScreenPlay extends RubikScreenBase implements RubikNetwork.Updatee
57 59
  {
58 60
  public static final int NUM_COLUMNS  = 5;
59 61
  public static final int LEVELS_SHOWN = 10;
......
229 231
    mObjectSize = (int)(cubeWidth + 2*margin + 0.5f);
230 232
    mMaxRowCount = (int)((height-1.8f*mUpperBarHeight)/mObjectSize);
231 233

  
234
    RubikNetwork network = RubikNetwork.getInstance();
235
    network.signUpForUpdates(this);
236

  
232 237
    LinearLayout view = (LinearLayout)inflate( act, R.layout.popup_object, null);
233 238
    GridLayout objectGrid = view.findViewById(R.id.objectGrid);
234 239

  
......
676 681
    {
677 682
    return mShouldReactToEndOfScrambling;
678 683
    }
684

  
685
///////////////////////////////////////////////////////////////////////////////////////////////////
686

  
687
  public void receiveUpdate(RubikUpdates updates)
688
    {
689
    updates.showDebug();
690
    }
691

  
692
///////////////////////////////////////////////////////////////////////////////////////////////////
693

  
694
  public void errorUpdate()
695
    {
696
    android.util.Log.e("D", "Error receiving update");
697
    }
679 698
  }

Also available in: Unified diff