Skip to content

Commit

Permalink
Update TextActivity to ViewBinding
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Aug 27, 2023
1 parent 9f033e7 commit 0f938bc
Showing 1 changed file with 9 additions and 15 deletions.
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

0 comments on commit 0f938bc

Please sign in to comment.