From a8e81f475dda2c25987391ed39d5eabaf957b94b Mon Sep 17 00:00:00 2001 From: hoeveid Date: Sat, 4 Jan 2025 12:32:38 +0100 Subject: [PATCH] Minor improvement for troubleshooting the app --- build.gradle | 2 +- .../scoreboard/activity/Feedback.java | 112 ++++++++++-------- .../scoreboard/feed/FeedFeedSelector.java | 1 + .../scoreboard/prefs/ExportImportPrefs.java | 6 +- .../scoreboard/prefs/PreferenceValues.java | 2 +- 5 files changed, 73 insertions(+), 50 deletions(-) diff --git a/build.gradle b/build.gradle index a0a6cba2..6611f0c9 100644 --- a/build.gradle +++ b/build.gradle @@ -102,7 +102,7 @@ android { } } flavorDimensions "devicetype" // actual flavors use camelCase with first letter lowercase - def versionCodeXXX = 529 + def versionCodeXXX = 530 productFlavors { // versionCodePrefix specifies [min_api_level][bitwise_supported_screensizes s=1,m=2,l=4,xl=8] phoneTabletPre22 { diff --git a/src/com/doubleyellow/scoreboard/activity/Feedback.java b/src/com/doubleyellow/scoreboard/activity/Feedback.java index 3e6b465a..04360144 100644 --- a/src/com/doubleyellow/scoreboard/activity/Feedback.java +++ b/src/com/doubleyellow/scoreboard/activity/Feedback.java @@ -80,6 +80,20 @@ public class Feedback extends XActivity implements View.OnClickListener, View.On btn.setOnClickListener(this); } + // allow alternative way of obtaining info for if e.g. no email client is available + View btn = findViewById(R.id.cmd_email_the_developer); + btn.setLongClickable(true); + btn.setOnLongClickListener(new View.OnLongClickListener() { + @Override public boolean onLongClick(View v) { + List lInfo = collectInfo(); + Intent intent = new Intent(Intent.ACTION_SEND); + intent.setType("text/plain"); + intent.putExtra(Intent.EXTRA_TEXT, ListUtil.join(lInfo, "\n")); // for whatsapp + Feedback.this.startActivity(Intent.createChooser(intent, Brand.getShortName(Feedback.this) + ":")); // This actually becomes the title of the chooser + return true; + } + }); + findViewById(R.id.ll_feedback) .setVisibility(View.VISIBLE); findViewById(R.id.ll_no_there_is_a_problem).setVisibility(View.GONE); findViewById(R.id.ll_yes_i_like ).setVisibility(View.GONE); @@ -95,6 +109,56 @@ public class Feedback extends XActivity implements View.OnClickListener, View.On return false; } + private List collectInfo() { + List lInfo = new ArrayList<>(); + + // put user settings in the email + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + lInfo.add(StringUtil.lrpad("Debug Info", '=', 40)); + try { + PackageInfo info = getPackageManager().getPackageInfo(this.getPackageName(), 0); + + lInfo.add("App Version: " + info.versionName + " (" + info.versionCode + ")"); + lInfo.add("Device API Level: " + Build.VERSION.SDK_INT); + lInfo.add("Device: " + Build.MANUFACTURER + " " + Build.MODEL + " " + Build.BRAND + " " + Build.VERSION.RELEASE); + } catch (Exception e) { } + lInfo.add("Screen Size HxW: " + ViewUtil.getScreenHeightWidthMaximum(this) + " x " + ViewUtil.getScreenHeightWidthMinimum(this)); + lInfo.add("DeviceDefaultOrientation:" + ViewUtil.getDeviceDefaultOrientation(this)); + lInfo.add("Resource folder: " + getString(R.string.setting_resource_folder)); + + DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); + lInfo.add(displayMetrics.toString()); // string like DisplayMetrics{density=1.5, width=480, height= 800, scaledDensity=1.2750001, xdpi=217.713 , ydpi=207.347} + + if ( true ) { + lInfo.add(StringUtil.lrpad("Features", '=', 40)); + final FeatureInfo[] featuresList = getPackageManager().getSystemAvailableFeatures(); + for (FeatureInfo f : featuresList) { + lInfo.add(f.name); + } + } + if ( true ) { + lInfo.add(StringUtil.lrpad("Settings", '=', 40)); + Map all = prefs.getAll(); + Set keys = all.keySet(); + SortedSet keysSorted = new TreeSet(keys); + for(String key: keysSorted) { + Object val = all.get(key); + if ( key.toLowerCase().matches(".*password$")) { + val = "******"; // do not send any passwords in the feedback mail: would piss off the user + } + if ( key.endsWith("List") ) { // EventList RoundList PlayerList MatchList + val = String.format("[list of length %s]", String.valueOf(val).split("\n").length); + } + lInfo.add("|" + key + ":" + val); + } + } + if ( true ) { + lInfo.add(StringUtil.lrpad("", '=', 40)); + lInfo.add("Become a tester: https://play.google.com/apps/testing/" + getPackageName()); + lInfo.add(StringUtil.lrpad("", '=', 40)); + } + return lInfo; + } @Override public void onClick(View view) { String sMarketURL = "market://details" + "?id=" + this.getPackageName(); String sPlayURL = "https://play.google.com/store/apps/details" + "?id=" + this.getPackageName(); @@ -145,53 +209,7 @@ public class Feedback extends XActivity implements View.OnClickListener, View.On break; } case R.id.cmd_email_the_developer: - List lInfo = new ArrayList<>(); - - // put user settings in the email - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - lInfo.add(StringUtil.lrpad("Debug Info", '=', 40)); - try { - PackageInfo info = getPackageManager().getPackageInfo(this.getPackageName(), 0); - - lInfo.add("App Version: " + info.versionName + " (" + info.versionCode + ")"); - lInfo.add("Device API Level: " + Build.VERSION.SDK_INT); - lInfo.add("Device: " + Build.MANUFACTURER + " " + Build.MODEL + " " + Build.BRAND + " " + Build.VERSION.RELEASE); - } catch (Exception e) { } - lInfo.add("Screen Size HxW: " + ViewUtil.getScreenHeightWidthMaximum(this) + " x " + ViewUtil.getScreenHeightWidthMinimum(this)); - lInfo.add("DeviceDefaultOrientation:" + ViewUtil.getDeviceDefaultOrientation(this)); - lInfo.add("Resource folder: " + getString(R.string.setting_resource_folder)); - - DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); - lInfo.add(displayMetrics.toString()); // string like DisplayMetrics{density=1.5, width=480, height= 800, scaledDensity=1.2750001, xdpi=217.713 , ydpi=207.347} - - if ( true ) { - lInfo.add(StringUtil.lrpad("Features", '=', 40)); - final FeatureInfo[] featuresList = getPackageManager().getSystemAvailableFeatures(); - for (FeatureInfo f : featuresList) { - lInfo.add(f.name); - } - } - if ( true ) { - lInfo.add(StringUtil.lrpad("Settings", '=', 40)); - Map all = prefs.getAll(); - Set keys = all.keySet(); - SortedSet keysSorted = new TreeSet(keys); - for(String key: keysSorted) { - Object val = all.get(key); - if ( key.toLowerCase().matches(".*password$")) { - val = "******"; // do not send any passwords in the feedback mail: would piss off the user - } - if ( key.endsWith("List") ) { // EventList RoundList PlayerList MatchList - val = String.format("[list of length %s]", String.valueOf(val).split("\n").length); - } - lInfo.add("|" + key + ":" + val); - } - } - if ( true ) { - lInfo.add(StringUtil.lrpad("", '=', 40)); - lInfo.add("Become a tester: https://play.google.com/apps/testing/" + getPackageName()); - lInfo.add(StringUtil.lrpad("", '=', 40)); - } + List lInfo = collectInfo(); String sendFeedbackTo = getString(R.string.developer_email); String sSubject = Brand.getShortName(this) + " Feedback"; diff --git a/src/com/doubleyellow/scoreboard/feed/FeedFeedSelector.java b/src/com/doubleyellow/scoreboard/feed/FeedFeedSelector.java index ad8c4159..72329f5a 100644 --- a/src/com/doubleyellow/scoreboard/feed/FeedFeedSelector.java +++ b/src/com/doubleyellow/scoreboard/feed/FeedFeedSelector.java @@ -303,6 +303,7 @@ private void fetchUrls(final JSONArray aUrls, final String sName, final JSONArra } catch (JSONException e) { e.printStackTrace(); changeStatus(Status.SelectFeed); + Toast.makeText(FeedFeedSelector.this, "Invalid JSON in " + sName, Toast.LENGTH_SHORT).show(); } } }); diff --git a/src/com/doubleyellow/scoreboard/prefs/ExportImportPrefs.java b/src/com/doubleyellow/scoreboard/prefs/ExportImportPrefs.java index c671187e..754792e7 100644 --- a/src/com/doubleyellow/scoreboard/prefs/ExportImportPrefs.java +++ b/src/com/doubleyellow/scoreboard/prefs/ExportImportPrefs.java @@ -25,7 +25,9 @@ import android.util.AttributeSet; import android.widget.Toast; import com.doubleyellow.android.util.ExportImport; +import com.doubleyellow.scoreboard.Brand; import com.doubleyellow.scoreboard.R; +import com.doubleyellow.scoreboard.dialog.MyDialogBuilder; import com.doubleyellow.util.FileUtil; import com.doubleyellow.util.MapUtil; @@ -125,9 +127,11 @@ public static void exportSettings(Context context) { boolean bWritten = FileUtil.writeObjectToFile(fSettings, buAll); if ( bWritten ) { String sMsg = context.getString(R.string.x_stored_in_y, context.getString(R.string.sb_preferences), fSettings.getAbsolutePath()); + MyDialogBuilder.dialogWithOkOnly(context, sMsg); Toast.makeText(context, sMsg, Toast.LENGTH_LONG).show(); } else { String sMsg = String.format("Could not store settings in %s", fSettings.getAbsolutePath()); + MyDialogBuilder.dialogWithOkOnly(context, sMsg + "\nMaybe try and change the export location. Settings > Archive > Directory for import/export"); Toast.makeText(context, sMsg, Toast.LENGTH_LONG).show(); } } @@ -143,7 +147,7 @@ public static File getSettingsBinaryFile(Context context, boolean bForImport) { Toast.makeText(context, R.string.could_not_determine_external_storage_location, Toast.LENGTH_LONG).show(); return null; } - return new File(externalStorageDirectory, "Squore.settings.bin"); + return new File(externalStorageDirectory, Brand.getShortName(context) + ".settings.bin"); } } \ No newline at end of file diff --git a/src/com/doubleyellow/scoreboard/prefs/PreferenceValues.java b/src/com/doubleyellow/scoreboard/prefs/PreferenceValues.java index a19b60a3..ea085eb7 100644 --- a/src/com/doubleyellow/scoreboard/prefs/PreferenceValues.java +++ b/src/com/doubleyellow/scoreboard/prefs/PreferenceValues.java @@ -1644,7 +1644,7 @@ public static boolean guessShareAction(String sModelSource, Context context) { boolean bChanged = setEnum(PreferenceKeys.shareAction, context, ShareMatchPrefs.LinkWithFullDetails); return bChanged; } - final int iLengthToCheck = 20; + final int iLengthToCheck = Math.max(20, sPostURL.indexOf('/', Math.min(10, sPostURL.length()))); int iMinLength = Math.min(StringUtil.size(sModelSource), StringUtil.size(sPostURL)); if ( iMinLength < iLengthToCheck ) { // prevent StringIndexOutOfBounds