-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert crash report fragment to dialog
- Loading branch information
1 parent
f5d366f
commit e06da10
Showing
9 changed files
with
154 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright 2024 Andrey Novikov | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the | ||
* terms of the GNU Lesser General Public License as published by the Free Software | ||
* Foundation, either version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package mobi.maptrek.dialogs; | ||
|
||
import android.app.AlertDialog; | ||
import android.app.Dialog; | ||
import android.content.Intent; | ||
import android.content.pm.PackageInfo; | ||
import android.content.pm.PackageManager; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
|
||
import android.view.Gravity; | ||
import android.view.Window; | ||
import android.view.WindowManager; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.fragment.app.DialogFragment; | ||
|
||
import java.io.File; | ||
import java.util.Locale; | ||
|
||
import mobi.maptrek.MapTrek; | ||
import mobi.maptrek.R; | ||
import mobi.maptrek.databinding.DialogCrashReportBinding; | ||
import mobi.maptrek.provider.ExportProvider; | ||
|
||
public class CrashReport extends DialogFragment { | ||
@NonNull | ||
@Override | ||
public Dialog onCreateDialog(Bundle savedInstanceState) { | ||
DialogCrashReportBinding viewBinding = DialogCrashReportBinding.inflate(getLayoutInflater()); | ||
|
||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext()); | ||
dialogBuilder.setPositiveButton(R.string.actionSend, (dialog, which) -> sendReport(viewBinding.message.getText().toString())); | ||
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, which) -> {}); | ||
dialogBuilder.setView(viewBinding.getRoot()); | ||
|
||
Dialog dialog = dialogBuilder.create(); | ||
|
||
Window window = dialog.getWindow(); | ||
assert window != null; | ||
WindowManager.LayoutParams lp = window.getAttributes(); | ||
lp.gravity = Gravity.BOTTOM; | ||
window.setAttributes(lp); | ||
|
||
return dialog; | ||
} | ||
|
||
private void sendReport(String message) { | ||
Intent intent = new Intent(Intent.ACTION_SEND); | ||
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"novikov+trekarta@gmail.com"}); | ||
File file = MapTrek.getApplication().getExceptionLog(); | ||
intent.putExtra(Intent.EXTRA_STREAM, ExportProvider.getUriForFile(requireContext(), file)); | ||
intent.setType("vnd.android.cursor.dir/email"); | ||
intent.putExtra(Intent.EXTRA_SUBJECT, "Trekarta crash report"); | ||
StringBuilder text = new StringBuilder(); | ||
text.append(message); | ||
text.append("\n\nDevice : ").append(Build.DEVICE); | ||
text.append("\nBrand : ").append(Build.BRAND); | ||
text.append("\nModel : ").append(Build.MODEL); | ||
text.append("\nProduct : ").append(Build.PRODUCT); | ||
text.append("\nLocale : ").append(Locale.getDefault()); | ||
text.append("\nBuild : ").append(Build.DISPLAY); | ||
text.append("\nVersion : ").append(Build.VERSION.RELEASE); | ||
try { | ||
PackageInfo info = requireContext().getPackageManager().getPackageInfo(requireContext().getPackageName(), 0); | ||
if (info != null) { | ||
text.append("\nApp code : ").append(info.versionCode); | ||
text.append("\nApp version : ").append(info.versionName); | ||
} | ||
} catch (PackageManager.NameNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
intent.putExtra(Intent.EXTRA_TEXT, text.toString()); | ||
startActivity(Intent.createChooser(intent, getString(R.string.send_crash_report))); | ||
} | ||
} |
112 changes: 0 additions & 112 deletions
112
app/src/main/java/mobi/maptrek/fragments/CrashReport.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:color="@color/colorAccent" android:state_focused="true" /> | ||
<item android:color="@color/textColorTertiary" /> | ||
</selector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle"> | ||
|
||
<stroke android:color="@color/focusable_color_selector" /> | ||
<stroke android:width="1dp" /> | ||
<corners android:radius="2dp" /> | ||
<solid android:color="@android:color/transparent" /> | ||
</shape> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
android:paddingStart="@dimen/dialogContentMargin" | ||
android:paddingTop="@dimen/dialogContentMargin" | ||
android:paddingEnd="@dimen/dialogContentMargin" | ||
tools:context=".dialogs.CrashReport"> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:labelFor="@id/message" | ||
android:text="@string/msgCrashOccurred" | ||
android:textAppearance="?android:attr/textAppearanceMedium" | ||
android:textColor="@color/textColorPrimary" /> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginVertical="@dimen/textPadding" | ||
android:text="@string/msgDescribeCrash" | ||
android:textAppearance="?android:attr/textAppearanceMedium" | ||
android:textColor="@color/textColorPrimary" /> | ||
|
||
<EditText | ||
android:id="@+id/message" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="@drawable/text_border" | ||
android:gravity="top" | ||
android:padding="@dimen/textPadding" | ||
android:importantForAutofill="no" | ||
android:inputType="text|textCapSentences|textAutoCorrect|textMultiLine" | ||
android:maxLines="8" | ||
android:minLines="3" /> | ||
|
||
</LinearLayout> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters