Skip to content

Commit

Permalink
Merge pull request #12 from akanshSirohi/dev
Browse files Browse the repository at this point in the history
Fixed Minor Issues
  • Loading branch information
akanshSirohi authored Feb 6, 2023
2 parents 0f8e920 + b32834e commit e970516
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ dependencies {
implementation 'com.github.clans:fab:1.6.4'
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'com.google.android.material:material:1.7.0'
implementation 'com.google.android.material:material:1.8.0'
implementation 'com.dlazaro66.qrcodereaderview:qrcodereaderview:2.0.3'
implementation 'com.github.SumiMakito:AwesomeQRCode:1.2.0'

Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/akansh/fileserversuit/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Constants {
public static final int SERVER_OFF = 0;
public static final int MATISSE_REQ_CODE = 101;
public static final int STORAGE_REQ_CODE = 1;
public static final int CAMERA_REQ_CODE = 2;
public static final int ITEM_TYPE_SENT = 0;
public static final int ITEM_TYPE_RECEIVED = 1;
public static final int DEVICE_TYPE_TEMP = 0;
Expand Down
62 changes: 36 additions & 26 deletions app/src/main/java/com/akansh/fileserversuit/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,13 @@

public class MainActivity extends AppCompatActivity {

private final String[] PERMISSIONS_OLD = {
Manifest.permission.CAMERA,
private final String[] PERMISSIONS = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
};
private final String[] PERMISSIONS_NEW = {
Manifest.permission.CAMERA,
};
// private final String[] PERMISSIONS_NEW = {
// Manifest.permission.CAMERA,
// };

private ImageButton serverBtn,hide_logger_btn;
Utils utils;
Expand Down Expand Up @@ -200,7 +199,7 @@ protected void onCreate(Bundle savedInstanceState) {
});

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions();
initRequestPermissions();
} else {
initializeApp();
}
Expand Down Expand Up @@ -482,7 +481,11 @@ public void onSetupStarted(boolean updating) {
if(itemId == R.id.settings) {
toggleSettings();
}else if(itemId == R.id.scan_qr) {
initQrScanner();
if(checkCameraPermission()) {
initQrScanner();
}else{
requestCameraPermission();
}
}else if(itemId == R.id.trans_hist) {
Intent intent=new Intent(MainActivity.this,TransferHistory.class);
startActivity(intent);
Expand Down Expand Up @@ -523,17 +526,24 @@ public void askIgnoreBatteryOptimizations() {
}
}

public boolean checkPermissions() {
public boolean checkStoragePermissions() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
return ActivityCompat.checkSelfPermission(this,PERMISSIONS_OLD[0]) == PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,PERMISSIONS_OLD[1]) == PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,PERMISSIONS_OLD[2]) == PackageManager.PERMISSION_GRANTED;
}else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R){
return ActivityCompat.checkSelfPermission(this,PERMISSIONS_NEW[0]) == PackageManager.PERMISSION_GRANTED;
return ActivityCompat.checkSelfPermission(this,PERMISSIONS[0]) == PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,PERMISSIONS[1]) == PackageManager.PERMISSION_GRANTED;
}
return true;
}

public boolean checkCameraPermission() {
return ActivityCompat.checkSelfPermission(this,Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
}

public void requestCameraPermission() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.CAMERA},Constants.CAMERA_REQ_CODE);
}
}

public void requestStoragePermissions() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
try {
Expand All @@ -553,29 +563,29 @@ public void requestStoragePermissions() {
}
}

public void requestPermissions() {
public void initRequestPermissions() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
requestPermissions(PERMISSIONS_OLD,Constants.STORAGE_REQ_CODE);
requestPermissions(PERMISSIONS,Constants.STORAGE_REQ_CODE);
}else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R){
requestPermissions(PERMISSIONS_NEW,Constants.STORAGE_REQ_CODE);
if (!Environment.isExternalStorageManager()) {
requestStoragePermissions();
} else {
initializeApp();
}
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if(requestCode == Constants.STORAGE_REQ_CODE) {
if (!checkPermissions()) {
requestPermissions();
if (!checkStoragePermissions()) {
initRequestPermissions();
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (!Environment.isExternalStorageManager()) {
requestStoragePermissions();
} else {
initializeApp();
}
} else {
initializeApp();
initializeApp();
}else if(requestCode == Constants.CAMERA_REQ_CODE) {
if(checkCameraPermission()) {
initQrScanner();
}
}else{
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
Expand Down
16 changes: 6 additions & 10 deletions app/src/main/java/com/akansh/fileserversuit/ServerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
import java.util.List;

import fi.iki.elonen.NanoHTTPD;

import static fi.iki.elonen.NanoHTTPD.newFixedLengthResponse;

public class ServerUtils {
private List<ApplicationInfo> packages = null;
private PackageManager packageManager=null;
private Context ctx;
private final List<ApplicationInfo> packages;
private final PackageManager packageManager;
private final Context ctx;
Utils utils;
SendProgressListener sendProgressListener;
UpdateTransferHistoryListener updateTransferHistoryListener;
Expand Down Expand Up @@ -365,12 +364,9 @@ public NanoHTTPD.Response downloadFile(String path,boolean pCheck,boolean pushHi
FileInputStream fis = new FileInputStream(path);
fis.skip(start);
ProgressInputStream pis = new ProgressInputStream(fis, (int) fileLength);
pis.addListener(new ProgressInputStream.ProgressListener() {
@Override
public void process(double percent) {
if (sendProgressListener != null) {
sendProgressListener.onProgressUpdate((int) percent);
}
pis.addListener(percent -> {
if (sendProgressListener != null) {
sendProgressListener.onProgressUpdate((int) percent);
}
});
response = newFixedLengthResponse(NanoHTTPD.Response.Status.PARTIAL_CONTENT,"application/octet-stream", pis,fileLength);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/akansh/fileserversuit/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void saveSetting(String constant, boolean b) {

public boolean loadSetting(String constant) {
boolean def = false;
if (constant == Constants.FORCE_DOWNLOAD || constant == Constants.IS_LOGGER_VISIBLE) {
if (constant.equals(Constants.FORCE_DOWNLOAD) || constant.equals(Constants.IS_LOGGER_VISIBLE) || constant.equals(Constants.RESTRICT_MODIFY)) {
def = true;
}
SharedPreferences sharedPrefs = ctx.getSharedPreferences(ctx.getPackageName(), MODE_PRIVATE);
Expand Down

0 comments on commit e970516

Please sign in to comment.