假数据
1
FileDialog/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
33
FileDialog/build.gradle
Normal file
@ -0,0 +1,33 @@
|
||||
plugins {
|
||||
id 'com.android.library'
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 33
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 33
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api project(path: ':DialogX')
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.4.1'
|
||||
}
|
0
FileDialog/consumer-rules.pro
Normal file
21
FileDialog/proguard-rules.pro
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
9
FileDialog/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.kongzue.filedialog">
|
||||
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||
|
||||
</manifest>
|
481
FileDialog/src/main/java/com/kongzue/filedialog/FileDialog.java
Normal file
@ -0,0 +1,481 @@
|
||||
package com.kongzue.filedialog;
|
||||
|
||||
import static com.kongzue.dialogx.interfaces.BaseDialog.isNull;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.kongzue.dialogx.dialogs.FullScreenDialog;
|
||||
import com.kongzue.dialogx.dialogs.PopTip;
|
||||
import com.kongzue.dialogx.interfaces.BaseDialog;
|
||||
import com.kongzue.dialogx.interfaces.OnBackPressedListener;
|
||||
import com.kongzue.dialogx.interfaces.OnBindView;
|
||||
import com.kongzue.filedialog.adapter.FileAdapter;
|
||||
import com.kongzue.filedialog.interfaces.FileSelectCallBack;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: Kongzue
|
||||
* @github: https://github.com/kongzue/
|
||||
* @homepage: http://kongzue.com/
|
||||
* @mail: myzcxhh@live.cn
|
||||
* @createTime: 2022/3/3 13:02
|
||||
*/
|
||||
public class FileDialog {
|
||||
|
||||
public static FileDialog build() {
|
||||
return new FileDialog();
|
||||
}
|
||||
|
||||
public static int REQUEST_PERMISSION_CODE = 9103;
|
||||
|
||||
String[] mimeTypes;
|
||||
String[] suffixArray;
|
||||
FileSelectCallBack fileSelectCallBack;
|
||||
int maxSelectionNumber = 1;
|
||||
boolean showFileDate = true;
|
||||
|
||||
enum SelectType {
|
||||
FILE,
|
||||
FOLDER
|
||||
}
|
||||
|
||||
SelectType selectType = SelectType.FILE;
|
||||
FullScreenDialog dialog;
|
||||
|
||||
public void selectFileByMime(String mimeType, FileSelectCallBack fileSelectCallBack) {
|
||||
selectFileByMime(new String[]{mimeType}, fileSelectCallBack);
|
||||
}
|
||||
|
||||
public void selectFileBySuffix(String suffix, FileSelectCallBack fileSelectCallBack) {
|
||||
selectFileBySuffix(new String[]{suffix}, fileSelectCallBack);
|
||||
}
|
||||
|
||||
public void selectFile(FileSelectCallBack fileSelectCallBack) {
|
||||
selectType = SelectType.FILE;
|
||||
this.fileSelectCallBack = fileSelectCallBack;
|
||||
readyShowDialog();
|
||||
}
|
||||
|
||||
public void selectFileByMime(String[] mimeTypes, FileSelectCallBack fileSelectCallBack) {
|
||||
selectType = SelectType.FILE;
|
||||
this.mimeTypes = mimeTypes;
|
||||
this.fileSelectCallBack = fileSelectCallBack;
|
||||
readyShowDialog();
|
||||
}
|
||||
|
||||
public void selectFileBySuffix(String[] suffixArray, FileSelectCallBack fileSelectCallBack) {
|
||||
selectType = SelectType.FILE;
|
||||
this.suffixArray = suffixArray;
|
||||
this.fileSelectCallBack = fileSelectCallBack;
|
||||
readyShowDialog();
|
||||
}
|
||||
|
||||
public void selectFolder(FileSelectCallBack fileSelectCallBack) {
|
||||
selectType = SelectType.FOLDER;
|
||||
this.fileSelectCallBack = fileSelectCallBack;
|
||||
readyShowDialog();
|
||||
}
|
||||
|
||||
private void readyShowDialog() {
|
||||
Context context = BaseDialog.getTopActivity();
|
||||
if (!(context instanceof Activity)) {
|
||||
errorLog("请先完成 DialogX 组件的初始化,详情:https://github.com/kongzue/DialogX");
|
||||
return;
|
||||
}
|
||||
requestPermissions(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 建议自行处理好权限问题,不要依赖 FileDialog 申请,原因是无法监听 onRequestPermissionsResult 的回调.
|
||||
* 若实在懒得自己处理,请重写 activity 的 onRequestPermissionsResult(...) 方法,
|
||||
* 并调用 FileDialog 实例的 onRequestPermissionsResult(...) 方法。
|
||||
*
|
||||
* @param context activity 上下文
|
||||
*/
|
||||
private void requestPermissions(Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
// 先判断有没有权限
|
||||
if (Environment.isExternalStorageManager()) {
|
||||
createDialog();
|
||||
} else {
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
|
||||
intent.setData(Uri.parse("package:" + context.getPackageName()));
|
||||
((Activity) context).startActivityForResult(intent, REQUEST_PERMISSION_CODE);
|
||||
}
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
||||
createDialog();
|
||||
} else {
|
||||
ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSION_CODE);
|
||||
}
|
||||
} else {
|
||||
createDialog();
|
||||
}
|
||||
}
|
||||
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
if (requestCode == REQUEST_PERMISSION_CODE) {
|
||||
readyShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
String path;
|
||||
FileAdapter fileAdapter;
|
||||
List<String> selectPathList;
|
||||
String title;
|
||||
String baseTitle;
|
||||
|
||||
private void createDialog() {
|
||||
dialog = FullScreenDialog.build();
|
||||
dialog.setCustomView(new OnBindView<FullScreenDialog>(R.layout.layout_dialogx_file_select) {
|
||||
|
||||
private TextView btnCancel;
|
||||
private TextView txtDialogTitle;
|
||||
private TextView btnSelect;
|
||||
private TextView txtPath;
|
||||
private ListView listFile;
|
||||
private ImageView imgFileListScreenshot;
|
||||
|
||||
@Override
|
||||
public void onBind(FullScreenDialog dialog, View v) {
|
||||
FileDialog.this.dialog = dialog;
|
||||
|
||||
btnCancel = v.findViewById(R.id.btn_cancel);
|
||||
txtDialogTitle = v.findViewById(R.id.txt_dialog_title);
|
||||
btnSelect = v.findViewById(R.id.btn_select);
|
||||
txtPath = v.findViewById(R.id.txt_path);
|
||||
listFile = v.findViewById(R.id.list_file);
|
||||
imgFileListScreenshot = v.findViewById(R.id.img_file_list_screenshot);
|
||||
|
||||
if (title == null || title.length() == 0) {
|
||||
if (selectType == SelectType.FILE) {
|
||||
if (getMaxSelectionNumber() == 1) {
|
||||
txtDialogTitle.setText(BaseDialog.getTopActivity().getResources().getText(R.string.dialogx_filedialog_title_file));
|
||||
} else {
|
||||
baseTitle = BaseDialog.getTopActivity().getResources().getString(R.string.dialogx_filedialog_title_file);
|
||||
txtDialogTitle.setText(baseTitle + "(0/" + getMaxSelectionNumber() + ")");
|
||||
}
|
||||
} else {
|
||||
txtDialogTitle.setText(BaseDialog.getTopActivity().getResources().getText(R.string.dialogx_filedialog_title_folder));
|
||||
}
|
||||
} else {
|
||||
txtDialogTitle.setText(title);
|
||||
}
|
||||
|
||||
btnCancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
btnSelect.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (getMaxSelectionNumber() == 1) {
|
||||
fileSelectCallBack.onSelect(new File(path), path);
|
||||
dialog.dismiss();
|
||||
} else {
|
||||
if (selectPathList != null && selectPathList.size() != 0) {
|
||||
File[] fileArray = new File[selectPathList.size()];
|
||||
String[] filePathArray = new String[selectPathList.size()];
|
||||
for (int i = 0; i < selectPathList.size(); i++) {
|
||||
filePathArray[i] = selectPathList.get(i);
|
||||
fileArray[i] = new File(selectPathList.get(i));
|
||||
}
|
||||
fileSelectCallBack.onMultiSelect(fileArray, filePathArray);
|
||||
dialog.dismiss();
|
||||
} else {
|
||||
PopTip.show(R.string.error_dialogx_filedialog_no_file_selected_tip);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (selectType == SelectType.FILE && getMaxSelectionNumber() == 1) {
|
||||
btnSelect.setFocusable(false);
|
||||
btnSelect.setClickable(false);
|
||||
btnSelect.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
dialog.setOnBackPressedListener(new OnBackPressedListener<FullScreenDialog>() {
|
||||
@Override
|
||||
public boolean onBackPressed(FullScreenDialog dialog) {
|
||||
if (!Environment.getExternalStorageDirectory().getPath().equals(path)) {
|
||||
if (path.contains("/")) {
|
||||
String[] folders = path.split("/");
|
||||
if (folders.length > 2) {
|
||||
path = "";
|
||||
for (int i = 0; i < folders.length - 1; i++) {
|
||||
path = path + (i == 0 ? "" : "/") + folders[i];
|
||||
}
|
||||
|
||||
Bitmap screenshot = screenshotView(listFile);
|
||||
imgFileListScreenshot.setImageBitmap(screenshot);
|
||||
|
||||
imgFileListScreenshot.setVisibility(View.VISIBLE);
|
||||
imgFileListScreenshot.setX(0);
|
||||
|
||||
refreshFileList();
|
||||
|
||||
listFile.setX(-listFile.getWidth());
|
||||
imgFileListScreenshot.animate().setInterpolator(new DecelerateInterpolator(2f)).x(listFile.getWidth());
|
||||
listFile.animate().setInterpolator(new DecelerateInterpolator(2f)).x(0);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
loadFileList();
|
||||
}
|
||||
|
||||
private void loadFileList() {
|
||||
if (isNull(path)) {
|
||||
path = Environment.getExternalStorageDirectory().getPath();
|
||||
}
|
||||
fileAdapter = new FileAdapter(FileDialog.this, (Activity) BaseDialog.getTopActivity(), new ArrayList<String>());
|
||||
listFile.setAdapter(fileAdapter);
|
||||
listFile.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
view.setPressed(false);
|
||||
String fileName = (String) fileAdapter.getItem(position);
|
||||
if ("...".equals(fileName)) {
|
||||
//返回上级
|
||||
if (path.contains("/")) {
|
||||
String[] folders = path.split("/");
|
||||
if (folders.length > 2) {
|
||||
path = "";
|
||||
for (int i = 0; i < folders.length - 1; i++) {
|
||||
path = path + (i == 0 ? "" : "/") + folders[i];
|
||||
}
|
||||
|
||||
Bitmap screenshot = screenshotView(listFile);
|
||||
imgFileListScreenshot.setImageBitmap(screenshot);
|
||||
|
||||
imgFileListScreenshot.setVisibility(View.VISIBLE);
|
||||
imgFileListScreenshot.setX(0);
|
||||
|
||||
refreshFileList();
|
||||
|
||||
listFile.setX(-listFile.getWidth());
|
||||
imgFileListScreenshot.animate().setInterpolator(new DecelerateInterpolator(2f)).x(listFile.getWidth());
|
||||
listFile.animate().setInterpolator(new DecelerateInterpolator(2f)).x(0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
boolean isFolder = fileName.startsWith("/");
|
||||
String itemPath = path + (isFolder ? "" : "/") + fileName;
|
||||
if (isFolder) {
|
||||
//点击文件夹
|
||||
Bitmap screenshot = screenshotView(listFile);
|
||||
imgFileListScreenshot.setImageBitmap(screenshot);
|
||||
|
||||
imgFileListScreenshot.setVisibility(View.VISIBLE);
|
||||
imgFileListScreenshot.setX(0);
|
||||
|
||||
path = itemPath;
|
||||
refreshFileList();
|
||||
|
||||
listFile.setX(listFile.getWidth());
|
||||
imgFileListScreenshot.animate().setInterpolator(new DecelerateInterpolator(2f)).x(-listFile.getWidth());
|
||||
listFile.animate().setInterpolator(new DecelerateInterpolator(2f)).x(0);
|
||||
} else {
|
||||
//点击文件
|
||||
if (getMaxSelectionNumber() != 1) {
|
||||
//多选
|
||||
if (selectPathList == null) {
|
||||
selectPathList = new ArrayList<String>();
|
||||
}
|
||||
if (selectPathList.contains(itemPath)) {
|
||||
selectPathList.remove(itemPath);
|
||||
} else {
|
||||
if (selectPathList.size() >= getMaxSelectionNumber()) {
|
||||
PopTip.show(String.format(
|
||||
BaseDialog.getTopActivity().getResources().getString(R.string.error_dialogx_filedialog_max_selection_tip),
|
||||
String.valueOf(getMaxSelectionNumber())
|
||||
));
|
||||
return;
|
||||
}
|
||||
selectPathList.add(itemPath);
|
||||
}
|
||||
fileAdapter.notifyDataSetChanged();
|
||||
baseTitle = BaseDialog.getTopActivity().getResources().getString(R.string.dialogx_filedialog_title_file);
|
||||
txtDialogTitle.setText(baseTitle + "(" + selectPathList.size() + "/" + getMaxSelectionNumber() + ")");
|
||||
} else {
|
||||
//选择文件
|
||||
if (view.getAlpha() == 1f) {
|
||||
dialog.dismiss();
|
||||
fileSelectCallBack.onSelect(new File(itemPath), itemPath);
|
||||
} else {
|
||||
PopTip.show(R.string.error_dialogx_filedialog_no_support_file_type_tip);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
refreshFileList();
|
||||
}
|
||||
|
||||
private void refreshFileList() {
|
||||
fileAdapter.setFileList(new ArrayList<>());
|
||||
fileAdapter.notifyDataSetChanged();
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ArrayList<String> allFileArray = new ArrayList<String>();
|
||||
ArrayList<String> folderArray = new ArrayList<String>();
|
||||
ArrayList<String> fileArray = new ArrayList<String>();
|
||||
|
||||
File file = new File(path);
|
||||
File[] listFiles = file.listFiles();
|
||||
if (listFiles != null && listFiles.length != 0) {
|
||||
for (File f : listFiles) {
|
||||
if (f.isDirectory()) {
|
||||
folderArray.add("/" + f.getName());
|
||||
} else {
|
||||
fileArray.add(f.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Environment.getExternalStorageDirectory().getPath().equals(path)) {
|
||||
allFileArray.add("...");
|
||||
}
|
||||
allFileArray.addAll(folderArray);
|
||||
if (selectType == SelectType.FILE) {
|
||||
allFileArray.addAll(fileArray);
|
||||
}
|
||||
((Activity) BaseDialog.getTopActivity()).runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
txtPath.setText(path);
|
||||
fileAdapter.setFileList(allFileArray);
|
||||
fileAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
public FullScreenDialog getDialog() {
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public FileDialog setDialog(FullScreenDialog dialog) {
|
||||
this.dialog = dialog;
|
||||
return this;
|
||||
}
|
||||
|
||||
private void errorLog(String msg) {
|
||||
Log.e(">>>", "FileDialog: " + msg);
|
||||
}
|
||||
|
||||
public int getMaxSelectionNumber() {
|
||||
return maxSelectionNumber;
|
||||
}
|
||||
|
||||
public FileDialog setMaxSelectionNumber(int maxSelectionNumber) {
|
||||
this.maxSelectionNumber = maxSelectionNumber;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public FileDialog setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
private Bitmap screenshotView(View view) {
|
||||
view.setDrawingCacheEnabled(true);
|
||||
view.buildDrawingCache(true);
|
||||
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
|
||||
view.setDrawingCacheEnabled(false);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public FileDialog setMimeTypes(String[] mimeTypes) {
|
||||
this.mimeTypes = mimeTypes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FileDialog setSuffixArray(String[] suffixArray) {
|
||||
this.suffixArray = suffixArray;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String[] getMimeTypes() {
|
||||
return mimeTypes;
|
||||
}
|
||||
|
||||
public String[] getSuffixArray() {
|
||||
return suffixArray;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public FileDialog setPath(String path) {
|
||||
this.path = path;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FileDialog setPath(File folder) {
|
||||
if (folder.isDirectory()) {
|
||||
this.path = folder.getAbsolutePath();
|
||||
}else{
|
||||
this.path = folder.getParent();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<String> getSelectPathList() {
|
||||
return selectPathList;
|
||||
}
|
||||
|
||||
public boolean isShowFileDate() {
|
||||
return showFileDate;
|
||||
}
|
||||
|
||||
public FileDialog setShowFileDate(boolean showFileDate) {
|
||||
this.showFileDate = showFileDate;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,217 @@
|
||||
package com.kongzue.filedialog.adapter;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.kongzue.filedialog.FileDialog;
|
||||
import com.kongzue.filedialog.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author: Kongzue
|
||||
* @github: https://github.com/kongzue/
|
||||
* @homepage: http://kongzue.com/
|
||||
* @mail: myzcxhh@live.cn
|
||||
* @createTime: 2022/3/3 14:48
|
||||
*/
|
||||
public class FileAdapter extends BaseAdapter {
|
||||
|
||||
private ArrayList<String> fileList;
|
||||
private LayoutInflater layoutInflater;
|
||||
private Activity activity;
|
||||
private FileDialog dialog;
|
||||
|
||||
public FileAdapter(FileDialog dialog, Activity activity, ArrayList<String> fileList) {
|
||||
super();
|
||||
layoutInflater = activity.getLayoutInflater();
|
||||
this.dialog = dialog;
|
||||
this.activity = activity;
|
||||
this.fileList = fileList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return fileList.size();
|
||||
}
|
||||
|
||||
public void setFileList(ArrayList<String> fileList) {
|
||||
this.fileList = fileList;
|
||||
}
|
||||
|
||||
public ArrayList<String> getFileList() {
|
||||
return this.fileList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return fileList.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder viewHolder;
|
||||
if (convertView == null) {
|
||||
convertView = layoutInflater.inflate(R.layout.item_dialogx_file_list, null);
|
||||
}
|
||||
if (convertView.getTag() instanceof ViewHolder) {
|
||||
viewHolder = (ViewHolder) convertView.getTag();
|
||||
} else {
|
||||
viewHolder = new ViewHolder(convertView);
|
||||
convertView.setTag(viewHolder);
|
||||
}
|
||||
String fileName = fileList.get(position);
|
||||
boolean isFolder = fileName.startsWith("/");
|
||||
String itemPath = dialog.getPath() + (isFolder ? "" : "/") + fileName;
|
||||
|
||||
viewHolder.txtFileName.getPaint().setFakeBoldText(false);
|
||||
if ("...".equals(fileName)) {
|
||||
viewHolder.txtFileName.setText("...");
|
||||
viewHolder.imgIcon.setImageResource(R.drawable.ic_dialogx_filedialog_back);
|
||||
viewHolder.btnHaveChild.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (fileName.startsWith("/")) {
|
||||
viewHolder.txtFileName.setText(fileName.substring(1));
|
||||
viewHolder.imgIcon.setImageResource(R.drawable.ic_dialogx_filedialog_folder);
|
||||
viewHolder.btnHaveChild.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
viewHolder.txtFileName.setText(fileName);
|
||||
if (dialog.getSelectPathList() != null && dialog.getSelectPathList().contains(itemPath)) {
|
||||
viewHolder.imgIcon.setImageResource(R.drawable.ic_dialogx_filedialog_select);
|
||||
viewHolder.txtFileName.getPaint().setFakeBoldText(true);
|
||||
} else {
|
||||
viewHolder.imgIcon.setImageResource(R.drawable.ic_dialogx_filedialog_file);
|
||||
}
|
||||
viewHolder.btnHaveChild.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
if ((dialog.getMimeTypes() != null && dialog.getMimeTypes().length != 0) ||
|
||||
dialog.getSuffixArray() != null && dialog.getSuffixArray().length != 0) {
|
||||
if ("...".equals(fileName) || isFolder) {
|
||||
convertView.setAlpha(1f);
|
||||
} else {
|
||||
if (isSelectMimeType(itemPath) || isSelectSuffix(itemPath)) {
|
||||
convertView.setAlpha(1f);
|
||||
} else {
|
||||
convertView.setAlpha(0.3f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dialog.isShowFileDate() && !"...".equals(fileName)){
|
||||
viewHolder.txtDate.setText(getFileDate(activity,new File(itemPath)));
|
||||
viewHolder.txtDate.setVisibility(View.VISIBLE);
|
||||
}else{
|
||||
viewHolder.txtDate.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private boolean isSelectSuffix(String itemPath) {
|
||||
if (dialog.getSuffixArray() != null && dialog.getSuffixArray().length != 0) {
|
||||
for (String suffix : dialog.getSuffixArray()) {
|
||||
if (itemPath.toLowerCase().endsWith(suffix.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isSelectMimeType(String itemPath) {
|
||||
if (dialog.getMimeTypes() != null && dialog.getMimeTypes().length != 0) {
|
||||
for (String mime : dialog.getMimeTypes()) {
|
||||
if (mime.toUpperCase().equals(getMimeType(new File(itemPath)).toUpperCase())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getFileDate(Context context,File file) {
|
||||
Date lastModified = new Date(file.lastModified());
|
||||
Calendar fileCal = Calendar.getInstance();
|
||||
fileCal.setTime(lastModified);
|
||||
|
||||
Calendar today = Calendar.getInstance();
|
||||
Calendar yesterday = Calendar.getInstance();
|
||||
yesterday.add(Calendar.DATE, -1);
|
||||
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(context.getString(R.string.dialogx_filedialog_default_date_format));
|
||||
|
||||
if (fileCal.get(Calendar.YEAR) == today.get(Calendar.YEAR)
|
||||
&& fileCal.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) {
|
||||
SimpleDateFormat timeFormat = new SimpleDateFormat(context.getString(R.string.dialogx_filedialog_default_date_format_today));
|
||||
return timeFormat.format(lastModified);
|
||||
} else if (fileCal.get(Calendar.YEAR) == yesterday.get(Calendar.YEAR)
|
||||
&& fileCal.get(Calendar.DAY_OF_YEAR) == yesterday.get(Calendar.DAY_OF_YEAR)) {
|
||||
SimpleDateFormat timeFormat = new SimpleDateFormat(context.getString(R.string.dialogx_filedialog_default_date_format_yesterday));
|
||||
return timeFormat.format(lastModified);
|
||||
} else {
|
||||
return dateFormat.format(lastModified);
|
||||
}
|
||||
}
|
||||
|
||||
private String getMimeType(File file) {
|
||||
String suffix = getSuffix(file);
|
||||
if (suffix == null) {
|
||||
return "file/*";
|
||||
}
|
||||
String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(suffix);
|
||||
if (type != null && !type.isEmpty()) {
|
||||
return type;
|
||||
}
|
||||
return "file/*";
|
||||
}
|
||||
|
||||
private String getSuffix(File file) {
|
||||
if (file == null || !file.exists() || file.isDirectory()) {
|
||||
return null;
|
||||
}
|
||||
String fileName = file.getName();
|
||||
if (fileName.equals("") || fileName.endsWith(".")) {
|
||||
return null;
|
||||
}
|
||||
int index = fileName.lastIndexOf(".");
|
||||
if (index != -1) {
|
||||
return fileName.substring(index + 1).toLowerCase(Locale.US);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class ViewHolder {
|
||||
|
||||
ImageView imgIcon;
|
||||
TextView txtFileName;
|
||||
TextView txtDate;
|
||||
ImageView btnHaveChild;
|
||||
|
||||
public ViewHolder(View convertView) {
|
||||
imgIcon = convertView.findViewById(R.id.img_icon);
|
||||
txtFileName = convertView.findViewById(R.id.txt_fileName);
|
||||
txtDate = convertView.findViewById(R.id.txt_date);
|
||||
btnHaveChild = convertView.findViewById(R.id.btn_have_child);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.kongzue.filedialog.interfaces;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author: Kongzue
|
||||
* @github: https://github.com/kongzue/
|
||||
* @homepage: http://kongzue.com/
|
||||
* @mail: myzcxhh@live.cn
|
||||
* @createTime: 2022/3/3 13:04
|
||||
*/
|
||||
public abstract class FileSelectCallBack {
|
||||
|
||||
public void onSelect(File file,String filePath){};
|
||||
|
||||
public void onMultiSelect(File[] file,String[] filePath){};
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.kongzue.filedialog.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.kongzue.dialogx.interfaces.ScrollController;
|
||||
|
||||
/**
|
||||
* @author: Kongzue
|
||||
* @github: https://github.com/kongzue/
|
||||
* @homepage: http://kongzue.com/
|
||||
* @mail: myzcxhh@live.cn
|
||||
* @createTime: 2022/3/3 23:45
|
||||
*/
|
||||
public class FileListView extends ListView implements ScrollController {
|
||||
public FileListView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public FileListView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public FileListView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
boolean lockScroll;
|
||||
|
||||
@Override
|
||||
public boolean isLockScroll() {
|
||||
return lockScroll;
|
||||
}
|
||||
|
||||
public void lockScroll(boolean lockScroll) {
|
||||
this.lockScroll = lockScroll;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScrollDistance() {
|
||||
View c = getChildAt(0);
|
||||
if (c == null) {
|
||||
return 0;
|
||||
}
|
||||
int firstVisiblePosition = getFirstVisiblePosition();
|
||||
int top = c.getTop();
|
||||
int scrollY = -top + firstVisiblePosition * c.getHeight();
|
||||
return scrollY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCanScroll() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
if (lockScroll) {
|
||||
return false;
|
||||
}
|
||||
return super.onTouchEvent(ev);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#9C9C9C"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>
|
||||
</vector>
|
@ -0,0 +1,11 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#2196F3"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M14,2H6c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2H18c1.1,0 2,-0.9 2,-2V8l-6,-6zM6,20V4h7v5h5v11H6z"/>
|
||||
</vector>
|
@ -0,0 +1,11 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#2196F3"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M20,6h-8l-2,-2L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,8c0,-1.1 -0.9,-2 -2,-2zM20,18L4,18L4,8h16v10z"/>
|
||||
</vector>
|
@ -0,0 +1,11 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#9C9C9C"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M10,6L8.59,7.41 13.17,12l-4.58,4.59L10,18l6,-6z"/>
|
||||
</vector>
|
@ -0,0 +1,16 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#2196F3"
|
||||
android:alpha="0.8">
|
||||
<group android:scaleX="1.2"
|
||||
android:scaleY="1.2"
|
||||
android:translateX="-2.4"
|
||||
android:translateY="-2.4">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM10,17l-5,-5 1.41,-1.41L10,14.17l7.59,-7.59L19,8l-9,9z"/>
|
||||
</group>
|
||||
</vector>
|
After Width: | Height: | Size: 186 B |
After Width: | Height: | Size: 282 B |
After Width: | Height: | Size: 259 B |
After Width: | Height: | Size: 150 B |
After Width: | Height: | Size: 537 B |
After Width: | Height: | Size: 152 B |
After Width: | Height: | Size: 208 B |
After Width: | Height: | Size: 203 B |
After Width: | Height: | Size: 138 B |
After Width: | Height: | Size: 399 B |
After Width: | Height: | Size: 211 B |
After Width: | Height: | Size: 388 B |
After Width: | Height: | Size: 337 B |
After Width: | Height: | Size: 185 B |
After Width: | Height: | Size: 702 B |
After Width: | Height: | Size: 320 B |
After Width: | Height: | Size: 636 B |
After Width: | Height: | Size: 512 B |
After Width: | Height: | Size: 247 B |
After Width: | Height: | Size: 1.6 KiB |
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<inset xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:insetLeft="75dp"
|
||||
android:insetRight="0dp"
|
||||
android:drawable="@color/black20">
|
||||
|
||||
</inset>
|
50
FileDialog/src/main/res/layout/item_dialogx_file_list.xml
Normal file
@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/img_icon"
|
||||
android:layout_width="55dp"
|
||||
android:layout_height="55dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:padding="15dp"
|
||||
android:src="@drawable/ic_dialogx_filedialog_folder" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_fileName"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Folder"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="16dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_date"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
tools:text="2024年1月1日 23:33"
|
||||
android:textColor="@color/black50"
|
||||
android:textSize="12dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/btn_have_child"
|
||||
android:layout_width="55dp"
|
||||
android:layout_height="55dp"
|
||||
android:padding="15dp"
|
||||
android:src="@drawable/ic_dialogx_filedialog_right" />
|
||||
|
||||
</LinearLayout>
|
101
FileDialog/src/main/res/layout/layout_dialogx_file_select.xml
Normal file
@ -0,0 +1,101 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/btn_cancel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="15dp"
|
||||
android:text="@string/dialogx_filedialog_cancel"
|
||||
android:textColor="@color/dialogxColorBlue"
|
||||
android:textSize="16dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_dialog_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="15dp"
|
||||
android:text="@string/dialogx_filedialog_title_file"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="18dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/btn_select"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="15dp"
|
||||
android:text="@string/dialogx_filedialog_select"
|
||||
android:textColor="@color/dialogxColorBlue"
|
||||
android:textSize="16dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<HorizontalScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="35dp"
|
||||
android:fadingEdge="horizontal"
|
||||
android:fadingEdgeLength="30dp"
|
||||
android:requiresFadingEdge="horizontal"
|
||||
android:overScrollMode="never"
|
||||
android:scrollbars="none">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txt_path"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:textIsSelectable="true"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="15dp"
|
||||
android:text=""
|
||||
android:textColor="@color/black80"
|
||||
android:textSize="14dp" />
|
||||
|
||||
</HorizontalScrollView>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.kongzue.filedialog.util.FileListView
|
||||
android:id="@+id/list_file"
|
||||
android:tag="ScrollController"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:listSelector="@color/empty"
|
||||
android:divider="@drawable/split_dialogx_filedialog_listitem"
|
||||
android:dividerHeight="1px"
|
||||
tools:listitem="@layout/item_dialogx_file_list" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/img_file_list_screenshot"
|
||||
android:layout_width="match_parent"
|
||||
android:visibility="gone"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
13
FileDialog/src/main/res/values/strings.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="dialogx_filedialog_title_file">选择文件</string>
|
||||
<string name="dialogx_filedialog_title_folder">选择文件夹</string>
|
||||
<string name="dialogx_filedialog_select">选择</string>
|
||||
<string name="dialogx_filedialog_cancel">取消</string>
|
||||
<string name="error_dialogx_filedialog_max_selection_tip">最多可选择 %s 个文件</string>
|
||||
<string name="error_dialogx_filedialog_no_support_file_type_tip">不支持此文件类型</string>
|
||||
<string name="error_dialogx_filedialog_no_file_selected_tip">请选择文件</string>
|
||||
<string name="dialogx_filedialog_default_date_format">yyyy年M月d日 HH:mm</string>
|
||||
<string name="dialogx_filedialog_default_date_format_today">今天 HH:mm</string>
|
||||
<string name="dialogx_filedialog_default_date_format_yesterday">昨天 HH:mm</string>
|
||||
</resources>
|
@ -130,5 +130,6 @@ dependencies {
|
||||
implementation 'com.github.li-xiaojun:XPopup:v2.2.23'
|
||||
|
||||
implementation project(path: ':AlbumDialog')
|
||||
implementation project(path: ':FileDialog')
|
||||
implementation project(path: ':TimePickerDialog')
|
||||
}
|
||||
|
@ -47,9 +47,9 @@ public class GacApplication extends Application {
|
||||
private void initHttp() {
|
||||
HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory();
|
||||
OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
||||
.connectTimeout(10, TimeUnit.SECONDS)
|
||||
.readTimeout(10, TimeUnit.SECONDS)
|
||||
.writeTimeout(10, TimeUnit.SECONDS)
|
||||
.connectTimeout(60, TimeUnit.SECONDS)
|
||||
.readTimeout(60, TimeUnit.SECONDS)
|
||||
.writeTimeout(60, TimeUnit.SECONDS)
|
||||
.sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)
|
||||
.hostnameVerifier((hostname, session) -> true)
|
||||
.dns(new ApiDns())
|
||||
|
@ -28,7 +28,8 @@ public class Api {
|
||||
*/
|
||||
public static final String STR_AUTHORIZATION = "Authorization";
|
||||
|
||||
public static final String UPDATE_APP = BASE_HOST + "/checkUpdate";
|
||||
public static final String UPDATE_APP = BASE_HOST + "/user-center/appVersionManager/getLastestVesion";
|
||||
public static final String ADD_APP = BASE_HOST + "/user-center/appVersionManager/addVersionInfo";
|
||||
|
||||
public static final String LOGIN = BASE_HOST + "/auth/app/login";
|
||||
public static final String LOGOUT = BASE_HOST + "/auth/logout";
|
||||
|
@ -8,6 +8,8 @@ public class Constant {
|
||||
|
||||
public static String LOGIN_USER_NAME = "login_user_name";
|
||||
|
||||
public static String SELECT_AREA = "select_area";
|
||||
|
||||
public static String SELECT_REGION = "select_region";
|
||||
|
||||
public static String SELECT_GRID = "select_grid";
|
||||
|
@ -0,0 +1,107 @@
|
||||
package com.tairui.gov_affairs_cloud.entity;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class UpdateEntity {
|
||||
|
||||
@SerializedName("id")
|
||||
private Integer id;
|
||||
@SerializedName("versionCode")
|
||||
private String versionCode;
|
||||
@SerializedName("versionName")
|
||||
private String versionName;
|
||||
@SerializedName("versionDesc")
|
||||
private String versionDesc;
|
||||
@SerializedName("downloadUrl")
|
||||
private String downloadUrl;
|
||||
@SerializedName("forceUpdate")
|
||||
private String forceUpdate;
|
||||
@SerializedName("phoneType")
|
||||
private String phoneType;
|
||||
@SerializedName("upTime")
|
||||
private String upTime;
|
||||
@SerializedName("createTime")
|
||||
private String createTime;
|
||||
@SerializedName("createUser")
|
||||
private Integer createUser;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getVersionCode() {
|
||||
return versionCode;
|
||||
}
|
||||
|
||||
public void setVersionCode(String versionCode) {
|
||||
this.versionCode = versionCode;
|
||||
}
|
||||
|
||||
public String getVersionName() {
|
||||
return versionName;
|
||||
}
|
||||
|
||||
public void setVersionName(String versionName) {
|
||||
this.versionName = versionName;
|
||||
}
|
||||
|
||||
public String getVersionDesc() {
|
||||
return versionDesc;
|
||||
}
|
||||
|
||||
public void setVersionDesc(String versionDesc) {
|
||||
this.versionDesc = versionDesc;
|
||||
}
|
||||
|
||||
public String getDownloadUrl() {
|
||||
return downloadUrl;
|
||||
}
|
||||
|
||||
public void setDownloadUrl(String downloadUrl) {
|
||||
this.downloadUrl = downloadUrl;
|
||||
}
|
||||
|
||||
public String getForceUpdate() {
|
||||
return forceUpdate;
|
||||
}
|
||||
|
||||
public void setForceUpdate(String forceUpdate) {
|
||||
this.forceUpdate = forceUpdate;
|
||||
}
|
||||
|
||||
public String getPhoneType() {
|
||||
return phoneType;
|
||||
}
|
||||
|
||||
public void setPhoneType(String phoneType) {
|
||||
this.phoneType = phoneType;
|
||||
}
|
||||
|
||||
public String getUpTime() {
|
||||
return upTime;
|
||||
}
|
||||
|
||||
public void setUpTime(String upTime) {
|
||||
this.upTime = upTime;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public Integer getCreateUser() {
|
||||
return createUser;
|
||||
}
|
||||
|
||||
public void setCreateUser(Integer createUser) {
|
||||
this.createUser = createUser;
|
||||
}
|
||||
}
|
@ -15,12 +15,14 @@ import com.tairui.gov_affairs_cloud.base.adapter.TabFragmentPagerAdapter;
|
||||
import com.tairui.gov_affairs_cloud.databinding.ActivityMainBinding;
|
||||
import com.tairui.gov_affairs_cloud.entity.Api;
|
||||
import com.tairui.gov_affairs_cloud.entity.TabEntity;
|
||||
import com.tairui.gov_affairs_cloud.entity.UpdateEntity;
|
||||
import com.tairui.gov_affairs_cloud.http.OnError;
|
||||
import com.tairui.gov_affairs_cloud.ui.ai.AiFragment;
|
||||
import com.tairui.gov_affairs_cloud.ui.home.HomeFragment;
|
||||
import com.tairui.gov_affairs_cloud.ui.my.MyFragment;
|
||||
import com.tairui.gov_affairs_cloud.ui.todo.TodoFragment;
|
||||
import com.tairui.gov_affairs_cloud.ui.workspace.WorkSpaceFragment;
|
||||
import com.tairui.gov_affairs_cloud.util.AppUtil;
|
||||
import com.tairui.gov_affairs_cloud.util.DownloadUtil;
|
||||
import com.tairui.gov_affairs_cloud.util.LogUtil;
|
||||
import com.tairui.gov_affairs_cloud.util.NetUtil;
|
||||
@ -137,19 +139,25 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> {
|
||||
|
||||
@Override
|
||||
protected void onApplyData() {
|
||||
super.onApplyData();
|
||||
// getAppVersionInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取线上APP的版本信息
|
||||
*/
|
||||
private void getAppVersionInfo() {
|
||||
RxHttp.get(Api.UPDATE_APP)
|
||||
.asResponse(Object.class)
|
||||
RxHttp.postJson(Api.UPDATE_APP)
|
||||
.add("phoneType", "1")
|
||||
.add("platform", "1")
|
||||
.asResponse(UpdateEntity.class)
|
||||
.as(RxLife.asOnMain(this))
|
||||
.subscribe(data -> {
|
||||
//TODO
|
||||
|
||||
int currentVersionCode = AppUtil.getVersionCode(mContext);
|
||||
int onlineVersionCode = Integer.parseInt(data.getVersionCode());
|
||||
if (onlineVersionCode > currentVersionCode) {
|
||||
int grade = Integer.parseInt(data.getForceUpdate());
|
||||
showUpdateDialog(grade, AppUtil.getImageUrl(data.getDownloadUrl()), data.getVersionDesc());
|
||||
}
|
||||
}, (OnError) error -> {
|
||||
LogUtil.e("getAppVersionInfo", error.getErrorMsg());
|
||||
});
|
||||
|
@ -77,7 +77,9 @@ public class UtilizationControlActivity extends BaseActivity<ActivityUtilization
|
||||
|
||||
@Override
|
||||
protected void onFindView(Bundle savedInstanceState) {
|
||||
setText(binding.tvRegion, selectRegion.getAreaName() + "-" + selectGrid.getGridName());
|
||||
if (selectRegion != null && selectGrid != null) {
|
||||
setText(binding.tvRegion, selectRegion.getAreaName() + "-" + selectGrid.getGridName());
|
||||
}
|
||||
binding.refreshRecycler.setLayoutManager(new LinearLayoutManager(mContext));
|
||||
adapter = new UtilizationControlAdapter();
|
||||
binding.refreshRecycler.setAdapter(adapter);
|
||||
|
@ -12,6 +12,7 @@ import com.tairui.gov_affairs_cloud.databinding.ActivityLandBinding;
|
||||
import com.tairui.gov_affairs_cloud.entity.Api;
|
||||
import com.tairui.gov_affairs_cloud.entity.RoseBean;
|
||||
import com.tairui.gov_affairs_cloud.http.OnError;
|
||||
import com.tairui.gov_affairs_cloud.ui.land.entity.ItemLandEntity;
|
||||
import com.tairui.gov_affairs_cloud.ui.land.entity.LandOverviewEntity;
|
||||
import com.tairui.gov_affairs_cloud.util.DensityUtils;
|
||||
import com.tairui.gov_affairs_cloud.util.SingleClickListener;
|
||||
@ -70,25 +71,106 @@ public class LandActivity extends BaseActivity<ActivityLandBinding> {
|
||||
setGone(binding.landTotalChart, false);
|
||||
binding.landItemChart.setLoading(true);
|
||||
setGone(binding.landItemChart, true);
|
||||
LandOverviewEntity.ListEntity item = landOverviewAdapter.getData().get(i);
|
||||
getItemLandData(item.getLandTypeId());
|
||||
// LandOverviewEntity.ListEntity item = landOverviewAdapter.getData().get(i);
|
||||
// getItemLandData(item.getLandTypeId());
|
||||
generateSubAreaData(i);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void generateSubAreaData(int index) {
|
||||
List<String> strXList = new ArrayList<>();
|
||||
List<List<BarBean>> dataList = new ArrayList<>();
|
||||
if (index == 1) {
|
||||
List<BarBean> list = new ArrayList<>();
|
||||
list.add(new BarBean(13.98f, "水田"));
|
||||
dataList.add(list);
|
||||
strXList.add("水田");
|
||||
|
||||
list = new ArrayList<>();
|
||||
list.add(new BarBean(52.05f, "旱地"));
|
||||
dataList.add(list);
|
||||
strXList.add("旱地");
|
||||
|
||||
list = new ArrayList<>();
|
||||
list.add(new BarBean(33.01f, "水耕地"));
|
||||
dataList.add(list);
|
||||
strXList.add("水耕地");
|
||||
} else if (index == 2) {
|
||||
List<BarBean> list = new ArrayList<>();
|
||||
list.add(new BarBean(13.98f, "果园"));
|
||||
dataList.add(list);
|
||||
strXList.add("果园");
|
||||
|
||||
list = new ArrayList<>();
|
||||
list.add(new BarBean(52.05f, "茶园"));
|
||||
dataList.add(list);
|
||||
strXList.add("茶园");
|
||||
|
||||
list = new ArrayList<>();
|
||||
list.add(new BarBean(33.01f, "橡胶园"));
|
||||
dataList.add(list);
|
||||
strXList.add("橡胶园");
|
||||
|
||||
list = new ArrayList<>();
|
||||
list.add(new BarBean(33.01f, "其他园地"));
|
||||
dataList.add(list);
|
||||
strXList.add("其他园地");
|
||||
}else if (index == 3) {
|
||||
List<BarBean> list = new ArrayList<>();
|
||||
list.add(new BarBean(58.32f, "灌木林地"));
|
||||
dataList.add(list);
|
||||
strXList.add("灌木林地");
|
||||
|
||||
list = new ArrayList<>();
|
||||
list.add(new BarBean(61.75f, "竹林地"));
|
||||
dataList.add(list);
|
||||
strXList.add("竹林地");
|
||||
|
||||
list = new ArrayList<>();
|
||||
list.add(new BarBean(59.28f, "乔木林地"));
|
||||
dataList.add(list);
|
||||
strXList.add("乔木林地");
|
||||
|
||||
list = new ArrayList<>();
|
||||
list.add(new BarBean(57.64f, "红树林地"));
|
||||
dataList.add(list);
|
||||
strXList.add("红树林地");
|
||||
|
||||
list = new ArrayList<>();
|
||||
list.add(new BarBean(62.19f, "森林沼泽"));
|
||||
dataList.add(list);
|
||||
strXList.add("森林沼泽");
|
||||
|
||||
list = new ArrayList<>();
|
||||
list.add(new BarBean(56.47f, "灌木沼泽"));
|
||||
dataList.add(list);
|
||||
strXList.add("灌木沼泽");
|
||||
|
||||
list = new ArrayList<>();
|
||||
list.add(new BarBean(48.35f, "其他林地"));
|
||||
dataList.add(list);
|
||||
strXList.add("其他林地");
|
||||
}
|
||||
binding.landItemChart.setLoading(false);
|
||||
binding.landItemChart.setData(dataList, strXList);
|
||||
}
|
||||
|
||||
private void getItemLandData(String pid) {
|
||||
RxHttp.get(Api.LAND_SUB_AREA)
|
||||
.add("pid", pid)
|
||||
.asResponseList(LandOverviewEntity.ListEntity.class)
|
||||
.asResponse(ItemLandEntity.class)
|
||||
.as(RxLife.asOnMain(this))
|
||||
.subscribe(data -> {
|
||||
initSubAreaChart(data);
|
||||
initSubAreaChart(data.getData());
|
||||
}, (OnError) error -> showToast(error.getErrorMsg()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onApplyData() {
|
||||
getLandOverViewData();
|
||||
// getLandOverViewData();
|
||||
generateData();
|
||||
}
|
||||
|
||||
private void getLandOverViewData() {
|
||||
@ -100,6 +182,45 @@ public class LandActivity extends BaseActivity<ActivityLandBinding> {
|
||||
}, (OnError) error -> showToast(error.getErrorMsg()));
|
||||
}
|
||||
|
||||
private void generateData() {
|
||||
List<LandOverviewEntity.ListEntity> list = new ArrayList<>();
|
||||
List<Object> chartDataList = new ArrayList<>();
|
||||
LandOverviewEntity.ListEntity totalItem = new LandOverviewEntity.ListEntity();
|
||||
totalItem.setLandTypeName("土地总");
|
||||
totalItem.setArea(575.55F);
|
||||
totalItem.setLandTypeId("-1");
|
||||
list.add(totalItem);
|
||||
|
||||
LandOverviewEntity.ListEntity item1 = new LandOverviewEntity.ListEntity();
|
||||
item1.setLandTypeName("耕地");
|
||||
item1.setArea(142.19f);
|
||||
item1.setLandTypeId("1");
|
||||
list.add(item1);
|
||||
chartDataList.add(new RoseBean(142.19f, "耕地"));
|
||||
|
||||
LandOverviewEntity.ListEntity item2 = new LandOverviewEntity.ListEntity();
|
||||
item2.setLandTypeName("园地");
|
||||
item2.setArea(44.69f);
|
||||
item2.setLandTypeId("2");
|
||||
list.add(item2);
|
||||
chartDataList.add(new RoseBean(44.69f, "园地"));
|
||||
|
||||
LandOverviewEntity.ListEntity item3 = new LandOverviewEntity.ListEntity();
|
||||
item3.setLandTypeName("林地");
|
||||
item3.setArea(404f);
|
||||
item3.setLandTypeId("3");
|
||||
list.add(item3);
|
||||
chartDataList.add(new RoseBean(404f, "林地"));
|
||||
|
||||
binding.recycleView.setLayoutManager(new GridLayoutManager(mContext, 2));
|
||||
binding.recycleView.addItemDecoration(new GridSpacingItemDecoration(2, DensityUtils.dp2px(mContext, 10), true));
|
||||
landOverviewAdapter.setNewData(list);
|
||||
binding.recycleView.setAdapter(landOverviewAdapter);
|
||||
|
||||
binding.landTotalChart.setData(RoseBean.class, "count", "ClassName", chartDataList);
|
||||
binding.landTotalChart.setLoading(false);//是否正在加载,数据加载完毕后置为false
|
||||
}
|
||||
|
||||
private void initView(LandOverviewEntity overviewEntity) {
|
||||
List<Object> chartDataList = new ArrayList<>();
|
||||
for (LandOverviewEntity.ListEntity listEntity : overviewEntity.getList()) {
|
||||
@ -121,10 +242,10 @@ public class LandActivity extends BaseActivity<ActivityLandBinding> {
|
||||
binding.recycleView.setAdapter(landOverviewAdapter);
|
||||
}
|
||||
|
||||
private void initSubAreaChart(List<LandOverviewEntity.ListEntity> data) {
|
||||
private void initSubAreaChart(List<ItemLandEntity.DataEntity> data) {
|
||||
List<String> strXList = new ArrayList<>();
|
||||
List<List<BarBean>> dataList = new ArrayList<>( );
|
||||
for (LandOverviewEntity.ListEntity entity : data) {
|
||||
List<List<BarBean>> dataList = new ArrayList<>();
|
||||
for (ItemLandEntity.DataEntity entity : data) {
|
||||
List<BarBean> list = new ArrayList<>();
|
||||
list.add(new BarBean(entity.getArea(), entity.getLandTypeName()));
|
||||
dataList.add(list);
|
||||
|
@ -7,12 +7,14 @@ import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
|
||||
import com.bigkoo.pickerview.view.OptionsPickerView;
|
||||
import com.orhanobut.hawk.Hawk;
|
||||
import com.rxjava.rxlife.RxLife;
|
||||
import com.tairui.gov_affairs_cloud.base.BaseActivity;
|
||||
import com.tairui.gov_affairs_cloud.base.BaseFragment;
|
||||
import com.tairui.gov_affairs_cloud.base.adapter.TabFragmentPagerAdapter;
|
||||
import com.tairui.gov_affairs_cloud.databinding.ActivityLandResourceInfoBinding;
|
||||
import com.tairui.gov_affairs_cloud.entity.Api;
|
||||
import com.tairui.gov_affairs_cloud.entity.Constant;
|
||||
import com.tairui.gov_affairs_cloud.entity.EventConstant;
|
||||
import com.tairui.gov_affairs_cloud.entity.EventMessage;
|
||||
import com.tairui.gov_affairs_cloud.http.OnError;
|
||||
@ -37,6 +39,7 @@ public class LandResouceInfoActivity extends BaseActivity<ActivityLandResourceIn
|
||||
private List<LandAreaRegionEntity> landAreaRegionData = new ArrayList<>();
|
||||
private List<LandResourceTypeEntity> landResourceTypeData = new ArrayList<>();
|
||||
private LandAreaRegionEntity selectRegion;
|
||||
private LandAreaRegionEntity selectArea;
|
||||
private OptionsPickerView landRegionPickerView;
|
||||
|
||||
@Override
|
||||
@ -57,9 +60,22 @@ public class LandResouceInfoActivity extends BaseActivity<ActivityLandResourceIn
|
||||
binding.viewPager.setCurrentItem(0, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onQueryArguments() {
|
||||
if (Hawk.contains(Constant.SELECT_REGION)) {
|
||||
selectRegion = Hawk.get(Constant.SELECT_REGION);
|
||||
}
|
||||
if (Hawk.contains(Constant.SELECT_AREA)) {
|
||||
selectArea = Hawk.get(Constant.SELECT_AREA);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFindView(Bundle savedInstanceState) {
|
||||
binding.viewPager.setIsCanScroll(true);
|
||||
if (selectArea != null && selectRegion != null) {
|
||||
setText(binding.tvLocation, selectArea.getAreaName() + selectRegion.getAreaName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -100,9 +116,12 @@ public class LandResouceInfoActivity extends BaseActivity<ActivityLandResourceIn
|
||||
}
|
||||
|
||||
landRegionPickerView = new OptionsPickerBuilder(this, (options1, options2, options3, v) -> {
|
||||
selectArea = landAreaRegionData.get(0).getAreaChildVOS().get(options1);
|
||||
selectRegion = landAreaRegionData.get(0).getAreaChildVOS().get(options1).getAreaChildVOS().get(options2);
|
||||
setText(binding.tvLocation,
|
||||
landAreaRegionData.get(0).getAreaChildVOS().get(options1).getAreaName() + selectRegion.getAreaName());
|
||||
Hawk.put(Constant.SELECT_AREA, selectArea);
|
||||
Hawk.put(Constant.SELECT_REGION, selectRegion);
|
||||
Hawk.delete(Constant.SELECT_GRID);
|
||||
setText(binding.tvLocation, selectArea.getAreaName() + selectRegion.getAreaName());
|
||||
EventBus.getDefault().post(new EventMessage(EventConstant.REFRESH_LIST, selectRegion.getAreaCode()));
|
||||
}).setTitleText("土地区域选择").setContentTextSize(20)//设置滚轮文字大小
|
||||
.setSelectOptions(0, 0)//默认选中项
|
||||
|
@ -241,7 +241,9 @@ public class PlantPlanActivity extends BaseActivity<ActivityPlantPlanBinding> {
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
setText(binding.tvRegion, selectRegion.getAreaName() + "-" + selectGrid.getGridName());
|
||||
if (selectRegion != null && selectGrid != null) {
|
||||
setText(binding.tvRegion, selectRegion.getAreaName() + "-" + selectGrid.getGridName());
|
||||
}
|
||||
setText(binding.tvYear, DateUtils.getCurrentYear() + "年种植计划");
|
||||
setText(binding.tvPlanArea, String.valueOf(mData.getTotal().getTotalPlanArea()));
|
||||
setText(binding.tvRealArea, String.valueOf(mData.getTotal().getTotalActualArea()));
|
||||
|
@ -82,7 +82,9 @@ public class PlantPlanListActivity extends BaseActivity<ActivityPlantPlanListBin
|
||||
binding.refreshRecycler.setLayoutManager(new LinearLayoutManager(mContext));
|
||||
mAdapter = new PlantPlanListAdapter();
|
||||
binding.refreshRecycler.setAdapter(mAdapter);
|
||||
setText(binding.tvRegion, selectRegion.getAreaName() + "-" + selectGrid.getGridName());
|
||||
if (selectRegion != null && selectGrid != null) {
|
||||
setText(binding.tvRegion, selectRegion.getAreaName() + "-" + selectGrid.getGridName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,72 @@
|
||||
package com.tairui.gov_affairs_cloud.ui.land.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class ItemLandEntity {
|
||||
|
||||
@SerializedName("title")
|
||||
private String title;
|
||||
@SerializedName("data")
|
||||
private List<DataEntity> data;
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public List<DataEntity> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(List<DataEntity> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public static class DataEntity {
|
||||
@SerializedName("landTypeId")
|
||||
private String landTypeId;
|
||||
@SerializedName("landTypeName")
|
||||
private String landTypeName;
|
||||
@SerializedName("area")
|
||||
private float area;
|
||||
@SerializedName("pid")
|
||||
private String pid;
|
||||
|
||||
public String getLandTypeId() {
|
||||
return landTypeId;
|
||||
}
|
||||
|
||||
public void setLandTypeId(String landTypeId) {
|
||||
this.landTypeId = landTypeId;
|
||||
}
|
||||
|
||||
public String getLandTypeName() {
|
||||
return landTypeName;
|
||||
}
|
||||
|
||||
public void setLandTypeName(String landTypeName) {
|
||||
this.landTypeName = landTypeName;
|
||||
}
|
||||
|
||||
public float getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
public void setArea(float area) {
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
public String getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(String pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
}
|
||||
}
|
@ -2,11 +2,14 @@ package com.tairui.gov_affairs_cloud.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.tairui.gov_affairs_cloud.BuildConfig;
|
||||
import com.tairui.gov_affairs_cloud.entity.Api;
|
||||
import com.tairui.gov_affairs_cloud.ui.photoview.PhotoViewActivty;
|
||||
import com.tairui.gov_affairs_cloud.widget.loading.LoadingDialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
@ -50,4 +53,25 @@ public class AppUtil {
|
||||
bundle.putString("id", id);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取应用的 Version Code
|
||||
*/
|
||||
public static int getVersionCode(Context context) {
|
||||
try {
|
||||
PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
|
||||
return getVersionCodeFromPackageInfo(pInfo);
|
||||
} catch (Exception e) {
|
||||
return BuildConfig.VERSION_CODE; // 降级方案
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static int getVersionCodeFromPackageInfo(PackageInfo pInfo) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
return (int) pInfo.getLongVersionCode(); // API 28+ 使用 long
|
||||
} else {
|
||||
return pInfo.versionCode; // 传统方式
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -360,8 +360,7 @@
|
||||
android:paddingLeft="12dp"
|
||||
android:text="重新选择"
|
||||
android:textColor="@color/color_blue"
|
||||
android:textSize="13sp"
|
||||
android:visibility="gone" />
|
||||
android:textSize="13sp"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
77
app/src/main/res/layout/activity_upload.xml
Normal file
@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tl="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/white"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSelect"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="选择文件" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvUrl"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:hint="文件地址"
|
||||
android:textColor="@color/color_txt_black"
|
||||
android:textColorHint="@color/color_txt_label"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/tvVersionCode"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:hint="版本号 int"
|
||||
android:textColor="@color/color_txt_black"
|
||||
android:textColorHint="@color/color_txt_label"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/tvVersionName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:hint="版本名 String"
|
||||
android:textColor="@color/color_txt_black"
|
||||
android:textColorHint="@color/color_txt_label"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/tvVersionDesc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:gravity="left|top"
|
||||
android:hint="更新描述"
|
||||
android:minHeight="200dp"
|
||||
android:textColor="@color/color_txt_black"
|
||||
android:textColorHint="@color/color_txt_label"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/tvForceUpdate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:hint="是否强制更新 1:是,0:否"
|
||||
android:textColor="@color/color_txt_black"
|
||||
android:textColorHint="@color/color_txt_label"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSubmit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="提交" />
|
||||
|
||||
|
||||
</LinearLayout>
|
@ -4,3 +4,4 @@ include ':DialogX'
|
||||
include ':DialogXInterface'
|
||||
include ':DialogXMaterialYou'
|
||||
include ':TimePickerDialog'
|
||||
include ':FileDialog'
|
||||
|