Skip to content

Commit

Permalink
Chore: Update DashboardFragment to ViewBinding
Browse files Browse the repository at this point in the history
  • Loading branch information
aanorbel committed Aug 18, 2023
1 parent 9f033e7 commit 9a7bd4f
Showing 1 changed file with 16 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,75 +1,66 @@
package org.openobservatory.ooniprobe.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import org.openobservatory.ooniprobe.R;
import org.openobservatory.ooniprobe.activity.AbstractActivity;
import org.openobservatory.ooniprobe.activity.MainActivity;
import org.openobservatory.ooniprobe.activity.OverviewActivity;
import org.openobservatory.ooniprobe.activity.RunningActivity;
import org.openobservatory.ooniprobe.common.Application;
import org.openobservatory.ooniprobe.common.PreferenceManager;
import org.openobservatory.ooniprobe.common.ReachabilityManager;
import org.openobservatory.ooniprobe.common.ThirdPartyServices;
import org.openobservatory.ooniprobe.databinding.FragmentDashboardBinding;
import org.openobservatory.ooniprobe.item.SeperatorItem;
import org.openobservatory.ooniprobe.item.TestsuiteItem;
import org.openobservatory.ooniprobe.model.database.Result;
import org.openobservatory.ooniprobe.test.TestAsyncTask;
import org.openobservatory.ooniprobe.test.suite.AbstractSuite;

import java.util.ArrayList;
import java.util.Objects;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerAdapter;
import localhost.toolkit.widget.recyclerview.HeterogeneousRecyclerItem;

public class DashboardFragment extends Fragment implements View.OnClickListener {
@BindView(R.id.recycler) RecyclerView recycler;
@BindView(R.id.toolbar) Toolbar toolbar;
@BindView(R.id.last_tested) TextView lastTested;
@BindView(R.id.run_all) TextView runAll;
@BindView(R.id.vpn) TextView vpn;

@Inject
PreferenceManager preferenceManager;

private ArrayList<HeterogeneousRecyclerItem> items;

private ArrayList<AbstractSuite> testSuites;

private HeterogeneousRecyclerAdapter<HeterogeneousRecyclerItem> adapter;

private FragmentDashboardBinding binding;

@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_dashboard, container, false);
ButterKnife.bind(this, v);
binding = FragmentDashboardBinding.inflate(inflater,container,false);
((Application) getActivity().getApplication()).getFragmentComponent().inject(this);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
((AppCompatActivity) getActivity()).setSupportActionBar(binding.toolbar);
((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(null);
items = new ArrayList<>();
testSuites = new ArrayList<>();
adapter = new HeterogeneousRecyclerAdapter<>(getActivity(), items);
recycler.setAdapter(adapter);
recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
runAll.setOnClickListener(v1 -> runAll());
vpn.setOnClickListener(view -> ((Application) getActivity().getApplication()).openVPNSettings());
return v;
binding.recycler.setAdapter(adapter);
binding.recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
binding.runAll.setOnClickListener(v1 -> runAll());
binding.vpn.setOnClickListener(view -> ((Application) getActivity().getApplication()).openVPNSettings());
return binding.getRoot();
}

@Override public void onResume() {
Expand Down Expand Up @@ -100,19 +91,19 @@ public class DashboardFragment extends Fragment implements View.OnClickListener
adapter.notifyTypesChanged();
if (ReachabilityManager.isVPNinUse(this.getContext())
&& preferenceManager.isWarnVPNInUse())
vpn.setVisibility(View.VISIBLE);
binding.vpn.setVisibility(View.VISIBLE);
else
vpn.setVisibility(View.GONE);
binding.vpn.setVisibility(View.GONE);
}

private void setLastTest() {
Result lastResult = Result.getLastResult();
if (lastResult == null)
lastTested.setText(getString(R.string.Dashboard_Overview_LatestTest)
binding.lastTested.setText(getString(R.string.Dashboard_Overview_LatestTest)
+ " " +
getString(R.string.Dashboard_Overview_LastRun_Never));
else
lastTested.setText(getString(R.string.Dashboard_Overview_LatestTest)
binding.lastTested.setText(getString(R.string.Dashboard_Overview_LatestTest)
+ " " +
DateUtils.getRelativeTimeSpanString(lastResult.start_time.getTime()));
}
Expand Down

0 comments on commit 9a7bd4f

Please sign in to comment.