Skip to content

Commit a27c1a0

Browse files
committed
update androidx support libs
1 parent 7b7df09 commit a27c1a0

File tree

12 files changed

+169
-88
lines changed

12 files changed

+169
-88
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@ This project is for me to learn Java, NDK, and for fun.
3333

3434
### About Me
3535
* GitHub: [https://huzongyao.github.io/](https://huzongyao.github.io/)
36-
* ITEye博客:[http://hzy3774.iteye.com/](http://hzy3774.iteye.com/)
37-
* 新浪微博: [http://weibo.com/hzy3774](http://weibo.com/hzy3774)
36+
* ITEye博客:[https://hzy3774.iteye.com/](https://hzy3774.iteye.com/)
37+
* 新浪微博: [https://weibo.com/hzy3774](https://weibo.com/hzy3774)
3838

3939
### Contact To Me
40-
* QQ: [377406997](http://wpa.qq.com/msgrd?v=3&uin=377406997&site=qq&menu=yes)
40+
* QQ: [377406997](https://wpa.qq.com/msgrd?v=3&uin=377406997&site=qq&menu=yes)
4141
* Gmail: [hzy3774@gmail.com](mailto:hzy3774@gmail.com)
42-
* Foxmail: [hzy3774@qq.com](mailto:hzy3774@qq.com)
42+
* Foxmail: [hzy3774@qq.com](mailto:hzy3774@qq.com)
43+
* WeChat: hzy3774
44+
45+
![image](https://raw.githubusercontent.com/hzy3774/AndroidP7zip/master/misc/wechat.png)
46+
47+
### Others
48+
* 想捐助我喝杯热水(¥0.01起捐)</br>
49+
![donate](https://github.com/huzongyao/JChineseChess/blob/master/misc/donate.png?raw=true)

app/build.gradle

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 28
4+
compileSdkVersion 29
55

66
signingConfigs {
77
demokey {
@@ -14,9 +14,9 @@ android {
1414
defaultConfig {
1515
applicationId "com.hzy.magic.app"
1616
minSdkVersion 15
17-
targetSdkVersion 28
18-
versionCode 2
19-
versionName "1.1.1"
17+
targetSdkVersion 29
18+
versionCode 3
19+
versionName "1.1.2"
2020
}
2121
compileOptions {
2222
targetCompatibility JavaVersion.VERSION_1_8
@@ -47,12 +47,10 @@ android {
4747

4848
dependencies {
4949
implementation fileTree(include: ['*.jar'], dir: 'libs')
50-
implementation 'com.android.support:appcompat-v7:28.0.0'
51-
implementation 'com.android.support:cardview-v7:28.0.0'
52-
implementation 'com.android.support:design:28.0.0'
53-
implementation 'com.blankj:utilcode:1.23.7'
54-
api 'io.reactivex.rxjava2:rxandroid:2.0.2'
55-
api 'com.jakewharton:butterknife:9.0.0'
56-
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0'
50+
implementation 'androidx.appcompat:appcompat:1.1.0'
51+
implementation 'com.google.android.material:material:1.0.0'
52+
implementation 'com.blankj:utilcode:1.25.9'
53+
api 'com.jakewharton:butterknife:10.1.0'
54+
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
5755
implementation project(':libmagic')
5856
}

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
android:supportsRtl="true"
1414
android:theme="@style/AppTheme"
1515
tools:ignore="GoogleAppIndexingWarning">
16-
<activity android:name=".activity.MainActivity">
16+
<activity android:name=".activity.MainActivity" />
17+
<activity android:name=".activity.SplashActivity">
1718
<intent-filter>
1819
<action android:name="android.intent.action.MAIN" />
1920

app/src/main/java/com/hzy/magic/app/activity/MainActivity.java

Lines changed: 51 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
import android.os.Build;
77
import android.os.Bundle;
88
import android.os.Environment;
9-
import android.support.v4.widget.SwipeRefreshLayout;
10-
import android.support.v7.app.AlertDialog;
11-
import android.support.v7.app.AppCompatActivity;
12-
import android.support.v7.widget.LinearLayoutManager;
13-
import android.support.v7.widget.RecyclerView;
149
import android.view.Menu;
1510
import android.view.MenuItem;
1611
import android.view.View;
1712

13+
import androidx.appcompat.app.AlertDialog;
14+
import androidx.appcompat.app.AppCompatActivity;
15+
import androidx.recyclerview.widget.LinearLayoutManager;
16+
import androidx.recyclerview.widget.RecyclerView;
17+
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
18+
1819
import com.blankj.utilcode.constant.PermissionConstants;
1920
import com.blankj.utilcode.util.PermissionUtils;
2021
import com.hzy.libmagic.MagicApi;
@@ -24,21 +25,16 @@
2425
import com.hzy.magic.app.bean.FileInfo;
2526
import com.hzy.magic.app.utils.FileUtils;
2627

27-
import java.io.IOException;
28-
import java.io.InputStream;
2928
import java.util.List;
29+
import java.util.Stack;
30+
import java.util.concurrent.ExecutorService;
31+
import java.util.concurrent.Executors;
3032

3133
import butterknife.BindView;
3234
import butterknife.ButterKnife;
33-
import io.reactivex.Observable;
34-
import io.reactivex.ObservableOnSubscribe;
35-
import io.reactivex.android.schedulers.AndroidSchedulers;
36-
import io.reactivex.functions.Consumer;
37-
import io.reactivex.schedulers.Schedulers;
3835

3936
public class MainActivity extends AppCompatActivity
40-
implements View.OnClickListener, SwipeRefreshLayout.OnRefreshListener,
41-
Consumer<List<FileInfo>> {
37+
implements View.OnClickListener, SwipeRefreshLayout.OnRefreshListener {
4238

4339
@BindView(R.id.main_storage_path)
4440
RecyclerView mPathList;
@@ -51,16 +47,20 @@ public class MainActivity extends AppCompatActivity
5147

5248
private PathItemAdapter mPathAdapter;
5349
private FileItemAdapter mFileAdapter;
54-
private String mCurPath;
50+
private String mCurrentPath;
5551
private ProgressDialog mProgressDialog;
5652
private AlertDialog mAboutDialog;
53+
private ExecutorService mThreadPool;
54+
private Stack<String> mHistoryStack;
5755

5856
@TargetApi(Build.VERSION_CODES.M)
5957
@Override
6058
protected void onCreate(Bundle savedInstanceState) {
6159
super.onCreate(savedInstanceState);
6260
setContentView(R.layout.activity_main);
6361
ButterKnife.bind(this);
62+
mThreadPool = Executors.newFixedThreadPool(8);
63+
mHistoryStack = new Stack<>();
6464
initUI();
6565
PermissionUtils.permission(PermissionConstants.STORAGE)
6666
.callback(new PermissionUtils.SimpleCallback() {
@@ -71,11 +71,11 @@ public void onGranted() {
7171

7272
@Override
7373
public void onDenied() {
74-
7574
}
7675
}).request();
7776
}
7877

78+
7979
private void initUI() {
8080
mProgressDialog = new ProgressDialog(this);
8181
mProgressDialog.setCancelable(false);
@@ -90,31 +90,31 @@ private void initUI() {
9090

9191
@SuppressLint("CheckResult")
9292
private void loadInitPath() {
93-
final String path = Environment.getExternalStorageDirectory().getPath();
94-
Observable.create((ObservableOnSubscribe<List<FileInfo>>) e -> {
95-
if (initMagicFromAssets()) {
96-
List<FileInfo> infoList = FileUtils.getInfoListFromPath(path);
97-
mCurPath = path;
98-
e.onNext(infoList);
99-
}
100-
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
101-
.subscribe(this);
93+
mCurrentPath = Environment.getExternalStorageDirectory().getPath();
94+
mHistoryStack.push(mCurrentPath);
95+
loadPathInfo(mCurrentPath);
10296
}
10397

104-
@SuppressLint("CheckResult")
105-
private void loadPathInfo(final String path) {
106-
Observable.create((ObservableOnSubscribe<List<FileInfo>>) e -> {
98+
private void loadPathInfo(String path) {
99+
mThreadPool.submit(() -> {
107100
List<FileInfo> infoList = FileUtils.getInfoListFromPath(path);
108-
mCurPath = path;
109-
e.onNext(infoList);
110-
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
111-
.subscribe(this);
101+
runOnUiThread(() -> {
102+
mCurrentPath = path;
103+
mFileAdapter.setDataList(infoList);
104+
mPathAdapter.setPathView(mCurrentPath);
105+
mPathList.scrollToPosition(mPathAdapter.getItemCount() - 1);
106+
mFileList.smoothScrollToPosition(0);
107+
mSwipeRefresh.setRefreshing(false);
108+
mProgressDialog.dismiss();
109+
});
110+
});
112111
}
113112

114113
@Override
115114
protected void onDestroy() {
116-
super.onDestroy();
115+
mThreadPool.shutdownNow();
117116
MagicApi.close();
117+
super.onDestroy();
118118
}
119119

120120
@Override
@@ -138,52 +138,44 @@ public boolean onOptionsItemSelected(MenuItem item) {
138138

139139
@Override
140140
public void onBackPressed() {
141-
super.onBackPressed();
142-
}
143-
144-
private boolean initMagicFromAssets() {
145-
try {
146-
InputStream inputStream = getAssets().open("magic.mgc");
147-
int length = inputStream.available();
148-
byte[] buffer = new byte[length];
149-
if (inputStream.read(buffer) > 0) {
150-
return MagicApi.loadFromBytes(buffer) == 0;
141+
if (mHistoryStack.size() > 1) {
142+
mHistoryStack.pop();
143+
String backPath = mHistoryStack.peek();
144+
if (backPath != null) {
145+
loadPathInfo(backPath);
151146
}
152-
} catch (IOException e) {
153-
e.printStackTrace();
147+
} else {
148+
super.onBackPressed();
154149
}
155-
return false;
156150
}
157151

158152
@Override
159153
public void onClick(View v) {
160154
if (v.getTag() instanceof String) {
161155
mProgressDialog.show();
162-
loadPathInfo((String) v.getTag());
156+
String path = (String) v.getTag();
157+
if (path != null) {
158+
if (mHistoryStack.empty() || !mHistoryStack.peek().equals(path)) {
159+
mHistoryStack.push(path);
160+
}
161+
loadPathInfo(path);
162+
}
163163
} else {
164164
FileInfo info = (FileInfo) v.getTag();
165165
FileInfo.FileType type = info.getFileType();
166166
if (type == FileInfo.FileType.folderEmpty
167167
|| type == FileInfo.FileType.folderFull) {
168168
mProgressDialog.show();
169-
loadPathInfo(info.getFilePath());
169+
String path = info.getFilePath();
170+
mHistoryStack.push(path);
171+
loadPathInfo(path);
170172
}
171173
}
172174
}
173175

174176
@Override
175177
public void onRefresh() {
176-
loadPathInfo(mCurPath);
177-
}
178-
179-
@Override
180-
public void accept(List<FileInfo> fileInfos) {
181-
mFileAdapter.setDataList(fileInfos);
182-
mPathAdapter.setPathView(mCurPath);
183-
mPathList.scrollToPosition(mPathAdapter.getItemCount() - 1);
184-
mFileList.smoothScrollToPosition(0);
185-
mSwipeRefresh.setRefreshing(false);
186-
mProgressDialog.dismiss();
178+
loadPathInfo(mCurrentPath);
187179
}
188180

189181
private void showAboutDialog() {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.hzy.magic.app.activity;
2+
3+
import android.app.Activity;
4+
import android.content.Intent;
5+
import android.os.Bundle;
6+
7+
import com.hzy.libmagic.MagicApi;
8+
import com.hzy.magic.app.R;
9+
10+
import java.io.InputStream;
11+
12+
public class SplashActivity extends Activity {
13+
14+
@Override
15+
protected void onCreate(Bundle savedInstanceState) {
16+
super.onCreate(savedInstanceState);
17+
setContentView(R.layout.activity_splash);
18+
ensureMagicAndStart();
19+
}
20+
21+
private void ensureMagicAndStart() {
22+
new Thread() {
23+
@Override
24+
public void run() {
25+
try {
26+
InputStream inputStream = getAssets().open("magic.mgc");
27+
int length = inputStream.available();
28+
byte[] buffer = new byte[length];
29+
if (inputStream.read(buffer) > 0) {
30+
if (MagicApi.loadFromBytes(buffer) == 0) {
31+
startMainApp();
32+
return;
33+
}
34+
}
35+
} catch (Exception e) {
36+
e.printStackTrace();
37+
}
38+
finish();
39+
}
40+
}.start();
41+
}
42+
43+
private void startMainApp() {
44+
startActivity(new Intent(this, MainActivity.class));
45+
finish();
46+
}
47+
}

app/src/main/java/com/hzy/magic/app/adapter/FileItemAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package com.hzy.magic.app.adapter;
22

33
import android.app.Activity;
4-
import android.support.v7.widget.RecyclerView;
54
import android.view.LayoutInflater;
65
import android.view.View;
76
import android.view.ViewGroup;
87
import android.widget.ImageView;
98
import android.widget.TextView;
109

10+
import androidx.recyclerview.widget.RecyclerView;
11+
1112
import com.hzy.magic.app.R;
1213
import com.hzy.magic.app.bean.FileInfo;
1314

app/src/main/java/com/hzy/magic/app/adapter/PathItemAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.hzy.magic.app.adapter;
22

33
import android.app.Activity;
4-
import android.support.annotation.NonNull;
5-
import android.support.v7.widget.RecyclerView;
64
import android.view.LayoutInflater;
75
import android.view.View;
86
import android.view.ViewGroup;
97
import android.widget.TextView;
108

9+
import androidx.annotation.NonNull;
10+
import androidx.recyclerview.widget.RecyclerView;
1111

1212
import com.hzy.magic.app.R;
1313

app/src/main/java/com/hzy/magic/app/utils/FileUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
public class FileUtils {
17+
1718
public static FileInfo getFileInfoFromPath(String filePath) {
1819
FileInfo info = new FileInfo();
1920
info.setFileType(FileInfo.FileType.fileKnown);

app/src/main/res/layout/activity_main.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@
66
android:background="#EBEFF2"
77
android:orientation="vertical">
88

9-
<android.support.v7.widget.RecyclerView
9+
<androidx.recyclerview.widget.RecyclerView
1010
android:id="@+id/main_storage_path"
1111
android:layout_width="match_parent"
1212
android:layout_height="wrap_content"
1313
android:background="#CCBCBC"
14+
tools:itemCount="3"
1415
tools:listitem="@layout/path_list_item" />
1516

16-
<android.support.v4.widget.SwipeRefreshLayout
17+
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
1718
android:id="@+id/main_storage_refresh"
1819
android:layout_width="match_parent"
1920
android:layout_height="match_parent">
2021

21-
<android.support.v7.widget.RecyclerView
22+
<androidx.recyclerview.widget.RecyclerView
2223
android:id="@+id/main_storage_list"
2324
android:layout_width="match_parent"
2425
android:layout_height="wrap_content"
2526
android:scrollbars="vertical"
2627
tools:listitem="@layout/storage_list_item" />
27-
</android.support.v4.widget.SwipeRefreshLayout>
28+
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
2829

2930
</LinearLayout>

0 commit comments

Comments
 (0)