Commit f5decb73 by Yu_Tung

修改MideaStore出現已經刪除的影片

parent 1f7eb234
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
<activity android:name=".ui.main.MainActivity" <activity android:name=".ui.main.MainActivity"
android:screenOrientation="portrait"/> android:screenOrientation="portrait"/>
<provider <provider
android:name="androidx.core.content.FileProvider" android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider" android:authorities="${applicationId}.provider"
......
...@@ -33,7 +33,7 @@ public class LoginPresenter<V extends LoginContract.View> implements LoginContra ...@@ -33,7 +33,7 @@ public class LoginPresenter<V extends LoginContract.View> implements LoginContra
@Override @Override
public void onLogin(String account, String password) { public void onLogin(String account, String password) {
String url = view.getResourceString(R.string.api_on_Login); String url = view.getResourceString(R.string.api_on_Login);
// LoginRequest mLoginRequest = new LoginRequest(LOGIN_AUTHORIZED_ID, "N000158385", "781122222"); // LoginRequest mLoginRequest = new LoginRequest(LOGIN_AUTHORIZED_ID, "N000042089", "566345");
LoginRequest mLoginRequest = new LoginRequest(LOGIN_AUTHORIZED_ID, account, password); LoginRequest mLoginRequest = new LoginRequest(LOGIN_AUTHORIZED_ID, account, password);
compositeDisposable.add(api.onLogin(url, mLoginRequest) compositeDisposable.add(api.onLogin(url, mLoginRequest)
.subscribeOn(schedulerProviderImp.io()) .subscribeOn(schedulerProviderImp.io())
......
...@@ -14,11 +14,12 @@ import android.content.pm.PackageManager; ...@@ -14,11 +14,12 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.media.MediaScannerConnection;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -46,6 +47,7 @@ import org.json.JSONObject; ...@@ -46,6 +47,7 @@ import org.json.JSONObject;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
...@@ -268,8 +270,8 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie ...@@ -268,8 +270,8 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmss"); SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmss");
String formattedDate = df.format(c); String formattedDate = df.format(c);
fileName = "IMG_"+formattedDate + ".jpg"; fileName = "IMG_" + formattedDate + ".jpg";
imageFilePhth = path + "/" +fileName; imageFilePhth = path + "/" + fileName;
// fileName = System.currentTimeMillis() + ""; // fileName = System.currentTimeMillis() + "";
Log.e("filepath", imageFilePhth); Log.e("filepath", imageFilePhth);
File file1 = new File(imageFilePhth); File file1 = new File(imageFilePhth);
...@@ -284,7 +286,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie ...@@ -284,7 +286,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
// MediaStore.Images.Media.insertImage(this.getContentResolver(), bitmap, "", ""); // MediaStore.Images.Media.insertImage(this.getContentResolver(), bitmap, "", "");
//要改掉下面那行 //要改掉下面那行
// this.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file1.getAbsolutePath()))); // this.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file1.getAbsolutePath())));
changeFileNameCheckDialog(imageFilePhth,fileName); changeFileNameCheckDialog(imageFilePhth, fileName);
// context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+ Environment.getExternalStorageDirectory()))); // context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
} catch (Exception e) { } catch (Exception e) {
...@@ -344,8 +346,11 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie ...@@ -344,8 +346,11 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
videoFilePath = MagicFileChooser.getAbsolutePathFromUri(this, videoUri); videoFilePath = MagicFileChooser.getAbsolutePathFromUri(this, videoUri);
File file = new File(videoFilePath); File file = new File(videoFilePath);
String name = (file.getName()); String name = (file.getName());
changeFileNameCheckDialog(videoFilePath,name); changeFileNameCheckDialog(videoFilePath, name);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Files.move(videoFilePath,Environment.getDataDirectory().toString(),REPLACE)
// }
} }
...@@ -364,6 +369,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie ...@@ -364,6 +369,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
mPresenter.onGetSid(uriList, getResourceString(R.string.on_upload_image)); mPresenter.onGetSid(uriList, getResourceString(R.string.on_upload_image));
} }
if (requestCode == PICK_VIDEO_FROM_GALLERY_REQUEST_CODE && resultCode == RESULT_OK) { if (requestCode == PICK_VIDEO_FROM_GALLERY_REQUEST_CODE && resultCode == RESULT_OK) {
ArrayList<String> uriList = new ArrayList<String>(); ArrayList<String> uriList = new ArrayList<String>();
...@@ -393,8 +399,8 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie ...@@ -393,8 +399,8 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
ArrayList<String> VideoList = new ArrayList<>(); ArrayList<String> VideoList = new ArrayList<>();
VideoList.add(path); VideoList.add(path);
Log.e("Listsize",VideoList.size()+""); Log.e("Listsize", VideoList.size() + "");
Log.e("List",VideoList.get(0)); Log.e("List", VideoList.get(0));
mPresenter.onGetSid(VideoList, getResourceString(R.string.on_upload_vedio)); mPresenter.onGetSid(VideoList, getResourceString(R.string.on_upload_vedio));
// TODO here==================== // TODO here====================
//影片的uri //影片的uri
...@@ -497,7 +503,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie ...@@ -497,7 +503,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
if (mChooseDeviceItemData.getProductionPlantId().equals("")) { if (mChooseDeviceItemData.getProductionPlantId().equals("")) {
showDialogCaveatMessage(getResourceString(R.string.add_device_no_production_plant_error)); showDialogCaveatMessage(getResourceString(R.string.add_device_no_production_plant_error));
} }
mPresenter.onGetSHIFTData(mChooseDeviceItemData.getCompanyId(), mChooseDeviceItemData.getProductionPlantId(),mChooseDeviceItemData.getFactoryClassCode()); mPresenter.onGetSHIFTData(mChooseDeviceItemData.getCompanyId(), mChooseDeviceItemData.getProductionPlantId(), mChooseDeviceItemData.getFactoryClassCode());
break; break;
case R.id.tv_shoottype: case R.id.tv_shoottype:
...@@ -574,14 +580,14 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie ...@@ -574,14 +580,14 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
@Override @Override
public void onUploadFile(final ArrayList<String> uriList, String type, final String sid) { public void onUploadFile(final ArrayList<String> uriList, String type, final String sid) {
uploadPath = mPresenter.onJudgmentPath(pathCompany, pathFactoryArea, pathFactoryClass, pathClass, pathShootType); uploadPath = mPresenter.onJudgmentPath(pathCompany, pathFactoryArea, pathFactoryClass, pathClass, pathShootType);
Log.e("path",uploadPath); Log.e("path", uploadPath);
dismissProgressDialog(); dismissProgressDialog();
showProgressDialog(type); showProgressDialog(type);
for (String path : uriList) { for (String path : uriList) {
updateMedia(path,this); updateMedia(path, this);
} }
new Thread(new Runnable() { new Thread(new Runnable() {
...@@ -718,7 +724,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie ...@@ -718,7 +724,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
}; };
//廣播更新媒體庫 //廣播更新媒體庫
private static void updateMedia(String path , Context context){ private static void updateMedia(String path, Context context) {
File file = new File(path); File file = new File(path);
Intent intent = new Intent(); Intent intent = new Intent();
intent.setAction(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); intent.setAction(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
...@@ -733,7 +739,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie ...@@ -733,7 +739,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
//取得自訂版面 //取得自訂版面
LayoutInflater inflater = LayoutInflater.from(MainActivity.this); LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
final View v = inflater.inflate(R.layout.dialog_changefilename,null); final View v = inflater.inflate(R.layout.dialog_changefilename, null);
builder.setTitle("請問要將檔名修改成:"); builder.setTitle("請問要將檔名修改成:");
builder.setView(v); builder.setView(v);
builder.setCancelable(false); builder.setCancelable(false);
...@@ -743,41 +749,41 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie ...@@ -743,41 +749,41 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
EditText editChangeName = v.findViewById(R.id.etChangeName); EditText editChangeName = v.findViewById(R.id.etChangeName);
changeFileName = editChangeName.getText().toString(); changeFileName = editChangeName.getText().toString();
// Log.e("euu",changeFileName); // Log.e("euu",changeFileName);
if (changeFileName.length() <= 0){ if (changeFileName.length() <= 0) {
Toast.makeText(MainActivity.this,"請輸入要更改的檔名",Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this, "請輸入要更改的檔名", Toast.LENGTH_SHORT).show();
changeFileNameCheckDialog(path,name); changeFileNameCheckDialog(path, name);
}else if(changeFileName.length()>0){
updateChangeFileName(changeFileName,path,name); } else if (changeFileName.length() > 0) {
updateChangeFileName(changeFileName, path, name);
} }
} }
}).setNegativeButton("取消", new DialogInterface.OnClickListener() { }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
//廣播圖片or影片 //廣播圖片or影片
updateMedia(path,MainActivity.this); updateMedia(path, MainActivity.this);
} }
}); });
builder.create(); builder.create();
builder.show(); builder.show();
} }
private void updateChangeFileName(final String changeFileName, final String path, String originFileName) {
if (originFileName.contains(".jpg")) {
private void updateChangeFileName(String changeFileName, final String path, String originFileName) { Log.e("type", "jpg");
if (originFileName.contains(".jpg")){ File newFile = new File(path.replace(originFileName, changeFileName) + ".jpg");
Log.e("type","jpg");
File newFile = new File(path.replace(originFileName,changeFileName)+".jpg");
File originFile = new File(path); File originFile = new File(path);
originFile.renameTo(newFile); originFile.renameTo(newFile);
updateMedia(newFile.getAbsolutePath(),this); updateMedia(newFile.getAbsolutePath(), this);
}else if (originFileName.contains(".mp4")){ } else if (originFileName.contains(".mp4")) {
Log.e("type","mp4"); Log.e("type", "mp4");
File newFile = new File(path.replace(originFileName,changeFileName)+".mp4"); final File newFile = new File(path.replace(originFileName, changeFileName) + ".mp4");
File originFile = new File(path); final File originFile = new File(path);
originFile.renameTo(newFile); originFile.renameTo(newFile);
updateMedia(newFile.getAbsolutePath(),this); // updateMedia(newFile.getAbsolutePath(),this);
//跑太快畫面來不及更新 // 跑太快畫面來不及更新
showProgressDialog("影片改名中"); showProgressDialog("影片改名中");
showProgressDialog("影片改名中"); showProgressDialog("影片改名中");
showProgressDialog("影片改名中"); showProgressDialog("影片改名中");
...@@ -787,16 +793,31 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie ...@@ -787,16 +793,31 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
@Override @Override
public void run() { public void run() {
try { try {
Thread.sleep(3000); refreshVideoMediastore(path,newFile);
updateMedia(new File(path).getAbsolutePath(),MainActivity.this); //把舊檔案更新掉,不然媒體庫會有一個額外且不能用的檔案 Thread.sleep(5000);
dismissProgressDialog(); dismissProgressDialog();
//updateMedia(new File(path).getAbsolutePath(),this); //把舊檔案更新掉,不然媒體庫會有一個額外且不能用的檔案
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
Log.e("error",e.getMessage()); Log.e("error",e.getMessage());
} }
} }
}).start(); }).start();
// updateMedia(new File(path).getAbsolutePath(),this); //把舊檔案更新掉,不然媒體庫會有一個額外且不能用的檔案
} }
} }
private void refreshVideoMediastore(String path,File after) {
MainActivity.this.getContentResolver().delete(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, MediaStore.Video.Media.DATA+"=?"
,new String[]{
path
});
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(after));
MainActivity.this.sendBroadcast(intent);
}
} }
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:hint="@string/login_account_hint" android:hint="@string/login_account_hint"
android:text="N000042089"
android:textColorHint="@color/white" android:textColorHint="@color/white"
android:paddingStart="100dp" android:paddingStart="100dp"
app:layout_constraintWidth_percent="0.9" app:layout_constraintWidth_percent="0.9"
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:hint="@string/login_password_hint" android:hint="@string/login_password_hint"
android:text="566345"
android:inputType="textPassword" android:inputType="textPassword"
android:textColorHint="@color/white" android:textColorHint="@color/white"
android:paddingStart="100dp" android:paddingStart="100dp"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment