Commit 2bbfadef8465716a10a7bc4ae60054fbed62dcdf
1 parent
34c4b7cd1c
Exists in
master
BUG修改
Showing
15 changed files
with
313 additions
and
11 deletions
Show diff stats
app/build.gradle
| ... | ... | @@ -25,8 +25,8 @@ android { |
| 25 | 25 | applicationId "com.hjx.parent" |
| 26 | 26 | minSdk 24 |
| 27 | 27 | targetSdk 32 |
| 28 | - versionCode 1002 | |
| 29 | - versionName "1.0.0.2" | |
| 28 | + versionCode 1003 | |
| 29 | + versionName "1.0.0.3" | |
| 30 | 30 | |
| 31 | 31 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" |
| 32 | 32 | } | ... | ... |
app/src/main/AndroidManifest.xml
| ... | ... | @@ -24,7 +24,11 @@ |
| 24 | 24 | <uses-permission |
| 25 | 25 | android:name="android.permission.WRITE_EXTERNAL_STORAGE" |
| 26 | 26 | tools:ignore="ScopedStorage" /> |
| 27 | + <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> | |
| 28 | + <uses-permission android:name="android.permission.GET_PACKAGE_SIZE" /> | |
| 27 | 29 | |
| 30 | + <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" | |
| 31 | + tools:ignore="ScopedStorage" /> | |
| 28 | 32 | <application |
| 29 | 33 | android:name=".App" |
| 30 | 34 | android:allowBackup="true" | ... | ... |
app/src/main/java/com/hjx/parent/ErrorBookActivity.java
| ... | ... | @@ -288,6 +288,12 @@ public class ErrorBookActivity extends BaseActivity<ActivityErrorBookBinding> { |
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | + @Override | |
| 292 | + protected void onResume() { | |
| 293 | + super.onResume(); | |
| 294 | + getError(getResources().getStringArray(R.array.filter_subject)[subject]); | |
| 295 | + } | |
| 296 | + | |
| 291 | 297 | public class HandlerCallBack implements IHandlerCallBack<ImageInfo> { |
| 292 | 298 | private String TAG = "---ImagePicker---"; |
| 293 | 299 | List<ImageInfo> photoList = new ArrayList<>(); | ... | ... |
app/src/main/java/com/hjx/parent/ErrorDetailActivity.java
| 1 | 1 | package com.hjx.parent; |
| 2 | 2 | |
| 3 | +import android.content.Intent; | |
| 4 | +import android.graphics.Color; | |
| 3 | 5 | import android.os.Bundle; |
| 6 | +import android.os.Handler; | |
| 4 | 7 | import android.text.TextUtils; |
| 8 | +import android.view.MotionEvent; | |
| 5 | 9 | import android.view.View; |
| 6 | 10 | import android.webkit.WebSettings; |
| 7 | 11 | import android.widget.AdapterView; |
| ... | ... | @@ -37,6 +41,7 @@ public class ErrorDetailActivity extends BaseActivity<ActivityErrorDetailBinding |
| 37 | 41 | |
| 38 | 42 | public void loadError() { |
| 39 | 43 | if (bean.getBean() != null) { |
| 44 | + binding.tvTip.setVisibility(View.GONE); | |
| 40 | 45 | ErrorDetailBean errorDetailBean = bean.getBean(); |
| 41 | 46 | if (TextUtils.isEmpty(errorDetailBean.getContent())) { |
| 42 | 47 | binding.llOrigin.setVisibility(View.GONE); |
| ... | ... | @@ -56,7 +61,14 @@ public class ErrorDetailActivity extends BaseActivity<ActivityErrorDetailBinding |
| 56 | 61 | binding.webContent.loadDataWithBaseURL(linkCss, body, "text/html", "UTF-8", null); |
| 57 | 62 | binding.webContent.setVisibility(View.VISIBLE); |
| 58 | 63 | binding.llOrigin.setVisibility(View.VISIBLE); |
| 64 | + binding.webContent.setOnTouchListener(new View.OnTouchListener() { | |
| 65 | + @Override | |
| 66 | + public boolean onTouch(View v, MotionEvent event) { | |
| 67 | + return true; | |
| 68 | + } | |
| 69 | + }); | |
| 59 | 70 | } |
| 71 | + | |
| 60 | 72 | if (TextUtils.isEmpty(errorDetailBean.getMethod())) { |
| 61 | 73 | binding.llAnalyse.setVisibility(View.GONE); |
| 62 | 74 | } else { |
| ... | ... | @@ -64,6 +76,7 @@ public class ErrorDetailActivity extends BaseActivity<ActivityErrorDetailBinding |
| 64 | 76 | String linkCss = "<link rel=\"stylesheet\" href=\"file:///android_asset/style.css\" type=\"text/css\">"; |
| 65 | 77 | String body = "<html><header>" + linkCss + "</header>" + errorDetailBean.getMethod() + "</body></html>"; |
| 66 | 78 | binding.webAnalyse.loadDataWithBaseURL(linkCss, body, "text/html", "UTF-8", null); |
| 79 | + binding.webAnalyse.setBackgroundColor(Color.parseColor("#F5F5F5")); | |
| 67 | 80 | } |
| 68 | 81 | if (TextUtils.isEmpty(errorDetailBean.getDisplayAnswer())) { |
| 69 | 82 | binding.llAnswer.setVisibility(View.GONE); |
| ... | ... | @@ -72,6 +85,7 @@ public class ErrorDetailActivity extends BaseActivity<ActivityErrorDetailBinding |
| 72 | 85 | String linkCss = "<link rel=\"stylesheet\" href=\"file:///android_asset/style.css\" type=\"text/css\">"; |
| 73 | 86 | String body = "<html><header>" + linkCss + "</header>" + errorDetailBean.getDisplayAnswer() + "</body></html>"; |
| 74 | 87 | binding.webAnswer.loadDataWithBaseURL(linkCss, body, "text/html", "UTF-8", null); |
| 88 | + binding.webAnswer.setBackgroundColor(Color.parseColor("#F5F5F5")); | |
| 75 | 89 | } |
| 76 | 90 | if (errorDetailBean.getPoints().size() > 0) { |
| 77 | 91 | List<String> points = new ArrayList<>(); |
| ... | ... | @@ -89,6 +103,7 @@ public class ErrorDetailActivity extends BaseActivity<ActivityErrorDetailBinding |
| 89 | 103 | binding.llPoints.setVisibility(View.GONE); |
| 90 | 104 | } |
| 91 | 105 | } else { |
| 106 | + binding.tvTip.setVisibility(View.VISIBLE); | |
| 92 | 107 | binding.llAnalyse.setVisibility(View.GONE); |
| 93 | 108 | binding.llAnswer.setVisibility(View.GONE); |
| 94 | 109 | binding.llOrigin.setVisibility(View.GONE); |
| ... | ... | @@ -105,7 +120,13 @@ public class ErrorDetailActivity extends BaseActivity<ActivityErrorDetailBinding |
| 105 | 120 | binding.typeRadio.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { |
| 106 | 121 | @Override |
| 107 | 122 | public void onCheckedChanged(RadioGroup group, int checkedId) { |
| 108 | - saveError(); | |
| 123 | + new Handler().postDelayed(new Runnable() { | |
| 124 | + @Override | |
| 125 | + public void run() { | |
| 126 | + saveError(); | |
| 127 | + } | |
| 128 | + }, 1000); | |
| 129 | + | |
| 109 | 130 | } |
| 110 | 131 | }); |
| 111 | 132 | binding.spinnerReason.setSelection(bean.getReason()); |
| ... | ... | @@ -154,7 +175,7 @@ public class ErrorDetailActivity extends BaseActivity<ActivityErrorDetailBinding |
| 154 | 175 | bean.setDone(done == 1); |
| 155 | 176 | Map<String, Object> map = new HashMap<>(); |
| 156 | 177 | map.put("bookId", bean.getId()); |
| 157 | - map.put("controlFlag", done == 1 ? 0 : 1); | |
| 178 | + map.put("controlFlag", done); | |
| 158 | 179 | map.put("errorReason", binding.spinnerReason.getSelectedItemPosition()); |
| 159 | 180 | NetWorks.editError(map, new Observer<ResponseResult>() { |
| 160 | 181 | @Override |
| ... | ... | @@ -164,7 +185,7 @@ public class ErrorDetailActivity extends BaseActivity<ActivityErrorDetailBinding |
| 164 | 185 | |
| 165 | 186 | @Override |
| 166 | 187 | public void onNext(ResponseResult responseResult) { |
| 167 | - | |
| 188 | + responseResult.toString(); | |
| 168 | 189 | } |
| 169 | 190 | |
| 170 | 191 | @Override | ... | ... |
app/src/main/java/com/hjx/parent/ErrorListActivity.java
| ... | ... | @@ -131,6 +131,8 @@ public class ErrorListActivity extends BaseActivity<ActivityErrorListBinding> im |
| 131 | 131 | return ActivityErrorListBinding.inflate(getLayoutInflater()); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | + | |
| 135 | + | |
| 134 | 136 | @Override |
| 135 | 137 | public void onClick(View v) { |
| 136 | 138 | switch (v.getId()) { |
| ... | ... | @@ -202,10 +204,10 @@ public class ErrorListActivity extends BaseActivity<ActivityErrorListBinding> im |
| 202 | 204 | }); |
| 203 | 205 | break; |
| 204 | 206 | case R.id.tv_add: |
| 205 | - if (!XXPermissions.isGranted(context, Permission.CAMERA, Permission.WRITE_EXTERNAL_STORAGE)) { | |
| 207 | + if (!XXPermissions.isGranted(context, Permission.CAMERA, Permission.MANAGE_EXTERNAL_STORAGE)) { | |
| 206 | 208 | XXPermissions.with(context) |
| 207 | 209 | // 申请多个权限 |
| 208 | - .permission(Permission.CAMERA) | |
| 210 | + .permission(Permission.CAMERA, Permission.MANAGE_EXTERNAL_STORAGE) | |
| 209 | 211 | .request(new OnPermissionCallback() { |
| 210 | 212 | @Override |
| 211 | 213 | public void onGranted(List<String> permissions, boolean all) { | ... | ... |
app/src/main/java/com/hjx/parent/MainActivity.java
| ... | ... | @@ -2,26 +2,44 @@ package com.hjx.parent; |
| 2 | 2 | |
| 3 | 3 | import androidx.appcompat.app.AppCompatActivity; |
| 4 | 4 | import androidx.constraintlayout.widget.ConstraintLayout; |
| 5 | +import androidx.core.content.FileProvider; | |
| 5 | 6 | |
| 7 | +import android.app.Dialog; | |
| 8 | +import android.app.ProgressDialog; | |
| 9 | +import android.content.Intent; | |
| 6 | 10 | import android.graphics.Color; |
| 11 | +import android.net.Uri; | |
| 12 | +import android.os.Build; | |
| 7 | 13 | import android.os.Bundle; |
| 14 | +import android.os.Looper; | |
| 8 | 15 | import android.widget.ImageView; |
| 9 | 16 | import android.widget.TextView; |
| 17 | +import android.widget.Toast; | |
| 10 | 18 | |
| 11 | 19 | import com.google.gson.JsonObject; |
| 20 | +import com.hjq.permissions.OnPermissionCallback; | |
| 21 | +import com.hjq.permissions.Permission; | |
| 22 | +import com.hjq.permissions.XXPermissions; | |
| 23 | +import com.hjx.parent.dialog.TipDialog; | |
| 12 | 24 | import com.hjx.parent.fragment.HomeFragment; |
| 13 | 25 | import com.hjx.parent.fragment.MeFragment; |
| 14 | 26 | import com.prws.common.base.BaseActivity; |
| 15 | 27 | import com.prws.common.base.BasePresenter; |
| 16 | 28 | import com.prws.common.bean.GradeAndSubject; |
| 17 | 29 | import com.prws.common.bean.ResponseResult; |
| 30 | +import com.prws.common.bean.UpdateBean; | |
| 18 | 31 | import com.prws.common.net.NetWorks; |
| 32 | +import com.prws.common.utils.DownloadUtil; | |
| 19 | 33 | import com.prws.common.utils.SharedPreferencesUtil; |
| 20 | 34 | |
| 35 | +import java.io.File; | |
| 21 | 36 | import java.util.List; |
| 22 | 37 | |
| 23 | 38 | import io.reactivex.Observer; |
| 24 | 39 | import io.reactivex.disposables.Disposable; |
| 40 | +import retrofit2.Call; | |
| 41 | +import retrofit2.Callback; | |
| 42 | +import retrofit2.Response; | |
| 25 | 43 | |
| 26 | 44 | public class MainActivity extends BaseActivity { |
| 27 | 45 | |
| ... | ... | @@ -101,6 +119,7 @@ public class MainActivity extends BaseActivity { |
| 101 | 119 | |
| 102 | 120 | } |
| 103 | 121 | }); |
| 122 | + checkUpdate(); | |
| 104 | 123 | } |
| 105 | 124 | |
| 106 | 125 | public HomeFragment getHomeFragment() { |
| ... | ... | @@ -144,4 +163,111 @@ public class MainActivity extends BaseActivity { |
| 144 | 163 | public void onNetChanged(int netWorkState) { |
| 145 | 164 | |
| 146 | 165 | } |
| 166 | + | |
| 167 | + public void downloadApk(String url, int versionCode) { | |
| 168 | + String filepath = getExternalFilesDir("apk").getPath() + "/" + versionCode + ".apk"; | |
| 169 | + ProgressDialog dialog = new ProgressDialog(this); | |
| 170 | + dialog.setTitle("版本更新"); | |
| 171 | + dialog.setMessage("正在下载新版本,请稍后"); | |
| 172 | + dialog.setMax(100); | |
| 173 | + dialog.setProgress(0); | |
| 174 | + dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); | |
| 175 | + dialog.show(); | |
| 176 | + DownloadUtil.download(url, filepath, new DownloadUtil.OnDownloadListener() { | |
| 177 | + @Override | |
| 178 | + public void onDownloadSuccess(String path) { | |
| 179 | + dialog.setProgress(100); | |
| 180 | + dialog.dismiss(); | |
| 181 | + installApk(filepath); | |
| 182 | + } | |
| 183 | + | |
| 184 | + @Override | |
| 185 | + public void onDownloading(int progress) { | |
| 186 | + dialog.setProgress(progress); | |
| 187 | + } | |
| 188 | + | |
| 189 | + @Override | |
| 190 | + public void onDownloadFailed(String msg) { | |
| 191 | + dialog.dismiss(); | |
| 192 | + Looper.prepare(); | |
| 193 | + showToast("下载失败。"); | |
| 194 | + Looper.loop(); | |
| 195 | + } | |
| 196 | + }); | |
| 197 | + } | |
| 198 | + | |
| 199 | + public void installApk(String path) { | |
| 200 | + //开启扫码界面 | |
| 201 | + Intent intentUpdate = new Intent("android.intent.action.VIEW"); | |
| 202 | + intentUpdate.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
| 203 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { //对Android N及以上的版本做判断 | |
| 204 | + Uri apkUriN = FileProvider.getUriForFile(MainActivity.this, | |
| 205 | + getApplicationContext().getPackageName() + ".fileprovider", new File(path)); | |
| 206 | + intentUpdate.addCategory("android.intent.category.DEFAULT"); | |
| 207 | + intentUpdate.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //天假Flag 表示我们需要什么权限 | |
| 208 | + intentUpdate.setDataAndType(apkUriN, "application/vnd.android.package-archive"); | |
| 209 | + } else { | |
| 210 | + Uri apkUri = Uri.fromFile(new File(path)); | |
| 211 | + intentUpdate.setDataAndType(apkUri, "application/vnd.android.package-archive"); | |
| 212 | + } | |
| 213 | + startActivity(intentUpdate); | |
| 214 | + } | |
| 215 | + | |
| 216 | + public void checkUpdate() { | |
| 217 | + NetWorks.checkUpdate(BuildConfig.VERSION_CODE, BuildConfig.APPLICATION_ID, new Callback<ResponseResult<UpdateBean>>() { | |
| 218 | + @Override | |
| 219 | + public void onResponse(Call<ResponseResult<UpdateBean>> call, Response<ResponseResult<UpdateBean>> response) { | |
| 220 | + if (response.body() != null && response.body().getCode() == 200) { | |
| 221 | + if (response.body().getData() != null) { | |
| 222 | + String msg = response.body().getData().getExplain(); | |
| 223 | + String url = response.body().getData().getUrl(); | |
| 224 | + int versionCode = response.body().getData().getVersion(); | |
| 225 | + showUpdateDialog(msg, url, versionCode); | |
| 226 | + } | |
| 227 | + } | |
| 228 | + } | |
| 229 | + | |
| 230 | + @Override | |
| 231 | + public void onFailure(Call<ResponseResult<UpdateBean>> call, Throwable t) { | |
| 232 | + } | |
| 233 | + }); | |
| 234 | + } | |
| 235 | + | |
| 236 | + public void showUpdateDialog(String msg, String url, int versionCode) { | |
| 237 | + TipDialog tipDialog = new TipDialog(this, "检测到新版本", msg, "升级", "取消", new TipDialog.TipDialogInterface() { | |
| 238 | + @Override | |
| 239 | + public void onConfirm(Dialog dialog) { | |
| 240 | + if (!XXPermissions.isGranted(MainActivity.this, Permission.MANAGE_EXTERNAL_STORAGE)) { | |
| 241 | + XXPermissions.with(MainActivity.this) | |
| 242 | + // 申请多个权限 | |
| 243 | + .permission(Permission.MANAGE_EXTERNAL_STORAGE) | |
| 244 | + .request(new OnPermissionCallback() { | |
| 245 | + @Override | |
| 246 | + public void onGranted(List<String> permissions, boolean all) { | |
| 247 | + if (all) { | |
| 248 | + //开启扫码界面 | |
| 249 | + downloadApk(url, versionCode); | |
| 250 | + } else { | |
| 251 | + Toast.makeText(MainActivity.this, "需要权限", Toast.LENGTH_SHORT).show(); | |
| 252 | + } | |
| 253 | + } | |
| 254 | + | |
| 255 | + @Override | |
| 256 | + public void onDenied(List<String> permissions, boolean never) { | |
| 257 | + XXPermissions.startPermissionActivity(MainActivity.this, permissions); | |
| 258 | + } | |
| 259 | + }); | |
| 260 | + } else { | |
| 261 | + downloadApk(url, versionCode); | |
| 262 | + } | |
| 263 | + | |
| 264 | + } | |
| 265 | + | |
| 266 | + @Override | |
| 267 | + public void onCancel(Dialog dialog) { | |
| 268 | + dialog.dismiss(); | |
| 269 | + } | |
| 270 | + }); | |
| 271 | + tipDialog.show(); | |
| 272 | + } | |
| 147 | 273 | } |
| 148 | 274 | \ No newline at end of file | ... | ... |
app/src/main/java/com/hjx/parent/adapter/ErrorAdapter.java
| ... | ... | @@ -5,6 +5,7 @@ import android.content.Intent; |
| 5 | 5 | import android.graphics.drawable.Drawable; |
| 6 | 6 | import android.text.TextUtils; |
| 7 | 7 | import android.view.LayoutInflater; |
| 8 | +import android.view.MotionEvent; | |
| 8 | 9 | import android.view.View; |
| 9 | 10 | import android.view.ViewGroup; |
| 10 | 11 | import android.webkit.WebSettings; |
| ... | ... | @@ -136,6 +137,23 @@ public class ErrorAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> |
| 136 | 137 | // settings.setSupportZoom(false);//设定支持缩放 |
| 137 | 138 | holder.binding.webview.loadDataWithBaseURL(linkCss, body, "text/html", "UTF-8", null); |
| 138 | 139 | holder.binding.webview.setVisibility(View.VISIBLE); |
| 140 | + holder.binding.webview.setOnTouchListener(new View.OnTouchListener() { | |
| 141 | + @Override | |
| 142 | + public boolean onTouch(View v, MotionEvent event) { | |
| 143 | + if (event.getAction() == MotionEvent.ACTION_UP) { | |
| 144 | + if (edit) { | |
| 145 | + list.get(position).setCheck(!topicBean.isCheck()); | |
| 146 | + notifyItemChanged(position); | |
| 147 | + checkInterface.onErrorCheck(); | |
| 148 | + } else { | |
| 149 | + Intent intent = new Intent(context, ErrorDetailActivity.class); | |
| 150 | + intent.putExtra("errorBean", topicBean); | |
| 151 | + context.startActivity(intent); | |
| 152 | + } | |
| 153 | + } | |
| 154 | + return true; | |
| 155 | + } | |
| 156 | + }); | |
| 139 | 157 | if (bean.getPoints().size() > 0) { |
| 140 | 158 | String topic = context.getString(R.string.topic_start); |
| 141 | 159 | topic += ":"; | ... | ... |
app/src/main/res/layout/activity_error_detail.xml
| ... | ... | @@ -142,6 +142,7 @@ |
| 142 | 142 | |
| 143 | 143 | <WebView |
| 144 | 144 | android:id="@+id/web_analyse" |
| 145 | + android:background="#F5F5F5" | |
| 145 | 146 | android:layout_width="wrap_content" |
| 146 | 147 | android:layout_height="wrap_content" |
| 147 | 148 | android:layout_margin="10dp" /> |
| ... | ... | @@ -176,6 +177,7 @@ |
| 176 | 177 | android:id="@+id/web_answer" |
| 177 | 178 | android:layout_width="wrap_content" |
| 178 | 179 | android:layout_height="wrap_content" |
| 180 | + android:background="#F5F5F5" | |
| 179 | 181 | android:layout_margin="10dp" /> |
| 180 | 182 | </LinearLayout> |
| 181 | 183 | </LinearLayout> |
| ... | ... | @@ -300,6 +302,17 @@ |
| 300 | 302 | android:textSize="14sp" /> |
| 301 | 303 | </RadioGroup> |
| 302 | 304 | </LinearLayout> |
| 305 | + | |
| 306 | + <TextView | |
| 307 | + android:id="@+id/tv_tip" | |
| 308 | + android:layout_width="wrap_content" | |
| 309 | + android:layout_height="wrap_content" | |
| 310 | + android:layout_gravity="center_horizontal" | |
| 311 | + android:layout_marginTop="50dp" | |
| 312 | + android:gravity="center_horizontal" | |
| 313 | + android:text="家长端暂不支持错题匹配和知识点分析\n请在学生平板端完成操作" | |
| 314 | + android:textColor="#999999" | |
| 315 | + android:visibility="gone" /> | |
| 303 | 316 | </LinearLayout> |
| 304 | 317 | </ScrollView> |
| 305 | 318 | </LinearLayout> |
| 306 | 319 | \ No newline at end of file | ... | ... |
app/src/main/res/values/styles.xml
| ... | ... | @@ -50,8 +50,8 @@ |
| 50 | 50 | <item name="divider">@color/border</item> |
| 51 | 51 | <item name="android:scrollbars">none</item> |
| 52 | 52 | <item name="android:dividerHeight">1dp</item> |
| 53 | + <item name="android:textSize">15sp</item> | |
| 53 | 54 | </style> |
| 54 | 55 | |
| 55 | 56 | |
| 56 | - | |
| 57 | 57 | </resources> |
| 58 | 58 | \ No newline at end of file | ... | ... |
build.gradle
libs/common/src/main/java/com/prws/common/base/BaseActivity.java
| ... | ... | @@ -121,6 +121,7 @@ public abstract class BaseActivity<P extends BasePresenter, CONTRACT> extends Ap |
| 121 | 121 | p.bindView(this); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | + | |
| 124 | 125 | public void showDialog(String title, String message, String confirm, String cancel, DialogInterface.OnClickListener cancelListener, DialogInterface.OnClickListener listener) { |
| 125 | 126 | AlertDialog.Builder builder = new AlertDialog.Builder(this, android.R.style.Theme_DeviceDefault_Light_Dialog_Alert); |
| 126 | 127 | builder.setTitle(title); | ... | ... |
libs/common/src/main/java/com/prws/common/bean/UpdateBean.java
| ... | ... | @@ -0,0 +1,31 @@ |
| 1 | +package com.prws.common.bean; | |
| 2 | + | |
| 3 | +public class UpdateBean { | |
| 4 | + private String explain; | |
| 5 | + private Integer version; | |
| 6 | + private String url; | |
| 7 | + | |
| 8 | + public void setExplain(String explain) { | |
| 9 | + this.explain = explain; | |
| 10 | + } | |
| 11 | + | |
| 12 | + public void setVersion(Integer version) { | |
| 13 | + this.version = version; | |
| 14 | + } | |
| 15 | + | |
| 16 | + public void setUrl(String url) { | |
| 17 | + this.url = url; | |
| 18 | + } | |
| 19 | + | |
| 20 | + public String getExplain() { | |
| 21 | + return explain; | |
| 22 | + } | |
| 23 | + | |
| 24 | + public Integer getVersion() { | |
| 25 | + return version; | |
| 26 | + } | |
| 27 | + | |
| 28 | + public String getUrl() { | |
| 29 | + return url; | |
| 30 | + } | |
| 31 | +} | ... | ... |
libs/common/src/main/java/com/prws/common/net/NetWorks.java
| ... | ... | @@ -12,6 +12,7 @@ import com.prws.common.bean.ResponseResult; |
| 12 | 12 | import com.prws.common.bean.ScheduleBean; |
| 13 | 13 | import com.prws.common.bean.Teacher; |
| 14 | 14 | import com.prws.common.bean.TopicBean; |
| 15 | +import com.prws.common.bean.UpdateBean; | |
| 15 | 16 | import com.prws.common.utils.SharedPreferencesUtil; |
| 16 | 17 | |
| 17 | 18 | import java.io.File; |
| ... | ... | @@ -168,6 +169,10 @@ public class NetWorks extends RetrofitUtils { |
| 168 | 169 | |
| 169 | 170 | @POST("api/v1/question/editErrorBook") |
| 170 | 171 | Observable<ResponseResult> editError(@Header("Authorization") String Authorization, @Body Map<String, Object> map); |
| 172 | + | |
| 173 | + @GET("api/v1/resource/checkUpdate") | |
| 174 | + Call<ResponseResult<UpdateBean>> checkUpdate(@Query("version") int version, @Query("packageName") String packageName, @Query("type") int type); | |
| 175 | + | |
| 171 | 176 | } |
| 172 | 177 | |
| 173 | 178 | |
| ... | ... | @@ -180,6 +185,10 @@ public class NetWorks extends RetrofitUtils { |
| 180 | 185 | } |
| 181 | 186 | |
| 182 | 187 | |
| 188 | + public static void checkUpdate(int code, String packageName, Callback<ResponseResult<UpdateBean>> callback) { | |
| 189 | + service_url.checkUpdate(code, packageName, 0).enqueue(callback); | |
| 190 | + } | |
| 191 | + | |
| 183 | 192 | public static void addError(String path, Map<String, String> param, Observer<ResponseResult> observer) { |
| 184 | 193 | File file = new File(path); |
| 185 | 194 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/jpg"), file); | ... | ... |
libs/common/src/main/java/com/prws/common/utils/DownloadUtil.java
| ... | ... | @@ -0,0 +1,71 @@ |
| 1 | +package com.prws.common.utils; | |
| 2 | + | |
| 3 | +import java.io.File; | |
| 4 | +import java.io.FileOutputStream; | |
| 5 | +import java.io.IOException; | |
| 6 | +import java.io.InputStream; | |
| 7 | + | |
| 8 | +import okhttp3.Call; | |
| 9 | +import okhttp3.Callback; | |
| 10 | +import okhttp3.OkHttpClient; | |
| 11 | +import okhttp3.Request; | |
| 12 | +import okhttp3.Response; | |
| 13 | + | |
| 14 | +public class DownloadUtil { | |
| 15 | + | |
| 16 | + public static void download(final String url, final String saveFile, final OnDownloadListener listener) { | |
| 17 | + Request request = new Request.Builder().url(url).build(); | |
| 18 | + new OkHttpClient().newCall(request).enqueue(new Callback() { | |
| 19 | + @Override | |
| 20 | + public void onFailure(Call call, IOException e) { | |
| 21 | + listener.onDownloadFailed(e.getMessage()); | |
| 22 | + } | |
| 23 | + | |
| 24 | + @Override | |
| 25 | + public void onResponse(Call call, Response response) throws IOException { | |
| 26 | + InputStream is = null; | |
| 27 | + byte[] buf = new byte[2048]; | |
| 28 | + int len; | |
| 29 | + FileOutputStream fos = null; | |
| 30 | + try { | |
| 31 | + is = response.body().byteStream(); | |
| 32 | + long total = response.body().contentLength(); | |
| 33 | + File file = new File(saveFile); | |
| 34 | + fos = new FileOutputStream(file); | |
| 35 | + long sum = 0; | |
| 36 | + while ((len = is.read(buf)) != -1) { | |
| 37 | + fos.write(buf, 0, len); | |
| 38 | + sum += len; | |
| 39 | + int progress = (int) (sum * 1.0f / total * 100); | |
| 40 | + listener.onDownloading(progress); | |
| 41 | + } | |
| 42 | + fos.flush(); | |
| 43 | + listener.onDownloadSuccess(file.getAbsolutePath()); | |
| 44 | + } catch (Exception e) { | |
| 45 | + listener.onDownloadFailed(e.getMessage()); | |
| 46 | + } finally { | |
| 47 | + try { | |
| 48 | + if (is != null) | |
| 49 | + is.close(); | |
| 50 | + } catch (IOException e) { | |
| 51 | + e.printStackTrace(); | |
| 52 | + } | |
| 53 | + try { | |
| 54 | + if (fos != null) | |
| 55 | + fos.close(); | |
| 56 | + } catch (IOException e) { | |
| 57 | + e.printStackTrace(); | |
| 58 | + } | |
| 59 | + } | |
| 60 | + } | |
| 61 | + }); | |
| 62 | + } | |
| 63 | + | |
| 64 | + public interface OnDownloadListener { | |
| 65 | + void onDownloadSuccess(String path); | |
| 66 | + | |
| 67 | + void onDownloading(int progress); | |
| 68 | + | |
| 69 | + void onDownloadFailed(String msg); | |
| 70 | + } | |
| 71 | +} | ... | ... |
libs/common/src/main/java/com/prws/common/widget/MarkSizeView.java
| ... | ... | @@ -172,7 +172,7 @@ public class MarkSizeView extends View { |
| 172 | 172 | |
| 173 | 173 | //draw button |
| 174 | 174 | if (isValid && isUp) { |
| 175 | - if (markedArea.width() >= CommonUtil.dpToPx(context, 40) && markedArea.height() >= CommonUtil.dpToPx(context, 40)) { | |
| 175 | + if (markedArea.width() >= CommonUtil.dpToPx(context, 30) && markedArea.height() >= CommonUtil.dpToPx(context, 30)) { | |
| 176 | 176 | canvas.drawBitmap(confirmBitmap, null, confirmArea, mBitPaint); |
| 177 | 177 | canvas.drawBitmap(cancelBitmap, null, cancelArea, mBitPaint); |
| 178 | 178 | } |
| ... | ... | @@ -255,7 +255,7 @@ public class MarkSizeView extends View { |
| 255 | 255 | break; |
| 256 | 256 | case MotionEvent.ACTION_UP: |
| 257 | 257 | isUp = true; |
| 258 | - if (markedArea.width() >= CommonUtil.dpToPx(context, 40) && markedArea.height() >= CommonUtil.dpToPx(context, 40)) { | |
| 258 | + if (markedArea.width() >= CommonUtil.dpToPx(context, 30) && markedArea.height() >= CommonUtil.dpToPx(context, 30)) { | |
| 259 | 259 | if (isButtonClicked) { |
| 260 | 260 | break; |
| 261 | 261 | } | ... | ... |