Project

General

Profile

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

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

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.content.DialogInterface;
16
import android.graphics.Bitmap;
17
import android.util.TypedValue;
18
import android.view.View;
19
import android.widget.Button;
20
import android.widget.LinearLayout;
21
import android.widget.TextView;
22

    
23
import androidx.appcompat.app.AlertDialog;
24
import androidx.fragment.app.FragmentActivity;
25

    
26
import org.distorted.main.R;
27
import org.distorted.external.RubikNetwork;
28
import org.distorted.external.RubikUpdates;
29

    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

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

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

    
41
  public int getResource()
42
    {
43
    return R.layout.dialog_updates;
44
    }
45

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

    
48
  public int getTitleResource()
49
    {
50
    return R.string.updates;
51
    }
52

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

    
55
  public boolean hasArgument()
56
    {
57
    return false;
58
    }
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
  public void setPositive(AlertDialog.Builder builder)
63
    {
64
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
65
      {
66
      @Override
67
      public void onClick(DialogInterface dialog, int which)
68
        {
69

    
70
        }
71
      });
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

    
76
  public void setNegative(AlertDialog.Builder builder)
77
    {
78

    
79
    }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

    
83
  public void onShowDialog(DialogInterface dialog, float size)
84
    {
85
    Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
86
    btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
87
    }
88

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

    
91
  public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size)
92
    {
93
    if( mPanes==null ) mPanes = new ArrayList<>();
94

    
95
    int minH  = (int)(mHeight*0.25f);
96
    mMargin   = (int)(mHeight*0.01f);
97
    mSize     = (int)(mHeight*0.14f);
98
    mFontSize = (int)(mHeight*0.02f);
99
    mPadding  = (int)(mHeight*0.01f);
100

    
101
    mLayout= view.findViewById(R.id.updates_main_layout);
102
    mText  = view.findViewById(R.id.updates_message);
103
    mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
104
    mText.setText( act.getString(R.string.downloading) );
105

    
106
    mLayout.setMinimumHeight(minH);
107
    mText.setMinimumHeight(minH);
108
    view.setMinimumHeight(minH);
109

    
110
    RubikNetwork network = RubikNetwork.getInstance();
111
    network.signUpForUpdates(this);
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

    
116
  private void receiveUpdate(RubikUpdates updates, FragmentActivity act)
117
    {
118
    int numC = updates.getCompletedNumber();
119
    int numS = updates.getStartedNumber();
120

    
121
    if( numC+numS<=0 )
122
      {
123
      mText.setText(act.getString(R.string.no_updates));
124
      }
125
    else
126
      {
127
      int textH = (int)(mSize*0.27f);
128
      int buttH = (int)(mSize*0.35f);
129

    
130
      LinearLayout.LayoutParams pV = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, mSize );
131
      pV.setMargins(mMargin, mMargin, mMargin, 0);
132
      LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, textH );
133
      LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, buttH );
134

    
135
      mText.setVisibility(View.GONE);
136

    
137
      if( mLayout!=null )
138
        {
139
        for(int i=0; i<numC; i++)
140
          {
141
          RubikUpdates.UpdateInfo info = updates.getCompletedUpdate(i);
142
          RubikDialogUpdateView rubikView = new RubikDialogUpdateView();
143
          View pane = rubikView.createView(act,info,mFontSize,mPadding,pV,pT,pB);
144
          mLayout.addView(pane);
145
          mPanes.add(rubikView);
146
          }
147

    
148
        for(int i=0; i<numS; i++)
149
          {
150
          RubikUpdates.UpdateInfo info = updates.getStartedUpdate(i);
151
          RubikDialogUpdateView rubikView = new RubikDialogUpdateView();
152
          View pane = rubikView.createView(act,info,mFontSize,mPadding,pV,pT,pB);
153
          mLayout.addView(pane);
154
          mPanes.add(rubikView);
155
          }
156

    
157
        RubikNetwork network = RubikNetwork.getInstance();
158
        network.downloadIcons(act,this);
159
        }
160
      else
161
        {
162
        android.util.Log.e("D", "mainLayout NULL");
163
        }
164
      }
165
    }
166

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168

    
169
  public void receiveUpdate(RubikUpdates updates)
170
    {
171
    FragmentActivity act = getActivity();
172

    
173
android.util.Log.e("D", "receiveUpdate1");
174

    
175
    if( act!=null )
176
      {
177
      act.runOnUiThread(new Runnable()
178
        {
179
        @Override
180
        public void run()
181
          {
182
          receiveUpdate(updates,act);
183
          }
184
        });
185
      }
186
    }
187

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189

    
190
  public void errorUpdate()
191
    {
192
    FragmentActivity act = getActivity();
193
    if( act!=null ) mText.setText(act.getString(R.string.networkError));
194
    }
195

    
196
///////////////////////////////////////////////////////////////////////////////////////////////////
197

    
198
  public void iconDownloaded(int ordinal, Bitmap icon, boolean downloaded)
199
    {
200
    FragmentActivity act = getActivity();
201

    
202
    if( act!=null )
203
      {
204
      act.runOnUiThread(new Runnable()
205
        {
206
        @Override
207
        public void run()
208
          {
209
          RubikDialogUpdateView view = mPanes.get(ordinal);
210
          if( view!=null ) view.setIcon(icon,downloaded);
211
          }
212
        });
213
      }
214
    }
215

    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

    
218
  public static String getDialogTag()
219
    {
220
    return "DialogUpdates";
221
    }
222
  }
(25-25/25)