Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Update TextActivity to ViewBinding #608

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,19 @@
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;

import localhost.toolkit.app.fragment.MessageDialogFragment;
import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.common.ReachabilityManager;
import org.openobservatory.ooniprobe.databinding.TextBinding;
import org.openobservatory.ooniprobe.domain.MeasurementsManager;
import org.openobservatory.ooniprobe.domain.callback.DomainCallback;
import org.openobservatory.ooniprobe.model.database.Measurement;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import localhost.toolkit.app.fragment.MessageDialogFragment;

public class TextActivity extends AbstractActivity {
private Measurement measurement;
private String text;
Expand All @@ -34,8 +29,7 @@ public class TextActivity extends AbstractActivity {
private static final String TEST = "test";
private static final String TYPE = "type";
private static final String TEXT = "text";
@BindView(R.id.textView)
TextView textView;
private TextBinding binding;

@Inject
MeasurementsManager measurementsManager;
Expand All @@ -52,8 +46,8 @@ public static Intent newIntent(Context context, int type, String text) {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivityComponent().inject(this);
setContentView(R.layout.text);
ButterKnife.bind(this);
binding = TextBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
showText();
}

Expand Down Expand Up @@ -95,7 +89,7 @@ public void showText() {
private void showLog() {
try {
text = measurementsManager.getReadableLog(measurement);
textView.setText(text);
binding.textView.setText(text);
} catch (Exception e) {
new MessageDialogFragment.Builder()
.withTitle(getString(R.string.Modal_Error_LogNotFound))
Expand All @@ -107,7 +101,7 @@ private void showJson() {
//Try to open file, if it doesn't exist dont show Error dialog immediately but try to download the json from internet
try {
text = measurementsManager.getReadableEntry(measurement);
textView.setText(text);
binding.textView.setText(text);
} catch (Exception e) {
e.printStackTrace();
if (ReachabilityManager.getNetworkType(this).equals(ReachabilityManager.NO_INTERNET)) {
Expand All @@ -125,7 +119,7 @@ private void showJson() {
public void onSuccess(String result) {
runOnUiThread(() -> {
text = result;
textView.setText(result);
binding.textView.setText(result);
});
}

Expand All @@ -140,7 +134,7 @@ public void onError(String msg) {
}

private void showUploadLog() {
textView.setText(text);
binding.textView.setText(text);
}

private void showError(String msg) {
Expand Down