Project

General

Profile

« Previous | Next » 

Revision b8b38548

Added by Leszek Koltunski over 4 years ago

Downloading High Scores

View differences:

src/main/java/org/distorted/magic/RubikScoresDownloader.java
21 21

  
22 22
///////////////////////////////////////////////////////////////////////////////////////////////////
23 23

  
24
class RubikScoresDownloader extends Thread
24
class RubikScoresDownloader implements Runnable
25 25
  {
26
  interface Receiver
27
    {
28
    void receive(String scores);
29
    }
30

  
31
  private static final int DOWNLOAD   = 0;
32
  private static final int SUBMIT     = 1;
33
  private static final int IDLE       = 2;
34

  
35
  private static final String URL  ="http://koltunski.pl/rubik/cgi-bin";
36

  
37
  private static boolean mRunning = false;
38
  private static Thread mNetworkThrd = null;
39
  private static int mMode = IDLE;
40
  private static Receiver mReceiver;
41

  
26 42
  private static String mScores = "";
27 43

  
28 44
///////////////////////////////////////////////////////////////////////////////////////////////////
29 45

  
30 46
  static void onPause()
31 47
    {
48
    mRunning = false;
32 49
    mScores = "";
33 50
    }
34 51

  
35 52
///////////////////////////////////////////////////////////////////////////////////////////////////
36 53

  
37
  static boolean gottaDownload()
54
  private boolean gottaDownload()
38 55
    {
39
    return mScores.length() == 0;
56
    return ((mScores.length()==0) && !mRunning);
40 57
    }
41 58

  
42 59
///////////////////////////////////////////////////////////////////////////////////////////////////
43 60

  
44
  static void download(RubikScores.ScoresReceiver receiver)
61
  void abortNetworkTransaction()
45 62
    {
46
    if( gottaDownload() )
47
      {
48
      doDownload();
49
      }
63
    mRunning = false;
64
    }
50 65

  
51
    receiver.receive(mScores);
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

  
68
  void download(Receiver receiver)
69
    {
70
    mReceiver = receiver;
71
    mMode = DOWNLOAD;
72
    mNetworkThrd = new Thread(this);
73
    mNetworkThrd.start();
52 74
    }
53 75

  
54 76
///////////////////////////////////////////////////////////////////////////////////////////////////
55 77

  
56
  private static void doDownload()
78
  public void run()
57 79
    {
80
    try
81
      {
82
      if( gottaDownload() )
83
        {
84
        mRunning = true;
85

  
86
        Thread.sleep(2000);
87

  
58 88
mScores =
59 89

  
60 90
"0 0 0 INEED7X7X7 1 rus" + "\n" +
......
77 107
"0 3 2 MDR04 9 ita" + "\n" +
78 108
"0 3 3 ROBERT04 9 unk" + "\n" +
79 109
"0 3 4 DULCE 10 mex" + "\n" +
80
"0 4 0 THISNAVIS 11 usa" + "\n" +
81
"0 4 1 Tilly 12 uk" + "\n" +
82
"0 4 2 OHIOCUBER 14 usa" + "\n" +
83
"0 4 3 GRV 15 mex" + "\n" +
84
"0 4 4 INEED7X7X7 16 rus" + "\n" +
85
"0 5 0 KADE 6 unk" + "\n" +
86
"0 5 1 FREDRIK 11 den" + "\n" +
87
"0 5 2 THISNAVIS 11 usa" + "\n" +
88
"0 5 3 Tilly 14 uk" + "\n" +
89
"0 5 4 A9QSKPJJDM 16 bra" + "\n" +
90
"0 6 0 LoiraH 1 bra" + "\n" +
91
"0 6 1 KAN 5 unk" + "\n" +
92
"0 6 2 Tilly 7 uk" + "\n" +
93
"0 6 3 FRITZ 17 ita" + "\n" +
94
"0 6 4 JONIWWE 17 ina" + "\n" +
95
"0 7 0 SULTANOUU 30 rus" + "\n" +
96
"0 7 1 LOLO766 33 fra" + "\n" +
97
"0 7 2 ElyKho 37 mly" + "\n" +
98
"0 7 3 FREDRIK 37 den" + "\n" +
99
"0 7 4 ILXOM707 37 uzb" + "\n" +
100
"0 8 0 pardal 16 bra" + "\n" +
101
"0 8 1 ILXOM707 32 uzb" + "\n" +
102
"0 8 2 LOLO766 43 fra" + "\n" +
103
"0 8 3 NIKODZ 44 geo" + "\n" +
104
"0 8 4 SHAFFAF 48 ind" + "\n" +
105 110
"1 0 0 INEED7X7X7 1 rus" + "\n" +
106 111
"1 0 1 Tilly 1 uk" + "\n" +
107 112
"1 0 2 REBECCA 1 fra" + "\n" +
......
122 127
"1 3 2 NIKITOS 21 rus" + "\n" +
123 128
"1 3 3 PYCUK1707 21 rus" + "\n" +
124 129
"1 3 4 KEDAR 22 ind" + "\n" +
125
"1 4 0 Kinkz 7 ned" + "\n" +
126
"1 4 1 UTEK 14 ina" + "\n" +
127
"1 4 2 SJNT 23 ind" + "\n" +
128
"1 4 3 ABCDEF89 24 vie" + "\n" +
129
"1 4 4 SIJOYSIJ 27 ind" + "\n" +
130
"1 5 0 SIJOYSIJ 40 ind" + "\n" +
131
"1 5 1 UTEK 46 ina" + "\n" +
132
"1 5 2 SJNT 54 ind" + "\n" +
133
"1 5 3 FREDRIK 59 den" + "\n" +
134
"1 5 4 YANY 64 arg" + "\n" +
135
"1 6 0 UTEK 26 ina" + "\n" +
136
"1 6 1 FLAVINHA 57 bra" + "\n" +
137
"1 6 2 MILKMAN 57 fin" + "\n" +
138
"1 6 3 MARIOEAGLE 59 ita" + "\n" +
139
"1 6 4 LOLO766 85 fra" + "\n" +
140
"1 7 0 UTEK 45 ina" + "\n" +
141
"1 7 1 SEUA 157 vie" + "\n" +
142
"1 7 2 FREDRIK 201 den" + "\n" +
143
"1 7 3 ARMIN 205 rus" + "\n" +
144
"1 7 4 ILXOM7 215 uzb" + "\n" +
145
"1 8 0 SJNT 73 ind" + "\n" +
146
"1 8 1 MILKOMANN 219 fin" + "\n" +
147
"1 8 2 DEMONAIRE 288 uk" + "\n" +
148
"1 8 3 SIJ 311 ind" + "\n" +
149
"1 8 4 SIJOYSIJ 316 ind" + "\n" +
150 130
"2 0 0 INEED7X7X7 1 rus" + "\n" +
151 131
"2 0 1 HOMER0815 1 ger" + "\n" +
152 132
"2 0 2 EIP 1 usa" + "\n" +
......
167 147
"2 3 2 NONAME 24 fin" + "\n" +
168 148
"2 3 3 ABB0 26 ind" + "\n" +
169 149
"2 3 4 NOYS 27 mex" + "\n" +
170
"2 4 0 NIKITOS 37 rus" + "\n" +
171
"2 4 1 INEED7X7X7 45 rus" + "\n" +
172
"2 4 2 ILXOM7 50 uzb" + "\n" +
173
"2 4 3 NOYS 52 mex" + "\n" +
174
"2 4 4 MikeK 57 ger" + "\n" +
175
"2 5 0 NIKITOS 62 rus" + "\n" +
176
"2 5 1 LOLO766 70 fra" + "\n" +
177
"2 5 2 HUBBUB 87 swe" + "\n" +
178
"2 5 3 TETRAULT 90 usa" + "\n" +
179
"2 5 4 NOYS 115 mex" + "\n" +
180
"2 6 0 LOLO766 128 fra" + "\n" +
181
"2 6 1 KAN 193 unk" + "\n" +
182
"2 6 2 MEECMEEC 195 uk" + "\n" +
183
"2 6 3 HUBBUB 197 swe" + "\n" +
184
"2 6 4 PTOR 238 kyr" + "\n" +
185
"2 7 0 CHRISTA 268 za" + "\n" +
186
"2 7 1 MUZAFFER 288 tur" + "\n" +
187
"2 7 2 INEED7X7X7 323 rus" + "\n" +
188
"2 7 3 HECTOR58 360 mex" + "\n" +
189
"2 7 4 CABC 391 rus" + "\n" +
190
"2 8 0 CABC 245 rus" + "\n" +
191
"2 8 1 SIRWALTR 289 arg" + "\n" +
192
"2 8 2 NAMIT 558 ind" + "\n" +
193
"2 8 3 HDH580702 602 mex" + "\n" +
194
"2 8 4 HECTOR58 959 mex" + "\n" +
195 150
"3 0 0 JARO 1 ger" + "\n" +
196 151
"3 0 1 INEED7X7X7 1 rus" + "\n" +
197 152
"3 0 2 MDR04 1 ita" + "\n" +
......
211 166
"3 3 1 THISNAVIS 23 usa" + "\n" +
212 167
"3 3 2 INEED7X7X7 24 rus" + "\n" +
213 168
"3 3 3 RUBIK123 30 lit" + "\n" +
214
"3 3 4 SKY16 31 usa" + "\n" +
215
"3 4 0 NIKITOS 37 rus" + "\n" +
216
"3 4 1 6969696 43 usa" + "\n" +
217
"3 4 2 ALFREDOPVV 45 bra" + "\n" +
218
"3 4 3 HIEU 48 vie" + "\n" +
219
"3 4 4 INEED7X7X7 52 rus" + "\n" +
220
"3 5 0 ILXOM707 63 uzb" + "\n" +
221
"3 5 1 PHOENIX 77 fin" + "\n" +
222
"3 5 2 Nargiza 82 unk" + "\n" +
223
"3 5 3 NIKITOS 83 rus" + "\n" +
224
"3 5 4 ILXOM7 83 uzb" + "\n" +
225
"3 6 0 ILXOM7 81 uzb" + "\n" +
226
"3 6 1 ILXOM707 140 uzb" + "\n" +
227
"3 6 2 INEED7X7X7 143 rus" + "\n" +
228
"3 6 3 KAN 143 unk" + "\n" +
229
"3 6 4 RUBIK123 177 lit" + "\n" +
230
"3 7 0 ILXOM707 238 uzb" + "\n" +
231
"3 7 1 LOLO766 283 fra" + "\n" +
232
"3 7 2 INEED7X7X7 293 rus" + "\n" +
233
"3 7 3 RUBIK123 313 lit" + "\n" +
234
"3 7 4 SIRWALTR 343 arg" + "\n" +
235
"3 8 0 CABC 312 rus" + "\n" +
236
"3 8 1 HDH580702 411 mex" + "\n" +
237
"3 8 2 RUBIK123 558 lit" + "\n" +
238
"3 8 3 MUZAFFER 568 tur" + "\n" +
239
"3 8 4 NOYS 649 mex";
169
"3 3 4 SKY16 31 usa";
170
      }
171
    }
172
  catch( Exception e )
173
    {
174
    android.util.Log.e("downloader", "Exception downloading records: "+e.getMessage() );
240 175
    }
176

  
177
  mRunning = false;
178
  mReceiver.receive(mScores);
241 179
  }
180
}

Also available in: Unified diff