From f02938ea8a5d7c23a8e820cd39261dd5b7ce5ce2 Mon Sep 17 00:00:00 2001 From: maning <154292322@qq.com> Date: Fri, 16 Oct 2020 16:26:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=AB=E7=A0=81=E5=8A=9F=E8=83=BD=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 26 ++++--- .../ui/activity/tools/ScanResultActivity.java | 49 ++++++++++-- .../ui/adapter/RecycleMoreItemAdapter.java | 2 +- .../ui/adapter/RecycleScanHistoryAdapter.java | 5 ++ .../com/maning/gankmm/utils/CacheManager.java | 9 ++- .../maning/gankmm/utils/ZxingScanUtils.java | 2 +- .../drawable/gank_icon_tools_scan_history.xml | 12 +++ .../main/res/layout/activity_scan_result.xml | 76 ++++++++++--------- 8 files changed, 128 insertions(+), 53 deletions(-) create mode 100644 app/src/main/res/drawable/gank_icon_tools_scan_history.xml diff --git a/app/build.gradle b/app/build.gradle index 894c9e9..1e9bae8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -117,6 +117,20 @@ dependencies { implementation librarys.recyclerview implementation librarys.cardview implementation librarys.multidex + implementation 'com.android.support.constraint:constraint-layout:2.0.2' + + /*-----------------------------------------*/ + + /*Umeng统计*/ + implementation 'com.umeng.sdk:common:1.5.3' + implementation 'com.umeng.sdk:analytics:7.5.3' + /*极光推送*/ + implementation files('libs/jcore-android_v1.1.2.jar') + implementation files('libs/jpush-android_v3.0.5.jar') + + + /*-----------------------------------------*/ + /*RecycleView的间隔线*/ implementation 'com.yqritc:recyclerview-flexibledivider:1.2.9' /*解析Json*/ @@ -139,19 +153,13 @@ dependencies { /*点赞收藏按钮*/ implementation 'com.ldoublem.thumbUplib:ThumbUplib:0.5' /*material风格的dialogs*/ - implementation 'com.afollestad.material-dialogs:core:0.9.3.0' + implementation 'com.afollestad.material-dialogs:core:0.9.6.0' /*解析HTML页面*/ implementation 'org.jsoup:jsoup:1.9.2' /*权限库*/ implementation 'com.yanzhenjie:permission:2.0.0-rc4' /*ViewPager指示器*/ implementation 'com.ogaclejapan.smarttablayout:library:1.6.1@aar' - /*Umeng统计*/ - implementation 'com.umeng.sdk:common:1.5.3' - implementation 'com.umeng.sdk:analytics:7.5.3' - /*极光推送*/ - implementation files('libs/jcore-android_v1.1.2.jar') - implementation files('libs/jpush-android_v3.0.5.jar') /*菜单*/ implementation 'io.github.yavski:fab-speed-dial:1.0.4' /*高德地图*/ @@ -159,7 +167,6 @@ dependencies { /* 模糊 */ implementation 'jp.wasabeef:blurry:2.1.1' /*网络监测*/ - implementation 'com.android.support.constraint:constraint-layout:2.0.2' debugImplementation 'com.readystatesoftware.chuck:library:1.1.0' releaseImplementation 'com.readystatesoftware.chuck:library-no-op:1.1.0' /* 表格 */ @@ -183,7 +190,8 @@ dependencies { /* 图片浏览器所需 */ implementation 'com.github.chrisbanes:PhotoView:2.0.0' - /* ----------自己------------ */ + /*-----------------------------------------*/ + /*二维码扫描*/ implementation 'com.github.maning0303:MNZXingCode:V2.1.4' /*翻滚广告条TextView*/ diff --git a/app/src/main/java/com/maning/gankmm/ui/activity/tools/ScanResultActivity.java b/app/src/main/java/com/maning/gankmm/ui/activity/tools/ScanResultActivity.java index f24f5e1..270a53f 100644 --- a/app/src/main/java/com/maning/gankmm/ui/activity/tools/ScanResultActivity.java +++ b/app/src/main/java/com/maning/gankmm/ui/activity/tools/ScanResultActivity.java @@ -11,7 +11,9 @@ import android.text.TextUtils; import android.view.Menu; import android.view.MenuItem; +import android.view.View; import android.widget.Button; +import android.widget.LinearLayout; import android.widget.TextView; import com.maning.gankmm.R; @@ -20,8 +22,10 @@ import com.maning.gankmm.ui.base.BaseActivity; import com.maning.gankmm.utils.CacheManager; import com.maning.gankmm.utils.ClipUtils; +import com.maning.gankmm.utils.DialogUtils; import com.maning.gankmm.utils.MMKVUtils; import com.maning.gankmm.utils.MySnackbar; +import com.maning.gankmm.utils.PermissionUtils; import com.maning.gankmm.utils.ThreadPoolUtils; import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration; @@ -43,8 +47,11 @@ public class ScanResultActivity extends BaseActivity { RecyclerView recyclerView; @Bind(R.id.tv_show) TextView tvShow; + @Bind(R.id.ll_result_show) + LinearLayout ll_result_show; + private String content; - private List scanResult = new ArrayList<>(); + private ArrayList scanResult = new ArrayList<>(); private RecycleScanHistoryAdapter recycleScanHistoryAdapter; public static void open(Context context, String content) { @@ -59,11 +66,20 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_scan_result); ButterKnife.bind(this); initIntent(); - initBackToolBar(toolbar, "扫码结果"); + initMyToolbar(); initRecyclerView(); initDatas(); } + private void initMyToolbar() { + if (TextUtils.isEmpty(content)) { + initBackToolBar(toolbar, "扫码记录"); + ll_result_show.setVisibility(View.GONE); + } else { + initBackToolBar(toolbar, "扫码内容"); + } + } + private void initDatas() { tvShow.setText(content); @@ -71,11 +87,11 @@ private void initDatas() { ThreadPoolUtils.execute(new Runnable() { @Override public void run() { - scanResult = CacheManager.getScanResult(); + scanResult = (ArrayList) CacheManager.getScanResult(); runOnUiThread(new Runnable() { @Override public void run() { - recycleScanHistoryAdapter = new RecycleScanHistoryAdapter(mActivity, (ArrayList) scanResult); + recycleScanHistoryAdapter = new RecycleScanHistoryAdapter(mActivity, scanResult); recyclerView.setAdapter(recycleScanHistoryAdapter); } }); @@ -90,9 +106,28 @@ public boolean onOptionsItemSelected(MenuItem item) { this.finish(); return true; case R.id.item_delete: - //TODO:删除提示 - - + DialogUtils.showMyDialog(this, + "提示", + "确定要清除所有记录吗?", + "确定", + "取消", + new DialogUtils.OnDialogClickListener() { + @Override + public void onConfirm() { + CacheManager.cleanScanResult(); + //刷新页面 + scanResult = new ArrayList<>(); + if (recycleScanHistoryAdapter != null) { + recycleScanHistoryAdapter.updateDatas(scanResult); + } + MySnackbar.makeSnackBarGreen(toolbar, "删除成功"); + } + + @Override + public void onCancel() { + + } + }); return true; } return super.onOptionsItemSelected(item); diff --git a/app/src/main/java/com/maning/gankmm/ui/adapter/RecycleMoreItemAdapter.java b/app/src/main/java/com/maning/gankmm/ui/adapter/RecycleMoreItemAdapter.java index 9ae6d56..f6f5af1 100644 --- a/app/src/main/java/com/maning/gankmm/ui/adapter/RecycleMoreItemAdapter.java +++ b/app/src/main/java/com/maning/gankmm/ui/adapter/RecycleMoreItemAdapter.java @@ -40,7 +40,7 @@ public class RecycleMoreItemAdapter extends RecyclerView.Adapter mDatas) { layoutInflater = LayoutInflater.from(this.context); } + public void updateDatas(ArrayList mDatas) { + this.mDatas = mDatas; + notifyDataSetChanged(); + } + @Override public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View inflate = layoutInflater.inflate(R.layout.item_scan_history, parent, false); diff --git a/app/src/main/java/com/maning/gankmm/utils/CacheManager.java b/app/src/main/java/com/maning/gankmm/utils/CacheManager.java index 3e78c1e..5e4ab2e 100644 --- a/app/src/main/java/com/maning/gankmm/utils/CacheManager.java +++ b/app/src/main/java/com/maning/gankmm/utils/CacheManager.java @@ -18,7 +18,14 @@ public class CacheManager { private static final String KEY_SCAN_RESULT = "KEY_SCAN_RESULT"; private static Gson gson = new Gson(); + public static void cleanScanResult() { + MMKVUtils.getInstance().putString(KEY_SCAN_RESULT, ""); + } + public static void saveScanResult(String content) { + if (TextUtils.isEmpty(content)) { + return; + } List caches = new ArrayList<>(); String cache = MMKVUtils.getInstance().getString(KEY_SCAN_RESULT, ""); if (TextUtils.isEmpty(cache)) { @@ -26,7 +33,7 @@ public static void saveScanResult(String content) { } else { caches = gson.fromJson(cache, new TypeToken>() { }.getType()); - caches.add(0,content); + caches.add(0, content); } MMKVUtils.getInstance().putString(KEY_SCAN_RESULT, gson.toJson(caches)); } diff --git a/app/src/main/java/com/maning/gankmm/utils/ZxingScanUtils.java b/app/src/main/java/com/maning/gankmm/utils/ZxingScanUtils.java index 30a1968..7e8f8b9 100644 --- a/app/src/main/java/com/maning/gankmm/utils/ZxingScanUtils.java +++ b/app/src/main/java/com/maning/gankmm/utils/ZxingScanUtils.java @@ -40,7 +40,7 @@ public static void open(final Activity activity) { .setFullScreenScan(true) //二维码标记点 .isShowResultPoint(true) - .setResultPointConfigs(40, 30, 10, "#70FFFFFF", "#7000A81F") + .setResultPointConfigs(60, 30, 10, "#FFFFFFFF", "#7000A81F") .builder(); MNScanManager.startScan(activity, scanConfig, new MNScanCallback() { @Override diff --git a/app/src/main/res/drawable/gank_icon_tools_scan_history.xml b/app/src/main/res/drawable/gank_icon_tools_scan_history.xml new file mode 100644 index 0000000..3311d6e --- /dev/null +++ b/app/src/main/res/drawable/gank_icon_tools_scan_history.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/layout/activity_scan_result.xml b/app/src/main/res/layout/activity_scan_result.xml index cad2d55..e29dc1c 100644 --- a/app/src/main/res/layout/activity_scan_result.xml +++ b/app/src/main/res/layout/activity_scan_result.xml @@ -8,47 +8,55 @@ - - - + android:orientation="vertical"> + + + android:orientation="horizontal" + android:padding="16dp"> -