Project

General

Profile

« Previous | Next » 

Revision 9c39179e

Added by Leszek Koltunski over 2 years ago

Downloading updates: dialog progress.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogUpdates.java
20 20
package org.distorted.dialogs;
21 21

  
22 22
import android.app.Dialog;
23
import android.content.Context;
23 24
import android.content.DialogInterface;
24 25
import android.os.Bundle;
25 26
import android.util.DisplayMetrics;
......
27 28
import android.view.LayoutInflater;
28 29
import android.view.View;
29 30
import android.view.Window;
31
import android.view.WindowManager;
30 32
import android.widget.Button;
33
import android.widget.LinearLayout;
34
import android.widget.ScrollView;
31 35
import android.widget.TextView;
32 36

  
33 37
import androidx.annotation.NonNull;
......
44 48

  
45 49
public class RubikDialogUpdates extends AppCompatDialogFragment implements RubikNetwork.Updatee
46 50
  {
47
  private View createView(LayoutInflater inflater)
51
  private TextView mText;
52
  private ScrollView mScroll;
53
  private LinearLayout mLayout;
54

  
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

  
57
  private View createView(FragmentActivity act, LayoutInflater inflater, float size)
48 58
    {
49 59
    final View view = inflater.inflate(R.layout.dialog_updates, null);
50 60

  
51
    TextView text = view.findViewById(R.id.about_version);
52
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, 50);
53
    text.setText("ggggg ruyujk j k");
61
    mLayout= view.findViewById(R.id.updates_main_layout);
62
    mScroll= view.findViewById(R.id.updates_scroll);
63
    mText  = view.findViewById(R.id.updates_message);
64
    mText.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
65
    mText.setText( act.getString(R.string.downloading) );
54 66

  
55 67
    return view;
56 68
    }
......
70 82
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
71 83
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
72 84

  
73
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
74
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
75
    tv.setText(R.string.updates);
76
    builder.setCustomTitle(tv);
85
    TextView title = (TextView) inflater.inflate(R.layout.dialog_title, null);
86
    title.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
87
    title.setText(R.string.updates);
88
    builder.setCustomTitle(title);
77 89

  
78 90
    builder.setCancelable(true);
79 91
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
......
85 97
        }
86 98
      });
87 99

  
88
    View view = createView(inflater);
100
    View view = createView(act,inflater,okSize);
89 101
    builder.setView(view);
90 102

  
91 103
    Dialog dialog = builder.create();
......
107 119
        }
108 120
      });
109 121

  
122
    return dialog;
123
    }
124

  
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

  
127
  @Override
128
  public void onResume()
129
    {
130
    super.onResume();
131

  
110 132
    RubikNetwork network = RubikNetwork.getInstance();
111 133
    network.signUpForUpdates(this);
112 134

  
113
    return dialog;
135
    Window window = getDialog().getWindow();
136
    Context context = getContext();
137

  
138
    if( window!=null && context!=null )
139
      {
140
      DisplayMetrics metrics = context.getResources().getDisplayMetrics();
141
      final float height= metrics.heightPixels;
142

  
143
      WindowManager.LayoutParams params = window.getAttributes();
144
      params.width = WindowManager.LayoutParams.WRAP_CONTENT;
145
      params.height = (int)(0.75f*height);
146
      window.setAttributes(params);
147

  
148
      int textHeight = (int)(0.8f*params.height);
149
      mText.setHeight(textHeight);
150
      }
114 151
    }
115 152

  
116 153
///////////////////////////////////////////////////////////////////////////////////////////////////
117 154

  
118 155
  public void receiveUpdate(RubikUpdates updates)
119 156
    {
157
    FragmentActivity act = getActivity();
158
    int numN = updates.getNewNumber();
159
    int numU = updates.getUpdNumber();
160
    int num = numN+numU;
120 161

  
162
    if( num<=0 )
163
      {
164
      mScroll.setVerticalScrollBarEnabled(false);
165
      mText.setText(act.getString(R.string.no_updates));
166
      }
167
    else
168
      {
169
      mText.setVisibility(View.GONE);
170

  
171
      if( mLayout!=null )
172
        {
173
        for(int i=0; i<numN; i++)
174
          {
175
          RubikUpdates.UpdateInfo info = updates.getNewUpdate(i);
176
          RubikDialogUpdateView rubikView = new RubikDialogUpdateView();
177
          View pane = rubikView.createView(act,info,true);
178
          mLayout.addView(pane);
179
          }
180
        for(int i=0; i<numU; i++)
181
          {
182
          RubikUpdates.UpdateInfo info = updates.getUpdUpdate(i);
183
          RubikDialogUpdateView rubikView = new RubikDialogUpdateView();
184
          View pane = rubikView.createView(act,info,false);
185
          mLayout.addView(pane);
186
          }
187
        }
188
      else
189
        {
190
        android.util.Log.e("D", "mainLayout NULL");
191
        }
192
      }
121 193
    }
122 194

  
123 195
///////////////////////////////////////////////////////////////////////////////////////////////////
124 196

  
125 197
  public void errorUpdate()
126 198
    {
127
    android.util.Log.e("D", "Dialog: Error receiving update");
199
    mScroll.setVerticalScrollBarEnabled(false);
200
    mText.setText("Network error");
128 201
    }
129 202

  
130 203
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff