mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 08:30:44 +00:00
Use view binding in ErrorActivity.
This commit is contained in:
parent
e6021465f6
commit
b4d77df1be
@ -14,15 +14,11 @@ import android.view.Menu;
|
|||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
|
||||||
import androidx.core.app.NavUtils;
|
import androidx.core.app.NavUtils;
|
||||||
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
@ -34,6 +30,7 @@ import org.schabi.newpipe.ActivityCommunicator;
|
|||||||
import org.schabi.newpipe.BuildConfig;
|
import org.schabi.newpipe.BuildConfig;
|
||||||
import org.schabi.newpipe.MainActivity;
|
import org.schabi.newpipe.MainActivity;
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
|
import org.schabi.newpipe.databinding.ActivityErrorBinding;
|
||||||
import org.schabi.newpipe.util.Localization;
|
import org.schabi.newpipe.util.Localization;
|
||||||
import org.schabi.newpipe.util.ShareUtils;
|
import org.schabi.newpipe.util.ShareUtils;
|
||||||
import org.schabi.newpipe.util.ThemeHelper;
|
import org.schabi.newpipe.util.ThemeHelper;
|
||||||
@ -87,7 +84,8 @@ public class ErrorActivity extends AppCompatActivity {
|
|||||||
private ErrorInfo errorInfo;
|
private ErrorInfo errorInfo;
|
||||||
private Class returnActivity;
|
private Class returnActivity;
|
||||||
private String currentTimeStamp;
|
private String currentTimeStamp;
|
||||||
private EditText userCommentBox;
|
|
||||||
|
private ActivityErrorBinding activityErrorBinding;
|
||||||
|
|
||||||
public static void reportUiError(final AppCompatActivity activity, final Throwable el) {
|
public static void reportUiError(final AppCompatActivity activity, final Throwable el) {
|
||||||
reportError(activity, el, activity.getClass(), null, ErrorInfo.make(UserAction.UI_ERROR,
|
reportError(activity, el, activity.getClass(), null, ErrorInfo.make(UserAction.UI_ERROR,
|
||||||
@ -181,12 +179,13 @@ public class ErrorActivity extends AppCompatActivity {
|
|||||||
assureCorrectAppLanguage(this);
|
assureCorrectAppLanguage(this);
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
ThemeHelper.setTheme(this);
|
ThemeHelper.setTheme(this);
|
||||||
setContentView(R.layout.activity_error);
|
|
||||||
|
activityErrorBinding = ActivityErrorBinding.inflate(getLayoutInflater());
|
||||||
|
setContentView(activityErrorBinding.getRoot());
|
||||||
|
|
||||||
final Intent intent = getIntent();
|
final Intent intent = getIntent();
|
||||||
|
|
||||||
final Toolbar toolbar = findViewById(R.id.toolbar);
|
setSupportActionBar(activityErrorBinding.toolbarLayout.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
|
||||||
|
|
||||||
final ActionBar actionBar = getSupportActionBar();
|
final ActionBar actionBar = getSupportActionBar();
|
||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
@ -195,15 +194,6 @@ public class ErrorActivity extends AppCompatActivity {
|
|||||||
actionBar.setDisplayShowTitleEnabled(true);
|
actionBar.setDisplayShowTitleEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Button reportEmailButton = findViewById(R.id.errorReportEmailButton);
|
|
||||||
final Button copyButton = findViewById(R.id.errorReportCopyButton);
|
|
||||||
final Button reportGithubButton = findViewById(R.id.errorReportGitHubButton);
|
|
||||||
|
|
||||||
userCommentBox = findViewById(R.id.errorCommentBox);
|
|
||||||
final TextView errorView = findViewById(R.id.errorView);
|
|
||||||
final TextView infoView = findViewById(R.id.errorInfosView);
|
|
||||||
final TextView errorMessageView = findViewById(R.id.errorMessageView);
|
|
||||||
|
|
||||||
final ActivityCommunicator ac = ActivityCommunicator.getCommunicator();
|
final ActivityCommunicator ac = ActivityCommunicator.getCommunicator();
|
||||||
returnActivity = ac.getReturnActivity();
|
returnActivity = ac.getReturnActivity();
|
||||||
errorInfo = intent.getParcelableExtra(ERROR_INFO);
|
errorInfo = intent.getParcelableExtra(ERROR_INFO);
|
||||||
@ -213,28 +203,27 @@ public class ErrorActivity extends AppCompatActivity {
|
|||||||
addGuruMeditation();
|
addGuruMeditation();
|
||||||
currentTimeStamp = getCurrentTimeStamp();
|
currentTimeStamp = getCurrentTimeStamp();
|
||||||
|
|
||||||
reportEmailButton.setOnClickListener(v ->
|
activityErrorBinding.errorReportEmailButton.setOnClickListener(v ->
|
||||||
openPrivacyPolicyDialog(this, "EMAIL"));
|
openPrivacyPolicyDialog(this, "EMAIL"));
|
||||||
|
|
||||||
copyButton.setOnClickListener(v -> {
|
activityErrorBinding.errorReportCopyButton.setOnClickListener(v -> {
|
||||||
ShareUtils.copyToClipboard(this, buildMarkdown());
|
ShareUtils.copyToClipboard(this, buildMarkdown());
|
||||||
Toast.makeText(this, R.string.msg_copied, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.msg_copied, Toast.LENGTH_SHORT).show();
|
||||||
});
|
});
|
||||||
|
|
||||||
reportGithubButton.setOnClickListener(v ->
|
activityErrorBinding.errorReportGitHubButton.setOnClickListener(v ->
|
||||||
openPrivacyPolicyDialog(this, "GITHUB"));
|
openPrivacyPolicyDialog(this, "GITHUB"));
|
||||||
|
|
||||||
|
|
||||||
// normal bugreport
|
// normal bugreport
|
||||||
buildInfo(errorInfo);
|
buildInfo(errorInfo);
|
||||||
if (errorInfo.getMessage() != 0) {
|
if (errorInfo.getMessage() != 0) {
|
||||||
errorMessageView.setText(errorInfo.getMessage());
|
activityErrorBinding.errorMessageView.setText(errorInfo.getMessage());
|
||||||
} else {
|
} else {
|
||||||
errorMessageView.setVisibility(View.GONE);
|
activityErrorBinding.errorMessageView.setVisibility(View.GONE);
|
||||||
findViewById(R.id.messageWhatHappenedView).setVisibility(View.GONE);
|
activityErrorBinding.messageWhatHappenedView.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
errorView.setText(formErrorText(errorList));
|
activityErrorBinding.errorView.setText(formErrorText(errorList));
|
||||||
|
|
||||||
// print stack trace once again for debugging:
|
// print stack trace once again for debugging:
|
||||||
for (final String e : errorList) {
|
for (final String e : errorList) {
|
||||||
@ -339,11 +328,10 @@ public class ErrorActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void buildInfo(final ErrorInfo info) {
|
private void buildInfo(final ErrorInfo info) {
|
||||||
final TextView infoLabelView = findViewById(R.id.errorInfoLabelsView);
|
|
||||||
final TextView infoView = findViewById(R.id.errorInfosView);
|
|
||||||
String text = "";
|
String text = "";
|
||||||
|
|
||||||
infoLabelView.setText(getString(R.string.info_labels).replace("\\n", "\n"));
|
activityErrorBinding.errorInfoLabelsView.setText(getString(R.string.info_labels)
|
||||||
|
.replace("\\n", "\n"));
|
||||||
|
|
||||||
text += getUserActionString(info.getUserAction()) + "\n"
|
text += getUserActionString(info.getUserAction()) + "\n"
|
||||||
+ info.getRequest() + "\n"
|
+ info.getRequest() + "\n"
|
||||||
@ -356,7 +344,7 @@ public class ErrorActivity extends AppCompatActivity {
|
|||||||
+ BuildConfig.VERSION_NAME + "\n"
|
+ BuildConfig.VERSION_NAME + "\n"
|
||||||
+ getOsString();
|
+ getOsString();
|
||||||
|
|
||||||
infoView.setText(text);
|
activityErrorBinding.errorInfosView.setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildJson() {
|
private String buildJson() {
|
||||||
@ -374,7 +362,8 @@ public class ErrorActivity extends AppCompatActivity {
|
|||||||
.value("os", getOsString())
|
.value("os", getOsString())
|
||||||
.value("time", currentTimeStamp)
|
.value("time", currentTimeStamp)
|
||||||
.array("exceptions", Arrays.asList(errorList))
|
.array("exceptions", Arrays.asList(errorList))
|
||||||
.value("user_comment", userCommentBox.getText().toString())
|
.value("user_comment", activityErrorBinding.errorCommentBox.getText()
|
||||||
|
.toString())
|
||||||
.end()
|
.end()
|
||||||
.done();
|
.done();
|
||||||
} catch (final Throwable e) {
|
} catch (final Throwable e) {
|
||||||
@ -389,7 +378,7 @@ public class ErrorActivity extends AppCompatActivity {
|
|||||||
try {
|
try {
|
||||||
final StringBuilder htmlErrorReport = new StringBuilder();
|
final StringBuilder htmlErrorReport = new StringBuilder();
|
||||||
|
|
||||||
final String userComment = userCommentBox.getText().toString();
|
final String userComment = activityErrorBinding.errorCommentBox.getText().toString();
|
||||||
if (!userComment.isEmpty()) {
|
if (!userComment.isEmpty()) {
|
||||||
htmlErrorReport.append(userComment).append("\n");
|
htmlErrorReport.append(userComment).append("\n");
|
||||||
}
|
}
|
||||||
@ -473,10 +462,9 @@ public class ErrorActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private void addGuruMeditation() {
|
private void addGuruMeditation() {
|
||||||
//just an easter egg
|
//just an easter egg
|
||||||
final TextView sorryView = findViewById(R.id.errorSorryView);
|
String text = activityErrorBinding.errorSorryView.getText().toString();
|
||||||
String text = sorryView.getText().toString();
|
|
||||||
text += "\n" + getString(R.string.guru_meditation);
|
text += "\n" + getString(R.string.guru_meditation);
|
||||||
sorryView.setText(text);
|
activityErrorBinding.errorSorryView.setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,7 +5,9 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".report.ErrorActivity">
|
tools:context=".report.ErrorActivity">
|
||||||
|
|
||||||
<include layout="@layout/toolbar_layout" />
|
<include
|
||||||
|
layout="@layout/toolbar_layout"
|
||||||
|
android:id="@+id/toolbar_layout"/>
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
android:id="@+id/scrollView"
|
android:id="@+id/scrollView"
|
||||||
|
Loading…
Reference in New Issue
Block a user