Skip to content

Commit

Permalink
handle android 30 when save local storage and bump up version 1.3.27
Browse files Browse the repository at this point in the history
  • Loading branch information
ariefnurputranto committed Jan 25, 2021
1 parent a78bc4f commit 9445a15
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ apply plugin: 'com.android.application'
apply from: rootProject.file('gradle/quality.gradle')

android {
compileSdkVersion 29
compileSdkVersion 30
defaultConfig {
applicationId "com.qiscus.dragonfly"
minSdkVersion 16
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName "1.0"
multiDexEnabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import android.provider.OpenableColumns;
Expand Down Expand Up @@ -160,7 +161,13 @@ public static File saveFile(File file) {

public static String generateFilePath(String fileName) {
String[] fileNameSplit = splitFileName(fileName);
return generateFilePath(fileName, fileNameSplit[1]);

int androidVersion = Build.VERSION.SDK_INT;
if (androidVersion >= 30) {
return generateFilePath(fileName, fileNameSplit[1], getEnvironment(fileName));
} else {
return generateFilePath(fileName, fileNameSplit[1]);
}
}

public static String generateFilePath(String fileName, String extension) {
Expand Down Expand Up @@ -188,6 +195,32 @@ public static String generateFilePath(String fileName, String extension) {
}
}

//api >=30
public static String generateFilePath(String fileName, String extension, String environment) {
File file = new File(Environment.getExternalStoragePublicDirectory(environment),
isImage(fileName) ? IMAGE_PATH : FILES_PATH);

if (!file.exists()) {
file.mkdirs();
}

int index = 0;
String directory = file.getAbsolutePath() + File.separator;
String[] fileNameSplit = splitFileName(fileName);
while (true) {
File newFile;
if (index == 0) {
newFile = new File(directory + fileNameSplit[0] + extension);
} else {
newFile = new File(directory + fileNameSplit[0] + "-" + index + extension);
}
if (!newFile.exists()) {
return newFile.getAbsolutePath();
}
index++;
}
}

public static boolean isImage(String fileName) {
String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(getExtension(fileName));
if (type == null) {
Expand All @@ -199,6 +232,26 @@ public static boolean isImage(String fileName) {
return false;
}

public static String getEnvironment(String fileName) {
String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(getExtension(fileName));
if (type == null) {
return Environment.DIRECTORY_DOWNLOADS;
} else if (type.contains("image")) {
return Environment.DIRECTORY_PICTURES;
} else if (type.contains("video")) {
return Environment.DIRECTORY_MOVIES;
} else if (type.contains("audio")) {
return Environment.DIRECTORY_MUSIC;
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return Environment.DIRECTORY_DOCUMENTS;
} else {
return Environment.DIRECTORY_DOWNLOADS;
}
}
}


public static File rename(File file, String newName) {
File newFile = new File(file.getParent(), newName);
if (!newFile.equals(file)) {
Expand Down
6 changes: 3 additions & 3 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ repositories {
ext {

minSDKVersion = 16
targetSDKVersion = 29
compileSDKVersion = 29
targetSDKVersion = 30
compileSDKVersion = 30

versions = [
support : "28.0.0",
support : "30.0.0",
firebaseCore : "17.2.2",
firebaseMessaging: "20.1.0",
okHttp : "3.12.5",
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ chatVersionPatch=17
# === qiscus chat-core library version ===
chatCoreVersionMajor=1
chatCoreVersionMinor=3
chatCoreVersionPatch=26
chatCoreVersionPatch=27

# === qiscus default base url
BASE_URL_SERVER="https://api.qiscus.com/"
Expand Down

0 comments on commit 9445a15

Please sign in to comment.