Skip to content

Commit

Permalink
Fix download on some android devices
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Oct 19, 2023
1 parent 8dc1035 commit 4e019f4
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 165 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ English DoliDroid ChangeLog

***** ChangeLog for 3.0 *****

3.0-b59
- NEW Hide a page About current instance in menu
- NEW Fix download of files for some Android version

3.0-b58
- NEW Hide Basic auth pass found into URLs
- NEW App targets Android 13 (API level 33) or higher
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http:https://schemas.android.com/apk/res/android"
android:versionCode="58"
android:versionCode="59"
android:versionName="DoliDroid Pro 3.0"
android:installLocation="auto"
>
Expand All @@ -16,7 +16,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Dangerous permissions -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- Permission in group android.permission-group.STORAGE -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:required="false" /> <!-- Permission in group android.permission-group.STORAGE -->
<!--<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>-->
<!--<uses-permission android:name="android.permission.CAMERA"/>-->
<!--<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION"/>-->
Expand Down Expand Up @@ -66,6 +66,11 @@
android:label="@string/title_activity_about"
android:theme="@style/DoliDroidThemeAbout" >
</activity>
<activity
android:name=".AboutInstanceActivity"
android:label="@string/title_activity_about"
android:theme="@style/DoliDroidThemeAbout" >
</activity>
<activity
android:name=".ManageURLActivity"
android:label="@string/title_activity_about"
Expand Down
56 changes: 14 additions & 42 deletions app/src/main/java/com/nltechno/dolidroidpro/AboutActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.nltechno.dolidroidpro;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.*;
Expand Down Expand Up @@ -149,6 +150,14 @@ public void onStart() {
//s1+=getString(R.string.DeviceHasMenuHardware)+": <b>"+(Utils.hasMenuHardware(this)?getString(R.string.Yes):getString(R.string.No))+"</b><br />\n";
s1+=getString(R.string.DeviceHasDownloadManager)+": <b>"+(Utils.isDownloadManagerAvailable(this)?getString(R.string.Yes):getString(R.string.No))+"</b><br />\n";

// For Environment.DIRECTORY_MUSIC, Environment.DIRECTORY_PODCASTS, Environment.DIRECTORY_RINGTONES, Environment.DIRECTORY_ALARMS, Environment.DIRECTORY_NOTIFICATIONS, Environment.DIRECTORY_PICTURES, or Environment.DIRECTORY_MOVIES.
// Files in this directory are deleted when application is deleted.
//File[] Files = getExternalFilesDirs();

// File[] Files = getExternalMediaDirs();
// Files[0].getAbsolutePath will return "/storage/emulated/0/Android/media/com.nltechno.dolidroidpro"
// From Android 30+, it is better to write into media dire with MediaStore

// This return /storage/sdcard0/Download for example (we use this for downloading files)
String downloaddirpublic=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
// This return /storage/sdcard0 for example (we do not use this)
Expand All @@ -160,6 +169,10 @@ public void onStart() {
//if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) photosdirpublic = Environment.getExternalStorageDirectory().getAbsolutePath();
s1+=getString(R.string.PhotosDirectory)+": <b>"+photosdirpublic+"</b><br />\n";

String documentdirpublic=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath();
//if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) documentdirpublic = Environment.getExternalStorageDirectory().getAbsolutePath();
s1+=getString(R.string.DocumentsDirectory)+": <b>"+documentdirpublic+"</b><br />\n";

/*
Intent testIntent = new Intent(Intent.ACTION_VIEW);
testIntent.setType("application/pdf");
Expand Down Expand Up @@ -207,47 +220,6 @@ public void onStart() {
{
Log.e(LOG_TAG, "Error");
}

// Show text section 3
TextView textViewAbout3 = findViewById(R.id.textAboutCurrentUrl);
String s3="";

// Current url
String currentUrl = intent.getStringExtra("currentUrl");
String title = intent.getStringExtra("title");
if (currentUrl != null && ! "".equals(currentUrl)) {
String pattern = "^(https?:https://[^:]+):[^@]+@";
Pattern regexPattern = Pattern.compile(pattern);
Matcher matcher = regexPattern.matcher(currentUrl);
String currentUrlWithoutPass = matcher.replaceFirst("$1:*****@");
s3+="<font color='#440066'><b>"+getString(R.string.currentUrl)+":</b></font><br /><br />\n"+title+"<br />\n"+currentUrlWithoutPass;
}
String lastversionfound = intent.getStringExtra("lastversionfound");
if (lastversionfound != null && ! "".equals(lastversionfound)) {
s3+="<br /><br />\nDolibarr "+getString(R.string.Version)+": "+lastversionfound+"<br />\n";
}

// User agent
// The About view is not a webview, so we must use the userAgent propagated by the SecondActivity. It may be null if not already created.
String userAgent = intent.getStringExtra("userAgent");
Log.d(LOG_TAG,"userAgent="+userAgent);
if (userAgent != null && ! "".equals(userAgent)) {
s3+="<br /><br />\n<font color='#440066'><b>"+getString(R.string.UserAgent)+":</b></font><br /><br />\n"+userAgent+"<br />\n";
}

if (currentUrl != null && ! "".equals(currentUrl)) {
findViewById(R.id.imageView03).setVisibility(View.VISIBLE);
findViewById(R.id.imageView03).setEnabled(true);
textViewAbout3.setText(Html.fromHtml(s3));
textViewAbout3.setVisibility(View.VISIBLE);
textViewAbout3.setEnabled(true);
} else {
findViewById(R.id.imageView03).setVisibility(View.INVISIBLE);
findViewById(R.id.imageView03).setEnabled(false);
textViewAbout3.setText("");
textViewAbout3.setVisibility(View.INVISIBLE);
textViewAbout3.setEnabled(false);
}
}

/**
Expand All @@ -268,7 +240,7 @@ public boolean onCreateOptionsMenu(Menu menu)
*/
public boolean onOptionsItemSelected(MenuItem item)
{
Log.d(LOG_TAG, "Click onto menu "+item.toString());
Log.d(LOG_TAG, "Click onto menu "+item.toString() + " from AboutActivity");

switch (item.getItemId())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,12 @@
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.Display;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -51,12 +46,12 @@
* @author [email protected]
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public class InfoInstanceActivity extends Activity {
public class AboutInstanceActivity extends Activity {

private static final String LOG_TAG = "DoliDroidInfoInstanceActivity";
private static final String LOG_TAG = "DoliDroidAboutInstanceActivity";
private String menuAre="hardwareonly";

static final int RESULT_ABOUT = RESULT_FIRST_USER;
static final int RESULT_ABOUT_INSTANCE = RESULT_FIRST_USER;

/**
* Called when activity is created
Expand Down Expand Up @@ -86,14 +81,7 @@ public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE); // Hide title with menus
}

setContentView(R.layout.activity_about);

// text2 has links specified by putting <a> tags in the string
// resource. By default these links will appear but not
// respond to user input. To make them active, you need to
// call setMovementMethod() on the TextView object.
TextView t1 = findViewById(R.id.textAboutVersion);
t1.setMovementMethod(LinkMovementMethod.getInstance());
setContentView(R.layout.activity_about_instance);

Log.d(LOG_TAG, "Open file " + MainActivity.FILENAME+ " in directory "+getApplicationContext().getFilesDir().toString());
}
Expand All @@ -106,19 +94,12 @@ public void onCreate(Bundle savedInstanceState) {
public void onStart() {
Log.d(LOG_TAG, "onStart");
super.onStart();

SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
//boolean prefAlwaysShowBar = sharedPrefs.getBoolean("prefAlwaysShowBar", true);
boolean prefAlwaysAutoFill = sharedPrefs.getBoolean("prefAlwaysAutoFill", true);
Intent intent = getIntent();

// Show text section 1
TextView textViewAbout1 = findViewById(R.id.textAboutVersion);
String s1="";

textViewAbout1.setText(Html.fromHtml(s1));
// For api level 24: textViewAbout1.setText(Html.fromHtml(s1, Html.FROM_HTML_MODE_LEGACY));

String savedDolRootUrl = intent.getStringExtra("savedDolRootUrl");

// Show btn or not
Expand Down Expand Up @@ -205,13 +186,13 @@ public boolean onCreateOptionsMenu(Menu menu)
*/
public boolean onOptionsItemSelected(MenuItem item)
{
Log.d(LOG_TAG, "Click onto menu "+item.toString());
Log.d(LOG_TAG, "Click onto menu "+item.toString() + " from AboutInstanceActivity");

switch (item.getItemId())
{
case R.id.menu_back:
Log.d(LOG_TAG, "We finish activity resultCode = "+RESULT_ABOUT);
setResult(RESULT_ABOUT);
Log.d(LOG_TAG, "We finish activity resultCode = "+RESULT_ABOUT_INSTANCE);
setResult(RESULT_ABOUT_INSTANCE);
finish();
return true;
}
Expand All @@ -232,8 +213,8 @@ public boolean onKeyDown(int keyCode, KeyEvent event)
// Check if the key event was the Back button and if there's history
if (keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_BACK)
{
Log.d(LOG_TAG, "We clicked onto KEYCODE_MENU or KEYCODE_BACK. We finish activity resultCode = "+RESULT_ABOUT);
setResult(RESULT_ABOUT);
Log.d(LOG_TAG, "We clicked onto KEYCODE_MENU or KEYCODE_BACK. We finish activity resultCode = "+RESULT_ABOUT_INSTANCE);
setResult(RESULT_ABOUT_INSTANCE);
finish();
return true;
}
Expand All @@ -248,8 +229,8 @@ public boolean onKeyDown(int keyCode, KeyEvent event)
@SuppressLint("SetJavaScriptEnabled")
public void onClickToBack(View v)
{
Log.d(LOG_TAG, "We finish activity resultCode = "+RESULT_ABOUT);
setResult(RESULT_ABOUT);
Log.d(LOG_TAG, "We finish activity resultCode = "+RESULT_ABOUT_INSTANCE);
setResult(RESULT_ABOUT_INSTANCE);
finish();
}

Expand All @@ -259,11 +240,11 @@ public void onClickToBack(View v)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
Log.d(LOG_TAG, "AboutActivity::onActivityResult requestCode = " + requestCode + " resultCode = " + resultCode);
if (resultCode==RESULT_ABOUT)
Log.d(LOG_TAG, "AboutInstanceActivity::onActivityResult requestCode = " + requestCode + " resultCode = " + resultCode);
if (resultCode==RESULT_ABOUT_INSTANCE)
{
Log.d(LOG_TAG, "AboutActivity::onActivityResult We finish activity resultCode = "+RESULT_ABOUT);
setResult(RESULT_ABOUT);
Log.d(LOG_TAG, "AboutInstanceActivity::onActivityResult We finish activity resultCode = "+RESULT_ABOUT_INSTANCE);
setResult(RESULT_ABOUT_INSTANCE);
finish();
}
}
Expand Down
Loading

0 comments on commit 4e019f4

Please sign in to comment.