Project

General

Profile

« Previous | Next » 

Revision c99db493

Added by Leszek Koltunski almost 3 years ago

Progress downloading updates: dialog.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogUpdates.java
21 21

  
22 22
import android.app.Dialog;
23 23
import android.content.DialogInterface;
24
import android.content.pm.PackageInfo;
25
import android.content.pm.PackageManager;
26 24
import android.os.Bundle;
27
import android.text.method.LinkMovementMethod;
28
import android.text.method.MovementMethod;
29 25
import android.util.DisplayMetrics;
30 26
import android.util.TypedValue;
31 27
import android.view.LayoutInflater;
32
import android.view.View;
33 28
import android.view.Window;
34 29
import android.widget.Button;
35 30
import android.widget.TextView;
......
46 41

  
47 42
///////////////////////////////////////////////////////////////////////////////////////////////////
48 43

  
49
public class RubikDialogUpdates extends AppCompatDialogFragment
44
public class RubikDialogUpdates extends AppCompatDialogFragment implements RubikNetwork.Updatee
50 45
  {
51 46
  @NonNull
52 47
  @Override
......
100 95

  
101 96
///////////////////////////////////////////////////////////////////////////////////////////////////
102 97

  
103
  public void setUpdates(RubikUpdates updates)
98
  public void receiveUpdate(RubikUpdates updates)
104 99
    {
105 100

  
106 101
    }
107 102

  
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

  
105
  public void errorUpdate()
106
    {
107
    android.util.Log.e("D", "Dialog: Error receiving update");
108
    }
109

  
108 110
///////////////////////////////////////////////////////////////////////////////////////////////////
109 111

  
110 112
  public static String getDialogTag()
src/main/java/org/distorted/network/RubikUpdates.java
29 29
{
30 30
  public static class UpdateInfo
31 31
    {
32
    public final String mObjectName;
33
    public final int mMinorVersion;
34

  
35
    public UpdateInfo(String name,int version)
32
    public final String mObjectShortName;
33
    public final String mObjectLongName;
34
    public final String mDescription;
35
    public final int mObjectMinorVersion;
36
    public final int mExtrasMinorVersion;
37
    public final boolean mUpdateObject;
38
    public final boolean mUpdateExtras;
39

  
40
    public UpdateInfo(String shortName, String longName, String description, int objectMinor, int extrasMinor, boolean updateO, boolean updateE)
36 41
      {
37
      mObjectName  = name;
38
      mMinorVersion= version;
42
      mObjectShortName    = shortName;
43
      mObjectLongName     = longName;
44
      mDescription        = description;
45
      mObjectMinorVersion = objectMinor;
46
      mExtrasMinorVersion = extrasMinor;
47
      mUpdateObject       = updateO;
48
      mUpdateExtras       = updateE;
39 49
      }
40 50
    }
41 51

  
52
  private int mNumberOfUpdates;
42 53
  private String mUrl;
43
  private final ArrayList<UpdateInfo> mNewObjects;
44
  private final ArrayList<UpdateInfo> mNewExtras;
45
  private final ArrayList<UpdateInfo> mUpdObjects;
46
  private final ArrayList<UpdateInfo> mUpdExtras;
54
  private final ArrayList<UpdateInfo> mNew, mUpd;
47 55

  
48 56
///////////////////////////////////////////////////////////////////////////////////////////////////
49 57

  
50 58
  public RubikUpdates()
51 59
    {
52
    mNewObjects = new ArrayList<>();
53
    mNewExtras  = new ArrayList<>();
54
    mUpdObjects = new ArrayList<>();
55
    mUpdExtras  = new ArrayList<>();
60
    mNew = new ArrayList<>();
61
    mUpd = new ArrayList<>();
56 62
    }
57 63

  
58 64
///////////////////////////////////////////////////////////////////////////////////////////////////
......
60 66
  private String debug(ArrayList<UpdateInfo> list)
61 67
    {
62 68
    String ret = "";
63
    for( UpdateInfo info : list) ret += ("  "+info.mObjectName+" "+info.mMinorVersion);
69

  
70
    for( UpdateInfo info : list)
71
      {
72
      ret += (info.mObjectShortName+" "+info.mObjectLongName+" "+info.mDescription+" ");
73
      ret += (info.mObjectMinorVersion+" "+info.mExtrasMinorVersion+" "+info.mUpdateObject+" "+info.mUpdateExtras+" , ");
74
      }
75

  
64 76
    return ret;
65 77
    }
66 78

  
......
68 80

  
69 81
  private void parseLine(String[] elements)
70 82
    {
71
    String objName  = elements[0];
72
    String objMinor = elements[1];
73
    String extMinor = elements[2];
83
    boolean added = false;
84
    String shortName   = elements[0];
85
    String objMinor    = elements[1];
86
    String extMinor    = elements[2];
87
    String longName    = elements[3];
88
    String description = elements[4];
74 89
    int oMinor, eMinor;
75 90

  
76 91
    try { oMinor = Integer.parseInt(objMinor); }
......
78 93
    try { eMinor = Integer.parseInt(extMinor); }
79 94
    catch (NumberFormatException ex) { eMinor = -1; }
80 95

  
81
    int objOrdinal = RubikObjectList.getOrdinal(objName.toUpperCase());
82

  
83
    if( oMinor>=0 )
96
    if( oMinor>=0 && eMinor>=0 )
84 97
      {
85
      if( objOrdinal>=0 )
86
        {
87
        int localObjectMinor = RubikObjectList.getLocalObjectMinor(objOrdinal);
88
        if( localObjectMinor>=0 && localObjectMinor<oMinor )
89
          {
90
          UpdateInfo info = new UpdateInfo(objName,oMinor);
91
          mUpdObjects.add(info);
92
          }
93
        }
94
      else
95
        {
96
        UpdateInfo info = new UpdateInfo(objName,oMinor);
97
        mNewObjects.add(info);
98
        }
99
      }
98
      int objOrdinal = RubikObjectList.getOrdinal(shortName.toUpperCase());
100 99

  
101
    if( eMinor>=0 )
102
      {
103 100
      if( objOrdinal>=0 )
104 101
        {
102
        int localObjectMinor = RubikObjectList.getLocalObjectMinor(objOrdinal);
105 103
        int localExtrasMinor = RubikObjectList.getLocalExtrasMinor(objOrdinal);
106
        if( localExtrasMinor>=0 && localExtrasMinor<eMinor )
104
        boolean updateO = localObjectMinor<oMinor;
105
        boolean updateE = localExtrasMinor<eMinor;
106

  
107
        if( updateO || updateE )
107 108
          {
108
          UpdateInfo info = new UpdateInfo(objName,eMinor);
109
          mUpdExtras.add(info);
109
          UpdateInfo info = new UpdateInfo(shortName,longName,description,oMinor,eMinor,updateO,updateE);
110
          mUpd.add(info);
111
          added = true;
110 112
          }
111 113
        }
112 114
      else
113 115
        {
114
        UpdateInfo info = new UpdateInfo(objName,eMinor);
115
        mNewExtras.add(info);
116
        UpdateInfo info = new UpdateInfo(shortName,longName,description,oMinor,eMinor,true,true);
117
        mNew.add(info);
118
        added = true;
116 119
        }
117 120
      }
121

  
122
    if( added ) mNumberOfUpdates++;
118 123
    }
119 124

  
120 125
///////////////////////////////////////////////////////////////////////////////////////////////////
......
123 128
    {
124 129
    android.util.Log.e("D", updates);
125 130

  
126
    mNewObjects.clear();
127
    mNewExtras.clear();
128
    mUpdObjects.clear();
129
    mUpdExtras.clear();
131
    mNumberOfUpdates = 0;
132

  
133
    mNew.clear();
134
    mUpd.clear();
130 135

  
131 136
    String[] lines = updates.split("\n");
132 137
    int numLines = lines.length;
......
136 141
      mUrl = lines[0];
137 142
      for(int line=1; line<numLines; line++)
138 143
        {
139
        String[] elements = lines[line].split(" ");
144
        String[] elements = lines[line].split(",");
140 145
        if( elements.length>=3 ) parseLine(elements);
141 146
        }
142 147
      }
......
146 151

  
147 152
  public int getNumberOfUpdates()
148 153
    {
149
    int newO = mNewObjects.size();
150
    int newE = mNewExtras.size();
151
    int updO = mUpdObjects.size();
152
    int updE = mUpdExtras.size();
153

  
154
    return newO+newE+updO+updE;
154
    return mNumberOfUpdates;
155 155
    }
156 156

  
157 157
///////////////////////////////////////////////////////////////////////////////////////////////////
......
159 159
  public void showDebug()
160 160
    {
161 161
    android.util.Log.e("D", "url: "+mUrl);
162
    android.util.Log.e("D", "new objects: "+debug(mNewObjects));
163
    android.util.Log.e("D", "new extras : "+debug(mNewExtras ));
164
    android.util.Log.e("D", "upd objects: "+debug(mUpdObjects));
165
    android.util.Log.e("D", "upd extras : "+debug(mUpdExtras ));
162
    android.util.Log.e("D", "new objects: "+debug(mNew));
163
    android.util.Log.e("D", "upd objects: "+debug(mUpd));
166 164
    }
167 165
}
src/main/java/org/distorted/screens/RubikScreenPlay.java
351 351
        {
352 352
        if( mObjectPopup!=null ) mObjectPopup.dismiss();
353 353
        RubikDialogUpdates uDiag = new RubikDialogUpdates();
354
        uDiag.setUpdates(mUpdates);
355 354
        uDiag.show( act.getSupportFragmentManager(), RubikDialogUpdates.getDialogTag() );
356 355
        }
357 356
      });
......
706 705

  
707 706
  public void receiveUpdate(RubikUpdates updates)
708 707
    {
708
    updates.showDebug();
709

  
709 710
    mUpdates = updates;
710 711
    int num = mUpdates.getNumberOfUpdates();
711 712

  
......
721 722

  
722 723
  public void errorUpdate()
723 724
    {
724
    android.util.Log.e("D", "Error receiving update");
725
    android.util.Log.e("D", "Screen: Error receiving update");
725 726
    }
726 727
  }

Also available in: Unified diff