Project

General

Profile

Download (6.2 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / dialogs / RubikDialogUpdates.java @ f8a21f6b

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.dialogs;
11

    
12
import java.util.ArrayList;
13

    
14
import android.app.Dialog;
15
import android.graphics.Bitmap;
16
import android.util.TypedValue;
17
import android.view.View;
18
import android.widget.LinearLayout;
19
import android.widget.TextView;
20

    
21
import androidx.fragment.app.FragmentActivity;
22

    
23
import org.distorted.main.R;
24
import org.distorted.external.RubikNetwork;
25
import org.distorted.external.RubikUpdates;
26

    
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

    
29
public class RubikDialogUpdates extends RubikDialogAbstract implements RubikNetwork.IconReceiver, RubikNetwork.Updatee
30
  {
31
  private TextView mText;
32
  private LinearLayout mLayout;
33
  private int mMargin, mSize, mFontSize, mPadding;
34
  private ArrayList<RubikDialogUpdateView> mPanes;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
  public int getResource()      { return R.layout.dialog_updates; }
39
  public int getTitleResource() { return R.string.updates; }
40
  public boolean hasArgument()  { return false; }
41
  public int getPositive()      { return R.string.ok; }
42
  public int getNegative()      { return -1; }
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

    
46
  public void positiveAction()
47
    {
48

    
49
    }
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
  public void negativeAction()
54
    {
55

    
56
    }
57

    
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

    
60
  public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
61
    {
62
    if( mPanes==null ) mPanes = new ArrayList<>();
63

    
64
    int minH  = (int)(mHeight*0.25f);
65
    mMargin   = (int)(mHeight*0.01f);
66
    mSize     = (int)(mHeight*0.14f);
67
    mFontSize = (int)(mHeight*0.02f);
68
    mPadding  = (int)(mHeight*0.01f);
69

    
70
    mLayout= view.findViewById(R.id.updates_main_layout);
71
    mText  = view.findViewById(R.id.updates_message);
72
    mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
73
    mText.setText( act.getString(R.string.downloading) );
74

    
75
    mLayout.setMinimumHeight(minH);
76
    mText.setMinimumHeight(minH);
77
    view.setMinimumHeight(minH);
78

    
79
    RubikNetwork network = RubikNetwork.getInstance();
80
    network.signUpForUpdates(this);
81
    }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

    
85
  private void receiveUpdate(RubikUpdates updates, FragmentActivity act)
86
    {
87
    int numC = updates.getCompletedNumber();
88
    int numS = updates.getStartedNumber();
89

    
90
    if( numC+numS<=0 )
91
      {
92
      mText.setText(act.getString(R.string.no_updates));
93
      }
94
    else
95
      {
96
      int textH = (int)(mSize*0.27f);
97
      int buttH = (int)(mSize*0.35f);
98

    
99
      LinearLayout.LayoutParams pV = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, mSize );
100
      pV.setMargins(mMargin, mMargin, mMargin, 0);
101
      LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, textH );
102
      LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, buttH );
103

    
104
      mText.setVisibility(View.GONE);
105

    
106
      if( mLayout!=null )
107
        {
108
        for(int i=0; i<numC; i++)
109
          {
110
          RubikUpdates.UpdateInfo info = updates.getCompletedUpdate(i);
111
          RubikDialogUpdateView rubikView = new RubikDialogUpdateView();
112
          View pane = rubikView.createView(act,info,mFontSize,mPadding,pV,pT,pB);
113
          mLayout.addView(pane);
114
          mPanes.add(rubikView);
115
          }
116

    
117
        for(int i=0; i<numS; i++)
118
          {
119
          RubikUpdates.UpdateInfo info = updates.getStartedUpdate(i);
120
          RubikDialogUpdateView rubikView = new RubikDialogUpdateView();
121
          View pane = rubikView.createView(act,info,mFontSize,mPadding,pV,pT,pB);
122
          mLayout.addView(pane);
123
          mPanes.add(rubikView);
124
          }
125

    
126
        RubikNetwork network = RubikNetwork.getInstance();
127
        network.downloadIcons(act,this);
128
        }
129
      else
130
        {
131
        android.util.Log.e("D", "mainLayout NULL");
132
        }
133
      }
134
    }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  public void receiveUpdate(RubikUpdates updates)
139
    {
140
    FragmentActivity act = getActivity();
141

    
142
    if( act!=null )
143
      {
144
      act.runOnUiThread(new Runnable()
145
        {
146
        @Override
147
        public void run()
148
          {
149
          receiveUpdate(updates,act);
150
          }
151
        });
152
      }
153
    }
154

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

    
157
  public void errorUpdate()
158
    {
159
    FragmentActivity act = getActivity();
160
    if( act!=null ) mText.setText(act.getString(R.string.networkError));
161
    }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
  public void iconDownloaded(int ordinal, Bitmap icon, boolean downloaded)
166
    {
167
    FragmentActivity act = getActivity();
168

    
169
    if( act!=null )
170
      {
171
      act.runOnUiThread(new Runnable()
172
        {
173
        @Override
174
        public void run()
175
          {
176
          RubikDialogUpdateView view = mPanes.get(ordinal);
177
          if( view!=null ) view.setIcon(icon,downloaded);
178
          }
179
        });
180
      }
181
    }
182

    
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

    
185
  public static String getDialogTag()
186
    {
187
    return "DialogUpdates";
188
    }
189
  }
(25-25/25)